Browse Source

科技需求交易订单--"我要接单"
附件上传及下载

Antiloveg 8 years ago
parent
commit
fa6f8b5b2c

+ 2 - 1
src/main/java/com/goafanti/common/enums/AttachmentType.java

@@ -20,7 +20,8 @@ public enum AttachmentType {
 	ACHIEVEMENT_MATURITY_TEXT_FILE("achievement_maturity_text_file", "科技成果成熟度资料文本文件"),
 	ACHIEVEMENT_TECH_PLAN("achievement_tech_plan", "科技成果技术方案文件"),
 	ACHIEVEMENT_BUSINESS_PLAN("achievement_business_plan", "科技成果商业计划书"),
-	DEMAND_TEMPLATE("demand_template", "科技需求批量导入模板"), ACHIEVEMENT_TEMPLATE("achievement_template", "科技成果批量导入模板")
+	DEMAND_TEMPLATE("demand_template", "科技需求批量导入模板"), ACHIEVEMENT_TEMPLATE("achievement_template", "科技成果批量导入模板"), 
+	DEMAND_ORDER_FILE("demand_order_file", "科技需求意向单/交易单附件")
 	;
 
 	private AttachmentType(String code, String desc) {

+ 59 - 0
src/main/java/com/goafanti/common/enums/DemandOrderFields.java

@@ -0,0 +1,59 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum DemandOrderFields {
+	DEMANDID("demandId", "科技需求ID"),
+	ENCLOSUREURL("enclosureUrl", "附件URL"),
+	STATUS("status", "状态"),
+	INTENTIONMONEY("intentionMoney", "意向金"),
+	
+	CONTRACTMONEY("contractMoney", "合同金"),
+	COMMISSION("commission", "佣金"),
+	SERVICEMONEY("serviceMoney", "服务金"),
+	REFUND("refund", "退款状态"),
+	
+	COMMENT("comment", "备注"),
+	
+	OTHER("", "未知参数");
+	
+	private String	code;
+	private String	desc;
+	
+	private static Map<String, DemandOrderFields> status = new HashMap<String, DemandOrderFields>();
+	
+	private DemandOrderFields(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+	
+	static {
+		for (DemandOrderFields value : DemandOrderFields.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+	
+	public static DemandOrderFields getField(String code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+	
+	public static String getFieldDesc(String code) {
+		return getField(code).getDesc();
+	}
+
+	public static boolean containsType(String code) {
+		return status.containsKey(code);
+	}
+	
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+}

+ 1 - 1
src/main/java/com/goafanti/common/enums/DemandOrderStatus.java

@@ -12,7 +12,7 @@ public enum DemandOrderStatus {
 	CONTRACTMONEY(3, "交付合同金"),
 	COMMISSION(4,"交付佣金"),
 	SERVICEMONEY(5, "交付服务金"),
-	CLOSE(6,"关闭订单"),
+	SHUTDOWN(6,"关闭订单"),
 	OTHER(7, "其他");
 
 	private DemandOrderStatus(Integer code, String desc) {

+ 16 - 0
src/main/java/com/goafanti/common/model/DemandOrder.java

@@ -2,6 +2,10 @@ package com.goafanti.common.model;
 
 import java.util.Date;
 
+import org.apache.commons.lang3.StringUtils;
+
+import com.goafanti.common.utils.FileUtils;
+
 public class DemandOrder {
     private String id;
 
@@ -168,4 +172,16 @@ public class DemandOrder {
     public void setDeletedSign(Integer deletedSign) {
         this.deletedSign = deletedSign;
     }
+    
+    public String getEnclosureDownloadFileName(){
+		if (StringUtils.isBlank(this.enclosureUrl)){
+			return null;
+		} else {
+			return FileUtils.getDownloadFileName(this.enclosureUrl);
+		}
+	}
+		
+	public void setEnclosureDownloadFileName(String enclosureDownloadFileName){
+			
+	}
 }

+ 2 - 1
src/main/java/com/goafanti/common/utils/FileUtils.java

@@ -104,7 +104,8 @@ public class FileUtils {
 				|| sign.indexOf("patent_certificate") != -1 || sign.indexOf("standard") != -1
 				|| sign.indexOf("demand_picture") != -1 || sign.indexOf("demand_text_file") != -1
 				|| sign.indexOf("achievement_technical_picture") != -1
-				|| sign.indexOf("achievement_maturity_picture") != -1) {
+				|| sign.indexOf("achievement_maturity_picture") != -1
+				|| sign.indexOf("demand_order_file") != -1) {
 			uniq = true;
 		}
 		String fileName = "";

+ 2 - 0
src/main/java/com/goafanti/demand/service/DemandOrderService.java

@@ -9,4 +9,6 @@ public interface DemandOrderService {
 
 	void saveDemandOrder(DemandOrder order, DemandOrderLog dol);
 
+	DemandOrder selectByPrimaryKey(String id);
+
 }

+ 5 - 0
src/main/java/com/goafanti/demand/service/impl/DemandOrderServiceImpl.java

@@ -45,4 +45,9 @@ public class DemandOrderServiceImpl implements DemandOrderService {
 		
 	}
 
+	@Override
+	public DemandOrder selectByPrimaryKey(String id) {
+		return demandOrderMapper.selectByPrimaryKey(id);
+	}
+
 }

+ 50 - 0
src/main/java/com/goafanti/portal/controller/PortalOrderApiController.java

@@ -1,6 +1,8 @@
 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;
@@ -13,8 +15,10 @@ 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;
@@ -31,6 +35,45 @@ public class PortalOrderApiController extends CertifyApiController {
 	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;
+	}
 
 	/**
 	 * "我要接单"
@@ -38,6 +81,11 @@ public class PortalOrderApiController extends CertifyApiController {
 	@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;
@@ -63,4 +111,6 @@ public class PortalOrderApiController extends CertifyApiController {
 		demandOrderService.saveDemandOrder(order, dol);
 		return res;
 	}
+	
+	//@RequestMapping(value = "/shutdown", method = )
 }

+ 2 - 1
src/main/java/com/goafanti/techproject/controller/TechProjectApiController.java

@@ -19,6 +19,7 @@ import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.enums.AttachmentType;
 import com.goafanti.common.enums.CopyrightFields;
+import com.goafanti.common.enums.TechProjectFields;
 import com.goafanti.common.enums.TechProjectStatus;
 import com.goafanti.common.model.TechProject;
 import com.goafanti.common.model.TechProjectLog;
@@ -170,7 +171,7 @@ public class TechProjectApiController extends CertifyApiController {
 		Result res = new Result();
 		if (bindingResult.hasErrors()) {
 			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
-					CopyrightFields.getFieldDesc(bindingResult.getFieldError().getField())));
+					TechProjectFields.getFieldDesc(bindingResult.getFieldError().getField())));
 			return res;
 		}