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,6 +11,9 @@ import lombok.SneakyThrows;
11 import lombok.extern.slf4j.Slf4j; 11 import lombok.extern.slf4j.Slf4j;
12 12
13 import java.time.Duration; 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,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 * 针对 {@link #parseDictDataValue(String, String)} 的缓存 59 * 针对 {@link #parseDictDataValue(String, String)} 的缓存
43 */ 60 */
44 private static final LoadingCache<KeyValue<String, String>, DictDataRespDTO> PARSE_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache( 61 private static final LoadingCache<KeyValue<String, String>, DictDataRespDTO> PARSE_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
@@ -68,6 +85,11 @@ public class DictFrameworkUtils { @@ -68,6 +85,11 @@ public class DictFrameworkUtils {
68 } 85 }
69 86
70 @SneakyThrows 87 @SneakyThrows
  88 + public static List<String> getDictDataLabelList(String dictType) {
  89 + return GET_DICT_DATA_LIST_CACHE.get(dictType);
  90 + }
  91 +
  92 + @SneakyThrows
71 public static String parseDictDataValue(String dictType, String label) { 93 public static String parseDictDataValue(String dictType, String label) {
72 return PARSE_DICT_DATA_CACHE.get(new KeyValue<>(dictType, label)).getValue(); 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,8 +13,13 @@ import java.lang.annotation.*;
13 public @interface ExcelColumnSelect { 13 public @interface ExcelColumnSelect {
14 14
15 /** 15 /**
  16 + * @return 字典类型
  17 + */
  18 + String dictType() default "";
  19 +
  20 + /**
16 * @return 获取下拉数据源的方法名称 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 import java.util.List; 3 import java.util.List;
7 4
8 /** 5 /**
9 * Excel 列下拉数据源获取接口 6 * Excel 列下拉数据源获取接口
10 * 7 *
11 * 为什么不直接解析字典还搞个接口?考虑到有的下拉数据不是从字典中获取的所有需要做一个兼容 8 * 为什么不直接解析字典还搞个接口?考虑到有的下拉数据不是从字典中获取的所有需要做一个兼容
12 - * TODO @puhui999:是不是 @ExcelColumnSelect 可以搞两个属性,一个 dictType,一个 functionName;如果 dictType,则默认走字典,否则走 functionName  
13 - * 这样的话,ExcelColumnSelectDataService 改成 ExcelColumnSelectFunction 用于获取数据。  
14 - * 9 +
15 * @author HUIHUI 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 * @return 方法名称 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 * @return 下拉数据源 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,15 +2,19 @@ package cn.iocoder.yudao.framework.excel.core.handler;
2 2
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.map.MapUtil; 4 import cn.hutool.core.map.MapUtil;
  5 +import cn.hutool.core.util.ObjUtil;
  6 +import cn.hutool.core.util.StrUtil;
5 import cn.hutool.extra.spring.SpringUtil; 7 import cn.hutool.extra.spring.SpringUtil;
6 import cn.hutool.poi.excel.ExcelUtil; 8 import cn.hutool.poi.excel.ExcelUtil;
7 import cn.iocoder.yudao.framework.common.core.KeyValue; 9 import cn.iocoder.yudao.framework.common.core.KeyValue;
  10 +import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils;
8 import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect; 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 import com.alibaba.excel.annotation.ExcelProperty; 13 import com.alibaba.excel.annotation.ExcelProperty;
11 import com.alibaba.excel.write.handler.SheetWriteHandler; 14 import com.alibaba.excel.write.handler.SheetWriteHandler;
12 import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; 15 import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
13 import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; 16 import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
  17 +import lombok.extern.slf4j.Slf4j;
14 import org.apache.poi.hssf.usermodel.HSSFDataValidation; 18 import org.apache.poi.hssf.usermodel.HSSFDataValidation;
15 import org.apache.poi.ss.usermodel.*; 19 import org.apache.poi.ss.usermodel.*;
16 import org.apache.poi.ss.util.CellRangeAddressList; 20 import org.apache.poi.ss.util.CellRangeAddressList;
@@ -26,13 +30,9 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @@ -26,13 +30,9 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
26 * 30 *
27 * @author HUIHUI 31 * @author HUIHUI
28 */ 32 */
  33 +@Slf4j
29 public class SelectSheetWriteHandler implements SheetWriteHandler { 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 * 数据起始行从 0 开始 37 * 数据起始行从 0 开始
38 * 38 *
@@ -46,34 +46,35 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { @@ -46,34 +46,35 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
46 46
47 private static final String DICT_SHEET_NAME = "字典sheet"; 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 public SelectSheetWriteHandler(Class<?> head) { 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 if (MapUtil.isEmpty(beansMap)) { 57 if (MapUtil.isEmpty(beansMap)) {
56 return; 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 Map<String, Field> excelPropertyFields = getFieldsWithAnnotation(head, ExcelProperty.class); 63 Map<String, Field> excelPropertyFields = getFieldsWithAnnotation(head, ExcelProperty.class);
67 Map<String, Field> excelColumnSelectFields = getFieldsWithAnnotation(head, ExcelColumnSelect.class); 64 Map<String, Field> excelColumnSelectFields = getFieldsWithAnnotation(head, ExcelColumnSelect.class);
68 int colIndex = 0; 65 int colIndex = 0;
69 for (String fieldName : excelPropertyFields.keySet()) { 66 for (String fieldName : excelPropertyFields.keySet()) {
70 Field field = excelColumnSelectFields.get(fieldName); 67 Field field = excelColumnSelectFields.get(fieldName);
71 if (field != null) { 68 if (field != null) {
  69 + // ExcelProperty 有一个自定义列索引的属性 index 兼容这个字段
  70 + int index = field.getAnnotation(ExcelProperty.class).index();
  71 + if (index != -1) {
  72 + colIndex = index;
  73 + }
72 getSelectDataList(colIndex, field); 74 getSelectDataList(colIndex, field);
73 } 75 }
74 colIndex++; 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,12 +84,25 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
83 * @param field 字段 84 * @param field 字段
84 */ 85 */
85 private void getSelectDataList(int colIndex, Field field) { 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 return; 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,10 +115,11 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
101 // 1. 获取相应操作对象 115 // 1. 获取相应操作对象
102 DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper(); // 需要设置下拉框的 sheet 页的数据验证助手 116 DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper(); // 需要设置下拉框的 sheet 页的数据验证助手
103 Workbook workbook = writeWorkbookHolder.getWorkbook(); // 获得工作簿 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 // 2. 创建数据字典的 sheet 页 120 // 2. 创建数据字典的 sheet 页
106 Sheet dictSheet = workbook.createSheet(DICT_SHEET_NAME); 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 int rowLength = keyValue.getValue().size(); 123 int rowLength = keyValue.getValue().size();
109 // 2.1 设置字典 sheet 页的值 每一列一个字典项 124 // 2.1 设置字典 sheet 页的值 每一列一个字典项
110 for (int i = 0; i < rowLength; i++) { 125 for (int i = 0; i < rowLength; i++) {
@@ -126,7 +141,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { @@ -126,7 +141,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
126 KeyValue<Integer, List<String>> keyValue) { 141 KeyValue<Integer, List<String>> keyValue) {
127 // 1.1 创建可被其他单元格引用的名称 142 // 1.1 创建可被其他单元格引用的名称
128 Name name = workbook.createName(); 143 Name name = workbook.createName();
129 - String excelColumn = ALPHABET.get(keyValue.getKey()); 144 + String excelColumn = ExcelUtil.indexToColName(keyValue.getKey());
130 // 1.2 下拉框数据来源 eg:字典sheet!$B1:$B2 145 // 1.2 下拉框数据来源 eg:字典sheet!$B1:$B2
131 String refers = DICT_SHEET_NAME + "!$" + excelColumn + "$1:$" + excelColumn + "$" + keyValue.getValue().size(); 146 String refers = DICT_SHEET_NAME + "!$" + excelColumn + "$1:$" + excelColumn + "$" + keyValue.getValue().size();
132 name.setNameName("dict" + keyValue.getKey()); // 设置名称的名字 147 name.setNameName("dict" + keyValue.getKey()); // 设置名称的名字
@@ -162,18 +177,4 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { @@ -162,18 +177,4 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
162 return annotatedFields; 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 \ No newline at end of file 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,10 +4,7 @@ import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
4 import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect; 4 import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect;
5 import cn.iocoder.yudao.framework.excel.core.convert.AreaConvert; 5 import cn.iocoder.yudao.framework.excel.core.convert.AreaConvert;
6 import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; 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 import com.alibaba.excel.annotation.ExcelProperty; 8 import com.alibaba.excel.annotation.ExcelProperty;
12 import lombok.AllArgsConstructor; 9 import lombok.AllArgsConstructor;
13 import lombok.Builder; 10 import lombok.Builder;
@@ -46,7 +43,7 @@ public class CrmCustomerImportExcelVO { @@ -46,7 +43,7 @@ public class CrmCustomerImportExcelVO {
46 private String email; 43 private String email;
47 44
48 @ExcelProperty(value = "地区", converter = AreaConvert.class) 45 @ExcelProperty(value = "地区", converter = AreaConvert.class)
49 - @ExcelColumnSelect(AreaExcelColumnSelectDataServiceImpl.FUNCTION_NAME) 46 + @ExcelColumnSelect(functionName = AreaExcelColumnSelectFunctionImpl.NAME)
50 private Integer areaId; 47 private Integer areaId;
51 48
52 @ExcelProperty("详细地址") 49 @ExcelProperty("详细地址")
@@ -54,17 +51,17 @@ public class CrmCustomerImportExcelVO { @@ -54,17 +51,17 @@ public class CrmCustomerImportExcelVO {
54 51
55 @ExcelProperty(value = "所属行业", converter = DictConvert.class) 52 @ExcelProperty(value = "所属行业", converter = DictConvert.class)
56 @DictFormat(CRM_CUSTOMER_INDUSTRY) 53 @DictFormat(CRM_CUSTOMER_INDUSTRY)
57 - @ExcelColumnSelect(CrmCustomerIndustryExcelColumnSelectDataServiceImpl.FUNCTION_NAME) 54 + @ExcelColumnSelect(dictType = CRM_CUSTOMER_INDUSTRY)
58 private Integer industryId; 55 private Integer industryId;
59 56
60 @ExcelProperty(value = "客户等级", converter = DictConvert.class) 57 @ExcelProperty(value = "客户等级", converter = DictConvert.class)
61 @DictFormat(CRM_CUSTOMER_LEVEL) 58 @DictFormat(CRM_CUSTOMER_LEVEL)
62 - @ExcelColumnSelect(CrmCustomerLevelExcelColumnSelectDataServiceImpl.FUNCTION_NAME) 59 + @ExcelColumnSelect(dictType = CRM_CUSTOMER_LEVEL)
63 private Integer level; 60 private Integer level;
64 61
65 @ExcelProperty(value = "客户来源", converter = DictConvert.class) 62 @ExcelProperty(value = "客户来源", converter = DictConvert.class)
66 @DictFormat(CRM_CUSTOMER_SOURCE) 63 @DictFormat(CRM_CUSTOMER_SOURCE)
67 - @ExcelColumnSelect(CrmCustomerSourceExcelColumnSelectDataServiceImpl.FUNCTION_NAME) 64 + @ExcelColumnSelect(dictType = CRM_CUSTOMER_SOURCE)
68 private Integer source; 65 private Integer source;
69 66
70 @ExcelProperty("备注") 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 import cn.iocoder.yudao.framework.ip.core.Area; 4 import cn.iocoder.yudao.framework.ip.core.Area;
5 import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; 5 import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
6 import org.springframework.stereotype.Service; 6 import org.springframework.stereotype.Service;
@@ -13,17 +13,17 @@ import java.util.List; @@ -13,17 +13,17 @@ import java.util.List;
13 * @author HUIHUI 13 * @author HUIHUI
14 */ 14 */
15 @Service 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 @Override 20 @Override
21 - public String getFunctionName() {  
22 - return FUNCTION_NAME; 21 + public String getName() {
  22 + return NAME;
23 } 23 }
24 24
25 @Override 25 @Override
26 - public List<String> getSelectDataList() { 26 + public List<String> getOptions() {
27 // 获取地区下拉数据 27 // 获取地区下拉数据
28 // TODO @puhui999:嘿嘿,这里改成省份、城市、区域,三个选项,难度大么? 28 // TODO @puhui999:嘿嘿,这里改成省份、城市、区域,三个选项,难度大么?
29 Area area = AreaUtils.getArea(Area.ID_CHINA); 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 package cn.iocoder.yudao.module.crm.framework.excel; 1 package cn.iocoder.yudao.module.crm.framework.excel;
3 \ No newline at end of file 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,7 +229,7 @@ public class CrmContractServiceImpl implements CrmContractService {
229 // 1.1 校验存在 229 // 1.1 校验存在
230 CrmContractDO contract = validateContractExists(id); 230 CrmContractDO contract = validateContractExists(id);
231 // 1.2 如果被 CrmReceivableDO 所使用,则不允许删除 231 // 1.2 如果被 CrmReceivableDO 所使用,则不允许删除
232 - if (CollUtil.isNotEmpty(receivableService.getReceivableByContractId(contract.getId()))) { 232 + if (receivableService.getReceivableByContractId(contract.getId()) != 0) {
233 throw exception(CONTRACT_DELETE_FAIL); 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,13 +122,12 @@ public interface CrmReceivableService {
122 */ 122 */
123 Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds); 123 Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds);
124 124
125 - // TODO @puhui999:这个搞成根据数量判断,会更好一点哈;  
126 /** 125 /**
127 * 更具合同编号查询回款列表 126 * 更具合同编号查询回款列表
128 * 127 *
129 * @param contractId 合同编号 128 * @param contractId 合同编号
130 * @return 回款 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,8 +302,8 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
302 } 302 }
303 303
304 @Override 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 }