|
@@ -179,6 +179,7 @@ public class TrialSummaryController {
|
|
|
&& ObjectUtil.isNotEmpty(classC.getHtmlUrl())
|
|
|
&& ObjectUtil.isNotEmpty(classC.getTrialTreeIds())) {
|
|
|
|
|
|
+ /*获取条件时间段内的试验自检数据*/
|
|
|
LocalDate startDate = LocalDate.parse(dto.getStartDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
LocalDate endDate = LocalDate.parse(dto.getEndDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
List<TrialSelfInspectionRecord> records = trialSelfInspectionRecordServiceImpl.getBaseMapper().selectList(Wrappers.<TrialSelfInspectionRecord>lambdaQuery()
|
|
@@ -200,6 +201,8 @@ public class TrialSummaryController {
|
|
|
.collect(Collectors.groupingBy(
|
|
|
reflection -> reflection.getTrialTabName() + "###" + reflection.getTrialTabId()
|
|
|
));
|
|
|
+
|
|
|
+ /*构造实体数据map*/
|
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
|
for (Map.Entry<String, List<TrialSummaryExcelTabReflection>> entry : maps.entrySet()) {
|
|
|
String tabName = entry.getKey().split("###")[0];
|
|
@@ -230,17 +233,24 @@ public class TrialSummaryController {
|
|
|
for (String valueRow : split) {
|
|
|
String[] splitValues = valueRow.split(Pattern.quote("_^_"));
|
|
|
String valueInput = splitValues[0];
|
|
|
- String indexKey = splitValues[1];
|
|
|
- String keyName = elementKey + "__" + indexKey;
|
|
|
- map.put(keyName, valueInput);
|
|
|
+ /*String indexKey = splitValues[1];*/
|
|
|
+ String keyName = elementKey + "__";
|
|
|
+
|
|
|
+ if (map.containsKey(keyName)) {
|
|
|
+ String existingValue = (String) map.get(keyName);
|
|
|
+ map.put(keyName, existingValue + "@@@###" + valueInput);
|
|
|
+ } else {
|
|
|
+ map.put(keyName, valueInput);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
} else {
|
|
|
//非跨行
|
|
|
if (tabDataStr.contains(".000Z]") && tabDataStr.contains("T")) {
|
|
|
String[] splitValues = tabDataStr.split(Pattern.quote("_^_"));
|
|
|
String valueInput = splitValues[0];
|
|
|
- String indexKey = splitValues[1];
|
|
|
- String keyName = elementKey + "__" + indexKey;
|
|
|
+ /*String indexKey = splitValues[1];*/
|
|
|
+ String keyName = elementKey + "__";
|
|
|
|
|
|
//范围日期
|
|
|
String[] split = valueInput.split(",");
|
|
@@ -252,48 +262,66 @@ public class TrialSummaryController {
|
|
|
ZonedDateTime endZonedTime = endTime.atZone(ZoneId.of("UTC"));
|
|
|
String time_1 = startZonedTime.format(DateTimeFormatter.ISO_DATE_TIME);
|
|
|
String time_2 = endZonedTime.format(DateTimeFormatter.ISO_DATE_TIME);
|
|
|
- map.put(keyName, time_1 + "~" + time_2);
|
|
|
+
|
|
|
+ if (map.containsKey(keyName)) {
|
|
|
+ String existingValue = (String) map.get(keyName);
|
|
|
+ map.put(keyName, existingValue + "@@@###" + time_1 + "~" + time_2);
|
|
|
+ } else {
|
|
|
+ map.put(keyName, time_1 + "~" + time_2);
|
|
|
+ }
|
|
|
|
|
|
} else if (tabDataStr.contains(".000Z") && tabDataStr.contains("T")) {
|
|
|
String[] splitValues = tabDataStr.split(Pattern.quote("_^_"));
|
|
|
String valueInput = splitValues[0];
|
|
|
- String indexKey = splitValues[1];
|
|
|
- String keyName = elementKey + "__" + indexKey;
|
|
|
+ /*String indexKey = splitValues[1];*/
|
|
|
+ String keyName = elementKey + "__";
|
|
|
|
|
|
//单日期
|
|
|
LocalDateTime time = LocalDateTime.parse(valueInput, DateTimeFormatter.ISO_DATE_TIME);
|
|
|
ZonedDateTime zonedDateTime = time.atZone(ZoneId.of("UTC"));
|
|
|
String timeStr = zonedDateTime.format(DateTimeFormatter.ISO_DATE_TIME);
|
|
|
- map.put(keyName, timeStr);
|
|
|
+
|
|
|
+ if (map.containsKey(keyName)) {
|
|
|
+ String existingValue = (String) map.get(keyName);
|
|
|
+ map.put(keyName, existingValue + "@@@###" + timeStr);
|
|
|
+ } else {
|
|
|
+ map.put(keyName, timeStr);
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
String[] splitValues = tabDataStr.split(Pattern.quote("_^_"));
|
|
|
String valueInput = splitValues[0];
|
|
|
- String indexKey = splitValues[1];
|
|
|
- String keyName = elementKey + "__" + indexKey;
|
|
|
- map.put(keyName, valueInput);
|
|
|
+ /*String indexKey = splitValues[1];*/
|
|
|
+ String keyName = elementKey + "__";
|
|
|
+
|
|
|
+ if (map.containsKey(keyName)) {
|
|
|
+ String existingValue = (String) map.get(keyName);
|
|
|
+ map.put(keyName, existingValue + "@@@###" + valueInput);
|
|
|
+ } else {
|
|
|
+ map.put(keyName, valueInput);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Map<String, String> needsSavedData = new LinkedHashMap<>();
|
|
|
String htmlString = this.html(classC.getHtmlUrl());
|
|
|
- Map<String, String> indexMap = this.indexMap(htmlString, map, needsSavedData);
|
|
|
+ Map<String, String> indexMap = this.indexMap(htmlString, map);
|
|
|
if (indexMap.size() > 0) {
|
|
|
ExcelTab excelTab = jdbcTemplate.query("SELECT file_url FROM m_excel_tab WHERE id = ?", new Object[]{classC.getExcelId()}, new BeanPropertyRowMapper<>(ExcelTab.class)).stream().findAny().orElse(null);
|
|
|
if (excelTab != null) {
|
|
|
- MultipartFile multipartFile = this.writeDataToMultipartFile(excelTab.getFileUrl(), indexMap);
|
|
|
- if (multipartFile != null) {
|
|
|
- NewBladeFile newBladeFile = newIOSSClient.excelToPdf(multipartFile);
|
|
|
+ List<MultipartFile> files = this.writeDataToMultipartFile(excelTab.getFileUrl(), indexMap);
|
|
|
+ if (files.size() > 0) {
|
|
|
+ NewBladeFile newBladeFile = newIOSSClient.excelToPdfs(files);
|
|
|
if (newBladeFile != null) {
|
|
|
TrialSummaryRecord obj = BeanUtil.copyProperties(dto, TrialSummaryRecord.class);
|
|
|
if (obj != null) {
|
|
|
obj.setId(SnowFlakeUtil.getId());
|
|
|
obj.setSummaryNumber(sn);
|
|
|
obj.setPdfUrl(newBladeFile.getPdfUrl());
|
|
|
- if (trialSummaryRecordServiceImpl.save(obj) && saveData(needsSavedData, obj, classC)) {
|
|
|
+ if (trialSummaryRecordServiceImpl.save(obj) && saveData(indexMap, obj, classC)) {
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
}
|
|
@@ -336,64 +364,109 @@ public class TrialSummaryController {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- private MultipartFile writeDataToMultipartFile(String fileUrl, Map<String, String> indexMap) throws Exception {
|
|
|
- InputStream modInput = CommonUtil.getOSSInputStream(fileUrl);
|
|
|
- if (modInput != null) {
|
|
|
- try (Workbook workbook = new XSSFWorkbook(modInput)) {
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- for (Map.Entry<String, String> entry : indexMap.entrySet()) {
|
|
|
- String key = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
- String[] coordinates = key.split("@");
|
|
|
- String x = coordinates[0];
|
|
|
- String y = coordinates[1];
|
|
|
-
|
|
|
- int x1 = Integer.parseInt(x.split(":")[0]) - 1;
|
|
|
- int x2 = Integer.parseInt(x.split(":")[1]) - 1;
|
|
|
- int y1 = Integer.parseInt(y.split(":")[0]) - 1;
|
|
|
- int y2 = Integer.parseInt(y.split(":")[1]) - 1;
|
|
|
-
|
|
|
- mergeAndCenterCells(sheet, x1, x2, y1, y2, value);
|
|
|
- }
|
|
|
- try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
|
|
|
- workbook.write(byteArrayOutputStream);
|
|
|
- try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
|
|
|
- return new MockMultipartFile("file", fileUrl, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", byteArrayInputStream);
|
|
|
+ private List<MultipartFile> writeDataToMultipartFile(String fileUrl, Map<String, String> indexMap) throws Exception {
|
|
|
+ /*pageSize分页分组*/
|
|
|
+ Map<String, List<Map.Entry<String, String>>> groupedByPageSize = indexMap.entrySet().stream()
|
|
|
+ .collect(Collectors.groupingBy(entry -> {
|
|
|
+ String[] indexAndPageSize = entry.getKey().split("@pageSize@");
|
|
|
+ return indexAndPageSize[1];
|
|
|
+ }));
|
|
|
+
|
|
|
+ List<MultipartFile> files = new LinkedList<>();
|
|
|
+
|
|
|
+ /*每一页视为一份新excel*/
|
|
|
+ for (Map.Entry<String, List<Map.Entry<String, String>>> page : groupedByPageSize.entrySet()) {
|
|
|
+ InputStream modInput = CommonUtil.getOSSInputStream(fileUrl);
|
|
|
+ if (modInput != null) {
|
|
|
+ try (Workbook workbook = new XSSFWorkbook(modInput)) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ for (Map.Entry<String, String> entry : page.getValue()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+ String[] indexAndPageSize = key.split("@pageSize@");
|
|
|
+
|
|
|
+ String index = indexAndPageSize[0];
|
|
|
+
|
|
|
+ String[] coordinates = index.split("@");
|
|
|
+ String x = coordinates[0];
|
|
|
+ String y = coordinates[1];
|
|
|
+
|
|
|
+ int x1 = Integer.parseInt(x.split(":")[0]) - 1;
|
|
|
+ int x2 = Integer.parseInt(x.split(":")[1]) - 1;
|
|
|
+ int y1 = Integer.parseInt(y.split(":")[0]) - 1;
|
|
|
+ int y2 = Integer.parseInt(y.split(":")[1]) - 1;
|
|
|
+
|
|
|
+ /*根据位置信息,将value写入excel*/
|
|
|
+ mergeAndCenterCells(sheet, x1, x2, y1, y2, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
|
|
|
+ workbook.write(byteArrayOutputStream);
|
|
|
+ try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
|
|
|
+ files.add(new MockMultipartFile("file", fileUrl, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", byteArrayInputStream));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
+ return files;
|
|
|
}
|
|
|
|
|
|
private void mergeAndCenterCells(Sheet sheet, int x1, int x2, int y1, int y2, String value) {
|
|
|
- if (!isAlreadyMerged(sheet, x1, x2, y1, y2)) {
|
|
|
- CellRangeAddress mergedRegion = new CellRangeAddress(y1, y2, x1, x2);
|
|
|
- sheet.addMergedRegion(mergedRegion);
|
|
|
- }
|
|
|
+ if (x1 == x2 && y1 == y2) {
|
|
|
+ /*单个单元格,直接写入value,不需要合并*/
|
|
|
+ Row row = sheet.getRow(y1);
|
|
|
+ if (row == null) {
|
|
|
+ row = sheet.createRow(y1);
|
|
|
+ }
|
|
|
|
|
|
- Row row = sheet.getRow(y1);
|
|
|
- if (row == null) {
|
|
|
- row = sheet.createRow(y1);
|
|
|
- }
|
|
|
+ Cell cell = row.createCell(x1);
|
|
|
+ cell.setCellValue(value);
|
|
|
+
|
|
|
+ CellStyle style = sheet.getWorkbook().createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
+ style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
+ style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
+ style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
+ style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ } else {
|
|
|
+ /*非单个单元格,判断执行合并操作*/
|
|
|
+ if (!isAlreadyMerged(sheet, x1, x2, y1, y2)) {
|
|
|
+ CellRangeAddress mergedRegion = new CellRangeAddress(y1, y2, x1, x2);
|
|
|
+ sheet.addMergedRegion(mergedRegion);
|
|
|
+ }
|
|
|
|
|
|
- Cell cell = row.createCell(x1);
|
|
|
- cell.setCellValue(value);
|
|
|
+ Row row = sheet.getRow(y1);
|
|
|
+ if (row == null) {
|
|
|
+ row = sheet.createRow(y1);
|
|
|
+ }
|
|
|
|
|
|
- CellStyle style = sheet.getWorkbook().createCellStyle();
|
|
|
- style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
- style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ Cell cell = row.createCell(x1);
|
|
|
+ cell.setCellValue(value);
|
|
|
|
|
|
- style.setBorderBottom(BorderStyle.THIN);
|
|
|
- style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
- style.setBorderTop(BorderStyle.THIN);
|
|
|
- style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
- style.setBorderLeft(BorderStyle.THIN);
|
|
|
- style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
- style.setBorderRight(BorderStyle.THIN);
|
|
|
- style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ CellStyle style = sheet.getWorkbook().createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
|
|
- cell.setCellStyle(style);
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
+ style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
+ style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
+ style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
+ style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
|
|
+
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private boolean isAlreadyMerged(Sheet sheet, int x1, int x2, int y1, int y2) {
|
|
@@ -438,26 +511,95 @@ public class TrialSummaryController {
|
|
|
*
|
|
|
* @param htmlString
|
|
|
* @param values
|
|
|
- * @param needsSavedData 需要保存入库的数据(历史记录,其他接口需要使用)
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String, String> indexMap(String htmlString, Map<String, Object> values, Map<String, String> needsSavedData) {
|
|
|
+ private Map<String, String> indexMap(String htmlString, Map<String, Object> values) {
|
|
|
Map<String, String> resultIndex = new LinkedHashMap<>();
|
|
|
Document doc = Jsoup.parse(htmlString);
|
|
|
String[] tagNames = {"el-input", "el-date-picker", "el-time-picker", "hc-form-select-search",
|
|
|
"hc-table-form-upload", "hc-form-checkbox-group", "el-radio-group", "el-select"};
|
|
|
for (String tagName : tagNames) {
|
|
|
Elements matchedElements = doc.select(tagName);
|
|
|
- for (Element element : matchedElements) {
|
|
|
- String keyName = element.attr("keyname");
|
|
|
- if (values.containsKey(keyName)) {
|
|
|
- String value = values.get(keyName).toString();
|
|
|
- String colIndex_1 = element.attr("x1");
|
|
|
- String colIndex_2 = element.attr("x2");
|
|
|
- String rowIndex_1 = element.attr("y1");
|
|
|
- String rowIndex_2 = element.attr("y2");
|
|
|
- resultIndex.put(colIndex_1 + ":" + colIndex_2 + "@" + rowIndex_1 + ":" + rowIndex_2, value);
|
|
|
- needsSavedData.put(keyName, value);
|
|
|
+
|
|
|
+ for (Map.Entry<String, Object> map : values.entrySet()) {
|
|
|
+ /*key:key_1__*/
|
|
|
+ String key = map.getKey();
|
|
|
+ String value = (String) map.getValue();
|
|
|
+ String[] data = value.split("@@@###");
|
|
|
+
|
|
|
+ /*排序,取data[]个数标签,依次构造数据*/
|
|
|
+ Elements keyElementGroup = new Elements();
|
|
|
+ for (Element element : matchedElements) {
|
|
|
+ /*模糊匹配,取包含部分key的标签*/
|
|
|
+ if (element.hasAttr("keyname") && element.attr("keyname").contains(key)) {
|
|
|
+ keyElementGroup.add(element);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (keyElementGroup.size() <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*输入框排序*/
|
|
|
+ Comparator<Element> elementComparator = Comparator
|
|
|
+ .comparingInt(element -> {
|
|
|
+ int x1 = Integer.parseInt(element.attr("x1"));
|
|
|
+ int x2 = Integer.parseInt(element.attr("x2"));
|
|
|
+ int y1 = Integer.parseInt(element.attr("y1"));
|
|
|
+ int y2 = Integer.parseInt(element.attr("y2"));
|
|
|
+ return x1 + x2 + y1 + y2;
|
|
|
+ });
|
|
|
+ List<Element> sortedElements = keyElementGroup.stream()
|
|
|
+ .sorted(elementComparator)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (sortedElements.size() < data.length) {
|
|
|
+ /*html输入框数量 < 试验自检实体数据 ,存在多页,需翻页*/
|
|
|
+ int countInputAdd = data.length - sortedElements.size();
|
|
|
+ /*每页需要sortedElements.size()个输入框,共需要countPage页*/
|
|
|
+ int countPage = (countInputAdd + sortedElements.size()) / sortedElements.size();
|
|
|
+ countPage += (countInputAdd + sortedElements.size() - 1) % sortedElements.size() > 0 ? 1 : 0;
|
|
|
+
|
|
|
+ List<Element> sortedElementsAll = new LinkedList<>();
|
|
|
+ for (int i = 0; i < countPage; i++) {
|
|
|
+ sortedElementsAll.addAll(sortedElements);
|
|
|
+ }
|
|
|
+
|
|
|
+ int pageSize = 0;
|
|
|
+ Elements sortedKeyElements = new Elements(sortedElementsAll);
|
|
|
+ for (int i = 0; i < sortedElementsAll.size(); i++) {
|
|
|
+ String dataResult = data[i];
|
|
|
+ Element keyElement = sortedKeyElements.get(i);
|
|
|
+ String colIndex_1 = keyElement.attr("x1");
|
|
|
+ String colIndex_2 = keyElement.attr("x2");
|
|
|
+ String rowIndex_1 = keyElement.attr("y1");
|
|
|
+ String rowIndex_2 = keyElement.attr("y2");
|
|
|
+ resultIndex.put(colIndex_1 + ":" + colIndex_2 + "@" + rowIndex_1 + ":" + rowIndex_2 + "@pageSize@" + pageSize, dataResult);
|
|
|
+ if ((i + 1) % sortedElements.size() == 0) {
|
|
|
+ pageSize++;
|
|
|
+ }
|
|
|
+ if (i == data.length - 1) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ /*html输入框数量 >= 试验自检实体数据 ,默认一页,直接写入当前页*/
|
|
|
+ List<Element> firstThreeElements = sortedElements.stream()
|
|
|
+ .limit(data.length)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Elements sortedKeyElements = new Elements(firstThreeElements);
|
|
|
+
|
|
|
+ for (int i = 0; i < sortedKeyElements.size(); i++) {
|
|
|
+ String dataResult = data[i];
|
|
|
+ Element keyElement = sortedKeyElements.get(i);
|
|
|
+ String colIndex_1 = keyElement.attr("x1");
|
|
|
+ String colIndex_2 = keyElement.attr("x2");
|
|
|
+ String rowIndex_1 = keyElement.attr("y1");
|
|
|
+ String rowIndex_2 = keyElement.attr("y2");
|
|
|
+ //默认第一页@pageSize@0
|
|
|
+ resultIndex.put(colIndex_1 + ":" + colIndex_2 + "@" + rowIndex_1 + ":" + rowIndex_2 + "@pageSize@0", dataResult);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|