PortalOrderApiController.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.goafanti.portal.controller;
  2. import javax.annotation.Resource;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import javax.validation.Valid;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.springframework.beans.BeanUtils;
  8. import org.springframework.validation.BindingResult;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import com.goafanti.common.bo.Result;
  13. import com.goafanti.common.constant.ErrorConstants;
  14. import com.goafanti.common.controller.CertifyApiController;
  15. import com.goafanti.common.enums.AttachmentType;
  16. import com.goafanti.common.enums.DeleteStatus;
  17. import com.goafanti.common.enums.DemandAuditStatus;
  18. import com.goafanti.common.enums.DemandOrderFields;
  19. import com.goafanti.common.enums.DemandReleaseStatus;
  20. import com.goafanti.common.model.Demand;
  21. import com.goafanti.common.model.DemandOrder;
  22. import com.goafanti.common.model.DemandOrderLog;
  23. import com.goafanti.core.shiro.token.TokenManager;
  24. import com.goafanti.demand.bo.InputDemandOrder;
  25. import com.goafanti.demand.service.DemandOrderService;
  26. import com.goafanti.demand.service.DemandService;
  27. @RestController
  28. @RequestMapping(value = "/api/user/portal/order")
  29. public class PortalOrderApiController extends CertifyApiController {
  30. @Resource
  31. private DemandOrderService demandOrderService;
  32. @Resource
  33. private DemandService demandService;
  34. /**
  35. * 附件上传
  36. */
  37. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  38. public Result uploadTextFile(HttpServletRequest req, String sign) {
  39. Result res = new Result();
  40. AttachmentType attachmentType = AttachmentType.getField(sign);
  41. if (attachmentType == AttachmentType.DEMAND_ORDER_FILE) {
  42. res.setData(handleFiles(res, "/demandOrder/", false, req, sign, TokenManager.getUserId()));
  43. } else {
  44. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  45. }
  46. return res;
  47. }
  48. /**
  49. * 下载文件
  50. */
  51. @RequestMapping(value = "/download", method = RequestMethod.GET)
  52. public Result download(HttpServletResponse response, String id) {
  53. Result res = new Result();
  54. if (StringUtils.isEmpty(id)) {
  55. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技需求订单ID"));
  56. return res;
  57. }
  58. DemandOrder order = demandOrderService.selectByPrimaryKey(id);
  59. if (null == order) {
  60. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技需求订单ID"));
  61. return res;
  62. }
  63. downloadUnPrivateFile(response, order.getEnclosureDownloadFileName(), order.getEnclosureUrl());
  64. return res;
  65. }
  66. /**
  67. * "我要接单"
  68. */
  69. @RequestMapping(value = "/orderDemand", method = RequestMethod.POST)
  70. public Result order(@Valid InputDemandOrder inputDemandOrder, BindingResult bindingResult) {
  71. Result res = new Result();
  72. if (bindingResult.hasErrors()) {
  73. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  74. DemandOrderFields.getFieldDesc(bindingResult.getFieldError().getField())));
  75. return res;
  76. }
  77. if (StringUtils.isBlank(inputDemandOrder.getDemandId())) {
  78. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
  79. return res;
  80. }
  81. DemandOrder demandOrder = demandOrderService.selectDemandOrderByUidAndDemandId(TokenManager.getUserId(), inputDemandOrder.getDemandId());
  82. if (null != demandOrder) {
  83. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "当前科技需求已接单!"));
  84. return res;
  85. }
  86. Demand d = demandService.selectByPrimaryKey(inputDemandOrder.getDemandId());
  87. if (null == d || d.getDeletedSign().equals(DeleteStatus.DELETED.getCode())
  88. || !d.getAuditStatus().equals(DemandAuditStatus.AUDITED.getCode())
  89. || !d.getReleaseStatus().equals(DemandReleaseStatus.RELEASED.getCode())) {
  90. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技需求ID"));
  91. return res;
  92. }
  93. DemandOrder order = new DemandOrder();
  94. DemandOrderLog dol = new DemandOrderLog();
  95. BeanUtils.copyProperties(inputDemandOrder, order);
  96. BeanUtils.copyProperties(inputDemandOrder, dol);
  97. demandOrderService.saveDemandOrder(order, dol);
  98. return res;
  99. }
  100. //@RequestMapping(value = "/shutdown", method = )
  101. }