Browse Source

需求资料--图片及文本文件上传

Antiloveg 8 years ago
parent
commit
175654c7ca

+ 47 - 0
src/main/java/com/goafanti/admin/controller/AdminDemandApiController.java

@@ -2,6 +2,7 @@ package com.goafanti.admin.controller;
 
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 
 import org.springframework.beans.BeanUtils;
@@ -13,6 +14,7 @@ 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.DemandDataCategory;
 import com.goafanti.common.enums.DemandFields;
 import com.goafanti.common.enums.DemandReleaseStatus;
@@ -26,6 +28,51 @@ import com.goafanti.demand.service.DemandService;
 public class AdminDemandApiController extends CertifyApiController {
 	@Resource
 	private DemandService demandService;
+	
+	
+	/**
+	 * 需求资料--图片上传
+	 */
+	@RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
+	public Result uploadPicture(HttpServletRequest req, String sign, String uid) {
+		Result res = new Result();
+		if (StringUtils.isBlank(uid)){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户ID", "用户ID"));
+			return res;
+		}
+		
+		AttachmentType attachmentType = AttachmentType.getField(sign);
+
+		if (attachmentType == AttachmentType.DEMAND_PICTURE) {
+			res.setData(handleFiles(res, "/demand/", false, req, sign, uid));
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+		}
+		
+		return res;
+	}
+	
+	/**
+	 * 需求资料--文本文件上传
+	 */
+	@RequestMapping(value = "/uploadTextFile", method = RequestMethod.POST)
+	public Result uploadTextFile(HttpServletRequest req, String sign, String uid){
+		Result res = new Result();
+	
+		if (StringUtils.isBlank(uid)){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户ID", "用户ID"));
+			return res;
+		}
+		
+		AttachmentType attachmentType = AttachmentType.getField(sign);
+
+		if (attachmentType == AttachmentType.DEMAND_TEXT_FILE) {
+			res.setData(handleFiles(res, "/demand/", false, req, sign, uid));
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+		}
+		return res;
+	}
 
 	/**
 	 * 个人用户--需求列表

+ 7 - 3
src/main/java/com/goafanti/common/controller/BaseApiController.java

@@ -163,7 +163,7 @@ public class BaseApiController extends BaseController {
 		}
 		return 10;
 	}
-	
+
 	protected String handleFiles(Result res, String path, boolean isPrivate, HttpServletRequest req, String sign,
 			String uid) {
 		List<MultipartFile> files = getFiles(req);
@@ -173,7 +173,11 @@ public class BaseApiController extends BaseController {
 				StringUtils.isBlank(uid) ? TokenManager.getUserId() : uid);
 		if (!files.isEmpty()) {
 			try {
-				mf.transferTo(toPrivateFile(fileName));
+				if (isPrivate) {
+					mf.transferTo(toPrivateFile(fileName));
+				} else {
+					mf.transferTo(toFile(fileName));
+				}
 				LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
 			} catch (IllegalStateException | IOException e) {
 				LoggerUtils.error(getClass(), "文件上传失败", e);
@@ -185,5 +189,5 @@ public class BaseApiController extends BaseController {
 			return "";
 		}
 		return fileName;
-	} 
+	}
 }

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

@@ -12,7 +12,8 @@ public enum AttachmentType {
 	PROPERTY_RIGHT("property_right", "知识产权证书"), ACHIEVEMENT("achievement", "科技成果附件"), RATEPAY("ratepay", "企业纳税申报表"),
 	FINANCE("finance", "企业财务报表"), ROSTER("roster", "企业花名册"), SOCIAL_SECURITY("social_security", "企业社保情况表"), 
 	HONOR("honor", "荣誉及其他证明材料"), LAST_YEAR_RATEPAY("last_year_ratepay", "上年度纳税申报表"), TECH_PROJECT("tech_project", "科技项目申报材料"),
-	STANDARD("standard", "标准制定附件"), MANUSCRIPT("manuscript", "知识产权稿件"), ORGCODE("orgcode", "组织结构代码证"), LICENCE("licence", "营业执照");
+	STANDARD("standard", "标准制定附件"), MANUSCRIPT("manuscript", "知识产权稿件"), ORGCODE("orgcode", "组织结构代码证"), LICENCE("licence", "营业执照"),
+	DEMAND_PICTURE("demand_picture", "需求图片资料"), DEMAND_TEXT_FILE("demand_text_file", "需求文本文件资料");
 
 	private AttachmentType(String code, String desc) {
 		this.code = code;

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

@@ -99,7 +99,8 @@ public class FileUtils {
 				|| sign.indexOf("tech_product") != -1 || sign.indexOf("property_ritht") != -1
 				|| sign.indexOf("tech_project") != -1 || sign.indexOf("patent_prory_statement") != -1
 				|| sign.indexOf("patent_writing") != -1 || sign.indexOf("authorization_notice") != -1
-				|| sign.indexOf("patent_certificate") != -1 || sign.indexOf("standard") != -1) {
+				|| sign.indexOf("patent_certificate") != -1 || sign.indexOf("standard") != -1
+				|| sign.indexOf("demand_picture") != -1 || sign.indexOf("demand_text_file") != -1) {
 			uniq = true;
 		}
 		String fileName = "";