فهرست منبع

Merge remote-tracking branch 'origin/develop' into develop

linhuili 3 سال پیش
والد
کامیت
e2e458b21c

+ 1 - 1
docker/dockerfiles/adm-middleware/Dockerfile

@@ -26,7 +26,7 @@ COPY *.jar $WORKER_HOME/app.jar
 COPY entrypoint.sh $WORKER_HOME/
 COPY version.txt $WORKER_HOME/
 COPY config $WORKER_HOME/config
-COPY template $WORKER_HOME/template
+COPY temp $WORKER_HOME/temp
 
 #设置工作目录
 WORKDIR $WORKER_HOME

+ 41 - 47
src/main/java/com/persagy/proxy/adm/utils/AdmExcelUtil.java

@@ -27,22 +27,27 @@ import lombok.extern.slf4j.Slf4j;
 @Slf4j
 public class AdmExcelUtil {
 
+	public static final String TEMP_PAHT = "/temp/";
+	
+	public static final String TEMP_UPLOAD_PAHT = "/temp/upload/";
+	
 	/**
 	 * 文件写入至本地
 	 * 
 	 * @param workbook
 	 * @param projectId
+	 * @param path
 	 * @param orgFileName
 	 * @return 
 	 */
-	public static String writeFile2Local(XSSFWorkbook workbook, String projectId, String orgFileName) {
+	public static String writeFile2Local(XSSFWorkbook workbook, String projectId, String path, String orgFileName) {
 		FileOutputStream fileOutputStream = null;
 		String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
 		// 重组文件名
         String fileName = projectId + date + "." + orgFileName.substring(orgFileName.lastIndexOf(".") + 1);
         try {
     		// 调用中台存储完成之后,此文件存储至本地
-    		File templateFile = createTemplateFile(fileName);
+    		File templateFile = createTemplateFile(path, fileName);
     		fileOutputStream = new FileOutputStream(templateFile);
     		workbook.write(fileOutputStream);
 		} catch (Exception e) {
@@ -66,18 +71,9 @@ public class AdmExcelUtil {
 	 * @throws FileNotFoundException 
 	 */
 	public static File getTemplateOrDefaultFile(String templateName) throws FileNotFoundException {
-		File file = null;
-		try {
-			file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "template/" + templateName);
-		} catch (FileNotFoundException e) {
-			file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + "template/" + templateName);
-		}
-		if (file == null || !file.exists()) {
-			try {
-				file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "template/relation-template.xlsx");
-			} catch (FileNotFoundException e) {
-				file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + "/template/relation-template.xlsx");
-			}
+		File file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + TEMP_PAHT + templateName);
+		if (!file.exists()) {
+			file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + TEMP_PAHT + "relation-template.xlsx");
 		}
 		return file;
 	}
@@ -90,29 +86,22 @@ public class AdmExcelUtil {
 	 * @throws FileNotFoundException 
 	 */
 	public static File getTemplateFile(String templateName) throws FileNotFoundException {
-		File file = null;
-		try {
-			file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "template/" + templateName);
-		} catch (FileNotFoundException e) {}
-		if (file == null || !file.exists()) {
-			file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + "/template/" + templateName);
-		}
-		return file;
+		return ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + TEMP_PAHT + templateName);
 	}
 	
 	/**
 	 * 创建本地文件,这里不再在classpath下创建
 	 * 
-	 * @param uploadFile 文件名称,带后缀
+	 * @param path 以 / 结尾
+	 * @param fileName 文件名称,带后缀
 	 * @throws IOException 
 	 */
-	public static File createTemplateFile(String uploadFile) throws IOException {
-		String path = AdmCommonConstant.SERVER_ROOT_PATH + "/template";
+	public static File createTemplateFile(String path, String fileName) throws IOException {
 		File file = new File(path);
 		if (!file.exists()) {
 			file.mkdirs();
 		}
-		file = new File(path + "/" + uploadFile);
+		file = new File(path + fileName);
 		if (!file.exists()) {
 			file.createNewFile();
 		}
@@ -122,22 +111,17 @@ public class AdmExcelUtil {
 	/**
 	 * 获取导入结果
 	 * 
+	 * @param graphId
+	 * @param successCount
+	 * @param failCount
 	 * @return
 	 */
-	public static JSONObject getImportResult(String graphId, int successNum, int failureNum) {
+	public static JSONObject getImportResult(String graphId, int successCount, int failCount) {
 		JSONObject result = new JSONObject();
 		result.put("relationType", graphId);
-		result.put("successCount", successNum);
-		result.put("failCount", failureNum);
-		String state = null;
-        if (successNum > 0 && failureNum > 0) {
-        	state = "1";
-        } else if (successNum > 0 && failureNum == 0) {
-            state = "0";
-        } else {
-            state = "2";
-        }
-        result.put("state", state);
+		result.put("successCount", successCount);
+		result.put("failCount", failCount);
+        result.put("state", getState(successCount, failCount));
 		return result;
 	}
 	
@@ -145,6 +129,7 @@ public class AdmExcelUtil {
 	 * 获取导入结果
 	 * 
 	 * @param message
+	 * @param state
 	 * @param successCount
 	 * @param failCount
 	 * @return
@@ -163,21 +148,14 @@ public class AdmExcelUtil {
 	/**
 	 * 获取导入结果
 	 * 
+	 * @param message
 	 * @param successCount
 	 * @param failCount
 	 * @return
 	 */
 	public static AdmResponse getImportSuccessResult(String message, int successCount, int failCount) {
 		JSONObject content = new JSONObject();
-		String state = null;
-        if (successCount > 0 && failCount > 0) {
-        	state = "1";
-        } else if (successCount > 0 && failCount == 0) {
-            state = "0";
-        } else {
-            state = "2";
-        }
-		content.put("state", state);
+		content.put("state", getState(successCount, failCount));
 		content.put("successCount", successCount);
 		content.put("failCount", failCount);
 		AdmResponse success = AdmResponse.success(Lists.newArrayList(content));
@@ -185,4 +163,20 @@ public class AdmExcelUtil {
 		return success;
 	}
 	
+	/**
+	 * 获取文件导入状态
+	 * 
+	 * @param successCount
+	 * @param failCount
+	 * @return
+	 */
+	private static String getState(int successCount, int failCount) {
+		if (successCount > 0 && failCount > 0) {
+        	return "1";
+        } else if (successCount > 0 && failCount == 0) {
+        	return "0";
+        }
+        return "2";
+	}
+	
 }

+ 8 - 8
src/main/java/com/persagy/proxy/object/controller/AdmEquipmentController.java

@@ -259,11 +259,11 @@ public class AdmEquipmentController {
 	 * @param response
 	 */
 	@RequestMapping("/import")
-	public AdmResponse importFile(@RequestParam("file") MultipartFile file, @RequestParam String relType, @RequestParam(required = false) String zoneType, 
-			HttpServletRequest request, HttpServletResponse response) {
+	public AdmResponse importFile(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
 		if (file == null) {
 			return AdmResponse.failure("未选择文件");
 		}
+		String path = AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_UPLOAD_PAHT;
 		
 		int failurNum = 0;
 		int successCount = 0;
@@ -280,32 +280,32 @@ public class AdmEquipmentController {
 		    XSSFSheet sheet = workbook.getSheetAt(0);	// 第一个sheet
 		    XSSFRow row1 = sheet.getRow(1);
 		    if (row1 == null) {
-		    	AdmExcelUtil.writeFile2Local(workbook, projectId, file.getOriginalFilename());
+		    	AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
                 return AdmExcelUtil.getImportFailResult("数据不存在", "2", 0, ++failurNum);
 			}
 		    
 	    	/** 获取识别码 */
             XSSFCell markCell = row1.getCell(0);
             if (markCell == null) {
-            	AdmExcelUtil.writeFile2Local(workbook, projectId, file.getOriginalFilename());
+            	AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
                 return AdmExcelUtil.getImportFailResult("未填写识别码", "2", 0, ++failurNum);
 			}
         	primaryKey = markCell.getStringCellValue().trim(); 	// 识别码
 			boolean containsKey = AdmCommonConstant.codeColMap.containsKey(primaryKey);
 			if (!containsKey) {
-				AdmExcelUtil.writeFile2Local(workbook, projectId, file.getOriginalFilename());
+				AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
                 return AdmExcelUtil.getImportFailResult("未找到识别码", "2", 0, ++failurNum);
 			}
 			
             /** 获取类型 */
             XSSFCell cell = row1.getCell(1);
             if (cell == null) {
-            	AdmExcelUtil.writeFile2Local(workbook, projectId, file.getOriginalFilename());
+            	AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
                 return AdmExcelUtil.getImportFailResult("未填写设备类型", "2", 0, ++failurNum);
 			}
             classCodeCloumn = cell.getStringCellValue().trim();
         	if (!"ClassCode".equals(classCodeCloumn)) {
-        		AdmExcelUtil.writeFile2Local(workbook, projectId, file.getOriginalFilename());
+        		AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
                 return AdmExcelUtil.getImportFailResult("缺少设备类型(ClassCode)", "2", 0, ++failurNum);
 			}
 		    
@@ -465,7 +465,7 @@ public class AdmEquipmentController {
 		    this.wirteReport(workbook, sheet);
 		    
 		    // 返回正确结果
-		    String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, file.getOriginalFilename());
+		    String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
 		    return AdmExcelUtil.getImportSuccessResult(fileName, successCount, failurNum);
 		} catch (Exception e) {
 			log.error("台账信息导入失败", e);

+ 6 - 16
src/main/java/com/persagy/proxy/report/controller/RelationReportController.java

@@ -1,7 +1,6 @@
 package com.persagy.proxy.report.controller;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.URLEncoder;
@@ -340,18 +339,9 @@ public class RelationReportController {
 			response.setCharacterEncoding(encode);
 			response.setHeader("Content-disposition", "attachment;filename=" + key);
 			
-			File file = null;
-			try {
-				file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "template/upload/" + key);
-			} catch (FileNotFoundException e) {
-				file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + "template/upload/" + key);
-			}
-			if (file == null || !file.exists()) {
-				try {
-					file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "/template/relation-template.xlsx");
-				} catch (FileNotFoundException e) {
-					file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + "/template/relation-template.xlsx");
-				}
+			File file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_UPLOAD_PAHT + key);
+			if (!file.exists()) {
+				file = ResourceUtils.getFile(AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_PAHT + "relation-template.xlsx");
 			}
 			
 			excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(file).build();
@@ -587,8 +577,8 @@ public class RelationReportController {
 		    
         	try {
         		// 调用中台存储完成之后,此文件存储至本地
-        		String uploadFile = projectId + AdmCommonConstant.LINE_THROUGH + relType + AdmCommonConstant.EXCEL_SUFFIX_XLSX;
-        		File templateFile = AdmExcelUtil.createTemplateFile(uploadFile);
+        		String fileName = projectId + AdmCommonConstant.LINE_THROUGH + relType + AdmCommonConstant.EXCEL_SUFFIX_XLSX;
+        		File templateFile = AdmExcelUtil.createTemplateFile(AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_PAHT, fileName);
         		fileOutputStream = new FileOutputStream(templateFile);
         		workbook.write(fileOutputStream);
 			} catch (Exception e) {
@@ -793,7 +783,7 @@ public class RelationReportController {
 			}
 
 		    // 文件存储及返回
-		    String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, file.getOriginalFilename());
+		    String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_UPLOAD_PAHT, file.getOriginalFilename());
 		    return AdmExcelUtil.getImportSuccessResult(fileName, successCount, failCount);
 		} catch (Exception e) {
 			log.error("文件导入失败", e);

docker/template/equip_template.xlsx → temp/equip_template.xlsx


docker/template/relation-template.xlsx → temp/relation-template.xlsx


docker/template/设备.xlsx → temp/设备.xlsx