diff --git a/src/main/java/com/gunshi/project/hsz/controller/ByLogController.java b/src/main/java/com/gunshi/project/hsz/controller/ByLogController.java index d3078a4..7fbafe2 100644 --- a/src/main/java/com/gunshi/project/hsz/controller/ByLogController.java +++ b/src/main/java/com/gunshi/project/hsz/controller/ByLogController.java @@ -77,7 +77,7 @@ public class ByLogController extends AbstractCommonFileController { public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { ByLog byId = byLogService.getById(id); if(Objects.isNull(byId)){ - throw new RuntimeException("该日志不存在"); + throw new IllegalArgumentException("该日志不存在"); } //先删除细节 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); diff --git a/src/main/java/com/gunshi/project/hsz/controller/ByPlanController.java b/src/main/java/com/gunshi/project/hsz/controller/ByPlanController.java index cdc8b6d..69882f5 100644 --- a/src/main/java/com/gunshi/project/hsz/controller/ByPlanController.java +++ b/src/main/java/com/gunshi/project/hsz/controller/ByPlanController.java @@ -55,7 +55,7 @@ public class ByPlanController extends AbstractCommonFileController{ queryWrapper.eq(ByPlan::getPlanId, dto.getPlanId()); ByPlan one = byPlanService.getOne(queryWrapper); if(Objects.nonNull(one)){ - throw new RuntimeException("该计划编号已存在"); + throw new IllegalArgumentException("该计划编号已存在"); } dto.setId(IdWorker.getId()); List byPlanDetail = dto.getByPlanDetail(); @@ -90,7 +90,7 @@ public class ByPlanController extends AbstractCommonFileController{ queryWrapper.eq(ByPlan::getId, id); ByPlan one = byPlanService.getOne(queryWrapper); if(Objects.isNull(one)){ - throw new RuntimeException("该计划不存在"); + throw new IllegalArgumentException("该计划不存在"); } String planId = one.getPlanId(); LambdaQueryWrapper queryWrapperDetail = new LambdaQueryWrapper<>(); diff --git a/src/main/java/com/gunshi/project/hsz/entity/dto/ExportCommonDto.java b/src/main/java/com/gunshi/project/hsz/entity/dto/ExportCommonDto.java new file mode 100644 index 0000000..d1ad3ce --- /dev/null +++ b/src/main/java/com/gunshi/project/hsz/entity/dto/ExportCommonDto.java @@ -0,0 +1,11 @@ +package com.gunshi.project.hsz.entity.dto; + +import lombok.Data; + +import java.util.List; + +@Data +public class ExportCommonDto { + + private List ids; +} diff --git a/src/main/java/com/gunshi/project/hsz/service/ByLogService.java b/src/main/java/com/gunshi/project/hsz/service/ByLogService.java index 86326f4..12c93a4 100644 --- a/src/main/java/com/gunshi/project/hsz/service/ByLogService.java +++ b/src/main/java/com/gunshi/project/hsz/service/ByLogService.java @@ -40,7 +40,7 @@ public class ByLogService extends ServiceImpl { public boolean update(ByLog dto) { ByLog byId = getById(dto.getId()); if(Objects.isNull(byId)){ - throw new RuntimeException("该日志不存在,请检查"); + throw new IllegalArgumentException("该日志不存在,请检查"); } boolean save = updateById(dto); List byLogDetails = dto.getDetails(); @@ -134,8 +134,9 @@ public class ByLogService extends ServiceImpl { private StyleGroup createAllStyles(Workbook workbook) { // 1. 基础数据样式 CellStyle dataStyle = workbook.createCellStyle(); - dataStyle.setAlignment(HorizontalAlignment.CENTER); - dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); + dataStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中 + dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); //垂直剧中 + //为单元格添加 上 下 左 右 细边框 dataStyle.setBorderBottom(BorderStyle.THIN); dataStyle.setBorderTop(BorderStyle.THIN); dataStyle.setBorderLeft(BorderStyle.THIN); @@ -145,9 +146,10 @@ public class ByLogService extends ServiceImpl { CellStyle headerStyle = workbook.createCellStyle(); headerStyle.cloneStyleFrom(dataStyle); Font headerFont = workbook.createFont(); - headerFont.setBold(true); - headerFont.setFontHeightInPoints((short) 12); + headerFont.setBold(true);//字体加粗 + headerFont.setFontHeightInPoints((short) 12); //字体大小 headerStyle.setFont(headerFont); + //表头背景颜色 headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); @@ -178,9 +180,9 @@ public class ByLogService extends ServiceImpl { "防治部位", "防治点", "防治人员", "防治方法", "防治效果" }; for (int i = 0; i < headers.length; i++) { - Cell cell = headerRow.createCell(i); - cell.setCellValue(headers[i]); - cell.setCellStyle(headerStyle); + Cell cell = headerRow.createCell(i);//创建表头单元格 + cell.setCellValue(headers[i]);//单元格复制 + cell.setCellStyle(headerStyle);//应用表头样式 } } @@ -188,14 +190,17 @@ public class ByLogService extends ServiceImpl { int currentRow = 1; int logSerialNumber = 1; // 序号 - for (ByLog log : dataList) { + for (ByLog log : dataList) {//遍历日志信息 + //获取当前日志细节(用于后续单元格合并) int detailCount = log.getDetails() != null ? log.getDetails().size() : 0; + // 计算需要合并的单元格行数 int rowSpan = Math.max(detailCount, 1); Row row = sheet.createRow(currentRow); // 1. 序号 Cell cell0 = row.createCell(0); cell0.setCellValue(logSerialNumber); cell0.setCellStyle(styles.dataStyle); + //判断是否需要合并单元格 if (rowSpan > 1) sheet.addMergedRegion(new CellRangeAddress(currentRow, currentRow + rowSpan - 1, 0, 0)); // 2. 日志名称 @@ -243,6 +248,7 @@ public class ByLogService extends ServiceImpl { cell5.setCellStyle(styles.dataStyle); if (rowSpan > 1) sheet.addMergedRegion(new CellRangeAddress(currentRow, currentRow + rowSpan - 1, 5, 5)); + //填充日志详细数据 if (detailCount > 0) { fillDetailInfo(row, log.getDetails().get(0), styles.detailStyle); for (int i = 1; i < detailCount; i++) {