AchievementServiceImpl.java 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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.apache.poi.ss.usermodel.Cell;
  12. import org.apache.poi.ss.usermodel.CellType;
  13. import org.apache.poi.ss.usermodel.Row;
  14. import org.apache.poi.ss.usermodel.Sheet;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.BeanUtils;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Value;
  20. import org.springframework.cache.annotation.CacheEvict;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.web.multipart.MultipartFile;
  23. import com.goafanti.achievement.bo.AchievementEntity;
  24. import com.goafanti.achievement.bo.AchievementImportBo;
  25. import com.goafanti.achievement.bo.AchievementOrgOwnerDetailBo;
  26. import com.goafanti.achievement.bo.AchievementPartnerListBo;
  27. import com.goafanti.achievement.bo.AchievementUserOwnerDetailBo;
  28. import com.goafanti.achievement.service.AchievementService;
  29. import com.goafanti.common.bo.Error;
  30. import com.goafanti.common.bo.MyCollection;
  31. import com.goafanti.common.bo.PolicyEntity;
  32. import com.goafanti.common.constant.AFTConstants;
  33. import com.goafanti.common.constant.PageConstants;
  34. import com.goafanti.common.dao.AchievementDemandCountMapper;
  35. import com.goafanti.common.dao.AchievementDemandMapper;
  36. import com.goafanti.common.dao.AchievementKeywordMapper;
  37. import com.goafanti.common.dao.AchievementMapper;
  38. import com.goafanti.common.dao.AchievementPublishMapper;
  39. import com.goafanti.common.dao.BranchInformationMapper;
  40. import com.goafanti.common.dao.DemandKeywordMapper;
  41. import com.goafanti.common.dao.JtCollectSearchMapper;
  42. import com.goafanti.common.dao.NoticeMapper;
  43. import com.goafanti.common.dao.OrganizationIdentityMapper;
  44. import com.goafanti.common.dao.UserIdentityMapper;
  45. import com.goafanti.common.dao.UserMapper;
  46. import com.goafanti.common.dao.UserRoleMapper;
  47. import com.goafanti.common.enums.AchievementAuditStatus;
  48. import com.goafanti.common.enums.AchievementReleaseStatus;
  49. import com.goafanti.common.enums.AchievementSwitchSign;
  50. import com.goafanti.common.enums.DeleteStatus;
  51. import com.goafanti.common.enums.DemandReleaseStatus;
  52. import com.goafanti.common.enums.NoticeReadStatus;
  53. import com.goafanti.common.enums.NoticeStatus;
  54. import com.goafanti.common.enums.UserType;
  55. import com.goafanti.common.enums.collectType;
  56. import com.goafanti.common.error.BusinessException;
  57. import com.goafanti.common.model.Achievement;
  58. import com.goafanti.common.model.AchievementDemand;
  59. import com.goafanti.common.model.AchievementDemandCount;
  60. import com.goafanti.common.model.AchievementKeyword;
  61. import com.goafanti.common.model.AchievementPublish;
  62. import com.goafanti.common.model.Admin;
  63. import com.goafanti.common.model.JtCollectSearch;
  64. import com.goafanti.common.model.Notice;
  65. import com.goafanti.common.model.OrganizationIdentity;
  66. import com.goafanti.common.model.User;
  67. import com.goafanti.common.model.UserIdentity;
  68. import com.goafanti.common.utils.DateUtils;
  69. import com.goafanti.common.utils.FileUtils;
  70. import com.goafanti.common.utils.LoggerUtils;
  71. import com.goafanti.core.mybatis.BaseMybatisDao;
  72. import com.goafanti.core.mybatis.page.Pagination;
  73. import com.goafanti.core.shiro.token.TokenManager;
  74. import com.goafanti.demand.bo.DemandAchievementListBo;
  75. import com.goafanti.portal.bo.AchievementDetailBo;
  76. import com.goafanti.portal.bo.AchievementObject;
  77. import com.goafanti.portal.bo.AchievementPortalDetailBo;
  78. import com.goafanti.portal.bo.AchievementResultObject;
  79. @Service
  80. public class AchievementServiceImpl extends BaseMybatisDao<AchievementMapper> implements AchievementService {
  81. @Autowired
  82. private AchievementMapper achievementMapper;
  83. @Autowired
  84. private UserRoleMapper userRoleMapper;
  85. @Autowired
  86. private NoticeMapper noticeMapper;
  87. @Autowired
  88. private AchievementKeywordMapper achievementKeywordMapper;
  89. @Autowired
  90. private AchievementDemandMapper achievementDemandMapper;
  91. @Autowired
  92. private DemandKeywordMapper demandKeywordMapper;
  93. @Autowired
  94. private AchievementDemandCountMapper achievementDemandCountMapper;
  95. @Autowired
  96. private UserIdentityMapper userIdentityMapper;
  97. @Autowired
  98. private OrganizationIdentityMapper organizationIdentityMapper;
  99. @Autowired
  100. private UserMapper userMapper;
  101. @Autowired
  102. BranchInformationMapper branchInformationMapper;
  103. @Autowired
  104. AchievementPublishMapper achievementPublishMapper;
  105. @Autowired
  106. JtCollectSearchMapper jtCollectSearchMapper;
  107. @Value(value="${collect_flag}")
  108. private Boolean collectFlag ;
  109. private static final Logger logger = LoggerFactory.getLogger(AchievementServiceImpl.class);
  110. @Override
  111. public void saveAchievement(Achievement a, String[] keywords,List<String >webPages,List<String>appPages) {
  112. a.setId(UUID.randomUUID().toString());
  113. a.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  114. Calendar now = Calendar.getInstance();
  115. now.set(Calendar.MILLISECOND, 0);
  116. if (TokenManager.getToken() instanceof Admin) {
  117. a.setTechBrokerId(TokenManager.getAdminId());
  118. }
  119. a.setReleaseStatus(AchievementReleaseStatus.UNRELEASE.getCode());
  120. if (AchievementAuditStatus.SUBMIT.getCode()==a.getAuditStatus()) {
  121. createAuditorNotice(a);
  122. } else {
  123. a.setAuditStatus(AchievementAuditStatus.CREATE.getCode());
  124. }
  125. String ownerId = "";
  126. if (TokenManager.getToken() instanceof User) {
  127. a.setOwnerId(TokenManager.getUserId());
  128. User u=userMapper.selectByPrimaryKey(TokenManager.getUserId());
  129. if (null != u) {
  130. ownerId = u.getId();
  131. }
  132. }
  133. a.setCreateTime(now.getTime());
  134. a.setOrgId(ownerId);
  135. a.setInfoSources(1);
  136. achievementMapper.insert(a);
  137. disposeAchievementKeyword(keywords, a, false);
  138. disposeAchievementPublish(a,webPages,appPages,false);
  139. }
  140. private void disposeAchievementPublish(Achievement a,List<String> webPages,List<String> appPages,boolean delete){
  141. if(delete){
  142. if(null != webPages && webPages.size()>0){
  143. achievementPublishMapper.deleteByAchievementId(a.getId());
  144. }
  145. }
  146. AchievementPublish ap = null;
  147. String defaultPlatformId = branchInformationMapper.selectByDomain(PageConstants.DEFAULT_DOMAIN).getId();
  148. if(webPages != null && webPages.size()>0){
  149. for(String page: webPages){
  150. ap = new AchievementPublish();
  151. ap.setId(UUID.randomUUID().toString());
  152. ap.setAchievementId((a.getId()));
  153. ap.setPublisher(TokenManager.getUserId());
  154. ap.setPublisher("1");
  155. ap.setPublishTime(a.getReleaseDate()==null?new Date():a.getReleaseDate());
  156. ap.setPublishClient(PageConstants.WEB_PLATFORM);
  157. ap.setPublishPage(page);
  158. ap.setPublishPlatform(defaultPlatformId);
  159. ap.setIfTop(AFTConstants.NO);
  160. ap.setTopNumber(PageConstants.DEFAULT_TOP_NUMBER);
  161. ap.setShowNumber(PageConstants.DEFAULT_SHOW_NUMBER);
  162. achievementPublishMapper.insert(ap);
  163. }
  164. }
  165. if(appPages != null && appPages.size()>0){
  166. for(String page: appPages){
  167. ap = new AchievementPublish();
  168. ap.setId(UUID.randomUUID().toString());
  169. ap.setAchievementId(a.getId());
  170. ap.setPublisher(TokenManager.getUserId());
  171. ap.setPublishTime(a.getReleaseDate()==null?new Date():a.getReleaseDate());
  172. ap.setPublishClient(PageConstants.APP_PLATFORM);
  173. ap.setPublishPage(page);
  174. ap.setPublishPlatform(defaultPlatformId);
  175. ap.setIfTop(AFTConstants.NO);
  176. ap.setTopNumber(PageConstants.DEFAULT_TOP_NUMBER);
  177. ap.setShowNumber(PageConstants.DEFAULT_SHOW_NUMBER);
  178. achievementPublishMapper.insert(ap);
  179. }
  180. }
  181. }
  182. @Override
  183. public int updateAchievement(Achievement a, String[] keywords, Integer switchSign,List<String>webPages,List<String>appPages) {
  184. if (AchievementAuditStatus.SUBMIT.getCode().equals(a.getAuditStatus())) {
  185. createAuditorNotice(a);
  186. }
  187. disposeAchievementKeyword(keywords, a, true);
  188. disposeAchievementPublish(a,webPages,appPages,true);
  189. if (null != switchSign && AchievementSwitchSign.CLOSE.getCode().equals(switchSign)) {
  190. a.setOwnerId("");
  191. }
  192. achievementMapper.updateByPrimaryKeySelective(a);
  193. return 1;
  194. }
  195. @Override
  196. public Achievement selectByPrimaryKey(String id) {
  197. return achievementMapper.selectByPrimaryKey(id);
  198. }
  199. @Override
  200. public int deleteByPrimaryKey(List<String> id) {
  201. achievementKeywordMapper.batchDeleteByAchievementIds(id);
  202. achievementDemandMapper.batchDeleteByAchievementIds(id);
  203. achievementPublishMapper.batchDeleteByAchievementIds(id);
  204. for (String s : id) {
  205. Achievement a = achievementMapper.selectByPrimaryKey(s);
  206. if(collectFlag)jtCollectSearchMapper.deleteByrowId(s);
  207. if (null != a && AchievementAuditStatus.AUDITED.getCode().equals(a.getAuditStatus())
  208. && StringUtils.isNotBlank(a.getOwnerId())) {
  209. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(a.getOwnerId());
  210. if (null != adc) {
  211. adc.setAchievementCount(adc.getAchievementCount() - 1);
  212. if (adc.getAchievementCount() < 0) {
  213. adc.setAchievementCount(0);
  214. }
  215. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  216. }
  217. }
  218. }
  219. return achievementMapper.batchDeleteByPrimaryKey(id);
  220. }
  221. @SuppressWarnings("unchecked")
  222. @Override
  223. public Pagination<AchievementObject> listMyAchievement(Integer auditStatus, String name,Integer dataCategory,
  224. String startDate,String endDate, Integer pNo, Integer pSize) {
  225. Map<String,Object> params = new HashMap<>();
  226. params.put("ownerId", TokenManager.getUserId());
  227. if (null != startDate) params.put("startDate", startDate);
  228. if (null != endDate) params.put("endDate", endDate);
  229. if (null != auditStatus) params.put("auditStatus", auditStatus);
  230. if(null != dataCategory) params.put("dataCategory", dataCategory);
  231. if (!StringUtils.isBlank(name)) params.put("name", name);
  232. return (Pagination<AchievementObject>) findPage("listMyAchievementByPage", "listMyAchievementCount",params,
  233. pNo, pSize);
  234. }
  235. private Map<String, Object> disposeParams(Integer ownerType,String username, String ownerName, String ownerId, Integer auditStatus,
  236. Integer serialNumber, String name, String keyword, Integer category, Integer status,
  237. String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer releaseStatus, Integer type,
  238. Integer boutique,String internationalFlag, Integer hot,String recordPerson) {
  239. Map<String, Object> params = new HashMap<>();
  240. Date rStart = null;
  241. Date rEnd = null;
  242. Date cStart = null;
  243. Date cEnd = null;
  244. if (null != ownerType) {
  245. params.put("ownerType", ownerType);
  246. }
  247. if (null != recordPerson) {
  248. params.put("recordPerson", recordPerson);
  249. }
  250. if (!StringUtils.isBlank(releaseDateStartDate)) {
  251. try {
  252. rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
  253. } catch (ParseException e) {
  254. }
  255. }
  256. if (!StringUtils.isBlank(releaseDateEndDate)) {
  257. try {
  258. rEnd = DateUtils.addDays(DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD), 1);
  259. } catch (ParseException e) {
  260. }
  261. }
  262. if (!StringUtils.isBlank(createDateStartDate)) {
  263. try {
  264. cStart = DateUtils.parseDate(createDateStartDate, AFTConstants.YYYYMMDD);
  265. } catch (ParseException e) {
  266. }
  267. }
  268. if (!StringUtils.isBlank(createDateEndDate)) {
  269. try {
  270. cEnd = DateUtils.addDays(DateUtils.parseDate(createDateEndDate, AFTConstants.YYYYMMDD), 1);
  271. } catch (ParseException e) {
  272. }
  273. }
  274. if (StringUtils.isNotBlank(ownerName)) {
  275. params.put("ownerName", ownerName);
  276. }
  277. if (null != type && StringUtils.isNotBlank(username)) {
  278. if (UserType.PERSONAL.getCode().equals(type)) {
  279. params.put("username", username);
  280. } else {
  281. params.put("unitName", username);
  282. }
  283. }
  284. if (null != rStart) {
  285. params.put("rStart", rStart);
  286. }
  287. if (null != rEnd) {
  288. params.put("rEnd", rEnd);
  289. }
  290. if (null != cStart) {
  291. params.put("cStart", cStart);
  292. }
  293. if (null != cEnd) {
  294. params.put("cEnd", cEnd);
  295. }
  296. if (null != auditStatus) {
  297. params.put("auditStatus", auditStatus);
  298. }
  299. if (!StringUtils.isBlank(ownerId)) {
  300. params.put("ownerId", ownerId);
  301. }
  302. if (null != serialNumber) {
  303. params.put("serialNumber", serialNumber);
  304. }
  305. if (!StringUtils.isBlank(name)) {
  306. params.put("name", name);
  307. }
  308. if (!StringUtils.isBlank(keyword)) {
  309. params.put("keyword", keyword);
  310. }
  311. if (null != category) {
  312. params.put("category", category);
  313. }
  314. if (null != status) {
  315. params.put("status", status);
  316. }
  317. if (null != releaseStatus) {
  318. params.put("releaseStatus", releaseStatus);
  319. }
  320. if (null != boutique) {
  321. params.put("boutique", boutique);
  322. }
  323. if (null != hot) {
  324. params.put("hot", hot);
  325. }
  326. if (null != internationalFlag) {
  327. params.put("internationalFlag", internationalFlag);
  328. }
  329. return params;
  330. }
  331. @Override
  332. public int updateAuditAchievement(Achievement a, String techBroderId, Integer auditStatus) {
  333. a.setAuditStatus(auditStatus);
  334. if (AchievementAuditStatus.AUDITED.getCode().equals(auditStatus)) {
  335. Calendar now = Calendar.getInstance();
  336. now.set(Calendar.MILLISECOND, 0);
  337. a.setReleaseDate(now.getTime());
  338. a.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  339. a.setTechBrokerId(techBroderId);
  340. if (StringUtils.isNotBlank(a.getKeyword())) {
  341. String[] keywords = a.getKeyword().trim().split(",|,");
  342. disposeAchievementKeyword(keywords, a, false);
  343. }
  344. String ownerId = a.getOwnerId();
  345. if (StringUtils.isNotBlank(ownerId)) {
  346. if (UserType.PERSONAL.getCode().equals(a.getOwnerType())) {
  347. UserIdentity ui = userIdentityMapper.selectUserIdentityByUserId(ownerId);
  348. if (null != ui) {
  349. a.setOwnerName(ui.getUsername());
  350. }
  351. } else if (UserType.ORGANIZATION.getCode().equals(a.getOwnerType())) {
  352. OrganizationIdentity oi = organizationIdentityMapper.selectOrgIdentityByUserId(ownerId);
  353. if (null != oi) {
  354. a.setOwnerName(oi.getUnitName());
  355. }
  356. }
  357. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(ownerId);
  358. if (null == adc) {
  359. AchievementDemandCount achievementDemandCount = new AchievementDemandCount();
  360. achievementDemandCount.setId(UUID.randomUUID().toString());
  361. achievementDemandCount.setUid(ownerId);
  362. achievementDemandCount.setAchievementCount(AFTConstants.ACHIEVEMENT_DEMAND_FIRST_COUNT);
  363. achievementDemandCount.setDemandCount(AFTConstants.ACHIEVEMENT_DEMAND_INIT_COUNT);
  364. achievementDemandCountMapper.insert(achievementDemandCount);
  365. } else {
  366. adc.setAchievementCount(adc.getAchievementCount() + 1);
  367. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  368. }
  369. }
  370. } else {
  371. a.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
  372. }
  373. createTechBorkerNotice(a);
  374. return achievementMapper.updateByPrimaryKeySelective(a);
  375. }
  376. @Override
  377. public int updateReleaseStatus(Achievement a) {
  378. a.setAuditStatus(AchievementAuditStatus.REVOKE.getCode());
  379. // if(a.getReleaseStatus()==1){
  380. // Calendar now = Calendar.getInstance();
  381. // now.set(Calendar.MILLISECOND, 0);
  382. // a.setReleaseDate(now.getTime());
  383. // }
  384. achievementDemandMapper.deleteByAchievementId(a.getId());
  385. // achievementKeywordMapper.batchDeleteByAchievementId(a.getId());
  386. achievementPublishMapper.deleteByAchievementId(a.getId());
  387. int i=0;
  388. i=achievementMapper.updateByPrimaryKeySelective(a);
  389. if(collectFlag)
  390. jtCollectSearchMapper.deleteByrowId(a.getId());
  391. if (StringUtils.isNotBlank(a.getOwnerId())) {
  392. AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(a.getOwnerId());
  393. if (null != adc) {
  394. adc.setAchievementCount(adc.getAchievementCount() - 1);
  395. if (adc.getAchievementCount() < 0) {
  396. adc.setAchievementCount(0);
  397. }
  398. achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
  399. }
  400. }
  401. return i;
  402. }
  403. @Override
  404. public AchievementEntity selectAppUserOwnerDetail(String id) {
  405. String uid=TokenManager.getUserId();
  406. return achievementMapper.selectAppAchuevementDetail(id,uid);
  407. }
  408. @Override
  409. public AchievementOrgOwnerDetailBo selectOrgOwnerDetail(String id) {
  410. return achievementMapper.selectOrgOwnerDetail(id);
  411. }
  412. @Override
  413. public AchievementUserOwnerDetailBo selectUserOwnerDetail(String id) {
  414. return achievementMapper.selectUserOwnerDetail(id);
  415. }
  416. @Override
  417. public List<DemandAchievementListBo> selectAchievementDemandListByAchievementId(String id) {
  418. return achievementDemandMapper.selectAchievementDemandListByAchievementId(id);
  419. }
  420. @Override
  421. public void insertImport(List<AchievementImportBo> data) {
  422. if (null == data || data.isEmpty()) {
  423. return;
  424. }
  425. Achievement a = null;
  426. AchievementKeyword ak = null;
  427. List<Achievement> achievementList = new ArrayList<>();
  428. List<AchievementKeyword> AchievementKeywordList = new ArrayList<>();
  429. Calendar now = Calendar.getInstance();
  430. now.set(Calendar.MILLISECOND, 0);
  431. String techBrokerId = TokenManager.hasRole(AFTConstants.TECHBROKER) ? TokenManager.getAdminId() : null;
  432. for (AchievementImportBo bo : data) {
  433. a = new Achievement();
  434. BeanUtils.copyProperties(bo, a);
  435. a.setId(UUID.randomUUID().toString());
  436. a.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  437. a.setCreateTime(now.getTime());
  438. a.setAuditStatus(AchievementAuditStatus.SUBMIT.getCode());
  439. a.setReleaseStatus(AchievementReleaseStatus.UNRELEASE.getCode());
  440. a.setTechBrokerId(techBrokerId);
  441. List<String> keywordsList = bo.getKeywords();
  442. if (null != keywordsList && keywordsList.size() > 0) {
  443. for (String s : keywordsList) {
  444. if (!StringUtils.isBlank(s)) {
  445. ak = new AchievementKeyword();
  446. ak.setAchievementId(a.getId());
  447. ak.setKeyword(s.trim());
  448. ak.setId(UUID.randomUUID().toString());
  449. AchievementKeywordList.add(ak);
  450. }
  451. }
  452. }
  453. achievementList.add(a);
  454. }
  455. achievementMapper.insertBatch(achievementList);
  456. achievementKeywordMapper.insertBatch(AchievementKeywordList);
  457. }
  458. @Override
  459. public AchievementDetailBo selectAchievementDetail(String uid, String id) {
  460. return achievementMapper.selectAchievementDetail(uid, id);
  461. }
  462. private void createTechBorkerNotice(Achievement a) {
  463. // noticeMapper.insert(disposeNotice(a, null));
  464. }
  465. // 给所有审核员发送审核通知
  466. private void createAuditorNotice(Achievement a) {
  467. List<String> ids = userRoleMapper.listAuditor();
  468. List<Notice> list = new ArrayList<>();
  469. if (null != ids && ids.size() > 0) {
  470. for (String s : ids) {
  471. list.add(disposeNotice(a, s));
  472. }
  473. noticeMapper.insertBatch(list);
  474. }
  475. }
  476. private Notice disposeNotice(Achievement a, String aid) {
  477. Notice n = new Notice();
  478. Calendar now = Calendar.getInstance();
  479. now.set(Calendar.MILLISECOND, 0);
  480. n.setId(UUID.randomUUID().toString());
  481. n.setCreateTime(now.getTime());
  482. n.setReaded(NoticeReadStatus.UNREAD.getCode());
  483. n.setRid(a.getId());
  484. if (StringUtils.isBlank(aid)) {
  485. n.setAid(a.getTechBrokerId());
  486. if (UserType.PERSONAL.getCode().equals(a.getOwnerType())) {
  487. n.setContent("编号" + a.getSerialNumber() + NoticeStatus.PERSONALACHIEVEMENTT.getDesc() + " "
  488. + (AchievementAuditStatus.AUDITED.getCode().equals(a.getAuditStatus())
  489. ? AchievementAuditStatus.AUDITED.getDesc()
  490. : AchievementAuditStatus.UNAUDITED.getDesc()));
  491. n.setNoticeType(NoticeStatus.PERSONALACHIEVEMENTT.getCode());
  492. } else if (UserType.ORGANIZATION.getCode().equals(a.getOwnerType())) {
  493. n.setContent("编号" + a.getSerialNumber() + NoticeStatus.ORGANIZATIONACHIEVEMENT.getDesc() + " "
  494. + (AchievementAuditStatus.AUDITED.getCode().equals(a.getAuditStatus())
  495. ? AchievementAuditStatus.AUDITED.getDesc()
  496. : AchievementAuditStatus.UNAUDITED.getDesc()));
  497. n.setNoticeType(NoticeStatus.ORGANIZATIONACHIEVEMENT.getCode());
  498. }
  499. } else {
  500. n.setAid(aid);
  501. if (UserType.PERSONAL.getCode().equals(a.getOwnerType())) {
  502. n.setContent(
  503. NoticeStatus.PERSONALACHIEVEMENTT.getDesc() + " " + AchievementAuditStatus.SUBMIT.getDesc());
  504. n.setNoticeType(NoticeStatus.PERSONALACHIEVEMENTT.getCode());
  505. } else if (UserType.ORGANIZATION.getCode().equals(a.getOwnerType())) {
  506. n.setContent(
  507. NoticeStatus.ORGANIZATIONACHIEVEMENT.getDesc() + " " + AchievementAuditStatus.SUBMIT.getDesc());
  508. n.setNoticeType(NoticeStatus.ORGANIZATIONACHIEVEMENT.getCode());
  509. }
  510. }
  511. return n;
  512. }
  513. private void disposeAchievementKeyword(String[] keywords, Achievement a, boolean delete) {
  514. if (null != keywords && keywords.length > 0) {
  515. if (delete) {
  516. achievementKeywordMapper.batchDeleteByAchievementId(a.getId());
  517. }
  518. List<AchievementKeyword> list = new ArrayList<>();
  519. AchievementKeyword ak = null;
  520. for (int i = 0; i < keywords.length; i++) {
  521. ak = new AchievementKeyword();
  522. ak.setId(UUID.randomUUID().toString());
  523. ak.setAchievementId(a.getId());
  524. ak.setKeyword(keywords[i].trim());
  525. list.add(ak);
  526. }
  527. achievementKeywordMapper.insertBatch(list);
  528. }
  529. }
  530. @Override
  531. public int updateMatchDemand(Achievement a) {
  532. achievementDemandMapper.deleteByAchievementId(a.getId());// 删除之前匹配单
  533. List<AchievementKeyword> achievement = achievementKeywordMapper.selectKeywordsByAchievementId(a.getId());
  534. if (null != achievement && achievement.size() > 0) {
  535. List<String> keyword = new ArrayList<>();
  536. for (AchievementKeyword k : achievement) {
  537. if (!StringUtils.isBlank(k.getKeyword())) {
  538. keyword.add(k.getKeyword());
  539. }
  540. }
  541. List<AchievementDemand> list = demandKeywordMapper.selectAchievementDemand(keyword);
  542. if (null != list && list.size() > 0) {
  543. for (AchievementDemand ad : list) {
  544. ad.setAchievementId(a.getId());
  545. }
  546. return achievementDemandMapper.insertBatch(list);
  547. }
  548. }
  549. return 0;
  550. }
  551. @SuppressWarnings("unchecked")
  552. @Override
  553. public Pagination<AchievementPartnerListBo> listPartnerAchievement(String ownerId, Integer pNo, Integer pSize) {
  554. Map<String, Object> params = new HashMap<>();
  555. params.put("ownerId", ownerId);
  556. if (pNo == null || pNo < 0) {
  557. pNo = 1;
  558. }
  559. if (pSize == null || pSize < 0 || pSize > 10) {
  560. pSize = 10;
  561. }
  562. return (Pagination<AchievementPartnerListBo>) findPage("findPartnerAchievementListByPage",
  563. "findPartnerAchievementCount", params, pNo, pSize);
  564. }
  565. @Override
  566. public AchievementPortalDetailBo findUserPortalAchievementDetail(String id) {
  567. return achievementMapper.findUserPortalAchievementDetail(id, TokenManager.getUserId());
  568. }
  569. @Override
  570. public AchievementPortalDetailBo findOrgPortalAchievementDetail(String id) {
  571. return achievementMapper.findOrgPortalAchievementDetail(id, TokenManager.getUserId());
  572. }
  573. @Override
  574. public int updateByPrimaryKeySelective(Achievement a) {
  575. return achievementMapper.updateByPrimaryKeySelective(a);
  576. }
  577. @CacheEvict(value = "internationalAchievementList", allEntries = true)
  578. public void cleanInternationalAchievement() {
  579. LoggerUtils.debug(logger, "清除国际化技术列表");
  580. }
  581. @Override
  582. public Achievement selectAchievementDetail(String id) {
  583. return achievementMapper.selectByPrimaryKey(id);
  584. }
  585. @SuppressWarnings("unchecked")
  586. @Override
  587. public Pagination<AchievementPartnerListBo> listAppUserAchievement(Integer auditStatus, Integer serialNumber,
  588. String name, String keyword,Integer dataCategory, Integer category, Integer ownerType, Integer status,
  589. String releaseDateStartDate, String releaseDateEndDate, Integer releaseStatus,String ownerId,Integer fieldA, Integer pNo, Integer pSize) {
  590. if (pNo == null || pNo < 0) {
  591. pNo = 1;
  592. }
  593. if (pSize == null || pSize < 0 || pSize > 10) {
  594. pSize = 10;
  595. }
  596. Map<String, Object> params=disposeParams(ownerType,null, null, ownerId, auditStatus, serialNumber, name, keyword, category,
  597. status, releaseDateStartDate, releaseDateEndDate,null, null, releaseStatus, null, null,null, null,null);
  598. if (null!=fieldA) {
  599. params.put("fieldA", fieldA);
  600. }
  601. if (null != dataCategory) {
  602. params.put("dataCategory", String.valueOf(dataCategory));
  603. }
  604. if (null != TokenManager.getUserId()) params.put("uid", TokenManager.getUserId());
  605. Pagination<AchievementPartnerListBo> p=(Pagination<AchievementPartnerListBo>) findPage("findAppAchievementListByPage", "findAppAchievementCount",
  606. params,pNo, pSize);
  607. return p;
  608. }
  609. @SuppressWarnings("unchecked")
  610. @Override
  611. public Pagination<AchievementPartnerListBo> listAppMyAchievement(Integer pNo, Integer pSize) {
  612. if (pNo == null || pNo < 0) {
  613. pNo = 1;
  614. }
  615. if (pSize == null || pSize < 0 || pSize > 10) {
  616. pSize = 10;
  617. }
  618. Map<String, Object> params = new HashMap<>();
  619. if (StringUtils.isNotBlank(TokenManager.getUserId())) {
  620. params.put("ownerId", TokenManager.getUserId());
  621. }
  622. //params.put("ownerId", "46433140-0a90-471e-a32f-6bc89c562e3d");
  623. return (Pagination<AchievementPartnerListBo>) findPage("findMyAchievementListByPage", "findMyAchievementCount",
  624. params,pNo, pSize);
  625. }
  626. @Override
  627. public int saveAppAchievement(Achievement a, String[] keywords) {
  628. a.setId(UUID.randomUUID().toString());
  629. a.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  630. a.setInfoSources(1);
  631. Calendar now = Calendar.getInstance();
  632. now.set(Calendar.MILLISECOND, 0);
  633. a.setReleaseStatus(AchievementReleaseStatus.UNRELEASE.getCode());
  634. if (AchievementAuditStatus.SUBMIT.getCode().equals(a.getAuditStatus())) {
  635. createAuditorNotice(a);
  636. } else {
  637. a.setAuditStatus(AchievementAuditStatus.SUBMIT.getCode());
  638. }
  639. if (null!=TokenManager.getUserId()) {
  640. a.setOwnerId(TokenManager.getUserId());
  641. User u=userMapper.selectByPrimaryKey(TokenManager.getUserId());
  642. if (null!=u.getType()) {
  643. a.setOwnerType(u.getType());
  644. }if (StringUtils.isNotBlank(u.getMobile())) {
  645. a.setOwnerMobile(u.getMobile());
  646. }if (StringUtils.isNotBlank(u.getNickname())) {
  647. a.setOwnerName(u.getNickname());
  648. }
  649. }
  650. a.setCreateTime(now.getTime());
  651. disposeAchievementKeyword(keywords, a, false);
  652. return achievementMapper.insert(a);
  653. }
  654. @Override
  655. public List<AchievementObject> recentAchievements(int size, String url, String showLocation) {
  656. // TODO Auto-generated method stub
  657. return achievementMapper.getRecentAchievements(size,url,showLocation);
  658. }
  659. @Override
  660. public List<AchievementObject> getHotAchievements(int size, String url, String showLocation) {
  661. // TODO Auto-generated method stub
  662. return achievementMapper.getHotAchievements( size, url, showLocation);
  663. }
  664. @Override
  665. public List<AchievementObject> getPatentList(int size, String url, String showLocation) {
  666. // TODO Auto-generated method stub
  667. return achievementMapper.getPatentList(size,url,showLocation);
  668. }
  669. @Override
  670. public List<AchievementObject> getPracticalTechnologys(int size, String url, String showLocation) {
  671. // TODO Auto-generated method stub
  672. return achievementMapper.getPracticalTechnologys(size,url,showLocation);
  673. }
  674. @Override
  675. public List<PolicyEntity> getIntellectualProperty(int size) {
  676. // TODO Auto-generated method stub
  677. return achievementMapper.getIntellectualProperty(size);
  678. }
  679. @Override
  680. public AchievementObject getAchievementDetail(String id, Integer type) {
  681. // TODO Auto-generated method stub
  682. return achievementMapper.getAchievementDetail(id,type);
  683. }
  684. @Override
  685. public List<AchievementObject> getBoutiquePatent(int size,int deletedSign) {
  686. // TODO Auto-generated method stub
  687. return achievementMapper.getBoutiquePatent( size,deletedSign);
  688. }
  689. @Override
  690. public List<AchievementObject> guessYouLike(int size) {
  691. // TODO Auto-generated method stub
  692. return achievementMapper.guessYouLike(size);
  693. }
  694. @Override
  695. public AchievementResultObject getAchievementDetailById(String id) {
  696. // TODO Auto-generated method stub
  697. return achievementMapper.getAchievementDetailById(id);
  698. }
  699. @SuppressWarnings("unchecked")
  700. @Override
  701. public Pagination<AchievementObject> listAchievement(String name, String ownerName, Integer category,
  702. Integer dataCategory, Integer auditStatus, String startDate, String endDate, Integer pageNo,
  703. Integer pageSize) {
  704. Map<String,Object> params = new HashMap<>();
  705. if (null != startDate) params.put("startDate", startDate);
  706. if (null != endDate) params.put("endDate", endDate);
  707. if (null != auditStatus) params.put("auditStatus", auditStatus);
  708. if (null != category) params.put("category", category);
  709. if (null != dataCategory) params.put("dataCategory", dataCategory);
  710. if (StringUtils.isNotBlank(name)) params.put("name", name);
  711. if (StringUtils.isNotBlank(ownerName)) params.put("ownerName", ownerName);
  712. return (Pagination<AchievementObject>) findPage("listMyAchievementByPage", "listMyAchievementCount",params,
  713. pageNo, pageSize);
  714. }
  715. @Override
  716. public int updateAuditAchievement(String id, Integer auditResult,String auditInfo) {
  717. // TODO Auto-generated method stub
  718. int auditStatus=AchievementAuditStatus.AUDITED.getCode().intValue();
  719. if(auditResult.intValue() == 0) {
  720. auditStatus=AchievementAuditStatus.UNAUDITED.getCode().intValue();
  721. if(collectFlag)jtCollectSearchMapper.deleteByrowId(id);
  722. }
  723. else {
  724. auditStatus=AchievementAuditStatus.AUDITED.getCode().intValue();
  725. if(collectFlag){
  726. Achievement a=achievementMapper.selectByPrimaryKey(id);
  727. JtCollectSearch r=new JtCollectSearch();
  728. r.setFromTable(collectType.ACHIEVEMENT.getDesc());
  729. r.setKeyword(a.getKeyword());
  730. r.setTitle(a.getName());
  731. r.setRowId(a.getId());
  732. String sum = a.getIntroduction();
  733. if(null != sum && sum.length() > 40){
  734. sum = sum.substring(0,40) + "...";
  735. }
  736. r.setSummary(sum);
  737. jtCollectSearchMapper.insertSelective(r);
  738. }
  739. }
  740. Achievement achievement=new Achievement();
  741. achievement.setId(id);
  742. achievement.setAuditStatus(auditStatus);
  743. achievement.setAuditInfo(auditInfo);
  744. achievement.setReleaseDate(new Date());
  745. achievementMapper.updateByPrimaryKeySelective(achievement);
  746. return auditStatus;
  747. }
  748. @SuppressWarnings("unchecked")
  749. @Override
  750. public Pagination<AchievementObject> getAchievementObjects(AchievementObject achievementObject,Integer pageNo,Integer pageSize) {
  751. if(pageNo==null ||pageNo<1)pageNo=1;
  752. if(pageSize== null ||pageSize<1)pageSize=10;
  753. // TODO Auto-generated method stub
  754. return (Pagination<AchievementObject>)findPage("findAchievementListWithPid","findAchievementCountWithPid",disposeAchievementParams(achievementObject), pageNo, pageSize);
  755. }
  756. private Map<String, Object> disposeAchievementParams(AchievementObject achievementObject) {
  757. Map<String, Object> params=new HashMap<String,Object>();
  758. if(null !=achievementObject.getName()) {
  759. params.put("name", achievementObject.getName());
  760. }
  761. if(null != achievementObject.getFieldA())
  762. {
  763. params.put("fieldA", achievementObject.getFieldA());
  764. }
  765. if(null != achievementObject.getFieldB()) {
  766. params.put("fieldB", achievementObject.getFieldB());
  767. }
  768. if(null != achievementObject.getDeletedSign()) {
  769. params.put("deletedSign", achievementObject.getDeletedSign());
  770. }else{
  771. params.put("deletedSign", 0);//未删除的数据
  772. }
  773. return params;
  774. }
  775. @Override
  776. public List<AchievementPartnerListBo> findPartnerAchievementList(String uid) {
  777. return achievementMapper.findPartnerAchievementListByPage(uid);
  778. }
  779. @SuppressWarnings("unchecked")
  780. @Override
  781. public Pagination<AchievementObject> listInterestedAchievement(Integer pageNo, Integer pageSize) {
  782. if(pageNo==null ||pageNo<1)pageNo=1;
  783. if(pageSize== null ||pageSize<1)pageSize=10;
  784. Map<String, Object> params=new HashMap<String,Object>();
  785. params.put("uid", TokenManager.getUserId());
  786. //params.put("uid", "1180fa62-7c42-44be-bc41-5583814d69f4");
  787. return (Pagination<AchievementObject>) findPage("listInterestedAchievement", "listInterestedAchievementCount", params, pageNo, pageSize);
  788. }
  789. @SuppressWarnings("unchecked")
  790. @Override
  791. public Pagination<MyCollection> myCollectionAchievement(Integer pageNo, Integer pageSize) {
  792. if(pageNo==null ||pageNo<1)pageNo=1;
  793. if(pageSize== null ||pageSize<1)pageSize=10;
  794. Map<String, Object> params=new HashMap<String,Object>();
  795. params.put("uid", TokenManager.getUserId());
  796. // params.put("uid", "1180fa62-7c42-44be-bc41-5583814d69f4");
  797. return (Pagination<MyCollection>) findPage("myCollectionAchievementList", "myCollectionAchievementCount", params, pageNo, pageSize);
  798. }
  799. @Override
  800. public void batchSaveAchievement(MultipartFile file) {
  801. //创建一个对象,用来存储数据
  802. List<Achievement> list=new ArrayList<>();
  803. List<AchievementKeyword> keyword = new ArrayList<>();
  804. List<AchievementPublish> publish = new ArrayList<>();
  805. Sheet sheet=FileUtils.pushReadFile(file);
  806. //获得当前sheet的开始行
  807. int firstRowNum = sheet.getFirstRowNum();
  808. //获得当前sheet最后一行
  809. int lastRowNum=sheet.getLastRowNum();
  810. //循环除了第2行的所有行
  811. Date date=new Date();
  812. //获取技淘网的id
  813. String defaultPlatformId = branchInformationMapper.selectByDomain(PageConstants.DEFAULT_DOMAIN).getId();
  814. for(int rowNum = firstRowNum+2;rowNum <= lastRowNum;rowNum++){
  815. //获得当前行
  816. Row row = sheet.getRow(rowNum);
  817. if(row == null){
  818. continue;
  819. }
  820. //获得当前行的开始列
  821. int firstCellNum = row.getFirstCellNum();
  822. //获得当前行的列数
  823. int lastCellNum = row.getLastCellNum();
  824. //循环当前行 cellNum = (firstCellNum+1) 则是除开第一例
  825. Achievement in=new Achievement();
  826. for(int cellNum = (firstCellNum); cellNum < lastCellNum;cellNum++){
  827. Cell cell = row.getCell(cellNum);
  828. try {
  829. switch (cellNum) {
  830. case 0:
  831. in.setName(FileUtils.getCellValue(cell));
  832. break;
  833. case 1:
  834. in.setDataCategory(Integer.valueOf(FileUtils.getCellValue(cell)));
  835. break;
  836. case 2:
  837. in.setCategory(Integer.valueOf(FileUtils.getCellValue(cell)));
  838. break;
  839. case 3:
  840. in.setIntroduction(FileUtils.getCellValue(cell));
  841. break;
  842. case 4:
  843. in.setKeyword(FileUtils.getCellValue(cell));
  844. break;
  845. case 5:
  846. in.setPatentCase(FileUtils.getCellValue(cell));
  847. break;
  848. case 6:
  849. in.setTeamDes(FileUtils.getCellValue(cell));
  850. break;
  851. case 7:
  852. in.setParameter(FileUtils.getCellValue(cell));
  853. break;
  854. case 8:
  855. in.setBoutique(Integer.valueOf(FileUtils.getCellValue(cell)));
  856. break;
  857. case 9:
  858. in.setIsHot(Integer.valueOf(FileUtils.getCellValue(cell)));
  859. break;
  860. }
  861. } catch (Exception e) {
  862. throw new BusinessException(new Error("表格第"+(rowNum+1)+"行输入内容不正确。"));
  863. }
  864. }
  865. in.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  866. in.setOrgId(TokenManager.getAdminId());
  867. in.setOwnerId(TokenManager.getAdminId());
  868. in.setCreateTime(date);
  869. in.setStatus(0);
  870. in.setReleaseStatus(AchievementAuditStatus.CREATE.getCode());
  871. in.setAuditStatus(0);
  872. in.setId(UUID.randomUUID().toString());
  873. in.setInfoSources(1);
  874. list.add(in);
  875. //关键字处理
  876. if(in.getKeyword()!=null) {
  877. String [] keywords=null;
  878. boolean flag= false;
  879. if (in.getKeyword().contains(",")) {
  880. keywords=in.getKeyword().split(",");
  881. flag=true;
  882. }else if (in.getKeyword().contains(",")) {
  883. keywords=in.getKeyword().split(",");
  884. flag=true;
  885. }else {
  886. AchievementKeyword ak = new AchievementKeyword();
  887. ak.setId(UUID.randomUUID().toString());
  888. ak.setAchievementId(in.getId());
  889. ak.setKeyword(in.getKeyword());
  890. keyword.add(ak);
  891. }
  892. if (flag) {
  893. for (String string : keywords) {
  894. AchievementKeyword ak = new AchievementKeyword();
  895. ak.setId(UUID.randomUUID().toString());
  896. ak.setAchievementId(in.getId());
  897. ak.setKeyword(string);
  898. keyword.add(ak);
  899. }
  900. }
  901. }
  902. AchievementPublish ap = null;
  903. List<String> webpages = new ArrayList<>();
  904. webpages.add("web_achievement_main");
  905. webpages.add("web_index");
  906. webpages.add("web_achievement_list");
  907. for(String page: webpages){
  908. ap = new AchievementPublish();
  909. ap.setId(UUID.randomUUID().toString());
  910. ap.setAchievementId((in.getId()));
  911. ap.setPublisher(TokenManager.getUserId());
  912. ap.setPublisher("1");
  913. ap.setPublishTime(date);
  914. ap.setPublishClient(PageConstants.WEB_PLATFORM);
  915. ap.setPublishPage(page);
  916. ap.setPublishPlatform(defaultPlatformId);
  917. ap.setIfTop(AFTConstants.NO);
  918. ap.setTopNumber(PageConstants.DEFAULT_TOP_NUMBER);
  919. ap.setShowNumber(PageConstants.DEFAULT_SHOW_NUMBER);
  920. publish.add(ap);
  921. }
  922. AchievementPublish ap2 = new AchievementPublish();
  923. ap2.setId(UUID.randomUUID().toString());
  924. ap2.setAchievementId(in.getId());
  925. ap2.setPublisher(TokenManager.getUserId());
  926. ap2.setPublishTime(date);
  927. ap2.setPublishClient(PageConstants.APP_PLATFORM);
  928. ap2.setPublishPage("ap2p_achievement_list");
  929. ap2.setPublishPlatform(defaultPlatformId);
  930. ap2.setIfTop(AFTConstants.NO);
  931. ap2.setTopNumber(PageConstants.DEFAULT_TOP_NUMBER);
  932. ap2.setShowNumber(PageConstants.DEFAULT_SHOW_NUMBER);
  933. publish.add(ap2);
  934. }
  935. achievementMapper.insertBatch(list);
  936. achievementKeywordMapper.insertBatch(keyword);
  937. achievementPublishMapper.insertBatch(publish);
  938. }
  939. }