DemandServiceImpl.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. package com.goafanti.demand.service.impl;
  2. import java.math.BigDecimal;
  3. import java.text.ParseException;
  4. import java.util.ArrayList;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.UUID;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.BeanUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import com.goafanti.achievement.bo.AchievementDemandListBo;
  16. import com.goafanti.common.constant.AFTConstants;
  17. import com.goafanti.common.dao.AchievementDemandCountMapper;
  18. import com.goafanti.common.dao.AchievementDemandMapper;
  19. import com.goafanti.common.dao.AchievementKeywordMapper;
  20. import com.goafanti.common.dao.DemandKeywordMapper;
  21. import com.goafanti.common.dao.DemandMapper;
  22. import com.goafanti.common.dao.NoticeMapper;
  23. import com.goafanti.common.dao.OrganizationIdentityMapper;
  24. import com.goafanti.common.dao.UserIdentityMapper;
  25. import com.goafanti.common.dao.UserMapper;
  26. import com.goafanti.common.dao.UserRoleMapper;
  27. import com.goafanti.common.enums.DeleteStatus;
  28. import com.goafanti.common.enums.DemandAuditStatus;
  29. import com.goafanti.common.enums.DemandInfoSourceStatus;
  30. import com.goafanti.common.enums.DemandPortalSearchSignType;
  31. import com.goafanti.common.enums.DemandReleaseStatus;
  32. import com.goafanti.common.enums.DemandStatus;
  33. import com.goafanti.common.enums.DemandSwitchSign;
  34. import com.goafanti.common.enums.NoticeReadStatus;
  35. import com.goafanti.common.enums.NoticeStatus;
  36. import com.goafanti.common.enums.UserType;
  37. import com.goafanti.common.model.AchievementDemand;
  38. import com.goafanti.common.model.AchievementDemandCount;
  39. import com.goafanti.common.model.Demand;
  40. import com.goafanti.common.model.DemandKeyword;
  41. import com.goafanti.common.model.Notice;
  42. import com.goafanti.common.model.OrganizationIdentity;
  43. import com.goafanti.common.model.User;
  44. import com.goafanti.common.model.UserIdentity;
  45. import com.goafanti.common.utils.DateUtils;
  46. import com.goafanti.core.mybatis.BaseMybatisDao;
  47. import com.goafanti.core.mybatis.page.Pagination;
  48. import com.goafanti.core.shiro.token.TokenManager;
  49. import com.goafanti.demand.bo.DemandImportBo;
  50. import com.goafanti.demand.bo.DemandListBo;
  51. import com.goafanti.demand.bo.DemandManageDetailBo;
  52. import com.goafanti.demand.bo.DemandManageListBo;
  53. import com.goafanti.demand.bo.DemandPartnerListBo;
  54. import com.goafanti.demand.service.DemandService;
  55. import com.goafanti.portal.bo.DemandPortalDetailBo;
  56. import com.goafanti.portal.bo.DemandPortalSimilarListBo;
  57. import com.goafanti.portal.bo.DemandSearchDetailBo;
  58. import com.goafanti.portal.bo.DemandSearchListBo;
  59. @Service
  60. public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements DemandService {
  61. @Autowired
  62. private DemandMapper demandMapper;
  63. @Autowired
  64. private UserMapper userMapper;
  65. @Autowired
  66. private UserRoleMapper userRoleMapper;
  67. @Autowired
  68. private NoticeMapper noticeMapper;
  69. @Autowired
  70. private DemandKeywordMapper demandKeywordMapper;
  71. @Autowired
  72. private AchievementDemandMapper achievementDemandMapper;
  73. @Autowired
  74. private AchievementKeywordMapper achievementKeywordMapper;
  75. @Autowired
  76. private AchievementDemandCountMapper achievementDemandCountMapper;
  77. @Autowired
  78. private UserIdentityMapper userIdentityMapper;
  79. @Autowired
  80. private OrganizationIdentityMapper organizationIdentityMapper;
  81. @SuppressWarnings("unchecked")
  82. @Override
  83. public Pagination<DemandManageListBo> selectUserDemandManageList(String employerName, Integer auditStatus,
  84. Integer province, Integer serialNumber, String name, String keyword, Integer infoSources,
  85. Integer demandType, String validityPeriodStartDate, String validityPeriodEndDate, String username,
  86. Integer status, Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate, Integer pNo,
  87. Integer pSize) {
  88. Map<String, Object> params = disposeParams(auditStatus, province, serialNumber, name, keyword, infoSources,
  89. demandType, validityPeriodStartDate, validityPeriodEndDate, username, status, releaseStatus,
  90. releaseDateStartDate, releaseDateEndDate);
  91. if (pNo == null || pNo < 0) {
  92. pNo = 1;
  93. }
  94. if (pSize == null || pSize < 0 || pSize > 10) {
  95. pSize = 10;
  96. }
  97. /*
  98. * if (TokenManager.hasRole(AFTConstants.SALESMANAGERADMIN) ||
  99. * TokenManager.hasRole(AFTConstants.SALESMANADMIN)) {
  100. * params.put("principal", TokenManager.getAdminId()); }
  101. *
  102. * if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  103. * params.put("mid", TokenManager.getAdminId()); }
  104. *
  105. * if (TokenManager.hasRole(AFTConstants.TECHBROKER)) {
  106. * params.put("techBroker", TokenManager.getAdminId()); }
  107. */
  108. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  109. params.put("adminId", TokenManager.getAdminId());
  110. }
  111. if (StringUtils.isNotBlank(employerName)) {
  112. params.put("employerName", employerName);
  113. }
  114. if (StringUtils.isNotBlank(username)) {
  115. params.put("username", username);
  116. }
  117. return (Pagination<DemandManageListBo>) findPage("findManageUserDemandListByPage", "findManageUserDemandCount",
  118. params, pNo, pSize);
  119. }
  120. @SuppressWarnings("unchecked")
  121. @Override
  122. public Pagination<DemandManageListBo> selectOrgDemandManageList(String employerName, Integer auditStatus,
  123. Integer province, Integer serialNumber, String name, String keyword, Integer infoSources,
  124. Integer demandType, String validityPeriodStartDate, String validityPeriodEndDate, String username,
  125. Integer status, Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate, Integer pNo,
  126. Integer pSize) {
  127. Map<String, Object> params = disposeParams(auditStatus, province, serialNumber, name, keyword, infoSources,
  128. demandType, validityPeriodStartDate, validityPeriodEndDate, username, status, releaseStatus,
  129. releaseDateStartDate, releaseDateEndDate);
  130. if (pNo == null || pNo < 0) {
  131. pNo = 1;
  132. }
  133. if (pSize == null || pSize < 0 || pSize > 10) {
  134. pSize = 10;
  135. }
  136. /*if (TokenManager.hasRole(AFTConstants.SALESMANAGERADMIN) || TokenManager.hasRole(AFTConstants.SALESMANADMIN)) {
  137. params.put("principal", TokenManager.getAdminId());
  138. }
  139. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  140. params.put("mid", TokenManager.getAdminId());
  141. }
  142. if (TokenManager.hasRole(AFTConstants.TECHBROKER)) {
  143. params.put("techBroker", TokenManager.getAdminId());
  144. }*/
  145. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  146. params.put("adminId", TokenManager.getAdminId());
  147. }
  148. if (StringUtils.isNotBlank(employerName)) {
  149. params.put("employerName", employerName);
  150. }
  151. if (StringUtils.isNotBlank(username)) {
  152. params.put("unitName", username);
  153. }
  154. return (Pagination<DemandManageListBo>) findPage("findManageOrgDemandListByPage", "findManageOrgDemandCount",
  155. params, pNo, pSize);
  156. }
  157. @Override
  158. public void saveUserDemand(Demand d, String validityPeriodFormattedDate, String[] keywords) {
  159. Date validityPeriod = null;
  160. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  161. try {
  162. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  163. } catch (ParseException e) {
  164. }
  165. }
  166. d.setValidityPeriod(validityPeriod);
  167. d.setId(UUID.randomUUID().toString());
  168. d.setTechBrokerId(TokenManager.getAdminId());
  169. d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  170. Calendar now = Calendar.getInstance();
  171. now.set(Calendar.MILLISECOND, 0);
  172. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  173. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  174. d.setPrincipalId(TokenManager.getAdminId());
  175. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  176. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  177. createAuditorNotice(d);
  178. } else {
  179. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  180. }
  181. d.setCreateTime(now.getTime());
  182. demandMapper.insert(d);
  183. disposeDemandKeyword(keywords, d, false);
  184. }
  185. @Override
  186. public int updateUserDemand(Demand d, String validityPeriodFormattedDate, String[] keywords, Integer switchSign) {
  187. Date validityPeriod = null;
  188. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  189. try {
  190. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  191. } catch (ParseException e) {
  192. }
  193. }
  194. d.setValidityPeriod(validityPeriod);
  195. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  196. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  197. createAuditorNotice(d);
  198. }
  199. disposeDemandKeyword(keywords, d, true);
  200. demandMapper.updateByPrimaryKeySelective(d);
  201. if (null != switchSign && DemandSwitchSign.CLOSE.getCode().equals(switchSign)) {
  202. demandMapper.updateEmployerId(d.getId());
  203. }
  204. return 1;
  205. }
  206. @Override
  207. public DemandManageDetailBo selectUserDemandDetail(String id) {
  208. return demandMapper.selectUserDemandDetail(id);
  209. }
  210. @Override
  211. public int deleteByPrimaryKey(List<String> id) {
  212. demandKeywordMapper.batchDeleteByDemandIds(id);
  213. achievementDemandMapper.batchDeleteByDemandIds(id);
  214. for (String s : id) {
  215. Demand d = demandMapper.selectByPrimaryKey(s);
  216. if (null != d && DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())
  217. && StringUtils.isNotBlank(d.getEmployerId())) {
  218. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(d.getEmployerId());
  219. if (null != adc) {
  220. adc.setDemandCount(adc.getDemandCount() - 1);
  221. if (adc.getDemandCount() < 0) {
  222. adc.setDemandCount(0);
  223. }
  224. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  225. }
  226. }
  227. }
  228. return demandMapper.batchDeleteByPrimaryKey(id);
  229. }
  230. @Override
  231. public DemandManageDetailBo selectOrgDemandDetail(String id) {
  232. return demandMapper.selectOrgDemandDetail(id);
  233. }
  234. @Override
  235. public Demand selectByPrimaryKey(String id) {
  236. return demandMapper.selectByPrimaryKey(id);
  237. }
  238. @SuppressWarnings("unchecked")
  239. @Override
  240. public Pagination<DemandListBo> listDemand(Integer auditStatus, Integer serialNumber, String name, String keyword,
  241. Integer demandType, String validityPeriodStartDate, String validityPeriodEndDate, Integer status,
  242. Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate, Integer pNo, Integer pSize) {
  243. Map<String, Object> params = disposeParams(auditStatus, null, serialNumber, name, keyword, null, demandType,
  244. validityPeriodStartDate, validityPeriodEndDate, null, status, releaseStatus, releaseDateStartDate,
  245. releaseDateEndDate);
  246. params.put("employerId", TokenManager.getUserId());
  247. if (pNo == null || pNo < 0) {
  248. pNo = 1;
  249. }
  250. if (pSize == null || pSize < 0) {
  251. pSize = 10;
  252. }
  253. return (Pagination<DemandListBo>) findPage("findDemandListByPage", "findDemandCount", params, pNo, pSize);
  254. }
  255. @Override
  256. public int updateReleaseStatus(Demand d) {
  257. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  258. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  259. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  260. demandMapper.updateByPrimaryKeySelective(d);
  261. demandKeywordMapper.batchDeleteByDemandId(d.getId());
  262. achievementDemandMapper.deleteByDemandId(d.getId());
  263. if (StringUtils.isNotBlank(d.getEmployerId())) {
  264. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(d.getEmployerId());
  265. if (null != adc) {
  266. adc.setDemandCount(adc.getDemandCount() - 1);
  267. if (adc.getDemandCount() < 0) {
  268. adc.setDemandCount(0);
  269. }
  270. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  271. }
  272. }
  273. return demandMapper.updateReleaseDate(d.getId());
  274. }
  275. @Override
  276. public int updateAuditDemand(Demand d, String techBroderId, Integer auditStatus) {
  277. d.setAuditStatus(auditStatus);
  278. if (DemandAuditStatus.AUDITED.getCode().equals(auditStatus)) {
  279. Calendar now = Calendar.getInstance();
  280. now.set(Calendar.MILLISECOND, 0);
  281. d.setReleaseDate(now.getTime());
  282. d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
  283. d.setTechBrokerId(techBroderId);
  284. if (StringUtils.isNotBlank(d.getKeyword())) {
  285. String[] keywords = d.getKeyword().trim().split(",|,");
  286. disposeDemandKeyword(keywords, d, false);
  287. }
  288. String employerId = d.getEmployerId();
  289. if (StringUtils.isNotBlank(employerId)) {
  290. if (UserType.PERSONAL.getCode().equals(d.getDataCategory())) {
  291. UserIdentity ui = userIdentityMapper.selectUserIdentityByUserId(employerId);
  292. if (null != ui) {
  293. d.setEmployerName(ui.getUsername());
  294. }
  295. } else if (UserType.ORGANIZATION.getCode().equals(d.getDataCategory())) {
  296. OrganizationIdentity oi = organizationIdentityMapper.selectOrgIdentityByUserId(employerId);
  297. if (null != oi) {
  298. d.setEmployerName(oi.getUnitName());
  299. }
  300. }
  301. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(employerId);
  302. if (null == adc) {
  303. AchievementDemandCount achievementDemandCount = new AchievementDemandCount();
  304. achievementDemandCount.setId(UUID.randomUUID().toString());
  305. achievementDemandCount.setUid(employerId);
  306. achievementDemandCount.setDemandCount(AFTConstants.ACHIEVEMENT_DEMAND_FIRST_COUNT);
  307. achievementDemandCount.setAchievementCount(AFTConstants.ACHIEVEMENT_DEMAND_INIT_COUNT);
  308. achievementDemandCountMapper.insert(achievementDemandCount);
  309. } else {
  310. adc.setDemandCount(adc.getDemandCount() + 1);
  311. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  312. }
  313. }
  314. } else {
  315. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  316. }
  317. createTechBorkerNotice(d);
  318. return demandMapper.updateByPrimaryKeySelective(d);
  319. }
  320. @Override
  321. public void saveDemand(Demand d, String validityPeriodFormattedDate, String[] keywords) {
  322. Date validityPeriod = null;
  323. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  324. try {
  325. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  326. } catch (ParseException e) {
  327. }
  328. }
  329. d.setValidityPeriod(validityPeriod);
  330. d.setId(UUID.randomUUID().toString());
  331. d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  332. Calendar now = Calendar.getInstance();
  333. now.set(Calendar.MILLISECOND, 0);
  334. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  335. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  336. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  337. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  338. createAuditorNotice(d);
  339. } else {
  340. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  341. }
  342. d.setCreateTime(now.getTime());
  343. demandMapper.insert(d);
  344. disposeDemandKeyword(keywords, d, false);
  345. }
  346. @Override
  347. public List<AchievementDemandListBo> selectAchievementDemandListByDemandId(String id) {
  348. return achievementDemandMapper.selectAchievementDemandListByDemandId(id);
  349. }
  350. @Override
  351. public void insertImport(List<DemandImportBo> data) {
  352. if (null == data || data.isEmpty()) {
  353. return;
  354. }
  355. Demand d = null;
  356. DemandKeyword dk = null;
  357. List<Demand> demandList = new ArrayList<>();
  358. List<DemandKeyword> demandKeywordList = new ArrayList<>();
  359. Calendar now = Calendar.getInstance();
  360. now.set(Calendar.MILLISECOND, 0);
  361. for (DemandImportBo bo : data) {
  362. d = new Demand();
  363. BeanUtils.copyProperties(bo, d);
  364. d.setId(UUID.randomUUID().toString());
  365. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  366. d.setCreateTime(now.getTime());
  367. d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  368. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  369. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  370. d.setInfoSources(DemandInfoSourceStatus.IMPORT.getCode());
  371. List<String> keywordsList = bo.getKeywords();
  372. if (null != keywordsList && keywordsList.size() > 0) {
  373. for (String s : keywordsList) {
  374. if (!StringUtils.isBlank(s)) {
  375. dk = new DemandKeyword();
  376. dk.setDemandId(d.getId());
  377. dk.setKeyword(s.trim());
  378. dk.setId(UUID.randomUUID().toString());
  379. demandKeywordList.add(dk);
  380. }
  381. }
  382. }
  383. demandList.add(d);
  384. }
  385. demandMapper.insertBatch(demandList);
  386. demandKeywordMapper.insertBatch(demandKeywordList);
  387. }
  388. @SuppressWarnings("unchecked")
  389. @Override
  390. public Pagination<DemandSearchListBo> listDemandSearchList(Integer sign, String keyword, Integer industryCategoryA,
  391. Integer industryCategoryB, Integer demandType, BigDecimal budgetCostLower, BigDecimal budgetCostUpper,
  392. Integer pNo, Integer pSize) {
  393. Map<String, Object> params = new HashMap<>();
  394. if (!StringUtils.isBlank(keyword)) {
  395. params.put("keyword", keyword);
  396. }
  397. if (null != industryCategoryA) {
  398. params.put("industryCategoryA", industryCategoryA);
  399. }
  400. if (null != industryCategoryB) {
  401. params.put("industryCategoryB", industryCategoryB);
  402. }
  403. if (null != demandType) {
  404. params.put("demandType", demandType);
  405. }
  406. if (null != budgetCostLower && DemandPortalSearchSignType.ALL.getCode().equals(sign)) {
  407. params.put("budgetCostLower", budgetCostLower);
  408. }
  409. if (null != budgetCostUpper && DemandPortalSearchSignType.ALL.getCode().equals(sign)) {
  410. params.put("budgetCostUpper", budgetCostUpper);
  411. }
  412. if (null != sign) {
  413. params.put("sign", sign);
  414. }
  415. if (pNo == null || pNo < 0) {
  416. pNo = 1;
  417. }
  418. if (pSize == null || pSize < 0 || pSize > 10) {
  419. pSize = 10;
  420. }
  421. return (Pagination<DemandSearchListBo>) findPage("findSearchDemandListByPage", "findSearchDemandCount", params,
  422. pNo, pSize);
  423. }
  424. @Override
  425. public DemandSearchDetailBo selectDemandSearchDetail(String uid, String id) {
  426. return demandMapper.selectDemandSearchDetail(uid, id);
  427. }
  428. private Map<String, Object> disposeParams(Integer auditStatus, Integer province, Integer serialNumber, String name,
  429. String keyword, Integer infoSources, Integer demandType, String validityPeriodStartDate,
  430. String validityPeriodEndDate, String username, Integer status, Integer releaseStatus,
  431. String releaseDateStartDate, String releaseDateEndDate) {
  432. Map<String, Object> params = new HashMap<>();
  433. Date vStart = null;
  434. Date vEnd = null;
  435. Date rStart = null;
  436. Date rEnd = null;
  437. if (!StringUtils.isBlank(validityPeriodStartDate)) {
  438. try {
  439. vStart = DateUtils.parseDate(validityPeriodStartDate, AFTConstants.YYYYMMDD);
  440. } catch (ParseException e) {
  441. }
  442. }
  443. if (!StringUtils.isBlank(validityPeriodEndDate)) {
  444. try {
  445. vEnd = DateUtils.addDays(DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD), 1);
  446. } catch (ParseException e) {
  447. }
  448. }
  449. if (!StringUtils.isBlank(releaseDateStartDate)) {
  450. try {
  451. rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
  452. } catch (ParseException e) {
  453. }
  454. }
  455. if (!StringUtils.isBlank(releaseDateEndDate)) {
  456. try {
  457. rEnd = DateUtils.addDays(DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD), 1);
  458. } catch (ParseException e) {
  459. }
  460. }
  461. if (null != vStart) {
  462. params.put("vStart", vStart);
  463. }
  464. if (null != vEnd) {
  465. params.put("vEnd", vEnd);
  466. }
  467. if (null != rStart) {
  468. params.put("rStart", rStart);
  469. }
  470. if (null != rEnd) {
  471. params.put("rEnd", rEnd);
  472. }
  473. if (null != auditStatus) {
  474. params.put("auditStatus", auditStatus);
  475. }
  476. if (null != province) {
  477. params.put("province", province);
  478. }
  479. if (null != serialNumber) {
  480. params.put("serialNumber", serialNumber);
  481. }
  482. if (!StringUtils.isBlank(name)) {
  483. params.put("name", name);
  484. }
  485. if (!StringUtils.isBlank(keyword)) {
  486. params.put("keyword", keyword);
  487. }
  488. /*
  489. * if (!StringUtils.isBlank(username)) { params.put("username",
  490. * username); }
  491. */
  492. if (null != infoSources) {
  493. params.put("infoSources", infoSources);
  494. }
  495. if (null != demandType) {
  496. params.put("demandType", demandType);
  497. }
  498. if (null != status) {
  499. params.put("status", status);
  500. }
  501. if (null != releaseStatus) {
  502. params.put("releaseStatus", releaseStatus);
  503. }
  504. return params;
  505. }
  506. // 给所有审核员发送审核通知
  507. private void createAuditorNotice(Demand d) {
  508. List<String> ids = userRoleMapper.listAuditor();
  509. List<Notice> list = new ArrayList<>();
  510. if (null != ids && ids.size() > 0) {
  511. for (String s : ids) {
  512. list.add(disposeNotice(d, s));
  513. }
  514. noticeMapper.insertBatch(list);
  515. }
  516. }
  517. // 给指派技术经纪人发送审核结果通知
  518. private void createTechBorkerNotice(Demand a) {
  519. noticeMapper.insert(disposeNotice(a, null));
  520. }
  521. private Notice disposeNotice(Demand d, String aid) {
  522. Notice n = new Notice();
  523. Calendar now = Calendar.getInstance();
  524. now.set(Calendar.MILLISECOND, 0);
  525. n.setId(UUID.randomUUID().toString());
  526. n.setCreateTime(now.getTime());
  527. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  528. n.setRid(d.getId());
  529. User u = userMapper.selectByPrimaryKey(d.getEmployerId());
  530. if (null != u) {
  531. n.setPid(u.getAid());
  532. }
  533. if (StringUtils.isBlank(aid)) {
  534. n.setAid(d.getTechBrokerId());
  535. if (UserType.PERSONAL.getCode().equals(d.getDataCategory())) {
  536. n.setContent("编号" + d.getSerialNumber() + NoticeStatus.PERSONALDEMAND.getDesc() + " "
  537. + (DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())
  538. ? DemandAuditStatus.AUDITED.getDesc() : DemandAuditStatus.UNAUDITED.getDesc()));
  539. n.setNoticeType(NoticeStatus.PERSONALDEMAND.getCode());
  540. } else if (UserType.ORGANIZATION.getCode().equals(d.getDataCategory())) {
  541. n.setContent("编号" + d.getSerialNumber() + NoticeStatus.ORGANIZATIONDEMAND.getDesc() + " "
  542. + (DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())
  543. ? DemandAuditStatus.AUDITED.getDesc() : DemandAuditStatus.UNAUDITED.getDesc()));
  544. n.setNoticeType(NoticeStatus.ORGANIZATIONDEMAND.getCode());
  545. }
  546. } else {
  547. n.setAid(aid);
  548. if (UserType.PERSONAL.getCode().equals(d.getDataCategory())) {
  549. n.setContent(NoticeStatus.PERSONALDEMAND.getDesc() + " " + DemandAuditStatus.SUBMIT.getDesc());
  550. n.setNoticeType(NoticeStatus.PERSONALDEMAND.getCode());
  551. } else if (UserType.ORGANIZATION.getCode().equals(d.getDataCategory())) {
  552. n.setContent(NoticeStatus.ORGANIZATIONDEMAND.getDesc() + " " + DemandAuditStatus.SUBMIT.getDesc());
  553. n.setNoticeType(NoticeStatus.ORGANIZATIONDEMAND.getCode());
  554. }
  555. }
  556. return n;
  557. }
  558. private void disposeDemandKeyword(String[] keywords, Demand d, boolean delete) {
  559. if (null != keywords && keywords.length > 0) {
  560. if (delete) {
  561. demandKeywordMapper.batchDeleteByDemandId(d.getId());
  562. }
  563. List<DemandKeyword> list = new ArrayList<>();
  564. DemandKeyword dk = null;
  565. for (int i = 0; i < keywords.length; i++) {
  566. dk = new DemandKeyword();
  567. dk.setId(UUID.randomUUID().toString());
  568. dk.setDemandId(d.getId());
  569. dk.setKeyword(keywords[i].trim());
  570. list.add(dk);
  571. }
  572. demandKeywordMapper.insertBatch(list);
  573. }
  574. }
  575. @Override
  576. public int updateMatchAchievement(Demand d) {
  577. achievementDemandMapper.deleteByDemandId(d.getId());
  578. List<DemandKeyword> demand = demandKeywordMapper.selectKeywordsByDemandId(d.getId());
  579. if (null != demand && demand.size() > 0) {
  580. List<String> keyword = new ArrayList<>();
  581. for (DemandKeyword k : demand) {
  582. if (!StringUtils.isBlank(k.getKeyword())) {
  583. keyword.add(k.getKeyword());
  584. }
  585. }
  586. List<AchievementDemand> list = achievementKeywordMapper.selectAchievementDemand(keyword);
  587. if (null != list && list.size() > 0) {
  588. for (AchievementDemand ad : list) {
  589. ad.setDemandId(d.getId());
  590. }
  591. return achievementDemandMapper.insertBatch(list);
  592. }
  593. }
  594. return 0;
  595. }
  596. @SuppressWarnings("unchecked")
  597. @Override
  598. public Pagination<DemandPartnerListBo> lisePartnerDemand(String employerId, Integer pNo, Integer pSize) {
  599. Map<String, Object> params = new HashMap<>();
  600. params.put("employerId", employerId);
  601. if (pNo == null || pNo < 0) {
  602. pNo = 1;
  603. }
  604. if (pSize == null || pSize < 0 || pSize > 10) {
  605. pSize = 10;
  606. }
  607. return (Pagination<DemandPartnerListBo>) findPage("findPartnerDemandListByPage", "findPartnerDemandCount",
  608. params, pNo, pSize);
  609. }
  610. @Override
  611. public DemandPortalDetailBo findUserPortalDemandDetail(String id) {
  612. return demandMapper.findUserPortalDemandDetail(id, TokenManager.getUserId());
  613. }
  614. @Override
  615. public DemandPortalDetailBo findOrgPortalDemandDetail(String id) {
  616. return demandMapper.findOrgPortalDemandDetail(id, TokenManager.getUserId());
  617. }
  618. @Override
  619. public List<DemandPortalSimilarListBo> findByIndustryCategoryA(Integer industryCategoryA, String id) {
  620. return demandMapper.findByIndustryCategoryA(industryCategoryA, id);
  621. }
  622. @Override
  623. public int updateByPrimaryKeySelective(Demand d) {
  624. return demandMapper.updateByPrimaryKeySelective(d);
  625. }
  626. }