UserAchievementApiController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. package com.goafanti.achievement.controller;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.Date;
  5. import java.util.List;
  6. import javax.annotation.Resource;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import javax.validation.Valid;
  10. import javax.xml.soap.Detail;
  11. import org.apache.ibatis.annotations.ResultMap;
  12. import org.springframework.beans.BeanUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.validation.BindingResult;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import com.goafanti.achievement.bo.InputAchievement;
  20. import com.goafanti.achievement.service.AchievementOrderService;
  21. import com.goafanti.achievement.service.AchievementService;
  22. import com.goafanti.admin.service.AftFileService;
  23. import com.goafanti.common.bo.Result;
  24. import com.goafanti.common.constant.AFTConstants;
  25. import com.goafanti.common.constant.ErrorConstants;
  26. import com.goafanti.common.constant.PageConstants;
  27. import com.goafanti.common.controller.CertifyApiController;
  28. import com.goafanti.common.dao.AchievementKeywordMapper;
  29. import com.goafanti.common.dao.AchievementPublishMapper;
  30. import com.goafanti.common.enums.AchievementAuditStatus;
  31. import com.goafanti.common.enums.AchievementFields;
  32. import com.goafanti.common.enums.AchievementOrderStatus;
  33. import com.goafanti.common.enums.AttachmentType;
  34. import com.goafanti.common.enums.DemandAuditStatus;
  35. import com.goafanti.common.model.Achievement;
  36. import com.goafanti.common.model.AchievementOrder;
  37. import com.goafanti.common.model.AftFile;
  38. import com.goafanti.common.model.Demand;
  39. import com.goafanti.common.utils.StringUtils;
  40. import com.goafanti.core.shiro.token.TokenManager;
  41. import com.goafanti.portal.bo.AchievementObject;
  42. import com.goafanti.portal.bo.AchievementResultObject;
  43. @RestController
  44. @RequestMapping(value = "/api/user/achievement")
  45. public class UserAchievementApiController extends CertifyApiController {
  46. @Resource
  47. private AchievementService achievementService;
  48. @Resource
  49. private AftFileService aftFileService;
  50. @Resource
  51. private AchievementOrderService achievementOrderService;
  52. @Autowired
  53. private AchievementKeywordMapper achievementKeywordMapper;
  54. @Autowired
  55. private AchievementPublishMapper achievementPublishMapper;
  56. /**
  57. * 成果需求匹配列表
  58. */
  59. @RequestMapping(value = "/achievementDemand", method = RequestMethod.GET)
  60. public Result achievementDemand(String id) {
  61. Result res = new Result();
  62. res.setData(achievementService.selectAchievementDemandListByAchievementId(id));
  63. return res;
  64. }
  65. /**
  66. * 下载科技成果批量导入Excel模板
  67. */
  68. @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
  69. public Result downloadTemplateFile(HttpServletResponse response, String sign) {
  70. Result res = new Result();
  71. AttachmentType attachmentType = AttachmentType.getField(sign);
  72. if (attachmentType == AttachmentType.ACHIEVEMENT_TEMPLATE) {
  73. String fileName = "";
  74. AftFile af = aftFileService.selectAftFileBySign(sign);
  75. if (null == af) {
  76. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
  77. } else {
  78. String path = af.getFilePath();
  79. String suffix = path.substring(path.lastIndexOf("."));
  80. fileName = AttachmentType.ACHIEVEMENT_TEMPLATE.getDesc() + suffix;
  81. downloadFile(response, fileName, path);
  82. }
  83. } else {
  84. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  85. }
  86. return res;
  87. }
  88. /**
  89. * 成果撤消发布(下架)
  90. */
  91. @RequestMapping(value = "/offShelf", method = RequestMethod.POST)
  92. public Result offShelf(String id) {
  93. Result res = new Result();
  94. if (StringUtils.isBlank(id)) {
  95. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
  96. return res;
  97. }
  98. Achievement a = achievementService.selectByPrimaryKey(id);
  99. if (null == a) {
  100. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID"));
  101. return res;
  102. }
  103. res.setData(achievementService.updateReleaseStatus(a));
  104. return res;
  105. }
  106. /**
  107. * 成果列表
  108. */
  109. @RequestMapping(value = "/list", method = RequestMethod.GET)
  110. private Result list(Integer auditStatus, String name, Integer dataCategory,
  111. String startDate, String endDate,
  112. Integer pageNo, Integer pageSize) {
  113. Result res = new Result();
  114. res.setData(achievementService.listMyAchievement(auditStatus, name, dataCategory,
  115. startDate, endDate, pageNo, pageSize));
  116. return res;
  117. }
  118. /**
  119. * 新增成果
  120. */
  121. @RequestMapping(value = "/apply", method = RequestMethod.POST)
  122. private Result apply(@Valid InputAchievement ia, BindingResult bindingResult,
  123. @RequestParam(name = "keywords[]", required = false) String[] keywords,
  124. @RequestParam(name = "publishPages[]", required = false) String[] publishPages) {
  125. Result res = new Result();
  126. if (bindingResult.hasErrors()) {
  127. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  128. AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
  129. return res;
  130. }
  131. res = disposeInputAchievement(res, ia, keywords,publishPages);
  132. if (!res.getError().isEmpty()) {
  133. return res;
  134. }
  135. if(TokenManager.getUserId()==null) {
  136. res.getError().add(buildError(ErrorConstants.NON_LOGIN, "", ""));return res;
  137. }
  138. Achievement a = new Achievement();
  139. BeanUtils.copyProperties(ia, a);
  140. a.setOwnerId(TokenManager.getUserId());
  141. List<String> webPages = new ArrayList<String>();
  142. List<String> appPages = new ArrayList<String>();
  143. PageConstants.putAchievement(publishPages, webPages, appPages);
  144. achievementService.saveAchievement(a, keywords,webPages,appPages);
  145. return res;
  146. }
  147. @RequestMapping(value = "/achievementDetail",method=RequestMethod.GET)
  148. private Result Detail(String id) {
  149. Result result=new Result();
  150. if (StringUtils.isBlank(id)) {
  151. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
  152. return result;
  153. }
  154. AchievementResultObject achievementObjects=achievementService.getAchievementDetailById(id);
  155. List<String>keywords=achievementKeywordMapper.getKeywordsByAchievementId(id);
  156. List<String> publishPages=achievementPublishMapper.getPublishPagesById(id);
  157. achievementObjects.setKeywords(keywords);
  158. achievementObjects.setPublishPages(publishPages);
  159. result.setData(achievementObjects);
  160. // AchievementResultObject achievementResultObject=new AchievementResultObject()
  161. return result;
  162. }
  163. /**
  164. * 个人成果详情详情
  165. */
  166. @RequestMapping(value = "/userDetail", method = RequestMethod.GET)
  167. private Result userDetail(String id) {
  168. Result res = new Result();
  169. if (StringUtils.isBlank(id)) {
  170. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
  171. return res;
  172. }
  173. res.setData(achievementService.selectUserOwnerDetail(id));
  174. return res;
  175. }
  176. /**
  177. * 组织用户成果详情详情
  178. */
  179. @RequestMapping(value = "/orgDetail", method = RequestMethod.GET)
  180. private Result orgDetail(String id) {
  181. Result res = new Result();
  182. if (StringUtils.isBlank(id)) {
  183. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
  184. return res;
  185. }
  186. res.setData(achievementService.selectOrgOwnerDetail(id));
  187. return res;
  188. }
  189. /**
  190. * 修改成果
  191. */
  192. @RequestMapping(value = "/update", method = RequestMethod.POST)
  193. public Result update(@Valid InputAchievement ia, BindingResult bindingResult,
  194. @RequestParam(name = "keywords[]", required = false) String[] keywords,
  195. @RequestParam(name = "publishPages[]", required = false) String[] publishPages) {
  196. Result res = new Result();
  197. if (bindingResult.hasErrors()) {
  198. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  199. AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
  200. return res;
  201. }
  202. if (StringUtils.isBlank(ia.getId())) {
  203. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
  204. return res;
  205. }
  206. if (!AchievementAuditStatus.CREATE.getCode().equals(ia.getAuditStatus())
  207. && !AchievementAuditStatus.SUBMIT.getCode().equals(ia.getAuditStatus())
  208. && !AchievementAuditStatus.UNAUDITED.getCode().equals(ia.getAuditStatus())) {
  209. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "当前状态无法提交审核!"));
  210. return res;
  211. }
  212. List<String> webPages = new ArrayList<String>();
  213. List<String> appPages = new ArrayList<String>();
  214. PageConstants.putAchievement(publishPages, webPages, appPages);
  215. res = disposeInputAchievement(res, ia, keywords,publishPages);
  216. if (!res.getError().isEmpty()) {
  217. return res;
  218. }
  219. if(webPages.size()==0 && appPages.size() == 0){
  220. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "页面参数错误","页面参数"));
  221. return res;
  222. }
  223. if(TokenManager.getUserId() ==null) {
  224. res.getError().add(buildError(ErrorConstants.NON_LOGIN, "", ""));return res;
  225. }
  226. Achievement a = new Achievement();
  227. BeanUtils.copyProperties(ia, a);
  228. a.setOwnerId(TokenManager.getUserId());
  229. res.setData(achievementService.updateAchievement(a, keywords, null,webPages,appPages));
  230. return res;
  231. }
  232. /**
  233. * 刷新发布时间
  234. * @param id
  235. * @param auditStatus
  236. * @return
  237. */
  238. @RequestMapping(value = "/refreshPublish", method = RequestMethod.POST)
  239. public Result refreshPublish(String id,Integer auditStatus){
  240. Result res = new Result();
  241. if (StringUtils.isBlank(id)) {
  242. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
  243. return res;
  244. }
  245. if (null == auditStatus) {
  246. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "成果状态错误", "成果状态"));
  247. return res;
  248. }
  249. if (AchievementAuditStatus.AUDITED.getCode() != auditStatus) {
  250. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "当前状态无法刷新发布,"));
  251. return res;
  252. }
  253. Achievement a = new Achievement();
  254. a.setId(id);
  255. a.setReleaseDate(new Date());
  256. // a.setAuditStatus(auditStatus);
  257. achievementService.updateByPrimaryKeySelective(a);
  258. return res;
  259. }
  260. /**
  261. * 提交审核
  262. * @param id
  263. * @param auditStatus
  264. * @return
  265. */
  266. @RequestMapping(value = "/commit", method = RequestMethod.POST)
  267. public Result refreshAuditStatus(String id){
  268. Result res = new Result();
  269. if (StringUtils.isBlank(id)) {
  270. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
  271. return res;
  272. }
  273. AchievementResultObject achievementResultObject=achievementService.getAchievementDetailById(id);
  274. if(achievementResultObject==null) {
  275. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
  276. return res;
  277. }
  278. if (AchievementAuditStatus.CREATE.getCode() != achievementResultObject.getAuditStatus()) {
  279. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "当前状态无法提交审核,"));
  280. return res;
  281. }
  282. Achievement a = new Achievement();
  283. a.setId(id);
  284. a.setAuditStatus(AchievementAuditStatus.SUBMIT.getCode());
  285. achievementService.updateByPrimaryKeySelective(a);
  286. return res;
  287. }
  288. /**
  289. * 下载文本文件
  290. */
  291. @RequestMapping(value = "/download", method = RequestMethod.GET)
  292. public Result download(HttpServletResponse response, String id, String sign) {
  293. Result res = new Result();
  294. if (StringUtils.isBlank(id)) {
  295. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技成果ID"));
  296. return res;
  297. }
  298. Achievement a = achievementService.selectByPrimaryKey(id);
  299. if (null == a) {
  300. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技成果ID"));
  301. return res;
  302. }
  303. AttachmentType attachmentType = AttachmentType.getField(sign);
  304. /*if (attachmentType == AttachmentType.ACHIEVEMENT_MATURITY_TEXT_FILE) {
  305. downloadUnPrivateFile(response, a.getMaturityTextFileDownloadFileName(), a.getMaturityTextFileUrl());
  306. } else if (attachmentType == AttachmentType.ACHIEVEMENT_TECH_PLAN) {
  307. downloadUnPrivateFile(response, a.getTechPlanDownloadFileName(), a.getTechPlanUrl());
  308. } else if (attachmentType == AttachmentType.ACHIEVEMENT_BUSINESS_PLAN) {
  309. downloadUnPrivateFile(response, a.getBusinessPlanDownloadFileName(), a.getBusinessPlanUrl());
  310. } else {
  311. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  312. }*/
  313. return res;
  314. }
  315. /**
  316. * 文本文件上传
  317. */
  318. @RequestMapping(value = "/uploadTextFile", method = RequestMethod.POST)
  319. public Result uploadTextFile(HttpServletRequest req, String sign) {
  320. Result res = new Result();
  321. AttachmentType attachmentType = AttachmentType.getField(sign);
  322. /*if (attachmentType == AttachmentType.ACHIEVEMENT_MATURITY_TEXT_FILE
  323. || attachmentType == AttachmentType.ACHIEVEMENT_TECH_PLAN
  324. || attachmentType == AttachmentType.ACHIEVEMENT_BUSINESS_PLAN) {
  325. res.setData(handleFiles(res, "/achievement/", false, req, sign, "achievement"));
  326. } else {
  327. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  328. }*/
  329. return res;
  330. }
  331. /**
  332. * 图片上传
  333. */
  334. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  335. public Result uploadPicture(HttpServletRequest req, String sign) {
  336. Result res = new Result();
  337. AttachmentType attachmentType = AttachmentType.getField(sign);
  338. if (attachmentType == AttachmentType.ACHIEVEMENT_PICTURE
  339. ) {
  340. res.setData(handleFiles(res, "/achievement/", false, req, sign, "achievement"));
  341. } else {
  342. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  343. }
  344. return res;
  345. }
  346. /**
  347. * 删除
  348. */
  349. @RequestMapping(value = "/delete", method = RequestMethod.POST)
  350. private Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
  351. Result res = new Result();
  352. if (ids == null || ids.length != 1) {
  353. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
  354. } else {
  355. List<AchievementOrder> list = achievementOrderService.selectAchievementOrderByAchievementId(ids[0]);
  356. for (AchievementOrder order : list) {
  357. if (!AchievementOrderStatus.UNPAYED.getCode().equals(order.getStatus())) {
  358. res.getError().add(buildError("", "当前科技成果有订单,无法删除!"));
  359. return res;
  360. }
  361. }
  362. res.setData(achievementService.deleteByPrimaryKey(Arrays.asList(ids)));
  363. }
  364. return res;
  365. }
  366. private Result disposeInputAchievement(Result res, InputAchievement ia, String[] keywords,String[] publishPages) {
  367. if (StringUtils.isBlank(ia.getName())) {
  368. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果名称", "成果名称"));
  369. return res;
  370. }
  371. if (null == ia.getCategory()) {
  372. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到数据类别", "数据类别"));
  373. return res;
  374. }
  375. if (StringUtils.isBlank(ia.getKeyword())) {
  376. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  377. return res;
  378. }
  379. if (null == keywords || keywords.length < 1) {
  380. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  381. return res;
  382. }
  383. for (int i = 0; i < keywords.length; i++) {
  384. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  385. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  386. return res;
  387. }
  388. }
  389. return res;
  390. }
  391. }