From 38fe4ba31a92e3955a36f0916b790fcf53efaac9 Mon Sep 17 00:00:00 2001 From: 龚焕茏 <2842157468@qq.com> Date: 星期五, 26 七月 2024 11:29:02 +0800 Subject: [PATCH] refactor:合同导入模板 --- ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java | 28 +- ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java | 75 ++++---- ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java | 4 ycl-common/src/main/java/enumeration/ContractRule.java | 59 +++++++ ycl-server/src/main/java/com/ycl/handler/CustomCellWriteHandler.java | 258 ++++++++++++++++++++++++++++++++ ycl-server/src/main/java/com/ycl/platform/service/impl/ContractScoreServiceImpl.java | 4 6 files changed, 374 insertions(+), 54 deletions(-) diff --git a/ycl-common/src/main/java/enumeration/ContractRule.java b/ycl-common/src/main/java/enumeration/ContractRule.java new file mode 100644 index 0000000..1e8080b --- /dev/null +++ b/ycl-common/src/main/java/enumeration/ContractRule.java @@ -0,0 +1,59 @@ +package enumeration; + +import lombok.Getter; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author gonghl + * @since 2024/7/25 涓婂崍 10:50 + */ +@Getter +public enum ContractRule { + + CONTRACT_RULE_1("瑙嗛骞冲潎鍦ㄧ嚎鐜�", Arrays.asList("CONTRACT_RULE_2", "CONTRACT_RULE_3", "CONTRACT_RULE_4", "CONTRACT_RULE_5")), + CONTRACT_RULE_2("鈮�98%", Collections.EMPTY_LIST), + CONTRACT_RULE_3("95%鈮よ棰戝钩鍧囧湪绾跨巼锛�98%", Collections.EMPTY_LIST), + CONTRACT_RULE_4("90%鈮よ棰戝钩鍧囧湪绾跨巼锛�95%", Collections.EMPTY_LIST), + CONTRACT_RULE_5("锛�90%", Collections.EMPTY_LIST), + CONTRACT_RULE_6("鍓嶇鎰熺煡婧愭不鐞嗗伐浣�", Arrays.asList("CONTRACT_RULE_7", "CONTRACT_RULE_8", "CONTRACT_RULE_9")), + CONTRACT_RULE_7("鏃堕挓鍚屾锛堣秴杩嚶�3绉掍负涓嶅悎鏍硷級", Collections.EMPTY_LIST), + CONTRACT_RULE_8("OSD鏍囪瘑", Collections.EMPTY_LIST), + CONTRACT_RULE_9("涓�鏈轰竴妗�", Collections.EMPTY_LIST), + CONTRACT_RULE_10("瀛樺偍鏁呴殰", Arrays.asList("CONTRACT_RULE_11", "CONTRACT_RULE_12")), + CONTRACT_RULE_11("鍥犲瓨鍌ㄨ澶囥�佷簯瀛樺偍杞欢绛夊紩璧峰钩鍙颁笉鑳芥甯告煡鐪嬪巻鍙插浘鍍忥紝椤诲湪24灏忔椂鎺掗櫎鏁呴殰", Collections.EMPTY_LIST), + CONTRACT_RULE_12("鍥犺棰戞垨鑰呭浘鐗囦涪澶卞鑷撮噸瑕佹浜嬩欢涓嶈兘鍥炴斁鎴栨煡鐪�", Collections.EMPTY_LIST), + CONTRACT_RULE_13("瀵逛簬鍓嶇鐐逛綅寮傚父鎯呭喌鐨勫鐞�", List.of("CONTRACT_RULE_14")), + CONTRACT_RULE_14("闀滃ご鏁呴殰鎴栨薄鏌撴垨鏍戞灊閬尅鎴栨灙鏈鸿瑙掑亸绉绘甯歌搴︽垨琛ュ厜鐏簲浜湭浜�", Collections.EMPTY_LIST), + CONTRACT_RULE_15("寤虹珛鏁版嵁鐩戞祴缁存姢鏈哄埗", List.of("CONTRACT_RULE_16")), + CONTRACT_RULE_16("涓爣浜哄簲褰撳缓绔嬫暟鎹洃娴嬬淮鎶ゆ満鍒讹紝褰撳彂鐢熸暟鎹紓甯告儏鍐垫椂锛屽簲鍦� 24 灏忔椂鍐呮仮澶嶃�傦紙鏁版嵁寮傚父鍖呮嫭瀹炴椂鐩戞帶鎴栧綍鍍忚棰戞媺娴佸け璐ワ紝鍥剧墖鑾峰彇澶辫触銆佽瑙夎绠楄В鏋愬紓甯哥瓑锛夈��", Collections.EMPTY_LIST), + CONTRACT_RULE_17("纭繚褰曞儚瀹屾暣涓嶅畾鏈熷鎵�鏈夌偣浣嶅綍鍍忓畬鏁存�ф娊鏌�", Arrays.asList("CONTRACT_RULE_18", "CONTRACT_RULE_19", "CONTRACT_RULE_20", "CONTRACT_RULE_21", "CONTRACT_RULE_22")), + CONTRACT_RULE_18("姣忚矾瑙嗛绱涓㈠け10鍒嗛挓浠ュ唴", Collections.EMPTY_LIST), + CONTRACT_RULE_19("涓㈠け10-60 鍒嗛挓", Collections.EMPTY_LIST), + CONTRACT_RULE_20("涓㈠け1 灏忔椂-4 灏忔椂锛堝惈锛�", Collections.EMPTY_LIST), + CONTRACT_RULE_21("涓㈠け4 灏忔椂-12 灏忔椂锛堝惈锛�", Collections.EMPTY_LIST), + CONTRACT_RULE_22("涓㈠け12 灏忔椂浠ヤ笂", Collections.EMPTY_LIST), + CONTRACT_RULE_23("纭繚鍥剧墖瀹屾暣涓嶅畾鏈熷鎵�鏈変汉鑴歌溅杈嗕互鍙婃櫤鑳藉墠绔姄鎷嶇殑鍥剧墖瀹屾暣鎬ф娊鏌�", List.of("CONTRACT_RULE_24")), + CONTRACT_RULE_24("鍙戠幇鍚庡彴瀛樺偍涓嶈兘璋冨彇鍓嶇璁惧鍥剧墖", Collections.EMPTY_LIST), + ; + + private final String name; + private final List<String> children; + + ContractRule(String name, List<String> children) { + this.name = name; + this.children = children; + } + + public static List<ContractRule> getParent() { + return Arrays.stream(ContractRule.values()).filter(contractRule -> !contractRule.getChildren().isEmpty()).toList(); + } + + public static List<ContractRule> getChildren(ContractRule parent) { + return parent.getChildren().stream().map(ContractRule::valueOf).collect(Collectors.toList()); + } + +} diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java index b6af342..22e3f62 100644 --- a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java +++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java @@ -7,12 +7,12 @@ import com.alibaba.excel.enums.poi.VerticalAlignmentEnum; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; -import com.ycl.system.domain.TreeEntity; import com.ycl.system.domain.TreeNode; import enumeration.converter.RuleDeductCategoryConverter; import enumeration.general.RuleDeductCategoryEnum; import lombok.Data; +import java.io.Serial; import java.util.Date; /** @@ -26,13 +26,9 @@ @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) @TableName("t_calculate_rule") public class CalculateRule extends TreeNode { - private static final long serialVersionUID = 1L; - /** - * 涓婚敭 - */ - @ExcelProperty("搴忓彿") - private Long id; + @Serial + private static final long serialVersionUID = 1L; /** * 鍚堝悓id @@ -51,18 +47,24 @@ private Long parentId; /** - * 瑙勫垯鎻忚堪 - */ - @ExcelProperty("璇勫垽鏍囧噯") - private String ruleDesc; - - /** * 瑙勫垯鏉′欢 */ @ExcelProperty("鑰冩牳瑕佹眰") private String ruleCondition; /** + * 杩濊鏈�灏忓�� + */ + @ExcelProperty("杩濊鏈�灏忓��") + private Double min; + + /** + * 杩濊鏈�澶у�� + */ + @ExcelProperty("杩濊鏈�澶у��") + private Double max; + + /** * 鎵e噺鏂瑰紡 鎵f寚瀹氬垎鏁�/鍒嗘暟涔樹互鏁伴噺/闄や互鏁伴噺鍚庝箻浠ュ垎鏁� */ @ExcelProperty(value = "鎵e垎鏂瑰紡", converter = RuleDeductCategoryConverter.class) diff --git a/ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java b/ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java index dff2657..f57b1c6 100644 --- a/ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java +++ b/ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java @@ -24,11 +24,11 @@ Sheet sheet = context.getWriteSheetHolder().getSheet(); Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch(); - Comment comment1 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 5, 4, 4, 5)); + Comment comment1 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 5, 5, 4, 6)); comment1.setString(new XSSFRichTextString("鎵i櫎鐩稿叧闀滃ご鏁伴噺*0.1鍒�")); sheet.getRow(0).getCell(1).setCellComment(comment1); - Comment comment2 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 5, 7, 7, 8)); + Comment comment2 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 5, 8, 7, 9)); comment2.setString(new XSSFRichTextString("鎵�2鍒�/12灏忔椂")); sheet.getRow(0).getCell(1).setCellComment(comment2); } diff --git a/ycl-server/src/main/java/com/ycl/handler/CustomCellWriteHandler.java b/ycl-server/src/main/java/com/ycl/handler/CustomCellWriteHandler.java new file mode 100644 index 0000000..acb9559 --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/handler/CustomCellWriteHandler.java @@ -0,0 +1,258 @@ +package com.ycl.handler; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.util.BooleanUtils; +import com.alibaba.excel.write.handler.CellWriteHandler; +import com.alibaba.excel.write.handler.context.CellWriteHandlerContext; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; +import com.ycl.platform.domain.entity.CalculateRule; +import enumeration.ContractRule; +import enumeration.general.RuleDeductCategoryEnum; +import lombok.Data; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.usermodel.XSSFDataValidation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CustomCellWriteHandler implements CellWriteHandler { + + /** + * 杩欎釜澶勭悊鍣ㄥ叾瀹炲彲浠ュ仛寰堝浜嬫儏 + * 浠栬兘鎷垮埌鏁翠釜 Excel 鐨� WorkHook + * 涔熻兘鎷垮埌褰撳墠鐨� sheet + * 涔熻兘鎷垮埌褰撳墠鐨� cell + * 鎵�浠ヨ兘鍋氱殑鑷畾涔夋搷浣滃緢涓板瘜 + */ + // static class CustomCellWriteHandler { + + @Override + public void afterCellDispose(CellWriteHandlerContext context) { + // 褰撳墠鐨� cell + Cell cell = context.getCell(); + // 杩欓噷鍙互瀵筩ell杩涜浠讳綍鎿嶄綔 + // 杩欓噷灏辫鑰冭檻 浣犺閽堝鍝竴鍒楄繘琛屼釜鎬у寲澶勭悊 涓�瀹氳璁板緱鍔犲垽鏂� 鍥犱负姣忎釜 cell 閮戒細鎵ц鍒拌繖閲� 鎵�浠ヨ璁板緱鍖哄垎 + if (BooleanUtils.isTrue(context.getHead()) && cell.getColumnIndex() == 1) { + // 1 琛ㄧず 鐪侀偅涓�鍒� 瑕佸鐪佸競鍖鸿繘琛岃仈鍔ㄤ笅鎷夊鐞� + ExcelAreaUtil.writeAreaInfo(context, 0); + } + } + // } + + public static class ExcelAreaUtil { + + @Data + static class AreaInfo { + + private String name; + + private List<String> areaList; + + + public AreaInfo(String name, List<String> areaList) { + this.name = name; + this.areaList = areaList; + } + } + + + /** + * @param context handler 鐨� 涓婁笅鏂� + * @param startIndex 鐪佺殑鍒楀彿 浠�0寮�濮嬬殑 + */ + public static void writeAreaInfo(CellWriteHandlerContext context, int startIndex) { + // 鑾峰彇鍒板綋鍓嶇殑 sheet 鍚庣画瑕佺粰鐪佸競鍖哄垪鍔犱笅鎷� + WriteSheetHolder writeSheetHolder = context.getWriteSheetHolder(); + Sheet sheet = writeSheetHolder.getSheet(); + + // 鐪佸競鍖烘尐鐫�鐨勫垪鍙� + int cIndex = startIndex + 1; + int aIndex = cIndex + 1; + + // 鍑嗗鐐规暟鎹� + List<AreaInfo> provinceList = new ArrayList<>(); + for (ContractRule contractRule : ContractRule.getParent()) { + provinceList.add(new AreaInfo(contractRule.getName(), ContractRule.getChildren(contractRule).stream().map(ContractRule::getName).toList())); + } + + // 鑾峰彇鍒板綋鍓嶇殑 excel 鍥犱负瑕佸垱寤洪殣钘忕殑 sheet 涔熷氨鏄渷甯傚尯鐨勫疄闄呭唴瀹归兘鏉ヨ嚜浜庨殣钘忕殑 sheet + Workbook workbook = context.getWriteSheetHolder().getParentWriteWorkbookHolder().getWorkbook(); + Sheet hideSheet = workbook.createSheet("area"); + workbook.setSheetHidden(workbook.getSheetIndex(hideSheet), true); + // 鍐欓殣钘� sheet 鐨勭渷甯傚尯淇℃伅 + int rowId = 0; + // 璁剧疆绗竴琛岋紝瀛樼渷鐨勪俊鎭� + Row provinceRow = hideSheet.createRow(rowId++); + provinceRow.createCell(0).setCellValue("鐪佸垪琛�"); + for (int i = 0; i < provinceList.size(); i++) { + Cell provinceCell = provinceRow.createCell(i + 1); + provinceCell.setCellValue(provinceList.get(i).getName()); + } + + for (AreaInfo pro : provinceList) { + String pName = pro.getName(); + List<String> cList = pro.getAreaList(); + Row cRow = hideSheet.createRow(rowId++); + cRow.createCell(0).setCellValue(pName); + for (int j = 0; j < cList.size(); j++) { + String cInfo = cList.get(j); + Cell cCell = cRow.createCell(j + 1); + cCell.setCellValue(cInfo); + } + + // 娣诲姞鍚嶇О绠$悊鍣� + String range = getRange(1, rowId, cList.size()); + Name name = workbook.createName(); + // key涓嶅彲閲嶅 + name.setNameName(pName); + String formula = "area!" + range; + name.setRefersToFormula(formula); + } + + // 缁欑渷娣诲姞涓嬫媺 + int lastRow = 100; + setDataValidation(sheet, 1, lastRow, startIndex, startIndex); + + // 缁欏競 鍖� 娣诲姞涓嬫媺 + // 璁剧疆绗簩鍒楀拰绗笁鍒楃殑鏈夋晥鎬� + for (int i = 2; i < lastRow; i++) { + setDataValidation(CellReference.convertNumToColString(startIndex), sheet, i - 1, i - 1, cIndex, cIndex); + setDataValidation(CellReference.convertNumToColString(cIndex), sheet, i - 1, i - 1, aIndex, aIndex); + } + } + + public static void setDataValidation(Sheet sheetPro, int firstRow, int lastRow, int firstCol, int lastCol) { + DataValidationHelper dvHelper = sheetPro.getDataValidationHelper(); + String formula = getFormula(1, 1, 1, 34); + // 鐪佽鍒� + DataValidationConstraint provConstraint = dvHelper.createFormulaListConstraint(formula); + // 鍥涗釜鍙傛暟鍒嗗埆鏄細璧峰琛屻�佺粓姝㈣銆佽捣濮嬪垪銆佺粓姝㈠垪 + CellRangeAddressList provRangeAddressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol); + DataValidation provinceDataValidation = dvHelper.createValidation(provConstraint, provRangeAddressList); + // 楠岃瘉 + provinceDataValidation.createErrorBox("error", "璇烽�夋嫨姝g‘鐨勭渷浠�"); + provinceDataValidation.setShowErrorBox(true); + provinceDataValidation.setSuppressDropDownArrow(true); + sheetPro.addValidationData(provinceDataValidation); + } + + public static void setDataValidation(String offset, Sheet sheet, int firstRow, int lastRow, int firstCol, int lastCol) { + DataValidationHelper dvHelper = sheet.getDataValidationHelper(); + String formulaString = String.format("INDIRECT($%s%s)", offset, firstRow + 1); + DataValidation dataValidation = getDataValidationByFormula(formulaString, dvHelper, firstRow, lastRow, firstCol, lastCol); + sheet.addValidationData(dataValidation); + } + + private static DataValidation getDataValidationByFormula(String formulaString, DataValidationHelper dvHelper, + int firstRow, int lastRow, int firstCol, int lastCol) { + // 鍔犺浇涓嬫媺鍒楄〃鍐呭 + // 涓句緥锛氳嫢formulaString = "INDIRECT($A$2)" 琛ㄧず瑙勫垯鏁版嵁浼氫粠鍚嶇О绠$悊鍣ㄤ腑鑾峰彇key涓庡崟鍏冩牸 A2 鍊肩浉鍚岀殑鏁版嵁锛� + // 濡傛灉A2鏄睙鑻忕渷锛岄偅涔堟澶勫氨鏄睙鑻忕渷涓嬬殑甯備俊鎭�� + DataValidationConstraint dvConstraint = dvHelper.createFormulaListConstraint(formulaString); + // 璁剧疆鏁版嵁鏈夋晥鎬у姞杞藉湪鍝釜鍗曞厓鏍间笂銆� + // 鍥涗釜鍙傛暟鍒嗗埆鏄細璧峰琛屻�佺粓姝㈣銆佽捣濮嬪垪銆佺粓姝㈠垪 + CellRangeAddressList regions = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol); + // 缁戝畾 鏁版嵁鏈夋晥鎬у璞� + XSSFDataValidation dataValidation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, regions); + dataValidation.setEmptyCellAllowed(true); + dataValidation.setSuppressDropDownArrow(true); + dataValidation.setShowErrorBox(true); + // 璁剧疆杈撳叆閿欒鎻愮ず淇℃伅 + dataValidation.createErrorBox("閫夋嫨閿欒鎻愮ず", "浣犺緭鍏ョ殑鍊兼湭鍦ㄥ閫夊垪琛ㄤ腑锛岃涓嬫媺閫夋嫨鍚堥�傜殑鍊硷紒"); + return dataValidation; + } + + private static String getFormula(int firstRow, int lastRow, int firstCol, int lastCol) { + String ss = String.format("$%s$%s:$%s$%s", CellReference.convertNumToColString(firstCol), firstRow, + CellReference.convertNumToColString(lastCol), lastRow); + return String.format("=%s!%s", "area", ss); + } + + private static String getRange(int offset, int rowId, int colCount) { + String columnLetter1 = CellReference.convertNumToColString(offset); + String columnLetter2 = CellReference.convertNumToColString(offset + colCount - 1); + return String.format("$%s$%s:$%s$%s", columnLetter1, rowId, columnLetter2, rowId); + } + + } + + + public static void main(String[] args) { + EasyExcel.write("test.xlsx", CalculateRule.class) + // 鑷�傚簲鍒楀 + .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) + // 涓嬫媺妗� + .registerWriteHandler(new CustomSheetWriteHandler(Arrays.asList("鎵f寚瀹氬垎鏁�", "鍒嗘暟涔樹互鏁伴噺", "闄や互鏁伴噺鍚庝箻浠ュ垎鏁�"))) + .registerWriteHandler(new CustomCellWriteHandler()) + // 鏍囨敞 + .registerWriteHandler(new CommentWriteHandler()) + .sheet("鍚堝悓瀵煎叆妯℃澘") + .doWrite(getExcelData()); + } + + private static List<CalculateRule> getExcelData() { + ArrayList<CalculateRule> list = new ArrayList<>(); + CalculateRule calculateRule1 = new CalculateRule(); + calculateRule1.setId(1L); + calculateRule1.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); + calculateRule1.setRuleCondition("鈮�98%"); + calculateRule1.setMax(98D); + calculateRule1.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); + calculateRule1.setCalcFraction(0.00); + list.add(calculateRule1); + CalculateRule calculateRule2 = new CalculateRule(); + calculateRule2.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); + calculateRule2.setRuleCondition("95%鈮よ棰戝钩鍧囧湪绾跨巼锛�98%"); + calculateRule2.setMax(97D); + calculateRule2.setMin(95D); + calculateRule2.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); + calculateRule2.setCalcFraction(5.00); + list.add(calculateRule2); + CalculateRule calculateRule3 = new CalculateRule(); + calculateRule3.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); + calculateRule3.setRuleCondition("90%鈮よ棰戝钩鍧囧湪绾跨巼锛�95%"); + calculateRule3.setMax(94D); + calculateRule3.setMin(90D); + calculateRule3.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); + calculateRule3.setCalcFraction(10.00); + list.add(calculateRule3); + CalculateRule calculateRule33 = new CalculateRule(); + calculateRule33.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); + calculateRule33.setRuleCondition("锛�90%"); + calculateRule33.setMin(89D); + calculateRule33.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); + calculateRule33.setCalcFraction(10.00); + list.add(calculateRule33); + CalculateRule calculateRule4 = new CalculateRule(); + calculateRule4.setId(2L); + calculateRule4.setRuleName("鍓嶇鎰熺煡婧愭不鐞嗗伐浣�"); + calculateRule4.setRuleCondition("鏃堕挓鍚屾锛堣秴杩嚶�3绉掍负涓嶅悎鏍硷級"); + calculateRule4.setDeductCategory(RuleDeductCategoryEnum.MULTIPLY_POINTS_BY_QUANTITY); + calculateRule4.setCalcFraction(0.1); + list.add(calculateRule4); + CalculateRule calculateRule7 = new CalculateRule(); + calculateRule7.setRuleName("鍓嶇鎰熺煡婧愭不鐞嗗伐浣�"); + calculateRule7.setRuleCondition("OSD鏍囪瘑"); + list.add(calculateRule7); + CalculateRule calculateRule6 = new CalculateRule(); + calculateRule6.setRuleName("鍓嶇鎰熺煡婧愭不鐞嗗伐浣�"); + calculateRule6.setRuleCondition("涓�鏈轰竴妗�"); + list.add(calculateRule6); + CalculateRule calculateRule5 = new CalculateRule(); + calculateRule5.setId(3L); + calculateRule5.setRuleName("鍚庡彴绯荤粺鐨勪繚闅�"); + calculateRule5.setRuleCondition("鍗曟鏁呴殰鏃堕暱鑻ヨ秴鍑�72灏忔椂涓嶈冻144灏忔椂鐨勶紝姣忚秴鍑�12灏忔椂锛堜笉瓒�12灏忔椂鎸�12灏忔椂璁★級"); + calculateRule5.setMax(144D); + calculateRule5.setMin(72D); + calculateRule5.setDeductCategory(RuleDeductCategoryEnum.MULTIPLY_POINTS_AFTER_DIVIDING_QUANTITY); + calculateRule5.setCalcFraction(2.00); + calculateRule5.setCalcUnit(12); + list.add(calculateRule5); + return list; + } + +} \ No newline at end of file diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/ContractScoreServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/ContractScoreServiceImpl.java index 9b9ebef..ec9831f 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/impl/ContractScoreServiceImpl.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/ContractScoreServiceImpl.java @@ -10,10 +10,8 @@ import com.ycl.platform.mapper.YwUnitMapper; import com.ycl.platform.service.IContractScoreService; import com.ycl.system.entity.SysUser; -import com.ycl.utils.DateUtils; import com.ycl.utils.SecurityUtils; import enumeration.general.AuditingStatus; -import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -66,7 +64,7 @@ contractScore.setRuleIds(Arrays.stream(contractScore.getRuleIdsArray()).map(String::valueOf).collect(Collectors.joining(","))); contractScore.setRuleIdsArray(Arrays.stream(contractScore.getRuleIds().split(",")).map(Long::parseLong).toArray(Long[]::new)); List<CalculateRule> list = new LambdaQueryChainWrapper<>(calculateRuleMapper).in(CalculateRule::getId, contractScore.getRuleIdsArray()).list(); - contractScore.setRuleName(String.join(" / ", new String[]{list.get(0).getRuleName(), list.get(1).getRuleDesc(), list.get(2).getRuleCondition()})); + contractScore.setRuleName(String.join(" / ", new String[]{list.get(0).getRuleName(), list.get(2).getRuleCondition()})); return super.save(contractScore); } diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java index 855a8a2..ba2cb87 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java @@ -1,13 +1,13 @@ package com.ycl.platform.service.impl; import com.alibaba.excel.EasyExcel; -import com.alibaba.excel.write.merge.LoopMergeStrategy; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.handler.CommentWriteHandler; +import com.ycl.handler.CustomCellWriteHandler; import com.ycl.handler.CustomSheetWriteHandler; import com.ycl.platform.domain.entity.CalculateMoneyRule; import com.ycl.platform.domain.entity.CalculateRule; @@ -35,6 +35,7 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -51,33 +52,24 @@ private final ICalculateRuleService calculateRuleService; private final CalculateMoneyRuleServiceImpl calculateMoneyRuleService; - private final YwUnitServiceImpl ywUnitService; @Override public void importTemplate(HttpServletResponse response) { try { - List<CalculateRule> list = getExcelData(); - ArrayList<String> arrayList = new ArrayList<>(); - arrayList.add("鎵f寚瀹氬垎鏁�"); - arrayList.add("鍒嗘暟涔樹互鏁伴噺"); - arrayList.add("闄や互鏁伴噺鍚庝箻浠ュ垎鏁�"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setCharacterEncoding("utf-8"); String fileName = URLEncoder.encode("瀵煎叆鍚堝悓妯℃澘", StandardCharsets.UTF_8).replace("\\+", "%20"); response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); - // 绗竴鍒椼�佺浜屽垪涓婁笅鍚堝苟3琛� - LoopMergeStrategy loopMergeStrategy1 = new LoopMergeStrategy(3, 0); - LoopMergeStrategy loopMergeStrategy2 = new LoopMergeStrategy(3, 1); EasyExcel.write(response.getOutputStream(), CalculateRule.class) - .registerWriteHandler(loopMergeStrategy1) - .registerWriteHandler(loopMergeStrategy2) // 鑷�傚簲鍒楀 .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 涓嬫媺妗� - .registerWriteHandler(new CustomSheetWriteHandler(arrayList)) + .registerWriteHandler(new CustomSheetWriteHandler(Arrays.asList("鎵f寚瀹氬垎鏁�", "鍒嗘暟涔樹互鏁伴噺", "闄や互鏁伴噺鍚庝箻浠ュ垎鏁�"))) + .registerWriteHandler(new CustomCellWriteHandler()) // 鏍囨敞 .registerWriteHandler(new CommentWriteHandler()) - .sheet("鍚堝悓瀵煎叆妯℃澘").doWrite(list); + .sheet("鍚堝悓瀵煎叆妯℃澘") + .doWrite(getExcelData()); } catch (Exception e) { throw new RuntimeException(e); } @@ -88,44 +80,55 @@ CalculateRule calculateRule1 = new CalculateRule(); calculateRule1.setId(1L); calculateRule1.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); - calculateRule1.setRuleDesc("锛�1锛夎棰戝湪绾跨巼=瑙嗛鍦ㄧ嚎鏁伴噺梅鍓嶇鏈嶅姟閰嶇疆鏁帮紙搴旀墸闄や笉鍙姉鍔涙垨涓庝腑鏍囦汉鏈嶅姟鏃犲叧閫犳垚鐨勬帀绾块櫎澶栥�傦級"); calculateRule1.setRuleCondition("鈮�98%"); + calculateRule1.setMax(98D); calculateRule1.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); calculateRule1.setCalcFraction(0.00); list.add(calculateRule1); CalculateRule calculateRule2 = new CalculateRule(); - calculateRule2.setRuleDesc("锛�2锛夎棰戝钩鍧囧湪绾跨巼锛氬綋鏈堟瘡鏃ヨ棰戝湪绾跨巼鐨勫钩鍧囧�笺��"); + calculateRule2.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); calculateRule2.setRuleCondition("95%鈮よ棰戝钩鍧囧湪绾跨巼锛�98%"); + calculateRule2.setMax(97D); + calculateRule2.setMin(95D); calculateRule2.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); calculateRule2.setCalcFraction(5.00); list.add(calculateRule2); CalculateRule calculateRule3 = new CalculateRule(); - calculateRule3.setRuleDesc("锛�3锛夎棰戝湪绾跨巼淇濈暀鏁存暟骞朵笖鍚戜笅鍙栨暣銆�"); + calculateRule3.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); calculateRule3.setRuleCondition("90%鈮よ棰戝钩鍧囧湪绾跨巼锛�95%"); + calculateRule3.setMax(94D); + calculateRule3.setMin(90D); calculateRule3.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); calculateRule3.setCalcFraction(10.00); list.add(calculateRule3); + CalculateRule calculateRule33 = new CalculateRule(); + calculateRule33.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); + calculateRule33.setRuleCondition("锛�90%"); + calculateRule33.setMin(89D); + calculateRule33.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); + calculateRule33.setCalcFraction(10.00); + list.add(calculateRule33); CalculateRule calculateRule4 = new CalculateRule(); calculateRule4.setId(2L); calculateRule4.setRuleName("鍓嶇鎰熺煡婧愭不鐞嗗伐浣�"); - calculateRule4.setRuleDesc("鏃堕挓鍚屾锛堣秴杩嚶�3绉掍负涓嶅悎鏍硷級"); - calculateRule4.setRuleCondition("瑙嗛鐩戞帶鎽勫儚鏈烘椂閽熶笉鍚屾锛�24灏忔椂鍐呮湭淇鐨�"); + calculateRule4.setRuleCondition("鏃堕挓鍚屾锛堣秴杩嚶�3绉掍负涓嶅悎鏍硷級"); calculateRule4.setDeductCategory(RuleDeductCategoryEnum.MULTIPLY_POINTS_BY_QUANTITY); calculateRule4.setCalcFraction(0.1); list.add(calculateRule4); CalculateRule calculateRule7 = new CalculateRule(); - calculateRule7.setRuleDesc("鈥︹�︹�︹��"); - calculateRule7.setRuleCondition("鈥︹�︹�︹��"); + calculateRule7.setRuleName("鍓嶇鎰熺煡婧愭不鐞嗗伐浣�"); + calculateRule7.setRuleCondition("OSD鏍囪瘑"); list.add(calculateRule7); CalculateRule calculateRule6 = new CalculateRule(); - calculateRule6.setRuleDesc("鈥︹�︹�︹��"); - calculateRule6.setRuleCondition("鈥︹�︹�︹��"); + calculateRule6.setRuleName("鍓嶇鎰熺煡婧愭不鐞嗗伐浣�"); + calculateRule6.setRuleCondition("涓�鏈轰竴妗�"); list.add(calculateRule6); CalculateRule calculateRule5 = new CalculateRule(); calculateRule5.setId(3L); calculateRule5.setRuleName("鍚庡彴绯荤粺鐨勪繚闅�"); - calculateRule5.setRuleDesc("鍦ㄤ釜鍒澶囨晠闅滀絾涓嶅奖鍝嶈鍔熻兘妯″潡鏁翠綋搴旂敤鎯呭喌涓嬶紝椤诲湪72灏忔椂浠ュ唴鎺掗櫎鏁呴殰銆�"); - calculateRule5.setRuleCondition("鍗曟鏁呴殰鏃堕暱鑻ヨ秴鍑�144灏忔椂浠ュ悗锛屾瘡瓒呭嚭12灏忔椂锛堜笉瓒�12灏忔椂鎸�12灏忔椂璁★級"); + calculateRule5.setRuleCondition("鍗曟鏁呴殰鏃堕暱鑻ヨ秴鍑�72灏忔椂涓嶈冻144灏忔椂鐨勶紝姣忚秴鍑�12灏忔椂锛堜笉瓒�12灏忔椂鎸�12灏忔椂璁★級"); + calculateRule5.setMax(144D); + calculateRule5.setMin(72D); calculateRule5.setDeductCategory(RuleDeductCategoryEnum.MULTIPLY_POINTS_AFTER_DIVIDING_QUANTITY); calculateRule5.setCalcFraction(2.00); calculateRule5.setCalcUnit(12); @@ -173,17 +176,17 @@ fuNew = true; } // 淇濆瓨绗簩灞傜埗瑙勫垯鑾峰彇绗簩灞傜埗id - if (StringUtils.isNotBlank(calculateRule.getRuleDesc())) { - CalculateRule two = new CalculateRule(); - two.setContractId(tContract.getId().intValue()); - two.setParentId(fu1.getId()); - two.setRuleDesc(calculateRule.getRuleDesc()); - two.setCreateTime(DateUtils.getNowDate()); - two.setDeleted(0); - calculateRuleService.save(two); - fu2 = two; - fuNew = false; - } + // if (StringUtils.isNotBlank(calculateRule.getRuleDesc())) { + // CalculateRule two = new CalculateRule(); + // two.setContractId(tContract.getId().intValue()); + // two.setParentId(fu1.getId()); + // two.setRuleDesc(calculateRule.getRuleDesc()); + // two.setCreateTime(DateUtils.getNowDate()); + // two.setDeleted(0); + // calculateRuleService.save(two); + // fu2 = two; + // fuNew = false; + // } calculateRule.setContractId(tContract.getId().intValue()); calculateRule.setCreateTime(DateUtils.getNowDate()); calculateRule.setDeleted(0); -- Gitblit v1.8.0