Commit fc7734319b01eb6979ac2ca5af663a57a7995dd9

Authored by YunaiV
2 parents 379bd958 720b54c3

Merge branch 'develop' of https://gitee.com/puhui999/ruoyi-vue-pro into develop

# Conflicts:
#	yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
#	yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java
Showing 20 changed files with 385 additions and 116 deletions
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/annotations/ExcelColumnSelect.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.excel.core.annotations;
  2 +
  3 +import java.lang.annotation.*;
  4 +
  5 +/**
  6 + * 给列添加下拉选择数据
  7 + *
  8 + * @author HUIHUI
  9 + */
  10 +@Target({ElementType.FIELD})
  11 +@Retention(RetentionPolicy.RUNTIME)
  12 +@Inherited
  13 +public @interface ExcelColumnSelect {
  14 +
  15 + /**
  16 + * @return 获取下拉数据源的方法名称
  17 + */
  18 + String value();
  19 +
  20 +}
... ...
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/enums/ExcelColumn.java deleted
1   -package cn.iocoder.yudao.framework.excel.core.enums;
2   -
3   -import lombok.AllArgsConstructor;
4   -import lombok.Getter;
5   -
6   -// TODO @puhui999:列表有办法通过 field name 么?主要考虑一个点,可能导入模版的顺序可能会变
7   -/**
8   - * Excel 列名枚举
9   - * 默认枚举 26 列列名如果有需求更多的列名请自行补充
10   - *
11   - * @author HUIHUI
12   - */
13   -@Getter
14   -@AllArgsConstructor
15   -public enum ExcelColumn {
16   -
17   - A(0), B(1), C(2), D(3), E(4), F(5), G(6), H(7), I(8),
18   - J(9), K(10), L(11), M(12), N(13), O(14), P(15), Q(16),
19   - R(17), S(18), T(19), U(20), V(21), W(22), X(23), Y(24),
20   - Z(25);
21   -
22   - /**
23   - * 列索引
24   - */
25   - private final int colNum;
26   -
27   -}
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java
1 1 package cn.iocoder.yudao.framework.excel.core.handler;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4   -import cn.hutool.core.lang.Assert;
  4 +import cn.hutool.core.map.MapUtil;
  5 +import cn.hutool.extra.spring.SpringUtil;
5 6 import cn.iocoder.yudao.framework.common.core.KeyValue;
6   -import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn;
  7 +import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect;
  8 +import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService;
  9 +import com.alibaba.excel.annotation.ExcelProperty;
7 10 import com.alibaba.excel.write.handler.SheetWriteHandler;
8 11 import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
9 12 import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
... ... @@ -11,10 +14,11 @@ import org.apache.poi.hssf.usermodel.HSSFDataValidation;
11 14 import org.apache.poi.ss.usermodel.*;
12 15 import org.apache.poi.ss.util.CellRangeAddressList;
13 16  
14   -import java.util.Comparator;
15   -import java.util.List;
16   -import java.util.Map;
17   -import java.util.stream.Collectors;
  17 +import java.lang.annotation.Annotation;
  18 +import java.lang.reflect.Field;
  19 +import java.util.*;
  20 +
  21 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
18 22  
19 23 /**
20 24 * 基于固定 sheet 实现下拉框
... ... @@ -23,6 +27,9 @@ import java.util.stream.Collectors;
23 27 */
24 28 public class SelectSheetWriteHandler implements SheetWriteHandler {
25 29  
  30 + private static final List<String> ALPHABET = getExcelColumnNameList();
  31 + private static final List<ExcelColumnSelectDataService> EXCEL_COLUMN_SELECT_DATA_SERVICES = new ArrayList<>();
  32 +
26 33 /**
27 34 * 数据起始行从 0 开始
28 35 *
... ... @@ -36,21 +43,46 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
36 43  
37 44 private static final String DICT_SHEET_NAME = "字典sheet";
38 45  
39   - // TODO @puhui999:Map<ExcelColumn, List<String>> 可以么?之前用 keyvalue 的原因,返回给前端,无法用 linkedhashmap,默认 key 会乱序
40   - private final List<KeyValue<ExcelColumn, List<String>>> selectMap;
  46 + private final List<KeyValue<Integer, List<String>>> selectMap = new ArrayList<>(); // 使用 List + KeyValue 组合方便排序
41 47  
42   - public SelectSheetWriteHandler(List<KeyValue<ExcelColumn, List<String>>> selectMap) {
43   - if (CollUtil.isEmpty(selectMap)) {
44   - this.selectMap = null;
  48 + public SelectSheetWriteHandler(Class<?> head) {
  49 + // 加载下拉数据获取接口
  50 + Map<String, ExcelColumnSelectDataService> beansMap = SpringUtil.getBeanFactory().getBeansOfType(ExcelColumnSelectDataService.class);
  51 + if (MapUtil.isEmpty(beansMap)) {
45 52 return;
46 53 }
47   - // 校验一下 key 是否唯一
48   - Map<String, Long> nameCounts = selectMap.stream()
49   - .collect(Collectors.groupingBy(item -> item.getKey().name(), Collectors.counting()));
50   - Assert.isFalse(nameCounts.entrySet().stream().allMatch(entry -> entry.getValue() > 1), "下拉数据 key 重复请排查!!!");
51   -
  54 + if (CollUtil.isEmpty(EXCEL_COLUMN_SELECT_DATA_SERVICES) || EXCEL_COLUMN_SELECT_DATA_SERVICES.size() != beansMap.values().size()) {
  55 + EXCEL_COLUMN_SELECT_DATA_SERVICES.clear();
  56 + EXCEL_COLUMN_SELECT_DATA_SERVICES.addAll(convertList(beansMap.values(), b -> b));
  57 + }
  58 + // 解析下拉数据
  59 + Map<String, Field> excelPropertyFields = getFieldsWithAnnotation(head, ExcelProperty.class);
  60 + Map<String, Field> excelColumnSelectFields = getFieldsWithAnnotation(head, ExcelColumnSelect.class);
  61 + int colIndex = 0;
  62 + for (String fieldName : excelPropertyFields.keySet()) {
  63 + Field field = excelColumnSelectFields.get(fieldName);
  64 + if (field != null) {
  65 + getSelectDataList(colIndex, field);
  66 + }
  67 + colIndex++;
  68 + }
52 69 selectMap.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错
53   - this.selectMap = selectMap;
  70 + }
  71 +
  72 + /**
  73 + * 获得下拉数据
  74 + *
  75 + * @param colIndex 列索引
  76 + * @param field 字段
  77 + */
  78 + private void getSelectDataList(int colIndex, Field field) {
  79 + EXCEL_COLUMN_SELECT_DATA_SERVICES.forEach(selectDataService -> {
  80 + List<String> stringList = selectDataService.handle(field.getAnnotation(ExcelColumnSelect.class).value());
  81 + if (CollUtil.isEmpty(stringList)) {
  82 + return;
  83 + }
  84 + selectMap.add(new KeyValue<>(colIndex, stringList));
  85 + });
54 86 }
55 87  
56 88 @Override
... ... @@ -65,7 +97,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
65 97  
66 98 // 2. 创建数据字典的 sheet 页
67 99 Sheet dictSheet = workbook.createSheet(DICT_SHEET_NAME);
68   - for (KeyValue<ExcelColumn, List<String>> keyValue : selectMap) {
  100 + for (KeyValue<Integer, List<String>> keyValue : selectMap) {
69 101 int rowLength = keyValue.getValue().size();
70 102 // 2.1 设置字典 sheet 页的值 每一列一个字典项
71 103 for (int i = 0; i < rowLength; i++) {
... ... @@ -73,7 +105,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
73 105 if (row == null) {
74 106 row = dictSheet.createRow(i);
75 107 }
76   - row.createCell(keyValue.getKey().getColNum()).setCellValue(keyValue.getValue().get(i));
  108 + row.createCell(keyValue.getKey()).setCellValue(keyValue.getValue().get(i));
77 109 }
78 110 // 2.2 设置单元格下拉选择
79 111 setColumnSelect(writeSheetHolder, workbook, helper, keyValue);
... ... @@ -84,10 +116,10 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
84 116 * 设置单元格下拉选择
85 117 */
86 118 private static void setColumnSelect(WriteSheetHolder writeSheetHolder, Workbook workbook, DataValidationHelper helper,
87   - KeyValue<ExcelColumn, List<String>> keyValue) {
  119 + KeyValue<Integer, List<String>> keyValue) {
88 120 // 1.1 创建可被其他单元格引用的名称
89 121 Name name = workbook.createName();
90   - String excelColumn = keyValue.getKey().name();
  122 + String excelColumn = ALPHABET.get(keyValue.getKey());
91 123 // 1.2 下拉框数据来源 eg:字典sheet!$B1:$B2
92 124 String refers = DICT_SHEET_NAME + "!$" + excelColumn + "$1:$" + excelColumn + "$" + keyValue.getValue().size();
93 125 name.setNameName("dict" + keyValue.getKey()); // 设置名称的名字
... ... @@ -97,7 +129,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
97 129 DataValidationConstraint constraint = helper.createFormulaListConstraint("dict" + keyValue.getKey()); // 设置引用约束
98 130 // 设置下拉单元格的首行、末行、首列、末列
99 131 CellRangeAddressList rangeAddressList = new CellRangeAddressList(FIRST_ROW, LAST_ROW,
100   - keyValue.getKey().getColNum(), keyValue.getKey().getColNum());
  132 + keyValue.getKey(), keyValue.getKey());
101 133 DataValidation validation = helper.createValidation(constraint, rangeAddressList);
102 134 if (validation instanceof HSSFDataValidation) {
103 135 validation.setSuppressDropDownArrow(false);
... ... @@ -112,4 +144,28 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
112 144 writeSheetHolder.getSheet().addValidationData(validation);
113 145 }
114 146  
  147 + public static Map<String, Field> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) {
  148 + Map<String, Field> annotatedFields = new LinkedHashMap<>();
  149 + Field[] fields = clazz.getDeclaredFields();
  150 + for (Field field : fields) {
  151 + if (field.isAnnotationPresent(annotationClass)) {
  152 + annotatedFields.put(field.getName(), field);
  153 + }
  154 + }
  155 + return annotatedFields;
  156 + }
  157 +
  158 +
  159 + private static List<String> getExcelColumnNameList() {
  160 + ArrayList<String> strings = new ArrayList<>();
  161 + for (int i = 1; i <= 52; i++) { // 生成 52 列名称,需要更多请重写此方法
  162 + if (i <= 26) {
  163 + strings.add(String.valueOf((char) ('A' + i - 1))); // 使用 ASCII 码值转字母
  164 + } else {
  165 + strings.add(String.valueOf((char) ('A' + (i - 1) / 26 - 1)) + (char) ('A' + (i - 1) % 26));
  166 + }
  167 + }
  168 + return strings;
  169 + }
  170 +
115 171 }
116 172 \ No newline at end of file
... ...
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/service/ExcelColumnSelectDataService.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.excel.core.service;
  2 +
  3 +import cn.hutool.core.util.StrUtil;
  4 +
  5 +import java.util.Collections;
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * Excel 列下拉数据源获取接口
  10 + *
  11 + * 为什么不直接解析字典还搞个接口?考虑到有的下拉数据不是从字典中获取的所有需要做一个兼容
  12 + *
  13 + * @author HUIHUI
  14 + */
  15 +public interface ExcelColumnSelectDataService {
  16 +
  17 + /**
  18 + * 获得方法名称
  19 + *
  20 + * @return 方法名称
  21 + */
  22 + String getFunctionName();
  23 +
  24 + /**
  25 + * 获得列下拉数据源
  26 + *
  27 + * @return 下拉数据源
  28 + */
  29 + List<String> getSelectDataList();
  30 +
  31 + default List<String> handle(String funcName) {
  32 + if (StrUtil.isEmptyIfStr(funcName) || !StrUtil.equals(getFunctionName(), funcName)) {
  33 + return Collections.emptyList();
  34 + }
  35 + return getSelectDataList();
  36 + }
  37 +
  38 +}
... ...
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java
1 1 package cn.iocoder.yudao.framework.excel.core.util;
2 2  
3   -import cn.iocoder.yudao.framework.common.core.KeyValue;
4   -import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn;
5 3 import cn.iocoder.yudao.framework.excel.core.handler.SelectSheetWriteHandler;
6 4 import com.alibaba.excel.EasyExcel;
7 5 import com.alibaba.excel.converters.longconverter.LongStringConverter;
... ... @@ -34,27 +32,11 @@ public class ExcelUtils {
34 32 */
35 33 public static <T> void write(HttpServletResponse response, String filename, String sheetName,
36 34 Class<T> head, List<T> data) throws IOException {
37   - write(response, filename, sheetName, head, data, null);
38   - }
39   -
40   - /**
41   - * 将列表以 Excel 响应给前端
42   - *
43   - * @param response 响应
44   - * @param filename 文件名
45   - * @param sheetName Excel sheet 名
46   - * @param head Excel head 头
47   - * @param data 数据列表哦
48   - * @param selectMap 下拉选择数据 Map<下拉所对应的列表名,下拉数据>
49   - * @throws IOException 写入失败的情况
50   - */
51   - public static <T> void write(HttpServletResponse response, String filename, String sheetName,
52   - Class<T> head, List<T> data, List<KeyValue<ExcelColumn, List<String>>> selectMap) throws IOException {
53 35 // 输出 Excel
54 36 EasyExcel.write(response.getOutputStream(), head)
55 37 .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理
56 38 .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 基于 column 长度,自动适配。最大 255 宽度
57   - .registerWriteHandler(new SelectSheetWriteHandler(selectMap)) // 基于固定 sheet 实现下拉框
  39 + .registerWriteHandler(new SelectSheetWriteHandler(head)) // 基于固定 sheet 实现下拉框
58 40 .registerConverter(new LongStringConverter()) // 避免 Long 类型丢失精度
59 41 .sheet(sheetName).doWrite(data);
60 42 // 设置 header 和 contentType。写在最后的原因是,避免报错时,响应 contentType 已经被修改了
... ...
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
... ... @@ -15,6 +15,7 @@ public interface ErrorCodeConstants {
15 15 ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态");
16 16 ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态");
17 17 ErrorCode CONTRACT_NO_EXISTS = new ErrorCode(1_020_000_004, "生成合同序列号重复,请重试");
  18 + ErrorCode CONTRACT_DELETE_FAIL = new ErrorCode(1_020_000_005, "删除合同失败,原因:有被回款所使用");
18 19  
19 20 // ========== 线索管理 1-020-001-000 ==========
20 21 ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
... ... @@ -40,6 +41,7 @@ public interface ErrorCodeConstants {
40 41 ErrorCode RECEIVABLE_NO_EXISTS = new ErrorCode(1_020_004_005, "生成回款序列号重复,请重试");
41 42 ErrorCode RECEIVABLE_CREATE_FAIL_CONTRACT_NOT_APPROVE = new ErrorCode(1_020_004_006, "创建回款失败,原因:合同不是审核通过状态");
42 43 ErrorCode RECEIVABLE_CREATE_FAIL_PRICE_EXCEEDS_LIMIT = new ErrorCode(1_020_004_007, "创建回款失败,原因:回款金额超出合同金额,目前剩余可退:{} 元");
  44 + ErrorCode RECEIVABLE_DELETE_FAIL_IS_APPROVE = new ErrorCode(1_020_004_008, "删除回款失败,原因:回款审批已通过");
43 45  
44 46 // ========== 回款计划 1-020-005-000 ==========
45 47 ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在");
... ...
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java
... ... @@ -142,11 +142,11 @@ public interface LogRecordConstants {
142 142  
143 143 String CRM_RECEIVABLE_TYPE = "CRM 回款";
144 144 String CRM_RECEIVABLE_CREATE_SUB_TYPE = "创建回款";
145   - String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款";
  145 + String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款";
146 146 String CRM_RECEIVABLE_UPDATE_SUB_TYPE = "更新回款";
147   - String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款: {_DIFF{#updateReqVO}}";
  147 + String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款: {_DIFF{#updateReqVO}}";
148 148 String CRM_RECEIVABLE_DELETE_SUB_TYPE = "删除回款";
149   - String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款";
  149 + String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款";
150 150 String CRM_RECEIVABLE_SUBMIT_SUB_TYPE = "提交回款审批";
151 151 String CRM_RECEIVABLE_SUBMIT_SUCCESS = "提交编号为【{{#receivableNo}}】的回款审批成功";
152 152  
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
... ... @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.map.MapUtil;
5   -import cn.iocoder.yudao.framework.common.core.KeyValue;
6 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
7 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 7 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
... ... @@ -10,9 +9,7 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
10 9 import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
11 10 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
12 11 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
13   -import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn;
14 12 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
15   -import cn.iocoder.yudao.framework.ip.core.Area;
16 13 import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
17 14 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
18 15 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*;
... ... @@ -38,7 +35,6 @@ import org.springframework.web.bind.annotation.*;
38 35  
39 36 import java.io.IOException;
40 37 import java.time.LocalDateTime;
41   -import java.util.ArrayList;
42 38 import java.util.Arrays;
43 39 import java.util.List;
44 40 import java.util.Map;
... ... @@ -49,7 +45,6 @@ import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
49 45 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
50 46 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
51 47 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
52   -import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.*;
53 48 import static java.util.Collections.singletonList;
54 49  
55 50 @Tag(name = "管理后台 - CRM 客户")
... ... @@ -265,25 +260,7 @@ public class CrmCustomerController {
265 260 .areaId(null).detailAddress("").remark("").build()
266 261 );
267 262 // 输出
268   - ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list, builderSelectMap());
269   - }
270   -
271   - private List<KeyValue<ExcelColumn, List<String>>> builderSelectMap() {
272   - List<KeyValue<ExcelColumn, List<String>>> selectMap = new ArrayList<>();
273   - // 获取地区下拉数据
274   - // TODO @puhui999:嘿嘿,这里改成省份、城市、区域,三个选项,难度大么?
275   - Area area = AreaUtils.getArea(Area.ID_CHINA);
276   - selectMap.add(new KeyValue<>(ExcelColumn.G, AreaUtils.getAreaNodePathList(area.getChildren())));
277   - // 获取客户所属行业
278   - List<String> customerIndustries = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_INDUSTRY);
279   - selectMap.add(new KeyValue<>(ExcelColumn.I, customerIndustries));
280   - // 获取客户等级
281   - List<String> customerLevels = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_LEVEL);
282   - selectMap.add(new KeyValue<>(ExcelColumn.J, customerLevels));
283   - // 获取客户来源
284   - List<String> customerSources = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_SOURCE);
285   - selectMap.add(new KeyValue<>(ExcelColumn.K, customerSources));
286   - return selectMap;
  263 + ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list);
287 264 }
288 265  
289 266 @PostMapping("/import")
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer;
2 2  
3 3 import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect;
4 5 import cn.iocoder.yudao.framework.excel.core.convert.AreaConvert;
5 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;
6 11 import com.alibaba.excel.annotation.ExcelProperty;
7 12 import lombok.AllArgsConstructor;
8 13 import lombok.Builder;
... ... @@ -41,6 +46,7 @@ public class CrmCustomerImportExcelVO {
41 46 private String email;
42 47  
43 48 @ExcelProperty(value = "地区", converter = AreaConvert.class)
  49 + @ExcelColumnSelect(AreaExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
44 50 private Integer areaId;
45 51  
46 52 @ExcelProperty("详细地址")
... ... @@ -48,14 +54,17 @@ public class CrmCustomerImportExcelVO {
48 54  
49 55 @ExcelProperty(value = "所属行业", converter = DictConvert.class)
50 56 @DictFormat(CRM_CUSTOMER_INDUSTRY)
  57 + @ExcelColumnSelect(CrmCustomerIndustryExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
51 58 private Integer industryId;
52 59  
53 60 @ExcelProperty(value = "客户等级", converter = DictConvert.class)
54 61 @DictFormat(CRM_CUSTOMER_LEVEL)
  62 + @ExcelColumnSelect(CrmCustomerLevelExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
55 63 private Integer level;
56 64  
57 65 @ExcelProperty(value = "客户来源", converter = DictConvert.class)
58 66 @DictFormat(CRM_CUSTOMER_SOURCE)
  67 + @ExcelColumnSelect(CrmCustomerSourceExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
59 68 private Integer source;
60 69  
61 70 @ExcelProperty("备注")
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanRespVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan;
2 2  
3 3 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
  4 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
4 5 import com.alibaba.excel.annotation.ExcelProperty;
5 6 import io.swagger.v3.oas.annotations.media.Schema;
6 7 import lombok.Data;
... ... @@ -8,53 +9,69 @@ import lombok.Data;
8 9 import java.math.BigDecimal;
9 10 import java.time.LocalDateTime;
10 11  
11   -// TODO @puhui999:缺导出
12 12 @Schema(description = "管理后台 - CRM 回款计划 Response VO")
13 13 @Data
  14 +@ExcelIgnoreUnannotated
14 15 public class CrmReceivablePlanRespVO {
15 16  
16 17 @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  18 + @ExcelProperty("编号")
17 19 private Long id;
18 20  
19 21 @Schema(description = "期数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  22 + @ExcelProperty("期数")
20 23 private Integer period;
21 24  
22 25 @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  26 + @ExcelProperty("客户编号")
23 27 private Long customerId;
24 28 @Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
  29 + @ExcelProperty("客户名字")
25 30 private String customerName;
26 31  
27 32 @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  33 + @ExcelProperty("合同编号")
28 34 private Long contractId;
29 35 @Schema(description = "合同编号", example = "Q110")
  36 + @ExcelProperty("合同编号")
30 37 private String contractNo;
31 38  
32 39 @Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  40 + @ExcelProperty("负责人编号")
33 41 private Long ownerUserId;
34 42 @Schema(description = "负责人", example = "test")
  43 + @ExcelProperty("负责人")
35 44 private String ownerUserName;
36 45  
37 46 @Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
  47 + @ExcelProperty("计划回款日期")
38 48 private LocalDateTime returnTime;
39 49  
40 50 @Schema(description = "计划回款方式", example = "1")
  51 + @ExcelProperty("计划回款方式")
41 52 private Integer returnType;
42 53  
43 54 @Schema(description = "计划回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000")
  55 + @ExcelProperty("计划回款金额")
44 56 private BigDecimal price;
45 57  
46 58 @Schema(description = "回款编号", example = "19852")
  59 + @ExcelProperty("回款编号")
47 60 private Long receivableId;
48 61 @Schema(description = "回款信息")
  62 + @ExcelProperty("回款信息")
49 63 private CrmReceivableRespVO receivable;
50 64  
51 65 @Schema(description = "提前几天提醒", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  66 + @ExcelProperty("提前几天提醒")
52 67 private Integer remindDays;
53 68  
54 69 @Schema(description = "提醒日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
  70 + @ExcelProperty("提醒日期")
55 71 private LocalDateTime remindTime;
56 72  
57 73 @Schema(description = "备注", example = "备注")
  74 + @ExcelProperty("备注")
58 75 private String remark;
59 76  
60 77 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/receivable/CrmReceivableRespVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable;
2 2  
3 3 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
  4 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
4 5 import com.alibaba.excel.annotation.ExcelProperty;
5 6 import io.swagger.v3.oas.annotations.media.Schema;
6 7 import lombok.Data;
... ... @@ -8,37 +9,47 @@ import lombok.Data;
8 9 import java.math.BigDecimal;
9 10 import java.time.LocalDateTime;
10 11  
11   -// TODO 芋艿:导出的 VO,可以考虑使用 @Excel 注解,实现导出功能
12 12 @Schema(description = "管理后台 - CRM 回款 Response VO")
13 13 @Data
  14 +@ExcelIgnoreUnannotated
14 15 public class CrmReceivableRespVO {
15 16  
16 17 @Schema(description = "编号", example = "25787")
  18 + @ExcelProperty("编号")
17 19 private Long id;
18 20  
19 21 @Schema(description = "回款编号", example = "31177")
  22 + @ExcelProperty("回款编号")
20 23 private String no;
21 24  
22 25 @Schema(description = "回款计划编号", example = "1024")
  26 + @ExcelProperty("回款计划编号")
23 27 private Long planId;
24 28  
25 29 @Schema(description = "回款方式", example = "2")
  30 + @ExcelProperty("回款方式")
26 31 private Integer returnType;
27 32  
28 33 @Schema(description = "回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000")
  34 + @ExcelProperty("回款金额")
29 35 private BigDecimal price;
30 36  
31 37 @Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
  38 + @ExcelProperty("计划回款日期")
32 39 private LocalDateTime returnTime;
33 40  
34 41 @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  42 + @ExcelProperty("客户编号")
35 43 private Long customerId;
36 44 @Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
  45 + @ExcelProperty("客户名字")
37 46 private String customerName;
38 47  
39 48 @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  49 + @ExcelProperty("合同编号")
40 50 private Long contractId;
41 51 @Schema(description = "合同信息")
  52 + @ExcelProperty("合同信息")
42 53 private CrmContractRespVO contract;
43 54  
44 55 @Schema(description = "负责人的用户编号", example = "25682")
... ... @@ -56,20 +67,26 @@ public class CrmReceivableRespVO {
56 67 private String processInstanceId;
57 68  
58 69 @Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
  70 + @ExcelProperty("审批状态")
59 71 private Integer auditStatus;
60 72  
61   - @Schema(description = "备注", example = "备注")
  73 + @Schema(description = "工作流编号", example = "备注")
  74 + @ExcelProperty("工作流编号")
62 75 private String remark;
63 76  
64 77 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  78 + @ExcelProperty("创建时间")
65 79 private LocalDateTime createTime;
66 80  
67 81 @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
  82 + @ExcelProperty("更新时间")
68 83 private LocalDateTime updateTime;
69 84  
70 85 @Schema(description = "创建人", example = "25682")
  86 + @ExcelProperty("创建人")
71 87 private String creator;
72 88 @Schema(description = "创建人名字", example = "test")
  89 + @ExcelProperty("创建人名字")
73 90 private String creatorName;
74 91  
75 92 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.framework.excel;
0 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/AreaExcelColumnSelectDataServiceImpl.java 0 → 100644
  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.framework.ip.core.Area;
  5 +import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
  6 +import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
  7 +import jakarta.annotation.Resource;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * Excel 所属地区列下拉数据源获取接口实现类
  14 + *
  15 + * @author HUIHUI
  16 + */
  17 +@Service
  18 +public class AreaExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService {
  19 +
  20 + public static final String FUNCTION_NAME = "getCrmAreaNameList"; // 防止和别的模块重名
  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 + // 获取地区下拉数据
  33 + // TODO @puhui999:嘿嘿,这里改成省份、城市、区域,三个选项,难度大么?
  34 + Area area = AreaUtils.parseArea(Area.ID_CHINA);
  35 + return AreaUtils.getAreaNodePathList(area.getChildren());
  36 + }
  37 +
  38 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/service/CrmCustomerIndustryExcelColumnSelectDataServiceImpl.java 0 → 100644
  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 0 → 100644
  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 0 → 100644
  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
... ... @@ -30,12 +30,14 @@ import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
30 30 import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
31 31 import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
32 32 import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
  33 +import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
33 34 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
34 35 import com.mzt.logapi.context.LogRecordContext;
35 36 import com.mzt.logapi.service.impl.DiffParseFunction;
36 37 import com.mzt.logapi.starter.annotation.LogRecord;
37 38 import jakarta.annotation.Resource;
38 39 import lombok.extern.slf4j.Slf4j;
  40 +import org.springframework.context.annotation.Lazy;
39 41 import org.springframework.stereotype.Service;
40 42 import org.springframework.transaction.annotation.Transactional;
41 43 import org.springframework.validation.annotation.Validated;
... ... @@ -86,7 +88,9 @@ public class CrmContractServiceImpl implements CrmContractService {
86 88 private CrmContactService contactService;
87 89 @Resource
88 90 private CrmContractConfigService contractConfigService;
89   -
  91 + @Resource
  92 + @Lazy // 延迟加载,避免循环依赖
  93 + private CrmReceivableService receivableService;
90 94 @Resource
91 95 private AdminUserApi adminUserApi;
92 96 @Resource
... ... @@ -222,9 +226,12 @@ public class CrmContractServiceImpl implements CrmContractService {
222 226 success = CRM_CONTRACT_DELETE_SUCCESS)
223 227 @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
224 228 public void deleteContract(Long id) {
225   - // TODO @puhui999:如果被 CrmReceivableDO 所使用,则不允许删除
226 229 // 校验存在
227 230 CrmContractDO contract = validateContractExists(id);
  231 + // 如果被 CrmReceivableDO 所使用,则不允许删除
  232 + if (CollUtil.isNotEmpty(receivableService.getReceivableByContractId(contract.getId()))) {
  233 + throw exception(CONTRACT_DELETE_FAIL);
  234 + }
228 235 // 删除
229 236 contractMapper.deleteById(id);
230 237 // 删除数据权限
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java
... ... @@ -122,4 +122,12 @@ public interface CrmReceivableService {
122 122 */
123 123 Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds);
124 124  
  125 + /**
  126 + * 更具合同编号查询回款列表
  127 + *
  128 + * @param contractId 合同编号
  129 + * @return 回款
  130 + */
  131 + List<CrmReceivableDO> getReceivableByContractId(Long contractId);
  132 +
125 133 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java
... ... @@ -37,10 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
37 37 import org.springframework.validation.annotation.Validated;
38 38  
39 39 import java.math.BigDecimal;
40   -import java.util.Arrays;
41   -import java.util.Collection;
42   -import java.util.List;
43   -import java.util.Map;
  40 +import java.util.*;
44 41  
45 42 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
46 43 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
... ... @@ -81,7 +78,6 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
81 78 @Resource
82 79 private BpmProcessInstanceApi bpmProcessInstanceApi;
83 80  
84   - // TODO @puhui999:操作日志没记录上
85 81 @Override
86 82 @Transactional(rollbackFor = Exception.class)
87 83 @LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_CREATE_SUB_TYPE, bizNo = "{{#receivable.id}}",
... ... @@ -115,6 +111,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
115 111  
116 112 // 5. 记录操作日志上下文
117 113 LogRecordContext.putVariable("receivable", receivable);
  114 + LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
118 115 return receivable.getId();
119 116 }
120 117  
... ... @@ -156,7 +153,6 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
156 153 }
157 154 }
158 155  
159   - // TODO @puhui999:操作日志没记录上
160 156 @Override
161 157 @Transactional(rollbackFor = Exception.class)
162 158 @LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
... ... @@ -164,11 +160,14 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
164 160 @CrmPermission(bizType = CrmBizTypeEnum.CRM_RECEIVABLE, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
165 161 public void updateReceivable(CrmReceivableSaveReqVO updateReqVO) {
166 162 Assert.notNull(updateReqVO.getId(), "回款编号不能为空");
167   - // 1.1 校验可回款金额超过上限
168   - validateReceivablePriceExceedsLimit(updateReqVO);
169 163 updateReqVO.setOwnerUserId(null).setCustomerId(null).setContractId(null).setPlanId(null); // 不允许修改的字段
170   - // 1.2 校验存在
  164 + // 1.1 校验存在
171 165 CrmReceivableDO receivable = validateReceivableExists(updateReqVO.getId());
  166 + updateReqVO.setOwnerUserId(receivable.getOwnerUserId()).setCustomerId(receivable.getCustomerId())
  167 + .setContractId(receivable.getContractId()).setPlanId(receivable.getPlanId()); // 设置已存在的值
  168 + // 1.2 校验可回款金额超过上限
  169 + validateReceivablePriceExceedsLimit(updateReqVO);
  170 +
172 171 // 1.3 只有草稿、审批中,可以编辑;
173 172 if (!ObjectUtils.equalsAny(receivable.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus(),
174 173 CrmAuditStatusEnum.PROCESS.getStatus())) {
... ... @@ -180,8 +179,17 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
180 179 receivableMapper.updateById(updateObj);
181 180  
182 181 // 3. 记录操作日志上下文
183   - LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(receivable, CrmReceivableSaveReqVO.class));
184 182 LogRecordContext.putVariable("receivable", receivable);
  183 + LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
  184 + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(receivable, CrmReceivableSaveReqVO.class));
  185 + }
  186 +
  187 + private Integer getReceivablePeriod(Long planId) {
  188 + if (Objects.isNull(planId)) {
  189 + return null;
  190 + }
  191 + CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(planId);
  192 + return receivablePlan.getPeriod();
185 193 }
186 194  
187 195 @Override
... ... @@ -212,8 +220,10 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
212 220 if (receivable.getPlanId() != null && receivablePlanService.getReceivablePlan(receivable.getPlanId()) != null) {
213 221 throw exception(RECEIVABLE_DELETE_FAIL);
214 222 }
215   - // TODO @puhui999:审批通过时,不允许删除;
216   -
  223 + // 1.3 审批通过时,不允许删除
  224 + if (ObjUtil.equal(receivable.getAuditStatus(), CrmAuditStatusEnum.APPROVE.getStatus())) {
  225 + throw exception(RECEIVABLE_DELETE_FAIL_IS_APPROVE);
  226 + }
217 227 // 2. 删除
218 228 receivableMapper.deleteById(id);
219 229 // 3. 删除数据权限
... ... @@ -221,6 +231,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
221 231  
222 232 // 4. 记录操作日志上下文
223 233 LogRecordContext.putVariable("receivable", receivable);
  234 + LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
224 235 }
225 236  
226 237 @Override
... ... @@ -289,4 +300,9 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
289 300 return receivableMapper.selectReceivablePriceMapByContractId(contractIds);
290 301 }
291 302  
  303 + @Override
  304 + public List<CrmReceivableDO> getReceivableByContractId(Long contractId) {
  305 + return receivableMapper.selectList(CrmReceivableDO::getContractId, contractId);
  306 + }
  307 +
292 308 }
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm
... ... @@ -94,7 +94,7 @@ const { t } = useI18n() // 国际化
94 94 const message = useMessage() // 消息弹窗
95 95  
96 96 const props = defineProps<{
97   - ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)
  97 + ${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段)
98 98 }>()
99 99 const loading = ref(false) // 列表的加载中
100 100 const list = ref([]) // 列表的数据
... ... @@ -103,17 +103,20 @@ const total = ref(0) // 列表的总页数
103 103 const queryParams = reactive({
104 104 pageNo: 1,
105 105 pageSize: 10,
106   - ${subJoinColumn.javaField}: undefined
  106 + ${subJoinColumn.javaField}: undefined as unknown
107 107 })
108 108  
109 109 /** 监听主表的关联字段的变化,加载对应的子表数据 */
110 110 watch(
111 111 () => props.${subJoinColumn.javaField},
112   - (val) => {
  112 + (val: number) => {
  113 + if (!val) {
  114 + return
  115 + }
113 116 queryParams.${subJoinColumn.javaField} = val
114 117 handleQuery()
115 118 },
116   - { immediate: false }
  119 + { immediate: true, deep: true }
117 120 )
118 121 #end
119 122  
... ...