DemandServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. package com.goafanti.demand.service.impl;
  2. import java.text.ParseException;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.UUID;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import com.goafanti.common.constant.AFTConstants;
  13. import com.goafanti.common.dao.DemandMapper;
  14. import com.goafanti.common.dao.NoticeMapper;
  15. import com.goafanti.common.dao.UserMapper;
  16. import com.goafanti.common.dao.UserRoleMapper;
  17. import com.goafanti.common.enums.DeleteStatus;
  18. import com.goafanti.common.enums.DemandAuditStatus;
  19. import com.goafanti.common.enums.DemandReleaseStatus;
  20. import com.goafanti.common.enums.DemandStatus;
  21. import com.goafanti.common.enums.NoticeReadStatus;
  22. import com.goafanti.common.enums.NoticeStatus;
  23. import com.goafanti.common.enums.UserType;
  24. import com.goafanti.common.model.Demand;
  25. import com.goafanti.common.model.Notice;
  26. import com.goafanti.common.model.User;
  27. import com.goafanti.common.utils.DateUtils;
  28. import com.goafanti.core.mybatis.BaseMybatisDao;
  29. import com.goafanti.core.mybatis.page.Pagination;
  30. import com.goafanti.core.shiro.token.TokenManager;
  31. import com.goafanti.demand.bo.DemandListBo;
  32. import com.goafanti.demand.bo.DemandManageDetailBo;
  33. import com.goafanti.demand.bo.DemandManageListBo;
  34. import com.goafanti.demand.service.DemandService;
  35. @Service
  36. public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements DemandService {
  37. @Autowired
  38. private DemandMapper demandMapper;
  39. @Autowired
  40. private UserMapper userMapper;
  41. @Autowired
  42. private UserRoleMapper userRoleMapper;
  43. @Autowired
  44. private NoticeMapper noticeMapper;
  45. @SuppressWarnings("unchecked")
  46. @Override
  47. public Pagination<DemandManageListBo> selectUserDemandManageList(Integer auditStatus, String province,
  48. Integer serialNumber, String name, String keyword, Integer infoSources, Integer demandType,
  49. String validityPeriodStartDate, String validityPeriodEndDate, String username, Integer status,
  50. Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate, Integer pNo, Integer pSize) {
  51. Map<String, Object> params = new HashMap<>();
  52. Date vStart = null;
  53. Date vEnd = null;
  54. Date rStart = null;
  55. Date rEnd = null;
  56. if (!StringUtils.isBlank(validityPeriodStartDate)) {
  57. try {
  58. vStart = DateUtils.parseDate(validityPeriodStartDate, AFTConstants.YYYYMMDD);
  59. } catch (ParseException e) {
  60. }
  61. }
  62. if (!StringUtils.isBlank(validityPeriodEndDate)) {
  63. try {
  64. vEnd = DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD);
  65. } catch (ParseException e) {
  66. }
  67. }
  68. if (!StringUtils.isBlank(releaseDateStartDate)) {
  69. try {
  70. rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
  71. } catch (ParseException e) {
  72. }
  73. }
  74. if (!StringUtils.isBlank(releaseDateEndDate)) {
  75. try {
  76. rEnd = DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD);
  77. } catch (ParseException e) {
  78. }
  79. }
  80. if (null != vStart) {
  81. params.put("vStart", vStart);
  82. }
  83. if (null != vEnd) {
  84. params.put("vEnd", vEnd);
  85. }
  86. if (null != rStart) {
  87. params.put("rStart", rStart);
  88. }
  89. if (null != rEnd) {
  90. params.put("rEnd", rEnd);
  91. }
  92. if (null != auditStatus) {
  93. params.put("auditStatus", auditStatus);
  94. }
  95. if (!StringUtils.isBlank(province)) {
  96. params.put("province", province);
  97. }
  98. if (null != serialNumber) {
  99. params.put("serialNumber", serialNumber);
  100. }
  101. if (!StringUtils.isBlank(name)) {
  102. params.put("name", name);
  103. }
  104. if (!StringUtils.isBlank(keyword)) {
  105. params.put("keyword", keyword);
  106. }
  107. if (!StringUtils.isBlank(username)) {
  108. params.put("username", username);
  109. }
  110. if (null != infoSources) {
  111. params.put("infoSources", infoSources);
  112. }
  113. if (null != demandType) {
  114. params.put("demandType", demandType);
  115. }
  116. if (null != status) {
  117. params.put("status", status);
  118. }
  119. if (null != releaseStatus) {
  120. params.put("releaseStatus", releaseStatus);
  121. }
  122. if (pNo == null || pNo < 0) {
  123. pNo = 1;
  124. }
  125. if (pSize == null || pSize < 0) {
  126. pSize = 10;
  127. }
  128. if (TokenManager.hasRole(AFTConstants.SALESMANAGERADMIN) || TokenManager.hasRole(AFTConstants.SALESMANADMIN)) {
  129. params.put("principal", TokenManager.getAdminId());
  130. }
  131. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  132. params.put("mid", TokenManager.getAdminId());
  133. }
  134. if (TokenManager.hasRole(AFTConstants.TECHBROKER)) {
  135. params.put("techBroker", TokenManager.getAdminId());
  136. }
  137. return (Pagination<DemandManageListBo>) findPage("findManageUserDemandListByPage", "findManageUserDemandCount",
  138. params, pNo, pSize);
  139. }
  140. @SuppressWarnings("unchecked")
  141. @Override
  142. public Pagination<DemandManageListBo> selectOrgDemandManageList(Integer auditStatus, String province,
  143. Integer serialNumber, String name, String keyword, Integer infoSources, Integer demandType,
  144. String validityPeriodStartDate, String validityPeriodEndDate, String username, Integer status,
  145. Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate, Integer pNo, Integer pSize) {
  146. Map<String, Object> params = new HashMap<>();
  147. Date vStart = null;
  148. Date vEnd = null;
  149. Date rStart = null;
  150. Date rEnd = null;
  151. if (!StringUtils.isBlank(validityPeriodStartDate)) {
  152. try {
  153. vStart = DateUtils.parseDate(validityPeriodStartDate, AFTConstants.YYYYMMDD);
  154. } catch (ParseException e) {
  155. }
  156. }
  157. if (!StringUtils.isBlank(validityPeriodEndDate)) {
  158. try {
  159. vEnd = DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD);
  160. } catch (ParseException e) {
  161. }
  162. }
  163. if (!StringUtils.isBlank(releaseDateStartDate)) {
  164. try {
  165. rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
  166. } catch (ParseException e) {
  167. }
  168. }
  169. if (!StringUtils.isBlank(releaseDateEndDate)) {
  170. try {
  171. rEnd = DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD);
  172. } catch (ParseException e) {
  173. }
  174. }
  175. if (null != vStart) {
  176. params.put("vStart", vStart);
  177. }
  178. if (null != vEnd) {
  179. params.put("vEnd", vEnd);
  180. }
  181. if (null != rStart) {
  182. params.put("rStart", rStart);
  183. }
  184. if (null != rEnd) {
  185. params.put("rEnd", rEnd);
  186. }
  187. if (null != auditStatus) {
  188. params.put("auditStatus", auditStatus);
  189. }
  190. if (!StringUtils.isBlank(province)) {
  191. params.put("province", province);
  192. }
  193. if (null != serialNumber) {
  194. params.put("serialNumber", serialNumber);
  195. }
  196. if (!StringUtils.isBlank(name)) {
  197. params.put("name", name);
  198. }
  199. if (!StringUtils.isBlank(keyword)) {
  200. params.put("keyword", keyword);
  201. }
  202. if (!StringUtils.isBlank(username)) {
  203. params.put("username", username);
  204. }
  205. if (null != infoSources) {
  206. params.put("infoSources", infoSources);
  207. }
  208. if (null != demandType) {
  209. params.put("demandType", demandType);
  210. }
  211. if (null != status) {
  212. params.put("status", status);
  213. }
  214. if (null != releaseStatus) {
  215. params.put("releaseStatus", releaseStatus);
  216. }
  217. if (pNo == null || pNo < 0) {
  218. pNo = 1;
  219. }
  220. if (pSize == null || pSize < 0) {
  221. pSize = 10;
  222. }
  223. if (TokenManager.hasRole(AFTConstants.SALESMANAGERADMIN) || TokenManager.hasRole(AFTConstants.SALESMANADMIN)) {
  224. params.put("principal", TokenManager.getAdminId());
  225. }
  226. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  227. params.put("mid", TokenManager.getAdminId());
  228. }
  229. if (TokenManager.hasRole(AFTConstants.TECHBROKER)) {
  230. params.put("techBroker", TokenManager.getAdminId());
  231. }
  232. return (Pagination<DemandManageListBo>) findPage("findManageOrgDemandListByPage", "findManageOrgDemandCount",
  233. params, pNo, pSize);
  234. }
  235. @Override
  236. public void saveUserDemand(Demand d, String validityPeriodFormattedDate) {
  237. Date validityPeriod = null;
  238. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  239. try {
  240. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  241. } catch (ParseException e) {
  242. }
  243. }
  244. d.setValidityPeriod(validityPeriod);
  245. d.setId(UUID.randomUUID().toString());
  246. d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  247. Calendar now = Calendar.getInstance();
  248. now.set(Calendar.MILLISECOND, 0);
  249. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  250. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  251. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  252. d.setPrincipalId(TokenManager.getAdminId());
  253. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  254. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  255. createAuditorNotice(d);
  256. }
  257. d.setCreateTime(now.getTime());
  258. demandMapper.insert(d);
  259. }
  260. @Override
  261. public int updateUserDemand(Demand d, String validityPeriodFormattedDate) {
  262. Date validityPeriod = null;
  263. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  264. try {
  265. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  266. } catch (ParseException e) {
  267. }
  268. }
  269. d.setValidityPeriod(validityPeriod);
  270. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  271. d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
  272. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  273. d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
  274. createAuditorNotice(d);
  275. }
  276. return demandMapper.updateByPrimaryKeySelective(d);
  277. }
  278. @Override
  279. public DemandManageDetailBo selectUserDemandDetail(String id) {
  280. return demandMapper.selectUserDemandDetail(id);
  281. }
  282. @Override
  283. public int deleteByPrimaryKey(List<String> id) {
  284. return demandMapper.batchDeleteByPrimaryKey(id);
  285. }
  286. @Override
  287. public DemandManageDetailBo selectOrgDemandDetail(String id) {
  288. return demandMapper.selectOrgDemandDetail(id);
  289. }
  290. @Override
  291. public Demand selectByPrimaryKey(String id) {
  292. return demandMapper.selectByPrimaryKey(id);
  293. }
  294. @SuppressWarnings("unchecked")
  295. @Override
  296. public Pagination<DemandListBo> listDemand(Integer serialNumber, String name, String keyword, Integer demandType,
  297. String validityPeriodStartDate, String validityPeriodEndDate, Integer status, Integer releaseStatus,
  298. String releaseDateStartDate, String releaseDateEndDate, Integer pNo, Integer pSize) {
  299. Map<String, Object> params = new HashMap<>();
  300. Date vStart = null;
  301. Date vEnd = null;
  302. Date rStart = null;
  303. Date rEnd = null;
  304. params.put("employerId", TokenManager.getUserId());
  305. if (!StringUtils.isBlank(validityPeriodStartDate)) {
  306. try {
  307. vStart = DateUtils.parseDate(validityPeriodStartDate, AFTConstants.YYYYMMDD);
  308. } catch (ParseException e) {
  309. }
  310. }
  311. if (!StringUtils.isBlank(validityPeriodEndDate)) {
  312. try {
  313. vEnd = DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD);
  314. } catch (ParseException e) {
  315. }
  316. }
  317. if (!StringUtils.isBlank(releaseDateStartDate)) {
  318. try {
  319. rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
  320. } catch (ParseException e) {
  321. }
  322. }
  323. if (!StringUtils.isBlank(releaseDateEndDate)) {
  324. try {
  325. rEnd = DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD);
  326. } catch (ParseException e) {
  327. }
  328. }
  329. if (null != vStart) {
  330. params.put("vStart", vStart);
  331. }
  332. if (null != vEnd) {
  333. params.put("vEnd", vEnd);
  334. }
  335. if (null != rStart) {
  336. params.put("rStart", rStart);
  337. }
  338. if (null != rEnd) {
  339. params.put("rEnd", rEnd);
  340. }
  341. if (null != serialNumber) {
  342. params.put("serialNumber", serialNumber);
  343. }
  344. if (!StringUtils.isBlank(name)) {
  345. params.put("name", name);
  346. }
  347. if (!StringUtils.isBlank(keyword)) {
  348. params.put("keyword", keyword);
  349. }
  350. if (null != demandType) {
  351. params.put("demandType", demandType);
  352. }
  353. if (null != status) {
  354. params.put("status", status);
  355. }
  356. if (null != releaseStatus) {
  357. params.put("releaseStatus", releaseStatus);
  358. }
  359. if (pNo == null || pNo < 0) {
  360. pNo = 1;
  361. }
  362. if (pSize == null || pSize < 0) {
  363. pSize = 10;
  364. }
  365. return (Pagination<DemandListBo>) findPage("findDemandListByPage", "findDemandCount", params, pNo, pSize);
  366. }
  367. @Override
  368. public int updateReleaseStatus(Demand d) {
  369. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  370. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  371. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  372. demandMapper.updateReleaseDate(d.getId());
  373. return demandMapper.updateByPrimaryKeySelective(d);
  374. }
  375. @Override
  376. public int updateAuditDemand(Demand d, String techBroderId, Integer auditStatus) {
  377. d.setAuditStatus(auditStatus);
  378. if (DemandAuditStatus.AUDITED.getCode().equals(auditStatus)) {
  379. Calendar now = Calendar.getInstance();
  380. now.set(Calendar.MILLISECOND, 0);
  381. d.setReleaseDate(now.getTime());
  382. } else {
  383. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  384. }
  385. return demandMapper.updateByPrimaryKeySelective(d);
  386. }
  387. @Override
  388. public void saveDemand(Demand d, String validityPeriodFormattedDate) {
  389. Date validityPeriod = null;
  390. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  391. try {
  392. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  393. } catch (ParseException e) {
  394. }
  395. }
  396. d.setValidityPeriod(validityPeriod);
  397. d.setId(UUID.randomUUID().toString());
  398. d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  399. Calendar now = Calendar.getInstance();
  400. now.set(Calendar.MILLISECOND, 0);
  401. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  402. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  403. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  404. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  405. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  406. d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
  407. createAuditorNotice(d);
  408. }
  409. d.setCreateTime(now.getTime());
  410. demandMapper.insert(d);
  411. }
  412. // 给所有审核员发送审核通知
  413. private void createAuditorNotice(Demand d) {
  414. List<String> ids = userRoleMapper.listAuditor();
  415. if (null != ids && ids.size() > 0) {
  416. for (String s : ids) {
  417. Notice n = new Notice();
  418. Calendar now = Calendar.getInstance();
  419. now.set(Calendar.MILLISECOND, 0);
  420. n.setId(UUID.randomUUID().toString());
  421. n.setCreateTime(now.getTime());
  422. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  423. User u = userMapper.selectByPrimaryKey(d.getEmployerId());
  424. n.setRid(d.getId());
  425. n.setUid(d.getEmployerId());
  426. n.setAid(s);
  427. if (null != u) {
  428. n.setPid(u.getAid());
  429. }
  430. if (UserType.PERSONAL.getCode().equals(d.getDataCategory())) {
  431. n.setContent(NoticeStatus.PERSONALDEMAND.getDesc() + " " + DemandAuditStatus.SUBMIT.getDesc());
  432. n.setNoticeType(NoticeStatus.PERSONALDEMAND.getCode());
  433. } else if (UserType.ORGANIZATION.getCode().equals(d.getDataCategory())) {
  434. n.setContent(NoticeStatus.ORGANIZATIONDEMAND.getDesc() + " " + DemandAuditStatus.SUBMIT.getDesc());
  435. n.setNoticeType(NoticeStatus.ORGANIZATIONDEMAND.getCode());
  436. }
  437. noticeMapper.insert(n);
  438. }
  439. }
  440. }
  441. }