From a915c14dafebeb823294935755b6646a2ca76ff9 Mon Sep 17 00:00:00 2001 From: zouyu <2723363702@qq.com> Date: 星期六, 04 十一月 2023 17:41:19 +0800 Subject: [PATCH] 参数 --- mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/CustemHandler.java | 80 +++++ mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/EasyExcelUtils.java | 441 +++++++++++++++++++++++++++ mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java | 8 mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ExcelMergeStrategy.java | 85 +++++ mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ResponseResultEnum.java | 28 + mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/converter/LocalDateConverter.java | 43 ++ mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/template/ParamTemplate.java | 55 +++ mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ExcelListener.java | 58 +++ mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/exception/ExcelException.java | 25 + mes-basic/src/main/java/com/chinaztt/mes/basic/enums/FileEnums.java | 3 mes-basic/src/main/java/com/chinaztt/mes/basic/entity/Param.java | 3 mes-basic/src/main/java/com/chinaztt/mes/basic/service/ParamService.java | 2 mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/converter/SaleTypeConverter.java | 48 +++ mes-basic/src/main/java/com/chinaztt/mes/basic/controller/ParamController.java | 58 ++ 14 files changed, 922 insertions(+), 15 deletions(-) diff --git a/mes-basic/src/main/java/com/chinaztt/mes/basic/controller/ParamController.java b/mes-basic/src/main/java/com/chinaztt/mes/basic/controller/ParamController.java index 5c3169a..eec09c0 100644 --- a/mes-basic/src/main/java/com/chinaztt/mes/basic/controller/ParamController.java +++ b/mes-basic/src/main/java/com/chinaztt/mes/basic/controller/ParamController.java @@ -28,6 +28,10 @@ import com.chinaztt.mes.basic.service.ParamService; import com.chinaztt.mes.basic.util.DictUtils; import com.chinaztt.mes.common.util.JsonUtil; +import com.chinaztt.mes.common.util.StringUtils; +import com.chinaztt.mes.common.util.easyexcel.EasyExcelUtils; +import com.chinaztt.mes.common.util.easyexcel.ExcelListener; +import com.chinaztt.mes.common.util.easyexcel.template.ParamTemplate; import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; import com.chinaztt.ztt.admin.api.entity.SysDictItem; import com.chinaztt.ztt.common.core.util.R; @@ -39,6 +43,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -70,12 +75,14 @@ @GetMapping("/page") @PreAuthorize("@pms.hasPermission('technology_param_view','product_workbench')") public R getParamPage(Page page, ParamDTO param) { + List<Map<String,Object>> all = new ArrayList<>(); List<SysDictItem> dict = dictUtils.getDict("technology_param"); - System.out.println(dict); - Page page1 = paramService.page(page, QueryWrapperUtil.gen(param)); + QueryWrapper<Param> gen = QueryWrapperUtil.gen(param); + gen.lambda().eq(Param::getParentId,0L); + Page page1 = paramService.page(page, gen); List records = page1.getRecords(); - List<Map>all = new ArrayList<Map>(); records.forEach(l->{ + System.out.println("涓�绾ф暟鎹�--"+l); Map pojo = JsonUtil.jsonToPojo(JsonUtil.jsonToString(l), Map.class); Optional.ofNullable(pojo.get("type")).ifPresent(o->{ pojo.put("type",dict.stream().filter(d-> Objects.equals(String.valueOf(d.getValue()),pojo.get("type"))).collect(Collectors.toList()).get(0).getLabel()); @@ -83,27 +90,54 @@ QueryWrapper<Param>queryWrapper=new QueryWrapper<>(); queryWrapper.lambda().eq(Param::getParentId,pojo.get("id")); List<Param> secondList = paramService.list(queryWrapper); - List<Map>secondMapList = new ArrayList<>(); + //娌℃湁children鐩存帴娣诲姞 + if(secondList.isEmpty()){ + Map<String,Object> oneMap = new HashMap<>(); + oneMap.put("code",pojo.get("code")); + oneMap.put("paramItem",pojo.get("parameterItem")); + oneMap.put("paramItemTwo",""); + oneMap.put("paramItemThree",""); + oneMap.put("oneId",pojo.get("id")); + oneMap.put("paramType",StringUtils.defaultString((String) pojo.get("type"),"")); + oneMap.put("paramFormat",StringUtils.defaultString((String) pojo.get("parameterFormat"),"")); + oneMap.put("unit",StringUtils.defaultString((String) pojo.get("unit"),"")); + all.add(oneMap); + } secondList.forEach(s->{ + System.out.println("浜岀骇鏁版嵁--"+s); Map second = JsonUtil.jsonToPojo(JsonUtil.jsonToString(s), Map.class); Optional.ofNullable(second.get("type")).ifPresent(o->{ second.put("type",dict.stream().filter(d-> Objects.equals(String.valueOf(d.getValue()),second.get("type"))).collect(Collectors.toList()).get(0).getLabel()); }); - System.out.println(second); QueryWrapper<Param>queryWrapperSecond=new QueryWrapper<>(); queryWrapperSecond.lambda().eq(Param::getParentId,second.get("id")); List<Param> third = paramService.getBaseMapper().selectList(queryWrapperSecond); + if(third.isEmpty()){ + Param p = new Param(); + p.setType(s.getType()); + p.setParameterFormat(s.getParameterFormat()); + p.setUnit(s.getUnit()); + third.add(p); + } third.forEach(t->{ + System.out.println("涓夌骇鏁版嵁--"+t); Optional.ofNullable(t.getType()).ifPresent(o->{ t.setType(dict.stream().filter(d-> Objects.equals(String.valueOf(d.getValue()),t.getType())).collect(Collectors.toList()).get(0).getLabel()); }); + Map<String,Object> allMap = new HashMap<>(); + allMap.put("code",pojo.get("code")); + allMap.put("paramItem",StringUtils.defaultString((String) pojo.get("parameterItem"),"")); + allMap.put("oneId",pojo.get("id")); + allMap.put("twoId",second.get("id")); + allMap.put("threeId",t.getId()); + allMap.put("paramItemTwo",StringUtils.defaultString((String) second.get("parameterItem"),"")); + allMap.put("paramItemThree",StringUtils.defaultString(t.getParameterItem(),"")); + allMap.put("paramType",StringUtils.defaultString(t.getType(),"")); + allMap.put("paramFormat",StringUtils.defaultString(t.getParameterFormat(),"")); + allMap.put("unit", StringUtils.defaultString(t.getUnit(),"")); + all.add(allMap); }); - System.out.println(third); - second.put("children",third); - secondMapList.add(second); }); - pojo.put("children",secondMapList); - all.add(pojo); }); page1.setRecords(all); return R.ok(page1); @@ -186,9 +220,11 @@ * @return */ @PostMapping("/upload") + @ApiOperation(value = "瀵煎叆", notes = "瀵煎叆") public R upload(@RequestParam("file") MultipartFile file) { try { - EasyExcel.read(file.getInputStream(), ParamData.class, new ParamUploadListener(paramService)).sheet().doRead(); +// EasyExcel.read(file.getInputStream(), ParamTemplate.class, new ExcelListener<ParamTemplate>()).sheet().doRead(); + EasyExcelUtils.readModelExcel(ParamTemplate.class,file); } catch (IOException e) { e.printStackTrace(); } diff --git a/mes-basic/src/main/java/com/chinaztt/mes/basic/entity/Param.java b/mes-basic/src/main/java/com/chinaztt/mes/basic/entity/Param.java index 9e5d860..b3d9010 100644 --- a/mes-basic/src/main/java/com/chinaztt/mes/basic/entity/Param.java +++ b/mes-basic/src/main/java/com/chinaztt/mes/basic/entity/Param.java @@ -108,7 +108,4 @@ @TableField("parent_id") private Long parentId; - public Param() { - this.parentId=0L; - } } diff --git a/mes-basic/src/main/java/com/chinaztt/mes/basic/enums/FileEnums.java b/mes-basic/src/main/java/com/chinaztt/mes/basic/enums/FileEnums.java index a645e67..ac0395e 100644 --- a/mes-basic/src/main/java/com/chinaztt/mes/basic/enums/FileEnums.java +++ b/mes-basic/src/main/java/com/chinaztt/mes/basic/enums/FileEnums.java @@ -13,7 +13,8 @@ crew("crew","鐝粍"), workstation("workstation","宸ヤ綔绔�"), - structure("structure","浜у搧缁撴瀯") + structure("structure","浜у搧缁撴瀯"), + param("param","鍙傛暟") ; FileEnums(String name, String fileName) { diff --git a/mes-basic/src/main/java/com/chinaztt/mes/basic/service/ParamService.java b/mes-basic/src/main/java/com/chinaztt/mes/basic/service/ParamService.java index 071a980..d7fd783 100644 --- a/mes-basic/src/main/java/com/chinaztt/mes/basic/service/ParamService.java +++ b/mes-basic/src/main/java/com/chinaztt/mes/basic/service/ParamService.java @@ -26,6 +26,7 @@ import com.chinaztt.mes.basic.dto.ParamPlusDto; import com.chinaztt.ztt.common.core.util.R; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -87,4 +88,5 @@ * @return */ String checkItemRepeat(Param param); + } diff --git a/mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java b/mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java index edbbd62..ca71185 100644 --- a/mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java +++ b/mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java @@ -17,6 +17,9 @@ package com.chinaztt.mes.basic.service.impl; import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.support.ExcelTypeEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -30,6 +33,9 @@ import com.chinaztt.mes.basic.mapper.ParamMapper; import com.chinaztt.mes.basic.service.ParamService; import com.chinaztt.mes.basic.util.DictUtils; +import com.chinaztt.mes.common.util.easyexcel.CustemHandler; +import com.chinaztt.mes.common.util.easyexcel.EasyExcelUtils; +import com.chinaztt.mes.common.util.easyexcel.template.ParamTemplate; import com.chinaztt.ztt.admin.api.entity.SysDictItem; import com.chinaztt.ztt.common.core.util.R; import lombok.AllArgsConstructor; @@ -37,6 +43,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.List; import java.util.stream.Collectors; diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/CustemHandler.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/CustemHandler.java new file mode 100644 index 0000000..80adfe7 --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/CustemHandler.java @@ -0,0 +1,80 @@ +package com.chinaztt.mes.common.util.easyexcel; + +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.Head; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy; +import org.apache.poi.ss.usermodel.Cell; +import org.springframework.util.CollectionUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** +*@author: Zou, Yu +*@description: +*@date: 2023/9/24 0024 12:56 +**/ +public class CustemHandler extends AbstractColumnWidthStyleStrategy { + + private static final int MAX_COLUMN_WIDTH = 255; + private static final int COLUMN_WIDTH = 20; + private Map<Integer, Map<Integer, Integer>> CACHE = new HashMap(8); + + public CustemHandler() { + } + + @Override + protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { + boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList); + if (needSetWidth) { + Map<Integer, Integer> maxColumnWidthMap = (Map) CACHE.get(writeSheetHolder.getSheetNo()); + if (maxColumnWidthMap == null) { + maxColumnWidthMap = new HashMap(16); + CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); + } + + Integer columnWidth = this.dataLength(cellDataList, cell, isHead); + if (columnWidth >= 0) { + if (columnWidth > MAX_COLUMN_WIDTH) { + columnWidth = MAX_COLUMN_WIDTH; + } else { + if (columnWidth < COLUMN_WIDTH) { + columnWidth = columnWidth * 2; + } + } + + Integer maxColumnWidth = (Integer) ((Map) maxColumnWidthMap).get(cell.getColumnIndex()); + if (maxColumnWidth == null || columnWidth > maxColumnWidth) { + ((Map) maxColumnWidthMap).put(cell.getColumnIndex(), columnWidth); + writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), columnWidth * 256); + } + } + } + } + + private Integer dataLength(List<CellData> cellDataList, Cell cell, Boolean isHead) { + if (isHead) { + return cell.getStringCellValue().getBytes().length; + } else { + CellData cellData = (CellData) cellDataList.get(0); + CellDataTypeEnum type = cellData.getType(); + if (type == null) { + return -1; + } else { + switch (type) { + case STRING: + return cellData.getStringValue().getBytes().length; + case BOOLEAN: + return cellData.getBooleanValue().toString().getBytes().length; + case NUMBER: + return cellData.getNumberValue().toString().getBytes().length; + default: + return -1; + } + } + } + } +} diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/EasyExcelUtils.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/EasyExcelUtils.java new file mode 100644 index 0000000..bc5f194 --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/EasyExcelUtils.java @@ -0,0 +1,441 @@ +package com.chinaztt.mes.common.util.easyexcel; + + +import cn.hutool.core.date.DateUtil; +import com.alibaba.excel.EasyExcelFactory; +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.metadata.Font; +import com.alibaba.excel.metadata.Sheet; +import com.alibaba.excel.metadata.Table; +import com.alibaba.excel.metadata.TableStyle; +import com.alibaba.excel.metadata.*; +import com.alibaba.excel.support.ExcelTypeEnum; +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.chinaztt.mes.common.util.easyexcel.exception.ExcelException; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Calendar; +import java.util.List; +import java.util.Map; + +/** +*@author: Zou, Yu +*@description: +*@date: 2023/9/24 0024 13:18 +**/ +public class EasyExcelUtils { + + public static HorizontalCellStyleStrategy getStyleStrategy() { + // 澶寸殑绛栫暐 + WriteCellStyle headWriteCellStyle = new WriteCellStyle(); + // 鑳屾櫙璁剧疆涓虹伆鑹� + headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + WriteFont headWriteFont = new WriteFont(); + headWriteFont.setFontHeightInPoints((short) 12); + // 瀛椾綋鏍峰紡 + headWriteFont.setFontName("瀹嬩綋"); + headWriteCellStyle.setWriteFont(headWriteFont); + // 鑷姩鎹㈣ + headWriteCellStyle.setWrapped(false); + // 姘村钩瀵归綈鏂瑰紡 + headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); + // 鍨傜洿瀵归綈鏂瑰紡 + headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + + // 鍐呭鐨勭瓥鐣� + WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); + // 杩欓噷闇�瑕佹寚瀹� FillPatternType 涓篎illPatternType.SOLID_FOREGROUND 涓嶇劧鏃犳硶鏄剧ず鑳屾櫙棰滆壊.澶撮粯璁や簡 FillPatternType鎵�浠ュ彲浠ヤ笉鎸囧畾 +// contentWriteCellStyle.setFillPatternType(FillPatternType.SQUARES); + // 鑳屾櫙鐧借壊 + contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); + WriteFont contentWriteFont = new WriteFont(); + // 瀛椾綋澶у皬 + contentWriteFont.setFontHeightInPoints((short) 11); + // 瀛椾綋鏍峰紡 + contentWriteFont.setFontName("瀹嬩綋"); + contentWriteCellStyle.setWriteFont(contentWriteFont); + // 鍐呭灞呬腑瀵归綈 + contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); + //鍐呭鍨傜洿灞呬腑 + contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + //杈规璁剧疆 + contentWriteCellStyle.setBorderTop(BorderStyle.THIN); + contentWriteCellStyle.setBorderRight(BorderStyle.THIN); + contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); + contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); + // 杩欎釜绛栫暐鏄� 澶存槸澶寸殑鏍峰紡 鍐呭鏄唴瀹圭殑鏍峰紡 鍏朵粬鐨勭瓥鐣ュ彲浠ヨ嚜宸卞疄鐜� + return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); + } + + public static HorizontalCellStyleStrategy getStyleFixedStrategy() { + // 澶寸殑绛栫暐 + WriteCellStyle headWriteCellStyle = new WriteCellStyle(); + // 鑳屾櫙璁剧疆涓虹伆鑹� + headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + WriteFont headWriteFont = new WriteFont(); + headWriteFont.setFontHeightInPoints((short) 12); + // 瀛椾綋鏍峰紡 + headWriteFont.setFontName("Calibri"); + headWriteCellStyle.setWriteFont(headWriteFont); + // 鑷姩鎹㈣ + headWriteCellStyle.setWrapped(false); + // 姘村钩瀵归綈鏂瑰紡 + headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); + // 鍨傜洿瀵归綈鏂瑰紡 + headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + // 鍐呭鐨勭瓥鐣� + WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); + // 杩欓噷闇�瑕佹寚瀹� FillPatternType 涓篎illPatternType.SOLID_FOREGROUND 涓嶇劧鏃犳硶鏄剧ず鑳屾櫙棰滆壊.澶撮粯璁や簡 FillPatternType鎵�浠ュ彲浠ヤ笉鎸囧畾 +// contentWriteCellStyle.setFillPatternType(FillPatternType.SQUARES); + // 鑳屾櫙鐧借壊 + contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); + WriteFont contentWriteFont = new WriteFont(); + // 瀛椾綋澶у皬 + contentWriteFont.setFontHeightInPoints((short) 10); + // 瀛椾綋鏍峰紡 + contentWriteFont.setFontName("Calibri"); + contentWriteCellStyle.setWriteFont(contentWriteFont); + // 鍐呭宸﹀榻� + contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT); + // 杩欎釜绛栫暐鏄� 澶存槸澶寸殑鏍峰紡 鍐呭鏄唴瀹圭殑鏍峰紡 鍏朵粬鐨勭瓥鐣ュ彲浠ヨ嚜宸卞疄鐜� + return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); + } + + public static HorizontalCellStyleStrategy getArveStyleStrategy() { + // 澶寸殑绛栫暐 + WriteCellStyle headWriteCellStyle = new WriteCellStyle(); + // 鑳屾櫙璁剧疆涓� + headWriteCellStyle.setFillForegroundColor(IndexedColors.BLACK.getIndex()); + WriteFont headWriteFont = new WriteFont(); + headWriteFont.setFontHeightInPoints((short) 12); + // 瀛椾綋鏍峰紡 + headWriteFont.setFontName("Calibri"); + headWriteFont.setColor(IndexedColors.WHITE.getIndex()); + headWriteCellStyle.setWriteFont(headWriteFont); + + headWriteCellStyle.setBorderBottom(BorderStyle.MEDIUM); + headWriteCellStyle.setLeftBorderColor(IndexedColors.WHITE.getIndex()); + headWriteCellStyle.setRightBorderColor(IndexedColors.WHITE.getIndex()); + // 鑷姩鎹㈣ + headWriteCellStyle.setWrapped(true); + // 姘村钩瀵归綈鏂瑰紡 + headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT); + // 鍨傜洿瀵归綈鏂瑰紡 + headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + // 鍐呭鐨勭瓥鐣� + WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); + // 杩欓噷闇�瑕佹寚瀹� FillPatternType 涓篎illPatternType.SOLID_FOREGROUND 涓嶇劧鏃犳硶鏄剧ず鑳屾櫙棰滆壊.澶撮粯璁や簡 FillPatternType鎵�浠ュ彲浠ヤ笉鎸囧畾 +// contentWriteCellStyle.setFillPatternType(FillPatternType.SQUARES); + // 鑳屾櫙鐧借壊 + contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); + WriteFont contentWriteFont = new WriteFont(); + // 瀛椾綋澶у皬 + contentWriteFont.setFontHeightInPoints((short) 10); + // 瀛椾綋鏍峰紡 + contentWriteFont.setFontName("Calibri"); + contentWriteCellStyle.setWriteFont(contentWriteFont); + // 杩欎釜绛栫暐鏄� 澶存槸澶寸殑鏍峰紡 鍐呭鏄唴瀹圭殑鏍峰紡 鍏朵粬鐨勭瓥鐣ュ彲浠ヨ嚜宸卞疄鐜� + return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); + } + + /** + * 璁剧疆response + * @param response + * @param targetName + * @return + */ + public static HttpServletResponse getResponse(HttpServletResponse response, String targetName){ + String fileName; + try { + fileName = String.valueOf(new StringBuilder() + .append(targetName) + .append("_") + .append(DateUtil.today()) + .append(ExcelTypeEnum.XLS.getValue())); + fileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()); + response.setContentType("application/vnd.ms-excel"); + response.setHeader("Cache-Control", "no-cache"); + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); + return response; + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + /** + * excel鏂囦欢璇诲彇 + * + * @param clazz model绫诲瀷Class瀵硅薄 + * @param excel excel鏂囦欢瀵硅薄 + * @param <T> model绫诲瀷娉涘瀷 + * @return model绫诲瀷鏁版嵁闆嗗悎 + * @throws IOException IO寮傚父 + */ + public static <T extends BaseRowModel> List<T> readModelExcel(Class<T> clazz, MultipartFile excel) throws IOException { + ExcelListener<T> excelListener = new ExcelListener<>(); + ExcelReader reader = getReader(excel, excelListener); + try { + reader.getSheets().forEach(sheet -> { + sheet.setClazz(clazz); + reader.read(sheet); + }); + } catch (Exception e) { + e.printStackTrace(); + throw new IOException("璇锋鏌ュ鍏ユā鏉匡紒"); + } + return excelListener.getDataList(); + } + + /** + * + * @param clazz model绫诲瀷Class瀵硅薄 + * @param excel excel鏂囦欢瀵硅薄 + * @param sheetNumber 鎸囧畾sheet椤� + * @param <T> model绫诲瀷娉涘瀷 + * @return model绫诲瀷鏁版嵁闆嗗悎 + * @throws IOException + */ + public static <T extends BaseRowModel> List<T> readModelSheetExcel(Class<T> clazz, MultipartFile excel, int sheetNumber) throws IOException { + ExcelListener<T> excelListener = new ExcelListener<>(); + ExcelReader reader = getReader(excel, excelListener); + try { + Sheet sheet = reader.getSheets().get(sheetNumber); + sheet.setClazz(clazz); + reader.read(sheet); + } catch (Exception e) { + throw new IOException("璇锋鏌ュ鍏ユā鏉匡紒"); + } + return excelListener.getDataList(); + } + + /** + * 鑾峰彇excel鏂囦欢璇诲彇瀵硅薄 + * + * @param excel excel鏂囦欢瀵硅薄 + * @param excelListener excel浜嬩欢澶勭悊 + * @return excel 璇诲彇瀵硅薄 + * @throws IOException IO寮傚父 + */ + private static ExcelReader getReader(MultipartFile excel, ExcelListener excelListener) throws IOException { + String filename = excel.getOriginalFilename(); + if (filename == null || (!filename.toLowerCase().endsWith(".xls") && !filename.toLowerCase().endsWith(".xlsx") && !filename.toLowerCase().endsWith(".xltm") && !filename.toLowerCase().endsWith(".xlsm"))) { + throw new ExcelException(ResponseResultEnum.EXCEL_FILE_EXT_ERROR); + } + InputStream inputStream = new BufferedInputStream(excel.getInputStream()); + return new ExcelReader(inputStream, null, excelListener, false); + } + + /** + * 鍐欏叆鏁版嵁鍒板鍑烘枃浠� + * + * @param clazz model绫诲瀷Class瀵硅薄 + * @param sheetNo sheet搴忓彿 + * @param headLineMun head琛屾暟 + * @param startRow 寮�濮嬪啓鍏ヨ鏁� + * @param tableNo table搴忓彿 + * @param modelList model鏁版嵁闆嗗悎 + * @param temp 涓存椂鏂囦欢瀵硅薄 + * @param export 瀵煎嚭鏂囦欢瀵硅薄 + * @param <T> model娉涘瀷 + */ + public static <T extends BaseRowModel> void writeModelExport(Class<T> clazz, Integer sheetNo, Integer headLineMun, Integer startRow, Integer tableNo, List<T> modelList, File temp, File export) { + try { + InputStream inputStream = new FileInputStream(temp); + FileOutputStream OutputStream = new FileOutputStream(export); + ExcelWriter writer = EasyExcelFactory.getWriterWithTemp(inputStream, OutputStream, ExcelTypeEnum.XLSX, false); + writer.write(modelList, initSheet(sheetNo, headLineMun, startRow), initTable(tableNo, clazz)); + writer.finish(); + OutputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Sheet鍒濆鍖� + * + * @param sheetNo sheet搴忓彿 + * @param headLineMun head琛屾暟 + * @param startRow 寮�濮嬪啓鍏ヨ鏁� + * @return Sheet瀵硅薄 + */ + public static Sheet initSheet(Integer sheetNo, Integer headLineMun, Integer startRow) { + Sheet sheet = new Sheet(sheetNo, headLineMun); + sheet.setStartRow(startRow); + return sheet; + } + + /** + * Table鍒濆鍖� + * + * @param tableNo table搴忓彿 + * @param clazz model绫诲瀷Class瀵硅薄 + * @param <T> model娉涘瀷 + * @return Table瀵硅薄 + */ + public static <T extends BaseRowModel> Table initTable(Integer tableNo, Class<T> clazz) { + Table table = new Table(tableNo); + table.setClazz(clazz); + TableStyle tableStyle = new TableStyle(); + tableStyle.setTableContentBackGroundColor(IndexedColors.WHITE); + tableStyle.setTableHeadBackGroundColor(IndexedColors.WHITE); + Font font = new Font(); + font.setBold(false); + font.setFontName("瀹嬩綋"); + font.setFontHeightInPoints((short) 11); + tableStyle.setTableContentFont(font); + table.setTableStyle(tableStyle); + return table; + } + + /** + * 鏇挎崲妯℃澘鏍囪 + * + * @param export 瀵煎嚭鏂囦欢瀵硅薄 + * @param index sheet搴忓彿 + * @param rows 鍗曞厓鏍艰搴� + * @param columns 鍗曞厓鏍煎垪搴� + * @param replaceMap 澶氫釜鏍囪闆嗗悎 + */ + public static void editModelWorkBook(File export, Integer index, Integer rows, Integer columns, Map<String, String> replaceMap) { + try { + XSSFWorkbook workBook = new XSSFWorkbook(export); +// editModelWorkBook(workBook,index,0,0,replaceMap); + editModelWorkBook(workBook, index, rows, columns, replaceMap); + workBook.close(); + } catch (IOException | InvalidFormatException e) { + e.printStackTrace(); + } + } + + /** + * 鏇挎崲妯℃澘鏍囪 + * + * @param workBook excel宸ヤ綔鍐屽璞� + * @param index sheet搴忓彿 + * @param rows 鍗曞厓鏍艰搴� + * @param columns 鍗曞厓鏍煎垪搴� + * @param replaceMap 澶氫釜鏍囪闆嗗悎 + */ + public static void editModelWorkBook(XSSFWorkbook workBook, Integer index, Integer rows, Integer columns, Map<String, String> replaceMap) { + XSSFSheet sheet = workBook.getSheetAt(index); + Row row = sheet.getRow(rows); + Cell cell = row.getCell(columns); + String replaceString = cell.toString(); + for (Map.Entry<String, String> entry : replaceMap.entrySet()) { + replaceString = replaceString.replace(entry.getKey(), entry.getValue()); + } + cell.setCellValue(replaceString); + workBook.setSheetName(index, replaceString.replace(":", "")); + } + + /** + * 妯℃澘sheet鍏嬮殕鍙婂懡鍚� + * + * @param temp 涓存椂鏂囦欢瀵硅薄 + * @param export 瀵煎嚭鏂囦欢瀵硅薄 + * @param cloneSheetNo 鍏嬮殕sheet搴忓垪 + * @param rows 鍗曞厓鏍艰搴� + * @param columns 鍗曞厓鏍煎垪搴� + * @param replaceMapList 澶氫釜鏍囪闆嗗悎 + */ + public static void writeModelCloneSheet(File temp, File export, Integer cloneSheetNo, Integer rows, Integer columns, List<Map<String, String>> replaceMapList) { + try { + XSSFWorkbook workBook = new XSSFWorkbook(temp); + OutputStream outputStream = new FileOutputStream(export); + /** 濡傛灉浣犻渶瑕�6浠界浉鍚屾ā鏉跨殑sheet 閭d箞浣犲彧闇�瑕佸厠闅�5浠藉嵆鍙�*/ + for (int index = 0; index < replaceMapList.size() - 1; index++) { + /** 鍏嬮殕妯℃澘鏂囦欢 */ + XSSFSheet sheet = workBook.cloneSheet(cloneSheetNo); + } + for (int index = 0; index < replaceMapList.size(); index++) { + editModelWorkBook(workBook, index, rows, columns, replaceMapList.get(index)); + } + workBook.write(outputStream); + outputStream.flush(); + outputStream.close(); + workBook.close(); + } catch (IOException | InvalidFormatException e) { + e.printStackTrace(); + } + } + + /** + * 涓存椂鏂囦欢鍐欏叆瀵煎嚭鏂囦欢 + * + * @param temp 涓存椂鏂囦欢瀵硅薄 + * @param export 瀵煎嚭鏂囦欢瀵硅薄 + * @param index sheet搴忓彿 + * @param rows 鍗曞厓鏍艰搴� + * @param columns 鍗曞厓鏍煎垪搴� + * @param isTime 鏄惁鏈夋椂闂存爣璁� + */ + public static void writeModelWorkBook(File temp, File export, Integer index, Integer rows, Integer columns, Boolean isTime) { + try { + XSSFWorkbook workBook = new XSSFWorkbook(temp); + OutputStream outputStream = new FileOutputStream(export); + if (isTime) { + writeModelWorkBook(workBook, index, rows, columns); + } + workBook.write(outputStream); + outputStream.flush(); + outputStream.close(); + workBook.close(); + } catch (IOException | InvalidFormatException e) { + e.printStackTrace(); + } + } + + /** + * 鏇挎崲鏃堕棿鏍囪锛坹ear,month,day锛� + * + * @param workBook excel宸ヤ綔鍐屽璞� + * @param index sheet搴忓彿 + * @param rows 鍗曞厓鏍艰搴� + * @param columns 鍗曞厓鏍煎垪搴� + */ + public static void writeModelWorkBook(XSSFWorkbook workBook, Integer index, Integer rows, Integer columns) { + XSSFSheet xssfSheet = workBook.getSheetAt(index); + Row row = xssfSheet.getRow(rows); + Cell cell = row.getCell(columns); + String cellString = cell.toString(); + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH) + 1; + int day = calendar.get(Calendar.DAY_OF_MONTH); + String yearString = cellString.replace("year", String.valueOf(year)); + String monthString = yearString.replace("month", String.valueOf(month)); + String dayString = monthString.replace("day", String.valueOf(day)); + cell.setCellValue(dayString); + } + + /** + * 閽堝UserModel瀵煎嚭鏂规硶 + * + * @param temp + * @param export + * @param isTime + */ + public static void writeModelWorkBook(File temp, File export, Boolean isTime) { + writeModelWorkBook(temp, export, 0, 1, 9, isTime); + } + + + public static void writeModelCloneSheet(File temp, File export, List<Map<String, String>> replaceMapList) { + writeModelCloneSheet(temp, export, 0, 0, 0, replaceMapList); + } + +} diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ExcelListener.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ExcelListener.java new file mode 100644 index 0000000..7631455 --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ExcelListener.java @@ -0,0 +1,58 @@ +package com.chinaztt.mes.common.util.easyexcel; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * excel鏁版嵁瀵煎叆鏁版嵁澶勭悊 + * + * @param <T> + * @author Zou, Yu + */ +@Slf4j +@Getter +@Setter +public class ExcelListener<T> extends AnalysisEventListener<T> { + + private List<T> dataList = new ArrayList<>(); + + @Override + public void invoke(T classType, AnalysisContext analysisContext) { + System.out.println("瀵煎叆鐨勬暟鎹�--"+classType); + dataList.add(classType); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + } + + @Override + public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { + String templateHead = ""; + +// List<String> headList = new ArrayList<>(); +// for (Integer i : headMap.keySet()) { +// headList.add(headMap.get(i)); +// } +// String importHead = headMap.values().toString(); +// log.info("importHead:{}", importHead); +// String templateName = context.getCurrentSheet().getClazz().getSimpleName(); +// log.info("templateName:{}", templateName); +// if("ExcelMBomTemplate".equals(templateName)){ +//// templateHead = mBomHead; +// } +// if (!templateHead.equals(importHead)) { +// throw new RuntimeException(ResponseResultEnum.EXCEL_MODEL_ERROR.getMessage()); +// } + + } + + +} \ No newline at end of file diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ExcelMergeStrategy.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ExcelMergeStrategy.java new file mode 100644 index 0000000..d4f7ab1 --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ExcelMergeStrategy.java @@ -0,0 +1,85 @@ +package com.chinaztt.mes.common.util.easyexcel; + +import com.alibaba.excel.metadata.Head; +import com.alibaba.excel.write.merge.AbstractMergeStrategy; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.util.CellRangeAddress; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * 鍚堝苟鍗曞厓鏍� + * @Author: Zou, Yu + * @DATE: 2023/9/26 0026 10:16 + */ +public class ExcelMergeStrategy extends AbstractMergeStrategy { + + /** + * 鍒嗙粍锛屾瘡鍑犺鍚堝苟涓�娆� + */ + private List<Integer> exportFieldGroupCountList; + + /** + * 鐩爣鍚堝苟鍒梚ndex + */ + private Integer targetColumnIndex; + + // 闇�瑕佸紑濮嬪悎骞跺崟鍏冩牸鐨勯琛宨ndex + private Integer rowIndex; + + // exportDataList涓哄緟鍚堝苟鐩爣鍒楃殑鍊� + public ExcelMergeStrategy(List<String> exportDataList, Integer targetColumnIndex) { + this.exportFieldGroupCountList = getGroupCountList(exportDataList); + this.targetColumnIndex = targetColumnIndex; + } + + @Override + protected void merge(Sheet sheet, Cell cell, Head head, Integer integer) { + if (null == rowIndex) { + rowIndex = cell.getRowIndex(); + } + // 浠呬粠棣栬浠ュ強鐩爣鍒楃殑鍗曞厓鏍煎紑濮嬪悎骞讹紝蹇界暐鍏朵粬 + if (cell.getRowIndex() == rowIndex && cell.getColumnIndex() == targetColumnIndex) { + mergeGroupColumn(sheet); + } + } + + private void mergeGroupColumn(Sheet sheet) { + int rowCount = rowIndex; + for (Integer count : exportFieldGroupCountList) { + if(count == 1) { + rowCount += count; + continue ; + } + // 鍚堝苟鍗曞厓鏍� + CellRangeAddress cellRangeAddress = new CellRangeAddress(rowCount, rowCount + count - 1, targetColumnIndex, targetColumnIndex); + sheet.addMergedRegionUnsafe(cellRangeAddress); + rowCount += count; + } + } + + // 璇ユ柟娉曞皢鐩爣鍒楁牴鎹�兼槸鍚︾浉鍚岃繛缁彲鍚堝苟锛屽瓨鍌ㄥ彲鍚堝苟鐨勮鏁� + private List<Integer> getGroupCountList(List<String> exportDataList){ + if (CollectionUtils.isEmpty(exportDataList)) { + return new ArrayList<>(); + } + + List<Integer> groupCountList = new ArrayList<>(); + int count = 1; + + for (int i = 1; i < exportDataList.size(); i++) { + if (exportDataList.get(i).equals(exportDataList.get(i - 1))) { + count++; + } else { + groupCountList.add(count); + count = 1; + } + } + // 澶勭悊瀹屾渶鍚庝竴鏉″悗 + groupCountList.add(count); + return groupCountList; + } +} diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ResponseResultEnum.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ResponseResultEnum.java new file mode 100644 index 0000000..2176ce3 --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/ResponseResultEnum.java @@ -0,0 +1,28 @@ +package com.chinaztt.mes.common.util.easyexcel; + +import lombok.Getter; + +/** + * 寮傚父淇℃伅鏋氫妇 + * @auther Zou, Yu + * @create 2023-09-24 + */ +@Getter +public enum ResponseResultEnum { + EXCEL_FILE_EXT_ERROR(1000,"鏂囦欢鏍煎紡閿欒"), + EXCEL_FILE_READ_FAIL(1001,"excel鏂囦欢璇诲彇澶辫触,璇锋鏌ユā鏉�!"), + EXCEL_FILE_IS_EMPTY(1002,"excel鏂囦欢涓虹┖"), + MODEL_FILE_NOT_EXIT(1003,"妯$増鏂囦欢涓嶅瓨鍦�"), + EXCEL_ACTIVE_DATE_ERROR(1004,"鐢熸晥鏃堕棿閿欒"), + EXCEL_MODEL_ERROR(1005,"瀵煎叆妯℃澘鏈夎锛岃妫�鏌ワ紒"), + EXCEL_FILE_EXCESS(1006,"鎵归噺瀵煎叆鏁版嵁閲忎笉鍙秴杩�500鏉�"); + + private Integer status; + private String message; + + ResponseResultEnum(Integer status, String message) { + this.status = status; + this.message = message; + } + +} diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/converter/LocalDateConverter.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/converter/LocalDateConverter.java new file mode 100644 index 0000000..ca493a3 --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/converter/LocalDateConverter.java @@ -0,0 +1,43 @@ +package com.chinaztt.mes.common.util.easyexcel.converter; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.property.ExcelContentProperty; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** +*@author: Zou, Yu +*@description: +*@date: 2023/9/24 0024 13:18 +**/ +@Component +public class LocalDateConverter implements Converter<LocalDate> { + + @Override + public Class<LocalDate> supportJavaTypeKey() { + return LocalDate.class; + } + + @Override + public CellDataTypeEnum supportExcelTypeKey() { + return CellDataTypeEnum.STRING; + } + + @Override + public LocalDate convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) { + return LocalDate.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } + + @Override + public CellData<String> convertToExcelData(LocalDate value, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) { + return new CellData<>(value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + } + +} \ No newline at end of file diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/converter/SaleTypeConverter.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/converter/SaleTypeConverter.java new file mode 100644 index 0000000..50e43bb --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/converter/SaleTypeConverter.java @@ -0,0 +1,48 @@ +package com.chinaztt.mes.common.util.easyexcel.converter; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.property.ExcelContentProperty; +import org.springframework.stereotype.Component; + +/** 璁㈠崟鐘舵�佽浆鎹� + * @Author: Zou, Yu + * @DATE: 2023/9/24 0024 14:21 + */ +@Component +public class SaleTypeConverter implements Converter<String> { + + @Override + public Class<String> supportJavaTypeKey() { + return String.class; + } + + @Override + public CellDataTypeEnum supportExcelTypeKey() { + return CellDataTypeEnum.STRING; + } + + @Override + public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { + if("閫氳繃".equals(cellData.getStringValue())){ + return "1"; + }else if("涓嶉�氳繃".equals(cellData.getStringValue())){ + return "0"; + }else{ + return "2"; + } + } + + @Override + public CellData convertToExcelData(String str, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { + if("1".equals(str)){ + return new CellData<>("閫氳繃"); + }else if("0".equals(str)){ + return new CellData<>("涓嶉�氳繃"); + }else{ + return new CellData<>("鏈鏍�"); + } + } +} diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/exception/ExcelException.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/exception/ExcelException.java new file mode 100644 index 0000000..d745848 --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/exception/ExcelException.java @@ -0,0 +1,25 @@ +package com.chinaztt.mes.common.util.easyexcel.exception; + +import com.chinaztt.mes.common.util.easyexcel.ResponseResultEnum; +import lombok.Getter; + +/** + * excel鍏ㄥ眬寮傚父 + * @auther Zou, Yu + * @create 2023-9-24 + */ +@Getter +public class ExcelException extends RuntimeException { + + private Integer status; + + public ExcelException(ResponseResultEnum resultEnum) { + super(resultEnum.getMessage()); + this.status = resultEnum.getStatus(); + } + + public ExcelException(Integer status, String message) { + super(message); + this.status = status; + } +} diff --git a/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/template/ParamTemplate.java b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/template/ParamTemplate.java new file mode 100644 index 0000000..3464218 --- /dev/null +++ b/mes-common/src/main/java/com/chinaztt/mes/common/util/easyexcel/template/ParamTemplate.java @@ -0,0 +1,55 @@ +package com.chinaztt.mes.common.util.easyexcel.template; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.annotation.write.style.ContentRowHeight; +import com.alibaba.excel.annotation.write.style.HeadRowHeight; +import com.alibaba.excel.metadata.BaseRowModel; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Arrays; + +@Data +@HeadRowHeight(40) +@ContentRowHeight(25) +@EqualsAndHashCode(callSuper = true) +public class ParamTemplate extends BaseRowModel implements Serializable { + + @ColumnWidth(30) + @ExcelProperty(value="鍙傛暟椤�", index = 0) + @JsonSerialize + private String paramItem; + + @ColumnWidth(30) + @ExcelProperty(value="浜岀骇鍙傛暟(鍙负绌�)", index = 1) + @JsonSerialize + private String paramItemTwo; + + @ColumnWidth(30) + @ExcelProperty(value="涓夌骇鍙傛暟(鍙负绌�)", index = 2) + @JsonSerialize + private String paramItemThree; + + @ColumnWidth(30) + @ExcelProperty(value="鍙傛暟绫诲瀷(鏁板��/鏂囨湰/涓嬫媺)", index = 3) + @JsonSerialize + private String paramType; + + @ColumnWidth(30) + @ExcelProperty(value="鍙傛暟鏍煎紡(鍙负绌�)", index = 4) + @JsonSerialize + private String paramFormat; + + @ColumnWidth(30) + @ExcelProperty(value="鍗曚綅(鍙负绌�)", index = 5) + @JsonSerialize + private String unit; + + public static String getTemplateHead(){ + return Arrays.asList("鍙傛暟椤�","浜岀骇鍙傛暟(鍙负绌�)","涓夌骇鍙傛暟(鍙负绌�)","鍙傛暟绫诲瀷(鏁板��/鏂囨湰/涓嬫媺)","鍙傛暟鏍煎紡(鍙负绌�)","鍗曚綅(鍙负绌�)").toString(); + } + +} -- Gitblit v1.9.3