Browse Source

Merge remote-tracking branch 'origin/master'

yaoll 4 years ago
parent
commit
af84c88f11

+ 0 - 2
dmp-alarm/src/main/java/com/persagy/dmp/alarm/model/AlarmRecordModels.java

@@ -1,10 +1,8 @@
 package com.persagy.dmp.alarm.model;
 
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import lombok.Getter;
 import lombok.Setter;
 
-import java.util.Date;
 import java.util.List;
 
 /**

+ 31 - 3
dmp-alarm/src/main/java/com/persagy/dmp/alarm/service/AlarmConfigService.java

@@ -474,18 +474,39 @@ public class AlarmConfigService extends AlarmBaseService {
         alarmConfigRepository.save(alarmConfig);
         response.add("id", alarmConfig.getId());
         // 报警定义发生变化,向mq推送消息
+        DmpMessage msg = getUpdateConfigsDmpMessage(Lists.newArrayList(alarmConfig));
+        if (msg != null) {
+            response.add(msg);
+        }
+        return response;
+    }
+
+    /**
+     * 获取更新报警定义消息
+     *
+     * @param alarmConfigList 更新的报警定义id
+     * @return 更新消息
+     * @author lixing
+     * @version V1.0 2021/3/27 3:30 下午
+     */
+    private DmpMessage getUpdateConfigsDmpMessage(List<AlarmConfig> alarmConfigList) {
+        if (CollectionUtils.isEmpty(alarmConfigList)) {
+            return null;
+        }
         DmpMessage msg = new DmpMessage();
         msg.setMid(UUID.randomUUID().toString());
         msg.setType(EnumAlarmMessageType.ALARM_CONFIGS_CHANGE.getValue());
         msg.setGroupCode(DmpParameterStorage.getGroupCode());
         msg.setProjectId(DmpParameterStorage.getProjectId());
-        msg.add("updatedConfigUniques", Lists.newArrayList(alarmConfig.getAlarmConfigUnique()));
+        List<AlarmConfig.AlarmConfigUnique> alarmConfigUniqueList = alarmConfigList.stream().
+                map(AlarmConfig::getAlarmConfigUnique).collect(Collectors.toList());
+        msg.add("updatedConfigUniques", alarmConfigUniqueList);
         msg.setAppId(DmpParameterStorage.getAppId());
         msg.setSendTime(DateUtils.format(new Date()));
-        response.add(msg);
-        return response;
+        return msg;
     }
 
+
     /**
      * @description: 根据更新条件更新实体
      * @param: param
@@ -634,6 +655,8 @@ public class AlarmConfigService extends AlarmBaseService {
             configs.add(alarmConfig);
         }
         alarmConfigRepository.saveAll(configs);
+        DmpMessage updateConfigsDmpMessage = getUpdateConfigsDmpMessage(configs);
+        messageProcesser.convertAndSend(updateConfigsDmpMessage);
         Date date1 = new Date();
         System.out.println("执行时间:" + (date1.getTime() - date.getTime()));
         return response;
@@ -660,6 +683,9 @@ public class AlarmConfigService extends AlarmBaseService {
             return response;
         }
         alarmConfigRepository.save(entity);
+        // 发送报警定义创建消息
+        DmpMessage msg = generateMessage(Lists.newArrayList(entity), null);
+        messageProcesser.convertAndSend(msg);
         response.add("id", entity.getId());
         return response;
     }
@@ -719,6 +745,8 @@ public class AlarmConfigService extends AlarmBaseService {
             }
             alarmConfigRepository.save(entity);
             ids.add(entity.getId());
+            DmpMessage msg = generateMessage(Lists.newArrayList(entity), null);
+            messageProcesser.convertAndSend(msg);
         }
         Date date1 = new Date();
         System.out.println("执行时间:" + (date1.getTime() - date.getTime()));

+ 4 - 2
dmp-alarm/src/main/resources/bootstrap.yml

@@ -5,8 +5,10 @@ spring:
     active: log-dev
   cloud:
     config:
-      profile: dev2
-      uri: http://192.168.64.18:9932
+      profile: dev
+      uri: http://192.168.100.107:9932
+      #      profile: dev2
+#      uri: http://192.168.64.18:9932
 persagy:
   log:
     path: ../logs/dmp-alarm/

+ 272 - 207
dmp-common/src/main/java/com/persagy/dmp/common/excel/ExcelUtils.java

@@ -2,6 +2,7 @@ package com.persagy.dmp.common.excel;
 
 
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddressList;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 import java.io.InputStream;
@@ -9,211 +10,275 @@ import java.util.*;
 
 public class ExcelUtils {
 
-	public static Object parseCell(Cell cell, String type) {
-		CellType cellType = cell.getCellTypeEnum();
-		if ("string".equalsIgnoreCase(type)) {
-			if (cellType == CellType.STRING) {
-				return cell.getStringCellValue();
-			} else if (cellType == CellType.NUMERIC) {
-				return cell.getNumericCellValue();
-			}
-		} else if ("integer".equalsIgnoreCase(type)) {
-			if (cellType == CellType.STRING) {
-				String stringCellValue = cell.getStringCellValue();
-				return stringCellValue == null ? null : Double.valueOf(stringCellValue).intValue();
-			} else if (cellType == CellType.NUMERIC) {
-				return Double.valueOf(cell.getNumericCellValue()).intValue();
-			}
-		} else if ("double".equalsIgnoreCase(type)) {
-			if (cellType == CellType.STRING) {
-				String stringCellValue = cell.getStringCellValue();
-				return stringCellValue == null ? null : Double.valueOf(stringCellValue);
-			} else if (cellType == CellType.NUMERIC) {
-				return cell.getNumericCellValue();
-			}
-		} else if ("date".equalsIgnoreCase(type)) {
-			if (cellType == CellType.NUMERIC) {
-				Date dateCellValue = cell.getDateCellValue();
-				return dateCellValue == null ? null : dateCellValue;
-			} else if (cellType == CellType.NUMERIC) {
-				return cell.getNumericCellValue();
-			}
-		}
-		return null;
-	}
-
-	public static List<List<Map<String, Object>>> read(InputStream inputStream, List<SheetReadInfo> infos) {
-		List<List<Map<String, Object>>> answer = new ArrayList<>(infos.size());
-
-		try {
-			Workbook workbook = new XSSFWorkbook(inputStream);
-
-			for (int infoIndex = 0; infoIndex < infos.size(); infoIndex++) {
-				List<Map<String, Object>> result = new ArrayList<>();
-				answer.add(result);
-
-				Sheet sheet = workbook.getSheetAt(infoIndex);
-				SheetReadInfo info = infos.get(infoIndex);
-				Integer startRow = info.getStartRow();
-				List<Integer> columnIndexs = info.getColumnIndexs();
-				List<String> keys = info.getColumnKeys();
-				List<String> types = info.getColumnTypes();
-
-				int lastRowNum = sheet.getLastRowNum();
-				for (int rowIndex = startRow; rowIndex < lastRowNum + 1; rowIndex++) {
-					Row row = sheet.getRow(rowIndex);
-					if (null == row) {
-						System.err.println("==========rowIndex:" + rowIndex);
-						continue;
-					}
-					Map<String, Object> data = new HashMap<>();
-					for (int columnDefIndex = 0; columnDefIndex < columnIndexs.size(); columnDefIndex++) {
-						Integer columnIndex = columnIndexs.get(columnDefIndex);
-						String key = keys.get(columnDefIndex);
-						String type = types.get(columnDefIndex);
-						Cell cell = row.getCell(columnIndex);
-						if (null == cell) {
-							System.err.println("==========columnIndex:" + columnIndex);
-							continue;
-						}
-						Object value = parseCell(cell, type);
-						if (null != value) {
-							data.put(key, value);
-						}
-					}
-					if (0 < data.size()) {
-						data.put(info.getSeqKey(), rowIndex);
-						result.add(data);
-					}
-				}
-			}
-			workbook.close();
-		} catch (Exception e) {
-			e.printStackTrace();
-		} finally {
-		}
-		return answer;
-
-	}
-
-	public static List<Map<String, Object>> read(InputStream inputStream, SheetReadInfo info) {
-		List<List<Map<String, Object>>> read = read(inputStream, Arrays.asList(info));
-		return read.get(0);
-	}
-
-	public static Workbook createExcel(List<SheetWriteInfo> sheets) {
-		Workbook wb = new XSSFWorkbook();
-		CreationHelper createHelper = wb.getCreationHelper();  //创建帮助工具
-		for (SheetWriteInfo sheetInfo : sheets) {
-			Sheet sheet = wb.createSheet(sheetInfo.getSheetName());
-			List<String> headList = sheetInfo.getHeadList();
-			List<HorizontalAlignment> aligns = sheetInfo.getHorizontalAlignments();
-			List<String> props = sheetInfo.getProps();
-			List<String> types = sheetInfo.getDataTypes();
-			List<Integer> widths = sheetInfo.getWidths();
-			List data = sheetInfo.getData();
-			ExcelDataHandler handler = sheetInfo.getDataHandler();
-			setColumnWidth(sheet, widths);
-			CellStyle headerStyle = getHeaderStyle(wb);
-			Row headRow = sheet.createRow(0); //第一行为头
-			int columnSize = headList.size();
-			for (int i = 0; i < columnSize; i++) {  //遍历表头数据
-				Cell cell = headRow.createCell(i);  //创建单元格
-				cell.setCellValue(createHelper.createRichTextString(headList.get(i)));  //设置值
-				cell.setCellStyle(headerStyle);  //设置样式
-			}
-
-			List<CellStyle> dataStyles = new ArrayList<>(columnSize);
-			for (int i = 0; i < aligns.size(); i++) {
-				dataStyles.add(getDataStyle(wb, aligns.get(i)));
-			}
-
-			int rowIndex = 1;
-			if (data != null) {
-				for (Object datum : data) {
-					Row row = sheet.createRow(rowIndex++); //第一行为头
-					for (int j = 0; j < columnSize; j++) {  //编译每一行
-						Cell cell = row.createCell(j);
-						cell.setCellStyle(dataStyles.get(j));
-						String prop = props.get(j);
-						String type = types.get(j);
-						Object o = handler.get(datum, prop);
-						if (o != null) {
-							if (type.equalsIgnoreCase("string")) {
-								if (o == null) {
-									cell.setCellValue("");
-								} else {
-									String str = o.toString();
-									cell.setCellValue(str.length() > 3000 ? str.substring(0, 3000) : str);
-								}
-							} else if (type.equalsIgnoreCase("byte")) {
-								cell.setCellValue((byte) o);
-							} else if (type.equalsIgnoreCase("short")) {
-								cell.setCellValue((short) o);
-							} else if (type.equalsIgnoreCase("int")) {
-								cell.setCellValue((int) o);
-							} else if (type.equalsIgnoreCase("long")) {
-								cell.setCellValue((long) o);
-							} else if (type.equalsIgnoreCase("double")) {
-								cell.setCellValue((Double) o);
-							} else if (type.equalsIgnoreCase("date")) {
-								CellStyle cellStyle = dataStyles.get(j);
-								DataFormat df = wb.createDataFormat();
-								cellStyle.setDataFormat(df.getFormat("yyyy/m/d"));
-								cell.setCellValue((Date) o);
-								cell.setCellStyle(cellStyle);
-							} else {
-								cell.setCellValue(o.toString());
-							}
-						}
-					}
-				}
-			}
-		}
-		return wb;
-	}
-
-	private static void setColumnWidth(Sheet sheet, List<Integer> widths) {
-		for (int i = 0; i < widths.size(); i++) {
-			sheet.setColumnWidth(i, widths.get(i) * 256);
-		}
-	}
-
-	private static CellStyle getHeaderStyle(Workbook wb) {
-		//设置字体
-		Font headFont = wb.createFont();
-		headFont.setFontHeightInPoints((short) 14);
-		headFont.setFontName("Courier New");
-		headFont.setItalic(false);
-		headFont.setStrikeout(false);
-		//设置头部单元格样式
-		CellStyle headStyle = wb.createCellStyle();
-		headStyle.setBorderBottom(BorderStyle.THIN);  //设置单元格线条
-		headStyle.setBorderLeft(BorderStyle.THIN);
-		headStyle.setBorderRight(BorderStyle.THIN);
-		headStyle.setBorderTop(BorderStyle.THIN);
-		headStyle.setAlignment(HorizontalAlignment.CENTER);    //设置水平对齐方式
-		headStyle.setVerticalAlignment(VerticalAlignment.CENTER);  //设置垂直对齐方式
-		headStyle.setFont(headFont);  //设置字体
-		return headStyle;
-	}
-
-	private static CellStyle getDataStyle(Workbook wb, HorizontalAlignment horizontalAlignment) {
-		//设置字体
-		Font headFont = wb.createFont();
-		headFont.setFontHeightInPoints((short) 14);
-		headFont.setFontName("Courier New");
-		headFont.setItalic(false);
-		headFont.setStrikeout(false);
-		//设置头部单元格样式
-		CellStyle dataStyle = wb.createCellStyle();
-		dataStyle.setBorderBottom(BorderStyle.THIN);  //设置单元格线条
-		dataStyle.setBorderLeft(BorderStyle.THIN);
-		dataStyle.setBorderRight(BorderStyle.THIN);
-		dataStyle.setBorderTop(BorderStyle.THIN);
-		dataStyle.setAlignment(horizontalAlignment);    //设置水平对齐方式
-		dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);  //设置垂直对齐方式
-		dataStyle.setFont(headFont);  //设置字体
-		return dataStyle;
-	}
+    public static Object parseCell(Cell cell, String type) {
+        CellType cellType = cell.getCellTypeEnum();
+        if ("string".equalsIgnoreCase(type)) {
+            if (cellType == CellType.STRING) {
+                return cell.getStringCellValue();
+            } else if (cellType == CellType.NUMERIC) {
+                return cell.getNumericCellValue();
+            }
+        } else if ("integer".equalsIgnoreCase(type)) {
+            if (cellType == CellType.STRING) {
+                String stringCellValue = cell.getStringCellValue();
+                return stringCellValue == null ? null : Double.valueOf(stringCellValue).intValue();
+            } else if (cellType == CellType.NUMERIC) {
+                return Double.valueOf(cell.getNumericCellValue()).intValue();
+            }
+        } else if ("double".equalsIgnoreCase(type)) {
+            if (cellType == CellType.STRING) {
+                String stringCellValue = cell.getStringCellValue();
+                return stringCellValue == null ? null : Double.valueOf(stringCellValue);
+            } else if (cellType == CellType.NUMERIC) {
+                return cell.getNumericCellValue();
+            }
+        } else if ("date".equalsIgnoreCase(type)) {
+            if (cellType == CellType.NUMERIC) {
+                Date dateCellValue = cell.getDateCellValue();
+                return dateCellValue == null ? null : dateCellValue;
+            } else if (cellType == CellType.NUMERIC) {
+                return cell.getNumericCellValue();
+            }
+        }
+        return null;
+    }
+
+    public static List<List<Map<String, Object>>> read(InputStream inputStream, List<SheetReadInfo> infos, List<String> sheetNameList) {
+        List<List<Map<String, Object>>> answer = new ArrayList<>(infos.size());
+
+        try {
+            Workbook workbook = new XSSFWorkbook(inputStream);
+
+            for (int infoIndex = 0; infoIndex < infos.size(); infoIndex++) {
+                List<Map<String, Object>> result = new ArrayList<>();
+                answer.add(result);
+
+                Sheet sheet = workbook.getSheet(sheetNameList.get(infoIndex));
+                SheetReadInfo info = infos.get(infoIndex);
+                Integer startRow = info.getStartRow();
+                List<Integer> columnIndexs = info.getColumnIndexs();
+                List<String> keys = info.getColumnKeys();
+                List<String> types = info.getColumnTypes();
+
+                int lastRowNum = sheet.getLastRowNum();
+                for (int rowIndex = startRow; rowIndex < lastRowNum + 1; rowIndex++) {
+                    Row row = sheet.getRow(rowIndex);
+                    if (null == row) {
+                        System.err.println("==========rowIndex:" + rowIndex);
+                        continue;
+                    }
+                    Map<String, Object> data = new HashMap<>();
+                    for (int columnDefIndex = 0; columnDefIndex < columnIndexs.size(); columnDefIndex++) {
+                        Integer columnIndex = columnIndexs.get(columnDefIndex);
+                        String key = keys.get(columnDefIndex);
+                        String type = types.get(columnDefIndex);
+                        Cell cell = row.getCell(columnIndex);
+                        if (null == cell) {
+                            System.err.println("==========columnIndex:" + columnIndex);
+                            continue;
+                        }
+                        Object value = parseCell(cell, type);
+                        if (null != value) {
+                            data.put(key, value);
+                        }
+                    }
+                    if (0 < data.size()) {
+                        data.put(info.getSeqKey(), rowIndex);
+                        result.add(data);
+                    }
+                }
+            }
+            workbook.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+        }
+        return answer;
+
+    }
+
+    public static List<List<Map<String, Object>>> read(InputStream inputStream, List<SheetReadInfo> infos) {
+        List<List<Map<String, Object>>> answer = new ArrayList<>(infos.size());
+
+        try {
+            Workbook workbook = new XSSFWorkbook(inputStream);
+
+            for (int infoIndex = 0; infoIndex < infos.size(); infoIndex++) {
+                List<Map<String, Object>> result = new ArrayList<>();
+                answer.add(result);
+
+                Sheet sheet = workbook.getSheetAt(infoIndex);
+                SheetReadInfo info = infos.get(infoIndex);
+                Integer startRow = info.getStartRow();
+                List<Integer> columnIndexs = info.getColumnIndexs();
+                List<String> keys = info.getColumnKeys();
+                List<String> types = info.getColumnTypes();
+
+                int lastRowNum = sheet.getLastRowNum();
+                for (int rowIndex = startRow; rowIndex < lastRowNum + 1; rowIndex++) {
+                    Row row = sheet.getRow(rowIndex);
+                    if (null == row) {
+                        System.err.println("==========rowIndex:" + rowIndex);
+                        continue;
+                    }
+                    Map<String, Object> data = new HashMap<>();
+                    for (int columnDefIndex = 0; columnDefIndex < columnIndexs.size(); columnDefIndex++) {
+                        Integer columnIndex = columnIndexs.get(columnDefIndex);
+                        String key = keys.get(columnDefIndex);
+                        String type = types.get(columnDefIndex);
+                        Cell cell = row.getCell(columnIndex);
+                        if (null == cell) {
+                            System.err.println("==========columnIndex:" + columnIndex);
+                            continue;
+                        }
+                        Object value = parseCell(cell, type);
+                        if (null != value) {
+                            data.put(key, value);
+                        }
+                    }
+                    if (0 < data.size()) {
+                        data.put(info.getSeqKey(), rowIndex);
+                        result.add(data);
+                    }
+                }
+            }
+            workbook.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+        }
+        return answer;
+
+    }
+
+    public static List<Map<String, Object>> read(InputStream inputStream, SheetReadInfo info) {
+        List<List<Map<String, Object>>> read = read(inputStream, Arrays.asList(info));
+        return read.get(0);
+    }
+
+    public static Workbook createExcel(List<SheetWriteInfo> sheets) {
+        Workbook wb = new XSSFWorkbook();
+        CreationHelper createHelper = wb.getCreationHelper();  //创建帮助工具
+        for (SheetWriteInfo sheetInfo : sheets) {
+            Sheet sheet = wb.createSheet(sheetInfo.getSheetName());
+            List<String> headList = sheetInfo.getHeadList();
+            List<HorizontalAlignment> aligns = sheetInfo.getHorizontalAlignments();
+            List<String> props = sheetInfo.getProps();
+            List<String> types = sheetInfo.getDataTypes();
+            List<Integer> widths = sheetInfo.getWidths();
+            List data = sheetInfo.getData();
+            ExcelDataHandler handler = sheetInfo.getDataHandler();
+            setColumnWidth(sheet, widths);
+            CellStyle headerStyle = getHeaderStyle(wb);
+            Row headRow = sheet.createRow(0); //第一行为头
+            int columnSize = headList.size();
+            for (int i = 0; i < columnSize; i++) {  //遍历表头数据
+                Cell cell = headRow.createCell(i);  //创建单元格
+                cell.setCellValue(createHelper.createRichTextString(headList.get(i)));  //设置值
+                cell.setCellStyle(headerStyle);  //设置样式
+            }
+
+            List<CellStyle> dataStyles = new ArrayList<>(columnSize);
+            for (int i = 0; i < aligns.size(); i++) {
+                dataStyles.add(getDataStyle(wb, aligns.get(i)));
+            }
+
+            int rowIndex = 1;
+            if (data != null) {
+                for (Object datum : data) {
+                    Row row = sheet.createRow(rowIndex++); //第一行为头
+                    for (int j = 0; j < columnSize; j++) {  //编译每一行
+                        Cell cell = row.createCell(j);
+                        cell.setCellStyle(dataStyles.get(j));
+                        String prop = props.get(j);
+                        String type = types.get(j);
+                        Object o = handler.get(datum, prop);
+                        if (o != null) {
+                            if (type.equalsIgnoreCase("string")) {
+                                if (o == null) {
+                                    cell.setCellValue("");
+                                } else {
+                                    String str = o.toString();
+                                    cell.setCellValue(str.length() > 3000 ? str.substring(0, 3000) : str);
+                                }
+                            } else if (type.equalsIgnoreCase("byte")) {
+                                cell.setCellValue((byte) o);
+                            } else if (type.equalsIgnoreCase("short")) {
+                                cell.setCellValue((short) o);
+                            } else if (type.equalsIgnoreCase("int")) {
+                                cell.setCellValue((int) o);
+                            } else if (type.equalsIgnoreCase("long")) {
+                                cell.setCellValue((long) o);
+                            } else if (type.equalsIgnoreCase("double")) {
+                                cell.setCellValue((Double) o);
+                            } else if (type.equalsIgnoreCase("date")) {
+                                CellStyle cellStyle = dataStyles.get(j);
+                                DataFormat df = wb.createDataFormat();
+                                cellStyle.setDataFormat(df.getFormat("yyyy/m/d"));
+                                cell.setCellValue((Date) o);
+                                cell.setCellStyle(cellStyle);
+                            } else if (type.equalsIgnoreCase("array")) {
+                                String[] array = (String[]) o;
+                                DataValidationHelper helper = sheet.getDataValidationHelper();
+                                DataValidationConstraint constraint = helper.createExplicitListConstraint(array);
+                                constraint.setExplicitListValues(array);
+                                CellRangeAddressList regions = new CellRangeAddressList(1, cell.getRowIndex(), cell.getColumnIndex(), cell.getColumnIndex());
+                                DataValidation dataValidation = helper.createValidation(constraint, regions);
+                                dataValidation.createErrorBox("Error", "Error");
+                                dataValidation.createPromptBox("", null);
+                                sheet.addValidationData(dataValidation);
+                            } else {
+                                cell.setCellValue(o.toString());
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return wb;
+    }
+
+    private static void setColumnWidth(Sheet sheet, List<Integer> widths) {
+        for (int i = 0; i < widths.size(); i++) {
+            sheet.setColumnWidth(i, widths.get(i) * 256);
+        }
+    }
+
+    private static CellStyle getHeaderStyle(Workbook wb) {
+        //设置字体
+        Font headFont = wb.createFont();
+        headFont.setFontHeightInPoints((short) 14);
+        headFont.setFontName("Courier New");
+        headFont.setItalic(false);
+        headFont.setStrikeout(false);
+        //设置头部单元格样式
+        CellStyle headStyle = wb.createCellStyle();
+        headStyle.setBorderBottom(BorderStyle.THIN);  //设置单元格线条
+        headStyle.setBorderLeft(BorderStyle.THIN);
+        headStyle.setBorderRight(BorderStyle.THIN);
+        headStyle.setBorderTop(BorderStyle.THIN);
+        headStyle.setAlignment(HorizontalAlignment.CENTER);    //设置水平对齐方式
+        headStyle.setVerticalAlignment(VerticalAlignment.CENTER);  //设置垂直对齐方式
+        headStyle.setFont(headFont);  //设置字体
+        return headStyle;
+    }
+
+    private static CellStyle getDataStyle(Workbook wb, HorizontalAlignment horizontalAlignment) {
+        //设置字体
+        Font headFont = wb.createFont();
+        headFont.setFontHeightInPoints((short) 14);
+        headFont.setFontName("Courier New");
+        headFont.setItalic(false);
+        headFont.setStrikeout(false);
+        //设置头部单元格样式
+        CellStyle dataStyle = wb.createCellStyle();
+        dataStyle.setBorderBottom(BorderStyle.THIN);  //设置单元格线条
+        dataStyle.setBorderLeft(BorderStyle.THIN);
+        dataStyle.setBorderRight(BorderStyle.THIN);
+        dataStyle.setBorderTop(BorderStyle.THIN);
+        dataStyle.setAlignment(horizontalAlignment);    //设置水平对齐方式
+        dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);  //设置垂直对齐方式
+        dataStyle.setFont(headFont);  //设置字体
+        return dataStyle;
+    }
 }

+ 0 - 15
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/controller/ClassDefChangeRecordController.java

@@ -43,19 +43,4 @@ public class ClassDefChangeRecordController {
     public MapResponse addVersion(@RequestParam String version, @RequestBody List<Integer> idList) {
         return service.addVersion(version, idList);
     }
-
-    @PostMapping("/uploadChangeRecord")
-    public MapResponse uploadChangeRecord(@RequestParam("file") MultipartFile file) {
-        List<ClassDefChangeRecord> classDefChangeRecordList = null;
-        try {
-            classDefChangeRecordList = service.CompareDataExcelRead(file);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        for (ClassDefChangeRecord classDefChangeRecord : classDefChangeRecordList) {
-            service.create(classDefChangeRecord);
-        }
-        return new MapResponse();
-    }
-
 }

+ 56 - 0
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/controller/DownloadController.java

@@ -0,0 +1,56 @@
+package com.persagy.dmp.rwd.edit.controller;
+
+import com.persagy.dmp.rwd.edit.model.DownloadModel;
+import com.persagy.dmp.rwd.edit.service.DownloadService;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+
+@RestController
+@RequestMapping("/rwdedit/common")
+public class DownloadController {
+
+    @Autowired
+    private DownloadService downloadService;
+
+    @GetMapping("/download")
+    private void download(@RequestParam String type, HttpServletResponse response) {
+        DownloadModel result = downloadService.download(type);
+        if ("workbook".equalsIgnoreCase(result.getType())) {
+            String fileName = result.getName();
+            downloadWorkbook(response, fileName, result.getWorkbook());
+        }
+    }
+
+    private void downloadWorkbook(HttpServletResponse resp, String fileName, Workbook workbook) {
+        OutputStream out = null;
+        try {
+            resp.reset();// 清空输出流
+            String resultFileName = URLEncoder.encode(fileName, "UTF-8");
+            resp.setCharacterEncoding("UTF-8");
+            resp.setHeader("Content-disposition", "attachment; filename=" + resultFileName);// 设定输出文件头
+            resp.setContentType("application/msexcel");// 定义输出类型
+            out = resp.getOutputStream();
+            workbook.write(out);
+            out.flush();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}

+ 0 - 16
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/controller/FuncidDefChangeRecordController.java

@@ -7,9 +7,7 @@ import com.persagy.dmp.rwd.edit.entity.FuncidDefChangeRecord;
 import com.persagy.dmp.rwd.edit.service.FuncidDefChangeRecordService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
 
-import java.io.IOException;
 import java.util.List;
 
 @RestController
@@ -43,18 +41,4 @@ public class FuncidDefChangeRecordController {
     public MapResponse addVersion(@RequestParam String version, @RequestBody List<Integer> idList) {
         return service.addVersion(version, idList);
     }
-
-    @PostMapping("/uploadChangeRecord")
-    public MapResponse uploadChangeRecord(@RequestParam("file") MultipartFile file) {
-        List<FuncidDefChangeRecord> funcidDefChangeRecordList = null;
-        try {
-            funcidDefChangeRecordList = service.CompareDataExcelRead(file);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        for (FuncidDefChangeRecord funcidDefChangeRecord : funcidDefChangeRecordList) {
-            service.create(funcidDefChangeRecord);
-        }
-        return new MapResponse();
-    }
 }

+ 31 - 0
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/controller/UploadController.java

@@ -0,0 +1,31 @@
+package com.persagy.dmp.rwd.edit.controller;
+
+import com.persagy.common.web.MapResponse;
+import com.persagy.dmp.rwd.edit.service.UploadService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+@Slf4j
+@RestController
+@RequestMapping("/rwdedit/common")
+public class UploadController {
+
+    @Autowired
+    private UploadService uploadService;
+
+    @PostMapping("/upload")
+    public MapResponse upload(@RequestParam String type, @RequestParam("file") MultipartFile file) {
+        MapResponse response = new MapResponse();
+        try {
+            return uploadService.upload(type, file);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return response;
+    }
+}

+ 13 - 0
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/model/DownloadModel.java

@@ -0,0 +1,13 @@
+package com.persagy.dmp.rwd.edit.model;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.poi.ss.usermodel.Workbook;
+
+@Getter
+@Setter
+public class DownloadModel {
+    private String type;
+    private String name;
+    private Workbook workbook;
+}

+ 0 - 70
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/service/ClassDefChangeRecordService.java

@@ -6,8 +6,6 @@ import com.persagy.common.criteria.JacksonCriteria;
 import com.persagy.common.web.ListResponse;
 import com.persagy.common.web.MapResponse;
 import com.persagy.common.web.PagedResponse;
-import com.persagy.dmp.common.excel.ExcelUtils;
-import com.persagy.dmp.common.excel.SheetReadInfo;
 import com.persagy.dmp.rwd.edit.config.web.UserUtils;
 import com.persagy.dmp.rwd.edit.entity.ClassDef;
 import com.persagy.dmp.rwd.edit.entity.ClassDefChangeRecord;
@@ -16,18 +14,13 @@ import com.persagy.dmp.rwd.edit.enumeration.EnumOperationType;
 import com.persagy.dmp.rwd.edit.enumeration.EnumVersionState;
 import com.persagy.dmp.rwd.edit.repository.ClassDefChangeRecordRepository;
 import com.persagy.dmp.rwd.edit.repository.ClassDefRepository;
-import com.persagy.dmp.rwd.enums.ObjType;
 import com.persagy.dmp.rwd.model.ClassDefModel;
 import com.querydsl.core.types.dsl.BooleanExpression;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
 
 import javax.transaction.Transactional;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.*;
 
 @Slf4j
@@ -358,68 +351,5 @@ public class ClassDefChangeRecordService {
         List<ClassDefModel> data = query.getData();
         return data;
     }
-
-    public List<ClassDefChangeRecord> CompareDataExcelRead(MultipartFile file) throws IOException {
-        SheetReadInfo info = new SheetReadInfo();
-        info.setStartRow(1);
-        info.add(0, "code", "string");
-        info.add(1, "objType", "string");
-        info.add(2, "name", "string");
-        info.add(3, "aliasCode", "string");
-        info.add(4, "aliasName", "string");
-        info.add(5, "majorCode", "string");
-        info.add(6, "systemCode", "string");
-        info.add(7, "equipmentCode", "string");
-        info.add(8, "parentCode", "string");
-        info.add(9, "operationType", "string");
-
-        InputStream inputStream = file.getInputStream();
-        List<Map<String, Object>> result = ExcelUtils.read(inputStream, info);
-
-        List<ClassDefChangeRecord> classDefChangeRecordList = new ArrayList<>();
-        for (Map<String, Object> map : result) {
-            String code = MapUtils.getString(map, "code");
-            String objType = MapUtils.getString(map, "objType");
-            String name = MapUtils.getString(map, "name");
-            String aliasCode = MapUtils.getString(map, "aliasCode");
-            String aliasName = MapUtils.getString(map, "aliasName");
-            String majorCode = MapUtils.getString(map, "majorCode");
-            String systemCode = MapUtils.getString(map, "systemCode");
-            String equipmentCode = MapUtils.getString(map, "equipmentCode");
-            String parentCode = MapUtils.getString(map, "parentCode");
-            String operationType = MapUtils.getString(map, "operationType");
-            if (code == null) {
-                return null;
-            }
-            if (objType == null) {
-                return null;
-            }
-            if (operationType == null) {
-                return null;
-            }
-
-            ClassDefChangeRecord classDefChangeRecord = new ClassDefChangeRecord();
-            classDefChangeRecord.setCode(code);
-            classDefChangeRecord.setName(name);
-            classDefChangeRecord.setObjType(ObjType.valueOf(objType));
-            classDefChangeRecord.setAliasCode(aliasCode);
-            classDefChangeRecord.setAliasName(aliasName);
-            classDefChangeRecord.setMajorCode(majorCode);
-            classDefChangeRecord.setSystemCode(systemCode);
-            classDefChangeRecord.setEquipmentCode(equipmentCode);
-            classDefChangeRecord.setParentCode(parentCode);
-            classDefChangeRecord.setOperationType(EnumOperationType.valueOf(operationType));
-
-            classDefChangeRecord.setType("common");
-            classDefChangeRecord.setOperationUser(UserUtils.currentUserId() + "");
-            classDefChangeRecord.setOperationTime(new Date());
-            classDefChangeRecord.setValid(true);
-            classDefChangeRecord.setState(EnumVersionState.INIT);
-            classDefChangeRecord.setGroupCode("0");
-            classDefChangeRecord.setProjectId("0");
-            classDefChangeRecordList.add(classDefChangeRecord);
-        }
-        return classDefChangeRecordList;
-    }
 }
 

+ 128 - 0
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/service/DownloadService.java

@@ -0,0 +1,128 @@
+package com.persagy.dmp.rwd.edit.service;
+
+import com.persagy.dmp.common.excel.ExcelUtils;
+import com.persagy.dmp.common.excel.SheetWriteInfo;
+import com.persagy.dmp.rwd.edit.entity.ClassDefChangeRecord;
+import com.persagy.dmp.rwd.edit.entity.FuncidDefChangeRecord;
+import com.persagy.dmp.rwd.edit.model.DownloadModel;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@Slf4j
+@Service
+public class DownloadService {
+
+    public DownloadModel download(String type) {
+        if ("changeDataTemplate".equals(type)) {
+            return downloadChangeDataTemplate();
+        }
+        return new DownloadModel();
+    }
+
+    private DownloadModel downloadChangeDataTemplate() {
+        DownloadModel result = new DownloadModel();
+        result.setType("workbook");
+        result.setName("批量上传变更记录.xlsx");
+
+        List<SheetWriteInfo> list = new ArrayList<>(2);
+        list.add(calendarReportPart1());
+        list.add(calendarReportPart2());
+        list.add(calendarReportPart3());
+        Workbook workbook = ExcelUtils.createExcel(list);
+        result.setWorkbook(workbook);
+        return result;
+    }
+
+    public SheetWriteInfo calendarReportPart1() {
+        SheetWriteInfo<String> info = new SheetWriteInfo<>();
+        List<String> list = new ArrayList<>();
+        list.add("1.不可合并单元格");
+        list.add("2.sheet1:类型变更");
+        list.add("3.sheet2:信息点变更");
+        list.add("4.sheet2-'字典选择'列:枚举类型用空格隔开;区间‘()’表示不包含‘[]’表示包含,例如:(10,20] [50,70],多个区间使用空格隔开");
+        list.add("5.sheet2-'信息点分类'列和'信息点类型'列:参考:http://39.102.54.110:9003/rwd/def_funcid.html 文档");
+        list.add("6.文件格式为:xlsx");
+        info.setData(list);
+        info.setSheetName("文件格式要求");
+        info.addColumn("文件格式要求", "type", "string", 120, HorizontalAlignment.LEFT);
+        info.setDataHandler((data, prop) -> {
+            return data;
+        });
+        return info;
+    }
+
+    public SheetWriteInfo calendarReportPart2() {
+        SheetWriteInfo<ClassDefChangeRecord> info = new SheetWriteInfo<>();
+        info.setData(Arrays.asList(new ClassDefChangeRecord()));
+        info.setSheetName("类型变更");
+        info.addColumn("专业编码", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("专业英文名称", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("专业名称", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("系统类编码", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("系统别编码", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("系统类英文名称", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("系统类名称", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("设备类编码", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("设备类别编码", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("设备类英文名称", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("设备类名称", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("部件类编码", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("部件别编码", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("部件类英文名称", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("部件类名称", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.setDataHandler((data, prop) -> {
+            return null;
+        });
+        return info;
+    }
+
+    public SheetWriteInfo calendarReportPart3() {
+        SheetWriteInfo<FuncidDefChangeRecord> info = new SheetWriteInfo<>();
+        info.setData(Arrays.asList(new FuncidDefChangeRecord()));
+        info.setSheetName("信息点变更");
+        info.addColumn("类型编码", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("类型名称", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("一级标签", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("二级标签", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("信息点编码", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("信息点别编码", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("信息点名称", "name", "string", 20, HorizontalAlignment.CENTER);
+        info.addColumn("信息点分类", "category", "array", 20, HorizontalAlignment.CENTER);
+        info.addColumn("优先级", "priority", "array", 10, HorizontalAlignment.CENTER);
+        info.addColumn("单位", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("信息点类型", "dataType", "array", 20, HorizontalAlignment.CENTER);
+        info.addColumn("是否复数", "isMultiple", "array", 10, HorizontalAlignment.CENTER);
+        info.addColumn("是否区间", "isRegion", "array", 10, HorizontalAlignment.GENERAL);
+        info.addColumn("字典选择", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("数据格式", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.addColumn("备注", "name", "string", 10, HorizontalAlignment.CENTER);
+        info.setDataHandler((data, prop) -> {
+            switch (prop) {
+                case ("dataType"): {
+                    return new String[]{"INTEGER", "DOUBLE", "BOOLEAN", "STRING", "DATETIME", "ENUM", "MENUM", "REFENMUM"};
+                }
+                case ("category"): {
+                    return new String[]{"STATIC", "PULSE", "SEQUENTIAL", "GRADATION"};
+                }
+                case ("priority"): {
+                    return new String[]{"A2", "D1", "M", "R", "S"};
+                }
+                case ("isRegion"):
+                case ("isMultiple"): {
+                    return new String[]{"1", "0"};
+                }
+                default: {
+                    return null;
+                }
+            }
+        });
+        return info;
+    }
+}
+

+ 0 - 104
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/service/FuncidDefChangeRecordService.java

@@ -8,8 +8,6 @@ import com.persagy.common.json.JacksonMapper;
 import com.persagy.common.web.ListResponse;
 import com.persagy.common.web.MapResponse;
 import com.persagy.common.web.PagedResponse;
-import com.persagy.dmp.common.excel.ExcelUtils;
-import com.persagy.dmp.common.excel.SheetReadInfo;
 import com.persagy.dmp.rwd.edit.config.web.UserUtils;
 import com.persagy.dmp.rwd.edit.entity.FuncidDef;
 import com.persagy.dmp.rwd.edit.entity.FuncidDefChangeRecord;
@@ -19,20 +17,15 @@ import com.persagy.dmp.rwd.edit.enumeration.EnumOperationType;
 import com.persagy.dmp.rwd.edit.enumeration.EnumVersionState;
 import com.persagy.dmp.rwd.edit.repository.FuncidDefChangeRecordRepository;
 import com.persagy.dmp.rwd.edit.repository.FuncidDefRepository;
-import com.persagy.dmp.rwd.enums.FuncidCategory;
 import com.persagy.dmp.rwd.enums.FuncidDataType;
 import com.persagy.dmp.rwd.model.ClassDefModel;
 import com.persagy.dmp.rwd.model.FuncidDefModel;
 import com.querydsl.core.types.dsl.BooleanExpression;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
 
 import javax.transaction.Transactional;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.*;
 
 @Slf4j
@@ -529,102 +522,5 @@ public class FuncidDefChangeRecordService {
         }
         return null;
     }
-
-    public List<FuncidDefChangeRecord> CompareDataExcelRead(MultipartFile file) throws IOException {
-        SheetReadInfo info = new SheetReadInfo();
-        info.setStartRow(1);
-        info.add(0, "code", "string");
-        info.add(1, "name", "string");
-        info.add(2, "aliasCode", "string");
-        info.add(3, "aliasName", "string");
-        info.add(4, "classCode", "string");
-        info.add(5, "category", "string");
-        info.add(6, "firstTag", "string");
-        info.add(7, "secondTag", "string");
-        info.add(8, "priority", "string");
-        info.add(9, "inputMode", "string");
-        info.add(10, "unit", "string");
-        info.add(11, "dataType", "string");
-        info.add(12, "isMultiple", "integer");
-        info.add(13, "isRegion", "integer");
-        info.add(14, "formater", "string");
-        info.add(15, "dataSource", "string");
-        info.add(16, "note", "string");
-        info.add(17, "subFlag", "integer");
-        info.add(18, "weakPoint", "integer");
-        info.add(19, "operationType", "string");
-
-        InputStream inputStream = file.getInputStream();
-        List<Map<String, Object>> result = ExcelUtils.read(inputStream, info);
-
-        List<FuncidDefChangeRecord> funcidDefChangeRecordList = new ArrayList<>();
-        for (Map<String, Object> map : result) {
-            String code = MapUtils.getString(map, "code");
-            String name = MapUtils.getString(map, "name");
-            String aliasCode = MapUtils.getString(map, "aliasCode");
-            String aliasName = MapUtils.getString(map, "aliasName");
-            String classCode = MapUtils.getString(map, "classCode");
-            String category = MapUtils.getString(map, "category");
-            String firstTag = MapUtils.getString(map, "firstTag");
-            String secondTag = MapUtils.getString(map, "secondTag");
-            String priority = MapUtils.getString(map, "priority");
-            String inputMode = MapUtils.getString(map, "inputMode");
-            String unit = MapUtils.getString(map, "unit");
-            String dataType = MapUtils.getString(map, "dataType");
-            Boolean isMultiple = MapUtils.getBoolean(map, "isMultiple");
-            Boolean isRegion = MapUtils.getBoolean(map, "isRegion");
-            String formater = MapUtils.getString(map, "formater");
-            String dataSource = MapUtils.getString(map, "dataSource");
-            String note = MapUtils.getString(map, "note");
-            Boolean subFlag = MapUtils.getBoolean(map, "subFlag");
-            Boolean weakPoint = MapUtils.getBoolean(map, "weakPoint");
-            String operationType = MapUtils.getString(map, "operationType");
-            if (code == null) {
-                return null;
-            }
-            if (classCode == null) {
-                return null;
-            }
-            if (category == null) {
-                return null;
-            }
-            if (operationType == null) {
-                return null;
-            }
-
-            FuncidDefChangeRecord funcidDefChangeRecord = new FuncidDefChangeRecord();
-            funcidDefChangeRecord.setCode(code);
-            funcidDefChangeRecord.setName(name);
-            funcidDefChangeRecord.setAliasCode(aliasCode);
-            funcidDefChangeRecord.setAliasName(aliasName);
-            funcidDefChangeRecord.setClassCode(classCode);
-            funcidDefChangeRecord.setCategory(FuncidCategory.valueOf(category));
-            funcidDefChangeRecord.setFirstTag(firstTag);
-            funcidDefChangeRecord.setSecondTag(secondTag);
-            funcidDefChangeRecord.setPriority(priority);
-            funcidDefChangeRecord.setInputMode(inputMode);
-            funcidDefChangeRecord.setUnit(unit);
-            funcidDefChangeRecord.setDataType(FuncidDataType.valueOf(dataType));
-            funcidDefChangeRecord.setIsMultiple(isMultiple);
-            funcidDefChangeRecord.setIsRegion(isRegion);
-            funcidDefChangeRecord.setFormater(formater);
-            ArrayNode dataSourceArray = JacksonMapper.toObject(dataSource, ArrayNode.class);
-            funcidDefChangeRecord.setDataSource(dataSourceArray);
-            funcidDefChangeRecord.setNote(note);
-            funcidDefChangeRecord.setSubFlag(subFlag);
-            funcidDefChangeRecord.setWeakPoint(weakPoint);
-            funcidDefChangeRecord.setOperationType(EnumOperationType.valueOf(operationType));
-
-            funcidDefChangeRecord.setType("common");
-            funcidDefChangeRecord.setOperationUser(UserUtils.currentUserId() + "");
-            funcidDefChangeRecord.setOperationTime(new Date());
-            funcidDefChangeRecord.setValid(true);
-            funcidDefChangeRecord.setState(EnumVersionState.INIT);
-            funcidDefChangeRecord.setGroupCode("0");
-            funcidDefChangeRecord.setProjectId("0");
-            funcidDefChangeRecordList.add(funcidDefChangeRecord);
-        }
-        return funcidDefChangeRecordList;
-    }
 }
 

+ 329 - 0
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/service/UploadService.java

@@ -0,0 +1,329 @@
+package com.persagy.dmp.rwd.edit.service;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.common.criteria.JacksonCriteria;
+import com.persagy.common.json.JacksonMapper;
+import com.persagy.common.web.MapResponse;
+import com.persagy.dmp.common.excel.ExcelUtils;
+import com.persagy.dmp.common.excel.SheetReadInfo;
+import com.persagy.dmp.rwd.edit.config.web.UserUtils;
+import com.persagy.dmp.rwd.edit.entity.ClassDefChangeRecord;
+import com.persagy.dmp.rwd.edit.entity.FuncidDefChangeRecord;
+import com.persagy.dmp.rwd.edit.enumeration.EnumOperationType;
+import com.persagy.dmp.rwd.edit.enumeration.EnumVersionState;
+import com.persagy.dmp.rwd.enums.FuncidCategory;
+import com.persagy.dmp.rwd.enums.FuncidDataType;
+import com.persagy.dmp.rwd.enums.ObjType;
+import com.persagy.dmp.rwd.model.ClassDefModel;
+import com.persagy.dmp.rwd.model.FuncidDefModel;
+import org.apache.commons.collections.MapUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Service
+public class UploadService {
+
+    @Autowired
+    private ClassDefChangeRecordService classDefChangeRecordService;
+
+    @Autowired
+    private FuncidDefChangeRecordService funcidDefChangeRecordService;
+
+    @Autowired
+    private ClassDefService classDefService;
+
+    @Autowired
+    private FuncidDefService funcidDefService;
+
+    public MapResponse upload(String type, MultipartFile file) throws Exception {
+        MapResponse response = new MapResponse();
+        if ("changeDataSave".equals(type)) {
+            return uploadCalendarReportSave(file);
+        }
+        response.setFail("type不存在");
+        return response;
+    }
+
+    private MapResponse uploadCalendarReportSave(MultipartFile file) throws Exception {
+        Map<String, Object> result = calendarReportExcelRead(file);
+        List<ClassDefChangeRecord> classDefChangeRecordList = (List<ClassDefChangeRecord>) result.get("classDefChangeRecordList");
+        List<FuncidDefChangeRecord> funcidDefChangeRecordList = (List<FuncidDefChangeRecord>) result.get("funcidDefChangeRecordList");
+
+        for (ClassDefChangeRecord classDefChangeRecord : classDefChangeRecordList) {
+            classDefChangeRecordService.create(classDefChangeRecord);
+        }
+
+        for (FuncidDefChangeRecord funcidDefChangeRecord : funcidDefChangeRecordList) {
+            funcidDefChangeRecordService.create(funcidDefChangeRecord);
+        }
+        return new MapResponse();
+    }
+
+    private Map<String, Object> calendarReportExcelRead(MultipartFile file) throws Exception {
+
+        SheetReadInfo info1 = new SheetReadInfo();
+        info1.setStartRow(1);
+        info1.add(0, "majorCode", "string");
+        info1.add(2, "majorName", "string");
+        info1.add(3, "systemCode", "string");
+        info1.add(4, "systemAliasCode", "string");
+        info1.add(6, "systemName", "string");
+        info1.add(7, "equipmentCode", "string");
+        info1.add(8, "equipmentAliasCode", "string");
+        info1.add(10, "equipmentName", "string");
+        info1.add(11, "componentCode", "string");
+        info1.add(12, "componentAliasCode", "string");
+        info1.add(14, "componentName", "string");
+
+        SheetReadInfo info2 = new SheetReadInfo();
+        info2.setStartRow(1);
+        info2.add(0, "classCode", "string");
+        info2.add(2, "firstTag", "string");
+        info2.add(3, "secondTag", "string");
+        info2.add(4, "code", "string");
+        info2.add(5, "aliasCode", "string");
+        info2.add(6, "name", "string");
+        info2.add(7, "category", "string");
+        info2.add(8, "priority", "string");
+        info2.add(9, "unit", "string");
+        info2.add(10, "dataType", "string");
+        info2.add(11, "isMultiple", "integer");
+        info2.add(12, "isRegion", "integer");
+        info2.add(13, "dataSource", "string");
+        info2.add(14, "formater", "string");
+        info2.add(15, "note", "string");
+
+        List<List<Map<String, Object>>> result = ExcelUtils.read(file.getInputStream(), Arrays.asList(info1, info2),Arrays.asList("类型变更","信息点变更"));
+        List<ClassDefChangeRecord> classDefChangeRecordList = compareDataExcelReadClass(result.get(0));
+        List<FuncidDefChangeRecord> funcidDefChangeRecordList = compareDataExcelReadFuncid(result.get(1));
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("classDefChangeRecordList", classDefChangeRecordList);
+        map.put("funcidDefChangeRecordList", funcidDefChangeRecordList);
+        return map;
+    }
+
+    public List<ClassDefChangeRecord> compareDataExcelReadClass(List<Map<String, Object>> result) throws Exception {
+        JacksonCriteria criteria = JacksonCriteria.newInstance();
+        criteria.add("type", "common");
+        List<ClassDefModel> data = classDefService.queryClass(criteria).getData();
+        Map<String, ClassDefModel> classCodeMap = data.stream().collect(Collectors.toMap(ClassDefModel::getCode, Function.identity()));
+        List<ClassDefChangeRecord> classDefChangeRecordList = new ArrayList<>();
+        for (Map<String, Object> map : result) {
+            String majorCode = MapUtils.getString(map, "majorCode");
+            String systemCode = MapUtils.getString(map, "systemCode");
+            String systemAliasCode = MapUtils.getString(map, "systemAliasCode");
+            String systemName = MapUtils.getString(map, "systemName");
+            String equipmentCode = MapUtils.getString(map, "equipmentCode");
+            String equipmentAliasCode = MapUtils.getString(map, "equipmentAliasCode");
+            String equipmentName = MapUtils.getString(map, "equipmentName");
+            String componentCode = MapUtils.getString(map, "componentCode");
+            String componentAliasCode = MapUtils.getString(map, "componentAliasCode");
+            String componentName = MapUtils.getString(map, "componentName");
+            if (majorCode == null) {
+                throw new Exception("专业编码不可为空");
+            }
+
+            ClassDefChangeRecord changeRecord = new ClassDefChangeRecord();
+            if (componentCode != null) {
+                componentCode = majorCode + systemCode + equipmentCode + componentCode;
+                equipmentCode = majorCode + systemCode + equipmentCode;
+                systemCode = majorCode + systemCode;
+                getClassDefChangeRecord(classCodeMap, changeRecord, componentCode, componentName, componentAliasCode, componentName, ObjType.component, majorCode, systemCode, equipmentCode);
+            } else if (equipmentCode != null) {
+                equipmentCode = majorCode + systemCode + equipmentCode;
+                systemCode = majorCode + systemCode;
+                getClassDefChangeRecord(classCodeMap, changeRecord, equipmentCode, equipmentName, equipmentAliasCode, equipmentName, ObjType.equipment, majorCode, systemCode, null);
+            } else if (systemCode != null) {
+                systemCode = majorCode + systemCode;
+                getClassDefChangeRecord(classCodeMap, changeRecord, systemCode, systemName, systemAliasCode, systemName, ObjType.system, majorCode, null, null);
+            }
+            classDefChangeRecordList.add(changeRecord);
+        }
+        return classDefChangeRecordList;
+    }
+
+    public ClassDefChangeRecord getClassDefChangeRecord(Map<String, ClassDefModel> classCodeMap, ClassDefChangeRecord changeRecord,
+                                                        String code, String name, String aliasCode, String aliasName,
+                                                        ObjType objType, String majorCode, String systemCode, String equipmentCode) {
+        if (classCodeMap.containsKey(code)) {
+            ClassDefModel classDefModel = classCodeMap.get(code);
+            changeRecord.setCode(classDefModel.getCode());
+            changeRecord.setObjType(classDefModel.getObjType());
+            changeRecord.setName(classDefModel.getName());
+            changeRecord.setMajorCode(classDefModel.getMajorCode());
+            changeRecord.setSystemCode(classDefModel.getSystemCode());
+            changeRecord.setParentCode(classDefModel.getParentCode());
+            changeRecord.setType(classDefModel.getType());
+            changeRecord.setGroupCode(classDefModel.getGroupCode());
+            changeRecord.setProjectId(classDefModel.getProjectId());
+            changeRecord.setOperationUser(UserUtils.currentUserId() + "");
+            changeRecord.setOperationTime(new Date());
+            changeRecord.setValid(true);
+            changeRecord.setState(EnumVersionState.INIT);
+            changeRecord.setOperationType(EnumOperationType.update);
+        } else {
+            changeRecord.setCode(code);
+            changeRecord.setObjType(objType);
+            changeRecord.setName(name);
+            changeRecord.setMajorCode(majorCode);
+            changeRecord.setSystemCode(systemCode);
+            changeRecord.setEquipmentCode(equipmentCode);
+            changeRecord.setParentCode(objType.toString());
+            changeRecord.setType("common");
+            changeRecord.setGroupCode("0");
+            changeRecord.setProjectId("0");
+            changeRecord.setOperationUser(UserUtils.currentUserId() + "");
+            changeRecord.setOperationTime(new Date());
+            changeRecord.setValid(true);
+            changeRecord.setState(EnumVersionState.INIT);
+            changeRecord.setOperationType(EnumOperationType.create);
+        }
+        changeRecord.setAliasCode(aliasCode == null ? code : aliasCode);
+        changeRecord.setAliasName(aliasName);
+        return changeRecord;
+    }
+
+    public List<FuncidDefChangeRecord> compareDataExcelReadFuncid(List<Map<String, Object>> result) throws Exception {
+        Map<String, FuncidDefModel> funcidDefMap = new HashMap<>();
+        List<FuncidDefChangeRecord> funcidDefChangeRecordList = new ArrayList<>();
+        for (Map<String, Object> map : result) {
+            String classCode = MapUtils.getString(map, "classCode");
+            String firstTag = MapUtils.getString(map, "firstTag");
+            String secondTag = MapUtils.getString(map, "secondTag");
+            String code = MapUtils.getString(map, "code");
+            String aliasCode = MapUtils.getString(map, "aliasCode");
+            String name = MapUtils.getString(map, "name");
+            String category = MapUtils.getString(map, "category");
+            String priority = MapUtils.getString(map, "priority");
+            String unit = MapUtils.getString(map, "unit");
+            String dataType = MapUtils.getString(map, "dataType");
+            Boolean isMultiple = MapUtils.getBoolean(map, "isMultiple");
+            Boolean isRegion = MapUtils.getBoolean(map, "isRegion");
+            String dataSource = MapUtils.getString(map, "dataSource");
+            String formater = MapUtils.getString(map, "formater");
+            String note = MapUtils.getString(map, "note");
+
+            if (classCode == null) {
+                throw new Exception("类型编码不可为空");
+            }
+            if (code == null) {
+                throw new Exception("信息点编码不可为空");
+            }
+
+            if (!funcidDefMap.containsKey(code)) {
+                JacksonCriteria criteria = JacksonCriteria.newInstance();
+                criteria.add("type", "common");
+                criteria.add("code", code);
+                criteria.add("classCode", classCode);
+                List<FuncidDefModel> data = funcidDefService.queryFuncid(criteria).getData();
+                Map<String, FuncidDefModel> dataMap = data.stream().collect(Collectors.toMap(FuncidDefModel::getCode, Function.identity()));
+                funcidDefMap.putAll(dataMap);
+            }
+
+            FuncidDefChangeRecord changeRecord = new FuncidDefChangeRecord();
+            if (funcidDefMap.containsKey(code)) {
+                FuncidDefModel funcidDefModel = funcidDefMap.get(code);
+                changeRecord.setCode(funcidDefModel.getCode());
+                changeRecord.setName(funcidDefModel.getName());
+                changeRecord.setClassCode(funcidDefModel.getClassCode());
+                changeRecord.setCategory(funcidDefModel.getCategory());
+                changeRecord.setPriority(funcidDefModel.getPriority());
+                changeRecord.setUnit(funcidDefModel.getUnit());
+                changeRecord.setDataType(funcidDefModel.getDataType());
+                changeRecord.setIsMultiple(funcidDefModel.getIsMultiple());
+                changeRecord.setIsRegion(funcidDefModel.getIsRegion());
+                changeRecord.setFormater(funcidDefModel.getFormater());
+                changeRecord.setType(funcidDefModel.getType());
+                changeRecord.setGroupCode(funcidDefModel.getGroupCode());
+                changeRecord.setProjectId(funcidDefModel.getProjectId());
+                changeRecord.setOperationUser(UserUtils.currentUserId() + "");
+                changeRecord.setOperationTime(new Date());
+                changeRecord.setValid(true);
+                changeRecord.setState(EnumVersionState.INIT);
+                changeRecord.setOperationType(EnumOperationType.update);
+            } else {
+                changeRecord.setCode(code);
+                changeRecord.setName(name);
+                changeRecord.setClassCode(classCode);
+                changeRecord.setCategory(FuncidCategory.valueOf(category));
+                changeRecord.setPriority(priority);
+                changeRecord.setUnit(unit);
+                changeRecord.setDataType(FuncidDataType.valueOf(dataType));
+                changeRecord.setIsMultiple(isMultiple);
+                changeRecord.setIsRegion(isRegion);
+                changeRecord.setFormater(formater);
+                changeRecord.setType("common");
+                changeRecord.setGroupCode("0");
+                changeRecord.setProjectId("0");
+                changeRecord.setOperationUser(UserUtils.currentUserId() + "");
+                changeRecord.setOperationTime(new Date());
+                changeRecord.setValid(true);
+                changeRecord.setState(EnumVersionState.INIT);
+                changeRecord.setOperationType(EnumOperationType.create);
+
+                //处理数据源
+                if (dataSource != null) {
+                    dataSource = dataSource.replace(". ", ".");
+                    dataSource = dataSource.replace(",", ",");
+                    String[] split = dataSource.split(" ");
+                    if (split.length != 0) {
+                        ArrayNode array = JsonNodeFactory.instance.arrayNode();
+                        if (dataType.equals(FuncidDataType.ENUM.toString())) {
+                            for (int i = 0; i < split.length; i++) {
+                                String temp = split[i];
+                                int idx = temp.indexOf(".");
+                                if (idx == -1) {
+                                    continue;
+                                }
+                                String key = temp.substring(0, idx);
+                                String value = temp.substring(idx + 1);
+                                ObjectNode item = array.addObject();
+                                item.put("code", key);
+                                item.put("name", value);
+                            }
+                            changeRecord.setDataSource(array);
+                        } else {
+                            for (int i = 0; i < split.length; i++) {
+                                String temp = split[i];
+                                int idx = temp.indexOf(",");
+                                String key = temp.substring(0, idx);
+                                String value = temp.substring(idx + 1);
+                                ObjectNode item = array.addObject();
+                                if (key.startsWith("(")) {
+                                    key = key.replace("(", "");
+                                    item.put("$gt", key);
+                                } else if (key.startsWith("[")) {
+                                    key = key.replace("[", "");
+                                    item.put("$gte", key);
+                                }
+                                if (value.endsWith(")")) {
+                                    value = value.replace(")", "");
+                                    item.put("$lt", value);
+                                } else if (value.endsWith("]")) {
+                                    value = value.replace("]", "");
+                                    item.put("$lte", value);
+                                }
+                            }
+                            changeRecord.setDataSource(array);
+                        }
+                    }
+                }
+            }
+            changeRecord.setAliasCode(aliasCode);
+            changeRecord.setAliasName(name);
+            changeRecord.setNote(note);
+            changeRecord.setFirstTag(firstTag);
+            changeRecord.setSecondTag(secondTag);
+            funcidDefChangeRecordList.add(changeRecord);
+        }
+        return funcidDefChangeRecordList;
+    }
+}