UserIdentityServiceImpl.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import com.goafanti.common.bo.Result;
  12. import com.goafanti.common.constant.AFTConstants;
  13. import com.goafanti.common.dao.NoticeMapper;
  14. import com.goafanti.common.dao.UserIdentityMapper;
  15. import com.goafanti.common.dao.UserMapper;
  16. import com.goafanti.common.dao.UserRoleMapper;
  17. import com.goafanti.common.enums.CertifySubmitType;
  18. import com.goafanti.common.enums.IdentityAuditStatus;
  19. import com.goafanti.common.enums.NoticeReadStatus;
  20. import com.goafanti.common.enums.NoticeStatus;
  21. import com.goafanti.common.enums.UserLevel;
  22. import com.goafanti.common.model.Notice;
  23. import com.goafanti.common.model.User;
  24. import com.goafanti.common.model.UserIdentity;
  25. import com.goafanti.core.mybatis.BaseMybatisDao;
  26. import com.goafanti.core.mybatis.page.Pagination;
  27. import com.goafanti.core.shiro.token.TokenManager;
  28. import com.goafanti.portal.bo.UserSubscriberListBo;
  29. import com.goafanti.user.bo.AuditorUserIdentityDetailBo;
  30. import com.goafanti.user.bo.UserIdentityBo;
  31. import com.goafanti.user.service.UserIdentityService;
  32. @Service
  33. public class UserIdentityServiceImpl extends BaseMybatisDao<UserIdentityMapper> implements UserIdentityService {
  34. @Autowired
  35. private UserIdentityMapper userIdentityMapper;
  36. @Autowired
  37. private UserMapper userMapper;
  38. @Autowired
  39. private UserRoleMapper userRoleMapper;
  40. @Autowired
  41. private NoticeMapper noticeMapper;
  42. @Override
  43. public UserIdentity selectUserIdentityByUserId(String uid) {
  44. return userIdentityMapper.selectUserIdentityByUserId(uid);
  45. }
  46. @Override
  47. public UserIdentity insert(UserIdentity userIdentity) {
  48. userIdentityMapper.insert(userIdentity);
  49. return userIdentity;
  50. }
  51. @Override
  52. public int updateByPrimaryKeySelective(UserIdentity userIdentity) {
  53. return userIdentityMapper.updateByPrimaryKeySelective(userIdentity);
  54. }
  55. @Override
  56. public UserIdentityBo selectUserIdentityBoByUserId(String uid) {
  57. return userIdentityMapper.selectUserIdentityBoByUserId(uid);
  58. }
  59. @Override
  60. public int updateByPrimaryKey(UserIdentity u) {
  61. return userIdentityMapper.updateByPrimaryKey(u);
  62. }
  63. @Override
  64. public int saveUserIdentityProcess(Result res, UserIdentity userIdentity, String uid) {
  65. UserIdentity identity = userIdentityMapper.selectUserIdentityByUserId(uid);
  66. if (null == identity) {
  67. userIdentity.setId(UUID.randomUUID().toString());
  68. userIdentity.setUid(uid);
  69. userIdentity.setWrongCount(0);
  70. userIdentity.setAuditStatus(0);
  71. return userIdentityMapper.insert(userIdentity);
  72. } else {
  73. userIdentity.setId(identity.getId());
  74. if (null != userIdentity.getAuditStatus() && 5 == userIdentity.getAuditStatus()) {
  75. User u = new User();
  76. u.setId(userIdentity.getUid());
  77. u.setLvl(1);
  78. userMapper.updateByPrimaryKeySelective(u);
  79. }
  80. return userIdentityMapper.updateByPrimaryKeySelective(userIdentity);
  81. }
  82. }
  83. @Override
  84. public int updateUserDetail(UserIdentity u, String saveSign, Integer level) {
  85. User user = userMapper.selectByPrimaryKey(u.getUid());
  86. user.setLvl(level);
  87. userMapper.updateByPrimaryKey(user);
  88. if (CertifySubmitType.SUBMIT.getCode().equals(saveSign)) {
  89. createAuditorNotice(user);
  90. }
  91. return userIdentityMapper.updateByPrimaryKeySelective(u);
  92. }
  93. @Override
  94. public int updateUserDetailByAuditAdmin(UserIdentity ui, String aid, String mid, Integer level) {
  95. // 审核员UPDATE_USER_DETAIL
  96. User user = userMapper.selectByPrimaryKey(ui.getUid());
  97. if (!IdentityAuditStatus.PASSED.getCode().equals(ui.getAuditStatus())) {
  98. user.setLvl(UserLevel.GENERAL.getCode());
  99. userMapper.updateByPrimaryKeySelective(user);
  100. createNotice(user, ui.getAuditStatus());
  101. }
  102. if (IdentityAuditStatus.PASSED.getCode().equals(ui.getAuditStatus())) {
  103. if (UserLevel.GENERAL.getCode().equals(level)) {
  104. user.setLvl(UserLevel.CERTIFIED.getCode());
  105. }
  106. user.setAid(aid);
  107. user.setMid(mid);
  108. userMapper.updateByPrimaryKeySelective(user);
  109. createNotice(user, ui.getAuditStatus());
  110. }
  111. return userIdentityMapper.updateByPrimaryKeySelective(ui);
  112. }
  113. @Override
  114. public UserIdentity insertByAdmin(UserIdentity ui, String saveSign) {
  115. userIdentityMapper.insert(ui);
  116. User u = userMapper.selectByPrimaryKey(ui.getUid());
  117. if (!TokenManager.hasRole(AFTConstants.AUDITORADMIN) && !TokenManager.hasRole(AFTConstants.SUPERADMIN)
  118. && CertifySubmitType.SUBMIT.getCode().equals(saveSign)) {
  119. u.setAid(TokenManager.getAdminId());
  120. userMapper.updateByPrimaryKeySelective(u);
  121. createAuditorNotice(u);
  122. }
  123. return ui;
  124. }
  125. @SuppressWarnings("unchecked")
  126. @Override
  127. public Pagination<UserSubscriberListBo> listSubscriber(String name, Integer level, String field, Integer province, Integer city,
  128. Integer area, Integer pNo, Integer pSize) {
  129. Map<String, Object> params = new HashMap<>();
  130. if (StringUtils.isNotBlank(name)) {
  131. params.put("name", name);
  132. }
  133. if (null != level) {
  134. params.put("level", level);
  135. }
  136. if (StringUtils.isNotBlank(field)) {
  137. params.put("field", field);
  138. }
  139. if (null != province) {
  140. params.put("province", province);
  141. }
  142. if (null != city) {
  143. params.put("city", city);
  144. }
  145. if (null != area) {
  146. params.put("area", area);
  147. }
  148. if (pNo == null || pNo < 0) {
  149. pNo = 1;
  150. }
  151. if (pSize == null || pSize < 0 || pSize > 12) {
  152. pSize = 12;
  153. }
  154. return (Pagination<UserSubscriberListBo>) findPage("findSearchSubscriberListByPage",
  155. "findSearchSubscriberCount", params, pNo, pSize);
  156. }
  157. // 给业务员及客户经理发送通知
  158. private void createNotice(User u, Integer status) {
  159. if (!StringUtils.isBlank(u.getAid())) {
  160. Notice n = new Notice();
  161. n.setPid(u.getAid());
  162. n.setAid(u.getAid());
  163. n.setUid(u.getId());
  164. notice(n, status);
  165. }
  166. if (!StringUtils.isBlank(u.getMid())) {
  167. Notice n = new Notice();
  168. n.setUid(u.getId());
  169. n.setAid(u.getMid());
  170. if (!StringUtils.isBlank(u.getAid())) {
  171. n.setPid(u.getAid());
  172. }
  173. notice(n, status);
  174. }
  175. }
  176. // 给所有审核员发送审核通知
  177. private void createAuditorNotice(User u) {
  178. List<String> ids = userRoleMapper.listAuditor();
  179. List<Notice> list = new ArrayList<>();
  180. if (null != ids && ids.size() > 0) {
  181. for (String s : ids) {
  182. Notice n = new Notice();
  183. Calendar now = Calendar.getInstance();
  184. now.set(Calendar.MILLISECOND, 0);
  185. n.setId(UUID.randomUUID().toString());
  186. n.setCreateTime(now.getTime());
  187. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  188. if (null != u) {
  189. n.setPid(u.getAid());
  190. }
  191. n.setUid(u.getId());
  192. n.setAid(s);
  193. n.setContent(NoticeStatus.PERSONALCERTIFY.getDesc() + " " + IdentityAuditStatus.COMMITTED.getDesc());
  194. n.setNoticeType(NoticeStatus.PERSONALCERTIFY.getCode());
  195. list.add(n);
  196. }
  197. noticeMapper.insertBatch(list);
  198. }
  199. }
  200. @Override
  201. public AuditorUserIdentityDetailBo selectAuditorUserIdentityByUserId(String uid) {
  202. return userIdentityMapper.selectAuditorUserIdentityByUserId(uid);
  203. }
  204. private void notice(Notice n, Integer status) {
  205. Calendar now = Calendar.getInstance();
  206. now.set(Calendar.MILLISECOND, 0);
  207. n.setId(UUID.randomUUID().toString());
  208. n.setCreateTime(now.getTime());
  209. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  210. String content = NoticeStatus.PERSONALCERTIFY.getDesc();
  211. if (IdentityAuditStatus.UNCOMMITTED.getCode() == status) {
  212. content = content + " " + IdentityAuditStatus.UNCOMMITTED.getDesc();
  213. } else if (IdentityAuditStatus.COMMITTED.getCode() == status) {
  214. content = content + " " + IdentityAuditStatus.COMMITTED.getDesc();
  215. } else if (IdentityAuditStatus.UNPAID.getCode() == status) {
  216. content = content + " " + IdentityAuditStatus.UNPAID.getDesc();
  217. } else if (IdentityAuditStatus.PAID.getCode() == status) {
  218. content = content + " " + IdentityAuditStatus.PAID.getDesc();
  219. } else if (IdentityAuditStatus.PASSED.getCode() == status) {
  220. content = content + " " + IdentityAuditStatus.PASSED.getDesc();
  221. } else {
  222. content = content + " " + IdentityAuditStatus.NOTPASSED.getDesc();
  223. }
  224. n.setContent(content);
  225. n.setNoticeType(NoticeStatus.PERSONALCERTIFY.getCode());
  226. noticeMapper.insert(n);
  227. }
  228. }