班次奶量导出功能修复
This commit is contained in:
parent
84bc894668
commit
29efc43392
@ -33,6 +33,11 @@ public @interface Excel
|
|||||||
*/
|
*/
|
||||||
public String dateFormat() default "";
|
public String dateFormat() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字格式, 如: 0.00
|
||||||
|
*/
|
||||||
|
public String numFormat() default ""; // 新增数字格式属性
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果是字典类型,请设置字典的type值 (如: sys_user_sex)
|
* 如果是字典类型,请设置字典的type值 (如: sys_user_sex)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1142,7 +1142,6 @@ public class ExcelUtil<T>
|
|||||||
sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column));
|
sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
|
|
||||||
|
|
||||||
// 用于读取对象中的属性
|
// 用于读取对象中的属性
|
||||||
Object value = getTargetValue(vo, field, attr);
|
Object value = getTargetValue(vo, field, attr);
|
||||||
@ -1150,14 +1149,33 @@ public class ExcelUtil<T>
|
|||||||
String readConverterExp = attr.readConverterExp();
|
String readConverterExp = attr.readConverterExp();
|
||||||
String separator = attr.separator();
|
String separator = attr.separator();
|
||||||
String dictType = attr.dictType();
|
String dictType = attr.dictType();
|
||||||
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
String numFormat = attr.numFormat(); // 获取数字格式
|
||||||
|
|
||||||
|
// 创建单元格样式
|
||||||
|
CellStyle cellStyle = wb.createCellStyle();
|
||||||
|
cellStyle.cloneStyleFrom(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}",
|
||||||
|
attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
|
||||||
|
|
||||||
|
// 处理日期格式
|
||||||
|
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value) && value instanceof Date)
|
||||||
{
|
{
|
||||||
cell.getCellStyle().setDataFormat(this.wb.getCreationHelper().createDataFormat().getFormat(dateFormat));
|
DataFormat format = wb.createDataFormat();
|
||||||
cell.setCellValue(parseDateToStr(dateFormat, value));
|
cellStyle.setDataFormat(format.getFormat(dateFormat));
|
||||||
|
cell.setCellValue((Date) value);
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
|
}
|
||||||
|
// 处理数字格式
|
||||||
|
else if (StringUtils.isNotEmpty(numFormat) && StringUtils.isNotNull(value) && value instanceof Number)
|
||||||
|
{
|
||||||
|
DataFormat format = wb.createDataFormat();
|
||||||
|
cellStyle.setDataFormat(format.getFormat(numFormat));
|
||||||
|
cell.setCellValue(((Number) value).doubleValue());
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
||||||
{
|
{
|
||||||
cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
|
cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value))
|
else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value))
|
||||||
{
|
{
|
||||||
@ -1167,20 +1185,32 @@ public class ExcelUtil<T>
|
|||||||
sysDictMap.put(dictType + value, lable);
|
sysDictMap.put(dictType + value, lable);
|
||||||
}
|
}
|
||||||
cell.setCellValue(sysDictMap.get(dictType + value));
|
cell.setCellValue(sysDictMap.get(dictType + value));
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
}
|
}
|
||||||
else if (value instanceof BigDecimal && -1 != attr.scale())
|
else if (value instanceof BigDecimal && -1 != attr.scale())
|
||||||
{
|
{
|
||||||
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue());
|
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue());
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
}
|
}
|
||||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||||
{
|
{
|
||||||
cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
|
cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 设置列类型
|
// 设置列类型
|
||||||
setCellVo(value, attr, cell);
|
setCellVo(value, attr, cell);
|
||||||
|
// 对于日期类型,确保应用日期格式
|
||||||
|
if (value instanceof Date && StringUtils.isNotEmpty(dateFormat)) {
|
||||||
|
DataFormat format = wb.createDataFormat();
|
||||||
|
CellStyle dateStyle = wb.createCellStyle();
|
||||||
|
dateStyle.cloneStyleFrom(cell.getCellStyle());
|
||||||
|
dateStyle.setDataFormat(format.getFormat(dateFormat));
|
||||||
|
cell.setCellStyle(dateStyle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addStatisticsData(column, Convert.toStr(value), attr);
|
addStatisticsData(column, Convert.toStr(value), attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1254,7 +1284,7 @@ public class ExcelUtil<T>
|
|||||||
DataValidationHelper helper = sheet.getDataValidationHelper();
|
DataValidationHelper helper = sheet.getDataValidationHelper();
|
||||||
// 加载下拉列表内容
|
// 加载下拉列表内容
|
||||||
DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data");
|
DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data");
|
||||||
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
||||||
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
||||||
// 数据有效性对象
|
// 数据有效性对象
|
||||||
DataValidation dataValidation = helper.createValidation(constraint, regions);
|
DataValidation dataValidation = helper.createValidation(constraint, regions);
|
||||||
|
|||||||
@ -58,10 +58,12 @@ public class NpMilkProdClassesController extends BaseController {
|
|||||||
public void export(HttpServletResponse response,
|
public void export(HttpServletResponse response,
|
||||||
@RequestParam(required = false) Date datetimeStart,
|
@RequestParam(required = false) Date datetimeStart,
|
||||||
@RequestParam(required = false) Date datetimeEnd,
|
@RequestParam(required = false) Date datetimeEnd,
|
||||||
@RequestParam(required = false) String manageEarNos,
|
@RequestParam(required = false) String manageEarNo,
|
||||||
@RequestParam(required = false) String factory,
|
@RequestParam(required = false) String factory,
|
||||||
@RequestParam(required = false) Integer classes) {
|
@RequestParam(required = false) Integer classes) {
|
||||||
List<NpMilkProdClasses> list = npMilkProdClassesService.selectNpMilkProdClassesList(datetimeStart, datetimeEnd, manageEarNos, factory, classes);
|
List<NpMilkProdClasses> list = npMilkProdClassesService.selectNpMilkProdClassesList(
|
||||||
|
datetimeStart, datetimeEnd, manageEarNo, factory, classes);
|
||||||
|
|
||||||
ExcelUtil<NpMilkProdClasses> util = new ExcelUtil<>(NpMilkProdClasses.class);
|
ExcelUtil<NpMilkProdClasses> util = new ExcelUtil<>(NpMilkProdClasses.class);
|
||||||
util.exportExcel(response, list, "班次产奶数据");
|
util.exportExcel(response, list, "班次产奶数据");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ public class NpMilkProdClasses implements Serializable {
|
|||||||
private Date updateTime; // 更新时间
|
private Date updateTime; // 更新时间
|
||||||
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
@Excel(name = "日期")
|
@Excel(name = "日期", dateFormat = "yyyy-MM-dd") // 添加日期格式
|
||||||
private Date datetime;
|
private Date datetime;
|
||||||
|
|
||||||
@Excel(name = "管理耳号")
|
@Excel(name = "管理耳号")
|
||||||
@ -33,10 +33,10 @@ public class NpMilkProdClasses implements Serializable {
|
|||||||
@Excel(name = "班次")
|
@Excel(name = "班次")
|
||||||
private Integer classes;
|
private Integer classes;
|
||||||
|
|
||||||
@Excel(name = "班次产奶量")
|
@Excel(name = "班次产奶量", numFormat = "0.00")
|
||||||
private Double milk;
|
private Double milk;
|
||||||
|
|
||||||
@Excel(name = "班次校正奶量")
|
@Excel(name = "班次校正奶量", numFormat = "0.00")
|
||||||
private Double correctedMilk;
|
private Double correctedMilk;
|
||||||
|
|
||||||
private String sheepId;
|
private String sheepId;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user