Commit 0fba56cda88f443e4fd2fb651a99ef5cfba349de
1 parent
c6041da3
📖 CRM:code review 合同逻辑
Showing
11 changed files
with
33 additions
and
21 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java
| @@ -77,6 +77,7 @@ public class CrmBusinessSaveReqVO { | @@ -77,6 +77,7 @@ public class CrmBusinessSaveReqVO { | ||
| 77 | @Schema(description = "联系人编号", example = "110") | 77 | @Schema(description = "联系人编号", example = "110") |
| 78 | private Long contactId; // 使用场景,在【联系人详情】添加商机时,如果需要关联两者,需要传递 contactId 字段 | 78 | private Long contactId; // 使用场景,在【联系人详情】添加商机时,如果需要关联两者,需要传递 contactId 字段 |
| 79 | 79 | ||
| 80 | + // TODO @puhui999:传递 items 就行啦; | ||
| 80 | @Schema(description = "产品列表") | 81 | @Schema(description = "产品列表") |
| 81 | private List<CrmBusinessProductItem> productItems; | 82 | private List<CrmBusinessProductItem> productItems; |
| 82 | 83 | ||
| @@ -86,7 +87,7 @@ public class CrmBusinessSaveReqVO { | @@ -86,7 +87,7 @@ public class CrmBusinessSaveReqVO { | ||
| 86 | @AllArgsConstructor | 87 | @AllArgsConstructor |
| 87 | public static class CrmBusinessProductItem { | 88 | public static class CrmBusinessProductItem { |
| 88 | 89 | ||
| 89 | - @Schema(description = "产品编号", example = "20529") | 90 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529") |
| 90 | @NotNull(message = "产品编号不能为空") | 91 | @NotNull(message = "产品编号不能为空") |
| 91 | private Long id; | 92 | private Long id; |
| 92 | 93 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
| @@ -46,6 +46,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | @@ -46,6 +46,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 46 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | 46 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 47 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 47 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 48 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 48 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 49 | +import static java.util.Collections.singletonList; | ||
| 49 | 50 | ||
| 50 | @Tag(name = "管理后台 - CRM 合同") | 51 | @Tag(name = "管理后台 - CRM 合同") |
| 51 | @RestController | 52 | @RestController |
| @@ -102,7 +103,7 @@ public class CrmContractController { | @@ -102,7 +103,7 @@ public class CrmContractController { | ||
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | // 2. 拼接合同信息 | 105 | // 2. 拼接合同信息 |
| 105 | - List<CrmContractRespVO> respVOList = buildContractDetailList(Collections.singletonList(contract)); | 106 | + List<CrmContractRespVO> respVOList = buildContractDetailList(singletonList(contract)); |
| 106 | return success(respVOList.get(0)); | 107 | return success(respVOList.get(0)); |
| 107 | } | 108 | } |
| 108 | 109 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractRespVO.java
| @@ -132,6 +132,7 @@ public class CrmContractRespVO { | @@ -132,6 +132,7 @@ public class CrmContractRespVO { | ||
| 132 | @Schema(description = "产品列表") | 132 | @Schema(description = "产品列表") |
| 133 | private List<CrmContractProductItemRespVO> productItems; | 133 | private List<CrmContractProductItemRespVO> productItems; |
| 134 | 134 | ||
| 135 | + // TODO @puhui999:可以直接叫 Item | ||
| 135 | @Schema(description = "产品列表") | 136 | @Schema(description = "产品列表") |
| 136 | @Data | 137 | @Data |
| 137 | @NoArgsConstructor | 138 | @NoArgsConstructor |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contract/CrmContractConvert.java
| @@ -61,9 +61,8 @@ public interface CrmContractConvert { | @@ -61,9 +61,8 @@ public interface CrmContractConvert { | ||
| 61 | List<CrmProductDO> productList) { | 61 | List<CrmProductDO> productList) { |
| 62 | respVO.setProductItems(CollectionUtils.convertList(productList, product -> { | 62 | respVO.setProductItems(CollectionUtils.convertList(productList, product -> { |
| 63 | CrmContractRespVO.CrmContractProductItemRespVO productItemRespVO = BeanUtils.toBean(product, CrmContractRespVO.CrmContractProductItemRespVO.class); | 63 | CrmContractRespVO.CrmContractProductItemRespVO productItemRespVO = BeanUtils.toBean(product, CrmContractRespVO.CrmContractProductItemRespVO.class); |
| 64 | - findAndThen(contractProductMap, product.getId(), contractProduct -> { | ||
| 65 | - productItemRespVO.setCount(contractProduct.getCount()).setDiscountPercent(contractProduct.getDiscountPercent()); | ||
| 66 | - }); | 64 | + findAndThen(contractProductMap, product.getId(), contractProduct -> |
| 65 | + productItemRespVO.setCount(contractProduct.getCount()).setDiscountPercent(contractProduct.getDiscountPercent())); | ||
| 67 | return productItemRespVO; | 66 | return productItemRespVO; |
| 68 | })); | 67 | })); |
| 69 | } | 68 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contract/CrmContractProductDO.java
| @@ -57,6 +57,8 @@ public class CrmContractProductDO extends BaseDO { | @@ -57,6 +57,8 @@ public class CrmContractProductDO extends BaseDO { | ||
| 57 | private Integer discountPercent; | 57 | private Integer discountPercent; |
| 58 | /** | 58 | /** |
| 59 | * 总计价格(折扣后价格) | 59 | * 总计价格(折扣后价格) |
| 60 | + * | ||
| 61 | + * TODO @puhui999:可以写下计算公式哈; | ||
| 60 | */ | 62 | */ |
| 61 | private Integer totalPrice; | 63 | private Integer totalPrice; |
| 62 | 64 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessProductMapper.java
| @@ -16,15 +16,17 @@ import java.util.List; | @@ -16,15 +16,17 @@ import java.util.List; | ||
| 16 | @Mapper | 16 | @Mapper |
| 17 | public interface CrmBusinessProductMapper extends BaseMapperX<CrmBusinessProductDO> { | 17 | public interface CrmBusinessProductMapper extends BaseMapperX<CrmBusinessProductDO> { |
| 18 | 18 | ||
| 19 | - default void deleteByBusinessId(Long id) { // TODO @lzxhqs:第一个方法,和类之间最好空一行; | ||
| 20 | - delete(CrmBusinessProductDO::getBusinessId, id); | 19 | + // TODO @puhui999:用不到的方法,看看是不是删除哈 |
| 20 | + default void deleteByBusinessId(Long getBusinessId) { // TODO @lzxhqs:第一个方法,和类之间最好空一行; | ||
| 21 | + delete(CrmBusinessProductDO::getBusinessId, getBusinessId); | ||
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | - default CrmBusinessProductDO selectByBusinessId(Long id) { | ||
| 24 | - return selectOne(CrmBusinessProductDO::getBusinessId, id); | 24 | + default CrmBusinessProductDO selectByBusinessId(Long getBusinessId) { |
| 25 | + return selectOne(CrmBusinessProductDO::getBusinessId, getBusinessId); | ||
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | default List<CrmBusinessProductDO> selectListByBusinessId(Long businessId) { | 28 | default List<CrmBusinessProductDO> selectListByBusinessId(Long businessId) { |
| 29 | + // TODO @puhui999:可以简化,selectList(CrmBusinessProductDO::getBusinessId, businessId) | ||
| 28 | return selectList(new LambdaQueryWrapperX<CrmBusinessProductDO>().eq(CrmBusinessProductDO::getBusinessId, businessId)); | 30 | return selectList(new LambdaQueryWrapperX<CrmBusinessProductDO>().eq(CrmBusinessProductDO::getBusinessId, businessId)); |
| 29 | } | 31 | } |
| 30 | 32 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractProductMapper.java
| @@ -16,6 +16,7 @@ import java.util.List; | @@ -16,6 +16,7 @@ import java.util.List; | ||
| 16 | @Mapper | 16 | @Mapper |
| 17 | public interface CrmContractProductMapper extends BaseMapperX<CrmContractProductDO> { | 17 | public interface CrmContractProductMapper extends BaseMapperX<CrmContractProductDO> { |
| 18 | 18 | ||
| 19 | + // TODO @puhui999:用不到的方法,看看是不是删除哈 | ||
| 19 | default void deleteByContractId(Long contractId) { // TODO @lzxhqs:第一个方法,和类之间最好空一行; | 20 | default void deleteByContractId(Long contractId) { // TODO @lzxhqs:第一个方法,和类之间最好空一行; |
| 20 | delete(CrmContractProductDO::getContractId, contractId); | 21 | delete(CrmContractProductDO::getContractId, contractId); |
| 21 | } | 22 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
| @@ -81,13 +81,13 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -81,13 +81,13 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 81 | businessMapper.insert(business); | 81 | businessMapper.insert(business); |
| 82 | // 1.2 插入商机关联商品 | 82 | // 1.2 插入商机关联商品 |
| 83 | if (CollUtil.isNotEmpty(createReqVO.getProductItems())) { // 如果有的话 | 83 | if (CollUtil.isNotEmpty(createReqVO.getProductItems())) { // 如果有的话 |
| 84 | - List<CrmBusinessProductDO> productList = convertBusinessProductList(createReqVO.getProductItems(), business.getId()); | 84 | + List<CrmBusinessProductDO> productList = buildBusinessProductList(createReqVO.getProductItems(), business.getId()); |
| 85 | businessProductMapper.insertBatch(productList); | 85 | businessProductMapper.insertBatch(productList); |
| 86 | // 更新合同商品总金额 | 86 | // 更新合同商品总金额 |
| 87 | businessMapper.updateById(new CrmBusinessDO().setId(business.getId()).setProductPrice( | 87 | businessMapper.updateById(new CrmBusinessDO().setId(business.getId()).setProductPrice( |
| 88 | getSumValue(productList, CrmBusinessProductDO::getTotalPrice, Integer::sum))); | 88 | getSumValue(productList, CrmBusinessProductDO::getTotalPrice, Integer::sum))); |
| 89 | } | 89 | } |
| 90 | - // TODO 商机待定:在联系人的详情页,如果直接【新建商机】,则需要关联下。这里要搞个 CrmContactBusinessDO 表 | 90 | + // TODO @puhui999:在联系人的详情页,如果直接【新建商机】,则需要关联下。这里要搞个 CrmContactBusinessDO 表 |
| 91 | createContactBusiness(business.getId(), createReqVO.getContactId()); | 91 | createContactBusiness(business.getId(), createReqVO.getContactId()); |
| 92 | 92 | ||
| 93 | // 2. 创建数据权限 | 93 | // 2. 创建数据权限 |
| @@ -95,7 +95,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -95,7 +95,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 95 | permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()) | 95 | permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()) |
| 96 | .setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); | 96 | .setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); |
| 97 | 97 | ||
| 98 | - // 4. 记录操作日志上下文 | 98 | + // 3. 记录操作日志上下文 |
| 99 | LogRecordContext.putVariable("business", business); | 99 | LogRecordContext.putVariable("business", business); |
| 100 | return business.getId(); | 100 | return business.getId(); |
| 101 | } | 101 | } |
| @@ -121,7 +121,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -121,7 +121,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 121 | CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class); | 121 | CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class); |
| 122 | businessMapper.updateById(updateObj); | 122 | businessMapper.updateById(updateObj); |
| 123 | // 2.2 更新商机关联商品 | 123 | // 2.2 更新商机关联商品 |
| 124 | - List<CrmBusinessProductDO> productList = convertBusinessProductList(updateReqVO.getProductItems(), updateObj.getId()); | 124 | + List<CrmBusinessProductDO> productList = buildBusinessProductList(updateReqVO.getProductItems(), updateObj.getId()); |
| 125 | updateBusinessProduct(productList, updateObj.getId()); | 125 | updateBusinessProduct(productList, updateObj.getId()); |
| 126 | 126 | ||
| 127 | // TODO @商机待定:如果状态发生变化,插入商机状态变更记录表 | 127 | // TODO @商机待定:如果状态发生变化,插入商机状态变更记录表 |
| @@ -175,7 +175,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -175,7 +175,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 175 | } | 175 | } |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | - private List<CrmBusinessProductDO> convertBusinessProductList(List<CrmBusinessSaveReqVO.CrmBusinessProductItem> productItems, Long businessId) { | 178 | + private List<CrmBusinessProductDO> buildBusinessProductList(List<CrmBusinessSaveReqVO.CrmBusinessProductItem> productItems, |
| 179 | + Long businessId) { | ||
| 179 | // 校验商品存在 | 180 | // 校验商品存在 |
| 180 | Set<Long> productIds = convertSet(productItems, CrmBusinessSaveReqVO.CrmBusinessProductItem::getId); | 181 | Set<Long> productIds = convertSet(productItems, CrmBusinessSaveReqVO.CrmBusinessProductItem::getId); |
| 181 | List<CrmProductDO> productList = productService.getProductList(productIds); | 182 | List<CrmProductDO> productList = productService.getProductList(productIds); |
| @@ -235,7 +236,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -235,7 +236,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 235 | @Override | 236 | @Override |
| 236 | public void updateBusinessProduct(CrmBusinessUpdateProductReqBO updateProductReqBO) { | 237 | public void updateBusinessProduct(CrmBusinessUpdateProductReqBO updateProductReqBO) { |
| 237 | // 更新商机关联商品 | 238 | // 更新商机关联商品 |
| 238 | - List<CrmBusinessProductDO> productList = convertBusinessProductList( | 239 | + List<CrmBusinessProductDO> productList = buildBusinessProductList( |
| 239 | BeanUtils.toBean(updateProductReqBO.getProductItems(), CrmBusinessSaveReqVO.CrmBusinessProductItem.class), updateProductReqBO.getId()); | 240 | BeanUtils.toBean(updateProductReqBO.getProductItems(), CrmBusinessSaveReqVO.CrmBusinessProductItem.class), updateProductReqBO.getId()); |
| 240 | updateBusinessProduct(productList, updateProductReqBO.getId()); | 241 | updateBusinessProduct(productList, updateProductReqBO.getId()); |
| 241 | } | 242 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/bo/CrmBusinessUpdateProductReqBO.java
| @@ -23,6 +23,7 @@ public class CrmBusinessUpdateProductReqBO { | @@ -23,6 +23,7 @@ public class CrmBusinessUpdateProductReqBO { | ||
| 23 | @NotNull(message = "商机编号不能为空") | 23 | @NotNull(message = "商机编号不能为空") |
| 24 | private Long id; | 24 | private Long id; |
| 25 | 25 | ||
| 26 | + // TODO @芋艿:再想想 | ||
| 26 | @NotEmpty(message = "产品列表不能为空") | 27 | @NotEmpty(message = "产品列表不能为空") |
| 27 | private List<CrmBusinessProductItem> productItems; | 28 | private List<CrmBusinessProductItem> productItems; |
| 28 | 29 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
| @@ -61,7 +61,10 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_E | @@ -61,7 +61,10 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_E | ||
| 61 | @Validated | 61 | @Validated |
| 62 | public class CrmContractServiceImpl implements CrmContractService { | 62 | public class CrmContractServiceImpl implements CrmContractService { |
| 63 | 63 | ||
| 64 | - public static final String CONTRACT_APPROVE = "contract-approve"; // 合同审批流程标识 | 64 | + /** |
| 65 | + * BPM 合同审批流程标识 | ||
| 66 | + */ | ||
| 67 | + public static final String CONTRACT_APPROVE = "contract-approve"; | ||
| 65 | 68 | ||
| 66 | @Resource | 69 | @Resource |
| 67 | private CrmContractMapper contractMapper; | 70 | private CrmContractMapper contractMapper; |
| @@ -149,11 +152,11 @@ public class CrmContractServiceImpl implements CrmContractService { | @@ -149,11 +152,11 @@ public class CrmContractServiceImpl implements CrmContractService { | ||
| 149 | List<CrmContractProductDO> newProductList = convertContractProductList(updateReqVO, contractId); | 152 | List<CrmContractProductDO> newProductList = convertContractProductList(updateReqVO, contractId); |
| 150 | List<CrmContractProductDO> oldProductList = contractProductMapper.selectListByContractId(contractId); | 153 | List<CrmContractProductDO> oldProductList = contractProductMapper.selectListByContractId(contractId); |
| 151 | List<List<CrmContractProductDO>> diffList = diffList(oldProductList, newProductList, (oldObj, newObj) -> { | 154 | List<List<CrmContractProductDO>> diffList = diffList(oldProductList, newProductList, (oldObj, newObj) -> { |
| 152 | - boolean equal = ObjUtil.equal(oldObj.getProductId(), newObj.getProductId()); | ||
| 153 | - if (equal) { | 155 | + boolean match = ObjUtil.equal(oldObj.getProductId(), newObj.getProductId()); |
| 156 | + if (match) { | ||
| 154 | newObj.setId(oldObj.getId()); // 设置一下老的编号更新时需要使用 | 157 | newObj.setId(oldObj.getId()); // 设置一下老的编号更新时需要使用 |
| 155 | } | 158 | } |
| 156 | - return equal; | 159 | + return match; |
| 157 | }); | 160 | }); |
| 158 | if (CollUtil.isNotEmpty(diffList.get(0))) { | 161 | if (CollUtil.isNotEmpty(diffList.get(0))) { |
| 159 | contractProductMapper.insertBatch(diffList.get(0)); | 162 | contractProductMapper.insertBatch(diffList.get(0)); |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
| @@ -266,10 +266,10 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | @@ -266,10 +266,10 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { | ||
| 266 | CrmCustomerDO customer = initCustomer(importCustomer, importReqVO.getOwnerUserId()); | 266 | CrmCustomerDO customer = initCustomer(importCustomer, importReqVO.getOwnerUserId()); |
| 267 | customerMapper.insert(customer); | 267 | customerMapper.insert(customer); |
| 268 | respVO.getCreateCustomerNames().add(importCustomer.getName()); | 268 | respVO.getCreateCustomerNames().add(importCustomer.getName()); |
| 269 | + // 1.2 创建数据权限 | ||
| 269 | if (importReqVO.getOwnerUserId() != null) { | 270 | if (importReqVO.getOwnerUserId() != null) { |
| 270 | - // 1.2 创建数据权限 | ||
| 271 | permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()) | 271 | permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()) |
| 272 | - .setBizId(customer.getId()).setUserId(importReqVO.getOwnerUserId()).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人 | 272 | + .setBizId(customer.getId()).setUserId(importReqVO.getOwnerUserId()).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); |
| 273 | } | 273 | } |
| 274 | // 1.3 记录操作日志 | 274 | // 1.3 记录操作日志 |
| 275 | getSelf().importCustomerLog(customer, false); | 275 | getSelf().importCustomerLog(customer, false); |