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
This commit is contained in:
YunaiV 2024-03-01 23:46:50 +08:00
commit fc7734319b
20 changed files with 385 additions and 116 deletions

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.framework.excel.core.annotations;
import java.lang.annotation.*;
/**
* 给列添加下拉选择数据
*
* @author HUIHUI
*/
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ExcelColumnSelect {
/**
* @return 获取下拉数据源的方法名称
*/
String value();
}

View File

@ -1,27 +0,0 @@
package cn.iocoder.yudao.framework.excel.core.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
// TODO @puhui999列表有办法通过 field name 主要考虑一个点可能导入模版的顺序可能会变
/**
* Excel 列名枚举
* 默认枚举 26 列列名如果有需求更多的列名请自行补充
*
* @author HUIHUI
*/
@Getter
@AllArgsConstructor
public enum ExcelColumn {
A(0), B(1), C(2), D(3), E(4), F(5), G(6), H(7), I(8),
J(9), K(10), L(11), M(12), N(13), O(14), P(15), Q(16),
R(17), S(18), T(19), U(20), V(21), W(22), X(23), Y(24),
Z(25);
/**
* 列索引
*/
private final int colNum;
}

View File

@ -1,9 +1,12 @@
package cn.iocoder.yudao.framework.excel.core.handler; package cn.iocoder.yudao.framework.excel.core.handler;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.map.MapUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn; import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect;
import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.write.handler.SheetWriteHandler; import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
@ -11,10 +14,11 @@ import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.ss.util.CellRangeAddressList;
import java.util.Comparator; import java.lang.annotation.Annotation;
import java.util.List; import java.lang.reflect.Field;
import java.util.Map; import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
/** /**
* 基于固定 sheet 实现下拉框 * 基于固定 sheet 实现下拉框
@ -23,6 +27,9 @@ import java.util.stream.Collectors;
*/ */
public class SelectSheetWriteHandler implements SheetWriteHandler { public class SelectSheetWriteHandler implements SheetWriteHandler {
private static final List<String> ALPHABET = getExcelColumnNameList();
private static final List<ExcelColumnSelectDataService> EXCEL_COLUMN_SELECT_DATA_SERVICES = new ArrayList<>();
/** /**
* 数据起始行从 0 开始 * 数据起始行从 0 开始
* *
@ -36,21 +43,46 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
private static final String DICT_SHEET_NAME = "字典sheet"; private static final String DICT_SHEET_NAME = "字典sheet";
// TODO @puhui999Map<ExcelColumn, List<String>> 可以么之前用 keyvalue 的原因返回给前端无法用 linkedhashmap默认 key 会乱序 private final List<KeyValue<Integer, List<String>>> selectMap = new ArrayList<>(); // 使用 List + KeyValue 组合方便排序
private final List<KeyValue<ExcelColumn, List<String>>> selectMap;
public SelectSheetWriteHandler(List<KeyValue<ExcelColumn, List<String>>> selectMap) { public SelectSheetWriteHandler(Class<?> head) {
if (CollUtil.isEmpty(selectMap)) { // 加载下拉数据获取接口
this.selectMap = null; Map<String, ExcelColumnSelectDataService> beansMap = SpringUtil.getBeanFactory().getBeansOfType(ExcelColumnSelectDataService.class);
if (MapUtil.isEmpty(beansMap)) {
return; return;
} }
// 校验一下 key 是否唯一 if (CollUtil.isEmpty(EXCEL_COLUMN_SELECT_DATA_SERVICES) || EXCEL_COLUMN_SELECT_DATA_SERVICES.size() != beansMap.values().size()) {
Map<String, Long> nameCounts = selectMap.stream() EXCEL_COLUMN_SELECT_DATA_SERVICES.clear();
.collect(Collectors.groupingBy(item -> item.getKey().name(), Collectors.counting())); EXCEL_COLUMN_SELECT_DATA_SERVICES.addAll(convertList(beansMap.values(), b -> b));
Assert.isFalse(nameCounts.entrySet().stream().allMatch(entry -> entry.getValue() > 1), "下拉数据 key 重复请排查!!!"); }
// 解析下拉数据
Map<String, Field> excelPropertyFields = getFieldsWithAnnotation(head, ExcelProperty.class);
Map<String, Field> excelColumnSelectFields = getFieldsWithAnnotation(head, ExcelColumnSelect.class);
int colIndex = 0;
for (String fieldName : excelPropertyFields.keySet()) {
Field field = excelColumnSelectFields.get(fieldName);
if (field != null) {
getSelectDataList(colIndex, field);
}
colIndex++;
}
selectMap.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错 selectMap.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错
this.selectMap = selectMap; }
/**
* 获得下拉数据
*
* @param colIndex 列索引
* @param field 字段
*/
private void getSelectDataList(int colIndex, Field field) {
EXCEL_COLUMN_SELECT_DATA_SERVICES.forEach(selectDataService -> {
List<String> stringList = selectDataService.handle(field.getAnnotation(ExcelColumnSelect.class).value());
if (CollUtil.isEmpty(stringList)) {
return;
}
selectMap.add(new KeyValue<>(colIndex, stringList));
});
} }
@Override @Override
@ -65,7 +97,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
// 2. 创建数据字典的 sheet // 2. 创建数据字典的 sheet
Sheet dictSheet = workbook.createSheet(DICT_SHEET_NAME); Sheet dictSheet = workbook.createSheet(DICT_SHEET_NAME);
for (KeyValue<ExcelColumn, List<String>> keyValue : selectMap) { for (KeyValue<Integer, List<String>> keyValue : selectMap) {
int rowLength = keyValue.getValue().size(); int rowLength = keyValue.getValue().size();
// 2.1 设置字典 sheet 页的值 每一列一个字典项 // 2.1 设置字典 sheet 页的值 每一列一个字典项
for (int i = 0; i < rowLength; i++) { for (int i = 0; i < rowLength; i++) {
@ -73,7 +105,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
if (row == null) { if (row == null) {
row = dictSheet.createRow(i); row = dictSheet.createRow(i);
} }
row.createCell(keyValue.getKey().getColNum()).setCellValue(keyValue.getValue().get(i)); row.createCell(keyValue.getKey()).setCellValue(keyValue.getValue().get(i));
} }
// 2.2 设置单元格下拉选择 // 2.2 设置单元格下拉选择
setColumnSelect(writeSheetHolder, workbook, helper, keyValue); setColumnSelect(writeSheetHolder, workbook, helper, keyValue);
@ -84,10 +116,10 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
* 设置单元格下拉选择 * 设置单元格下拉选择
*/ */
private static void setColumnSelect(WriteSheetHolder writeSheetHolder, Workbook workbook, DataValidationHelper helper, private static void setColumnSelect(WriteSheetHolder writeSheetHolder, Workbook workbook, DataValidationHelper helper,
KeyValue<ExcelColumn, List<String>> keyValue) { KeyValue<Integer, List<String>> keyValue) {
// 1.1 创建可被其他单元格引用的名称 // 1.1 创建可被其他单元格引用的名称
Name name = workbook.createName(); Name name = workbook.createName();
String excelColumn = keyValue.getKey().name(); String excelColumn = ALPHABET.get(keyValue.getKey());
// 1.2 下拉框数据来源 eg:字典sheet!$B1:$B2 // 1.2 下拉框数据来源 eg:字典sheet!$B1:$B2
String refers = DICT_SHEET_NAME + "!$" + excelColumn + "$1:$" + excelColumn + "$" + keyValue.getValue().size(); String refers = DICT_SHEET_NAME + "!$" + excelColumn + "$1:$" + excelColumn + "$" + keyValue.getValue().size();
name.setNameName("dict" + keyValue.getKey()); // 设置名称的名字 name.setNameName("dict" + keyValue.getKey()); // 设置名称的名字
@ -97,7 +129,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
DataValidationConstraint constraint = helper.createFormulaListConstraint("dict" + keyValue.getKey()); // 设置引用约束 DataValidationConstraint constraint = helper.createFormulaListConstraint("dict" + keyValue.getKey()); // 设置引用约束
// 设置下拉单元格的首行末行首列末列 // 设置下拉单元格的首行末行首列末列
CellRangeAddressList rangeAddressList = new CellRangeAddressList(FIRST_ROW, LAST_ROW, CellRangeAddressList rangeAddressList = new CellRangeAddressList(FIRST_ROW, LAST_ROW,
keyValue.getKey().getColNum(), keyValue.getKey().getColNum()); keyValue.getKey(), keyValue.getKey());
DataValidation validation = helper.createValidation(constraint, rangeAddressList); DataValidation validation = helper.createValidation(constraint, rangeAddressList);
if (validation instanceof HSSFDataValidation) { if (validation instanceof HSSFDataValidation) {
validation.setSuppressDropDownArrow(false); validation.setSuppressDropDownArrow(false);
@ -112,4 +144,28 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
writeSheetHolder.getSheet().addValidationData(validation); writeSheetHolder.getSheet().addValidationData(validation);
} }
public static Map<String, Field> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) {
Map<String, Field> annotatedFields = new LinkedHashMap<>();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(annotationClass)) {
annotatedFields.put(field.getName(), field);
}
}
return annotatedFields;
}
private static List<String> getExcelColumnNameList() {
ArrayList<String> 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;
}
} }

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.framework.excel.core.service;
import cn.hutool.core.util.StrUtil;
import java.util.Collections;
import java.util.List;
/**
* Excel 列下拉数据源获取接口
*
* 为什么不直接解析字典还搞个接口考虑到有的下拉数据不是从字典中获取的所有需要做一个兼容
*
* @author HUIHUI
*/
public interface ExcelColumnSelectDataService {
/**
* 获得方法名称
*
* @return 方法名称
*/
String getFunctionName();
/**
* 获得列下拉数据源
*
* @return 下拉数据源
*/
List<String> getSelectDataList();
default List<String> handle(String funcName) {
if (StrUtil.isEmptyIfStr(funcName) || !StrUtil.equals(getFunctionName(), funcName)) {
return Collections.emptyList();
}
return getSelectDataList();
}
}

View File

@ -1,7 +1,5 @@
package cn.iocoder.yudao.framework.excel.core.util; package cn.iocoder.yudao.framework.excel.core.util;
import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn;
import cn.iocoder.yudao.framework.excel.core.handler.SelectSheetWriteHandler; import cn.iocoder.yudao.framework.excel.core.handler.SelectSheetWriteHandler;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.converters.longconverter.LongStringConverter; import com.alibaba.excel.converters.longconverter.LongStringConverter;
@ -34,27 +32,11 @@ public class ExcelUtils {
*/ */
public static <T> void write(HttpServletResponse response, String filename, String sheetName, public static <T> void write(HttpServletResponse response, String filename, String sheetName,
Class<T> head, List<T> data) throws IOException { Class<T> head, List<T> data) throws IOException {
write(response, filename, sheetName, head, data, null);
}
/**
* 将列表以 Excel 响应给前端
*
* @param response 响应
* @param filename 文件名
* @param sheetName Excel sheet
* @param head Excel head
* @param data 数据列表哦
* @param selectMap 下拉选择数据 Map<下拉所对应的列表名下拉数据>
* @throws IOException 写入失败的情况
*/
public static <T> void write(HttpServletResponse response, String filename, String sheetName,
Class<T> head, List<T> data, List<KeyValue<ExcelColumn, List<String>>> selectMap) throws IOException {
// 输出 Excel // 输出 Excel
EasyExcel.write(response.getOutputStream(), head) EasyExcel.write(response.getOutputStream(), head)
.autoCloseStream(false) // 不要自动关闭交给 Servlet 自己处理 .autoCloseStream(false) // 不要自动关闭交给 Servlet 自己处理
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 基于 column 长度自动适配最大 255 宽度 .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 基于 column 长度自动适配最大 255 宽度
.registerWriteHandler(new SelectSheetWriteHandler(selectMap)) // 基于固定 sheet 实现下拉框 .registerWriteHandler(new SelectSheetWriteHandler(head)) // 基于固定 sheet 实现下拉框
.registerConverter(new LongStringConverter()) // 避免 Long 类型丢失精度 .registerConverter(new LongStringConverter()) // 避免 Long 类型丢失精度
.sheet(sheetName).doWrite(data); .sheet(sheetName).doWrite(data);
// 设置 header contentType写在最后的原因是避免报错时响应 contentType 已经被修改了 // 设置 header contentType写在最后的原因是避免报错时响应 contentType 已经被修改了

View File

@ -15,6 +15,7 @@ public interface ErrorCodeConstants {
ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态"); ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态");
ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态"); ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态");
ErrorCode CONTRACT_NO_EXISTS = new ErrorCode(1_020_000_004, "生成合同序列号重复,请重试"); ErrorCode CONTRACT_NO_EXISTS = new ErrorCode(1_020_000_004, "生成合同序列号重复,请重试");
ErrorCode CONTRACT_DELETE_FAIL = new ErrorCode(1_020_000_005, "删除合同失败,原因:有被回款所使用");
// ========== 线索管理 1-020-001-000 ========== // ========== 线索管理 1-020-001-000 ==========
ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
@ -40,6 +41,7 @@ public interface ErrorCodeConstants {
ErrorCode RECEIVABLE_NO_EXISTS = new ErrorCode(1_020_004_005, "生成回款序列号重复,请重试"); ErrorCode RECEIVABLE_NO_EXISTS = new ErrorCode(1_020_004_005, "生成回款序列号重复,请重试");
ErrorCode RECEIVABLE_CREATE_FAIL_CONTRACT_NOT_APPROVE = new ErrorCode(1_020_004_006, "创建回款失败,原因:合同不是审核通过状态"); ErrorCode RECEIVABLE_CREATE_FAIL_CONTRACT_NOT_APPROVE = new ErrorCode(1_020_004_006, "创建回款失败,原因:合同不是审核通过状态");
ErrorCode RECEIVABLE_CREATE_FAIL_PRICE_EXCEEDS_LIMIT = new ErrorCode(1_020_004_007, "创建回款失败,原因:回款金额超出合同金额,目前剩余可退:{} 元"); ErrorCode RECEIVABLE_CREATE_FAIL_PRICE_EXCEEDS_LIMIT = new ErrorCode(1_020_004_007, "创建回款失败,原因:回款金额超出合同金额,目前剩余可退:{} 元");
ErrorCode RECEIVABLE_DELETE_FAIL_IS_APPROVE = new ErrorCode(1_020_004_008, "删除回款失败,原因:回款审批已通过");
// ========== 回款计划 1-020-005-000 ========== // ========== 回款计划 1-020-005-000 ==========
ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在"); ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在");

View File

@ -142,11 +142,11 @@ public interface LogRecordConstants {
String CRM_RECEIVABLE_TYPE = "CRM 回款"; String CRM_RECEIVABLE_TYPE = "CRM 回款";
String CRM_RECEIVABLE_CREATE_SUB_TYPE = "创建回款"; String CRM_RECEIVABLE_CREATE_SUB_TYPE = "创建回款";
String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款"; String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款";
String CRM_RECEIVABLE_UPDATE_SUB_TYPE = "更新回款"; String CRM_RECEIVABLE_UPDATE_SUB_TYPE = "更新回款";
String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款: {_DIFF{#updateReqVO}}"; String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款: {_DIFF{#updateReqVO}}";
String CRM_RECEIVABLE_DELETE_SUB_TYPE = "删除回款"; String CRM_RECEIVABLE_DELETE_SUB_TYPE = "删除回款";
String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款"; String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款";
String CRM_RECEIVABLE_SUBMIT_SUB_TYPE = "提交回款审批"; String CRM_RECEIVABLE_SUBMIT_SUB_TYPE = "提交回款审批";
String CRM_RECEIVABLE_SUBMIT_SUCCESS = "提交编号为【{{#receivableNo}}】的回款审批成功"; String CRM_RECEIVABLE_SUBMIT_SUCCESS = "提交编号为【{{#receivableNo}}】的回款审批成功";

View File

@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
@ -10,9 +9,7 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.enums.ExcelColumn;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*;
@ -38,7 +35,6 @@ import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -49,7 +45,6 @@ import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.*;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
@Tag(name = "管理后台 - CRM 客户") @Tag(name = "管理后台 - CRM 客户")
@ -265,25 +260,7 @@ public class CrmCustomerController {
.areaId(null).detailAddress("").remark("").build() .areaId(null).detailAddress("").remark("").build()
); );
// 输出 // 输出
ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list, builderSelectMap()); ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list);
}
private List<KeyValue<ExcelColumn, List<String>>> builderSelectMap() {
List<KeyValue<ExcelColumn, List<String>>> selectMap = new ArrayList<>();
// 获取地区下拉数据
// TODO @puhui999嘿嘿这里改成省份城市区域三个选项难度大么
Area area = AreaUtils.getArea(Area.ID_CHINA);
selectMap.add(new KeyValue<>(ExcelColumn.G, AreaUtils.getAreaNodePathList(area.getChildren())));
// 获取客户所属行业
List<String> customerIndustries = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_INDUSTRY);
selectMap.add(new KeyValue<>(ExcelColumn.I, customerIndustries));
// 获取客户等级
List<String> customerLevels = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_LEVEL);
selectMap.add(new KeyValue<>(ExcelColumn.J, customerLevels));
// 获取客户来源
List<String> customerSources = dictDataApi.getDictDataLabelList(CRM_CUSTOMER_SOURCE);
selectMap.add(new KeyValue<>(ExcelColumn.K, customerSources));
return selectMap;
} }
@PostMapping("/import") @PostMapping("/import")

View File

@ -1,8 +1,13 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer; package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; 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.AreaConvert;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; 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 com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@ -41,6 +46,7 @@ public class CrmCustomerImportExcelVO {
private String email; private String email;
@ExcelProperty(value = "地区", converter = AreaConvert.class) @ExcelProperty(value = "地区", converter = AreaConvert.class)
@ExcelColumnSelect(AreaExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
private Integer areaId; private Integer areaId;
@ExcelProperty("详细地址") @ExcelProperty("详细地址")
@ -48,14 +54,17 @@ public class CrmCustomerImportExcelVO {
@ExcelProperty(value = "所属行业", converter = DictConvert.class) @ExcelProperty(value = "所属行业", converter = DictConvert.class)
@DictFormat(CRM_CUSTOMER_INDUSTRY) @DictFormat(CRM_CUSTOMER_INDUSTRY)
@ExcelColumnSelect(CrmCustomerIndustryExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
private Integer industryId; private Integer industryId;
@ExcelProperty(value = "客户等级", converter = DictConvert.class) @ExcelProperty(value = "客户等级", converter = DictConvert.class)
@DictFormat(CRM_CUSTOMER_LEVEL) @DictFormat(CRM_CUSTOMER_LEVEL)
@ExcelColumnSelect(CrmCustomerLevelExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
private Integer level; private Integer level;
@ExcelProperty(value = "客户来源", converter = DictConvert.class) @ExcelProperty(value = "客户来源", converter = DictConvert.class)
@DictFormat(CRM_CUSTOMER_SOURCE) @DictFormat(CRM_CUSTOMER_SOURCE)
@ExcelColumnSelect(CrmCustomerSourceExcelColumnSelectDataServiceImpl.FUNCTION_NAME)
private Integer source; private Integer source;
@ExcelProperty("备注") @ExcelProperty("备注")

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan; package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO; import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -8,53 +9,69 @@ import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
// TODO @puhui999缺导出
@Schema(description = "管理后台 - CRM 回款计划 Response VO") @Schema(description = "管理后台 - CRM 回款计划 Response VO")
@Data @Data
@ExcelIgnoreUnannotated
public class CrmReceivablePlanRespVO { public class CrmReceivablePlanRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("编号")
private Long id; private Long id;
@Schema(description = "期数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "期数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("期数")
private Integer period; private Integer period;
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("客户编号")
private Long customerId; private Long customerId;
@Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test") @Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
@ExcelProperty("客户名字")
private String customerName; private String customerName;
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("合同编号")
private Long contractId; private Long contractId;
@Schema(description = "合同编号", example = "Q110") @Schema(description = "合同编号", example = "Q110")
@ExcelProperty("合同编号")
private String contractNo; private String contractNo;
@Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("负责人编号")
private Long ownerUserId; private Long ownerUserId;
@Schema(description = "负责人", example = "test") @Schema(description = "负责人", example = "test")
@ExcelProperty("负责人")
private String ownerUserName; private String ownerUserName;
@Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02") @Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
@ExcelProperty("计划回款日期")
private LocalDateTime returnTime; private LocalDateTime returnTime;
@Schema(description = "计划回款方式", example = "1") @Schema(description = "计划回款方式", example = "1")
@ExcelProperty("计划回款方式")
private Integer returnType; private Integer returnType;
@Schema(description = "计划回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000") @Schema(description = "计划回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000")
@ExcelProperty("计划回款金额")
private BigDecimal price; private BigDecimal price;
@Schema(description = "回款编号", example = "19852") @Schema(description = "回款编号", example = "19852")
@ExcelProperty("回款编号")
private Long receivableId; private Long receivableId;
@Schema(description = "回款信息") @Schema(description = "回款信息")
@ExcelProperty("回款信息")
private CrmReceivableRespVO receivable; private CrmReceivableRespVO receivable;
@Schema(description = "提前几天提醒", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "提前几天提醒", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty("提前几天提醒")
private Integer remindDays; private Integer remindDays;
@Schema(description = "提醒日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02") @Schema(description = "提醒日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
@ExcelProperty("提醒日期")
private LocalDateTime remindTime; private LocalDateTime remindTime;
@Schema(description = "备注", example = "备注") @Schema(description = "备注", example = "备注")
@ExcelProperty("备注")
private String remark; private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable; package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -8,37 +9,47 @@ import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
// TODO 芋艿导出的 VO可以考虑使用 @Excel 注解实现导出功能
@Schema(description = "管理后台 - CRM 回款 Response VO") @Schema(description = "管理后台 - CRM 回款 Response VO")
@Data @Data
@ExcelIgnoreUnannotated
public class CrmReceivableRespVO { public class CrmReceivableRespVO {
@Schema(description = "编号", example = "25787") @Schema(description = "编号", example = "25787")
@ExcelProperty("编号")
private Long id; private Long id;
@Schema(description = "回款编号", example = "31177") @Schema(description = "回款编号", example = "31177")
@ExcelProperty("回款编号")
private String no; private String no;
@Schema(description = "回款计划编号", example = "1024") @Schema(description = "回款计划编号", example = "1024")
@ExcelProperty("回款计划编号")
private Long planId; private Long planId;
@Schema(description = "回款方式", example = "2") @Schema(description = "回款方式", example = "2")
@ExcelProperty("回款方式")
private Integer returnType; private Integer returnType;
@Schema(description = "回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000") @Schema(description = "回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000")
@ExcelProperty("回款金额")
private BigDecimal price; private BigDecimal price;
@Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02") @Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
@ExcelProperty("计划回款日期")
private LocalDateTime returnTime; private LocalDateTime returnTime;
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("客户编号")
private Long customerId; private Long customerId;
@Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test") @Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
@ExcelProperty("客户名字")
private String customerName; private String customerName;
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("合同编号")
private Long contractId; private Long contractId;
@Schema(description = "合同信息") @Schema(description = "合同信息")
@ExcelProperty("合同信息")
private CrmContractRespVO contract; private CrmContractRespVO contract;
@Schema(description = "负责人的用户编号", example = "25682") @Schema(description = "负责人的用户编号", example = "25682")
@ -56,20 +67,26 @@ public class CrmReceivableRespVO {
private String processInstanceId; private String processInstanceId;
@Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") @Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
@ExcelProperty("审批状态")
private Integer auditStatus; private Integer auditStatus;
@Schema(description = "备注", example = "备注") @Schema(description = "工作流编号", example = "备注")
@ExcelProperty("工作流编号")
private String remark; private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime; private LocalDateTime createTime;
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("更新时间")
private LocalDateTime updateTime; private LocalDateTime updateTime;
@Schema(description = "创建人", example = "25682") @Schema(description = "创建人", example = "25682")
@ExcelProperty("创建人")
private String creator; private String creator;
@Schema(description = "创建人名字", example = "test") @Schema(description = "创建人名字", example = "test")
@ExcelProperty("创建人名字")
private String creatorName; private String creatorName;
} }

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.crm.framework.excel;

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.crm.framework.excel.service;
import cn.iocoder.yudao.framework.excel.core.service.ExcelColumnSelectDataService;
import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Excel 所属地区列下拉数据源获取接口实现类
*
* @author HUIHUI
*/
@Service
public class AreaExcelColumnSelectDataServiceImpl implements ExcelColumnSelectDataService {
public static final String FUNCTION_NAME = "getCrmAreaNameList"; // 防止和别的模块重名
@Resource
private DictDataApi dictDataApi;
@Override
public String getFunctionName() {
return FUNCTION_NAME;
}
@Override
public List<String> getSelectDataList() {
// 获取地区下拉数据
// TODO @puhui999嘿嘿这里改成省份城市区域三个选项难度大么
Area area = AreaUtils.parseArea(Area.ID_CHINA);
return AreaUtils.getAreaNodePathList(area.getChildren());
}
}

View File

@ -0,0 +1,35 @@
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<String> getSelectDataList() {
return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_INDUSTRY);
}
}

View File

@ -0,0 +1,35 @@
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<String> getSelectDataList() {
return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_LEVEL);
}
}

View File

@ -0,0 +1,35 @@
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<String> getSelectDataList() {
return dictDataApi.getDictDataLabelList(CRM_CUSTOMER_SOURCE);
}
}

View File

@ -30,12 +30,14 @@ import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
import cn.iocoder.yudao.module.crm.service.product.CrmProductService; import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import com.mzt.logapi.context.LogRecordContext; import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.service.impl.DiffParseFunction; import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord; import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -86,7 +88,9 @@ public class CrmContractServiceImpl implements CrmContractService {
private CrmContactService contactService; private CrmContactService contactService;
@Resource @Resource
private CrmContractConfigService contractConfigService; private CrmContractConfigService contractConfigService;
@Resource
@Lazy // 延迟加载避免循环依赖
private CrmReceivableService receivableService;
@Resource @Resource
private AdminUserApi adminUserApi; private AdminUserApi adminUserApi;
@Resource @Resource
@ -222,9 +226,12 @@ public class CrmContractServiceImpl implements CrmContractService {
success = CRM_CONTRACT_DELETE_SUCCESS) success = CRM_CONTRACT_DELETE_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void deleteContract(Long id) { public void deleteContract(Long id) {
// TODO @puhui999如果被 CrmReceivableDO 所使用则不允许删除
// 校验存在 // 校验存在
CrmContractDO contract = validateContractExists(id); CrmContractDO contract = validateContractExists(id);
// 如果被 CrmReceivableDO 所使用则不允许删除
if (CollUtil.isNotEmpty(receivableService.getReceivableByContractId(contract.getId()))) {
throw exception(CONTRACT_DELETE_FAIL);
}
// 删除 // 删除
contractMapper.deleteById(id); contractMapper.deleteById(id);
// 删除数据权限 // 删除数据权限

View File

@ -122,4 +122,12 @@ public interface CrmReceivableService {
*/ */
Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds); Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds);
/**
* 更具合同编号查询回款列表
*
* @param contractId 合同编号
* @return 回款
*/
List<CrmReceivableDO> getReceivableByContractId(Long contractId);
} }

View File

@ -37,10 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Arrays; import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
@ -81,7 +78,6 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
@Resource @Resource
private BpmProcessInstanceApi bpmProcessInstanceApi; private BpmProcessInstanceApi bpmProcessInstanceApi;
// TODO @puhui999操作日志没记录上
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_CREATE_SUB_TYPE, bizNo = "{{#receivable.id}}", @LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_CREATE_SUB_TYPE, bizNo = "{{#receivable.id}}",
@ -115,6 +111,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
// 5. 记录操作日志上下文 // 5. 记录操作日志上下文
LogRecordContext.putVariable("receivable", receivable); LogRecordContext.putVariable("receivable", receivable);
LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
return receivable.getId(); return receivable.getId();
} }
@ -156,7 +153,6 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
} }
} }
// TODO @puhui999操作日志没记录上
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", @LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
@ -164,11 +160,14 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
@CrmPermission(bizType = CrmBizTypeEnum.CRM_RECEIVABLE, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) @CrmPermission(bizType = CrmBizTypeEnum.CRM_RECEIVABLE, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
public void updateReceivable(CrmReceivableSaveReqVO updateReqVO) { public void updateReceivable(CrmReceivableSaveReqVO updateReqVO) {
Assert.notNull(updateReqVO.getId(), "回款编号不能为空"); Assert.notNull(updateReqVO.getId(), "回款编号不能为空");
// 1.1 校验可回款金额超过上限
validateReceivablePriceExceedsLimit(updateReqVO);
updateReqVO.setOwnerUserId(null).setCustomerId(null).setContractId(null).setPlanId(null); // 不允许修改的字段 updateReqVO.setOwnerUserId(null).setCustomerId(null).setContractId(null).setPlanId(null); // 不允许修改的字段
// 1.2 校验存在 // 1.1 校验存在
CrmReceivableDO receivable = validateReceivableExists(updateReqVO.getId()); CrmReceivableDO receivable = validateReceivableExists(updateReqVO.getId());
updateReqVO.setOwnerUserId(receivable.getOwnerUserId()).setCustomerId(receivable.getCustomerId())
.setContractId(receivable.getContractId()).setPlanId(receivable.getPlanId()); // 设置已存在的值
// 1.2 校验可回款金额超过上限
validateReceivablePriceExceedsLimit(updateReqVO);
// 1.3 只有草稿审批中可以编辑 // 1.3 只有草稿审批中可以编辑
if (!ObjectUtils.equalsAny(receivable.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus(), if (!ObjectUtils.equalsAny(receivable.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus(),
CrmAuditStatusEnum.PROCESS.getStatus())) { CrmAuditStatusEnum.PROCESS.getStatus())) {
@ -180,8 +179,17 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
receivableMapper.updateById(updateObj); receivableMapper.updateById(updateObj);
// 3. 记录操作日志上下文 // 3. 记录操作日志上下文
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(receivable, CrmReceivableSaveReqVO.class));
LogRecordContext.putVariable("receivable", receivable); LogRecordContext.putVariable("receivable", receivable);
LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(receivable, CrmReceivableSaveReqVO.class));
}
private Integer getReceivablePeriod(Long planId) {
if (Objects.isNull(planId)) {
return null;
}
CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(planId);
return receivablePlan.getPeriod();
} }
@Override @Override
@ -212,8 +220,10 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
if (receivable.getPlanId() != null && receivablePlanService.getReceivablePlan(receivable.getPlanId()) != null) { if (receivable.getPlanId() != null && receivablePlanService.getReceivablePlan(receivable.getPlanId()) != null) {
throw exception(RECEIVABLE_DELETE_FAIL); throw exception(RECEIVABLE_DELETE_FAIL);
} }
// TODO @puhui999审批通过时不允许删除 // 1.3 审批通过时不允许删除
if (ObjUtil.equal(receivable.getAuditStatus(), CrmAuditStatusEnum.APPROVE.getStatus())) {
throw exception(RECEIVABLE_DELETE_FAIL_IS_APPROVE);
}
// 2. 删除 // 2. 删除
receivableMapper.deleteById(id); receivableMapper.deleteById(id);
// 3. 删除数据权限 // 3. 删除数据权限
@ -221,6 +231,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
// 4. 记录操作日志上下文 // 4. 记录操作日志上下文
LogRecordContext.putVariable("receivable", receivable); LogRecordContext.putVariable("receivable", receivable);
LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
} }
@Override @Override
@ -289,4 +300,9 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
return receivableMapper.selectReceivablePriceMapByContractId(contractIds); return receivableMapper.selectReceivablePriceMapByContractId(contractIds);
} }
@Override
public List<CrmReceivableDO> getReceivableByContractId(Long contractId) {
return receivableMapper.selectList(CrmReceivableDO::getContractId, contractId);
}
} }

View File

@ -94,7 +94,7 @@ const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗 const message = useMessage() // 消息弹窗
const props = defineProps<{ const props = defineProps<{
${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段) ${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段)
}>() }>()
const loading = ref(false) // 列表的加载中 const loading = ref(false) // 列表的加载中
const list = ref([]) // 列表的数据 const list = ref([]) // 列表的数据
@ -103,17 +103,20 @@ const total = ref(0) // 列表的总页数
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
${subJoinColumn.javaField}: undefined ${subJoinColumn.javaField}: undefined as unknown
}) })
/** 监听主表的关联字段的变化,加载对应的子表数据 */ /** 监听主表的关联字段的变化,加载对应的子表数据 */
watch( watch(
() => props.${subJoinColumn.javaField}, () => props.${subJoinColumn.javaField},
(val) => { (val: number) => {
if (!val) {
return
}
queryParams.${subJoinColumn.javaField} = val queryParams.${subJoinColumn.javaField} = val
handleQuery() handleQuery()
}, },
{ immediate: false } { immediate: true, deep: true }
) )
#end #end