UserServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. package com.goafanti.user.service.impl;
  2. import java.text.ParseException;
  3. import java.util.Date;
  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.cache.annotation.Cacheable;
  11. import org.springframework.stereotype.Service;
  12. import com.goafanti.common.constant.AFTConstants;
  13. import com.goafanti.common.dao.AdminLocationMapper;
  14. import com.goafanti.common.dao.CopyrightInfoMapper;
  15. import com.goafanti.common.dao.OrgIntellectualPropertyMapper;
  16. import com.goafanti.common.dao.OrganizationIdentityMapper;
  17. import com.goafanti.common.dao.PatentInfoMapper;
  18. import com.goafanti.common.dao.TechProjectMapper;
  19. import com.goafanti.common.dao.UserIdentityMapper;
  20. import com.goafanti.common.dao.UserMapper;
  21. import com.goafanti.common.enums.UserType;
  22. import com.goafanti.common.model.OrganizationIdentity;
  23. import com.goafanti.common.model.User;
  24. import com.goafanti.common.model.UserIdentity;
  25. import com.goafanti.common.utils.DateUtils;
  26. import com.goafanti.core.mybatis.BaseMybatisDao;
  27. import com.goafanti.core.mybatis.page.Pagination;
  28. import com.goafanti.core.shiro.token.TokenManager;
  29. import com.goafanti.user.bo.OrgListBo;
  30. import com.goafanti.user.bo.OrgPartnerDetailBo;
  31. import com.goafanti.user.bo.OrgUnitNames;
  32. import com.goafanti.user.bo.StarAndExpertListBo;
  33. import com.goafanti.user.bo.StarListBo;
  34. import com.goafanti.user.bo.UserDownLoadBo;
  35. import com.goafanti.user.bo.UserListBo;
  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 AdminLocationMapper adminLocationMapper;
  50. @Autowired
  51. private PatentInfoMapper patentInfoMapper;
  52. @Autowired
  53. private CopyrightInfoMapper copyrightInfoMapper;
  54. @Autowired
  55. private TechProjectMapper techProjectMapper;
  56. @Autowired
  57. private OrgIntellectualPropertyMapper orgIntellectualPropertyMapper;
  58. @Override
  59. public User insertRegister(User user, String contacts, String unitName, String username) {
  60. userMapper.insert(user);
  61. if (null != user.getType() && UserType.ORGANIZATION.getCode().equals(user.getType())) {
  62. OrganizationIdentity organizationIdentity = new OrganizationIdentity();
  63. organizationIdentity.setUid(user.getId());
  64. organizationIdentity.setUnitName(StringUtils.isBlank(unitName) ? "" : unitName);
  65. organizationIdentity.setContacts(StringUtils.isBlank(contacts) ? "" : contacts);
  66. organizationIdentity.setId(UUID.randomUUID().toString());
  67. organizationIdentity.setIdentityType(0);
  68. organizationIdentity.setAuditStatus(0);
  69. organizationIdentity.setProcess(0);
  70. organizationIdentity.setWrongCount(0);
  71. organizationIdentity.setListed(0);
  72. organizationIdentity.setListedType(0);
  73. organizationIdentityMapper.insert(organizationIdentity);
  74. }
  75. if (null != user.getType() && UserType.PERSONAL.getCode().equals(user.getType())) {
  76. UserIdentity ui = new UserIdentity();
  77. ui.setId(UUID.randomUUID().toString());
  78. ui.setUid(user.getId());
  79. ui.setAuditStatus(0);
  80. ui.setProcess(0);
  81. ui.setWrongCount(0);
  82. ui.setUsername(StringUtils.isBlank(username) ? "" : username);
  83. userIdentityMapper.insert(ui);
  84. }
  85. return user;
  86. }
  87. @Override
  88. public User selectByMobieAndType(java.lang.String mobile, Integer type) {
  89. return userMapper.selectByMobieAndType(mobile, type);
  90. }
  91. @Override
  92. public User selectByPrimaryKey(String id) {
  93. return userMapper.selectByPrimaryKey(id);
  94. }
  95. @Override
  96. public int updateByPrimaryKeySelective(User u) {
  97. return userMapper.updateByPrimaryKeySelective(u);
  98. }
  99. @Override
  100. public User insert(User user) {
  101. userMapper.insert(user);
  102. return user;
  103. }
  104. @Override
  105. public int updateByPrimaryKey(User u) {
  106. return userMapper.updateByPrimaryKey(u);
  107. }
  108. @Override
  109. public UserPageHomeBo selectUserPageHomeBoByUserId(String uid) {
  110. UserPageHomeBo bo = userMapper.selectUserPageHomeBoByUserId(uid);
  111. bo.setPatentNum(patentInfoMapper.findPatentInfoNumByUid(uid));
  112. bo.setCopyrightNum(copyrightInfoMapper.findCopyrightInfoNumByUid(uid));
  113. bo.setTechProjectNum(techProjectMapper.findTechProjectNumByUid(uid));
  114. bo.setIntellectualPropertyNum(orgIntellectualPropertyMapper.findIntellectualPropertyNum(uid));
  115. return bo;
  116. }
  117. @Override
  118. public UserDownLoadBo selectUserDownLoadBoByUserId(String id) {
  119. return userMapper.selectUserDownLoadBoByUserId(id);
  120. }
  121. @SuppressWarnings("unchecked")
  122. @Override
  123. public Pagination<UserListBo> listUser(String username, String mobile, String email, String[] pDate, Integer number,
  124. String aftUsername, Integer auditStatus, Integer pageNo, Integer pageSize) throws ParseException {
  125. Map<String, Object> params = new HashMap<>();
  126. Date pStart = null;
  127. Date pEnd = null;
  128. if (null != pDate) {
  129. pStart = DateUtils.parseDate(pDate[0], AFTConstants.YYYYMMDD);
  130. if (pDate.length == 2) {
  131. pEnd = DateUtils.addDays(DateUtils.parseDate(pDate[1], AFTConstants.YYYYMMDD), 1);
  132. }
  133. }
  134. if (null != pStart) {
  135. params.put("pStart", pStart);
  136. }
  137. if (null != pEnd) {
  138. params.put("pEnd", pEnd);
  139. }
  140. if (!StringUtils.isBlank(mobile)) {
  141. params.put("mobile", mobile);
  142. }
  143. if (!StringUtils.isBlank(email)) {
  144. params.put("email", email);
  145. }
  146. if (null != number) {
  147. params.put("number", number);
  148. }
  149. if (!StringUtils.isBlank(username)) {
  150. params.put("username", username);
  151. }
  152. if (null != auditStatus) {
  153. params.put("auditStatus", auditStatus);
  154. }
  155. if (!StringUtils.isBlank(aftUsername)) {
  156. params.put("aftUsername", aftUsername);
  157. }
  158. if (pageNo == null || pageNo < 0) {
  159. pageNo = 1;
  160. }
  161. if (pageSize == null || pageSize < 0 || pageSize > 10) {
  162. pageSize = 10;
  163. }
  164. if (TokenManager.hasRole(AFTConstants.AREAADMIN) || TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  165. List<Integer> provinceList = adminLocationMapper
  166. .selectProvinceWhereCityIsNullByAdminId(TokenManager.getAdminId());
  167. List<Integer> cityList = adminLocationMapper.selectCityByAdminId(TokenManager.getAdminId());
  168. provinceList.addAll(cityList);
  169. if (null != provinceList && provinceList.size() > 0) {
  170. params.put("provinceList", provinceList);
  171. }
  172. if (null != cityList && cityList.size() > 0) {
  173. params.put("cityList", cityList);
  174. }
  175. return (Pagination<UserListBo>) findPage("findAreaManagerUserListByPage", "findAreaManagerUserCount",
  176. params, pageNo, pageSize);
  177. } else if (TokenManager.hasRole(AFTConstants.SUPERADMIN) || TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  178. return (Pagination<UserListBo>) findPage("findUserListByPage", "findUserCount", params, pageNo, pageSize);
  179. }
  180. return null;
  181. }
  182. @SuppressWarnings("unchecked")
  183. @Override
  184. public Pagination<OrgListBo> listOrg(String uid, String mobile, String email, String[] pDate, Integer number,
  185. String unitName, Integer auditStatus, Integer pageNo, Integer pageSize) throws ParseException {
  186. Map<String, Object> params = new HashMap<>();
  187. Date pStart = null;
  188. Date pEnd = null;
  189. if (null != pDate && pDate.length > 0) {
  190. pStart = StringUtils.isBlank(pDate[0]) ? null : DateUtils.parseDate(pDate[0], AFTConstants.YYYYMMDD);
  191. pEnd = StringUtils.isBlank(pDate[1]) ? null
  192. : DateUtils.addDays(DateUtils.parseDate(pDate[1], AFTConstants.YYYYMMDD), 1);
  193. pStart = DateUtils.parseDate(pDate[0], AFTConstants.YYYYMMDD);
  194. if (pDate.length == 2) {
  195. pEnd = DateUtils.addDays(DateUtils.parseDate(pDate[1], AFTConstants.YYYYMMDD), 1);
  196. }
  197. }
  198. if (null != pStart) {
  199. params.put("pStart", pStart);
  200. }
  201. if (null != pEnd) {
  202. params.put("pEnd", pEnd);
  203. }
  204. if (!StringUtils.isBlank(mobile)) {
  205. params.put("mobile", mobile);
  206. }
  207. if (!StringUtils.isBlank(uid)) {
  208. params.put("uid", uid);
  209. }
  210. if (!StringUtils.isBlank(email)) {
  211. params.put("email", email);
  212. }
  213. if (null != number) {
  214. params.put("number", number);
  215. }
  216. if (!StringUtils.isBlank(unitName)) {
  217. params.put("unitName", unitName);
  218. }
  219. if (null != auditStatus) {
  220. params.put("auditStatus", auditStatus);
  221. }
  222. if (pageNo == null || pageNo < 0) {
  223. pageNo = 1;
  224. }
  225. if (pageSize == null || pageSize < 0) {
  226. pageSize = 10;
  227. }
  228. if (TokenManager.hasRole(AFTConstants.SUPERADMIN) || TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  229. return (Pagination<OrgListBo>) findPage("findOrgListByPage", "findOrgCount", params, pageNo, pageSize);
  230. } else if (TokenManager.hasRole(AFTConstants.AREAADMIN) || TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  231. List<Integer> provinceList = adminLocationMapper
  232. .selectProvinceWhereCityIsNullByAdminId(TokenManager.getAdminId());
  233. List<Integer> cityList = adminLocationMapper.selectCityByAdminId(TokenManager.getAdminId());
  234. provinceList.addAll(cityList);
  235. if (null != provinceList && provinceList.size() > 0) {
  236. params.put("provinceList", provinceList);
  237. }
  238. if (null != cityList && cityList.size() > 0) {
  239. params.put("cityList", cityList);
  240. }
  241. return (Pagination<OrgListBo>) findPage("findAreaManagerOrgListByPage", "findAreaManagerOrgCount", params,
  242. pageNo, pageSize);
  243. }
  244. return null;
  245. }
  246. @SuppressWarnings("unchecked")
  247. @Override
  248. public Pagination<OrgListBo> selectUserByAid(Integer number, String mobile, Integer auditStatus, String auditName,
  249. String email, String aid, String startCreateTime, String endCreateTime, Integer type, Integer pageNo,
  250. Integer pageSize) {
  251. Map<String, Object> params = new HashMap<>();
  252. if (StringUtils.isNotBlank(startCreateTime)) {
  253. try {
  254. params.put("startCreateTime", DateUtils.parseDate(startCreateTime, AFTConstants.YYYYMMDD));
  255. } catch (ParseException e) {
  256. }
  257. }
  258. if (StringUtils.isNotBlank(endCreateTime)) {
  259. try {
  260. params.put("endCreateTime",
  261. DateUtils.addDays(DateUtils.parseDate(endCreateTime, AFTConstants.YYYYMMDD), 1));
  262. } catch (ParseException e) {
  263. }
  264. }
  265. if (null != number) {
  266. params.put("number", number);
  267. }
  268. if (StringUtils.isNotBlank(mobile)) {
  269. params.put("mobile", mobile);
  270. }
  271. if (null != auditStatus) {
  272. params.put("auditStatus", auditStatus);
  273. }
  274. if (StringUtils.isNotBlank(auditName)) {
  275. params.put("auditName", auditName);
  276. }
  277. if (StringUtils.isNotBlank(email)) {
  278. params.put("email", email);
  279. }
  280. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  281. params.put("aid", aid);
  282. }
  283. if (pageNo == null || pageNo < 0) {
  284. pageNo = 1;
  285. }
  286. if (pageSize == null || pageSize < 0 || pageSize > 10) {
  287. pageSize = 10;
  288. }
  289. if (UserType.PERSONAL.getCode().equals(type)) {
  290. return (Pagination<OrgListBo>) findPage("findUserByAidWithParamsListByPage", "findUserByAidWithParamsCount",
  291. params, pageNo, pageSize);
  292. } else if (UserType.ORGANIZATION.getCode().equals(type)) {
  293. return (Pagination<OrgListBo>) findPage("findOrgByAidWithParamsListByPage", "findOrgByAidWithParamsCount",
  294. params, pageNo, pageSize);
  295. }
  296. return null;
  297. }
  298. @Override
  299. public List<OrgUnitNames> selectDemandUnitNames() {
  300. String aid = TokenManager.getAdminId();
  301. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  302. return organizationIdentityMapper.selectManagerUnitNames(aid);
  303. } else {
  304. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  305. aid = null;
  306. }
  307. return organizationIdentityMapper.selectAllOrgIndentity(aid);
  308. }
  309. }
  310. @Override
  311. public List<UserNames> selectDemandUserNames() {
  312. String aid = TokenManager.getAdminId();
  313. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  314. return userIdentityMapper.selectManagerUserNames(aid);
  315. } else {
  316. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  317. aid = null;
  318. }
  319. return userIdentityMapper.selectAllUserNames(aid);
  320. }
  321. }
  322. @Override
  323. public Map<String, String> selectAchievementUserOwner(String name) {
  324. String aid = TokenManager.getAdminId();
  325. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  326. return disposeAchievementUserOwner(userIdentityMapper.selectManagerAchievementUserOwner(aid, name));
  327. } else {
  328. if (TokenManager.hasRole(AFTConstants.SUPERADMIN) || TokenManager.hasRole(AFTConstants.TECHBROKER)
  329. || TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  330. aid = null;
  331. }
  332. return disposeAchievementUserOwner(userIdentityMapper.selectAchievementUserOwner(aid, name));
  333. }
  334. }
  335. public List<OrgUnitNames> selectAchievementOrgOwner(String name) {
  336. String aid = TokenManager.getAdminId();
  337. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  338. return organizationIdentityMapper.selectManagerAchievementOrgOwner(aid, name);
  339. } else {
  340. if (TokenManager.hasRole(AFTConstants.SUPERADMIN) || TokenManager.hasRole(AFTConstants.TECHBROKER)
  341. || TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  342. aid = null;
  343. }
  344. return organizationIdentityMapper.selectAchievementOrgOwner(aid, name);
  345. }
  346. }
  347. private Map<String, String> disposeAchievementUserOwner(List<UserNames> list) {
  348. Map<String, String> map = new HashMap<>();
  349. if (null != list && list.size() > 0) {
  350. for (UserNames u : list) {
  351. map.put(u.getUid(), u.getUsername() + " " + u.getMobile());
  352. }
  353. }
  354. return map;
  355. }
  356. @Override
  357. public String findUserNameByNameAndMobile(String name, String mobile) {
  358. return userMapper.findUserByNameAndMobile(name, mobile);
  359. }
  360. @Override
  361. public String findOrgNameByNameAndMobile(String name, String mobile) {
  362. return userMapper.findOrgByNameAndMobile(name, mobile);
  363. }
  364. @Override
  365. public UserPartnerDetailBo findUserPartnerDetail(String uid) {
  366. return userMapper.findUserPartnerDetail(uid, TokenManager.getUserId());
  367. }
  368. @Override
  369. public OrgPartnerDetailBo findOrgPartnerDetail(String uid) {
  370. return userMapper.findOrgPartnerDetail(uid, TokenManager.getUserId());
  371. }
  372. @SuppressWarnings("unchecked")
  373. @Override
  374. public Pagination<StarListBo> listStar(Integer number, String engagedField, String username,
  375. String professionalTitle, String workUnit, Integer pNo, Integer pSize) {
  376. Map<String, Object> params = new HashMap<>();
  377. if (null != number) {
  378. params.put("number", number);
  379. }
  380. if (StringUtils.isNotBlank(engagedField)) {
  381. params.put("engagedField", engagedField);
  382. }
  383. if (StringUtils.isNotBlank(username)) {
  384. params.put("username", username);
  385. }
  386. if (StringUtils.isNotBlank(professionalTitle)) {
  387. params.put("professionalTitle", professionalTitle);
  388. }
  389. if (StringUtils.isNotBlank(workUnit)) {
  390. params.put("workUnit", workUnit);
  391. }
  392. if (pNo == null || pNo < 0) {
  393. pNo = 1;
  394. }
  395. if (pSize == null || pSize < 0 || pSize > 10) {
  396. pSize = 10;
  397. }
  398. return (Pagination<StarListBo>) findPage("findStarListByPage", "findStarCount", params, pNo, pSize);
  399. }
  400. @SuppressWarnings("unchecked")
  401. @Override
  402. public Pagination<StarAndExpertListBo> listStarAndExpert(Integer number, String engagedField, String username,
  403. String professionalTitle, String workUnit, Integer pNo, Integer pSize) {
  404. Map<String, Object> params = new HashMap<>();
  405. if (null != number) {
  406. params.put("number", number);
  407. }
  408. if (StringUtils.isNotBlank(engagedField)) {
  409. params.put("engagedField", engagedField);
  410. }
  411. if (StringUtils.isNotBlank(username)) {
  412. params.put("username", username);
  413. }
  414. if (StringUtils.isNotBlank(professionalTitle)) {
  415. params.put("professionalTitle", professionalTitle);
  416. }
  417. if (StringUtils.isNotBlank(workUnit)) {
  418. params.put("workUnit", workUnit);
  419. }
  420. if (pNo == null || pNo < 0) {
  421. pNo = 1;
  422. }
  423. if (pSize == null || pSize < 0 || pSize > 10) {
  424. pSize = 10;
  425. }
  426. return (Pagination<StarAndExpertListBo>) findPage("findStarAndExpertListByPage", "findStarAndExpertCount",
  427. params, pNo, pSize);
  428. }
  429. @Override
  430. @Cacheable(value = "UserNumberCache", key = "'UserNumberCache:UID:'+#userId")
  431. public String selectNumberByPrimaryKey(String userId) {
  432. return String.valueOf(userMapper.selectNumberByPrimaryKey(userId));
  433. }
  434. }