From f56fab932a34369b49457de7ab1569cd966710e9 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 2 Mar 2024 23:24:42 +0800 Subject: [PATCH] =?UTF-8?q?CRM=EF=BC=9A=E5=AE=8C=E5=96=84=20excel=20?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=20review=20=E6=8F=90=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dict/core/DictFrameworkUtils.java | 22 ++++++ .../core/annotations/ExcelColumnSelect.java | 7 +- .../function/ExcelColumnSelectFunction.java | 28 +++++++ .../core/handler/SelectSheetWriteHandler.java | 75 ++++++++++--------- .../service/ExcelColumnSelectDataService.java | 43 ----------- .../vo/customer/CrmCustomerImportExcelVO.java | 13 ++-- .../AreaExcelColumnSelectFunctionImpl.java} | 14 ++-- .../crm/framework/excel/package-info.java | 1 - ...ustryExcelColumnSelectDataServiceImpl.java | 35 --------- ...LevelExcelColumnSelectDataServiceImpl.java | 35 --------- ...ourceExcelColumnSelectDataServiceImpl.java | 35 --------- .../contract/CrmContractServiceImpl.java | 2 +- .../receivable/CrmReceivableService.java | 3 +- .../receivable/CrmReceivableServiceImpl.java | 4 +- 14 files changed, 110 insertions(+), 207 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/function/ExcelColumnSelectFunction.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/service/ExcelColumnSelectDataService.java rename yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/{service/AreaExcelColumnSelectDataServiceImpl.java => core/AreaExcelColumnSelectFunctionImpl.java} (56%) delete mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerIndustryExcelColumnSelectDataServiceImpl.java delete mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerLevelExcelColumnSelectDataServiceImpl.java delete mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerSourceExcelColumnSelectDataServiceImpl.java diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/DictFrameworkUtils.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/DictFrameworkUtils.java index 9fb0f692e..e51ef16e7 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/DictFrameworkUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/core/DictFrameworkUtils.java @@ -11,6 +11,9 @@ import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import java.time.Duration; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; /** * 字典工具类 @@ -38,6 +41,20 @@ public class DictFrameworkUtils { }); + /** + * 针对 {@link #getDictDataLabelList(String)} 的缓存 + */ + private static final LoadingCache> GET_DICT_DATA_LIST_CACHE = CacheUtils.buildAsyncReloadingCache( + Duration.ofMinutes(1L), // 过期时间 1 分钟 + new CacheLoader>() { + + @Override + public List load(String dictType) { + return dictDataApi.getDictDataLabelList(dictType); + } + + }); + /** * 针对 {@link #parseDictDataValue(String, String)} 的缓存 */ @@ -67,6 +84,11 @@ public class DictFrameworkUtils { return GET_DICT_DATA_CACHE.get(new KeyValue<>(dictType, value)).getLabel(); } + @SneakyThrows + public static List getDictDataLabelList(String dictType) { + return GET_DICT_DATA_LIST_CACHE.get(dictType); + } + @SneakyThrows public static String parseDictDataValue(String dictType, String label) { return PARSE_DICT_DATA_CACHE.get(new KeyValue<>(dictType, label)).getValue(); diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java index 2c519523b..5daa1e064 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java @@ -12,9 +12,14 @@ import java.lang.annotation.*; @Inherited public @interface ExcelColumnSelect { + /** + * @return 字典类型 + */ + String dictType() default ""; + /** * @return 获取下拉数据源的方法名称 */ - String value(); + String functionName() default ""; } diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/function/ExcelColumnSelectFunction.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/function/ExcelColumnSelectFunction.java new file mode 100644 index 000000000..51953c463 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/function/ExcelColumnSelectFunction.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.framework.excel.core.function; + +import java.util.List; + +/** + * Excel 列下拉数据源获取接口 + * + * 为什么不直接解析字典还搞个接口?考虑到有的下拉数据不是从字典中获取的所有需要做一个兼容 + + * @author HUIHUI + */ +public interface ExcelColumnSelectFunction { + + /** + * 获得方法名称 + * + * @return 方法名称 + */ + String getName(); + + /** + * 获得列下拉数据源 + * + * @return 下拉数据源 + */ + List getOptions(); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java index c50158de3..df4601b94 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java @@ -2,15 +2,19 @@ package cn.iocoder.yudao.framework.excel.core.handler; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import cn.hutool.poi.excel.ExcelUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils; import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect; -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService; +import cn.iocoder.yudao.framework.excel.core.function.ExcelColumnSelectFunction; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.write.handler.SheetWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; +import lombok.extern.slf4j.Slf4j; import org.apache.poi.hssf.usermodel.HSSFDataValidation; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddressList; @@ -26,13 +30,9 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. * * @author HUIHUI */ +@Slf4j public class SelectSheetWriteHandler implements SheetWriteHandler { - // TODO @puhui999:注释哈; - private static final List ALPHABET = getExcelColumnNameList(); - - private static final List EXCEL_COLUMN_SELECT_DATA_SERVICES = new ArrayList<>(); - /** * 数据起始行从 0 开始 * @@ -46,34 +46,35 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { private static final String DICT_SHEET_NAME = "字典sheet"; - // TODO @puhui999:这个 selectMap 可以改成 Map>,然后在 afterSheetCreate 里面进行排序。这样整体的理解成本会更简单 - private final List>> selectMap = new ArrayList<>(); // 使用 List + KeyValue 组合方便排序 + /** + * key: 列 value: 下拉数据源 + */ + private final Map> selectMap = new HashMap<>(); public SelectSheetWriteHandler(Class head) { // 加载下拉数据获取接口 - Map beansMap = SpringUtil.getBeanFactory().getBeansOfType(ExcelColumnSelectDataService.class); + Map beansMap = SpringUtil.getBeanFactory().getBeansOfType(ExcelColumnSelectFunction.class); if (MapUtil.isEmpty(beansMap)) { return; } - // TODO @puhui999:static 是共享。如果并发情况下,会不会存在问题? 其实 EXCEL_COLUMN_SELECT_DATA_SERVICES 不用全局声明,直接 按照 ExcelColumnSelect 去拿下就好了; - if (CollUtil.isEmpty(EXCEL_COLUMN_SELECT_DATA_SERVICES) || EXCEL_COLUMN_SELECT_DATA_SERVICES.size() != beansMap.values().size()) { - EXCEL_COLUMN_SELECT_DATA_SERVICES.clear(); - EXCEL_COLUMN_SELECT_DATA_SERVICES.addAll(convertList(beansMap.values(), b -> b)); - } // 解析下拉数据 - // TODO @puhui999:感觉可以 head 循环 field,如果有 ExcelColumnSelect 则进行处理;而 ExcelProperty 可能是非必须的 + // TODO @puhui999:感觉可以 head 循环 field,如果有 ExcelColumnSelect 则进行处理;而 ExcelProperty 可能是非必须的。回答:主要是用于定位到列索引 Map excelPropertyFields = getFieldsWithAnnotation(head, ExcelProperty.class); Map excelColumnSelectFields = getFieldsWithAnnotation(head, ExcelColumnSelect.class); int colIndex = 0; for (String fieldName : excelPropertyFields.keySet()) { Field field = excelColumnSelectFields.get(fieldName); if (field != null) { + // ExcelProperty 有一个自定义列索引的属性 index 兼容这个字段 + int index = field.getAnnotation(ExcelProperty.class).index(); + if (index != -1) { + colIndex = index; + } getSelectDataList(colIndex, field); } colIndex++; } - selectMap.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错 } /** @@ -83,12 +84,25 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { * @param field 字段 */ private void getSelectDataList(int colIndex, Field field) { - EXCEL_COLUMN_SELECT_DATA_SERVICES.forEach(selectDataService -> { - List stringList = selectDataService.handle(field.getAnnotation(ExcelColumnSelect.class).value()); - if (CollUtil.isEmpty(stringList)) { + // 获得下拉注解信息 + ExcelColumnSelect columnSelect = field.getAnnotation(ExcelColumnSelect.class); + String dictType = columnSelect.dictType(); + if (StrUtil.isNotEmpty(dictType)) { // 情况一: 字典数据 (默认) + selectMap.put(colIndex, DictFrameworkUtils.getDictDataLabelList(dictType)); + return; + } + String functionName = columnSelect.functionName(); + if (StrUtil.isEmpty(functionName)) { // 情况二: 获取自定义数据 + log.warn("[getSelectDataList]解析下拉数据失败,参数信息 dictType[{}] functionName[{}]", dictType, functionName); + return; + } + // 获得所有的下拉数据源获取方法 + Map functionMap = SpringUtil.getApplicationContext().getBeansOfType(ExcelColumnSelectFunction.class); + functionMap.values().forEach(func -> { + if (ObjUtil.notEqual(func.getName(), functionName)) { return; } - selectMap.add(new KeyValue<>(colIndex, stringList)); + selectMap.put(colIndex, func.getOptions()); }); } @@ -101,10 +115,11 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { // 1. 获取相应操作对象 DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper(); // 需要设置下拉框的 sheet 页的数据验证助手 Workbook workbook = writeWorkbookHolder.getWorkbook(); // 获得工作簿 - + List>> keyValues = convertList(selectMap.entrySet(), entry -> new KeyValue<>(entry.getKey(), entry.getValue())); + keyValues.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错 // 2. 创建数据字典的 sheet 页 Sheet dictSheet = workbook.createSheet(DICT_SHEET_NAME); - for (KeyValue> keyValue : selectMap) { + for (KeyValue> keyValue : keyValues) { int rowLength = keyValue.getValue().size(); // 2.1 设置字典 sheet 页的值 每一列一个字典项 for (int i = 0; i < rowLength; i++) { @@ -126,7 +141,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { KeyValue> keyValue) { // 1.1 创建可被其他单元格引用的名称 Name name = workbook.createName(); - String excelColumn = ALPHABET.get(keyValue.getKey()); + String excelColumn = ExcelUtil.indexToColName(keyValue.getKey()); // 1.2 下拉框数据来源 eg:字典sheet!$B1:$B2 String refers = DICT_SHEET_NAME + "!$" + excelColumn + "$1:$" + excelColumn + "$" + keyValue.getValue().size(); name.setNameName("dict" + keyValue.getKey()); // 设置名称的名字 @@ -162,18 +177,4 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { return annotatedFields; } - - private static List getExcelColumnNameList() { - // TODO @puhui999:是不是可以使用 ExcelUtil.indexToColName() 替代 - ArrayList strings = new ArrayList<>(); - for (int i = 1; i <= 52; i++) { // 生成 52 列名称,需要更多请重写此方法 - if (i <= 26) { - strings.add(String.valueOf((char) ('A' + i - 1))); // 使用 ASCII 码值转字母 - } else { - strings.add(String.valueOf((char) ('A' + (i - 1) / 26 - 1)) + (char) ('A' + (i - 1) % 26)); - } - } - return strings; - } - } \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/service/ExcelColumnSelectDataService.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/service/ExcelColumnSelectDataService.java deleted file mode 100644 index c4dc6e3bc..000000000 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/service/ExcelColumnSelectDataService.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.yudao.framework.excel.core.service; - -import cn.hutool.core.util.StrUtil; - -import java.util.Collections; -import java.util.List; - -/** - * Excel 列下拉数据源获取接口 - * - * 为什么不直接解析字典还搞个接口?考虑到有的下拉数据不是从字典中获取的所有需要做一个兼容 - * TODO @puhui999:是不是 @ExcelColumnSelect 可以搞两个属性,一个 dictType,一个 functionName;如果 dictType,则默认走字典,否则走 functionName - * 这样的话,ExcelColumnSelectDataService 改成 ExcelColumnSelectFunction 用于获取数据。 - * - * @author HUIHUI - */ -public interface ExcelColumnSelectDataService { - - // TODO @puhui999:可以考虑改成 getName - /** - * 获得方法名称 - * - * @return 方法名称 - */ - String getFunctionName(); - - // TODO @puhui999:可以考虑改成 getOptions;因为 select 下面是 option 哈,和前端 html 类似的标签; - /** - * 获得列下拉数据源 - * - * @return 下拉数据源 - */ - List getSelectDataList(); - - // TODO @puhui999:这个建议放到 SelectSheetWriteHandler 里 - default List handle(String funcName) { - if (StrUtil.isEmptyIfStr(funcName) || !StrUtil.equals(getFunctionName(), funcName)) { - return Collections.emptyList(); - } - return getSelectDataList(); - } - -} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java index 4b5fbefbd..f06122c3b 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java @@ -4,10 +4,7 @@ import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect; import cn.iocoder.yudao.framework.excel.core.convert.AreaConvert; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.crm.framework.excel.service.AreaExcelColumnSelectDataServiceImpl; -import cn.iocoder.yudao.module.crm.framework.excel.service.CrmCustomerIndustryExcelColumnSelectDataServiceImpl; -import cn.iocoder.yudao.module.crm.framework.excel.service.CrmCustomerLevelExcelColumnSelectDataServiceImpl; -import cn.iocoder.yudao.module.crm.framework.excel.service.CrmCustomerSourceExcelColumnSelectDataServiceImpl; +import cn.iocoder.yudao.module.crm.framework.excel.core.AreaExcelColumnSelectFunctionImpl; import com.alibaba.excel.annotation.ExcelProperty; import lombok.AllArgsConstructor; import lombok.Builder; @@ -46,7 +43,7 @@ public class CrmCustomerImportExcelVO { private String email; @ExcelProperty(value = "地区", converter = AreaConvert.class) - @ExcelColumnSelect(AreaExcelColumnSelectDataServiceImpl.FUNCTION_NAME) + @ExcelColumnSelect(functionName = AreaExcelColumnSelectFunctionImpl.NAME) private Integer areaId; @ExcelProperty("详细地址") @@ -54,17 +51,17 @@ public class CrmCustomerImportExcelVO { @ExcelProperty(value = "所属行业", converter = DictConvert.class) @DictFormat(CRM_CUSTOMER_INDUSTRY) - @ExcelColumnSelect(CrmCustomerIndustryExcelColumnSelectDataServiceImpl.FUNCTION_NAME) + @ExcelColumnSelect(dictType = CRM_CUSTOMER_INDUSTRY) private Integer industryId; @ExcelProperty(value = "客户等级", converter = DictConvert.class) @DictFormat(CRM_CUSTOMER_LEVEL) - @ExcelColumnSelect(CrmCustomerLevelExcelColumnSelectDataServiceImpl.FUNCTION_NAME) + @ExcelColumnSelect(dictType = CRM_CUSTOMER_LEVEL) private Integer level; @ExcelProperty(value = "客户来源", converter = DictConvert.class) @DictFormat(CRM_CUSTOMER_SOURCE) - @ExcelColumnSelect(CrmCustomerSourceExcelColumnSelectDataServiceImpl.FUNCTION_NAME) + @ExcelColumnSelect(dictType = CRM_CUSTOMER_SOURCE) private Integer source; @ExcelProperty("备注") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/AreaExcelColumnSelectDataServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunctionImpl.java similarity index 56% rename from yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/AreaExcelColumnSelectDataServiceImpl.java rename to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunctionImpl.java index bd2bbd9e9..9df93ac6d 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/AreaExcelColumnSelectDataServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunctionImpl.java @@ -1,6 +1,6 @@ -package cn.iocoder.yudao.module.crm.framework.excel.service; +package cn.iocoder.yudao.module.crm.framework.excel.core; -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService; +import cn.iocoder.yudao.framework.excel.core.function.ExcelColumnSelectFunction; import cn.iocoder.yudao.framework.ip.core.Area; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import org.springframework.stereotype.Service; @@ -13,17 +13,17 @@ import java.util.List; * @author HUIHUI */ @Service -public class AreaExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService { +public class AreaExcelColumnSelectFunctionImpl implements ExcelColumnSelectFunction { - public static final String FUNCTION_NAME = "getCrmAreaNameList"; // 防止和别的模块重名 + public static final String NAME = "getCrmAreaNameList"; // 防止和别的模块重名 @Override - public String getFunctionName() { - return FUNCTION_NAME; + public String getName() { + return NAME; } @Override - public List getSelectDataList() { + public List getOptions() { // 获取地区下拉数据 // TODO @puhui999:嘿嘿,这里改成省份、城市、区域,三个选项,难度大么? Area area = AreaUtils.getArea(Area.ID_CHINA); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java index bd9cb957a..8b54b9f55 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java @@ -1,2 +1 @@ -// TODO @puhui999:在 framework 目录,保持 config 和 core 目录的风格哈; package cn.iocoder.yudao.module.crm.framework.excel; \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerIndustryExcelColumnSelectDataServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerIndustryExcelColumnSelectDataServiceImpl.java deleted file mode 100644 index 8a78104bf..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerIndustryExcelColumnSelectDataServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.crm.framework.excel.service; - -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService; -import cn.iocoder.yudao.module.system.api.dict.DictDataApi; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; - -import java.util.List; - -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY; - -/** - * Excel 客户所属行业列下拉数据源获取接口实现类 - * - * @author HUIHUI - */ -@Service -public class CrmCustomerIndustryExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService { - - public static final String FUNCTION_NAME = "getCrmCustomerIndustryList"; - - @Resource - private DictDataApi dictDataApi; - - @Override - public String getFunctionName() { - return FUNCTION_NAME; - } - - @Override - public List getSelectDataList() { - return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_INDUSTRY); - } - -} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerLevelExcelColumnSelectDataServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerLevelExcelColumnSelectDataServiceImpl.java deleted file mode 100644 index 5948aa427..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerLevelExcelColumnSelectDataServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.crm.framework.excel.service; - -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService; -import cn.iocoder.yudao.module.system.api.dict.DictDataApi; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; - -import java.util.List; - -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL; - -/** - * Excel 客户等级列下拉数据源获取接口实现类 - * - * @author HUIHUI - */ -@Service -public class CrmCustomerLevelExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService { - - public static final String FUNCTION_NAME = "getCrmCustomerLevelList"; - - @Resource - private DictDataApi dictDataApi; - - @Override - public String getFunctionName() { - return FUNCTION_NAME; - } - - @Override - public List getSelectDataList() { - return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_LEVEL); - } - -} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerSourceExcelColumnSelectDataServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerSourceExcelColumnSelectDataServiceImpl.java deleted file mode 100644 index c160ed90f..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerSourceExcelColumnSelectDataServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.crm.framework.excel.service; - -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService; -import cn.iocoder.yudao.module.system.api.dict.DictDataApi; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; - -import java.util.List; - -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE; - -/** - * Excel 客户来源列下拉数据源获取接口实现类 - * - * @author HUIHUI - */ -@Service -public class CrmCustomerSourceExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService { - - public static final String FUNCTION_NAME = "getCrmCustomerSourceList"; - - @Resource - private DictDataApi dictDataApi; - - @Override - public String getFunctionName() { - return FUNCTION_NAME; - } - - @Override - public List getSelectDataList() { - return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_SOURCE); - } - -} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java index 1a8772415..fdab61428 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java @@ -229,7 +229,7 @@ public class CrmContractServiceImpl implements CrmContractService { // 1.1 校验存在 CrmContractDO contract = validateContractExists(id); // 1.2 如果被 CrmReceivableDO 所使用,则不允许删除 - if (CollUtil.isNotEmpty(receivableService.getReceivableByContractId(contract.getId()))) { + if (receivableService.getReceivableByContractId(contract.getId()) != 0) { throw exception(CONTRACT_DELETE_FAIL); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java index ed84ad03f..c4a68fd70 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java @@ -122,13 +122,12 @@ public interface CrmReceivableService { */ Map getReceivablePriceMapByContractId(Collection contractIds); - // TODO @puhui999:这个搞成根据数量判断,会更好一点哈; /** * 更具合同编号查询回款列表 * * @param contractId 合同编号 * @return 回款 */ - List getReceivableByContractId(Long contractId); + Long getReceivableByContractId(Long contractId); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java index 52db93273..889d94e1f 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java @@ -302,8 +302,8 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { } @Override - public List getReceivableByContractId(Long contractId) { - return receivableMapper.selectList(CrmReceivableDO::getContractId, contractId); + public Long getReceivableByContractId(Long contractId) { + return receivableMapper.selectCount(CrmReceivableDO::getContractId, contractId); } }