瀏覽代碼

客户端excel导入范围日期bug

liuyc 2 年之前
父節點
當前提交
774d5e6cff

+ 62 - 62
blade-service/blade-business/src/main/java/org/springblade/business/controller/ImageClassificationFileController.java

@@ -188,72 +188,72 @@ public class ImageClassificationFileController extends BladeController {
                                 try {
                                     //创建模板Workbook
                                     modInput = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
-                                    workbook = WorkbookFactory.create(modInput);
-
-                                    for (int i = 0, l = urls.size(); i < l; i++) {
-                                        try {
-                                            CreationHelper helper = workbook.getCreationHelper();
-                                            Sheet sheet = workbook.getSheetAt(0);
-                                            Drawing<?> drawing = sheet.createDrawingPatriarch();
-                                            ClientAnchor anchor = helper.createClientAnchor();
-
-                                            if (i == 0) {
-                                                anchor.setRow1(0);
-                                                anchor.setCol1(0);
-                                            } else {
-                                                anchor.setRow1(28);
-                                                anchor.setCol1(1);
+                                    if (modInput != null) {
+                                        workbook = WorkbookFactory.create(modInput);
+                                        for (int i = 0, l = urls.size(); i < l; i++) {
+                                            try {
+                                                CreationHelper helper = workbook.getCreationHelper();
+                                                Sheet sheet = workbook.getSheetAt(0);
+                                                Drawing<?> drawing = sheet.createDrawingPatriarch();
+                                                ClientAnchor anchor = helper.createClientAnchor();
+
+                                                if (i == 0) {
+                                                    anchor.setRow1(0);
+                                                    anchor.setCol1(0);
+                                                } else {
+                                                    anchor.setRow1(28);
+                                                    anchor.setCol1(1);
+                                                }
+
+                                                //获取文件流
+                                                byte[] bytes = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(urls.get(i)));
+
+                                                //压缩文件大小
+                                                byte[] byteNew = FileUtils.compressImage(bytes);
+
+                                                //创建图片
+                                                Picture picture = drawing.createPicture(anchor, workbook.addPicture(byteNew, Workbook.PICTURE_TYPE_PNG));
+                                                picture.resize();
+
+                                                //图片定位
+                                                FileUtils.imageOrientation(sheet, anchor, i == 1 ? new DataVO(1, 28) : new DataVO(0, 0));
+
+                                                //定位其它信息
+                                                //文字说明
+                                                sheet.getRow(i == 0 ? 1 : 29).getCell(i == 0 ? 5 : 0).setCellValue(file.getTextContent());
+                                                //照片号
+                                                sheet.getRow(i == 0 ? 11 : 39).getCell(i == 0 ? 5 : 0).setCellValue(file.getPhotoCode());
+                                                //底片号
+                                                sheet.getRow(i == 0 ? 17 : 45).getCell(i == 0 ? 5 : 0).setCellValue(file.getFilmCode());
+                                                //题名
+                                                sheet.getRow(i == 0 ? 23 : 51).getCell(i == 0 ? 0 : 3).setCellValue(file.getTitle());
+                                                //参见号
+                                                sheet.getRow(i == 0 ? 23 : 51).getCell(i == 0 ? 3 : 0).setCellValue(file.getSeeAlsoCode());
+                                                //拍摄时间
+                                                sheet.getRow(i == 0 ? 25 : 53).getCell(i == 0 ? 3 : 0).setCellValue(DateUtil.format(file.getShootingTime(), "yyyy-MM-dd"));
+                                                //拍摄者
+                                                sheet.getRow(i == 0 ? 27 : 55).getCell(i == 0 ? 3 : 0).setCellValue(file.getShootingUser());
+
+                                            } catch (Exception e) {
+                                                e.printStackTrace();
                                             }
-
-                                            //获取文件流
-                                            byte[] bytes = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(urls.get(i)));
-
-                                            //压缩文件大小
-                                            byte[] byteNew = FileUtils.compressImage(bytes);
-
-                                            //创建图片
-                                            Picture picture = drawing.createPicture(anchor, workbook.addPicture(byteNew, Workbook.PICTURE_TYPE_PNG));
-                                            picture.resize();
-
-                                            //图片定位
-                                            FileUtils.imageOrientation(sheet, anchor, i == 1 ? new DataVO(1, 28) : new DataVO(0, 0));
-
-                                            //定位其它信息
-                                            //文字说明
-                                            sheet.getRow(i == 0 ? 1 : 29).getCell(i == 0 ? 5 : 0).setCellValue(file.getTextContent());
-                                            //照片号
-                                            sheet.getRow(i == 0 ? 11 : 39).getCell(i == 0 ? 5 : 0).setCellValue(file.getPhotoCode());
-                                            //底片号
-                                            sheet.getRow(i == 0 ? 17 : 45).getCell(i == 0 ? 5 : 0).setCellValue(file.getFilmCode());
-                                            //题名
-                                            sheet.getRow(i == 0 ? 23 : 51).getCell(i == 0 ? 0 : 3).setCellValue(file.getTitle());
-                                            //参见号
-                                            sheet.getRow(i == 0 ? 23 : 51).getCell(i == 0 ? 3 : 0).setCellValue(file.getSeeAlsoCode());
-                                            //拍摄时间
-                                            sheet.getRow(i == 0 ? 25 : 53).getCell(i == 0 ? 3 : 0).setCellValue(DateUtil.format(file.getShootingTime(), "yyyy-MM-dd"));
-                                            //拍摄者
-                                            sheet.getRow(i == 0 ? 27 : 55).getCell(i == 0 ? 3 : 0).setCellValue(file.getShootingUser());
-
-                                        } catch (Exception e) {
-                                            e.printStackTrace();
                                         }
-                                    }
 
-                                    String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
-                                    outputStream = new FileOutputStream(locationFile);
-                                    //记录文件删除
-                                    removeList.add(locationFile);
-                                    //生成一份新的excel
-                                    workbook.write(outputStream);
-                                    //将excel转PDF
-                                    File excelFile = new File(locationFile);
-                                    excelFileInput = new FileInputStream(excelFile);
-                                    MultipartFile files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
-                                    NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
-                                    if (bladeFile != null) {
-                                        pdfFileList.add(bladeFile.getPdfUrl());
+                                        String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
+                                        outputStream = new FileOutputStream(locationFile);
+                                        //记录文件删除
+                                        removeList.add(locationFile);
+                                        //生成一份新的excel
+                                        workbook.write(outputStream);
+                                        //将excel转PDF
+                                        File excelFile = new File(locationFile);
+                                        excelFileInput = new FileInputStream(excelFile);
+                                        MultipartFile files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
+                                        NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
+                                        if (bladeFile != null) {
+                                            pdfFileList.add(bladeFile.getPdfUrl());
+                                        }
                                     }
-
                                 } catch (Exception e) {
                                     e.printStackTrace();
                                 } finally {

+ 1 - 1
blade-service/blade-business/src/main/java/org/springblade/business/utils/FileUtils.java

@@ -209,7 +209,7 @@ public class FileUtils {
      */
     public static void imageOrientation(Sheet sheet, ClientAnchor anchor, DataVO dataVO) {
         // 设置图片距左边和上边的偏移量
-        anchor.setDx1(Units.pixelToEMU(-90));
+        anchor.setDx1(Units.pixelToEMU(5));
         anchor.setDy1(Units.pixelToEMU(5));
         // 设置图片右下角所在单元格的行列号与左上角一致
         anchor.setCol2(anchor.getCol1());

+ 85 - 12
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeContractController.java

@@ -49,6 +49,7 @@ import java.net.URLEncoder;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.List;
@@ -280,6 +281,12 @@ public class WbsTreeContractController extends BladeController {
         return R.data(list);
     }
 
+    /**
+     * 客户端-下载元素表对应的excel模板
+     *
+     * @author liuyc
+     * @date 2023年8月30日15:44:55
+     */
     @SneakyThrows
     @GetMapping("/download-excel")
     @ApiOperationSupport(order = 13)
@@ -355,7 +362,7 @@ public class WbsTreeContractController extends BladeController {
                 try (ServletOutputStream outputStream = response.getOutputStream();
                      ByteArrayOutputStream byteArrayOutputStreamResult = new ByteArrayOutputStream()) {
                     //设置响应头
-                    response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(tab.getFullName(), "UTF-8") + ".xlsx");
+                    response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(ObjectUtil.isNotEmpty(tab.getFullName()) ? tab.getFullName() : tab.getNodeName(), "UTF-8") + ".xlsx");
                     response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                     poiWorkbook.write(byteArrayOutputStreamResult);
                     byte[] excelBytesResult = byteArrayOutputStreamResult.toByteArray();
@@ -439,6 +446,12 @@ public class WbsTreeContractController extends BladeController {
         cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
     }
 
+    /**
+     * 客户端-导入excel数据到对应元素表中
+     *
+     * @author liuyc
+     * @date 2023年8月29日
+     */
     @PostMapping("/import-excel")
     @ApiOperationSupport(order = 14)
     @ApiOperation(value = "客户端-导入excel数据到对应元素表中", notes = "传入表的pKeyId、excel文件file")
@@ -456,6 +469,7 @@ public class WbsTreeContractController extends BladeController {
         String doubleSlashRegex_XG = ".*\\/[^\\/]*\\/.*"; //匹配包含两个斜杠且不相邻的字符串
         String dateFormatRegex_yyyyMdd = "\\d{4}/\\d{1,2}/\\d{1,2}"; //yyyy/M/dd格式
         String dateFormatRegex_yyyyMMdd = "\\d{4}/\\d{2}/\\d{2}";   //yyyy/MM/dd格式
+        String dateFormatRegex_chinese = "(\\d{4}年\\d{1,2}月\\d{1,2}日|\\d{4}年\\d{2}月\\d{2}日)"; //“2023年1月1日、2023年01月01日”这两种格式
         SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy/M/dd");
         SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
 
@@ -490,12 +504,16 @@ public class WbsTreeContractController extends BladeController {
                 for (int j = 0; j < tdElements1.size(); j++) {
                     Element td1 = tdElements1.get(j);
                     Element td2 = tdElements2.get(j);
-                    //String x1 = getX1Attribute(td1);
-                    //String y1 = getY1Attribute(td1);
                     String keyName = getKeyNameFromChildElement(td1);
                     if (StringUtils.isNotEmpty(keyName)) {
                         String divValue = td2.text(); //获取文本值
                         if (StringUtils.isNotEmpty(divValue)) {
+                            if (parseDateRange(divValue).size() == 2) {
+                                //判断范围日期
+                                List<String> dateArr = parseDateRange(divValue);
+                                stringStringMap.put(keyName, dateArr);
+                                continue;
+                            }
                             //判断是否存在两个斜杠,且不在一起,那么视为日期格式
                             Pattern pattern_XG = Pattern.compile(doubleSlashRegex_XG);
                             Matcher matcher_XG = pattern_XG.matcher(divValue);
@@ -512,8 +530,16 @@ public class WbsTreeContractController extends BladeController {
                                     Date date = inputDateFormat.parse(divValue);
                                     divValue = outputDateFormat.format(date);
                                 }
+
+                            } else if (divValue.contains("年") && divValue.contains("月") && divValue.contains("日")) {
+                                //判断如:“2023年1月1日、2023年01月01日”这两种格式
+                                Pattern pattern_chinese = Pattern.compile(dateFormatRegex_chinese);
+                                Matcher matcher_chinese = pattern_chinese.matcher(divValue);
+                                if (matcher_chinese.matches()) {
+                                    Date date = outputDateFormat.parse(divValue);
+                                    divValue = outputDateFormat.format(date);
+                                }
                             }
-                            //String mapKey = keyName + "***" + x1 + "_" + y1;
                             stringStringMap.put(keyName, divValue);
                         }
                     }
@@ -552,6 +578,53 @@ public class WbsTreeContractController extends BladeController {
         return R.data(null, "没有获取到excel中的数据");
     }
 
+    /**
+     * 判断日期范围格式数据,以下12种格式
+     * 2023-01-01-2023-01-30 或 2023-01-01~2023-01-30
+     * 2023-1-1-2023-1-30 或 2023-1-1~2023-1-30
+     * 2023/01/01-2023/01/30 或 2023/01/01~2023/01/30
+     * 2023/1/1-2023/1/30 或 2023/1/1~2023/1/30
+     * 2023年01月01日-2023年01月30日 或 2023年01月01日~2023年01月30日
+     * 2023年1月1日-2023年1月30日 或 2023年1月1日~2023年01月30日
+     *
+     * @param inputDateStr
+     * @return
+     * @throws ParseException
+     */
+    public static List<String> parseDateRange(String inputDateStr) throws ParseException {
+        String[] patterns = {
+                "(\\d{4}[年\\/-]\\d{1,2}[月\\/-]\\d{1,2}[日]?)[-~](\\d{4}[年\\/-]\\d{1,2}[月\\/-]\\d{1,2}[日]?)"
+        };
+        for (String pattern : patterns) {
+            Pattern regex = Pattern.compile(pattern);
+            Matcher matcher = regex.matcher(inputDateStr);
+            if (matcher.find()) {
+                String startDateStr = matcher.group(1);
+                String endDateStr = matcher.group(2);
+                boolean var1 = startDateStr.contains("年");
+                boolean var2 = startDateStr.contains("-");
+                boolean var3 = startDateStr.contains("/");
+                SimpleDateFormat inputDateFormat = null;
+                SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
+                if (var1) {
+                    inputDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
+                } else if (var2) {
+                    inputDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+                } else if (var3) {
+                    inputDateFormat = new SimpleDateFormat("yyyy/MM/dd");
+                }
+                if (inputDateFormat != null) {
+                    Date startDate = inputDateFormat.parse(startDateStr);
+                    Date endDate = inputDateFormat.parse(endDateStr);
+                    String resultStartDateStr = outputDateFormat.format(startDate);
+                    String resultEndDateStr = outputDateFormat.format(endDate);
+                    return Arrays.asList(resultStartDateStr, resultEndDateStr);
+                }
+            }
+        }
+        return new ArrayList<>();
+    }
+
     private static boolean deleteFolder(Path folderPath) throws IOException {
         if (Files.exists(folderPath)) {
             Files.walk(folderPath)
@@ -574,14 +647,6 @@ public class WbsTreeContractController extends BladeController {
         return false;
     }
 
-    private static String getX1Attribute(Element element) {
-        return element.select("[x1]").attr("x1");
-    }
-
-    private static String getY1Attribute(Element element) {
-        return element.select("[y1]").attr("y1");
-    }
-
     private static String getKeyNameFromChildElement(Element element) {
         //TODO Element UI的时间标签待补全
         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"};
@@ -608,6 +673,14 @@ public class WbsTreeContractController extends BladeController {
         }
     }
 
+    /**
+     * 懒加载获取合同段隐蔽工程节点树
+     *
+     * @param contractId
+     * @param parentId
+     * @author liuyc
+     * @date 2023年8月30日15:44:28
+     */
     @PostMapping("/getConcealedWorksNodeTree")
     @ApiOperationSupport(order = 15)
     @ApiOperation(value = "懒加载获取合同段隐蔽工程节点树", notes = "传入合同段id、父级id")