Browse Source

1.管理端--科技需求批量导入模版上传及下载;
2.用户端--科技需求批量导入模板下载

Antiloveg 8 years ago
parent
commit
b4d0087f7a

+ 99 - 3
src/main/java/com/goafanti/admin/controller/AdminDemandApiController.java

@@ -1,6 +1,9 @@
 package com.goafanti.admin.controller;
 
+import java.io.IOException;
 import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -13,16 +16,21 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
+import com.goafanti.admin.service.AftFileService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 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.DemandDataCategory;
 import com.goafanti.common.enums.DemandFields;
+import com.goafanti.common.model.AftFile;
 import com.goafanti.common.model.Demand;
+import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.demand.bo.InputDemand;
 import com.goafanti.demand.service.DemandService;
@@ -35,6 +43,75 @@ public class AdminDemandApiController extends CertifyApiController {
 	private DemandService	demandService;
 	@Resource
 	private UserService		userService;
+	@Resource
+	private AftFileService	aftFileService;
+	
+	
+
+	/**
+	 * 上传技术需求批量导入Excel模板
+	 * 
+	 * @param req
+	 * @return
+	 */
+	@RequestMapping(value = "/uploadTemplate", method = RequestMethod.POST)
+	public Result uploadPatentTemplate(HttpServletRequest req, String sign) {
+		Result res = new Result();
+		String fileName = "";
+		List<MultipartFile> files = getFiles(req);
+		MultipartFile mf = files.get(0);
+		String suffix = mf.getOriginalFilename().substring(mf.getOriginalFilename().lastIndexOf("."));
+		if (suffix.equals(".xls") || suffix.equals(".xlsx")) {
+			AttachmentType attachmentType = AttachmentType.getField(sign);
+			if (attachmentType == AttachmentType.DEMAND_TEMPLATE) {
+				fileName = sign + suffix;
+			} else {
+				res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+				return res;
+			}
+			String name = handleFile(res, req, fileName, files, mf);
+			res.setData(name);
+			if (!StringUtils.isBlank(name) && null == aftFileService.selectAftFileBySign(sign)) {
+				AftFile f = new AftFile();
+				f.setId(UUID.randomUUID().toString());
+				f.setFileName(AttachmentType.DEMAND_TEMPLATE.getDesc());
+				f.setSign(sign);
+				f.setFilePath("/admin/" + fileName);
+				f.setDeleletedSign(DeleteStatus.UNDELETE.getCode());
+				aftFileService.insert(f);
+			}
+		} else {
+			res.getError().add(buildError(ErrorConstants.FILE_PATTERN_ERROR, "文件格式错误,请重新上传!"));
+		}
+		return res;
+	}
+	
+	/**
+	 * 下载技术需求批量导入Excel模板
+	 * 
+	 * @param response
+	 * @return
+	 */
+	@RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
+	public Result downloadTemplateFile(HttpServletResponse response, String sign) {
+		Result res = new Result();
+		AttachmentType attachmentType = AttachmentType.getField(sign);
+		if (attachmentType == AttachmentType.DEMAND_TEMPLATE) {
+			String fileName = "";
+			AftFile af = aftFileService.selectAftFileBySign(sign);
+			if (null == af) {
+				res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
+			} else {
+				String path = af.getFilePath();
+				String suffix = path.substring(path.lastIndexOf("."));
+				fileName = AttachmentType.DEMAND_TEMPLATE.getDesc() + suffix;
+				downloadFile(response, fileName, path);
+			}
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+		}
+		return res;
+	}
 
 	/**
 	 * 个人用户--需求列表
@@ -346,9 +423,9 @@ public class AdminDemandApiController extends CertifyApiController {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到问题说明", "问题说明"));
 			return res;
 		}
-		
-		for (int i=0; i<keywords.length; i++){
-			if (AFTConstants.KEYWORDLENTH < keywords[i].length()){
+
+		for (int i = 0; i < keywords.length; i++) {
+			if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
 				res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
 				return res;
 			}
@@ -356,4 +433,23 @@ public class AdminDemandApiController extends CertifyApiController {
 
 		return res;
 	}
+
+	private String handleFile(Result res, HttpServletRequest req, String fileName, List<MultipartFile> files,
+			MultipartFile mf) {
+		if (!files.isEmpty()) {
+			try {
+				mf.transferTo(toAdminPrivateFile(fileName));
+				LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
+			} catch (IllegalStateException | IOException e) {
+				LoggerUtils.error(getClass(), "文件上传失败", e);
+				res.getError().add(buildError("", "文件上传失败!"));
+				return "";
+			}
+		} else {
+			res.getError().add(buildError("", "文件上传失败!"));
+			return "";
+		}
+		return fileName;
+	}
+
 }

+ 34 - 33
src/main/java/com/goafanti/admin/controller/AdminPatentApiController.java

@@ -156,9 +156,9 @@ public class AdminPatentApiController extends CertifyApiController {
 	 * @throws ParseException
 	 */
 	@RequestMapping(value = "/patentList", method = RequestMethod.GET)
-	public Result patentList(String contractId, Integer serialNumber, String patentNumber, String office, String locationProvince,
-			String unitName, Integer patentCatagory, String patentName, Integer patentState, String uid,
-			@RequestParam(name = "createTime[]", required = false) String[] createTime,
+	public Result patentList(String contractId, Integer serialNumber, String patentNumber, String office,
+			String locationProvince, String unitName, Integer patentCatagory, String patentName, Integer patentState,
+			String uid, @RequestParam(name = "createTime[]", required = false) String[] createTime,
 			@RequestParam(name = "patentApplicationDate[]", required = false) String[] patentApplicationDate,
 			String author, String pageNo, String pageSize) {
 		Result res = new Result();
@@ -167,13 +167,13 @@ public class AdminPatentApiController extends CertifyApiController {
 		if (StringUtils.isNumeric(pageSize)) {
 			pSize = Integer.parseInt(pageSize);
 		}
-		
+
 		if (StringUtils.isNumeric(pageNo)) {
 			pNo = Integer.parseInt(pageNo);
 		}
-		res.setData(patentInfoService.getManagePatentList(contractId, serialNumber, patentNumber, office, locationProvince,
-				unitName, patentCatagory, patentName, patentState, createTime, patentApplicationDate, author, uid, pNo,
-				pSize));
+		res.setData(patentInfoService.getManagePatentList(contractId, serialNumber, patentNumber, office,
+				locationProvince, unitName, patentCatagory, patentName, patentState, createTime, patentApplicationDate,
+				author, uid, pNo, pSize));
 		return res;
 	}
 
@@ -193,12 +193,12 @@ public class AdminPatentApiController extends CertifyApiController {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
 			return res;
 		}
-		
-		if (StringUtils.isBlank(patentInfo.getSalesman())){
+
+		if (StringUtils.isBlank(patentInfo.getSalesman())) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到营销员", "营销员"));
 			return res;
 		}
-		
+
 		String salesman = patentInfo.getSalesman();
 
 		User curUser = userService.selectByPrimaryKey(patentInfo.getUid());
@@ -473,15 +473,15 @@ public class AdminPatentApiController extends CertifyApiController {
 			String fileName = "";
 			AftFile af = aftFileService.selectAftFileBySign(sign);
 			if (null == af) {
-				res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "找不到", "文件"));
+				res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件"));
 			} else {
 				String path = af.getFilePath();
 				String suffix = path.substring(path.lastIndexOf("."));
-				fileName = "专利代理委托书模版" + suffix;
+				fileName = AttachmentType.PATENT_TEMPLATE.getDesc() + suffix;
 				downloadFile(response, fileName, path);
 			}
 		} else {
-			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "专利代理委托书标示"));
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
 		}
 		return res;
 	}
@@ -532,23 +532,21 @@ public class AdminPatentApiController extends CertifyApiController {
 		List<MultipartFile> files = getFiles(req);
 		MultipartFile mf = files.get(0);
 		String suffix = mf.getOriginalFilename().substring(mf.getOriginalFilename().lastIndexOf("."));
-		System.err.println("suffix" + " " + suffix);
 		if (suffix.equals(".doc") || suffix.equals(".docx")) {
-			if ("patent_prory_statement".equals(sign)) {
-				fileName = "patent_prory_statement" + suffix;
+			AttachmentType attachmentType = AttachmentType.getField(sign);
+			if (attachmentType == AttachmentType.PATENT_PRORY_STATEMENT) {
+				fileName = sign + suffix;
 			} else {
-				fileName = System.nanoTime() + "";
+				res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+				return res;
 			}
 			String name = handleFile(res, req, fileName, files, mf);
 			res.setData(name);
-			System.out.println(name);
-			if (res.getData() != "" && res.getData() != null && null == aftFileService.selectAftFileBySign(sign)) {
+			if (!StringUtils.isBlank(name) && null == aftFileService.selectAftFileBySign(sign)) {
 				AftFile f = new AftFile();
 				f.setId(UUID.randomUUID().toString());
-				if ("patent_prory_statement".equals(sign)) {
-					f.setFileName("专利代理委托书模版");
-					f.setSign(sign);
-				}
+				f.setFileName(AttachmentType.PATENT_TEMPLATE.getDesc());
+				f.setSign(sign);
 				f.setFilePath("/admin/" + fileName);
 				f.setDeleletedSign(DeleteStatus.UNDELETE.getCode());
 				aftFileService.insert(f);
@@ -819,8 +817,9 @@ public class AdminPatentApiController extends CertifyApiController {
 	 */
 	@SuppressWarnings("unchecked")
 	@RequestMapping(value = "/exportComposite", method = RequestMethod.GET)
-	public Result exportComposite(String contractId, @RequestParam(name = "serialNumber", required = false) String serialNumber,
-			String patentNumber, String office, String locationProvince, String unitName, String uid,
+	public Result exportComposite(String contractId,
+			@RequestParam(name = "serialNumber", required = false) String serialNumber, String patentNumber,
+			String office, String locationProvince, String unitName, String uid,
 			@RequestParam(name = "patentCatagory", required = false) String patentCatagory, String patentName,
 			@RequestParam(name = "patentState", required = false) String patentState,
 			@RequestParam(name = "createTime[]", required = false) String[] createTime,
@@ -832,8 +831,9 @@ public class AdminPatentApiController extends CertifyApiController {
 		Integer pc = (!StringUtils.isNumeric(patentCatagory) ? null : Integer.parseInt(patentCatagory));
 		Integer ps = (!StringUtils.isNumeric(patentState) ? null : Integer.parseInt(patentState));
 		String lp = ("undefined".equals(locationProvince)) ? null : locationProvince;
-		List<PatentManageListBo> composites = (List<PatentManageListBo>) getManagePatentList(contractId, sn, patentNumber, office,
-				lp, unitName, pc, patentName, ps, createTime, patentApplicationDate, author, uid, 1, 1000).getList();
+		List<PatentManageListBo> composites = (List<PatentManageListBo>) getManagePatentList(contractId, sn,
+				patentNumber, office, lp, unitName, pc, patentName, ps, createTime, patentApplicationDate, author, uid,
+				1, 1000).getList();
 		if (res.getError().isEmpty()) {
 			exportComosites(response, composites);
 		} else {
@@ -1139,12 +1139,13 @@ public class AdminPatentApiController extends CertifyApiController {
 	}
 
 	// 管理端申请专利列表(专利综合管理)
-	private Pagination<PatentManageListBo> getManagePatentList(String contractId, Integer serialNumber, String patentNumber, String office,
-			String locationProvince, String unitName, Integer patentCatagory, String patentName, Integer patentState,
-			String[] createTime, String[] patentApplicationDate, String author, String uid, Integer pNo, Integer pSize)
-			throws ParseException {
-		return patentInfoService.getManagePatentList(contractId, serialNumber, patentNumber, office, locationProvince, unitName,
-				patentCatagory, patentName, patentState, createTime, patentApplicationDate, author, uid, pNo, pSize);
+	private Pagination<PatentManageListBo> getManagePatentList(String contractId, Integer serialNumber,
+			String patentNumber, String office, String locationProvince, String unitName, Integer patentCatagory,
+			String patentName, Integer patentState, String[] createTime, String[] patentApplicationDate, String author,
+			String uid, Integer pNo, Integer pSize) throws ParseException {
+		return patentInfoService.getManagePatentList(contractId, serialNumber, patentNumber, office, locationProvince,
+				unitName, patentCatagory, patentName, patentState, createTime, patentApplicationDate, author, uid, pNo,
+				pSize);
 	}
 
 	// 缴费截止日期

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

@@ -6,7 +6,8 @@ import java.util.Map;
 public enum AttachmentType {
 	COPYRIGHT_AUTH("copyright_auth", "软著证书"), COPYRIGHT_APPLY("copyright_apply", "软著申请书"), DEFAULT("attachment", "附件"),
 	PATENT_PRORY_STATEMENT("patent_prory_statement", "专利代理委托书"), PATENT_WRITING("patent_writing", "专利稿件"),
-	AUTHORIZATION_NOTICE("authorization_notice", "授权通知书 "), PATENT_CERTIFICATE("patent_certificate", "专利证书"),
+	AUTHORIZATION_NOTICE("authorization_notice", "授权通知书 "), PATENT_CERTIFICATE("patent_certificate", "专利证书"), 
+	PATENT_TEMPLATE("patent_template", "专利代理委托书模版"),
 	INSTITUTION("institution", "研发部门制度"), PROTOCOL("protocol", "产学研技术中心协议"), PROOF("proof", "研发活动立项证明材料"),
 	ACTIVITY_COST_ACCOUNT("activity_cost_account", "研发活动费用台帐"), TECH_PRODUCT("tech_product", "高新技术产品台帐"),
 	PROPERTY_RIGHT("property_right", "知识产权证书"), ACHIEVEMENT("achievement", "科技成果附件"), RATEPAY("ratepay", "企业纳税申报表"),
@@ -18,7 +19,9 @@ public enum AttachmentType {
 	ACHIEVEMENT_MATURITY_PICTURE("achievement_maturity_picture", "科技成果成熟度资料图片"),
 	ACHIEVEMENT_MATURITY_TEXT_FILE("achievement_maturity_text_file", "科技成果成熟度资料文本文件"),
 	ACHIEVEMENT_TECH_PLAN("achievement_tech_plan", "科技成果技术方案文件"),
-	ACHIEVEMENT_BUSINESS_PLAN("achievement_business_plan", "科技成果商业计划书");
+	ACHIEVEMENT_BUSINESS_PLAN("achievement_business_plan", "科技成果商业计划书"),
+	DEMAND_TEMPLATE("demand_template", "科技需求批量导入EXCEL模板"),
+	;
 
 	private AttachmentType(String code, String desc) {
 		this.code = code;

+ 28 - 0
src/main/java/com/goafanti/demand/controller/DemandApiController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.goafanti.admin.service.AftFileService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
@@ -22,6 +23,7 @@ import com.goafanti.common.enums.AttachmentType;
 import com.goafanti.common.enums.DemandAuditStatus;
 import com.goafanti.common.enums.DemandDataCategory;
 import com.goafanti.common.enums.DemandFields;
+import com.goafanti.common.model.AftFile;
 import com.goafanti.common.model.Demand;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.shiro.token.TokenManager;
@@ -33,6 +35,32 @@ import com.goafanti.demand.service.DemandService;
 public class DemandApiController extends CertifyApiController{
 	@Resource
 	private DemandService demandService;
+	@Resource
+	private AftFileService aftFileService;
+	
+	/**
+	 * 下载技术需求批量导入Excel模板
+	 */
+	@RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
+	public Result downloadTemplateFile(HttpServletResponse response, String sign) {
+		Result res = new Result();
+		AttachmentType attachmentType = AttachmentType.getField(sign);
+		if (attachmentType == AttachmentType.DEMAND_TEMPLATE) {
+			String fileName = "";
+			AftFile af = aftFileService.selectAftFileBySign(sign);
+			if (null == af) {
+				res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
+			} else {
+				String path = af.getFilePath();
+				String suffix = path.substring(path.lastIndexOf("."));
+				fileName = AttachmentType.DEMAND_TEMPLATE.getDesc() + suffix;
+				downloadFile(response, fileName, path);
+			}
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+		}
+		return res;
+	}
 	
 	/**
 	 * 用户需求列表

+ 2 - 2
src/main/java/com/goafanti/patent/controller/PatentApiController.java

@@ -159,11 +159,11 @@ public class PatentApiController extends CertifyApiController {
 			String fileName = "";
 			AftFile af = aftFileService.selectAftFileBySign(sign);
 			if (null == af) {
-				res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "找不到", "文件"));
+				res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件"));
 			} else {
 				String path = af.getFilePath();
 				String suffix = path.substring(path.lastIndexOf("."));
-				fileName = "专利代理委托书模版" + suffix;
+				fileName = AttachmentType.PATENT_TEMPLATE.getDesc() + suffix;
 				downloadFile(response, fileName, path);
 			}
 		} else {