DemandServiceImpl.java 32 KB

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