白蚁-日志导出

master
yangzhe123 2025-08-28 14:57:04 +08:00
parent b7fff4283c
commit 54474b63de
4 changed files with 29 additions and 12 deletions

View File

@ -77,7 +77,7 @@ public class ByLogController extends AbstractCommonFileController {
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
ByLog byId = byLogService.getById(id);
if(Objects.isNull(byId)){
throw new RuntimeException("该日志不存在");
throw new IllegalArgumentException("该日志不存在");
}
//先删除细节
LambdaQueryWrapper<ByLogDetail> queryWrapper = new LambdaQueryWrapper<>();

View File

@ -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> 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<ByPlanDetail> queryWrapperDetail = new LambdaQueryWrapper<>();

View File

@ -0,0 +1,11 @@
package com.gunshi.project.hsz.entity.dto;
import lombok.Data;
import java.util.List;
@Data
public class ExportCommonDto {
private List<Long> ids;
}

View File

@ -40,7 +40,7 @@ public class ByLogService extends ServiceImpl<ByLogMapper, ByLog> {
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<ByLogDetail> byLogDetails = dto.getDetails();
@ -134,8 +134,9 @@ public class ByLogService extends ServiceImpl<ByLogMapper, ByLog> {
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<ByLogMapper, ByLog> {
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<ByLogMapper, ByLog> {
"防治部位", "防治点", "防治人员", "防治方法", "防治效果"
};
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<ByLogMapper, ByLog> {
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<ByLogMapper, ByLog> {
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++) {