Commit f56fab932a34369b49457de7ab1569cd966710e9

Authored by puhui999
1 parent 1f35ef59

CRM:完善 excel 导出 review 提到的问题

Showing 13 changed files with 87 additions and 184 deletions
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;
11 11 import lombok.extern.slf4j.Slf4j;
12 12  
13 13 import java.time.Duration;
  14 +import java.util.List;
  15 +
  16 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
14 17  
15 18 /**
16 19 * 字典工具类
... ... @@ -39,6 +42,20 @@ public class DictFrameworkUtils {
39 42 });
40 43  
41 44 /**
  45 + * 针对 {@link #getDictDataLabelList(String)} 的缓存
  46 + */
  47 + private static final LoadingCache<String, List<String>> GET_DICT_DATA_LIST_CACHE = CacheUtils.buildAsyncReloadingCache(
  48 + Duration.ofMinutes(1L), // 过期时间 1 分钟
  49 + new CacheLoader<String, List<String>>() {
  50 +
  51 + @Override
  52 + public List<String> load(String dictType) {
  53 + return dictDataApi.getDictDataLabelList(dictType);
  54 + }
  55 +
  56 + });
  57 +
  58 + /**
42 59 * 针对 {@link #parseDictDataValue(String, String)} 的缓存
43 60 */
44 61 private static final LoadingCache<KeyValue<String, String>, DictDataRespDTO> PARSE_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
... ... @@ -68,6 +85,11 @@ public class DictFrameworkUtils {
68 85 }
69 86  
70 87 @SneakyThrows
  88 + public static List<String> getDictDataLabelList(String dictType) {
  89 + return GET_DICT_DATA_LIST_CACHE.get(dictType);
  90 + }
  91 +
  92 + @SneakyThrows
71 93 public static String parseDictDataValue(String dictType, String label) {
72 94 return PARSE_DICT_DATA_CACHE.get(new KeyValue<>(dictType, label)).getValue();
73 95 }
... ...
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java
... ... @@ -13,8 +13,13 @@ import java.lang.annotation.*;
13 13 public @interface ExcelColumnSelect {
14 14  
15 15 /**
  16 + * @return 字典类型
  17 + */
  18 + String dictType() default "";
  19 +
  20 + /**
16 21 * @return 获取下拉数据源的方法名称
17 22 */
18   - String value();
  23 + String functionName() default "";
19 24  
20 25 }
... ...
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/service/ExcelColumnSelectDataService.java renamed to yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/function/ExcelColumnSelectFunction.java
1   -package cn.iocoder.yudao.framework.excel.core.service;
  1 +package cn.iocoder.yudao.framework.excel.core.function;
2 2  
3   -import cn.hutool.core.util.StrUtil;
4   -
5   -import java.util.Collections;
6 3 import java.util.List;
7 4  
8 5 /**
9 6 * Excel 列下拉数据源获取接口
10 7 *
11 8 * 为什么不直接解析字典还搞个接口?考虑到有的下拉数据不是从字典中获取的所有需要做一个兼容
12   - * TODO @puhui999:是不是 @ExcelColumnSelect 可以搞两个属性,一个 dictType,一个 functionName;如果 dictType,则默认走字典,否则走 functionName
13   - * 这样的话,ExcelColumnSelectDataService 改成 ExcelColumnSelectFunction 用于获取数据。
14   - *
  9 +
15 10 * @author HUIHUI
16 11 */
17   -public interface ExcelColumnSelectDataService {
  12 +public interface ExcelColumnSelectFunction {
18 13  
19   - // TODO @puhui999:可以考虑改成 getName
20 14 /**
21 15 * 获得方法名称
22 16 *
23 17 * @return 方法名称
24 18 */
25   - String getFunctionName();
  19 + String getName();
26 20  
27   - // TODO @puhui999:可以考虑改成 getOptions;因为 select 下面是 option 哈,和前端 html 类似的标签;
28 21 /**
29 22 * 获得列下拉数据源
30 23 *
31 24 * @return 下拉数据源
32 25 */
33   - List<String> getSelectDataList();
34   -
35   - // TODO @puhui999:这个建议放到 SelectSheetWriteHandler 里
36   - default List<String> handle(String funcName) {
37   - if (StrUtil.isEmptyIfStr(funcName) || !StrUtil.equals(getFunctionName(), funcName)) {
38   - return Collections.emptyList();
39   - }
40   - return getSelectDataList();
41   - }
  26 + List<String> getOptions();
42 27  
43 28 }
... ...
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;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.map.MapUtil;
  5 +import cn.hutool.core.util.ObjUtil;
  6 +import cn.hutool.core.util.StrUtil;
5 7 import cn.hutool.extra.spring.SpringUtil;
6 8 import cn.hutool.poi.excel.ExcelUtil;
7 9 import cn.iocoder.yudao.framework.common.core.KeyValue;
  10 +import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils;
8 11 import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect;
9   -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService;
  12 +import cn.iocoder.yudao.framework.excel.core.function.ExcelColumnSelectFunction;
10 13 import com.alibaba.excel.annotation.ExcelProperty;
11 14 import com.alibaba.excel.write.handler.SheetWriteHandler;
12 15 import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
13 16 import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
  17 +import lombok.extern.slf4j.Slf4j;
14 18 import org.apache.poi.hssf.usermodel.HSSFDataValidation;
15 19 import org.apache.poi.ss.usermodel.*;
16 20 import org.apache.poi.ss.util.CellRangeAddressList;
... ... @@ -26,13 +30,9 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
26 30 *
27 31 * @author HUIHUI
28 32 */
  33 +@Slf4j
29 34 public class SelectSheetWriteHandler implements SheetWriteHandler {
30 35  
31   - // TODO @puhui999:注释哈;
32   - private static final List<String> ALPHABET = getExcelColumnNameList();
33   -
34   - private static final List<ExcelColumnSelectDataService> EXCEL_COLUMN_SELECT_DATA_SERVICES = new ArrayList<>();
35   -
36 36 /**
37 37 * 数据起始行从 0 开始
38 38 *
... ... @@ -46,34 +46,35 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
46 46  
47 47 private static final String DICT_SHEET_NAME = "字典sheet";
48 48  
49   - // TODO @puhui999:这个 selectMap 可以改成 Map<Integer, List<String>>,然后在 afterSheetCreate 里面进行排序。这样整体的理解成本会更简单
50   - private final List<KeyValue<Integer, List<String>>> selectMap = new ArrayList<>(); // 使用 List + KeyValue 组合方便排序
  49 + /**
  50 + * key: 列 value: 下拉数据源
  51 + */
  52 + private final Map<Integer, List<String>> selectMap = new HashMap<>();
51 53  
52 54 public SelectSheetWriteHandler(Class<?> head) {
53 55 // 加载下拉数据获取接口
54   - Map<String, ExcelColumnSelectDataService> beansMap = SpringUtil.getBeanFactory().getBeansOfType(ExcelColumnSelectDataService.class);
  56 + Map<String, ExcelColumnSelectFunction> beansMap = SpringUtil.getBeanFactory().getBeansOfType(ExcelColumnSelectFunction.class);
55 57 if (MapUtil.isEmpty(beansMap)) {
56 58 return;
57 59 }
58   - // TODO @puhui999:static 是共享。如果并发情况下,会不会存在问题? 其实 EXCEL_COLUMN_SELECT_DATA_SERVICES 不用全局声明,直接 按照 ExcelColumnSelect 去拿下就好了;
59   - if (CollUtil.isEmpty(EXCEL_COLUMN_SELECT_DATA_SERVICES) || EXCEL_COLUMN_SELECT_DATA_SERVICES.size() != beansMap.values().size()) {
60   - EXCEL_COLUMN_SELECT_DATA_SERVICES.clear();
61   - EXCEL_COLUMN_SELECT_DATA_SERVICES.addAll(convertList(beansMap.values(), b -> b));
62   - }
63 60  
64 61 // 解析下拉数据
65   - // TODO @puhui999:感觉可以 head 循环 field,如果有 ExcelColumnSelect 则进行处理;而 ExcelProperty 可能是非必须的
  62 + // TODO @puhui999:感觉可以 head 循环 field,如果有 ExcelColumnSelect 则进行处理;而 ExcelProperty 可能是非必须的。回答:主要是用于定位到列索引
66 63 Map<String, Field> excelPropertyFields = getFieldsWithAnnotation(head, ExcelProperty.class);
67 64 Map<String, Field> excelColumnSelectFields = getFieldsWithAnnotation(head, ExcelColumnSelect.class);
68 65 int colIndex = 0;
69 66 for (String fieldName : excelPropertyFields.keySet()) {
70 67 Field field = excelColumnSelectFields.get(fieldName);
71 68 if (field != null) {
  69 + // ExcelProperty 有一个自定义列索引的属性 index 兼容这个字段
  70 + int index = field.getAnnotation(ExcelProperty.class).index();
  71 + if (index != -1) {
  72 + colIndex = index;
  73 + }
72 74 getSelectDataList(colIndex, field);
73 75 }
74 76 colIndex++;
75 77 }
76   - selectMap.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错
77 78 }
78 79  
79 80 /**
... ... @@ -83,12 +84,25 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
83 84 * @param field 字段
84 85 */
85 86 private void getSelectDataList(int colIndex, Field field) {
86   - EXCEL_COLUMN_SELECT_DATA_SERVICES.forEach(selectDataService -> {
87   - List<String> stringList = selectDataService.handle(field.getAnnotation(ExcelColumnSelect.class).value());
88   - if (CollUtil.isEmpty(stringList)) {
  87 + // 获得下拉注解信息
  88 + ExcelColumnSelect columnSelect = field.getAnnotation(ExcelColumnSelect.class);
  89 + String dictType = columnSelect.dictType();
  90 + if (StrUtil.isNotEmpty(dictType)) { // 情况一: 字典数据 (默认)
  91 + selectMap.put(colIndex, DictFrameworkUtils.getDictDataLabelList(dictType));
  92 + return;
  93 + }
  94 + String functionName = columnSelect.functionName();
  95 + if (StrUtil.isEmpty(functionName)) { // 情况二: 获取自定义数据
  96 + log.warn("[getSelectDataList]解析下拉数据失败,参数信息 dictType[{}] functionName[{}]", dictType, functionName);
  97 + return;
  98 + }
  99 + // 获得所有的下拉数据源获取方法
  100 + Map<String, ExcelColumnSelectFunction> functionMap = SpringUtil.getApplicationContext().getBeansOfType(ExcelColumnSelectFunction.class);
  101 + functionMap.values().forEach(func -> {
  102 + if (ObjUtil.notEqual(func.getName(), functionName)) {
89 103 return;
90 104 }
91   - selectMap.add(new KeyValue<>(colIndex, stringList));
  105 + selectMap.put(colIndex, func.getOptions());
92 106 });
93 107 }
94 108  
... ... @@ -101,10 +115,11 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
101 115 // 1. 获取相应操作对象
102 116 DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper(); // 需要设置下拉框的 sheet 页的数据验证助手
103 117 Workbook workbook = writeWorkbookHolder.getWorkbook(); // 获得工作簿
104   -
  118 + List<KeyValue<Integer, List<String>>> keyValues = convertList(selectMap.entrySet(), entry -> new KeyValue<>(entry.getKey(), entry.getValue()));
  119 + keyValues.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错
105 120 // 2. 创建数据字典的 sheet 页
106 121 Sheet dictSheet = workbook.createSheet(DICT_SHEET_NAME);
107   - for (KeyValue<Integer, List<String>> keyValue : selectMap) {
  122 + for (KeyValue<Integer, List<String>> keyValue : keyValues) {
108 123 int rowLength = keyValue.getValue().size();
109 124 // 2.1 设置字典 sheet 页的值 每一列一个字典项
110 125 for (int i = 0; i < rowLength; i++) {
... ... @@ -126,7 +141,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
126 141 KeyValue<Integer, List<String>> keyValue) {
127 142 // 1.1 创建可被其他单元格引用的名称
128 143 Name name = workbook.createName();
129   - String excelColumn = ALPHABET.get(keyValue.getKey());
  144 + String excelColumn = ExcelUtil.indexToColName(keyValue.getKey());
130 145 // 1.2 下拉框数据来源 eg:字典sheet!$B1:$B2
131 146 String refers = DICT_SHEET_NAME + "!$" + excelColumn + "$1:$" + excelColumn + "$" + keyValue.getValue().size();
132 147 name.setNameName("dict" + keyValue.getKey()); // 设置名称的名字
... ... @@ -162,18 +177,4 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
162 177 return annotatedFields;
163 178 }
164 179  
165   -
166   - private static List<String> getExcelColumnNameList() {
167   - // TODO @puhui999:是不是可以使用 ExcelUtil.indexToColName() 替代
168   - ArrayList<String> strings = new ArrayList<>();
169   - for (int i = 1; i <= 52; i++) { // 生成 52 列名称,需要更多请重写此方法
170   - if (i <= 26) {
171   - strings.add(String.valueOf((char) ('A' + i - 1))); // 使用 ASCII 码值转字母
172   - } else {
173   - strings.add(String.valueOf((char) ('A' + (i - 1) / 26 - 1)) + (char) ('A' + (i - 1) % 26));
174   - }
175   - }
176   - return strings;
177   - }
178   -
179 180 }
180 181 \ No newline at end of file
... ...
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;
4 4 import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect;
5 5 import cn.iocoder.yudao.framework.excel.core.convert.AreaConvert;
6 6 import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
7   -import cn.iocoder.yudao.module.crm.framework.excel.service.AreaExcelColumnSelectDataServiceImpl;
8   -import cn.iocoder.yudao.module.crm.framework.excel.service.CrmCustomerIndustryExcelColumnSelectDataServiceImpl;
9   -import cn.iocoder.yudao.module.crm.framework.excel.service.CrmCustomerLevelExcelColumnSelectDataServiceImpl;
10   -import cn.iocoder.yudao.module.crm.framework.excel.service.CrmCustomerSourceExcelColumnSelectDataServiceImpl;
  7 +import cn.iocoder.yudao.module.crm.framework.excel.core.AreaExcelColumnSelectFunctionImpl;
11 8 import com.alibaba.excel.annotation.ExcelProperty;
12 9 import lombok.AllArgsConstructor;
13 10 import lombok.Builder;
... ... @@ -46,7 +43,7 @@ public class CrmCustomerImportExcelVO {
46 43 private String email;
47 44  
48 45 @ExcelProperty(value = "地区", converter = AreaConvert.class)
49   - @ExcelColumnSelect(AreaExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
  46 + @ExcelColumnSelect(functionName = AreaExcelColumnSelectFunctionImpl.NAME)
50 47 private Integer areaId;
51 48  
52 49 @ExcelProperty("详细地址")
... ... @@ -54,17 +51,17 @@ public class CrmCustomerImportExcelVO {
54 51  
55 52 @ExcelProperty(value = "所属行业", converter = DictConvert.class)
56 53 @DictFormat(CRM_CUSTOMER_INDUSTRY)
57   - @ExcelColumnSelect(CrmCustomerIndustryExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
  54 + @ExcelColumnSelect(dictType = CRM_CUSTOMER_INDUSTRY)
58 55 private Integer industryId;
59 56  
60 57 @ExcelProperty(value = "客户等级", converter = DictConvert.class)
61 58 @DictFormat(CRM_CUSTOMER_LEVEL)
62   - @ExcelColumnSelect(CrmCustomerLevelExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
  59 + @ExcelColumnSelect(dictType = CRM_CUSTOMER_LEVEL)
63 60 private Integer level;
64 61  
65 62 @ExcelProperty(value = "客户来源", converter = DictConvert.class)
66 63 @DictFormat(CRM_CUSTOMER_SOURCE)
67   - @ExcelColumnSelect(CrmCustomerSourceExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
  64 + @ExcelColumnSelect(dictType = CRM_CUSTOMER_SOURCE)
68 65 private Integer source;
69 66  
70 67 @ExcelProperty("备注")
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/AreaExcelColumnSelectDataServiceImpl.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunctionImpl.java
1   -package cn.iocoder.yudao.module.crm.framework.excel.service;
  1 +package cn.iocoder.yudao.module.crm.framework.excel.core;
2 2  
3   -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService;
  3 +import cn.iocoder.yudao.framework.excel.core.function.ExcelColumnSelectFunction;
4 4 import cn.iocoder.yudao.framework.ip.core.Area;
5 5 import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
6 6 import org.springframework.stereotype.Service;
... ... @@ -13,17 +13,17 @@ import java.util.List;
13 13 * @author HUIHUI
14 14 */
15 15 @Service
16   -public class AreaExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService {
  16 +public class AreaExcelColumnSelectFunctionImpl implements ExcelColumnSelectFunction {
17 17  
18   - public static final String FUNCTION_NAME = "getCrmAreaNameList"; // 防止和别的模块重名
  18 + public static final String NAME = "getCrmAreaNameList"; // 防止和别的模块重名
19 19  
20 20 @Override
21   - public String getFunctionName() {
22   - return FUNCTION_NAME;
  21 + public String getName() {
  22 + return NAME;
23 23 }
24 24  
25 25 @Override
26   - public List<String> getSelectDataList() {
  26 + public List<String> getOptions() {
27 27 // 获取地区下拉数据
28 28 // TODO @puhui999:嘿嘿,这里改成省份、城市、区域,三个选项,难度大么?
29 29 Area area = AreaUtils.getArea(Area.ID_CHINA);
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java
1   -// TODO @puhui999:在 framework 目录,保持 config 和 core 目录的风格哈;
2 1 package cn.iocoder.yudao.module.crm.framework.excel;
3 2 \ No newline at end of file
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerIndustryExcelColumnSelectDataServiceImpl.java deleted
1   -package cn.iocoder.yudao.module.crm.framework.excel.service;
2   -
3   -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService;
4   -import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
5   -import jakarta.annotation.Resource;
6   -import org.springframework.stereotype.Service;
7   -
8   -import java.util.List;
9   -
10   -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY;
11   -
12   -/**
13   - * Excel 客户所属行业列下拉数据源获取接口实现类
14   - *
15   - * @author HUIHUI
16   - */
17   -@Service
18   -public class CrmCustomerIndustryExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService {
19   -
20   - public static final String FUNCTION_NAME = "getCrmCustomerIndustryList";
21   -
22   - @Resource
23   - private DictDataApi dictDataApi;
24   -
25   - @Override
26   - public String getFunctionName() {
27   - return FUNCTION_NAME;
28   - }
29   -
30   - @Override
31   - public List<String> getSelectDataList() {
32   - return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_INDUSTRY);
33   - }
34   -
35   -}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerLevelExcelColumnSelectDataServiceImpl.java deleted
1   -package cn.iocoder.yudao.module.crm.framework.excel.service;
2   -
3   -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService;
4   -import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
5   -import jakarta.annotation.Resource;
6   -import org.springframework.stereotype.Service;
7   -
8   -import java.util.List;
9   -
10   -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL;
11   -
12   -/**
13   - * Excel 客户等级列下拉数据源获取接口实现类
14   - *
15   - * @author HUIHUI
16   - */
17   -@Service
18   -public class CrmCustomerLevelExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService {
19   -
20   - public static final String FUNCTION_NAME = "getCrmCustomerLevelList";
21   -
22   - @Resource
23   - private DictDataApi dictDataApi;
24   -
25   - @Override
26   - public String getFunctionName() {
27   - return FUNCTION_NAME;
28   - }
29   -
30   - @Override
31   - public List<String> getSelectDataList() {
32   - return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_LEVEL);
33   - }
34   -
35   -}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerSourceExcelColumnSelectDataServiceImpl.java deleted
1   -package cn.iocoder.yudao.module.crm.framework.excel.service;
2   -
3   -import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService;
4   -import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
5   -import jakarta.annotation.Resource;
6   -import org.springframework.stereotype.Service;
7   -
8   -import java.util.List;
9   -
10   -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE;
11   -
12   -/**
13   - * Excel 客户来源列下拉数据源获取接口实现类
14   - *
15   - * @author HUIHUI
16   - */
17   -@Service
18   -public class CrmCustomerSourceExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService {
19   -
20   - public static final String FUNCTION_NAME = "getCrmCustomerSourceList";
21   -
22   - @Resource
23   - private DictDataApi dictDataApi;
24   -
25   - @Override
26   - public String getFunctionName() {
27   - return FUNCTION_NAME;
28   - }
29   -
30   - @Override
31   - public List<String> getSelectDataList() {
32   - return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_SOURCE);
33   - }
34   -
35   -}
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 {
229 229 // 1.1 校验存在
230 230 CrmContractDO contract = validateContractExists(id);
231 231 // 1.2 如果被 CrmReceivableDO 所使用,则不允许删除
232   - if (CollUtil.isNotEmpty(receivableService.getReceivableByContractId(contract.getId()))) {
  232 + if (receivableService.getReceivableByContractId(contract.getId()) != 0) {
233 233 throw exception(CONTRACT_DELETE_FAIL);
234 234 }
235 235  
... ...
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 {
122 122 */
123 123 Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds);
124 124  
125   - // TODO @puhui999:这个搞成根据数量判断,会更好一点哈;
126 125 /**
127 126 * 更具合同编号查询回款列表
128 127 *
129 128 * @param contractId 合同编号
130 129 * @return 回款
131 130 */
132   - List<CrmReceivableDO> getReceivableByContractId(Long contractId);
  131 + Long getReceivableByContractId(Long contractId);
133 132  
134 133 }
... ...
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 {
302 302 }
303 303  
304 304 @Override
305   - public List<CrmReceivableDO> getReceivableByContractId(Long contractId) {
306   - return receivableMapper.selectList(CrmReceivableDO::getContractId, contractId);
  305 + public Long getReceivableByContractId(Long contractId) {
  306 + return receivableMapper.selectCount(CrmReceivableDO::getContractId, contractId);
307 307 }
308 308  
309 309 }
... ...