Commit b3cfad9396b55a730718957d16f061cf1260ed83

Authored by puhui999
1 parent 872fe535

CRM: 完善回款计划

Showing 14 changed files with 181 additions and 176 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
@@ -33,8 +33,9 @@ public interface ErrorCodeConstants { @@ -33,8 +33,9 @@ public interface ErrorCodeConstants {
33 // ========== 回款 1-020-004-000 ========== 33 // ========== 回款 1-020-004-000 ==========
34 ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_020_004_000, "回款不存在"); 34 ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_020_004_000, "回款不存在");
35 35
36 - // ========== 合同管理 1-020-005-000 ========== 36 + // ========== 回款计划 1-020-005-000 ==========
37 ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在"); 37 ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在");
  38 + ErrorCode RECEIVABLE_PLAN_UPDATE_FAIL = new ErrorCode(1_020_006_000, "更想回款计划失败,原因:{}");
38 39
39 // ========== 客户管理 1_020_006_000 ========== 40 // ========== 客户管理 1_020_006_000 ==========
40 ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在"); 41 ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在");
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivablePlanController.java
@@ -5,12 +5,12 @@ import cn.hutool.core.lang.Assert; @@ -5,12 +5,12 @@ import cn.hutool.core.lang.Assert;
5 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
6 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 import cn.iocoder.yudao.framework.common.util.number.NumberUtils; 7 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
  8 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
8 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 9 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
9 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; 10 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
10 -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanCreateReqVO;  
11 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanPageReqVO; 11 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanPageReqVO;
12 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanRespVO; 12 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanRespVO;
13 -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanUpdateReqVO; 13 +import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanSaveReqVO;
14 import cn.iocoder.yudao.module.crm.convert.receivable.CrmReceivablePlanConvert; 14 import cn.iocoder.yudao.module.crm.convert.receivable.CrmReceivablePlanConvert;
15 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; 15 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
16 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 16 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@@ -67,14 +67,14 @@ public class CrmReceivablePlanController { @@ -67,14 +67,14 @@ public class CrmReceivablePlanController {
67 @PostMapping("/create") 67 @PostMapping("/create")
68 @Operation(summary = "创建回款计划") 68 @Operation(summary = "创建回款计划")
69 @PreAuthorize("@ss.hasPermission('crm:receivable-plan:create')") 69 @PreAuthorize("@ss.hasPermission('crm:receivable-plan:create')")
70 - public CommonResult<Long> createReceivablePlan(@Valid @RequestBody CrmReceivablePlanCreateReqVO createReqVO) {  
71 - return success(receivablePlanService.createReceivablePlan(createReqVO, getLoginUserId())); 70 + public CommonResult<Long> createReceivablePlan(@Valid @RequestBody CrmReceivablePlanSaveReqVO createReqVO) {
  71 + return success(receivablePlanService.createReceivablePlan(createReqVO));
72 } 72 }
73 73
74 @PutMapping("/update") 74 @PutMapping("/update")
75 @Operation(summary = "更新回款计划") 75 @Operation(summary = "更新回款计划")
76 @PreAuthorize("@ss.hasPermission('crm:receivable-plan:update')") 76 @PreAuthorize("@ss.hasPermission('crm:receivable-plan:update')")
77 - public CommonResult<Boolean> updateReceivablePlan(@Valid @RequestBody CrmReceivablePlanUpdateReqVO updateReqVO) { 77 + public CommonResult<Boolean> updateReceivablePlan(@Valid @RequestBody CrmReceivablePlanSaveReqVO updateReqVO) {
78 receivablePlanService.updateReceivablePlan(updateReqVO); 78 receivablePlanService.updateReceivablePlan(updateReqVO);
79 return success(true); 79 return success(true);
80 } 80 }
@@ -94,7 +94,7 @@ public class CrmReceivablePlanController { @@ -94,7 +94,7 @@ public class CrmReceivablePlanController {
94 @PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')") 94 @PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')")
95 public CommonResult<CrmReceivablePlanRespVO> getReceivablePlan(@RequestParam("id") Long id) { 95 public CommonResult<CrmReceivablePlanRespVO> getReceivablePlan(@RequestParam("id") Long id) {
96 CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(id); 96 CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(id);
97 - return success(CrmReceivablePlanConvert.INSTANCE.convert(receivablePlan)); 97 + return success(BeanUtils.toBean(receivablePlan, CrmReceivablePlanRespVO.class));
98 } 98 }
99 99
100 @GetMapping("/page") 100 @GetMapping("/page")
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanBaseVO.java deleted
1 -package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan;  
2 -  
3 -import io.swagger.v3.oas.annotations.media.Schema;  
4 -import lombok.Data;  
5 -import org.springframework.format.annotation.DateTimeFormat;  
6 -  
7 -import java.time.LocalDateTime;  
8 -  
9 -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;  
10 -  
11 -/**  
12 - * 回款计划 Base VO,提供给添加、修改、详细的子 VO 使用  
13 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成  
14 - */  
15 -@Data  
16 -public class CrmReceivablePlanBaseVO {  
17 -  
18 - @Schema(description = "期数", example = "1")  
19 - private Integer period;  
20 -  
21 - @Schema(description = "回款计划编号", example = "19852")  
22 - private Long receivableId;  
23 -  
24 - @Schema(description = "计划回款金额", example = "29675")  
25 - private Integer price;  
26 -  
27 - @Schema(description = "计划回款日期")  
28 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
29 - private LocalDateTime returnTime;  
30 -  
31 - @Schema(description = "提前几天提醒")  
32 - private Integer remindDays;  
33 -  
34 - @Schema(description = "提醒日期")  
35 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
36 - private LocalDateTime remindTime;  
37 -  
38 - @Schema(description = "客户名称", example = "18026")  
39 - private Long customerId;  
40 -  
41 - @Schema(description = "合同编号", example = "3473")  
42 - private Long contractId;  
43 -  
44 - // TODO @liuhongfeng:负责人编号  
45 - @Schema(description = "负责人编号", example = "17828")  
46 - private Long ownerUserId;  
47 -  
48 - @Schema(description = "显示顺序")  
49 - private Integer sort;  
50 -  
51 - @Schema(description = "备注", example = "备注")  
52 - private String remark;  
53 -  
54 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanCreateReqVO.java deleted
1 -package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan;  
2 -  
3 -import lombok.*;  
4 -import io.swagger.v3.oas.annotations.media.Schema;  
5 -  
6 -@Schema(description = "管理后台 - CRM 回款计划创建 Request VO")  
7 -@Data  
8 -@EqualsAndHashCode(callSuper = true)  
9 -@ToString(callSuper = true)  
10 -public class CrmReceivablePlanCreateReqVO extends CrmReceivablePlanBaseVO {  
11 -  
12 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanRespVO.java
1 package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan; 1 package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan;
2 2
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 -import lombok.*; 4 +import lombok.Data;
  5 +
5 import java.time.LocalDateTime; 6 import java.time.LocalDateTime;
6 7
7 @Schema(description = "管理后台 - CRM 回款计划 Response VO") 8 @Schema(description = "管理后台 - CRM 回款计划 Response VO")
8 @Data 9 @Data
9 -@EqualsAndHashCode(callSuper = true)  
10 -@ToString(callSuper = true)  
11 -public class CrmReceivablePlanRespVO extends CrmReceivablePlanBaseVO { 10 +public class CrmReceivablePlanRespVO {
12 11
13 @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25153") 12 @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25153")
14 private Long id; 13 private Long id;
15 14
  15 + @Schema(description = "期数", example = "1")
  16 + private Integer period;
  17 +
  18 + @Schema(description = "回款计划编号", example = "19852")
  19 + private Long receivableId;
  20 +
  21 + @Schema(description = "计划回款金额", example = "29675")
  22 + private Integer price;
  23 +
  24 + @Schema(description = "计划回款日期")
  25 + private LocalDateTime returnTime;
  26 +
  27 + @Schema(description = "提前几天提醒")
  28 + private Integer remindDays;
  29 +
  30 + @Schema(description = "提醒日期")
  31 + private LocalDateTime remindTime;
  32 +
  33 + @Schema(description = "客户名称", example = "18026")
  34 + private Long customerId;
  35 +
  36 + @Schema(description = "合同编号", example = "3473")
  37 + private Long contractId;
  38 +
  39 + @Schema(description = "负责人编号", example = "17828")
  40 + private Long ownerUserId;
  41 +
  42 + @Schema(description = "显示顺序")
  43 + private Integer sort;
  44 +
  45 + @Schema(description = "备注", example = "备注")
  46 + private String remark;
  47 +
16 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) 48 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
17 private LocalDateTime createTime; 49 private LocalDateTime createTime;
18 50
@@ -34,7 +66,7 @@ public class CrmReceivablePlanRespVO extends CrmReceivablePlanBaseVO { @@ -34,7 +66,7 @@ public class CrmReceivablePlanRespVO extends CrmReceivablePlanBaseVO {
34 @Schema(description = "完成状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") 66 @Schema(description = "完成状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
35 private Boolean finishStatus; 67 private Boolean finishStatus;
36 68
37 - @Schema(description = "回款方式", example = "1") // 来自 Receivable 的 returnType 字段  
38 - private Integer returnType; 69 + @Schema(description = "回款方式", example = "1")
  70 + private Integer returnType; // 来自 Receivable 的 returnType 字段
39 71
40 } 72 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotNull;
  5 +import lombok.Data;
  6 +
  7 +import java.math.BigDecimal;
  8 +import java.time.LocalDateTime;
  9 +
  10 +@Schema(description = "管理后台 - CRM 回款计划新增/修改 Request VO")
  11 +@Data
  12 +public class CrmReceivablePlanSaveReqVO {
  13 +
  14 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  15 + private Long id;
  16 +
  17 + @Schema(description = "期数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  18 + @NotNull(message = "期数不能为空")
  19 + private Integer period;
  20 +
  21 + @Schema(description = "计划回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000")
  22 + @NotNull(message = "计划回款金额不能为空")
  23 + private BigDecimal price;
  24 +
  25 + @Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
  26 + @NotNull(message = "计划回款日期不能为空")
  27 + private LocalDateTime returnTime;
  28 +
  29 + @Schema(description = "提前几天提醒", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  30 + @NotNull(message = "提前几天提醒不能为空")
  31 + private Integer remindDays;
  32 +
  33 + @Schema(description = "提醒日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
  34 + @NotNull(message = "提醒日期不能为空")
  35 + private LocalDateTime remindTime;
  36 +
  37 + @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  38 + @NotNull(message = "客户编号不能为空")
  39 + private Long customerId;
  40 +
  41 + @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  42 + @NotNull(message = "合同编号不能为空")
  43 + private Long contractId;
  44 +
  45 + @Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  46 + @NotNull(message = "负责人编号不能为空")
  47 + private Long ownerUserId;
  48 +
  49 + @Schema(description = "显示顺序")
  50 + private Integer sort;
  51 +
  52 + @Schema(description = "备注", example = "备注")
  53 + private String remark;
  54 +
  55 +}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/plan/CrmReceivablePlanUpdateReqVO.java deleted
1 -package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan;  
2 -  
3 -import io.swagger.v3.oas.annotations.media.Schema;  
4 -import lombok.*;  
5 -  
6 -import jakarta.validation.constraints.*;  
7 -  
8 -@Schema(description = "管理后台 - CRM 回款计划更新 Request VO")  
9 -@Data  
10 -@EqualsAndHashCode(callSuper = true)  
11 -@ToString(callSuper = true)  
12 -public class CrmReceivablePlanUpdateReqVO extends CrmReceivablePlanBaseVO {  
13 -  
14 - @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25153")  
15 - @NotNull(message = "ID不能为空")  
16 - private Long id;  
17 -  
18 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/receivable/CrmReceivablePlanConvert.java
@@ -2,9 +2,7 @@ package cn.iocoder.yudao.module.crm.convert.receivable; @@ -2,9 +2,7 @@ package cn.iocoder.yudao.module.crm.convert.receivable;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanCreateReqVO;  
6 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanRespVO; 5 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanRespVO;
7 -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanUpdateReqVO;  
8 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; 6 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
9 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 7 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
10 import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO; 8 import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO;
@@ -29,12 +27,6 @@ public interface CrmReceivablePlanConvert { @@ -29,12 +27,6 @@ public interface CrmReceivablePlanConvert {
29 27
30 CrmReceivablePlanConvert INSTANCE = Mappers.getMapper(CrmReceivablePlanConvert.class); 28 CrmReceivablePlanConvert INSTANCE = Mappers.getMapper(CrmReceivablePlanConvert.class);
31 29
32 - CrmReceivablePlanDO convert(CrmReceivablePlanCreateReqVO bean);  
33 -  
34 - CrmReceivablePlanDO convert(CrmReceivablePlanUpdateReqVO bean);  
35 -  
36 - CrmReceivablePlanRespVO convert(CrmReceivablePlanDO bean);  
37 -  
38 default PageResult<CrmReceivablePlanRespVO> convertPage(PageResult<CrmReceivablePlanDO> pageResult, Map<Long, AdminUserRespDTO> userMap, 30 default PageResult<CrmReceivablePlanRespVO> convertPage(PageResult<CrmReceivablePlanDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
39 List<CrmCustomerDO> customerList, List<CrmContractDO> contractList, 31 List<CrmCustomerDO> customerList, List<CrmContractDO> contractList,
40 List<CrmReceivableDO> receivableList) { 32 List<CrmReceivableDO> receivableList) {
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/receivable/CrmReceivablePlanDO.java
1 package cn.iocoder.yudao.module.crm.dal.dataobject.receivable; 1 package cn.iocoder.yudao.module.crm.dal.dataobject.receivable;
2 2
3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
  5 +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
  6 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
4 import com.baomidou.mybatisplus.annotation.KeySequence; 7 import com.baomidou.mybatisplus.annotation.KeySequence;
5 import com.baomidou.mybatisplus.annotation.TableId; 8 import com.baomidou.mybatisplus.annotation.TableId;
6 import com.baomidou.mybatisplus.annotation.TableName; 9 import com.baomidou.mybatisplus.annotation.TableName;
7 import lombok.*; 10 import lombok.*;
8 11
  12 +import java.math.BigDecimal;
9 import java.time.LocalDateTime; 13 import java.time.LocalDateTime;
10 14
11 /** 15 /**
@@ -24,7 +28,7 @@ import java.time.LocalDateTime; @@ -24,7 +28,7 @@ import java.time.LocalDateTime;
24 public class CrmReceivablePlanDO extends BaseDO { 28 public class CrmReceivablePlanDO extends BaseDO {
25 29
26 /** 30 /**
27 - * ID 31 + * 编号
28 */ 32 */
29 @TableId 33 @TableId
30 private Long id; 34 private Long id;
@@ -33,19 +37,13 @@ public class CrmReceivablePlanDO extends BaseDO { @@ -33,19 +37,13 @@ public class CrmReceivablePlanDO extends BaseDO {
33 */ 37 */
34 private Integer period; 38 private Integer period;
35 /** 39 /**
36 - * 回款ID  
37 - *  
38 - * TODO @liuhongfeng:少关联实体; 40 + * 回款编号,关联 {@link CrmReceivableDO#getId()}
39 */ 41 */
40 private Long receivableId; 42 private Long receivableId;
41 /** 43 /**
42 - * 完成状态 44 + * 计划回款金额,单位:元
43 */ 45 */
44 - private Boolean finishStatus;  
45 - /**  
46 - * 计划回款金额,单位:分  
47 - */  
48 - private Integer price; 46 + private BigDecimal price;
49 /** 47 /**
50 * 计划回款日期 48 * 计划回款日期
51 */ 49 */
@@ -59,21 +57,15 @@ public class CrmReceivablePlanDO extends BaseDO { @@ -59,21 +57,15 @@ public class CrmReceivablePlanDO extends BaseDO {
59 */ 57 */
60 private LocalDateTime remindTime; 58 private LocalDateTime remindTime;
61 /** 59 /**
62 - * 客户 ID  
63 - *  
64 - * TODO @liuhongfeng:少关联实体; 60 + * 客户编号,关联 {@link CrmCustomerDO#getId()}
65 */ 61 */
66 private Long customerId; 62 private Long customerId;
67 /** 63 /**
68 - * 合同 ID  
69 - *  
70 - * TODO @liuhongfeng:少关联实体; 64 + * 合同编号,关联 {@link CrmContractDO#getId()}
71 */ 65 */
72 private Long contractId; 66 private Long contractId;
73 /** 67 /**
74 - * 负责人 ID  
75 - *  
76 - * TODO @liuhongfeng:少关联实体; 68 + * 负责人编号,关联 {@link AdminUserRespDTO#getId()}
77 */ 69 */
78 private Long ownerUserId; 70 private Long ownerUserId;
79 /** 71 /**
@@ -85,4 +77,9 @@ public class CrmReceivablePlanDO extends BaseDO { @@ -85,4 +77,9 @@ public class CrmReceivablePlanDO extends BaseDO {
85 */ 77 */
86 private String remark; 78 private String remark;
87 79
  80 + /**
  81 + * 完成状态
  82 + */
  83 + private Boolean finishStatus;
  84 +
88 } 85 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivablePlanMapper.java
@@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO
10 import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; 10 import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
11 import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum; 11 import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum;
12 import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils; 12 import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils;
13 -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;  
14 import org.apache.ibatis.annotations.Mapper; 13 import org.apache.ibatis.annotations.Mapper;
15 14
16 import java.time.LocalDateTime; 15 import java.time.LocalDateTime;
@@ -25,12 +24,6 @@ import java.util.List; @@ -25,12 +24,6 @@ import java.util.List;
25 @Mapper 24 @Mapper
26 public interface CrmReceivablePlanMapper extends BaseMapperX<CrmReceivablePlanDO> { 25 public interface CrmReceivablePlanMapper extends BaseMapperX<CrmReceivablePlanDO> {
27 26
28 - default int updateOwnerUserIdById(Long id, Long ownerUserId) {  
29 - return update(new LambdaUpdateWrapper<CrmReceivablePlanDO>()  
30 - .eq(CrmReceivablePlanDO::getId, id)  
31 - .set(CrmReceivablePlanDO::getOwnerUserId, ownerUserId));  
32 - }  
33 -  
34 default PageResult<CrmReceivablePlanDO> selectPageByCustomerId(CrmReceivablePlanPageReqVO reqVO) { 27 default PageResult<CrmReceivablePlanDO> selectPageByCustomerId(CrmReceivablePlanPageReqVO reqVO) {
35 return selectPage(reqVO, new LambdaQueryWrapperX<CrmReceivablePlanDO>() 28 return selectPage(reqVO, new LambdaQueryWrapperX<CrmReceivablePlanDO>()
36 .eq(CrmReceivablePlanDO::getCustomerId, reqVO.getCustomerId()) // 必须传递 29 .eq(CrmReceivablePlanDO::getCustomerId, reqVO.getCustomerId()) // 必须传递
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivablePlanService.java
1 package cn.iocoder.yudao.module.crm.service.receivable; 1 package cn.iocoder.yudao.module.crm.service.receivable;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanCreateReqVO;  
5 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanPageReqVO; 4 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanPageReqVO;
6 -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanUpdateReqVO; 5 +import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanSaveReqVO;
7 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 6 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
8 import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO; 7 import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO;
9 import jakarta.validation.Valid; 8 import jakarta.validation.Valid;
@@ -24,14 +23,14 @@ public interface CrmReceivablePlanService { @@ -24,14 +23,14 @@ public interface CrmReceivablePlanService {
24 * @param createReqVO 创建信息 23 * @param createReqVO 创建信息
25 * @return 编号 24 * @return 编号
26 */ 25 */
27 - Long createReceivablePlan(@Valid CrmReceivablePlanCreateReqVO createReqVO, Long userId); 26 + Long createReceivablePlan(@Valid CrmReceivablePlanSaveReqVO createReqVO);
28 27
29 /** 28 /**
30 * 更新回款计划 29 * 更新回款计划
31 * 30 *
32 * @param updateReqVO 更新信息 31 * @param updateReqVO 更新信息
33 */ 32 */
34 - void updateReceivablePlan(@Valid CrmReceivablePlanUpdateReqVO updateReqVO); 33 + void updateReceivablePlan(@Valid CrmReceivablePlanSaveReqVO updateReqVO);
35 34
36 /** 35 /**
37 * 删除回款计划 36 * 删除回款计划
@@ -84,4 +83,5 @@ public interface CrmReceivablePlanService { @@ -84,4 +83,5 @@ public interface CrmReceivablePlanService {
84 * @return 提醒数量 83 * @return 提醒数量
85 */ 84 */
86 Long getRemindReceivablePlanCount(Long userId); 85 Long getRemindReceivablePlanCount(Long userId);
  86 +
87 } 87 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivablePlanServiceImpl.java
@@ -5,10 +5,8 @@ import cn.hutool.core.collection.ListUtil; @@ -5,10 +5,8 @@ import cn.hutool.core.collection.ListUtil;
5 import cn.hutool.core.util.ObjectUtil; 5 import cn.hutool.core.util.ObjectUtil;
6 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
8 -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanCreateReqVO;  
9 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanPageReqVO; 8 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanPageReqVO;
10 -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanUpdateReqVO;  
11 -import cn.iocoder.yudao.module.crm.convert.receivable.CrmReceivablePlanConvert; 9 +import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanSaveReqVO;
12 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; 10 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
13 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 11 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
14 import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO; 12 import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO;
@@ -20,22 +18,24 @@ import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; @@ -20,22 +18,24 @@ import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
20 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; 18 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
21 import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; 19 import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
22 import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; 20 import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
  21 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
23 import com.mzt.logapi.context.LogRecordContext; 22 import com.mzt.logapi.context.LogRecordContext;
24 import com.mzt.logapi.service.impl.DiffParseFunction; 23 import com.mzt.logapi.service.impl.DiffParseFunction;
25 import com.mzt.logapi.starter.annotation.LogRecord; 24 import com.mzt.logapi.starter.annotation.LogRecord;
26 import jakarta.annotation.Resource; 25 import jakarta.annotation.Resource;
  26 +import org.hibernate.validator.internal.util.stereotypes.Lazy;
27 import org.springframework.stereotype.Service; 27 import org.springframework.stereotype.Service;
  28 +import org.springframework.transaction.annotation.Transactional;
28 import org.springframework.validation.annotation.Validated; 29 import org.springframework.validation.annotation.Validated;
29 30
30 import java.util.Collection; 31 import java.util.Collection;
31 import java.util.List; 32 import java.util.List;
  33 +import java.util.Objects;
32 34
33 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 35 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
34 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; 36 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
35 import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; 37 import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
36 38
37 -// TODO @liuhongfeng:参考 CrmReceivableServiceImpl 写的 todo 哈;  
38 -  
39 /** 39 /**
40 * 回款计划 Service 实现类 40 * 回款计划 Service 实现类
41 * 41 *
@@ -49,72 +49,78 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService { @@ -49,72 +49,78 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService {
49 private CrmReceivablePlanMapper receivablePlanMapper; 49 private CrmReceivablePlanMapper receivablePlanMapper;
50 50
51 @Resource 51 @Resource
  52 + @Lazy // 延迟加载,避免循环依赖
  53 + private CrmReceivableService receivableService;
  54 + @Resource
52 private CrmContractService contractService; 55 private CrmContractService contractService;
53 @Resource 56 @Resource
54 private CrmCustomerService customerService; 57 private CrmCustomerService customerService;
55 @Resource 58 @Resource
56 private CrmPermissionService permissionService; 59 private CrmPermissionService permissionService;
  60 + @Resource
  61 + private AdminUserApi adminUserApi;
57 62
58 @Override 63 @Override
  64 + @Transactional(rollbackFor = Exception.class)
59 @LogRecord(type = CRM_RECEIVABLE_PLAN_TYPE, subType = CRM_RECEIVABLE_PLAN_CREATE_SUB_TYPE, bizNo = "{{#receivablePlan.id}}", 65 @LogRecord(type = CRM_RECEIVABLE_PLAN_TYPE, subType = CRM_RECEIVABLE_PLAN_CREATE_SUB_TYPE, bizNo = "{{#receivablePlan.id}}",
60 success = CRM_RECEIVABLE_PLAN_CREATE_SUCCESS) 66 success = CRM_RECEIVABLE_PLAN_CREATE_SUCCESS)
61 - public Long createReceivablePlan(CrmReceivablePlanCreateReqVO createReqVO, Long userId) {  
62 - // TODO @liuhongfeng:第几期的计算;基于是 contractId + contractDO 的第几个还款  
63 - // TODO @liuhongfeng contractId:校验合同是否存在  
64 - // 插入  
65 - CrmReceivablePlanDO receivablePlan = CrmReceivablePlanConvert.INSTANCE.convert(createReqVO);  
66 - receivablePlan.setFinishStatus(false);  
67 -  
68 - checkReceivablePlan(receivablePlan);  
69 - 67 + public Long createReceivablePlan(CrmReceivablePlanSaveReqVO createReqVO) {
  68 + // 1.1 校验关联数据是否存在
  69 + checkReceivablePlan(createReqVO);
  70 + // 1.2 查验关联合同回款数量
  71 + Long count = receivableService.getReceivableCountByContractId(createReqVO.getContractId());
  72 + int period = (int) (count + 1);
  73 + createReqVO.setPeriod(createReqVO.getPeriod() != period ? period : createReqVO.getPeriod()); // 如果期数不对则纠正
  74 +
  75 + // 2.1 插入
  76 + CrmReceivablePlanDO receivablePlan = BeanUtils.toBean(createReqVO, CrmReceivablePlanDO.class).setId(null).setFinishStatus(false);
70 receivablePlanMapper.insert(receivablePlan); 77 receivablePlanMapper.insert(receivablePlan);
71 - // 创建数据权限  
72 - permissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(userId) 78 + // 2.2 创建数据权限
  79 + permissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(createReqVO.getOwnerUserId())
73 .setBizType(CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType()).setBizId(receivablePlan.getId()) 80 .setBizType(CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType()).setBizId(receivablePlan.getId())
74 .setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); 81 .setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
75 82
76 - // 4. 记录操作日志上下文 83 + // 3. 记录操作日志上下文
77 LogRecordContext.putVariable("receivablePlan", receivablePlan); 84 LogRecordContext.putVariable("receivablePlan", receivablePlan);
78 return receivablePlan.getId(); 85 return receivablePlan.getId();
79 } 86 }
80 87
81 - private void checkReceivablePlan(CrmReceivablePlanDO receivablePlan) {  
82 -  
83 - if (ObjectUtil.isNull(receivablePlan.getContractId())) {  
84 - throw exception(CONTRACT_NOT_EXISTS);  
85 - }  
86 -  
87 - CrmContractDO contract = contractService.getContract(receivablePlan.getContractId());  
88 - if (ObjectUtil.isNull(contract)) {  
89 - throw exception(CONTRACT_NOT_EXISTS);  
90 - }  
91 -  
92 - CrmCustomerDO customer = customerService.getCustomer(receivablePlan.getCustomerId());  
93 - if (ObjectUtil.isNull(customer)) {  
94 - throw exception(CUSTOMER_NOT_EXISTS);  
95 - }  
96 -  
97 - }  
98 -  
99 @Override 88 @Override
  89 + @Transactional(rollbackFor = Exception.class)
100 @LogRecord(type = CRM_RECEIVABLE_PLAN_TYPE, subType = CRM_RECEIVABLE_PLAN_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", 90 @LogRecord(type = CRM_RECEIVABLE_PLAN_TYPE, subType = CRM_RECEIVABLE_PLAN_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
101 success = CRM_RECEIVABLE_PLAN_UPDATE_SUCCESS) 91 success = CRM_RECEIVABLE_PLAN_UPDATE_SUCCESS)
102 @CrmPermission(bizType = CrmBizTypeEnum.CRM_RECEIVABLE_PLAN, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) 92 @CrmPermission(bizType = CrmBizTypeEnum.CRM_RECEIVABLE_PLAN, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
103 - public void updateReceivablePlan(CrmReceivablePlanUpdateReqVO updateReqVO) {  
104 - // TODO @liuhongfeng:如果已经有对应的还款,则不允许编辑;  
105 - // 校验存在 93 + public void updateReceivablePlan(CrmReceivablePlanSaveReqVO updateReqVO) {
  94 + // 1. 校验存在
  95 + checkReceivablePlan(updateReqVO);
106 CrmReceivablePlanDO oldReceivablePlan = validateReceivablePlanExists(updateReqVO.getId()); 96 CrmReceivablePlanDO oldReceivablePlan = validateReceivablePlanExists(updateReqVO.getId());
  97 + if (Objects.nonNull(oldReceivablePlan.getReceivableId())) { // 如果已经有对应的还款,则不允许编辑;
  98 + throw exception(RECEIVABLE_PLAN_UPDATE_FAIL, "已经有对应的还款");
  99 + }
107 100
108 - // 更新  
109 - CrmReceivablePlanDO updateObj = CrmReceivablePlanConvert.INSTANCE.convert(updateReqVO); 101 + // 2. 更新
  102 + CrmReceivablePlanDO updateObj = BeanUtils.toBean(updateReqVO, CrmReceivablePlanDO.class);
110 receivablePlanMapper.updateById(updateObj); 103 receivablePlanMapper.updateById(updateObj);
111 104
112 // 3. 记录操作日志上下文 105 // 3. 记录操作日志上下文
113 - LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldReceivablePlan, CrmReceivablePlanUpdateReqVO.class)); 106 + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldReceivablePlan, CrmReceivablePlanSaveReqVO.class));
114 LogRecordContext.putVariable("receivablePlan", oldReceivablePlan); 107 LogRecordContext.putVariable("receivablePlan", oldReceivablePlan);
115 } 108 }
116 109
  110 + private void checkReceivablePlan(CrmReceivablePlanSaveReqVO reqVO) {
  111 + adminUserApi.validateUser(reqVO.getOwnerUserId()); // 校验负责人存在
  112 + CrmContractDO contract = contractService.getContract(reqVO.getContractId());
  113 + if (ObjectUtil.isNull(contract)) { // 合同不存在
  114 + throw exception(CONTRACT_NOT_EXISTS);
  115 + }
  116 + CrmCustomerDO customer = customerService.getCustomer(reqVO.getCustomerId());
  117 + if (ObjectUtil.isNull(customer)) { // 客户不存在
  118 + throw exception(CUSTOMER_NOT_EXISTS);
  119 + }
  120 + }
  121 +
117 @Override 122 @Override
  123 + @Transactional(rollbackFor = Exception.class)
118 @LogRecord(type = CRM_RECEIVABLE_PLAN_TYPE, subType = CRM_RECEIVABLE_PLAN_DELETE_SUB_TYPE, bizNo = "{{#id}}", 124 @LogRecord(type = CRM_RECEIVABLE_PLAN_TYPE, subType = CRM_RECEIVABLE_PLAN_DELETE_SUB_TYPE, bizNo = "{{#id}}",
119 success = CRM_RECEIVABLE_PLAN_DELETE_SUCCESS) 125 success = CRM_RECEIVABLE_PLAN_DELETE_SUCCESS)
120 @CrmPermission(bizType = CrmBizTypeEnum.CRM_RECEIVABLE_PLAN, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) 126 @CrmPermission(bizType = CrmBizTypeEnum.CRM_RECEIVABLE_PLAN, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java
@@ -86,4 +86,12 @@ public interface CrmReceivableService { @@ -86,4 +86,12 @@ public interface CrmReceivableService {
86 */ 86 */
87 Long getCheckReceivablesCount(Long userId); 87 Long getCheckReceivablesCount(Long userId);
88 88
  89 + /**
  90 + * 根据合同编号,获取合同关联的回款数量
  91 + *
  92 + * @param contractId 合同编号
  93 + * @return 数量
  94 + */
  95 + Long getReceivableCountByContractId(Long contractId);
  96 +
89 } 97 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java
@@ -187,4 +187,9 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { @@ -187,4 +187,9 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
187 return receivableMapper.selectCheckReceivablesCount(userId); 187 return receivableMapper.selectCheckReceivablesCount(userId);
188 } 188 }
189 189
  190 + @Override
  191 + public Long getReceivableCountByContractId(Long contractId) {
  192 + return receivableMapper.selectCount(CrmReceivableDO::getContractId, contractId);
  193 + }
  194 +
190 } 195 }