Browse Source

导出模版待完善

anderx 4 years ago
parent
commit
e4d43e125b

+ 5 - 0
src/main/java/com/goafanti/admin/service/impl/AttachmentServiceImpl.java

@@ -32,6 +32,11 @@ public class AttachmentServiceImpl implements AttachmentService {
 			a.setFileName("模板.xls");
 			a.setFilePath("/tmp/user_channel.xls");
 			return a;
+		}else if (sign.equals("new_patent_template")) {
+			Attachment a=new Attachment();
+			a.setFileName("模板.xls");
+			a.setFilePath("/tmp/new_patent_template.xls");
+			return a;
 		}
 		return null;
 	}

+ 4 - 0
src/main/java/com/goafanti/common/controller/BaseApiController.java

@@ -114,11 +114,15 @@ public class BaseApiController extends BaseController {
 	 */
 	protected void downloadFile(HttpServletResponse res, String fileName, String filePath) {
 		FileUtils.downloadFile(res, fileName,  uploadPath+ filePath);
+		
 	}
 
 	protected void downloadUnPrivateFile(HttpServletResponse res, String fileName, String filePath) {
 		FileUtils.downloadFile(res, fileName, uploadPrivatePath + filePath);
 	}
+	
+	
+	
 
 	private File buildFile(String filePath) {
 		File toFile = new File(filePath);

+ 1 - 1
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -708,7 +708,7 @@ public class PublicController extends CertifyApiController {
               {
                   if (!FileUtils.checkAllowDownload(fileName))
                   {
-                      throw new Exception("文件名称({})非法,不允许下载。 ");
+                      throw new Exception("文件名称非法,不允许下载。 ");
                   }
                   String realFileName =DateUtils.parseDateToStr(AFTConstants.YYYYMMDDHHMMSS, new Date())+fileName.substring(fileName.indexOf("_") + 1);
                   String filePath = uploadPath +"/"+ fileName;

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

@@ -41,6 +41,7 @@ public enum AttachmentType {
 	DEMAND_TEMPLATE("demand_template", "科技需求批量导入模板"),
 	ACHIEVEMENT_TEMPLATE("achievement_template", "科技成果批量导入模板"),
 	RECEIVABLES_TEMPLATE("receivbles_template", "收款批量导入模板"),
+	NEW_PATENT_TEMPLATE("new_patent_template", "新专利导入模板"),
 	USER_CHANNEL("user_channel", "渠道客户导入模板"),
 	DEMAND_ORDER_FILE("demand_order_file", "科技需求意向单/交易单附件"),
 	DEMAND_COVER_PICTURE("demand_cover_picture","科技需求封面图"),

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

@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.multipart.MultipartFile;
 
 import com.goafanti.common.enums.AttachmentType;
+import com.goafanti.common.error.BusinessException;
 
 public class FileUtils {
 	@Value(value = "${upload.private.path}")
@@ -273,6 +274,9 @@ public class FileUtils {
 		OutputStream out = null;
 		byte[] buffer = new byte[8 * 1024];
 		try {
+			if(!com.goafanti.common.utils.excel.FileUtils.checkAllowDownload(realFilePath)){
+                throw new BusinessException("文件名称非法,不允许下载。 ");
+            }
 			File file = new File(realFilePath);
 			in = new FileInputStream(file);
 			out = response.getOutputStream();
@@ -288,7 +292,9 @@ public class FileUtils {
 				}
 				out.write(buffer, 0, bytes);
 			}
-		} catch (IOException e) {
+		}catch (BusinessException e) {
+			LoggerUtils.fmtError(FileUtils.class, e, "名称错误:%s", e.getMessage());
+        } catch (IOException e) {
 			LoggerUtils.fmtError(FileUtils.class, e, "IO错误:%s", e.getMessage());
 		} finally {
 			try {

+ 31 - 1
src/main/java/com/goafanti/patent/controller/AdminPatentNewApiController.java

@@ -5,6 +5,7 @@ import java.text.SimpleDateFormat;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,10 +13,13 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.multipart.MultipartFile;
 
+import com.goafanti.admin.service.AttachmentService;
 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.model.Attachment;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.common.utils.excel.NewExcelUtil;
 import com.goafanti.patent.bo.PatentNewBo;
@@ -28,6 +32,8 @@ public class AdminPatentNewApiController extends CertifyApiController {
 
 	@Resource
 	private PatentNewService patentNewService;
+	@Resource
+	private AttachmentService	attachmentService;
  
 	
 	/**
@@ -116,7 +122,7 @@ public class AdminPatentNewApiController extends CertifyApiController {
 	}
 	
 	/**
-	 * 专利列表
+	 * 导出专利列表
 	 */
 	@RequestMapping(value = "/export", method = RequestMethod.GET)
 	public Result export(PatentNewBo p,Integer pageSize,Integer pageNo){
@@ -125,6 +131,30 @@ public class AdminPatentNewApiController extends CertifyApiController {
 	}
 	
 	/**
+	 * 导出专利列表
+	 */
+	@RequestMapping(value = "/exportMode", method = RequestMethod.GET)
+	public Result export(HttpServletResponse response, String sign){
+        Result res = new Result();
+        AttachmentType attachmentType = AttachmentType.getField(sign);
+        if (attachmentType == AttachmentType.NEW_PATENT_TEMPLATE) {
+            String fileName = "";
+            Attachment af = attachmentService.selectByReceivbles(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.RECEIVABLES_TEMPLATE.getDesc() + suffix;
+                downloadFile(response, fileName, path);
+            }
+        } else {
+            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
+        }
+        return res;
+    }
+	
+	/**
 	 * 	Excel批量导入专利
      * 
      * @param response

+ 7 - 11
src/main/java/com/goafanti/patent/service/impl/PatentNewServiceImpl.java

@@ -219,15 +219,6 @@ public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> imple
 						trb.setEmail(ExcelUtils.getCellValue(cell));
 						break;
 					case 8:
-						trb.setPatentAmount(new BigDecimal((ExcelUtils.getCellValue(cell).equals("")?"0":ExcelUtils.getCellValue(cell))));
-						break;
-					case 9:
-						trb.setDelayingAmount(new BigDecimal((ExcelUtils.getCellValue(cell).equals("")?"0":ExcelUtils.getCellValue(cell))));
-						break;
-					case 10:
-						trb.setRecoveryAmount(new BigDecimal((ExcelUtils.getCellValue(cell).equals("")?"0":ExcelUtils.getCellValue(cell))));
-						break;
-					case 11:
 						trb.setTid(Integer.parseInt(ExcelUtils.getCellValue(cell)));
 						break;
 					
@@ -243,12 +234,17 @@ public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> imple
 						}
 					}
 		        }
+		        for (PatentNew pt : list) {
+		        	if (pt.getPatentNo().equals(trb.getPatentNo())) {
+		        		throw new BusinessException(new Error("表格第"+(rowNum+1)+"行[专利编号]重复导入。"));
+		        	}
+		        }
 		        trb.setAid(TokenManager.getAdminId());
 		        trb.setInputId(trb.getAid());
 		        trb.setCreateTime(new Date());
 		        trb.setStatus(0);
 		        trb.setNewType(1);
-		        trb.setYears(0);
+		        trb.setYears(getyear(trb));
 		        list.add(trb);
 		    }
     		
@@ -334,7 +330,7 @@ public class PatentNewServiceImpl  extends BaseMybatisDao<PatentNewMapper> imple
 		for (PatentYearPayment p : patentYear) {
 			if (type==p.getType()&&year==p.getYear()) {
 				TOrderTask t=tOrderTaskMapper.selectByPrimaryKey(tid);
-				if (t.getCostReduction()==1) {
+				if (t!=null&&t.getCostReduction()!=null&& t.getCostReduction()==1) {
 					return p.getReductionAmount();
 				}else {
 					return p.getPatentAmount();