UserIdentityServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. package com.goafanti.user.service.impl;
  2. import java.util.ArrayList;
  3. import java.util.Calendar;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.UUID;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import org.springframework.beans.BeanUtils;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.cache.annotation.CacheEvict;
  14. import org.springframework.stereotype.Service;
  15. import com.goafanti.app.bo.consultantListBo;
  16. import com.goafanti.common.bo.Result;
  17. import com.goafanti.common.bo.fieldGlossoryBo;
  18. import com.goafanti.common.constant.AFTConstants;
  19. import com.goafanti.common.dao.DistrictGlossoryMapper;
  20. import com.goafanti.common.dao.IndustryCategoryMapper;
  21. import com.goafanti.common.dao.NoticeMapper;
  22. import com.goafanti.common.dao.UserIdentityMapper;
  23. import com.goafanti.common.dao.UserInterestMapper;
  24. import com.goafanti.common.dao.UserMapper;
  25. import com.goafanti.common.dao.UserRoleMapper;
  26. import com.goafanti.common.enums.CertifySubmitType;
  27. import com.goafanti.common.enums.IdentityAuditStatus;
  28. import com.goafanti.common.enums.NoticeReadStatus;
  29. import com.goafanti.common.enums.NoticeStatus;
  30. import com.goafanti.common.enums.UserLevel;
  31. import com.goafanti.common.model.Notice;
  32. import com.goafanti.common.model.User;
  33. import com.goafanti.common.model.UserIdentity;
  34. import com.goafanti.common.utils.LoggerUtils;
  35. import com.goafanti.core.mybatis.BaseMybatisDao;
  36. import com.goafanti.core.mybatis.page.Pagination;
  37. import com.goafanti.core.shiro.token.TokenManager;
  38. import com.goafanti.demand.bo.ObjectInterestListBo;
  39. import com.goafanti.portal.bo.UserSubscriberListBo;
  40. import com.goafanti.user.bo.Advertisings;
  41. import com.goafanti.user.bo.AuditorUserIdentityDetailBo;
  42. import com.goafanti.user.bo.UserIdentityBo;
  43. import com.goafanti.user.bo.UserIdentityDetailAdminBo;
  44. import com.goafanti.user.service.UserIdentityService;
  45. @Service
  46. public class UserIdentityServiceImpl extends BaseMybatisDao<UserIdentityMapper> implements UserIdentityService {
  47. @Autowired
  48. private UserIdentityMapper userIdentityMapper;
  49. @Autowired
  50. private UserMapper userMapper;
  51. @Autowired
  52. private UserRoleMapper userRoleMapper;
  53. @Autowired
  54. private NoticeMapper noticeMapper;
  55. @Autowired
  56. DistrictGlossoryMapper districtGlossoryMapper;
  57. @Autowired
  58. IndustryCategoryMapper industryCategoryMapper;
  59. @Autowired
  60. UserInterestMapper userInterestMapper;
  61. private static final Logger logger = LoggerFactory.getLogger(UserIdentityServiceImpl.class);
  62. @Override
  63. public UserIdentity selectUserIdentityByUserId(String uid) {
  64. return userIdentityMapper.selectUserIdentityByUserId(uid);
  65. }
  66. @Override
  67. public UserIdentity insert(UserIdentity userIdentity) {
  68. userIdentityMapper.insert(userIdentity);
  69. return userIdentity;
  70. }
  71. @Override
  72. public int updateByPrimaryKeySelective(UserIdentity userIdentity) {
  73. return userIdentityMapper.updateByPrimaryKeySelective(userIdentity);
  74. }
  75. @Override
  76. public UserIdentityBo selectUserIdentityBoByUserId(String uid) {
  77. return userIdentityMapper.selectUserIdentityBoByUserId(uid);
  78. }
  79. @Override
  80. public int updateByPrimaryKey(UserIdentity u) {
  81. return userIdentityMapper.updateByPrimaryKey(u);
  82. }
  83. @Override
  84. public int saveUserIdentityProcess(Result res, UserIdentity userIdentity, String uid) {
  85. UserIdentity identity = userIdentityMapper.selectUserIdentityByUserId(uid);
  86. if (null == identity) {
  87. userIdentity.setId(UUID.randomUUID().toString());
  88. userIdentity.setUid(uid);
  89. userIdentity.setWrongCount(0);
  90. userIdentity.setAuditStatus(0);
  91. return userIdentityMapper.insert(userIdentity);
  92. } else {
  93. userIdentity.setId(identity.getId());
  94. if (null != userIdentity.getAuditStatus() && 5 == userIdentity.getAuditStatus()) {
  95. User u = new User();
  96. u.setId(userIdentity.getUid());
  97. u.setLvl(1);
  98. userMapper.updateByPrimaryKeySelective(u);
  99. }
  100. return userIdentityMapper.updateByPrimaryKeySelective(userIdentity);
  101. }
  102. }
  103. @Override
  104. public int updateUserDetail(UserIdentity u, String saveSign, Integer level) {
  105. User user = userMapper.selectByPrimaryKey(u.getUid());
  106. if (!UserLevel.GENERAL.getCode().equals(user.getLvl())
  107. && !CertifySubmitType.SUBMIT.getCode().equals(saveSign)) {
  108. user.setLvl(level);
  109. userMapper.updateByPrimaryKeySelective(user);
  110. }
  111. if (CertifySubmitType.SUBMIT.getCode().equals(saveSign)) {
  112. createAuditorNotice(user);
  113. }
  114. return userIdentityMapper.updateByPrimaryKeySelective(u);
  115. }
  116. @Override
  117. public int updateUserDetailByAuditAdmin(UserIdentity ui, String aid, String mid, Integer level) {
  118. // 审核员UPDATE_USER_DETAIL
  119. User user = userMapper.selectByPrimaryKey(ui.getUid());
  120. if (!IdentityAuditStatus.PASSED.getCode().equals(ui.getAuditStatus())) {
  121. user.setLvl(UserLevel.GENERAL.getCode());
  122. userMapper.updateByPrimaryKeySelective(user);
  123. createNotice(user, ui.getAuditStatus());
  124. }
  125. if (IdentityAuditStatus.PASSED.getCode().equals(ui.getAuditStatus())) {
  126. /*
  127. * if (UserLevel.GENERAL.getCode().equals(level)) {
  128. * user.setLvl(UserLevel.CERTIFIED.getCode()); }
  129. */
  130. user.setLvl(UserLevel.CERTIFIED.getCode());
  131. user.setAid(aid);
  132. user.setMid(mid);
  133. userMapper.updateByPrimaryKeySelective(user);
  134. createNotice(user, ui.getAuditStatus());
  135. }
  136. return userIdentityMapper.updateByPrimaryKeySelective(ui);
  137. }
  138. @Override
  139. public UserIdentity insertByAdmin(UserIdentity ui, String saveSign) {
  140. userIdentityMapper.insert(ui);
  141. User u = userMapper.selectByPrimaryKey(ui.getUid());
  142. if (!TokenManager.hasRole(AFTConstants.AUDITORADMIN) && !TokenManager.hasRole(AFTConstants.SUPERADMIN)
  143. && CertifySubmitType.SUBMIT.getCode().equals(saveSign)) {
  144. u.setAid(TokenManager.getAdminId());
  145. userMapper.updateByPrimaryKeySelective(u);
  146. createAuditorNotice(u);
  147. }
  148. return ui;
  149. }
  150. @SuppressWarnings("unchecked")
  151. @Override
  152. public Pagination<UserSubscriberListBo> listSubscriber(String url,String name, Integer level, String field, Integer province,
  153. Integer city, Integer area, Integer international, Integer pNo, Integer pSize) {
  154. Map<String, Object> params = new HashMap<>();
  155. if (StringUtils.isNotBlank(url)) {
  156. params.put("url", url);
  157. }
  158. if (StringUtils.isNotBlank(name)) {
  159. params.put("name", name);
  160. }
  161. if (null != level) {
  162. params.put("level", level);
  163. }
  164. if (StringUtils.isNotBlank(field)) {
  165. params.put("field", field);
  166. }
  167. if (null != province) {
  168. params.put("province", province);
  169. }
  170. if (null != city) {
  171. params.put("city", city);
  172. }
  173. if (null != area) {
  174. params.put("area", area);
  175. }
  176. if (null != international) {
  177. params.put("international", international);
  178. }
  179. if (pNo == null || pNo < 0) {
  180. pNo = 1;
  181. }
  182. if (pSize == null || pSize < 0 || pSize > 12) {
  183. pSize = 12;
  184. }
  185. return (Pagination<UserSubscriberListBo>) findPage("findSearchSubscriberListByPage",
  186. "findSearchSubscriberCount", params, pNo, pSize);
  187. }
  188. // 给业务员及客户经理发送通知
  189. private void createNotice(User u, Integer status) {
  190. if (!StringUtils.isBlank(u.getAid())) {
  191. Notice n = new Notice();
  192. n.setPid(u.getAid());
  193. n.setAid(u.getAid());
  194. n.setUid(u.getId());
  195. notice(n, status);
  196. }
  197. if (!StringUtils.isBlank(u.getMid())) {
  198. Notice n = new Notice();
  199. n.setUid(u.getId());
  200. n.setAid(u.getMid());
  201. if (!StringUtils.isBlank(u.getAid())) {
  202. n.setPid(u.getAid());
  203. }
  204. notice(n, status);
  205. }
  206. }
  207. // 给所有审核员发送审核通知
  208. private void createAuditorNotice(User u) {
  209. List<String> ids = userRoleMapper.listAuditor();
  210. List<Notice> list = new ArrayList<>();
  211. if (null != ids && ids.size() > 0) {
  212. for (String s : ids) {
  213. Notice n = new Notice();
  214. Calendar now = Calendar.getInstance();
  215. now.set(Calendar.MILLISECOND, 0);
  216. n.setId(UUID.randomUUID().toString());
  217. n.setCreateTime(now.getTime());
  218. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  219. if (null != u) {
  220. n.setPid(u.getAid());
  221. }
  222. n.setUid(u.getId());
  223. n.setAid(s);
  224. n.setContent(NoticeStatus.PERSONALCERTIFY.getDesc() + " " + IdentityAuditStatus.COMMITTED.getDesc());
  225. n.setNoticeType(NoticeStatus.PERSONALCERTIFY.getCode());
  226. list.add(n);
  227. }
  228. noticeMapper.insertBatch(list);
  229. }
  230. }
  231. @Override
  232. public AuditorUserIdentityDetailBo selectAuditorUserIdentityByUserId(String uid) {
  233. return userIdentityMapper.selectAuditorUserIdentityByUserId(uid);
  234. }
  235. private void notice(Notice n, Integer status) {
  236. Calendar now = Calendar.getInstance();
  237. now.set(Calendar.MILLISECOND, 0);
  238. n.setId(UUID.randomUUID().toString());
  239. n.setCreateTime(now.getTime());
  240. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  241. String content = NoticeStatus.PERSONALCERTIFY.getDesc();
  242. if (IdentityAuditStatus.UNCOMMITTED.getCode() == status) {
  243. content = content + " " + IdentityAuditStatus.UNCOMMITTED.getDesc();
  244. } else if (IdentityAuditStatus.COMMITTED.getCode() == status) {
  245. content = content + " " + IdentityAuditStatus.COMMITTED.getDesc();
  246. } else if (IdentityAuditStatus.UNPAID.getCode() == status) {
  247. content = content + " " + IdentityAuditStatus.UNPAID.getDesc();
  248. } else if (IdentityAuditStatus.PAID.getCode() == status) {
  249. content = content + " " + IdentityAuditStatus.PAID.getDesc();
  250. } else if (IdentityAuditStatus.PASSED.getCode() == status) {
  251. content = content + " " + IdentityAuditStatus.PASSED.getDesc();
  252. } else {
  253. content = content + " " + IdentityAuditStatus.NOTPASSED.getDesc();
  254. }
  255. n.setContent(content);
  256. n.setNoticeType(NoticeStatus.PERSONALCERTIFY.getCode());
  257. // noticeMapper.insert(n);
  258. }
  259. @Override
  260. public UserIdentityDetailAdminBo selectUserIdentityByUserIdAdmin(String uid) {
  261. UserIdentity ui = userIdentityMapper.selectUserIdentityByUserId(uid);
  262. User u = userMapper.selectByPrimaryKey(uid);
  263. UserIdentityDetailAdminBo bo = new UserIdentityDetailAdminBo();
  264. if (ui != null) {
  265. BeanUtils.copyProperties(ui, bo);
  266. }
  267. bo.setLevel(u.getLvl().toString());
  268. return bo;
  269. }
  270. @CacheEvict(value = "internationalUserList", allEntries = true)
  271. public void cleanInternationalUser() {
  272. LoggerUtils.debug(logger, "清除国际专家列表");
  273. }
  274. @Override
  275. public UserIdentityBo expertsDetail(String uid) {
  276. UserIdentityBo u=userIdentityMapper.selectUserIdentityByUid(uid);
  277. if (null!=u.getProvince()) {
  278. u.setProvince0(districtGlossoryMapper.selectByPrimaryKey(u.getProvince()).getName());
  279. }
  280. if (null!=u.getCity()) {
  281. u.setCity0(String.valueOf(districtGlossoryMapper.selectByPrimaryKey(u.getCity()).getName()));
  282. }
  283. if (null!=u.getArea()) {
  284. u.setArea0(String.valueOf(districtGlossoryMapper.selectByPrimaryKey(u.getArea()).getName()));
  285. }
  286. if (null!=u.getIndustry()) {
  287. u.setIndustry0(String.valueOf(industryCategoryMapper.selectByPrimaryKey(u.getIndustry()).getName()));
  288. }
  289. if (null!=u.getUid()) {
  290. u.setCountInterest(String.valueOf(userInterestMapper.countByToUid(u.getUid())));
  291. }
  292. String id=TokenManager.getUserId();
  293. if(TokenManager.isLogin()&&userInterestMapper.checkUidAndDid(uid,id)>0){
  294. u.setInterest("1");
  295. }else {
  296. u.setInterest("0");
  297. }
  298. return u;
  299. }
  300. @SuppressWarnings("unchecked")
  301. @Override
  302. public Pagination<UserIdentityBo> expertsList(String name,String industry, Integer pNo, Integer pSize) {
  303. Map<String, Object> params = new HashMap<>();
  304. if (StringUtils.isNotBlank(industry)) {
  305. params.put("industry", industry);
  306. }
  307. if (StringUtils.isNotBlank(name)) {
  308. params.put("name", name);
  309. }
  310. if (pNo == null || pNo < 0) {
  311. pNo = 1;
  312. }
  313. if (pSize == null || pSize < 0 || pSize > 12) {
  314. pSize = 10;
  315. }
  316. Pagination<UserIdentityBo> p= (Pagination<UserIdentityBo>) findPage("findUserIdentityListByPage",
  317. "findUserIdentityCount", params, pNo, pSize);
  318. List<UserIdentityBo> l=(List<UserIdentityBo>) p.getList();
  319. for (UserIdentityBo u : l) {
  320. int i=userInterestMapper.countInterest(u.getId());
  321. u.setCountInterest(String.valueOf(i));
  322. }
  323. return p;
  324. }
  325. @Override
  326. public List<fieldGlossoryBo> industryList() {
  327. List<fieldGlossoryBo> list=industryCategoryMapper.selectindustryList();
  328. return list;
  329. }
  330. @SuppressWarnings("unchecked")
  331. @Override
  332. public Pagination<consultantListBo> consultantList(Integer pNo, Integer pSize) {
  333. Map<String, Object> params = new HashMap<>();
  334. if (pNo == null || pNo < 0) {
  335. pNo = 1;
  336. }
  337. if (pSize == null || pSize < 0 || pSize > 12) {
  338. pSize = 10;
  339. }
  340. Pagination<consultantListBo> p=(Pagination<consultantListBo>) findPage("findConsultantListByPage",
  341. "findConsultantCount", params, pNo, pSize);
  342. return p;
  343. }
  344. @Override
  345. public consultantListBo consultantDetail(String id) {
  346. consultantListBo c=userIdentityMapper.selectconsultantByUid(id);
  347. if (TokenManager.isLogin()&&userInterestMapper.checkUidAndDid(id, TokenManager.getUserId())>0) {
  348. c.setInterest("1");
  349. }else {
  350. c.setInterest("0");
  351. }
  352. return c;
  353. }
  354. @Override
  355. public List<Advertisings> advertising() {
  356. List<String> a=new ArrayList<>();
  357. a.add("关于开展2018年度高新技术企业认定专项审计机构申报工作的通知");
  358. a.add("转发四川省经济和信息化委员会关于开展2017年上市补助申报通知的通知");
  359. a.add("关于组织企业参加第十三届中国重庆高新技术成果交易会暨第九届中国国际军民两用技术博览会的通知");
  360. a.add("关于组织参加第十三届中国重庆高新技术交易会暨第九届中国国际军民两用技术博览会的通知");
  361. List<Advertisings> ads=new ArrayList<>();
  362. int i=0;
  363. List<String> l=new ArrayList<>();
  364. for (String s : a) {
  365. i++;
  366. l.add(s);
  367. if (i%2==0) {
  368. ads.add(new Advertisings(l));
  369. l=new ArrayList<>();
  370. }
  371. }
  372. return ads;
  373. }
  374. @SuppressWarnings("unchecked")
  375. @Override
  376. public Pagination<consultantListBo> portalConsultantList(Integer pNo, Integer pSize) {
  377. Pagination<consultantListBo> p=(Pagination<consultantListBo>) findPage("findConsultantListByPage",
  378. "findConsultantCount", new HashMap<>(), pNo, pSize);
  379. List<consultantListBo> list=(List<consultantListBo>) p.getList();
  380. for (consultantListBo c : list) {
  381. if (StringUtils.isNotBlank(TokenManager.getUserId())&&userInterestMapper.checkUidAndDid(c.getId(), TokenManager.getUserId())>0) {
  382. c.setInterest("1");
  383. }else {
  384. c.setInterest("0");
  385. }
  386. }
  387. return p;
  388. }
  389. @Override
  390. public consultantListBo portalconsultantDetail(String id) {
  391. consultantListBo c=userIdentityMapper.selectconsultantByUid(id);
  392. if (StringUtils.isNotBlank(TokenManager.getUserId())&&userInterestMapper.checkUidAndDid(id, TokenManager.getUserId())>0) {
  393. c.setInterest("1");
  394. }else {
  395. c.setInterest("0");
  396. }
  397. return c;
  398. }
  399. @Override
  400. public List<fieldGlossoryBo> domainList() {
  401. List<fieldGlossoryBo> list=industryCategoryMapper.selectDomainList();
  402. return list;
  403. }
  404. }