UserIdentityServiceImpl.java 7.3 KB

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