DemandServiceImpl.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  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.AchievementMapper;
  21. import com.goafanti.common.dao.DemandInterestMapper;
  22. import com.goafanti.common.dao.DemandKeywordMapper;
  23. import com.goafanti.common.dao.DemandMapper;
  24. import com.goafanti.common.dao.FieldGlossoryMapper;
  25. import com.goafanti.common.dao.NewsInterestMapper;
  26. import com.goafanti.common.dao.NoticeMapper;
  27. import com.goafanti.common.dao.OrganizationIdentityMapper;
  28. import com.goafanti.common.dao.ProjectInterestMapper;
  29. import com.goafanti.common.dao.UserIdentityMapper;
  30. import com.goafanti.common.dao.UserInterestMapper;
  31. import com.goafanti.common.dao.UserMapper;
  32. import com.goafanti.common.dao.UserRoleMapper;
  33. import com.goafanti.common.enums.DeleteStatus;
  34. import com.goafanti.common.enums.DemandAuditStatus;
  35. import com.goafanti.common.enums.DemandInfoSourceStatus;
  36. import com.goafanti.common.enums.DemandPortalSearchSignType;
  37. import com.goafanti.common.enums.DemandReleaseStatus;
  38. import com.goafanti.common.enums.DemandStatus;
  39. import com.goafanti.common.enums.DemandSwitchSign;
  40. import com.goafanti.common.enums.InterestType;
  41. import com.goafanti.common.enums.NoticeReadStatus;
  42. import com.goafanti.common.enums.NoticeStatus;
  43. import com.goafanti.common.enums.UserType;
  44. import com.goafanti.common.model.AchievementDemand;
  45. import com.goafanti.common.model.AchievementDemandCount;
  46. import com.goafanti.common.model.Demand;
  47. import com.goafanti.common.model.DemandKeyword;
  48. import com.goafanti.common.model.Notice;
  49. import com.goafanti.common.model.OrganizationIdentity;
  50. import com.goafanti.common.model.User;
  51. import com.goafanti.common.model.UserIdentity;
  52. import com.goafanti.common.utils.DateUtils;
  53. import com.goafanti.core.mybatis.BaseMybatisDao;
  54. import com.goafanti.core.mybatis.page.Pagination;
  55. import com.goafanti.core.shiro.token.TokenManager;
  56. import com.goafanti.demand.bo.DemandImportBo;
  57. import com.goafanti.demand.bo.DemandListBo;
  58. import com.goafanti.demand.bo.DemandManageDetailBo;
  59. import com.goafanti.demand.bo.DemandManageListBo;
  60. import com.goafanti.demand.bo.DemandPartnerListBo;
  61. import com.goafanti.demand.bo.ObjectInterestListBo;
  62. import com.goafanti.demand.service.DemandService;
  63. import com.goafanti.portal.bo.BoutiqueListBo;
  64. import com.goafanti.portal.bo.DemandPortalDetailBo;
  65. import com.goafanti.portal.bo.DemandPortalSimilarListBo;
  66. import com.goafanti.portal.bo.DemandSearchDetailBo;
  67. import com.goafanti.portal.bo.DemandSearchListBo;
  68. @Service
  69. public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements DemandService {
  70. @Autowired
  71. private DemandMapper demandMapper;
  72. @Autowired
  73. private UserMapper userMapper;
  74. @Autowired
  75. private UserRoleMapper userRoleMapper;
  76. @Autowired
  77. private NoticeMapper noticeMapper;
  78. @Autowired
  79. private DemandKeywordMapper demandKeywordMapper;
  80. @Autowired
  81. private AchievementDemandMapper achievementDemandMapper;
  82. @Autowired
  83. private AchievementKeywordMapper achievementKeywordMapper;
  84. @Autowired
  85. private AchievementDemandCountMapper achievementDemandCountMapper;
  86. @Autowired
  87. private UserIdentityMapper userIdentityMapper;
  88. @Autowired
  89. private OrganizationIdentityMapper organizationIdentityMapper;
  90. @Autowired
  91. private AchievementMapper achievementMapper;
  92. @Autowired
  93. private FieldGlossoryMapper fieldGlossoryMapper;
  94. @Autowired
  95. private DemandInterestMapper demandInterestMapper;
  96. @Autowired
  97. private NewsInterestMapper newsInterestMapper;
  98. @Autowired
  99. private UserInterestMapper userInterestMapper;
  100. @Autowired
  101. ProjectInterestMapper projectInterestMapper;
  102. @SuppressWarnings("unchecked")
  103. @Override
  104. public Pagination<DemandManageListBo> selectUserDemandManageList(String employerName, Integer auditStatus,
  105. Integer province, Integer serialNumber, String name, String keyword, Integer infoSources,
  106. Integer demandType, String validityPeriodStartDate, String validityPeriodEndDate, String username,
  107. Integer status, Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer pNo,
  108. Integer pSize, Integer boutique, Integer hot) {
  109. Map<String, Object> params = disposeParams(auditStatus, province, serialNumber, name, keyword, infoSources,
  110. demandType, validityPeriodStartDate, validityPeriodEndDate, username, status, releaseStatus,
  111. releaseDateStartDate, releaseDateEndDate, createDateStartDate, createDateEndDate, boutique, hot);
  112. if (pNo == null || pNo < 0) {
  113. pNo = 1;
  114. }
  115. if (pSize == null || pSize < 0 || pSize > 10) {
  116. pSize = 10;
  117. }
  118. /*
  119. * if (TokenManager.hasRole(AFTConstants.SALESMANAGERADMIN) ||
  120. * TokenManager.hasRole(AFTConstants.SALESMANADMIN)) {
  121. * params.put("principal", TokenManager.getAdminId()); }
  122. *
  123. * if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  124. * params.put("mid", TokenManager.getAdminId()); }
  125. *
  126. * if (TokenManager.hasRole(AFTConstants.TECHBROKER)) {
  127. * params.put("techBroker", TokenManager.getAdminId()); }
  128. */
  129. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  130. params.put("adminId", TokenManager.getAdminId());
  131. }
  132. if (StringUtils.isNotBlank(employerName)) {
  133. params.put("employerName", employerName);
  134. }
  135. if (StringUtils.isNotBlank(username)) {
  136. params.put("username", username);
  137. }
  138. return (Pagination<DemandManageListBo>) findPage("findManageUserDemandListByPage", "findManageUserDemandCount",
  139. params, pNo, pSize);
  140. }
  141. @SuppressWarnings("unchecked")
  142. @Override
  143. public Pagination<DemandManageListBo> selectOrgDemandManageList(String employerName, Integer auditStatus,
  144. Integer province, Integer serialNumber, String name, String keyword, Integer infoSources,
  145. Integer demandType, String validityPeriodStartDate, String validityPeriodEndDate, String username,
  146. Integer status, Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer pNo,
  147. Integer pSize, Integer boutique, Integer hot, String techBrokerId) {
  148. Map<String, Object> params = disposeParams(auditStatus, province, serialNumber, name, keyword, infoSources,
  149. demandType, validityPeriodStartDate, validityPeriodEndDate, username, status, releaseStatus,
  150. releaseDateStartDate, releaseDateEndDate, createDateStartDate, createDateEndDate, boutique, hot);
  151. if (pNo == null || pNo < 0) {
  152. pNo = 1;
  153. }
  154. if (pSize == null || pSize < 0 || pSize > 10) {
  155. pSize = 10;
  156. }
  157. /*if (TokenManager.hasRole(AFTConstants.SALESMANAGERADMIN) || TokenManager.hasRole(AFTConstants.SALESMANADMIN)) {
  158. params.put("principal", TokenManager.getAdminId());
  159. }
  160. if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
  161. params.put("mid", TokenManager.getAdminId());
  162. }
  163. if (TokenManager.hasRole(AFTConstants.TECHBROKER)) {
  164. params.put("techBroker", TokenManager.getAdminId());
  165. }*/
  166. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  167. params.put("adminId", TokenManager.getAdminId());
  168. }
  169. if (StringUtils.isNotBlank(employerName)) {
  170. params.put("employerName", employerName);
  171. }
  172. if (StringUtils.isNotBlank(username)) {
  173. params.put("unitName", username);
  174. }
  175. return (Pagination<DemandManageListBo>) findPage("findManageOrgDemandListByPage", "findManageOrgDemandCount",
  176. params, pNo, pSize);
  177. }
  178. @Override
  179. public void saveUserDemand(Demand d, String validityPeriodFormattedDate, String[] keywords) {
  180. Date validityPeriod = null;
  181. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  182. try {
  183. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  184. } catch (ParseException e) {
  185. }
  186. }
  187. d.setValidityPeriod(validityPeriod);
  188. d.setId(UUID.randomUUID().toString());
  189. d.setTechBrokerId(TokenManager.getAdminId());
  190. d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  191. Calendar now = Calendar.getInstance();
  192. now.set(Calendar.MILLISECOND, 0);
  193. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  194. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  195. d.setPrincipalId(TokenManager.getAdminId());
  196. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  197. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  198. createAuditorNotice(d);
  199. } else {
  200. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  201. }
  202. d.setCreateTime(now.getTime());
  203. demandMapper.insert(d);
  204. disposeDemandKeyword(keywords, d, false);
  205. }
  206. @Override
  207. public int updateUserDemand(Demand d, String validityPeriodFormattedDate, String[] keywords, Integer switchSign) {
  208. Date validityPeriod = null;
  209. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  210. try {
  211. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  212. } catch (ParseException e) {
  213. }
  214. }
  215. d.setValidityPeriod(validityPeriod);
  216. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  217. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  218. createAuditorNotice(d);
  219. }
  220. disposeDemandKeyword(keywords, d, true);
  221. demandMapper.updateByPrimaryKeySelective(d);
  222. if (null != switchSign && DemandSwitchSign.CLOSE.getCode().equals(switchSign)) {
  223. demandMapper.updateEmployerId(d.getId());
  224. }
  225. return 1;
  226. }
  227. @Override
  228. public DemandManageDetailBo selectUserDemandDetail(String id) {
  229. return demandMapper.selectUserDemandDetail(id);
  230. }
  231. @Override
  232. public int deleteByPrimaryKey(List<String> id) {
  233. demandKeywordMapper.batchDeleteByDemandIds(id);
  234. achievementDemandMapper.batchDeleteByDemandIds(id);
  235. for (String s : id) {
  236. Demand d = demandMapper.selectByPrimaryKey(s);
  237. if (null != d && DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())
  238. && StringUtils.isNotBlank(d.getEmployerId())) {
  239. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(d.getEmployerId());
  240. if (null != adc) {
  241. adc.setDemandCount(adc.getDemandCount() - 1);
  242. if (adc.getDemandCount() < 0) {
  243. adc.setDemandCount(0);
  244. }
  245. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  246. }
  247. }
  248. }
  249. return demandMapper.batchDeleteByPrimaryKey(id);
  250. }
  251. @Override
  252. public DemandManageDetailBo selectOrgDemandDetail(String id) {
  253. return demandMapper.selectOrgDemandDetail(id);
  254. }
  255. @Override
  256. public Demand selectByPrimaryKey(String id) {
  257. return demandMapper.selectByPrimaryKey(id);
  258. }
  259. @SuppressWarnings("unchecked")
  260. @Override
  261. public Pagination<DemandListBo> listDemand(Integer auditStatus, Integer serialNumber, String name, String keyword,
  262. Integer demandType, String validityPeriodStartDate, String validityPeriodEndDate, Integer status,
  263. Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer pNo, Integer pSize) {
  264. Map<String, Object> params = disposeParams(auditStatus, null, serialNumber, name, keyword, null, demandType,
  265. validityPeriodStartDate, validityPeriodEndDate, null, status, releaseStatus, releaseDateStartDate,
  266. releaseDateEndDate, createDateStartDate, createDateEndDate, null, null);
  267. params.put("employerId", TokenManager.getUserId());
  268. if (pNo == null || pNo < 0) {
  269. pNo = 1;
  270. }
  271. if (pSize == null || pSize < 0) {
  272. pSize = 10;
  273. }
  274. return (Pagination<DemandListBo>) findPage("findDemandListByPage", "findDemandCount", params, pNo, pSize);
  275. }
  276. @Override
  277. public int updateReleaseStatus(Demand d) {
  278. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  279. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  280. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  281. demandMapper.updateByPrimaryKeySelective(d);
  282. demandKeywordMapper.batchDeleteByDemandId(d.getId());
  283. achievementDemandMapper.deleteByDemandId(d.getId());
  284. if (StringUtils.isNotBlank(d.getEmployerId())) {
  285. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(d.getEmployerId());
  286. if (null != adc) {
  287. adc.setDemandCount(adc.getDemandCount() - 1);
  288. if (adc.getDemandCount() < 0) {
  289. adc.setDemandCount(0);
  290. }
  291. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  292. }
  293. }
  294. return demandMapper.updateReleaseDate(d.getId());
  295. }
  296. @Override
  297. public int updateAuditDemand(Demand d, String techBroderId, Integer auditStatus) {
  298. d.setAuditStatus(auditStatus);
  299. if (DemandAuditStatus.AUDITED.getCode().equals(auditStatus)) {
  300. Calendar now = Calendar.getInstance();
  301. now.set(Calendar.MILLISECOND, 0);
  302. d.setReleaseDate(now.getTime());
  303. d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
  304. d.setTechBrokerId(techBroderId);
  305. if (StringUtils.isNotBlank(d.getKeyword())) {
  306. String[] keywords = d.getKeyword().trim().split(",|,");
  307. disposeDemandKeyword(keywords, d, false);
  308. }
  309. String employerId = d.getEmployerId();
  310. if (StringUtils.isNotBlank(employerId)) {
  311. if (UserType.PERSONAL.getCode().equals(d.getDataCategory())) {
  312. UserIdentity ui = userIdentityMapper.selectUserIdentityByUserId(employerId);
  313. if (null != ui) {
  314. d.setEmployerName(ui.getUsername());
  315. }
  316. } else if (UserType.ORGANIZATION.getCode().equals(d.getDataCategory())) {
  317. OrganizationIdentity oi = organizationIdentityMapper.selectOrgIdentityByUserId(employerId);
  318. if (null != oi) {
  319. d.setEmployerName(oi.getUnitName());
  320. }
  321. }
  322. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(employerId);
  323. if (null == adc) {
  324. AchievementDemandCount achievementDemandCount = new AchievementDemandCount();
  325. achievementDemandCount.setId(UUID.randomUUID().toString());
  326. achievementDemandCount.setUid(employerId);
  327. achievementDemandCount.setDemandCount(AFTConstants.ACHIEVEMENT_DEMAND_FIRST_COUNT);
  328. achievementDemandCount.setAchievementCount(AFTConstants.ACHIEVEMENT_DEMAND_INIT_COUNT);
  329. achievementDemandCountMapper.insert(achievementDemandCount);
  330. } else {
  331. adc.setDemandCount(adc.getDemandCount() + 1);
  332. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  333. }
  334. }
  335. } else {
  336. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  337. }
  338. createTechBorkerNotice(d);
  339. return demandMapper.updateByPrimaryKeySelective(d);
  340. }
  341. @Override
  342. public void saveDemand(Demand d, String validityPeriodFormattedDate, String[] keywords) {
  343. Date validityPeriod = null;
  344. if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
  345. try {
  346. validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
  347. } catch (ParseException e) {
  348. }
  349. }
  350. d.setValidityPeriod(validityPeriod);
  351. d.setId(UUID.randomUUID().toString());
  352. d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  353. Calendar now = Calendar.getInstance();
  354. now.set(Calendar.MILLISECOND, 0);
  355. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  356. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  357. if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
  358. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  359. createAuditorNotice(d);
  360. } else {
  361. d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
  362. }
  363. d.setCreateTime(now.getTime());
  364. demandMapper.insert(d);
  365. disposeDemandKeyword(keywords, d, false);
  366. }
  367. @Override
  368. public List<AchievementDemandListBo> selectAchievementDemandListByDemandId(String id) {
  369. return achievementDemandMapper.selectAchievementDemandListByDemandId(id);
  370. }
  371. @Override
  372. public void insertImport(List<DemandImportBo> data) {
  373. if (null == data || data.isEmpty()) {
  374. return;
  375. }
  376. Demand d = null;
  377. DemandKeyword dk = null;
  378. List<Demand> demandList = new ArrayList<>();
  379. List<DemandKeyword> demandKeywordList = new ArrayList<>();
  380. Calendar now = Calendar.getInstance();
  381. now.set(Calendar.MILLISECOND, 0);
  382. String techBrokerId = TokenManager.getAdminId();
  383. for (DemandImportBo bo : data) {
  384. d = new Demand();
  385. BeanUtils.copyProperties(bo, d);
  386. d.setId(UUID.randomUUID().toString());
  387. d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  388. d.setCreateTime(now.getTime());
  389. d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  390. d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
  391. d.setStatus(DemandStatus.UNRESOLVED.getCode());
  392. d.setInfoSources(DemandInfoSourceStatus.IMPORT.getCode());
  393. d.setTechBrokerId(techBrokerId);
  394. List<String> keywordsList = bo.getKeywords();
  395. if (null != keywordsList && keywordsList.size() > 0) {
  396. for (String s : keywordsList) {
  397. if (!StringUtils.isBlank(s)) {
  398. dk = new DemandKeyword();
  399. dk.setDemandId(d.getId());
  400. dk.setKeyword(s.trim());
  401. dk.setId(UUID.randomUUID().toString());
  402. demandKeywordList.add(dk);
  403. }
  404. }
  405. }
  406. demandList.add(d);
  407. }
  408. demandMapper.insertBatch(demandList);
  409. demandKeywordMapper.insertBatch(demandKeywordList);
  410. }
  411. @SuppressWarnings("unchecked")
  412. @Override
  413. public Pagination<DemandSearchListBo> listDemandSearchList(Integer sign, String keyword, Integer industryCategoryA,
  414. Integer industryCategoryB, Integer demandType, BigDecimal budgetCostLower, BigDecimal budgetCostUpper,
  415. Integer pNo, Integer pSize, Integer dateSort) {
  416. Map<String, Object> params = new HashMap<>();
  417. if (!StringUtils.isBlank(keyword)) {
  418. params.put("keyword", keyword);
  419. }
  420. if (null != industryCategoryA) {
  421. params.put("industryCategoryA", industryCategoryA);
  422. }
  423. if (null != industryCategoryB) {
  424. params.put("industryCategoryB", industryCategoryB);
  425. }
  426. if (null != demandType) {
  427. params.put("demandType", demandType);
  428. }
  429. if (null != budgetCostLower && DemandPortalSearchSignType.ALL.getCode().equals(sign)) {
  430. params.put("budgetCostLower", budgetCostLower);
  431. }
  432. if (null != budgetCostUpper && DemandPortalSearchSignType.ALL.getCode().equals(sign)) {
  433. params.put("budgetCostUpper", budgetCostUpper);
  434. }
  435. if (null != sign) {
  436. params.put("sign", sign);
  437. }
  438. if (null != dateSort) {
  439. params.put("dateSort", dateSort);
  440. }
  441. if (pNo == null || pNo < 0) {
  442. pNo = 1;
  443. }
  444. if (pSize == null || pSize < 0 || pSize > 10) {
  445. pSize = 12;
  446. }
  447. return (Pagination<DemandSearchListBo>) findPage("findSearchDemandListByPage", "findSearchDemandCount", params,
  448. pNo, pSize);
  449. }
  450. @Override
  451. public DemandSearchDetailBo selectDemandSearchDetail(String uid, String id) {
  452. return demandMapper.selectDemandSearchDetail(uid, id);
  453. }
  454. private Map<String, Object> disposeParams(Integer auditStatus, Integer province, Integer serialNumber, String name,
  455. String keyword, Integer infoSources, Integer demandType, String validityPeriodStartDate,
  456. String validityPeriodEndDate, String username, Integer status, Integer releaseStatus,
  457. String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer boutique, Integer hot) {
  458. Map<String, Object> params = new HashMap<>();
  459. Date vStart = null;
  460. Date vEnd = null;
  461. Date rStart = null;
  462. Date rEnd = null;
  463. Date cStart = null;
  464. Date cEnd = null;
  465. if (!StringUtils.isBlank(validityPeriodStartDate)) {
  466. try {
  467. vStart = DateUtils.parseDate(validityPeriodStartDate, AFTConstants.YYYYMMDD);
  468. } catch (ParseException e) {
  469. }
  470. }
  471. if (!StringUtils.isBlank(validityPeriodEndDate)) {
  472. try {
  473. vEnd = DateUtils.addDays(DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD), 1);
  474. } catch (ParseException e) {
  475. }
  476. }
  477. if (!StringUtils.isBlank(releaseDateStartDate)) {
  478. try {
  479. rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
  480. } catch (ParseException e) {
  481. }
  482. }
  483. if (!StringUtils.isBlank(releaseDateEndDate)) {
  484. try {
  485. rEnd = DateUtils.addDays(DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD), 1);
  486. } catch (ParseException e) {
  487. }
  488. }
  489. if (!StringUtils.isBlank(createDateStartDate)) {
  490. try {
  491. cStart = DateUtils.parseDate(createDateStartDate, AFTConstants.YYYYMMDD);
  492. } catch (ParseException e) {
  493. }
  494. }
  495. if (!StringUtils.isBlank(createDateEndDate)) {
  496. try {
  497. cEnd = DateUtils.addDays(DateUtils.parseDate(createDateEndDate, AFTConstants.YYYYMMDD), 1);
  498. } catch (ParseException e) {
  499. }
  500. }
  501. if (null != vStart) {
  502. params.put("vStart", vStart);
  503. }
  504. if (null != vEnd) {
  505. params.put("vEnd", vEnd);
  506. }
  507. if (null != rStart) {
  508. params.put("rStart", rStart);
  509. }
  510. if (null != rEnd) {
  511. params.put("rEnd", rEnd);
  512. }
  513. if (null != cStart) {
  514. params.put("cStart", cStart);
  515. }
  516. if (null != cEnd) {
  517. params.put("cEnd", cEnd);
  518. }
  519. if (null != auditStatus) {
  520. params.put("auditStatus", auditStatus);
  521. }
  522. if (null != province) {
  523. params.put("province", province);
  524. }
  525. if (null != serialNumber) {
  526. params.put("serialNumber", serialNumber);
  527. }
  528. if (!StringUtils.isBlank(name)) {
  529. params.put("name", name);
  530. }
  531. if (!StringUtils.isBlank(keyword)) {
  532. params.put("keyword", keyword);
  533. }
  534. /*
  535. * if (!StringUtils.isBlank(username)) { params.put("username",
  536. * username); }
  537. */
  538. if (null != infoSources) {
  539. params.put("infoSources", infoSources);
  540. }
  541. if (null != demandType) {
  542. params.put("demandType", demandType);
  543. }
  544. if (null != status) {
  545. params.put("status", status);
  546. }
  547. if (null != releaseStatus) {
  548. params.put("releaseStatus", releaseStatus);
  549. }
  550. if (null != boutique) {
  551. params.put("boutique", boutique);
  552. }
  553. if (null != hot) {
  554. params.put("hot", hot);
  555. }
  556. return params;
  557. }
  558. // 给所有审核员发送审核通知
  559. private void createAuditorNotice(Demand d) {
  560. List<String> ids = userRoleMapper.listAuditor();
  561. List<Notice> list = new ArrayList<>();
  562. if (null != ids && ids.size() > 0) {
  563. for (String s : ids) {
  564. list.add(disposeNotice(d, s));
  565. }
  566. noticeMapper.insertBatch(list);
  567. }
  568. }
  569. // 给指派技术经纪人发送审核结果通知
  570. private void createTechBorkerNotice(Demand a) {
  571. noticeMapper.insert(disposeNotice(a, null));
  572. }
  573. private Notice disposeNotice(Demand d, String aid) {
  574. Notice n = new Notice();
  575. Calendar now = Calendar.getInstance();
  576. now.set(Calendar.MILLISECOND, 0);
  577. n.setId(UUID.randomUUID().toString());
  578. n.setCreateTime(now.getTime());
  579. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  580. n.setRid(d.getId());
  581. User u = userMapper.selectByPrimaryKey(d.getEmployerId());
  582. if (null != u) {
  583. n.setPid(u.getAid());
  584. }
  585. if (StringUtils.isBlank(aid)) {
  586. n.setAid(d.getTechBrokerId());
  587. if (UserType.PERSONAL.getCode().equals(d.getDataCategory())) {
  588. n.setContent("编号" + d.getSerialNumber() + NoticeStatus.PERSONALDEMAND.getDesc() + " "
  589. + (DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())
  590. ? DemandAuditStatus.AUDITED.getDesc() : DemandAuditStatus.UNAUDITED.getDesc()));
  591. n.setNoticeType(NoticeStatus.PERSONALDEMAND.getCode());
  592. } else if (UserType.ORGANIZATION.getCode().equals(d.getDataCategory())) {
  593. n.setContent("编号" + d.getSerialNumber() + NoticeStatus.ORGANIZATIONDEMAND.getDesc() + " "
  594. + (DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())
  595. ? DemandAuditStatus.AUDITED.getDesc() : DemandAuditStatus.UNAUDITED.getDesc()));
  596. n.setNoticeType(NoticeStatus.ORGANIZATIONDEMAND.getCode());
  597. }
  598. } else {
  599. n.setAid(aid);
  600. if (UserType.PERSONAL.getCode().equals(d.getDataCategory())) {
  601. n.setContent(NoticeStatus.PERSONALDEMAND.getDesc() + " " + DemandAuditStatus.SUBMIT.getDesc());
  602. n.setNoticeType(NoticeStatus.PERSONALDEMAND.getCode());
  603. } else if (UserType.ORGANIZATION.getCode().equals(d.getDataCategory())) {
  604. n.setContent(NoticeStatus.ORGANIZATIONDEMAND.getDesc() + " " + DemandAuditStatus.SUBMIT.getDesc());
  605. n.setNoticeType(NoticeStatus.ORGANIZATIONDEMAND.getCode());
  606. }
  607. }
  608. return n;
  609. }
  610. private void disposeDemandKeyword(String[] keywords, Demand d, boolean delete) {
  611. if (null != keywords && keywords.length > 0) {
  612. if (delete) {
  613. demandKeywordMapper.batchDeleteByDemandId(d.getId());
  614. }
  615. List<DemandKeyword> list = new ArrayList<>();
  616. DemandKeyword dk = null;
  617. for (int i = 0; i < keywords.length; i++) {
  618. dk = new DemandKeyword();
  619. dk.setId(UUID.randomUUID().toString());
  620. dk.setDemandId(d.getId());
  621. dk.setKeyword(keywords[i].trim());
  622. list.add(dk);
  623. }
  624. demandKeywordMapper.insertBatch(list);
  625. }
  626. }
  627. @Override
  628. public int updateMatchAchievement(Demand d) {
  629. achievementDemandMapper.deleteByDemandId(d.getId());
  630. List<DemandKeyword> demand = demandKeywordMapper.selectKeywordsByDemandId(d.getId());
  631. if (null != demand && demand.size() > 0) {
  632. List<String> keyword = new ArrayList<>();
  633. for (DemandKeyword k : demand) {
  634. if (!StringUtils.isBlank(k.getKeyword())) {
  635. keyword.add(k.getKeyword());
  636. }
  637. }
  638. List<AchievementDemand> list = achievementKeywordMapper.selectAchievementDemand(keyword);
  639. if (null != list && list.size() > 0) {
  640. for (AchievementDemand ad : list) {
  641. ad.setDemandId(d.getId());
  642. }
  643. return achievementDemandMapper.insertBatch(list);
  644. }
  645. }
  646. return 0;
  647. }
  648. @SuppressWarnings("unchecked")
  649. @Override
  650. public Pagination<DemandPartnerListBo> lisePartnerDemand(String employerId, Integer pNo, Integer pSize) {
  651. Map<String, Object> params = new HashMap<>();
  652. params.put("employerId", employerId);
  653. if (pNo == null || pNo < 0) {
  654. pNo = 1;
  655. }
  656. if (pSize == null || pSize < 0 || pSize > 10) {
  657. pSize = 10;
  658. }
  659. return (Pagination<DemandPartnerListBo>) findPage("findPartnerDemandListByPage", "findPartnerDemandCount",
  660. params, pNo, pSize);
  661. }
  662. @Override
  663. public DemandPortalDetailBo findUserPortalDemandDetail(String id) {
  664. return demandMapper.findUserPortalDemandDetail(id, TokenManager.getUserId());
  665. }
  666. @Override
  667. public DemandPortalDetailBo findOrgPortalDemandDetail(String id) {
  668. return demandMapper.findOrgPortalDemandDetail(id, TokenManager.getUserId());
  669. }
  670. @Override
  671. public List<DemandPortalSimilarListBo> findByIndustryCategoryA(Integer industryCategoryA, String id) {
  672. return demandMapper.findByIndustryCategoryA(industryCategoryA, id);
  673. }
  674. @Override
  675. public int updateByPrimaryKeySelective(Demand d) {
  676. return demandMapper.updateByPrimaryKeySelective(d);
  677. }
  678. @Override
  679. public DemandListBo selectDemandDetail(String id ) {
  680. DemandListBo d=demandMapper.selectAppByPrimaryKey(id);
  681. if (null!=d.getIndustryCategoryA()) {
  682. d.setIndustryCategory1(fieldGlossoryMapper.selectByPrimaryKey(d.getIndustryCategoryA()).getName());
  683. }
  684. if (null!=d.getIndustryCategoryB()) {
  685. d.setIndustryCategory2(String.valueOf(fieldGlossoryMapper.selectByPrimaryKey(d.getIndustryCategoryB()).getName()));
  686. }
  687. if (null!=d.getIndustryCategoryC()) {
  688. d.setIndustryCategory3(String.valueOf(fieldGlossoryMapper.selectByPrimaryKey(d.getIndustryCategoryC()).getName()));
  689. }
  690. int i=demandMapper.countInterest(d.getId());
  691. d.setCountInterest(String.valueOf(i));
  692. String uid=TokenManager.getUserId();
  693. if(StringUtils.isNotBlank(TokenManager.getUserId())&&demandInterestMapper.checkUidAndDid(uid,id)>0){
  694. d.setInterest("1");//已关注
  695. }else {
  696. d.setInterest("0");//未关注
  697. }
  698. return d;
  699. }
  700. @SuppressWarnings("unchecked")
  701. @Override
  702. public Pagination<BoutiqueListBo> boutiqueSearchList(Integer industryCategoryA, Integer pNo, Integer pSize) {
  703. Map<String, Object> params = new HashMap<>();
  704. if (null != industryCategoryA)
  705. params.put("industryCategoryA", industryCategoryA);
  706. return (Pagination<BoutiqueListBo>) findPage("findBoutiqueListByPage", "findBoutiqueCount", params, pNo, pSize);
  707. }
  708. @Override
  709. public ArrayList<DemandListBo> selectDemandList(Integer boutique) {
  710. return demandMapper.selectDemandList(boutique);
  711. }
  712. @Override
  713. public List<DemandListBo> selectCsutomerLike() {
  714. return demandMapper.selectCsutomerLike(TokenManager.getUserId());
  715. }
  716. @SuppressWarnings("unchecked")
  717. @Override
  718. public Pagination<DemandSearchListBo> listAppDemand(Integer auditStatus, Integer serialNumber, String name,
  719. String keyword, Integer demandType,Integer industryCategoryA, String validityPeriodStartDate, String validityPeriodEndDate,
  720. Integer status, Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate,String employerId, Integer pNo,
  721. Integer pSize) {
  722. Map<String, Object> params = disposeParams(auditStatus, null, serialNumber, name, keyword, null, demandType,
  723. validityPeriodStartDate, validityPeriodEndDate, null, status, releaseStatus, releaseDateStartDate,
  724. releaseDateEndDate,null,null, null, null);
  725. if (null!=industryCategoryA) {
  726. params.put("industryCategoryA", industryCategoryA);
  727. }
  728. if (null!=employerId) {
  729. params.put("employerId", employerId);
  730. }
  731. if (pNo == null || pNo < 0) {
  732. pNo = 1;
  733. }
  734. if (pSize == null || pSize < 0) {
  735. pSize = 10;
  736. }
  737. Pagination<DemandSearchListBo> p=(Pagination<DemandSearchListBo>) findPage("findAppDemandListByPage", "findAppDemandCount", params, pNo, pSize);
  738. return p;
  739. }
  740. @SuppressWarnings("unchecked")
  741. @Override
  742. public Pagination<ObjectInterestListBo> selectinterest(Integer type,Integer pNo, Integer pSize) {
  743. if (pNo == null || pNo < 0) {
  744. pNo = 1;
  745. }
  746. if (pSize == null || pSize < 0) {
  747. pSize = 10;
  748. }
  749. Map<String, Object> params=new HashMap<>();
  750. params.put("type", type);
  751. if (StringUtils.isNotBlank(TokenManager.getUserId())) {
  752. params.put("uid", TokenManager.getUserId());
  753. }
  754. //params.put("uid", "6d71349c-7bb8-4e8a-8c03-0c3f36fc66ae");
  755. if (type==InterestType.POLICY.getCode()) {
  756. Pagination<ObjectInterestListBo> p=(Pagination<ObjectInterestListBo>) findPage("findAppNewsInterestByPage", "findAppNewsInterestCount", params, pNo, pSize);
  757. List<ObjectInterestListBo> l=(List<ObjectInterestListBo>) p.getList();
  758. for (ObjectInterestListBo o : l) {
  759. int i=newsInterestMapper.countInterest(o.getId());
  760. o.setCountInterest(String.valueOf(i));
  761. o.setType(type);
  762. }
  763. return p;
  764. }
  765. if (type==InterestType.EXPERTS.getCode()) {
  766. Pagination<ObjectInterestListBo> p=(Pagination<ObjectInterestListBo>) findPage("findAppUserInterestByPage", "findAppUserInterestCount", params, pNo, pSize);
  767. List<ObjectInterestListBo> l=(List<ObjectInterestListBo>) p.getList();
  768. for (ObjectInterestListBo o : l) {
  769. int i=userInterestMapper.countInterest(o.getId());
  770. o.setCountInterest(String.valueOf(i));
  771. o.setType(type);
  772. }
  773. return p;
  774. }
  775. if (type==InterestType.DEMAND.getCode()) {
  776. Pagination<ObjectInterestListBo> p=(Pagination<ObjectInterestListBo>) findPage("findAppDemandInterestByPage", "findAppDemandInterestCount", params, pNo, pSize);
  777. List<ObjectInterestListBo> l=(List<ObjectInterestListBo>) p.getList();
  778. for (ObjectInterestListBo o : l) {
  779. int i=demandInterestMapper.checkCount(o.getId());
  780. o.setCountInterest(String.valueOf(i));
  781. o.setType(type);
  782. }
  783. return p;
  784. }
  785. if (null==type||type==InterestType.ACHIEVEMENT.getCode()) {
  786. Pagination<ObjectInterestListBo> p=(Pagination<ObjectInterestListBo>) findPage("findAppAchievementInterestByPage", "findAppAchievementInterestCount", params, pNo, pSize);
  787. List<ObjectInterestListBo> l=(List<ObjectInterestListBo>) p.getList();
  788. for (ObjectInterestListBo o : l) {
  789. int i=achievementMapper.countInterest(o.getId());
  790. o.setCountInterest(String.valueOf(i));
  791. o.setType(type);
  792. }
  793. return p;
  794. }
  795. if (null==type||type==InterestType.PROJECT.getCode()) {
  796. Pagination<ObjectInterestListBo> p=(Pagination<ObjectInterestListBo>) findPage("findAppProjectInterestByPage", "findAppProjectInterestCount", params, pNo, pSize);
  797. List<ObjectInterestListBo> l=(List<ObjectInterestListBo>) p.getList();
  798. for (ObjectInterestListBo o : l) {
  799. int i=projectInterestMapper.countInterest(o.getId());
  800. o.setCountInterest(String.valueOf(i));
  801. o.setType(type);
  802. }
  803. return p;
  804. }
  805. return null;
  806. }
  807. @SuppressWarnings("unchecked")
  808. @Override
  809. public Pagination<DemandSearchListBo> listMyDemand(Integer pNo, Integer pSize) {
  810. Map<String, Object> params = new HashMap<>();
  811. if (pNo == null || pNo < 0) {
  812. pNo = 1;
  813. }
  814. if (pSize == null || pSize < 0) {
  815. pSize = 10;
  816. }
  817. if (StringUtils.isNotBlank(TokenManager.getUserId())) {
  818. params.put("employerId", TokenManager.getUserId());
  819. }
  820. //params.put("employerId", "46433140-0a90-471e-a32f-6bc89c562e3d");
  821. return (Pagination<DemandSearchListBo>) findPage("findAppMyDemandListByPage", "findAppMyDemandCount", params, pNo, pSize);
  822. }
  823. }