DemandServiceImpl.java 31 KB

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