Browse Source

excel模板导出和数据导出

大数据与最优化研究所 1 week ago
parent
commit
4d92aafe57

+ 0 - 1
src/main/java/com/xjrsoft/module/attendance/controller/AttendanceStatisticsController.java

@@ -146,7 +146,6 @@ public class AttendanceStatisticsController {
     @SaCheckPermission("attendancestatistics:detail")
     public RT<Boolean> refreshStatistics(@Valid @RequestBody RefreshStatisticsDto dto){
         Boolean aBoolean = attendanceStatisticsService.refreshRecord(dto.getId());
-
         return RT.ok(aBoolean);
     }
 

+ 0 - 1
src/main/java/com/xjrsoft/module/attendance/service/impl/AttendanceStatisticsServiceImpl.java

@@ -475,7 +475,6 @@ public class AttendanceStatisticsServiceImpl extends MPJBaseServiceImpl<Attendan
                     weekList.add(daysJson.get("week").getAsString());
                 }
             }
-
             dataList.add(data);
         }
 

+ 38 - 17
src/main/java/com/xjrsoft/module/form/controller/FormExecuteController.java

@@ -235,14 +235,14 @@ public class FormExecuteController {
         return R.ok(formExecuteService.workFlowInfo(dto));
     }
 
-//    @GetMapping(value = "/export")
-//    @ApiOperation(value = "导出")
-//    @XjrLog(value = "导出表单数据")
-//    public ResponseEntity<byte[]> export(@Valid FormExecuteListDto dto) throws IOException {
-    @PostMapping(value = "/export")
+    @GetMapping(value = "/export")
     @ApiOperation(value = "导出")
     @XjrLog(value = "导出表单数据")
-    public ResponseEntity<byte[]> export(@Valid @RequestBody FormExecuteListDto dto) throws IOException {
+    public ResponseEntity<byte[]> export(@Valid FormExecuteListDto dto) throws IOException {
+//    @PostMapping(value = "/export")
+//    @ApiOperation(value = "导出")
+//    @XjrLog(value = "导出表单数据")
+//    public ResponseEntity<byte[]> export(@Valid @RequestBody FormExecuteListDto dto) throws IOException {
         FormRelease formRelease = formReleaseService.getById(dto.getReleaseId());
         FormReleaseConfig formReleaseConfig = JSONUtil.toBean(formRelease.getConfigJson(), FormReleaseConfig.class);
         // 配置excel第一行字段名
@@ -258,12 +258,13 @@ public class FormExecuteController {
         Sheet sheet = workbook.createSheet(sheetName);
 
         // 设置第每列的列宽度
-//        for (ImportConfig importConfig : importConfigs) {
-//            if(importConfig.getWidth() == 0){
-//                sheet.autoSizeColumn(importConfig.getSortCode());
-//            }
-//            sheet.setColumnWidth(importConfig.getSortCode(), 100);
-//        }
+        for (ImportConfig importConfig : importConfigs) {
+            if(importConfig.getWidth() == 0){
+                sheet.autoSizeColumn(importConfig.getSortCode());
+            }else {
+                sheet.setColumnWidth(importConfig.getSortCode(), importConfig.getWidth() * 256);
+            }
+        }
 
         // 表头
         createHead(workbook, sheet, importConfigs);
@@ -276,7 +277,6 @@ public class FormExecuteController {
             font.setBold(false);// 设置为粗体
             font.setFontName("宋体");
             font.setFontHeightInPoints((short)12);
-            font.setColor(Font.COLOR_RED);
             CellStyle cellStyle = workbook.createCellStyle();
             cellStyle.setFont(font); // 将字体应用到样式
 //            cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
@@ -286,7 +286,6 @@ public class FormExecuteController {
                 Row dataRow = sheet.createRow(dataRowNumber);
                 for (int i = 0; i < importConfigs.size(); i++) {
                     ImportConfig importConfig = importConfigs.get(i);
-                    sheet.autoSizeColumn(importConfig.getSortCode());
                     ColumnConfig columnConfig = columnConfigMap.get(importConfig.getFieldName());
                     Object value = entity.get(importConfig.getFieldName());
                     String componentType = columnConfig.getComponentType();
@@ -320,6 +319,9 @@ public class FormExecuteController {
                 }
                 dataRowNumber ++;
             }
+        }else {
+            // 提示必填
+            createCautionHead(workbook, sheet);
         }
 
         //写入文件
@@ -401,14 +403,13 @@ public class FormExecuteController {
         normalCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
         normalCellStyle.setAlignment(HorizontalAlignment.CENTER);
 
-
         // 必填样式
         CellStyle requiredCellStyle = workbook.createCellStyle();
         requiredCellStyle.setFont(font); // 将字体应用到样式
         requiredCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
         requiredCellStyle.setAlignment(HorizontalAlignment.CENTER);
-        requiredCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
-        requiredCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        requiredCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());//设置背景颜色
+        requiredCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//设置填充模式
 
         // 所在行
         Row row = sheet.createRow(rowNumber);
@@ -426,6 +427,26 @@ public class FormExecuteController {
         }
     }
 
+    private void createCautionHead(Workbook workbook, Sheet sheet) {
+        int rowNumber = 1;
+        Font font = workbook.createFont();
+        font.setFontName("宋体");
+        font.setFontHeightInPoints((short)12);
+        font.setColor(IndexedColors.RED.getIndex());
+
+        CellStyle cellStyle = workbook.createCellStyle();
+        cellStyle.setFont(font); // 将字体应用到样式
+//        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+//        cellStyle.setAlignment(HorizontalAlignment.CENTER);
+
+        Row row = sheet.createRow(rowNumber);
+        Cell cell = row.createCell(0);
+        String content = "红色背景为必填项,导入时请删除本行。";
+        cell.setCellValue(content);
+        cell.setCellStyle(cellStyle);
+        sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 0, 5));
+    }
+
     @PostMapping("/import")
     @ApiOperation(value = "导入")
     public R importData(@RequestParam String releaseId, @RequestParam MultipartFile file) throws IOException {