DemandServiceImpl.java 33 KB

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