cn.idev.excel

This commit is contained in:
2025-12-19 16:21:56 +08:00
parent c480bda112
commit c0dfe36b59
6 changed files with 46 additions and 36 deletions

View File

@ -74,6 +74,7 @@ public class ExcelUtil {
return listener.getExcelResult();
}
/**
* 导出excel
*
@ -92,6 +93,7 @@ public class ExcelUtil {
}
}
/**
* 导出excel
*
@ -174,6 +176,7 @@ public class ExcelUtil {
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, OutputStream os, List<DropDownOptions> options) {
exportExcel(list, sheetName, clazz, false, os, options);
}
/**
* 导出excel
@ -187,13 +190,13 @@ public class ExcelUtil {
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge,
OutputStream os, List<DropDownOptions> options) {
ExcelWriterSheetBuilder builder = FastExcel.write(os, clazz)
.autoCloseStream(false)
// 自动适配
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
// 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert())
.registerWriteHandler(new DataWriteHandler(clazz))
.sheet(sheetName);
.autoCloseStream(false)
// 自动适配
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
// 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert())
.registerWriteHandler(new DataWriteHandler(clazz))
.sheet(sheetName);
if (merge) {
// 合并处理器
builder.registerWriteHandler(new CellMergeStrategy(list, true));
@ -203,6 +206,7 @@ public class ExcelUtil {
builder.doWrite(list);
}
/**
* 单表多数据模板导出 模板格式为 {.属性}
*
@ -238,12 +242,12 @@ public class ExcelUtil {
public static <T> void exportTemplate(List<T> data, String templatePath, OutputStream os) {
ClassPathResource templateResource = new ClassPathResource(templatePath);
ExcelWriter excelWriter = FastExcel.write(os)
.withTemplate(templateResource.getStream())
.autoCloseStream(false)
// 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert())
.registerWriteHandler(new DataWriteHandler(data.get(0).getClass()))
.build();
.withTemplate(templateResource.getStream())
.autoCloseStream(false)
// 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert())
.registerWriteHandler(new DataWriteHandler(data.get(0).getClass()))
.build();
WriteSheet writeSheet = FastExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
// 单表多数据导出 模板格式为 {.属性}
@ -311,11 +315,11 @@ public class ExcelUtil {
public static void exportTemplateMultiList(Map<String, Object> data, String templatePath, OutputStream os) {
ClassPathResource templateResource = new ClassPathResource(templatePath);
ExcelWriter excelWriter = FastExcel.write(os)
.withTemplate(templateResource.getStream())
.autoCloseStream(false)
// 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert())
.build();
.withTemplate(templateResource.getStream())
.autoCloseStream(false)
// 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert())
.build();
WriteSheet writeSheet = FastExcel.writerSheet().build();
for (Map.Entry<String, Object> map : data.entrySet()) {
// 设置列表后续还有数据
@ -342,11 +346,11 @@ public class ExcelUtil {
public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String templatePath, OutputStream os) {
ClassPathResource templateResource = new ClassPathResource(templatePath);
ExcelWriter excelWriter = FastExcel.write(os)
.withTemplate(templateResource.getStream())
.autoCloseStream(false)
// 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert())
.build();
.withTemplate(templateResource.getStream())
.autoCloseStream(false)
// 大数值自动转换 防止失真
.registerConverter(new ExcelBigNumberConvert())
.build();
for (int i = 0; i < data.size(); i++) {
WriteSheet writeSheet = FastExcel.writerSheet(i).build();
for (Map.Entry<String, Object> map : data.get(i).entrySet()) {

View File

@ -41,6 +41,7 @@ public class DeviceRepairRecordsController extends BaseController {
private final IDeviceRepairRecordsService deviceRepairRecordsService;
/**
* 查询设备维修记录列表
*/
@ -52,6 +53,7 @@ public class DeviceRepairRecordsController extends BaseController {
return deviceRepairRecordsService.queryPageList(criteria, page);
}
/**
* 导出设备维修记录列表
*/
@ -63,6 +65,7 @@ public class DeviceRepairRecordsController extends BaseController {
ExcelUtil.exportExcel(list, "设备维修记录", DeviceRepairRecordsVo.class, response);
}
/**
* 获取设备维修记录详细信息
*
@ -75,6 +78,7 @@ public class DeviceRepairRecordsController extends BaseController {
return R.ok(deviceRepairRecordsService.queryById(recordId));
}
/**
* 新增设备维修记录
*/
@ -86,6 +90,7 @@ public class DeviceRepairRecordsController extends BaseController {
return toAjax(deviceRepairRecordsService.insertByBo(bo));
}
/**
* 修改设备维修记录
*/
@ -109,4 +114,5 @@ public class DeviceRepairRecordsController extends BaseController {
@PathVariable Long[] recordIds) {
return toAjax(deviceRepairRecordsService.deleteWithValidByIds(List.of(recordIds), true));
}
}

View File

@ -108,7 +108,7 @@ public class DeviceFenceAccessRecordVo implements Serializable {
/**
* 记录创建时间
*/
@ExcelProperty(value = "记录创建时间")
// @ExcelProperty(value = "记录创建时间")
private Date createTime;
}

View File

@ -1,15 +1,11 @@
package com.fuyuanshen.equipment.domain.vo;
import java.util.Date;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
@ -56,8 +52,8 @@ public class DeviceRepairRecordsVo extends TenantEntity implements Serializable
*/
@ExcelProperty(value = "维修时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ColumnWidth(20)
private String repairTime;
@ColumnWidth(value = 20)
private Date repairTime;
/**
* 损坏部位

View File

@ -32,8 +32,8 @@ public interface IDeviceRepairRecordsService extends IService<DeviceRepairRecord
/**
* 分页查询设备维修记录列表
*
* @param bo 查询条件
* @param pageQuery 分页参数
* @param criteria 查询条件
* @param page 分页参数
* @return 设备维修记录分页列表
*/
TableDataInfo<DeviceRepairRecordsVo> queryPageList(DeviceRepairRecordsQueryCriteria criteria, Page<DeviceRepairRecords> page);
@ -41,7 +41,7 @@ public interface IDeviceRepairRecordsService extends IService<DeviceRepairRecord
/**
* 查询符合条件的设备维修记录列表
*
* @param bo 查询条件
* @param criteria 查询条件
* @return 设备维修记录列表
*/
List<DeviceRepairRecordsVo> queryList(DeviceRepairRecordsQueryCriteria criteria);
@ -70,4 +70,5 @@ public interface IDeviceRepairRecordsService extends IService<DeviceRepairRecord
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}

View File

@ -52,6 +52,7 @@ public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairReco
private final ISysOssService ossService;
private final FileHashUtil fileHashUtil;
/**
* 查询设备维修记录
*
@ -76,6 +77,7 @@ public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairReco
return vo;
}
/**
* 分页查询设备维修记录列表
*
@ -98,6 +100,7 @@ public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairReco
return new TableDataInfo<DeviceRepairRecordsVo>(deviceRepairRecordsIPage.getRecords(), deviceRepairRecordsIPage.getTotal());
}
/**
* 查询符合条件的设备维修记录列表
*