AchievementServiceImpl.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. package com.goafanti.achievement.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.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.cache.annotation.CacheEvict;
  16. import org.springframework.cache.annotation.Cacheable;
  17. import org.springframework.stereotype.Service;
  18. import com.goafanti.achievement.bo.AchievementImportBo;
  19. import com.goafanti.achievement.bo.AchievementListBo;
  20. import com.goafanti.achievement.bo.AchievementOrgOwnerDetailBo;
  21. import com.goafanti.achievement.bo.AchievementPartnerListBo;
  22. import com.goafanti.achievement.bo.AchievementUserOwnerDetailBo;
  23. import com.goafanti.achievement.service.AchievementService;
  24. import com.goafanti.common.bo.PolicyEntity;
  25. import com.goafanti.common.constant.AFTConstants;
  26. import com.goafanti.common.dao.AchievementDemandCountMapper;
  27. import com.goafanti.common.dao.AchievementDemandMapper;
  28. import com.goafanti.common.dao.AchievementInterestMapper;
  29. import com.goafanti.common.dao.AchievementKeywordMapper;
  30. import com.goafanti.common.dao.AchievementMapper;
  31. import com.goafanti.common.dao.DemandKeywordMapper;
  32. import com.goafanti.common.dao.NoticeMapper;
  33. import com.goafanti.common.dao.OrganizationIdentityMapper;
  34. import com.goafanti.common.dao.UserIdentityMapper;
  35. import com.goafanti.common.dao.UserMapper;
  36. import com.goafanti.common.dao.UserRoleMapper;
  37. import com.goafanti.common.enums.AchievementAuditStatus;
  38. import com.goafanti.common.enums.AchievementReleaseStatus;
  39. import com.goafanti.common.enums.AchievementSwitchSign;
  40. import com.goafanti.common.enums.DeleteStatus;
  41. import com.goafanti.common.enums.DemandReleaseStatus;
  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.Achievement;
  46. import com.goafanti.common.model.AchievementDemand;
  47. import com.goafanti.common.model.AchievementDemandCount;
  48. import com.goafanti.common.model.AchievementKeyword;
  49. import com.goafanti.common.model.Admin;
  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.common.utils.LoggerUtils;
  56. import com.goafanti.core.mybatis.BaseMybatisDao;
  57. import com.goafanti.core.mybatis.page.Pagination;
  58. import com.goafanti.core.shiro.token.TokenManager;
  59. import com.goafanti.demand.bo.DemandAchievementListBo;
  60. import com.goafanti.portal.bo.AchievementDetailBo;
  61. import com.goafanti.portal.bo.AchievementObject;
  62. import com.goafanti.portal.bo.AchievementPortalDetailBo;
  63. import com.goafanti.portal.bo.AchievementPortalSimilarListBo;
  64. import com.goafanti.portal.bo.AchievementSearchListBo;
  65. import com.goafanti.portal.bo.BoutiqueListBo;
  66. import com.goafanti.portal.bo.InternationalListBo;
  67. @Service
  68. public class AchievementServiceImpl extends BaseMybatisDao<AchievementMapper> implements AchievementService {
  69. @Autowired
  70. private AchievementMapper achievementMapper;
  71. @Autowired
  72. private UserRoleMapper userRoleMapper;
  73. @Autowired
  74. private NoticeMapper noticeMapper;
  75. @Autowired
  76. private AchievementKeywordMapper achievementKeywordMapper;
  77. @Autowired
  78. private AchievementDemandMapper achievementDemandMapper;
  79. @Autowired
  80. private DemandKeywordMapper demandKeywordMapper;
  81. @Autowired
  82. private AchievementDemandCountMapper achievementDemandCountMapper;
  83. @Autowired
  84. private UserIdentityMapper userIdentityMapper;
  85. @Autowired
  86. private OrganizationIdentityMapper organizationIdentityMapper;
  87. @Autowired
  88. private AchievementInterestMapper achievementInterestMapper;
  89. @Autowired
  90. private UserMapper userMapper;
  91. private static final Logger logger = LoggerFactory.getLogger(AchievementServiceImpl.class);
  92. @SuppressWarnings("unchecked")
  93. @Override
  94. public Pagination<AchievementListBo> listUserOwnerAchievement(Integer ownerType,String username, String ownerName, String ownerId,
  95. Integer auditStatus, Integer serialNumber, String name, String keyword, Integer category, Integer status,
  96. String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer releaseStatus, Integer pNo, Integer pSize,
  97. Integer boutique, Integer hot) {
  98. Map<String, Object> params = disposeParams(ownerType,username, ownerName, ownerId, auditStatus, serialNumber, name, keyword, category, status,
  99. releaseDateStartDate, releaseDateEndDate, createDateStartDate, createDateEndDate, releaseStatus, UserType.ORGANIZATION.getCode(),
  100. boutique,null, hot,null);
  101. if (pNo == null || pNo < 0) {
  102. pNo = 1;
  103. }
  104. if (pSize == null || pSize < 0 || pSize > 10) {
  105. pSize = 10;
  106. }
  107. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  108. params.put("adminId", TokenManager.getAdminId());
  109. }
  110. return (Pagination<AchievementListBo>) findPage("findUserOwnerAchievementListByPage",
  111. "findUserOwnerAchievementCount",params,
  112. pNo, pSize);
  113. }
  114. @SuppressWarnings("unchecked")
  115. @Override
  116. public Pagination<AchievementListBo> listOrgOwnerAchievement(Integer ownerType,String unitName, String ownerName, String ownerId,
  117. Integer auditStatus, Integer serialNumber, String name, String keyword, Integer category, Integer status,
  118. String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer releaseStatus, String internationalFlag,Integer pNo, Integer pSize,
  119. Integer boutique, Integer hot,String recordPerson) {
  120. Map<String, Object> params = disposeParams(ownerType,unitName, ownerName, ownerId, auditStatus, serialNumber, name, keyword, category, status,
  121. releaseDateStartDate, releaseDateEndDate, createDateStartDate, createDateEndDate, releaseStatus, UserType.ORGANIZATION.getCode(),
  122. boutique,internationalFlag, hot,recordPerson);
  123. if (pNo == null || pNo < 0) {
  124. pNo = 1;
  125. }
  126. if (pSize == null || pSize < 0 || pSize > 10) {
  127. pSize = 10;
  128. }
  129. return (Pagination<AchievementListBo>) findPage("findOrgOwnerAchievementListByPage",
  130. "findOrgOwnerAchievementCount",params,pNo, pSize);
  131. }
  132. @Override
  133. public void saveAchievement(Achievement a, String[] keywords) {
  134. a.setId(UUID.randomUUID().toString());
  135. a.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  136. Calendar now = Calendar.getInstance();
  137. now.set(Calendar.MILLISECOND, 0);
  138. if (TokenManager.getToken() instanceof Admin) {
  139. a.setTechBrokerId(TokenManager.getAdminId());
  140. }
  141. a.setReleaseStatus(AchievementReleaseStatus.UNRELEASE.getCode());
  142. if (AchievementAuditStatus.SUBMIT.getCode().equals(a.getAuditStatus())) {
  143. createAuditorNotice(a);
  144. } else {
  145. a.setAuditStatus(AchievementAuditStatus.CREATE.getCode());
  146. }
  147. Integer ownerType = a.getOwnerType();
  148. String ownerMobile = a.getOwnerMobile();
  149. String ownerName = a.getOwnerName();
  150. String ownerId = "";
  151. if (TokenManager.getToken() instanceof User) {
  152. a.setOwnerId(TokenManager.getUserId());
  153. User u=userMapper.selectByPrimaryKey(TokenManager.getUserId());
  154. if (null != u) {
  155. ownerId = u.getId();
  156. if(ownerType == null) ownerType = u.getType();
  157. if(StringUtils.isBlank(ownerMobile)) ownerMobile = u.getMobile();
  158. if(StringUtils.isBlank(ownerName)) ownerName = u.getNickname();
  159. // 如果是单位客户 -查询单位客户的邮件 和通讯地址、证件号码
  160. //TODO
  161. }
  162. }
  163. a.setCreateTime(now.getTime());
  164. a.setOwnerType(ownerType);
  165. a.setOwnerMobile(ownerMobile);
  166. a.setOwnerName(ownerName);
  167. a.setOrgId(ownerId);
  168. achievementMapper.insert(a);
  169. disposeAchievementKeyword(keywords, a, false);
  170. }
  171. @Override
  172. public int updateAchievement(Achievement a, String[] keywords, Integer switchSign) {
  173. if (AchievementAuditStatus.SUBMIT.getCode().equals(a.getAuditStatus())) {
  174. createAuditorNotice(a);
  175. }
  176. disposeAchievementKeyword(keywords, a, true);
  177. achievementMapper.updateByPrimaryKeySelective(a);
  178. if (null != switchSign && AchievementSwitchSign.CLOSE.getCode().equals(switchSign)) {
  179. achievementMapper.updateOwnerId(a.getId());
  180. }
  181. return 1;
  182. }
  183. @Override
  184. public Achievement selectByPrimaryKey(String id) {
  185. return achievementMapper.selectByPrimaryKey(id);
  186. }
  187. @Override
  188. public int deleteByPrimaryKey(List<String> id) {
  189. achievementKeywordMapper.batchDeleteByAchievementIds(id);
  190. achievementDemandMapper.batchDeleteByAchievementIds(id);
  191. for (String s : id) {
  192. Achievement a = achievementMapper.selectByPrimaryKey(s);
  193. if (null != a && AchievementAuditStatus.AUDITED.getCode().equals(a.getAuditStatus())
  194. && StringUtils.isNotBlank(a.getOwnerId())) {
  195. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(a.getOwnerId());
  196. if (null != adc) {
  197. adc.setAchievementCount(adc.getAchievementCount() - 1);
  198. if (adc.getAchievementCount() < 0) {
  199. adc.setAchievementCount(0);
  200. }
  201. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  202. }
  203. }
  204. }
  205. return achievementMapper.batchDeleteByPrimaryKey(id);
  206. }
  207. @SuppressWarnings("unchecked")
  208. @Override
  209. public Pagination<AchievementListBo> listUserAchievement(Integer auditStatus, Integer serialNumber, String name,
  210. String keyword, Integer category, Integer ownerType, Integer status, String releaseDateStartDate,
  211. String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer releaseStatus, Integer pNo, Integer pSize) {
  212. if (pNo == null || pNo < 0) {
  213. pNo = 1;
  214. }
  215. if (pSize == null || pSize < 0 || pSize > 10) {
  216. pSize = 10;
  217. }
  218. return (Pagination<AchievementListBo>) findPage("findAchievementListByPage", "findAchievementCount",
  219. disposeParams(ownerType,null, null, TokenManager.getUserId(), auditStatus, serialNumber, name, keyword, category,
  220. status, releaseDateStartDate, releaseDateEndDate,createDateStartDate,createDateEndDate, releaseStatus, null, null,null, null,null),
  221. pNo, pSize);
  222. }
  223. private Map<String, Object> disposeParams(Integer ownerType,String username, String ownerName, String ownerId, Integer auditStatus,
  224. Integer serialNumber, String name, String keyword, Integer category, Integer status,
  225. String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer releaseStatus, Integer type,
  226. Integer boutique,String internationalFlag, Integer hot,String recordPerson) {
  227. Map<String, Object> params = new HashMap<>();
  228. Date rStart = null;
  229. Date rEnd = null;
  230. Date cStart = null;
  231. Date cEnd = null;
  232. if (null != ownerType) {
  233. params.put("ownerType", ownerType);
  234. }
  235. if (null != recordPerson) {
  236. params.put("recordPerson", recordPerson);
  237. }
  238. if (!StringUtils.isBlank(releaseDateStartDate)) {
  239. try {
  240. rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
  241. } catch (ParseException e) {
  242. }
  243. }
  244. if (!StringUtils.isBlank(releaseDateEndDate)) {
  245. try {
  246. rEnd = DateUtils.addDays(DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD), 1);
  247. } catch (ParseException e) {
  248. }
  249. }
  250. if (!StringUtils.isBlank(createDateStartDate)) {
  251. try {
  252. cStart = DateUtils.parseDate(createDateStartDate, AFTConstants.YYYYMMDD);
  253. } catch (ParseException e) {
  254. }
  255. }
  256. if (!StringUtils.isBlank(createDateEndDate)) {
  257. try {
  258. cEnd = DateUtils.addDays(DateUtils.parseDate(createDateEndDate, AFTConstants.YYYYMMDD), 1);
  259. } catch (ParseException e) {
  260. }
  261. }
  262. if (StringUtils.isNotBlank(ownerName)) {
  263. params.put("ownerName", ownerName);
  264. }
  265. if (null != type && StringUtils.isNotBlank(username)) {
  266. if (UserType.PERSONAL.getCode().equals(type)) {
  267. params.put("username", username);
  268. } else {
  269. params.put("unitName", username);
  270. }
  271. }
  272. if (null != rStart) {
  273. params.put("rStart", rStart);
  274. }
  275. if (null != rEnd) {
  276. params.put("rEnd", rEnd);
  277. }
  278. if (null != cStart) {
  279. params.put("cStart", cStart);
  280. }
  281. if (null != cEnd) {
  282. params.put("cEnd", cEnd);
  283. }
  284. if (null != auditStatus) {
  285. params.put("auditStatus", auditStatus);
  286. }
  287. if (!StringUtils.isBlank(ownerId)) {
  288. params.put("ownerId", ownerId);
  289. }
  290. if (null != serialNumber) {
  291. params.put("serialNumber", serialNumber);
  292. }
  293. if (!StringUtils.isBlank(name)) {
  294. params.put("name", name);
  295. }
  296. if (!StringUtils.isBlank(keyword)) {
  297. params.put("keyword", keyword);
  298. }
  299. if (null != category) {
  300. params.put("category", category);
  301. }
  302. if (null != status) {
  303. params.put("status", status);
  304. }
  305. if (null != releaseStatus) {
  306. params.put("releaseStatus", releaseStatus);
  307. }
  308. if (null != boutique) {
  309. params.put("boutique", boutique);
  310. }
  311. if (null != hot) {
  312. params.put("hot", hot);
  313. }
  314. if (null != internationalFlag) {
  315. params.put("internationalFlag", internationalFlag);
  316. }
  317. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.AUDITORADMIN)) {
  318. params.put("techBrokerId", TokenManager.getAdminId());
  319. }
  320. return params;
  321. }
  322. @Override
  323. public int updateAuditAchievement(Achievement a, String techBroderId, Integer auditStatus) {
  324. a.setAuditStatus(auditStatus);
  325. if (AchievementAuditStatus.AUDITED.getCode().equals(auditStatus)) {
  326. Calendar now = Calendar.getInstance();
  327. now.set(Calendar.MILLISECOND, 0);
  328. a.setReleaseDate(now.getTime());
  329. a.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  330. a.setTechBrokerId(techBroderId);
  331. if (StringUtils.isNotBlank(a.getKeyword())) {
  332. String[] keywords = a.getKeyword().trim().split(",|,");
  333. disposeAchievementKeyword(keywords, a, false);
  334. }
  335. String ownerId = a.getOwnerId();
  336. if (StringUtils.isNotBlank(ownerId)) {
  337. if (UserType.PERSONAL.getCode().equals(a.getOwnerType())) {
  338. UserIdentity ui = userIdentityMapper.selectUserIdentityByUserId(ownerId);
  339. if (null != ui) {
  340. a.setOwnerName(ui.getUsername());
  341. }
  342. } else if (UserType.ORGANIZATION.getCode().equals(a.getOwnerType())) {
  343. OrganizationIdentity oi = organizationIdentityMapper.selectOrgIdentityByUserId(ownerId);
  344. if (null != oi) {
  345. a.setOwnerName(oi.getUnitName());
  346. }
  347. }
  348. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(ownerId);
  349. if (null == adc) {
  350. AchievementDemandCount achievementDemandCount = new AchievementDemandCount();
  351. achievementDemandCount.setId(UUID.randomUUID().toString());
  352. achievementDemandCount.setUid(ownerId);
  353. achievementDemandCount.setAchievementCount(AFTConstants.ACHIEVEMENT_DEMAND_FIRST_COUNT);
  354. achievementDemandCount.setDemandCount(AFTConstants.ACHIEVEMENT_DEMAND_INIT_COUNT);
  355. achievementDemandCountMapper.insert(achievementDemandCount);
  356. } else {
  357. adc.setAchievementCount(adc.getAchievementCount() + 1);
  358. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  359. }
  360. }
  361. } else {
  362. a.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  363. }
  364. createTechBorkerNotice(a);
  365. return achievementMapper.updateByPrimaryKeySelective(a);
  366. }
  367. @Override
  368. public int updateReleaseStatus(Achievement a) {
  369. a.setAuditStatus(AchievementAuditStatus.AUDITED.getCode());
  370. if(a.getReleaseStatus()==1){
  371. Calendar now = Calendar.getInstance();
  372. now.set(Calendar.MILLISECOND, 0);
  373. a.setReleaseDate(now.getTime());
  374. }
  375. achievementDemandMapper.deleteByAchievementId(a.getId());
  376. achievementKeywordMapper.batchDeleteByAchievementId(a.getId());
  377. int i=0;
  378. i=achievementMapper.updateByPrimaryKeySelective(a);
  379. if (StringUtils.isNotBlank(a.getOwnerId())) {
  380. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(a.getOwnerId());
  381. if (null != adc) {
  382. adc.setAchievementCount(adc.getAchievementCount() - 1);
  383. if (adc.getAchievementCount() < 0) {
  384. adc.setAchievementCount(0);
  385. }
  386. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  387. }
  388. }
  389. return i;
  390. }
  391. @Override
  392. public AchievementUserOwnerDetailBo selectAppUserOwnerDetail(String id) {
  393. AchievementUserOwnerDetailBo a=achievementMapper.selectUserOwnerDetail(id);
  394. int i=achievementMapper.countInterest(a.getId());
  395. a.setCountInterest(String.valueOf(i));
  396. String uid=TokenManager.getUserId();
  397. if(TokenManager.isLogin()&&achievementInterestMapper.checkUidAndDid(uid,id)>0){
  398. a.setInterest("1");
  399. }else {
  400. a.setInterest("0");
  401. }
  402. return a;
  403. }
  404. @Override
  405. public AchievementOrgOwnerDetailBo selectOrgOwnerDetail(String id) {
  406. return achievementMapper.selectOrgOwnerDetail(id);
  407. }
  408. @Override
  409. public AchievementUserOwnerDetailBo selectUserOwnerDetail(String id) {
  410. return achievementMapper.selectUserOwnerDetail(id);
  411. }
  412. @Override
  413. public List<DemandAchievementListBo> selectAchievementDemandListByAchievementId(String id) {
  414. return achievementDemandMapper.selectAchievementDemandListByAchievementId(id);
  415. }
  416. @Override
  417. public void insertImport(List<AchievementImportBo> data) {
  418. if (null == data || data.isEmpty()) {
  419. return;
  420. }
  421. Achievement a = null;
  422. AchievementKeyword ak = null;
  423. List<Achievement> achievementList = new ArrayList<>();
  424. List<AchievementKeyword> AchievementKeywordList = new ArrayList<>();
  425. Calendar now = Calendar.getInstance();
  426. now.set(Calendar.MILLISECOND, 0);
  427. String techBrokerId = TokenManager.hasRole(AFTConstants.TECHBROKER) ? TokenManager.getAdminId() : null;
  428. for (AchievementImportBo bo : data) {
  429. a = new Achievement();
  430. BeanUtils.copyProperties(bo, a);
  431. a.setId(UUID.randomUUID().toString());
  432. a.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  433. a.setCreateTime(now.getTime());
  434. a.setAuditStatus(AchievementAuditStatus.INAUDIT.getCode());
  435. a.setReleaseStatus(AchievementReleaseStatus.UNRELEASE.getCode());
  436. a.setTechBrokerId(techBrokerId);
  437. List<String> keywordsList = bo.getKeywords();
  438. if (null != keywordsList && keywordsList.size() > 0) {
  439. for (String s : keywordsList) {
  440. if (!StringUtils.isBlank(s)) {
  441. ak = new AchievementKeyword();
  442. ak.setAchievementId(a.getId());
  443. ak.setKeyword(s.trim());
  444. ak.setId(UUID.randomUUID().toString());
  445. AchievementKeywordList.add(ak);
  446. }
  447. }
  448. }
  449. achievementList.add(a);
  450. }
  451. achievementMapper.insertBatch(achievementList);
  452. achievementKeywordMapper.insertBatch(AchievementKeywordList);
  453. }
  454. @SuppressWarnings("unchecked")
  455. @Override
  456. public Pagination<AchievementSearchListBo> listAchievementSearchList(String url,String keyword, Integer dataCategory,
  457. Integer category, Integer fieldA, String transferMode, Integer pNo, Integer pSize, Integer dateSort,
  458. String upperPrice, String lowerPrice,Integer internationalFlag) {
  459. Map<String, Object> params = new HashMap<>();
  460. if (!StringUtils.isBlank(url)) {
  461. params.put("url", url);
  462. }
  463. if (!StringUtils.isBlank(keyword)) {
  464. params.put("keyword", keyword);
  465. }
  466. if (null != dataCategory) {
  467. params.put("dataCategory", dataCategory);
  468. }
  469. if (null != category) {
  470. params.put("category", category);
  471. }
  472. if (null != fieldA) {
  473. params.put("fieldA", fieldA);
  474. }
  475. if (!StringUtils.isBlank(transferMode)) {
  476. params.put("transferMode", transferMode);
  477. }
  478. if (dateSort != null) {
  479. params.put("dateSort", dateSort);
  480. }
  481. if (upperPrice != null) {
  482. params.put("upperPrice", upperPrice);
  483. }
  484. if (lowerPrice != null) {
  485. params.put("lowerPrice", lowerPrice);
  486. }
  487. if (null !=internationalFlag ) {
  488. params.put("internationalFlag", internationalFlag);
  489. }
  490. if (pNo == null || pNo < 0) {
  491. pNo = 1;
  492. }
  493. if (pSize == null || pSize < 0 || pSize > 20) {
  494. pSize = 20;
  495. }
  496. Pagination<AchievementSearchListBo> result = (Pagination<AchievementSearchListBo>) findPage(
  497. "findSearchAchievementListByPage", "findSearchAchievementCount", params, pNo, pSize);
  498. List<AchievementSearchListBo> AchievementSearchList = (List<AchievementSearchListBo>) result.getList();
  499. for (int i = 0; i < AchievementSearchList.size(); i++) {
  500. String introduction = AchievementSearchList.get(i).getIntroduction();
  501. if (introduction != null)
  502. introduction = introduction.length() > 20 ? introduction.substring(0, 20) + "... ..." : introduction;
  503. }
  504. return result;
  505. }
  506. @Override
  507. public AchievementDetailBo selectAchievementSearchDetail(String uid, String id) {
  508. return achievementMapper.selectAchievementSearchDetail(uid, id);
  509. }
  510. private void createTechBorkerNotice(Achievement a) {
  511. // noticeMapper.insert(disposeNotice(a, null));
  512. }
  513. // 给所有审核员发送审核通知
  514. private void createAuditorNotice(Achievement a) {
  515. List<String> ids = userRoleMapper.listAuditor();
  516. List<Notice> list = new ArrayList<>();
  517. if (null != ids && ids.size() > 0) {
  518. for (String s : ids) {
  519. list.add(disposeNotice(a, s));
  520. }
  521. noticeMapper.insertBatch(list);
  522. }
  523. }
  524. private Notice disposeNotice(Achievement a, String aid) {
  525. Notice n = new Notice();
  526. Calendar now = Calendar.getInstance();
  527. now.set(Calendar.MILLISECOND, 0);
  528. n.setId(UUID.randomUUID().toString());
  529. n.setCreateTime(now.getTime());
  530. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  531. n.setRid(a.getId());
  532. if (StringUtils.isBlank(aid)) {
  533. n.setAid(a.getTechBrokerId());
  534. if (UserType.PERSONAL.getCode().equals(a.getOwnerType())) {
  535. n.setContent("编号" + a.getSerialNumber() + NoticeStatus.PERSONALACHIEVEMENTT.getDesc() + " "
  536. + (AchievementAuditStatus.AUDITED.getCode().equals(a.getAuditStatus())
  537. ? AchievementAuditStatus.AUDITED.getDesc()
  538. : AchievementAuditStatus.UNAUDITED.getDesc()));
  539. n.setNoticeType(NoticeStatus.PERSONALACHIEVEMENTT.getCode());
  540. } else if (UserType.ORGANIZATION.getCode().equals(a.getOwnerType())) {
  541. n.setContent("编号" + a.getSerialNumber() + NoticeStatus.ORGANIZATIONACHIEVEMENT.getDesc() + " "
  542. + (AchievementAuditStatus.AUDITED.getCode().equals(a.getAuditStatus())
  543. ? AchievementAuditStatus.AUDITED.getDesc()
  544. : AchievementAuditStatus.UNAUDITED.getDesc()));
  545. n.setNoticeType(NoticeStatus.ORGANIZATIONACHIEVEMENT.getCode());
  546. }
  547. } else {
  548. n.setAid(aid);
  549. if (UserType.PERSONAL.getCode().equals(a.getOwnerType())) {
  550. n.setContent(
  551. NoticeStatus.PERSONALACHIEVEMENTT.getDesc() + " " + AchievementAuditStatus.SUBMIT.getDesc());
  552. n.setNoticeType(NoticeStatus.PERSONALACHIEVEMENTT.getCode());
  553. } else if (UserType.ORGANIZATION.getCode().equals(a.getOwnerType())) {
  554. n.setContent(
  555. NoticeStatus.ORGANIZATIONACHIEVEMENT.getDesc() + " " + AchievementAuditStatus.SUBMIT.getDesc());
  556. n.setNoticeType(NoticeStatus.ORGANIZATIONACHIEVEMENT.getCode());
  557. }
  558. }
  559. return n;
  560. }
  561. private void disposeAchievementKeyword(String[] keywords, Achievement a, boolean delete) {
  562. if (null != keywords && keywords.length > 0) {
  563. if (delete) {
  564. achievementKeywordMapper.batchDeleteByAchievementId(a.getId());
  565. }
  566. List<AchievementKeyword> list = new ArrayList<>();
  567. AchievementKeyword ak = null;
  568. for (int i = 0; i < keywords.length; i++) {
  569. ak = new AchievementKeyword();
  570. ak.setId(UUID.randomUUID().toString());
  571. ak.setAchievementId(a.getId());
  572. ak.setKeyword(keywords[i].trim());
  573. list.add(ak);
  574. }
  575. achievementKeywordMapper.insertBatch(list);
  576. }
  577. }
  578. @Override
  579. public int updateMatchDemand(Achievement a) {
  580. achievementDemandMapper.deleteByAchievementId(a.getId());// 删除之前匹配单
  581. List<AchievementKeyword> achievement = achievementKeywordMapper.selectKeywordsByAchievementId(a.getId());
  582. if (null != achievement && achievement.size() > 0) {
  583. List<String> keyword = new ArrayList<>();
  584. for (AchievementKeyword k : achievement) {
  585. if (!StringUtils.isBlank(k.getKeyword())) {
  586. keyword.add(k.getKeyword());
  587. }
  588. }
  589. List<AchievementDemand> list = demandKeywordMapper.selectAchievementDemand(keyword);
  590. if (null != list && list.size() > 0) {
  591. for (AchievementDemand ad : list) {
  592. ad.setAchievementId(a.getId());
  593. }
  594. return achievementDemandMapper.insertBatch(list);
  595. }
  596. }
  597. return 0;
  598. }
  599. @SuppressWarnings("unchecked")
  600. @Override
  601. public Pagination<AchievementPartnerListBo> listPartnerAchievement(String ownerId, Integer pNo, Integer pSize) {
  602. Map<String, Object> params = new HashMap<>();
  603. params.put("ownerId", ownerId);
  604. if (pNo == null || pNo < 0) {
  605. pNo = 1;
  606. }
  607. if (pSize == null || pSize < 0 || pSize > 10) {
  608. pSize = 10;
  609. }
  610. return (Pagination<AchievementPartnerListBo>) findPage("findPartnerAchievementListByPage",
  611. "findPartnerAchievementCount", params, pNo, pSize);
  612. }
  613. @Override
  614. public AchievementPortalDetailBo findUserPortalAchievementDetail(String id) {
  615. return achievementMapper.findUserPortalAchievementDetail(id, TokenManager.getUserId());
  616. }
  617. @Override
  618. public AchievementPortalDetailBo findOrgPortalAchievementDetail(String id) {
  619. return achievementMapper.findOrgPortalAchievementDetail(id, TokenManager.getUserId());
  620. }
  621. @Override
  622. public List<AchievementPortalSimilarListBo> findByFieldA(Integer fieldA, String id, Integer type) {
  623. if (UserType.PERSONAL.getCode().equals(type)) {
  624. return achievementMapper.findUserPortalSimilarByFieldA(fieldA, id);
  625. } else if (UserType.ORGANIZATION.getCode().equals(type)) {
  626. return achievementMapper.findOrgPortalSimilarByFieldA(fieldA, id);
  627. }
  628. return null;
  629. }
  630. @Override
  631. public int updateByPrimaryKeySelective(Achievement a) {
  632. return achievementMapper.updateByPrimaryKey(a);
  633. }
  634. @Override
  635. @Cacheable(value = "internationalAchievementList", key = "'internationalAchievementList:'+#internationalAchievementCacheKey")
  636. public List<InternationalListBo> selectInternationalAchievement(Integer internationalAchievementCacheKey) {
  637. return achievementMapper.selectInternationalAchievement();
  638. }
  639. @CacheEvict(value = "internationalAchievementList", allEntries = true)
  640. public void cleanInternationalAchievement() {
  641. LoggerUtils.debug(logger, "清除国际化技术列表");
  642. }
  643. @Override
  644. public Achievement selectAchievementDetail(String id) {
  645. return achievementMapper.selectByPrimaryKey(id);
  646. }
  647. @SuppressWarnings("unchecked")
  648. @Override
  649. public Pagination<BoutiqueListBo> boutiqueSearchList(Integer dataCategory, Integer category, Integer fieldA,
  650. Integer pNo, Integer pSize) {
  651. Map<String, Object> params = new HashMap<>();
  652. if (null != dataCategory) {
  653. params.put("dataCategory", dataCategory);
  654. }
  655. if (null != category) {
  656. params.put("category", category);
  657. }
  658. if (null != fieldA) {
  659. params.put("fieldA", fieldA);
  660. }
  661. return (Pagination<BoutiqueListBo>) findPage("findBoutiqueListByPage", "findBoutiqueCount", params, pNo, pSize);
  662. }
  663. @Override
  664. public List<AchievementListBo> getAchievement(Integer boutique) {
  665. return achievementMapper.listAchievement();
  666. }
  667. @Override
  668. public List<AchievementListBo> getPerhapLike() {
  669. return achievementMapper.selectCsutomerLike(); //查询出猜你喜欢
  670. }
  671. @Override
  672. public List<AchievementPartnerListBo> findPartnerAchievementList(String uid) {
  673. return achievementMapper.findPartnerAchievementListByPage(uid);
  674. }
  675. @SuppressWarnings("unchecked")
  676. @Override
  677. public Pagination<AchievementPartnerListBo> listAppUserAchievement(Integer auditStatus, Integer serialNumber,
  678. String name, String keyword,Integer dataCategory, Integer category, Integer ownerType, Integer status,
  679. String releaseDateStartDate, String releaseDateEndDate, Integer releaseStatus,String ownerId,Integer fieldA, Integer pNo, Integer pSize) {
  680. if (pNo == null || pNo < 0) {
  681. pNo = 1;
  682. }
  683. if (pSize == null || pSize < 0 || pSize > 10) {
  684. pSize = 10;
  685. }
  686. Map<String, Object> params=disposeParams(ownerType,null, null, ownerId, auditStatus, serialNumber, name, keyword, category,
  687. status, releaseDateStartDate, releaseDateEndDate,null, null, releaseStatus, null, null,null, null,null);
  688. if (null!=fieldA) {
  689. params.put("fieldA", fieldA);
  690. }
  691. if (null != dataCategory) {
  692. params.put("dataCategory", dataCategory);
  693. }
  694. Pagination<AchievementPartnerListBo> p=(Pagination<AchievementPartnerListBo>) findPage("findAppAchievementListByPage", "findAppAchievementCount",
  695. params,pNo, pSize);
  696. return p;
  697. }
  698. @SuppressWarnings("unchecked")
  699. @Override
  700. public Pagination<AchievementPartnerListBo> listAppMyAchievement(Integer pNo, Integer pSize) {
  701. if (pNo == null || pNo < 0) {
  702. pNo = 1;
  703. }
  704. if (pSize == null || pSize < 0 || pSize > 10) {
  705. pSize = 10;
  706. }
  707. Map<String, Object> params = new HashMap<>();
  708. if (StringUtils.isNotBlank(TokenManager.getUserId())) {
  709. params.put("ownerId", TokenManager.getUserId());
  710. }
  711. //params.put("ownerId", "46433140-0a90-471e-a32f-6bc89c562e3d");
  712. return (Pagination<AchievementPartnerListBo>) findPage("findMyAchievementListByPage", "findMyAchievementCount",
  713. params,pNo, pSize);
  714. }
  715. @SuppressWarnings("unchecked")
  716. @Override
  717. public Pagination<AchievementListBo> listMyAchievement(String techBrokerId,Integer ownerType,String unitName, String ownerName, String ownerId,
  718. Integer auditStatus, Integer serialNumber, String name, String keyword, Integer category, Integer status,
  719. String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer releaseStatus, String internationalFlag,Integer pNo, Integer pSize,
  720. Integer boutique, Integer hot) {
  721. Map<String, Object> params = disposeParams(ownerType,unitName, ownerName, ownerId, auditStatus, serialNumber, name, keyword, category, status,
  722. releaseDateStartDate, releaseDateEndDate, createDateStartDate, createDateEndDate, releaseStatus, UserType.ORGANIZATION.getCode(),
  723. boutique,internationalFlag, hot,null);
  724. if (pNo == null || pNo < 0) {
  725. pNo = 1;
  726. }
  727. if (pSize == null || pSize < 0 || pSize > 10) {
  728. pSize = 10;
  729. }
  730. if (null != techBrokerId) {
  731. params.put("techBrokerId", techBrokerId);
  732. }
  733. return (Pagination<AchievementListBo>) findPage("findMyyAchievementListByPage",
  734. "findMyyAchievementCount",params,pNo, pSize);
  735. }
  736. @SuppressWarnings("unchecked")
  737. @Override
  738. public Pagination<AchievementListBo> listManageAchievement(String techBrokerId,Integer ownerType,String unitName, String ownerName, String ownerId,
  739. Integer auditStatus, Integer serialNumber, String name, String keyword, Integer category, Integer status,
  740. String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer releaseStatus, String internationalFlag,Integer pNo, Integer pSize,
  741. Integer boutique, Integer hot,String recordPerson) {
  742. Map<String, Object> params = disposeParams(ownerType,unitName, ownerName, ownerId, auditStatus, serialNumber, name, keyword, category, status,
  743. releaseDateStartDate, releaseDateEndDate, createDateStartDate, createDateEndDate, releaseStatus, UserType.ORGANIZATION.getCode(),
  744. boutique,internationalFlag, hot,recordPerson);
  745. if (pNo == null || pNo < 0) {
  746. pNo = 1;
  747. }
  748. if (pSize == null || pSize < 0 || pSize > 10) {
  749. pSize = 10;
  750. }
  751. if (null != techBrokerId) {
  752. params.put("techBrokerId", techBrokerId);
  753. }
  754. return (Pagination<AchievementListBo>) findPage("findManageAchievementListByPage",
  755. "findManageAchievementCount",params,pNo, pSize);
  756. }
  757. @Override
  758. public int saveAppAchievement(Achievement a, String[] keywords) {
  759. a.setId(UUID.randomUUID().toString());
  760. a.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  761. Calendar now = Calendar.getInstance();
  762. now.set(Calendar.MILLISECOND, 0);
  763. if (TokenManager.getToken() instanceof Admin) {
  764. a.setTechBrokerId(TokenManager.getAdminId());
  765. }
  766. a.setReleaseStatus(AchievementReleaseStatus.UNRELEASE.getCode());
  767. if (AchievementAuditStatus.SUBMIT.getCode().equals(a.getAuditStatus())) {
  768. createAuditorNotice(a);
  769. } else {
  770. a.setAuditStatus(AchievementAuditStatus.INAUDIT.getCode());
  771. }
  772. if (null!=TokenManager.getUserId()) {
  773. a.setOwnerId(TokenManager.getUserId());
  774. User u=userMapper.selectByPrimaryKey(TokenManager.getUserId());
  775. if (null!=u.getType()) {
  776. a.setOwnerType(u.getType());
  777. }if (StringUtils.isNotBlank(u.getMobile())) {
  778. a.setOwnerMobile(u.getMobile());
  779. }if (StringUtils.isNotBlank(u.getNickname())) {
  780. a.setOwnerName(u.getNickname());
  781. }
  782. }
  783. a.setDataCategory(0);
  784. a.setCreateTime(now.getTime());
  785. disposeAchievementKeyword(keywords, a, false);
  786. return achievementMapper.insert(a);
  787. }
  788. @Override
  789. public List<AchievementObject> recentAchievements(int size, String url, String showLocation) {
  790. // TODO Auto-generated method stub
  791. return achievementMapper.getRecentAchievements(size,url,showLocation);
  792. }
  793. @Override
  794. public List<AchievementObject> getHotAchievements(int size, String url, String showLocation) {
  795. // TODO Auto-generated method stub
  796. return achievementMapper.getHotAchievements( size, url, showLocation);
  797. }
  798. @Override
  799. public List<AchievementObject> getPatentList(int size, String url, String showLocation) {
  800. // TODO Auto-generated method stub
  801. return achievementMapper.getPatentList(size,url,showLocation);
  802. }
  803. @Override
  804. public List<AchievementObject> getPracticalTechnologys(int size, String url, String showLocation) {
  805. // TODO Auto-generated method stub
  806. return achievementMapper.getPracticalTechnologys(size,url,showLocation);
  807. }
  808. @Override
  809. public List<PolicyEntity> getIntellectualProperty(int size) {
  810. // TODO Auto-generated method stub
  811. return achievementMapper.getIntellectualProperty(size);
  812. }
  813. @Override
  814. public AchievementObject getAchievementDetail(String id, Integer type) {
  815. // TODO Auto-generated method stub
  816. return achievementMapper.getAchievementDetail(id,type);
  817. }
  818. @Override
  819. public List<AchievementObject> getBoutiquePatent(int size) {
  820. // TODO Auto-generated method stub
  821. return achievementMapper.getBoutiquePatent( size);
  822. }
  823. @Override
  824. public List<AchievementObject> guessYouLike(int size) {
  825. // TODO Auto-generated method stub
  826. return achievementMapper.guessYouLike(size);
  827. }
  828. }