AdminDemandApiController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. package com.goafanti.demand.controller;
  2. import javax.annotation.Resource;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. import org.springframework.web.bind.annotation.RestController;
  8. import com.goafanti.admin.service.AftFileService;
  9. import com.goafanti.common.bo.Result;
  10. import com.goafanti.common.constant.AFTConstants;
  11. import com.goafanti.common.constant.ErrorConstants;
  12. import com.goafanti.common.controller.CertifyApiController;
  13. import com.goafanti.common.enums.AttachmentType;
  14. import com.goafanti.common.enums.DeleteStatus;
  15. import com.goafanti.common.enums.DemandAuditStatus;
  16. import com.goafanti.common.model.AftFile;
  17. import com.goafanti.common.model.Demand;
  18. import com.goafanti.common.model.DemandPublish;
  19. import com.goafanti.common.utils.StringUtils;
  20. import com.goafanti.demand.service.DemandFollowService;
  21. import com.goafanti.demand.service.DemandOrderService;
  22. import com.goafanti.demand.service.DemandPublishPageService;
  23. import com.goafanti.demand.service.DemandPublishService;
  24. import com.goafanti.demand.service.DemandService;
  25. import com.goafanti.user.service.UserService;
  26. @RestController
  27. @RequestMapping(value = "/api/admin/demand")
  28. public class AdminDemandApiController extends CertifyApiController {
  29. @Resource
  30. private DemandService demandService;
  31. @Resource
  32. private UserService userService;
  33. @Resource
  34. private AftFileService aftFileService;
  35. @Resource
  36. private DemandOrderService demandOrderService;
  37. @Resource
  38. DemandPublishService demandPublishService;
  39. @Resource
  40. DemandFollowService demandFollowService;
  41. /**
  42. * 科技需求匹配科技成果
  43. */
  44. @RequestMapping(value = "/matchAchievement", method = RequestMethod.POST)
  45. public Result matchAchievement(String id) {
  46. Result res = new Result();
  47. if (StringUtils.isBlank(id)) {
  48. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "成果ID"));
  49. return res;
  50. }
  51. Demand d = demandService.selectByPrimaryKey(id);
  52. if (null == d|| !DeleteStatus.UNDELETE.getCode().equals(d.getDeletedSign())
  53. || !DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())) {
  54. res.getError().add(buildError("", "当前状态无法匹配!"));
  55. return res;
  56. }
  57. res.setData(demandService.updateMatchAchievement(d));
  58. return res;
  59. }
  60. /**
  61. * 下载技术需求批量导入Excel模板
  62. *
  63. * @param response
  64. * @return
  65. */
  66. @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
  67. public Result downloadTemplateFile(HttpServletResponse response, String sign) {
  68. Result res = new Result();
  69. AttachmentType attachmentType = AttachmentType.getField(sign);
  70. if (attachmentType == AttachmentType.DEMAND_TEMPLATE) {
  71. String fileName = "";
  72. AftFile af = aftFileService.selectAftFileBySign(sign);
  73. if (null == af) {
  74. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
  75. } else {
  76. String path = af.getFilePath();
  77. String suffix = path.substring(path.lastIndexOf("."));
  78. fileName = AttachmentType.DEMAND_TEMPLATE.getDesc() + suffix;
  79. downloadFile(response, fileName, path);
  80. }
  81. } else {
  82. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  83. }
  84. return res;
  85. }
  86. /**
  87. * 个人用户--需求列表
  88. */
  89. @RequestMapping(value = "/userList", method = RequestMethod.GET)
  90. public Result userList(String pageNo, String pageSize) {
  91. Result res = new Result();
  92. //res.setData(null); TODO
  93. return res;
  94. }
  95. /**
  96. * 组织用户--需求列表(个人组织合并)
  97. */
  98. @RequestMapping(value = "/orgList", method = RequestMethod.GET)
  99. public Result orgList(String pageNo, String pageSize) {
  100. Result res = new Result();
  101. //res.setData(null); TODO
  102. return res;
  103. }
  104. /**
  105. * 需求列表
  106. * @param pageNo
  107. * @param pageSize
  108. * @return
  109. */
  110. @RequestMapping(value = "/list", method = RequestMethod.GET)
  111. public Result list(String name,String employerName,Integer demandType,
  112. Integer auditStatus,Integer status,String startDate, String endDate,Integer pageNo, Integer pageSize){
  113. Result res = new Result();
  114. res.setData(demandService.listDemand(name, employerName, demandType, auditStatus, status,startDate,endDate, pageNo, pageSize));
  115. return res;
  116. }
  117. /**
  118. * 个人需求详情
  119. */
  120. @RequestMapping(value = "/userDemandDetail", method = RequestMethod.GET)
  121. public Result userDemandDetail(String id) {
  122. Result res = new Result();
  123. if (StringUtils.isBlank(id)) {
  124. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
  125. return res;
  126. }
  127. res.setData(demandService.selectUserDemandDetail(id));
  128. return res;
  129. }
  130. /**
  131. * 组织用户详情(个人组织合并)
  132. */
  133. @RequestMapping(value = "/orgDemandDetail", method = RequestMethod.GET)
  134. public Result orgDemandDetail(String id,Integer dataCategory) {
  135. Result res = new Result();
  136. if (StringUtils.isBlank(id)) {
  137. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
  138. return res;
  139. }
  140. if(dataCategory==0){
  141. res.setData(demandService.selectUserDemandDetail(id));
  142. return res;
  143. }else if(dataCategory==1){
  144. res.setData(demandService.selectOrgDemandDetail(id));
  145. return res;
  146. }
  147. return res;
  148. }
  149. /**
  150. * 需求详情
  151. * @param id
  152. * @return
  153. */
  154. @RequestMapping(value = "/demandDetail", method = RequestMethod.GET)
  155. public Result demandDetail(String id){
  156. Result res = new Result();
  157. if (StringUtils.isBlank(id)) {
  158. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
  159. return res;
  160. }
  161. res.setData(demandService.selectDemandDetail(id));
  162. return res;
  163. }
  164. /**
  165. * 审核需求
  166. * @param id
  167. * @param auditResult
  168. * @return
  169. */
  170. @RequestMapping(value = "/auditDemand", method = RequestMethod.GET)
  171. public Result auditDemand(String id, Integer auditResult,String auditInfo){
  172. Result res = new Result();
  173. if (StringUtils.isBlank(id)) {
  174. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
  175. return res;
  176. }
  177. Demand d = demandService.selectByPrimaryKey(id);
  178. if (null == d) {
  179. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID"));
  180. return res;
  181. }
  182. if(d.getAuditStatus() != DemandAuditStatus.INAUDIT.getCode()){
  183. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求未达审核条件"));
  184. return res;
  185. }
  186. if(AFTConstants.NO == auditResult && StringUtils.isBlank(auditInfo)){
  187. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需填写审核意见"));
  188. return res;
  189. }
  190. if(AFTConstants.YES == auditResult || AFTConstants.NO == auditResult){
  191. d.setAuditStatus(auditResult);
  192. }
  193. demandService.updateByPrimaryKeySelective(d);
  194. return res;
  195. }
  196. /**
  197. * 需求管理--获取个人用户下拉
  198. */
  199. @RequestMapping(value = "/userNames", method = RequestMethod.GET)
  200. public Result getUserNames() {
  201. Result res = new Result();
  202. res.setData(userService.selectDemandUserNames());
  203. return res;
  204. }
  205. /**
  206. * 需求管理--获取组织用户下拉
  207. */
  208. @RequestMapping(value = "/unitNames", method = RequestMethod.GET)
  209. public Result getUnitNames() {
  210. Result res = new Result();
  211. res.setData(userService.selectDemandUnitNames());
  212. return res;
  213. }
  214. /**
  215. * 需求资料--图片上传
  216. */
  217. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  218. public Result uploadPicture(HttpServletRequest req, String sign, String uid) {
  219. Result res = new Result();
  220. if (StringUtils.isBlank(uid)) {
  221. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户ID", "用户ID"));
  222. return res;
  223. }
  224. AttachmentType attachmentType = AttachmentType.getField(sign);
  225. if (attachmentType == AttachmentType.DEMAND_PICTURE|| attachmentType == AttachmentType.DEMAND_COVER_PICTURE) {
  226. res.setData(handleFiles(res, "/demand/", false, req, sign, uid));
  227. } else {
  228. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  229. }
  230. return res;
  231. }
  232. /**
  233. * 需求资料--文本文件上传
  234. */
  235. @RequestMapping(value = "/uploadTextFile", method = RequestMethod.POST)
  236. public Result uploadTextFile(HttpServletRequest req, String sign, String uid) {
  237. Result res = new Result();
  238. if (StringUtils.isBlank(uid)) {
  239. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户ID", "用户ID"));
  240. return res;
  241. }
  242. AttachmentType attachmentType = AttachmentType.getField(sign);
  243. if (attachmentType == AttachmentType.DEMAND_TEXT_FILE) {
  244. res.setData(handleFiles(res, "/demand/", false, req, sign, uid));
  245. } else {
  246. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  247. }
  248. return res;
  249. }
  250. /**
  251. * 需求撤消发布(下架)
  252. */
  253. @RequestMapping(value = "/offShelf", method = RequestMethod.POST)
  254. public Result offShelf(String id,Integer releaseStatus) {
  255. Result res = new Result();
  256. if (StringUtils.isBlank(id)) {
  257. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
  258. return res;
  259. }
  260. Demand d = demandService.selectByPrimaryKey(id);
  261. if (null == d) {
  262. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID"));
  263. return res;
  264. }
  265. d.setReleaseStatus(releaseStatus);
  266. res.setData(demandService.updateReleaseStatus(d));
  267. return res;
  268. }
  269. /**
  270. * 下载需求文件--文本文件
  271. */
  272. @RequestMapping(value = "/download", method = RequestMethod.GET)
  273. public Result download(HttpServletResponse response, String id) {
  274. Result res = new Result();
  275. if (StringUtils.isEmpty(id)) {
  276. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID"));
  277. return res;
  278. }
  279. Demand d = demandService.selectByPrimaryKey(id);
  280. if (null == d) {
  281. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID"));
  282. return res;
  283. }
  284. downloadUnPrivateFile(response, d.getTextFileDownloadFileName(), d.getTextFileUrl());
  285. return res;
  286. }
  287. /**
  288. * 我的需求列表
  289. */
  290. @RequestMapping(value = "/myList", method = RequestMethod.GET)
  291. public Result myList(String pageNo, String pageSize) {
  292. Result res = new Result();
  293. // res.setData(null) todo;
  294. return res;
  295. }
  296. /**
  297. * 需求发布
  298. */
  299. @RequestMapping(value = "/addDemandPublish", method = RequestMethod.POST)
  300. private Result addDemandPublish(DemandPublish d) {
  301. Result res = new Result();
  302. if (StringUtils.isBlank(d.getDemandId())) {
  303. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求", "需求"));
  304. return res;
  305. }
  306. res.setData(demandPublishService.insertDemandPublish(d));
  307. return res;
  308. }
  309. /**
  310. * 撤销发布
  311. */
  312. @RequestMapping(value = "/deletePublish", method = RequestMethod.GET)
  313. private Result deletePublish(String id) {
  314. Result res = new Result();
  315. res.setData(demandPublishService.deletePublish(id));
  316. return res;
  317. }
  318. /**
  319. * 修改发布
  320. */
  321. @RequestMapping(value = "/updatePublish", method = RequestMethod.GET)
  322. private Result updatePublish(DemandPublish d) {
  323. Result res = new Result();
  324. res.setData(demandPublishService.updatePublish(d));
  325. return res;
  326. }
  327. /**
  328. * 发布列表
  329. */
  330. @RequestMapping(value = "/listPublish", method = RequestMethod.GET)
  331. private Result listPublish(String name,String publishPlatform,Integer publishClient,String publishPage,
  332. Integer ifTop, Integer pageNo, Integer pageSize,String employerName) {
  333. Result res = new Result();
  334. if (null==pageNo) {
  335. pageNo=1;
  336. }
  337. if (null==pageSize) {
  338. pageSize=10;
  339. }
  340. res.setData(demandPublishService.listPublish( name, publishPlatform, publishClient, publishPage,
  341. ifTop, pageNo, pageSize,employerName));
  342. return res;
  343. }
  344. /**
  345. * 获取需求页面位置
  346. */
  347. @RequestMapping(value="/getPublishPage",method = RequestMethod.GET)
  348. private Result getPublishPage(){
  349. Result res=new Result();
  350. return res.data(DemandPublishPageService.getBranchInformation());
  351. }
  352. }