package com.goafanti.portal.controller; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.goafanti.common.bo.Result; import com.goafanti.common.constant.ErrorConstants; import com.goafanti.common.controller.CertifyApiController; import com.goafanti.common.enums.AttachmentType; import com.goafanti.common.enums.DeleteStatus; import com.goafanti.common.enums.DemandAuditStatus; import com.goafanti.common.enums.DemandOrderFields; import com.goafanti.common.enums.DemandReleaseStatus; import com.goafanti.common.model.Demand; import com.goafanti.common.model.DemandOrder; import com.goafanti.common.model.DemandOrderLog; import com.goafanti.core.shiro.token.TokenManager; import com.goafanti.demand.bo.InputDemandOrder; import com.goafanti.demand.service.DemandOrderService; import com.goafanti.demand.service.DemandService; @RestController @RequestMapping(value = "/api/user/portal/order") public class PortalOrderApiController extends CertifyApiController { @Resource private DemandOrderService demandOrderService; @Resource private DemandService demandService; /** * 附件上传 */ @RequestMapping(value = "/upload", method = RequestMethod.POST) public Result uploadTextFile(HttpServletRequest req, String sign) { Result res = new Result(); AttachmentType attachmentType = AttachmentType.getField(sign); if (attachmentType == AttachmentType.DEMAND_ORDER_FILE) { res.setData(handleFiles(res, "/demandOrder/", false, req, sign, TokenManager.getUserId())); } else { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示")); } return res; } /** * 下载文件 */ @RequestMapping(value = "/download", method = RequestMethod.GET) public Result download(HttpServletResponse response, String id) { Result res = new Result(); if (StringUtils.isEmpty(id)) { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技需求订单ID")); return res; } DemandOrder order = demandOrderService.selectByPrimaryKey(id); if (null == order) { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技需求订单ID")); return res; } downloadUnPrivateFile(response, order.getEnclosureDownloadFileName(), order.getEnclosureUrl()); return res; } /** * "我要接单" */ @RequestMapping(value = "/orderDemand", method = RequestMethod.POST) public Result order(@Valid InputDemandOrder inputDemandOrder, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), DemandOrderFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } if (StringUtils.isBlank(inputDemandOrder.getDemandId())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID")); return res; } DemandOrder demandOrder = demandOrderService.selectDemandOrderByUidAndDemandId(TokenManager.getUserId(), inputDemandOrder.getDemandId()); if (null != demandOrder) { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "当前科技需求已接单!")); return res; } Demand d = demandService.selectByPrimaryKey(inputDemandOrder.getDemandId()); if (null == d || d.getDeletedSign().equals(DeleteStatus.DELETED.getCode()) || !d.getAuditStatus().equals(DemandAuditStatus.AUDITED.getCode()) || !d.getReleaseStatus().equals(DemandReleaseStatus.RELEASED.getCode())) { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技需求ID")); return res; } DemandOrder order = new DemandOrder(); DemandOrderLog dol = new DemandOrderLog(); BeanUtils.copyProperties(inputDemandOrder, order); BeanUtils.copyProperties(inputDemandOrder, dol); demandOrderService.saveDemandOrder(order, dol); return res; } //@RequestMapping(value = "/shutdown", method = ) }