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