Browse Source

天合修复bug

master
songguoqiang 6 months ago
parent
commit
f308722ace
  1. 88
      win-framework/win-spring-boot-starter-excel/src/main/java/com/win/framework/excel/core/handler/CustomCellWriteHandler.java
  2. 28
      win-framework/win-spring-boot-starter-excel/src/main/java/com/win/framework/excel/core/util/ExcelUtils.java
  3. 3
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/item/vo/ItemImportVO.java
  4. 4
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/vo/ItemAccountsImportExcelVO.java
  5. 3
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/location/vo/LocationExcelVO.java
  6. 1
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/location/vo/LocationImportVO.java
  7. 2
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/locationarea/vo/LocationAreaImportVO.java

88
win-framework/win-spring-boot-starter-excel/src/main/java/com/win/framework/excel/core/handler/CustomCellWriteHandler.java

@ -0,0 +1,88 @@
package com.win.framework.excel.core.handler;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.win.framework.excel.core.annotations.Colour;
import com.win.framework.excel.core.annotations.ExcelValid;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import java.lang.reflect.Field;
import java.util.List;
@Slf4j
public class CustomCellWriteHandler implements CellWriteHandler {
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
if(isHead){
WriteCellData writeCellData = cellDataList.get(0);
WriteCellStyle headWriteCellStyle = writeCellData.getOrCreateStyle();
// 头的策略 样式调整
Field field = head.getField();
if (field.isAnnotationPresent(Colour.class)) {
// 如果是头部 主表数据
headWriteCellStyle.setFillForegroundColor(field.getAnnotation(Colour.class).value().getIndex());
}else {
//头背景 浅绿 子表数据
headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
}
WriteFont headWriteFont = new WriteFont();
// 头字号
headWriteFont.setFontHeightInPoints((short) 14);
// 字体样式
headWriteFont.setFontName("宋体");
headWriteCellStyle.setWriteFont(headWriteFont);
// 自动换行
headWriteCellStyle.setWrapped(true);
// 设置细边框
headWriteCellStyle.setBorderBottom(BorderStyle.THIN);
headWriteCellStyle.setBorderLeft(BorderStyle.THIN);
headWriteCellStyle.setBorderRight(BorderStyle.THIN);
headWriteCellStyle.setBorderTop(BorderStyle.THIN);
// 设置必填项备注消息
if(field.isAnnotationPresent(ExcelValid.class)){
Sheet sheet = writeSheetHolder.getSheet();
// 备注
Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), 0, (short) cell.getColumnIndex()+1, 1));
comment.setString(new XSSFRichTextString(field.getAnnotation(ExcelValid.class).message()));
// 将批注添加到单元格对象中
sheet.getRow(cell.getRowIndex()).getCell(cell.getColumnIndex()).setCellComment(comment);
}
// 设置边框颜色 25灰度
headWriteCellStyle.setBottomBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
headWriteCellStyle.setTopBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
headWriteCellStyle.setLeftBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
headWriteCellStyle.setRightBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
// 水平对齐方式
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// 垂直对齐方式
headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
}else {
for(int i=1;i<cellDataList.size();i++){
WriteCellData writeCellData = cellDataList.get(i);
// 内容的策略 宋体
WriteCellStyle contentStyle = writeCellData.getOrCreateStyle();
// 设置垂直居中
contentStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 设置 水平居中
contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
WriteFont contentWriteFont = new WriteFont();
// 内容字号
contentWriteFont.setFontHeightInPoints((short) 12);
// 字体样式
contentWriteFont.setFontName("宋体");
contentStyle.setWriteFont(contentWriteFont);
}
}
}
}

28
win-framework/win-spring-boot-starter-excel/src/main/java/com/win/framework/excel/core/util/ExcelUtils.java

@ -7,6 +7,7 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.win.framework.excel.core.handler.CustomCellWriteHandler;
import com.win.framework.excel.core.handler.CustomSheetWriteHandler;
import com.win.framework.web.config.WebProperties;
import com.win.framework.web.constant.Constant;
@ -56,6 +57,30 @@ public class ExcelUtils {
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
}
/**
* 将列表以 Excel 响应给前端
*
* @param response 响应
* @param filename 文件名
* @param sheetName Excel sheet
* @param head Excel head
* @param data 数据列表哦
* @param mapDropDown 下拉数据
* @param <T> 泛型保证 head data 类型的一致性
* @throws IOException 写入失败的情况
*/
// public static <T> void write(HttpServletResponse response, String filename, String sheetName, Class<T> head, List<T> data, Map<Integer, String[]> mapDropDown) throws IOException {
// // 输出 Excel
// EasyExcel.write(response.getOutputStream(), head)
// .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理
// .registerWriteHandler(new CustomSheetWriteHandler(mapDropDown))
// .registerWriteHandler(getStyleStrategy()) // 设置excel样式
// .sheet(sheetName).doWrite(data);
// // 设置 header 和 contentType。写在最后的原因是,避免报错时,响应 contentType 已经被修改了
// response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
// response.setContentType("application/vnd.ms-excel;charset=UTF-8");
// }
/**
* 将列表以 Excel 响应给前端
*
@ -73,7 +98,8 @@ public class ExcelUtils {
EasyExcel.write(response.getOutputStream(), head)
.autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理
.registerWriteHandler(new CustomSheetWriteHandler(mapDropDown))
.registerWriteHandler(getStyleStrategy()) // 设置excel样式
// .registerWriteHandler(getStyleStrategy()) // 设置excel样式
.registerWriteHandler(new CustomCellWriteHandler())
.sheet(sheetName).doWrite(data);
// 设置 header 和 contentType。写在最后的原因是,避免报错时,响应 contentType 已经被修改了
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));

3
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/item/vo/ItemImportVO.java

@ -1,6 +1,7 @@
package com.win.module.eam.controller.item.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.win.framework.excel.core.annotations.ExcelValid;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -21,6 +22,7 @@ import java.math.BigDecimal;
public class ItemImportVO {
@ExcelProperty("零件编码")
@ExcelValid(message = "零件编码必填")
private String number;
@ExcelProperty("零件名称")
@ -48,6 +50,7 @@ public class ItemImportVO {
private Integer procurementCycle;
@ExcelProperty("ABC分类")
@ExcelValid(message = "ABC分类必填")
private String classification;
@ExcelProperty("使用地点")

4
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/vo/ItemAccountsImportExcelVO.java

@ -25,16 +25,20 @@ import java.time.LocalDateTime;
public class ItemAccountsImportExcelVO {
@ExcelProperty("备件编号")
@ExcelValid(message = "备件编号必填")
private String itemNumber;
@ExcelProperty("库位编号")
@ExcelValid(message = "库位编号必填")
private String locationNumber;
@ExcelProperty("库存数量")
@ExcelValid(message = "库存数量必填")
private BigDecimal qty;
@ExcelProperty(value = "库存类型", converter = DictConvert.class)
@DictFormat("item_account_location_type") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
@ExcelValid(message = "库存类型必填")
private String type;

3
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/location/vo/LocationExcelVO.java

@ -3,6 +3,7 @@ package com.win.module.eam.controller.location.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.win.framework.excel.core.annotations.DictFormat;
import com.win.framework.excel.core.annotations.ExcelValid;
import com.win.framework.excel.core.convert.DictConvert;
import com.win.module.eam.enums.DictTypeConstants;
import lombok.Data;
@ -17,6 +18,7 @@ public class LocationExcelVO {
@ExcelProperty("库位编号")
@ColumnWidth(value = 20)
@ExcelValid(message = "库位编号必填")
private String number;
@ExcelProperty("库位名称")
@ -25,6 +27,7 @@ public class LocationExcelVO {
@ExcelProperty("库区编号")
@ColumnWidth(value = 20)
@ExcelValid(message = "库区编号必填")
private String areaNumber;
@ExcelProperty("描述")

1
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/location/vo/LocationImportVO.java

@ -33,6 +33,7 @@ public class LocationImportVO {
@ExcelProperty("库区编号")
@ColumnWidth(value = 20)
@ExcelValid(message = "必填")
private String areaNumber;
@ExcelProperty("描述")

2
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/locationarea/vo/LocationAreaImportVO.java

@ -2,6 +2,7 @@ package com.win.module.eam.controller.locationarea.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.win.framework.excel.core.annotations.ExcelValid;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -21,6 +22,7 @@ public class LocationAreaImportVO {
@ExcelProperty("库区编号")
@ColumnWidth(value = 20)
@ExcelValid(message = "库区编号必填")
private String number;
@ExcelProperty("库区名称")

Loading…
Cancel
Save