UserServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. package com.goafanti.user.service.impl;
  2. import java.text.ParseException;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.UUID;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.cache.annotation.Cacheable;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import com.goafanti.app.bo.UserBasicInfo;
  13. import com.goafanti.common.bo.userDaysBo;
  14. import com.goafanti.common.constant.AFTConstants;
  15. import com.goafanti.common.dao.CopyrightInfoMapper;
  16. import com.goafanti.common.dao.OrgIntellectualPropertyMapper;
  17. import com.goafanti.common.dao.OrganizationIdentityMapper;
  18. import com.goafanti.common.dao.PatentInfoMapper;
  19. import com.goafanti.common.dao.TechProjectMapper;
  20. import com.goafanti.common.dao.UserIdentityMapper;
  21. import com.goafanti.common.dao.UserMapper;
  22. import com.goafanti.common.enums.UserType;
  23. import com.goafanti.common.model.OrganizationIdentity;
  24. import com.goafanti.common.model.User;
  25. import com.goafanti.common.model.UserIdentity;
  26. import com.goafanti.common.utils.DateUtils;
  27. import com.goafanti.core.mybatis.BaseMybatisDao;
  28. import com.goafanti.core.mybatis.page.Pagination;
  29. import com.goafanti.core.shiro.token.TokenManager;
  30. import com.goafanti.user.bo.OrgListBo;
  31. import com.goafanti.user.bo.OrgPartnerDetailBo;
  32. import com.goafanti.user.bo.OrgUnitNames;
  33. import com.goafanti.user.bo.StarAndExpertListBo;
  34. import com.goafanti.user.bo.StarListBo;
  35. import com.goafanti.user.bo.UserDownLoadBo;
  36. import com.goafanti.user.bo.UserNames;
  37. import com.goafanti.user.bo.UserPageHomeBo;
  38. import com.goafanti.user.bo.UserPartnerDetailBo;
  39. import com.goafanti.user.service.UserService;
  40. @Service
  41. public class UserServiceImpl extends BaseMybatisDao<UserMapper> implements UserService {
  42. @Autowired
  43. private UserMapper userMapper;
  44. @Autowired
  45. private OrganizationIdentityMapper organizationIdentityMapper;
  46. @Autowired
  47. private UserIdentityMapper userIdentityMapper;
  48. @Autowired
  49. private PatentInfoMapper patentInfoMapper;
  50. @Autowired
  51. private CopyrightInfoMapper copyrightInfoMapper;
  52. @Autowired
  53. private TechProjectMapper techProjectMapper;
  54. @Autowired
  55. private OrgIntellectualPropertyMapper orgIntellectualPropertyMapper;
  56. @Override
  57. @Transactional
  58. public User insertRegister(User user, String unitName, String userName) {
  59. userMapper.insert(user);
  60. if (null != user.getType() && UserType.ORGANIZATION.getCode().equals(user.getType())) {
  61. OrganizationIdentity organizationIdentity = new OrganizationIdentity();
  62. organizationIdentity.setUid(user.getId());
  63. organizationIdentity.setUnitName(StringUtils.isBlank(unitName) ? "" : unitName);
  64. organizationIdentity.setId(UUID.randomUUID().toString());
  65. organizationIdentity.setIdentityType(0);
  66. organizationIdentity.setAuditStatus(0);
  67. organizationIdentity.setProcess(0);
  68. organizationIdentity.setWrongCount(0);
  69. organizationIdentity.setListed(0);
  70. organizationIdentity.setListedType(0);
  71. organizationIdentityMapper.insert(organizationIdentity);
  72. }
  73. if (null != user.getType() && UserType.PERSONAL.getCode().equals(user.getType())) {
  74. UserIdentity ui = new UserIdentity();
  75. ui.setId(UUID.randomUUID().toString());
  76. ui.setUid(user.getId());
  77. ui.setAuditStatus(0);
  78. ui.setProcess(0);
  79. ui.setWrongCount(0);
  80. ui.setUsername(StringUtils.isBlank(userName) ? "" : userName);
  81. userIdentityMapper.insert(ui);
  82. }
  83. return user;
  84. }
  85. @Override
  86. public User selectByMobieAndType(String mobile, Integer type) {
  87. return userMapper.selectByMobieAndType(mobile, type);
  88. }
  89. @Override
  90. public User selectByPrimaryKey(String id) {
  91. return userMapper.selectByPrimaryKey(id);
  92. }
  93. @Override
  94. public int updateByPrimaryKeySelective(User u) {
  95. return userMapper.updateByPrimaryKeySelective(u);
  96. }
  97. @Override
  98. public User insert(User user) {
  99. userMapper.insert(user);
  100. return user;
  101. }
  102. @Override
  103. public UserPageHomeBo selectUserPageHomeBoByUserId(String uid) {
  104. UserPageHomeBo bo = userMapper.selectUserPageHomeBoByUserId(uid);
  105. bo.setPatentNum(patentInfoMapper.findPatentInfoNumByUid(uid));
  106. bo.setCopyrightNum(copyrightInfoMapper.findCopyrightInfoNumByUid(uid));
  107. bo.setTechProjectNum(techProjectMapper.findTechProjectNumByUid(uid));
  108. bo.setIntellectualPropertyNum(orgIntellectualPropertyMapper.findIntellectualPropertyNum(uid));
  109. return bo;
  110. }
  111. @Override
  112. public UserDownLoadBo selectUserDownLoadBoByUserId(String id) {
  113. return userMapper.selectUserDownLoadBoByUserId(id);
  114. }
  115. @SuppressWarnings("unchecked")
  116. @Override
  117. public Pagination<OrgListBo> selectUserByAid(Integer number, String mobile, Integer auditStatus, String auditName,
  118. String email, String aid, String startCreateTime, String endCreateTime, Integer type, Integer pageNo,
  119. Integer pageSize) {
  120. Map<String, Object> params = new HashMap<>();
  121. if (StringUtils.isNotBlank(startCreateTime)) {
  122. try {
  123. params.put("startCreateTime", DateUtils.parseDate(startCreateTime, AFTConstants.YYYYMMDD));
  124. } catch (ParseException e) {
  125. }
  126. }
  127. if (StringUtils.isNotBlank(endCreateTime)) {
  128. try {
  129. params.put("endCreateTime",
  130. DateUtils.addDays(DateUtils.parseDate(endCreateTime, AFTConstants.YYYYMMDD), 1));
  131. } catch (ParseException e) {
  132. }
  133. }
  134. if (null != number) {
  135. params.put("number", number);
  136. }
  137. if (StringUtils.isNotBlank(mobile)) {
  138. params.put("mobile", mobile);
  139. }
  140. if (null != auditStatus) {
  141. params.put("auditStatus", auditStatus);
  142. }
  143. if (StringUtils.isNotBlank(auditName)) {
  144. params.put("auditName", auditName);
  145. }
  146. if (StringUtils.isNotBlank(email)) {
  147. params.put("email", email);
  148. }
  149. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  150. params.put("aid", aid);
  151. }
  152. if (pageNo == null || pageNo < 0) {
  153. pageNo = 1;
  154. }
  155. if (pageSize == null || pageSize < 0 || pageSize > 10) {
  156. pageSize = 10;
  157. }
  158. if (UserType.PERSONAL.getCode().equals(type)) {
  159. return (Pagination<OrgListBo>) findPage("findUserByAidWithParamsListByPage", "findUserByAidWithParamsCount",
  160. params, pageNo, pageSize);
  161. } else if (UserType.ORGANIZATION.getCode().equals(type)) {
  162. return (Pagination<OrgListBo>) findPage("findOrgByAidWithParamsListByPage", "findOrgByAidWithParamsCount",
  163. params, pageNo, pageSize);
  164. }
  165. return null;
  166. }
  167. @Override
  168. public List<OrgUnitNames> selectDemandUnitNames() {
  169. String aid = TokenManager.getAdminId();
  170. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  171. return organizationIdentityMapper.selectManagerUnitNames(aid);
  172. } else {
  173. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  174. aid = null;
  175. }
  176. return organizationIdentityMapper.selectAllOrgIndentity(aid);
  177. }
  178. }
  179. @Override
  180. public List<UserNames> selectDemandUserNames() {
  181. String aid = TokenManager.getAdminId();
  182. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  183. return userIdentityMapper.selectManagerUserNames(aid);
  184. } else {
  185. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  186. aid = null;
  187. }
  188. return userIdentityMapper.selectAllUserNames(aid);
  189. }
  190. }
  191. @Override
  192. public Map<String, String> selectAchievementUserOwner(String name) {
  193. String aid = TokenManager.getAdminId();
  194. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  195. return disposeAchievementUserOwner(userIdentityMapper.selectManagerAchievementUserOwner(aid, name));
  196. } else {
  197. if (TokenManager.hasRole(AFTConstants.SUPERADMIN) || TokenManager.hasRole(AFTConstants.TECHBROKER)
  198. || TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  199. aid = null;
  200. }
  201. return disposeAchievementUserOwner(userIdentityMapper.selectAchievementUserOwner(aid, name));
  202. }
  203. }
  204. public List<OrgUnitNames> selectAchievementOrgOwner(String name) {
  205. String aid = TokenManager.getAdminId();
  206. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  207. return organizationIdentityMapper.selectManagerAchievementOrgOwner(aid, name);
  208. } else {
  209. if (TokenManager.hasRole(AFTConstants.SUPERADMIN) || TokenManager.hasRole(AFTConstants.TECHBROKER)
  210. || TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  211. aid = null;
  212. }
  213. return organizationIdentityMapper.selectAchievementOrgOwner(aid, name);
  214. }
  215. }
  216. private Map<String, String> disposeAchievementUserOwner(List<UserNames> list) {
  217. Map<String, String> map = new HashMap<>();
  218. if (null != list && list.size() > 0) {
  219. for (UserNames u : list) {
  220. map.put(u.getUid(), u.getUsername() + " " + u.getMobile());
  221. }
  222. }
  223. return map;
  224. }
  225. @Override
  226. public String findUserNameByNameAndMobile(String name, String mobile) {
  227. return userMapper.findUserByNameAndMobile(name, mobile);
  228. }
  229. @Override
  230. public String findOrgNameByNameAndMobile(String name, String mobile) {
  231. return userMapper.findOrgByNameAndMobile(name, mobile);
  232. }
  233. @Override
  234. public UserPartnerDetailBo findUserPartnerDetail(String uid) {
  235. return userMapper.findUserPartnerDetail(uid);
  236. }
  237. @Override
  238. public OrgPartnerDetailBo findOrgPartnerDetail(String uid) {
  239. return userMapper.findOrgPartnerDetail(uid);
  240. }
  241. @SuppressWarnings("unchecked")
  242. @Override
  243. public Pagination<StarListBo> listStar(Integer number, String engagedField, String username,
  244. String professionalTitle, String workUnit, Integer pNo, Integer pSize) {
  245. Map<String, Object> params = new HashMap<>();
  246. if (null != number) {
  247. params.put("number", number);
  248. }
  249. if (StringUtils.isNotBlank(engagedField)) {
  250. params.put("engagedField", engagedField);
  251. }
  252. if (StringUtils.isNotBlank(username)) {
  253. params.put("username", username);
  254. }
  255. if (StringUtils.isNotBlank(professionalTitle)) {
  256. params.put("professionalTitle", professionalTitle);
  257. }
  258. if (StringUtils.isNotBlank(workUnit)) {
  259. params.put("workUnit", workUnit);
  260. }
  261. if (pNo == null || pNo < 0) {
  262. pNo = 1;
  263. }
  264. if (pSize == null || pSize < 0 || pSize > 10) {
  265. pSize = 10;
  266. }
  267. return (Pagination<StarListBo>) findPage("findStarListByPage", "findStarCount", params, pNo, pSize);
  268. }
  269. @SuppressWarnings("unchecked")
  270. @Override
  271. public Pagination<StarAndExpertListBo> listStarAndExpert(Integer number, String engagedField, String username,
  272. String professionalTitle, String workUnit, Integer pNo, Integer pSize) {
  273. Map<String, Object> params = new HashMap<>();
  274. if (null != number) {
  275. params.put("number", number);
  276. }
  277. if (StringUtils.isNotBlank(engagedField)) {
  278. params.put("engagedField", engagedField);
  279. }
  280. if (StringUtils.isNotBlank(username)) {
  281. params.put("username", username);
  282. }
  283. if (StringUtils.isNotBlank(professionalTitle)) {
  284. params.put("professionalTitle", professionalTitle);
  285. }
  286. if (StringUtils.isNotBlank(workUnit)) {
  287. params.put("workUnit", workUnit);
  288. }
  289. if (pNo == null || pNo < 0) {
  290. pNo = 1;
  291. }
  292. if (pSize == null || pSize < 0 || pSize > 10) {
  293. pSize = 10;
  294. }
  295. return (Pagination<StarAndExpertListBo>) findPage("findStarAndExpertListByPage", "findStarAndExpertCount",
  296. params, pNo, pSize);
  297. }
  298. @Override
  299. @Cacheable(value = "UserNumberCache", key = "'UserNumberCache:UID:'+#userId")
  300. public String selectNumberByPrimaryKey(String userId) {
  301. return String.valueOf(userMapper.selectNumberByPrimaryKey(userId));
  302. }
  303. @Override
  304. public List<UserPartnerDetailBo> findUserPartner() {
  305. return userMapper.findUserPartner();
  306. }
  307. @Override
  308. public UserBasicInfo selectBaseInfo() {
  309. if(TokenManager.getToken() instanceof User)return userMapper.selectBaseInfo(TokenManager.getUserId());
  310. return null;
  311. }
  312. @Override
  313. public User selectByNumber(String easemobName) {
  314. return userMapper.selectByNumber(easemobName);
  315. }
  316. @Override
  317. public List<User> selectUserByRoleName(String roleName1,String roleName2){
  318. return userMapper.selectUserByRoleName(roleName1,roleName2);
  319. }
  320. @Override
  321. public void pushReleaseUserChannel(List<userDaysBo> newCList,Integer type) {
  322. userMapper.updateReleaseUserChannel(newCList,type);
  323. }
  324. }