UserIdentityServiceImpl.java 14 KB

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