Commit b0def8b5862dea8c81b1bf0a82832625d5744de9
1 parent
ef26b5e8
✨ CRM:完善合同的新增、修改实现
Showing
10 changed files
with
102 additions
and
154 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
| @@ -135,7 +135,6 @@ public class CrmBusinessController { | @@ -135,7 +135,6 @@ public class CrmBusinessController { | ||
| 135 | return success(BeanUtils.toBean(businessService.getBusinessList(ids, getLoginUserId()), CrmBusinessRespVO.class)); | 135 | return success(BeanUtils.toBean(businessService.getBusinessList(ids, getLoginUserId()), CrmBusinessRespVO.class)); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | - // TODO 芋艿:处理下 | ||
| 139 | @GetMapping("/simple-all-list") | 138 | @GetMapping("/simple-all-list") |
| 140 | @Operation(summary = "获得联系人的精简列表") | 139 | @Operation(summary = "获得联系人的精简列表") |
| 141 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") | 140 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| @@ -144,7 +143,8 @@ public class CrmBusinessController { | @@ -144,7 +143,8 @@ public class CrmBusinessController { | ||
| 144 | reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页 | 143 | reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页 |
| 145 | PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPage(reqVO, getLoginUserId()); | 144 | PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPage(reqVO, getLoginUserId()); |
| 146 | return success(convertList(pageResult.getList(), business -> // 只返回 id、name 字段 | 145 | return success(convertList(pageResult.getList(), business -> // 只返回 id、name 字段 |
| 147 | - new CrmBusinessRespVO().setId(business.getId()).setName(business.getName()))); | 146 | + new CrmBusinessRespVO().setId(business.getId()).setName(business.getName()) |
| 147 | + .setCustomerId(business.getCustomerId()))); | ||
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | @GetMapping("/page") | 150 | @GetMapping("/page") |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java
| @@ -120,7 +120,8 @@ public class CrmContactController { | @@ -120,7 +120,8 @@ public class CrmContactController { | ||
| 120 | public CommonResult<List<CrmContactRespVO>> getSimpleContactList() { | 120 | public CommonResult<List<CrmContactRespVO>> getSimpleContactList() { |
| 121 | List<CrmContactDO> list = contactService.getContactList(getLoginUserId()); | 121 | List<CrmContactDO> list = contactService.getContactList(getLoginUserId()); |
| 122 | return success(convertList(list, contact -> // 只返回 id、name 字段 | 122 | return success(convertList(list, contact -> // 只返回 id、name 字段 |
| 123 | - new CrmContactRespVO().setId(contact.getId()).setName(contact.getName()))); | 123 | + new CrmContactRespVO().setId(contact.getId()).setName(contact.getName()) |
| 124 | + .setCustomerId(contact.getCustomerId()))); | ||
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | @GetMapping("/page") | 127 | @GetMapping("/page") |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
| @@ -16,7 +16,9 @@ import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTrans | @@ -16,7 +16,9 @@ import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTrans | ||
| 16 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | 16 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; |
| 17 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | 17 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; |
| 18 | import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; | 18 | import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; |
| 19 | +import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractProductDO; | ||
| 19 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 20 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 21 | +import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; | ||
| 20 | import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; | 22 | import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; |
| 21 | import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; | 23 | import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; |
| 22 | import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; | 24 | import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; |
| @@ -108,13 +110,16 @@ public class CrmContractController { | @@ -108,13 +110,16 @@ public class CrmContractController { | ||
| 108 | if (contract == null) { | 110 | if (contract == null) { |
| 109 | return null; | 111 | return null; |
| 110 | } | 112 | } |
| 111 | -// List<CrmProductDO> productList = null; | ||
| 112 | -// if (contractList.size() == 1) { | ||
| 113 | -// List<CrmContractProductDO> contractProductList = contractService.getContractProductListByContractId(contractList.get(0).getId()); | ||
| 114 | -// contractProductMap = convertMap(contractProductList, CrmContractProductDO::getProductId); | ||
| 115 | -// productList = productService.getProductList(convertSet(contractProductList, CrmContractProductDO::getProductId)); | ||
| 116 | -// } | ||
| 117 | - return buildContractDetailList(singletonList(contract)).get(0); | 113 | + CrmContractRespVO contractVO = buildContractDetailList(singletonList(contract)).get(0); |
| 114 | + // 拼接产品项 | ||
| 115 | + List<CrmContractProductDO> businessProducts = contractService.getContractProductListByContractId(contractVO.getId()); | ||
| 116 | + Map<Long, CrmProductDO> productMap = productService.getProductMap( | ||
| 117 | + convertSet(businessProducts, CrmContractProductDO::getProductId)); | ||
| 118 | + contractVO.setProducts(BeanUtils.toBean(businessProducts, CrmContractRespVO.Product.class, businessProductVO -> | ||
| 119 | + MapUtils.findAndThen(productMap, businessProductVO.getProductId(), | ||
| 120 | + product -> businessProductVO.setProductName(product.getName()) | ||
| 121 | + .setProductNo(product.getNo()).setProductUnit(product.getUnit())))); | ||
| 122 | + return contractVO; | ||
| 118 | } | 123 | } |
| 119 | 124 | ||
| 120 | @GetMapping("/page") | 125 | @GetMapping("/page") |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractRespVO.java
| @@ -121,13 +121,13 @@ public class CrmContractRespVO { | @@ -121,13 +121,13 @@ public class CrmContractRespVO { | ||
| 121 | private LocalDateTime updateTime; | 121 | private LocalDateTime updateTime; |
| 122 | 122 | ||
| 123 | @Schema(description = "产品列表") | 123 | @Schema(description = "产品列表") |
| 124 | - private List<Item> products; | 124 | + private List<Product> products; |
| 125 | 125 | ||
| 126 | @Schema(description = "产品列表") | 126 | @Schema(description = "产品列表") |
| 127 | @Data | 127 | @Data |
| 128 | @NoArgsConstructor | 128 | @NoArgsConstructor |
| 129 | @AllArgsConstructor | 129 | @AllArgsConstructor |
| 130 | - public static class Item { | 130 | + public static class Product { |
| 131 | 131 | ||
| 132 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "888") | 132 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "888") |
| 133 | private Long id; | 133 | private Long id; |
| @@ -145,7 +145,7 @@ public class CrmContractRespVO { | @@ -145,7 +145,7 @@ public class CrmContractRespVO { | ||
| 145 | private BigDecimal productPrice; | 145 | private BigDecimal productPrice; |
| 146 | 146 | ||
| 147 | @Schema(description = "合同价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "123.00") | 147 | @Schema(description = "合同价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "123.00") |
| 148 | - private BigDecimal businessPrice; | 148 | + private BigDecimal contractPrice; |
| 149 | 149 | ||
| 150 | @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911") | 150 | @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911") |
| 151 | private BigDecimal count; | 151 | private BigDecimal count; |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractSaveReqVO.java
| @@ -100,7 +100,7 @@ public class CrmContractSaveReqVO { | @@ -100,7 +100,7 @@ public class CrmContractSaveReqVO { | ||
| 100 | 100 | ||
| 101 | @Schema(description = "合同价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "123.00") | 101 | @Schema(description = "合同价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "123.00") |
| 102 | @NotNull(message = "合同价格不能为空") | 102 | @NotNull(message = "合同价格不能为空") |
| 103 | - private BigDecimal businessPrice; | 103 | + private BigDecimal contractPrice; |
| 104 | 104 | ||
| 105 | @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911") | 105 | @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911") |
| 106 | @NotNull(message = "产品数量不能为空") | 106 | @NotNull(message = "产品数量不能为空") |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contract/CrmContractProductDO.java
| @@ -44,7 +44,7 @@ public class CrmContractProductDO extends BaseDO { | @@ -44,7 +44,7 @@ public class CrmContractProductDO extends BaseDO { | ||
| 44 | /** | 44 | /** |
| 45 | * 产品单价,单位:元 | 45 | * 产品单价,单位:元 |
| 46 | */ | 46 | */ |
| 47 | - private Integer productPrice; | 47 | + private BigDecimal productPrice; |
| 48 | /** | 48 | /** |
| 49 | * 合同价格, 单位:分 | 49 | * 合同价格, 单位:分 |
| 50 | */ | 50 | */ |
| @@ -58,6 +58,6 @@ public class CrmContractProductDO extends BaseDO { | @@ -58,6 +58,6 @@ public class CrmContractProductDO extends BaseDO { | ||
| 58 | * | 58 | * |
| 59 | * totalPrice = businessPrice * count | 59 | * totalPrice = businessPrice * count |
| 60 | */ | 60 | */ |
| 61 | - private Integer totalPrice; | 61 | + private BigDecimal totalPrice; |
| 62 | 62 | ||
| 63 | } | 63 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java
| @@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusDO; | @@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusDO; | ||
| 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; |
| 12 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 12 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 13 | import cn.iocoder.yudao.module.crm.enums.business.CrmBusinessEndStatusEnum; | 13 | import cn.iocoder.yudao.module.crm.enums.business.CrmBusinessEndStatusEnum; |
| 14 | -import cn.iocoder.yudao.module.crm.service.business.bo.CrmBusinessUpdateProductReqBO; | ||
| 15 | import jakarta.validation.Valid; | 14 | import jakarta.validation.Valid; |
| 16 | 15 | ||
| 17 | import java.time.LocalDateTime; | 16 | import java.time.LocalDateTime; |
| @@ -81,19 +80,20 @@ public interface CrmBusinessService { | @@ -81,19 +80,20 @@ public interface CrmBusinessService { | ||
| 81 | void transferBusiness(CrmBusinessTransferReqVO reqVO, Long userId); | 80 | void transferBusiness(CrmBusinessTransferReqVO reqVO, Long userId); |
| 82 | 81 | ||
| 83 | /** | 82 | /** |
| 84 | - * 更新商机关联商品 | 83 | + * 获得商机 |
| 85 | * | 84 | * |
| 86 | - * @param updateProductReqBO 请求 | 85 | + * @param id 编号 |
| 86 | + * @return 商机 | ||
| 87 | */ | 87 | */ |
| 88 | - void updateBusinessProduct(CrmBusinessUpdateProductReqBO updateProductReqBO); | 88 | + CrmBusinessDO getBusiness(Long id); |
| 89 | 89 | ||
| 90 | /** | 90 | /** |
| 91 | - * 获得商机 | 91 | + * 校验商机是否有效 |
| 92 | * | 92 | * |
| 93 | * @param id 编号 | 93 | * @param id 编号 |
| 94 | * @return 商机 | 94 | * @return 商机 |
| 95 | */ | 95 | */ |
| 96 | - CrmBusinessDO getBusiness(Long id); | 96 | + CrmBusinessDO validateBusiness(Long id); |
| 97 | 97 | ||
| 98 | /** | 98 | /** |
| 99 | * 获得商机列表 | 99 | * 获得商机列表 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
| @@ -19,7 +19,6 @@ import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessProductMapper; | @@ -19,7 +19,6 @@ import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessProductMapper; | ||
| 19 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | 19 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; |
| 20 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; | 20 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; |
| 21 | import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; | 21 | import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; |
| 22 | -import cn.iocoder.yudao.module.crm.service.business.bo.CrmBusinessUpdateProductReqBO; | ||
| 23 | import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService; | 22 | import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService; |
| 24 | import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; | 23 | import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; |
| 25 | import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; | 24 | import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; |
| @@ -91,10 +90,10 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -91,10 +90,10 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 91 | // 1.1 校验产品项的有效性 | 90 | // 1.1 校验产品项的有效性 |
| 92 | List<CrmBusinessProductDO> businessProducts = validateBusinessProducts(createReqVO.getProducts()); | 91 | List<CrmBusinessProductDO> businessProducts = validateBusinessProducts(createReqVO.getProducts()); |
| 93 | // 1.2 校验关联字段 | 92 | // 1.2 校验关联字段 |
| 94 | - validateBusinessForCreate(createReqVO); | 93 | + validateRelationDataExists(createReqVO); |
| 95 | 94 | ||
| 96 | // 2.1 插入商机 | 95 | // 2.1 插入商机 |
| 97 | - CrmBusinessDO business = BeanUtils.toBean(createReqVO, CrmBusinessDO.class).setOwnerUserId(userId); | 96 | + CrmBusinessDO business = BeanUtils.toBean(createReqVO, CrmBusinessDO.class); |
| 98 | business.setStatusId(businessStatusService.getBusinessStatusListByTypeId(createReqVO.getStatusTypeId()).get(0).getId()); // 默认状态 | 97 | business.setStatusId(businessStatusService.getBusinessStatusListByTypeId(createReqVO.getStatusTypeId()).get(0).getId()); // 默认状态 |
| 99 | calculateTotalPrice(business, businessProducts); | 98 | calculateTotalPrice(business, businessProducts); |
| 100 | businessMapper.insert(business); | 99 | businessMapper.insert(business); |
| @@ -105,9 +104,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -105,9 +104,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 105 | } | 104 | } |
| 106 | 105 | ||
| 107 | // 3. 创建数据权限 | 106 | // 3. 创建数据权限 |
| 108 | - // 设置当前操作的人为负责人 | ||
| 109 | - permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()) | ||
| 110 | - .setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); | 107 | + permissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(business.getOwnerUserId()) |
| 108 | + .setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()).setBizId(business.getId()) | ||
| 109 | + .setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); | ||
| 111 | 110 | ||
| 112 | // 4. 在联系人的详情页,如果直接【新建商机】,则需要关联下 | 111 | // 4. 在联系人的详情页,如果直接【新建商机】,则需要关联下 |
| 113 | if (createReqVO.getContactId() != null) { | 112 | if (createReqVO.getContactId() != null) { |
| @@ -132,7 +131,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -132,7 +131,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 132 | // 1.2 校验产品项的有效性 | 131 | // 1.2 校验产品项的有效性 |
| 133 | List<CrmBusinessProductDO> businessProducts = validateBusinessProducts(updateReqVO.getProducts()); | 132 | List<CrmBusinessProductDO> businessProducts = validateBusinessProducts(updateReqVO.getProducts()); |
| 134 | // 1.3 校验关联字段 | 133 | // 1.3 校验关联字段 |
| 135 | - validateBusinessForCreate(updateReqVO); | 134 | + validateRelationDataExists(updateReqVO); |
| 136 | 135 | ||
| 137 | // 2.1 更新商机 | 136 | // 2.1 更新商机 |
| 138 | CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class); | 137 | CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class); |
| @@ -184,7 +183,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -184,7 +183,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 184 | } | 183 | } |
| 185 | } | 184 | } |
| 186 | 185 | ||
| 187 | - private void validateBusinessForCreate(CrmBusinessSaveReqVO saveReqVO) { | 186 | + private void validateRelationDataExists(CrmBusinessSaveReqVO saveReqVO) { |
| 188 | // 校验商机状态 | 187 | // 校验商机状态 |
| 189 | if (saveReqVO.getStatusTypeId() != null) { | 188 | if (saveReqVO.getStatusTypeId() != null) { |
| 190 | businessStatusService.validateBusinessStatusType(saveReqVO.getStatusTypeId()); | 189 | businessStatusService.validateBusinessStatusType(saveReqVO.getStatusTypeId()); |
| @@ -207,9 +206,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -207,9 +206,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 207 | // 1. 校验产品存在 | 206 | // 1. 校验产品存在 |
| 208 | productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.Product::getProductId)); | 207 | productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.Product::getProductId)); |
| 209 | // 2. 转化为 CrmBusinessProductDO 列表 | 208 | // 2. 转化为 CrmBusinessProductDO 列表 |
| 210 | - return convertList(list, o -> BeanUtils.toBean(o, CrmBusinessProductDO.class, item -> { | ||
| 211 | - item.setTotalPrice(MoneyUtils.priceMultiply(item.getBusinessPrice(), item.getCount())); | ||
| 212 | - })); | 209 | + return convertList(list, o -> BeanUtils.toBean(o, CrmBusinessProductDO.class, |
| 210 | + item -> item.setTotalPrice(MoneyUtils.priceMultiply(item.getBusinessPrice(), item.getCount())))); | ||
| 213 | } | 211 | } |
| 214 | 212 | ||
| 215 | private void calculateTotalPrice(CrmBusinessDO business, List<CrmBusinessProductDO> businessProducts) { | 213 | private void calculateTotalPrice(CrmBusinessDO business, List<CrmBusinessProductDO> businessProducts) { |
| @@ -218,7 +216,6 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -218,7 +216,6 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 218 | business.setTotalPrice(business.getTotalProductPrice().subtract(discountPrice)); | 216 | business.setTotalPrice(business.getTotalProductPrice().subtract(discountPrice)); |
| 219 | } | 217 | } |
| 220 | 218 | ||
| 221 | - | ||
| 222 | @Override | 219 | @Override |
| 223 | @LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_UPDATE_STATUS_SUB_TYPE, bizNo = "{{#reqVO.id}}", | 220 | @LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_UPDATE_STATUS_SUB_TYPE, bizNo = "{{#reqVO.id}}", |
| 224 | success = CRM_BUSINESS_UPDATE_STATUS_SUCCESS) | 221 | success = CRM_BUSINESS_UPDATE_STATUS_SUCCESS) |
| @@ -312,14 +309,6 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -312,14 +309,6 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 312 | LogRecordContext.putVariable("business", business); | 309 | LogRecordContext.putVariable("business", business); |
| 313 | } | 310 | } |
| 314 | 311 | ||
| 315 | - @Override | ||
| 316 | - public void updateBusinessProduct(CrmBusinessUpdateProductReqBO updateProductReqBO) { | ||
| 317 | - // 更新商机关联商品 TODO yunai | ||
| 318 | -// List<CrmBusinessProductDO> productList = buildBusinessProductList( | ||
| 319 | -// BeanUtils.toBean(updateProductReqBO.getProductItems(), CrmBusinessSaveReqVO.Product.class), updateProductReqBO.getId()); | ||
| 320 | -// updateBusinessProduct(productList, updateProductReqBO.getId()); | ||
| 321 | - } | ||
| 322 | - | ||
| 323 | //======================= 查询相关 ======================= | 312 | //======================= 查询相关 ======================= |
| 324 | 313 | ||
| 325 | @Override | 314 | @Override |
| @@ -329,6 +318,11 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -329,6 +318,11 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 329 | } | 318 | } |
| 330 | 319 | ||
| 331 | @Override | 320 | @Override |
| 321 | + public CrmBusinessDO validateBusiness(Long id) { | ||
| 322 | + return validateBusinessExists(id); | ||
| 323 | + } | ||
| 324 | + | ||
| 325 | + @Override | ||
| 332 | public List<CrmBusinessDO> getBusinessList(Collection<Long> ids, Long userId) { | 326 | public List<CrmBusinessDO> getBusinessList(Collection<Long> ids, Long userId) { |
| 333 | if (CollUtil.isEmpty(ids)) { | 327 | if (CollUtil.isEmpty(ids)) { |
| 334 | return ListUtil.empty(); | 328 | return ListUtil.empty(); |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/bo/CrmBusinessUpdateProductReqBO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.service.business.bo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import jakarta.validation.constraints.NotEmpty; | ||
| 5 | -import jakarta.validation.constraints.NotNull; | ||
| 6 | -import lombok.AllArgsConstructor; | ||
| 7 | -import lombok.Data; | ||
| 8 | -import lombok.NoArgsConstructor; | ||
| 9 | - | ||
| 10 | -import java.util.List; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * 更新商机商品 Update Req BO | ||
| 14 | - * | ||
| 15 | - * @author HUIHUI | ||
| 16 | - */ | ||
| 17 | -@Data | ||
| 18 | -public class CrmBusinessUpdateProductReqBO { | ||
| 19 | - | ||
| 20 | - /** | ||
| 21 | - * 商机编号 | ||
| 22 | - */ | ||
| 23 | - @NotNull(message = "商机编号不能为空") | ||
| 24 | - private Long id; | ||
| 25 | - | ||
| 26 | - // TODO @芋艿:再想想 | ||
| 27 | - @NotEmpty(message = "产品列表不能为空") | ||
| 28 | - private List<Item> items; | ||
| 29 | - | ||
| 30 | - @Schema(description = "产品列表") | ||
| 31 | - @Data | ||
| 32 | - @NoArgsConstructor | ||
| 33 | - @AllArgsConstructor | ||
| 34 | - public static class Item { | ||
| 35 | - | ||
| 36 | - @Schema(description = "产品编号", example = "20529") | ||
| 37 | - @NotNull(message = "产品编号不能为空") | ||
| 38 | - private Long id; | ||
| 39 | - | ||
| 40 | - @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911") | ||
| 41 | - @NotNull(message = "产品数量不能为空") | ||
| 42 | - private Integer count; | ||
| 43 | - | ||
| 44 | - @Schema(description = "产品折扣") | ||
| 45 | - private Integer discountPercent; | ||
| 46 | - | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
| @@ -5,6 +5,7 @@ import cn.hutool.core.collection.ListUtil; | @@ -5,6 +5,7 @@ import cn.hutool.core.collection.ListUtil; | ||
| 5 | import cn.hutool.core.lang.Assert; | 5 | import cn.hutool.core.lang.Assert; |
| 6 | import cn.hutool.core.util.ObjUtil; | 6 | import cn.hutool.core.util.ObjUtil; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | ||
| 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 9 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 10 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 10 | import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; | 11 | import cn.iocoder.yudao.module.bpm.api.listener.dto.BpmResultListenerRespDTO; |
| @@ -16,7 +17,6 @@ import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveR | @@ -16,7 +17,6 @@ import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveR | ||
| 16 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO; | 17 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO; |
| 17 | import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; | 18 | import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; |
| 18 | import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractProductDO; | 19 | import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractProductDO; |
| 19 | -import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; | ||
| 20 | import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper; | 20 | import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper; |
| 21 | import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractProductMapper; | 21 | import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractProductMapper; |
| 22 | import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum; | 22 | import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum; |
| @@ -24,7 +24,7 @@ import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | @@ -24,7 +24,7 @@ import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | ||
| 24 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; | 24 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; |
| 25 | import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; | 25 | import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; |
| 26 | import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; | 26 | import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; |
| 27 | -import cn.iocoder.yudao.module.crm.service.business.bo.CrmBusinessUpdateProductReqBO; | 27 | +import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; |
| 28 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | 28 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| 29 | import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO; | 29 | import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO; |
| 30 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; | 30 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| @@ -40,16 +40,14 @@ import org.springframework.stereotype.Service; | @@ -40,16 +40,14 @@ import org.springframework.stereotype.Service; | ||
| 40 | import org.springframework.transaction.annotation.Transactional; | 40 | import org.springframework.transaction.annotation.Transactional; |
| 41 | import org.springframework.validation.annotation.Validated; | 41 | import org.springframework.validation.annotation.Validated; |
| 42 | 42 | ||
| 43 | +import java.math.BigDecimal; | ||
| 43 | import java.util.Collection; | 44 | import java.util.Collection; |
| 44 | import java.util.List; | 45 | import java.util.List; |
| 45 | -import java.util.Map; | ||
| 46 | -import java.util.Set; | ||
| 47 | 46 | ||
| 48 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 47 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 49 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | 48 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 50 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | 49 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| 51 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; | 50 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; |
| 52 | -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; | ||
| 53 | 51 | ||
| 54 | /** | 52 | /** |
| 55 | * CRM 合同 Service 实现类 | 53 | * CRM 合同 Service 实现类 |
| @@ -78,6 +76,8 @@ public class CrmContractServiceImpl implements CrmContractService { | @@ -78,6 +76,8 @@ public class CrmContractServiceImpl implements CrmContractService { | ||
| 78 | private CrmCustomerService customerService; | 76 | private CrmCustomerService customerService; |
| 79 | @Resource | 77 | @Resource |
| 80 | private CrmBusinessService businessService; | 78 | private CrmBusinessService businessService; |
| 79 | + @Resource | ||
| 80 | + private CrmContactService contactService; | ||
| 81 | 81 | ||
| 82 | @Resource | 82 | @Resource |
| 83 | private AdminUserApi adminUserApi; | 83 | private AdminUserApi adminUserApi; |
| @@ -89,30 +89,29 @@ public class CrmContractServiceImpl implements CrmContractService { | @@ -89,30 +89,29 @@ public class CrmContractServiceImpl implements CrmContractService { | ||
| 89 | @LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_CREATE_SUB_TYPE, bizNo = "{{#contract.id}}", | 89 | @LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_CREATE_SUB_TYPE, bizNo = "{{#contract.id}}", |
| 90 | success = CRM_CONTRACT_CREATE_SUCCESS) | 90 | success = CRM_CONTRACT_CREATE_SUCCESS) |
| 91 | public Long createContract(CrmContractSaveReqVO createReqVO, Long userId) { | 91 | public Long createContract(CrmContractSaveReqVO createReqVO, Long userId) { |
| 92 | + // 1.1 校验产品项的有效性 | ||
| 93 | + List<CrmContractProductDO> contractProducts = validateContractProducts(createReqVO.getProducts()); | ||
| 94 | + // 1.2 校验关联字段 | ||
| 92 | validateRelationDataExists(createReqVO); | 95 | validateRelationDataExists(createReqVO); |
| 93 | - // 1.1 插入合同 | ||
| 94 | - CrmContractDO contract = BeanUtils.toBean(createReqVO, CrmContractDO.class).setId(null); | 96 | + // TODO 芋艿:生成 no |
| 97 | + | ||
| 98 | + // 2.1 插入合同 | ||
| 99 | + CrmContractDO contract = BeanUtils.toBean(createReqVO, CrmContractDO.class); | ||
| 100 | + contract.setNo(System.currentTimeMillis() + ""); // TODO | ||
| 101 | + calculateTotalPrice(contract, contractProducts); | ||
| 95 | contractMapper.insert(contract); | 102 | contractMapper.insert(contract); |
| 96 | - // 1.2 插入合同关联商品 | ||
| 97 | - if (CollUtil.isNotEmpty(createReqVO.getProducts())) { // 如果有的话 | ||
| 98 | - List<CrmContractProductDO> productList = convertContractProductList(createReqVO, contract.getId()); | ||
| 99 | - contractProductMapper.insertBatch(productList); | ||
| 100 | - // 更新合同商品总金额 TODO 芋艿 | ||
| 101 | -// contractMapper.updateById(new CrmContractDO().setId(contract.getId()).setTotalProductPrice( | ||
| 102 | -// getSumValue(productList, CrmContractProductDO::getTotalPrice, Integer::sum))); | ||
| 103 | - // 如果存在合同关联了商机则更新商机商品关联 | ||
| 104 | - if (contract.getBusinessId() != null) { | ||
| 105 | - businessService.updateBusinessProduct(new CrmBusinessUpdateProductReqBO().setId(contract.getBusinessId()) | ||
| 106 | - .setItems(BeanUtils.toBean(createReqVO.getProducts(), CrmBusinessUpdateProductReqBO.Item.class))); | ||
| 107 | - } | 103 | + // 2.2 插入合同关联商品 |
| 104 | + if (CollUtil.isNotEmpty(contractProducts)) { | ||
| 105 | + contractProducts.forEach(item -> item.setContractId(contract.getId())); | ||
| 106 | + contractProductMapper.insertBatch(contractProducts); | ||
| 108 | } | 107 | } |
| 109 | 108 | ||
| 110 | - // 2. 创建数据权限 | ||
| 111 | - crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(userId) | 109 | + // 3. 创建数据权限 |
| 110 | + crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(contract.getOwnerUserId()) | ||
| 112 | .setBizType(CrmBizTypeEnum.CRM_CONTRACT.getType()).setBizId(contract.getId()) | 111 | .setBizType(CrmBizTypeEnum.CRM_CONTRACT.getType()).setBizId(contract.getId()) |
| 113 | .setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); | 112 | .setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); |
| 114 | 113 | ||
| 115 | - // 3. 记录操作日志上下文 | 114 | + // 4. 记录操作日志上下文 |
| 116 | LogRecordContext.putVariable("contract", contract); | 115 | LogRecordContext.putVariable("contract", contract); |
| 117 | return contract.getId(); | 116 | return contract.getId(); |
| 118 | } | 117 | } |
| @@ -124,6 +123,7 @@ public class CrmContractServiceImpl implements CrmContractService { | @@ -124,6 +123,7 @@ public class CrmContractServiceImpl implements CrmContractService { | ||
| 124 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) | 123 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) |
| 125 | public void updateContract(CrmContractSaveReqVO updateReqVO) { | 124 | public void updateContract(CrmContractSaveReqVO updateReqVO) { |
| 126 | Assert.notNull(updateReqVO.getId(), "合同编号不能为空"); | 125 | Assert.notNull(updateReqVO.getId(), "合同编号不能为空"); |
| 126 | + updateReqVO.setOwnerUserId(null); // 不允许更新的字段 | ||
| 127 | // 1.1 校验存在 | 127 | // 1.1 校验存在 |
| 128 | CrmContractDO contract = validateContractExists(updateReqVO.getId()); | 128 | CrmContractDO contract = validateContractExists(updateReqVO.getId()); |
| 129 | // 1.2 只有草稿、审批中,可以编辑; | 129 | // 1.2 只有草稿、审批中,可以编辑; |
| @@ -131,65 +131,41 @@ public class CrmContractServiceImpl implements CrmContractService { | @@ -131,65 +131,41 @@ public class CrmContractServiceImpl implements CrmContractService { | ||
| 131 | CrmAuditStatusEnum.PROCESS.getStatus())) { | 131 | CrmAuditStatusEnum.PROCESS.getStatus())) { |
| 132 | throw exception(CONTRACT_UPDATE_FAIL_EDITING_PROHIBITED); | 132 | throw exception(CONTRACT_UPDATE_FAIL_EDITING_PROHIBITED); |
| 133 | } | 133 | } |
| 134 | + // 1.3 校验产品项的有效性 | ||
| 135 | + List<CrmContractProductDO> contractProducts = validateContractProducts(updateReqVO.getProducts()); | ||
| 136 | + // 1.4 校验关联字段 | ||
| 134 | validateRelationDataExists(updateReqVO); | 137 | validateRelationDataExists(updateReqVO); |
| 135 | 138 | ||
| 136 | // 2.1 更新合同 | 139 | // 2.1 更新合同 |
| 137 | CrmContractDO updateObj = BeanUtils.toBean(updateReqVO, CrmContractDO.class); | 140 | CrmContractDO updateObj = BeanUtils.toBean(updateReqVO, CrmContractDO.class); |
| 141 | + calculateTotalPrice(updateObj, contractProducts); | ||
| 138 | contractMapper.updateById(updateObj); | 142 | contractMapper.updateById(updateObj); |
| 139 | // 2.2 更新合同关联商品 | 143 | // 2.2 更新合同关联商品 |
| 140 | - updateContractProduct(updateReqVO, updateObj.getId()); | 144 | + updateContractProduct(updateReqVO.getId(), contractProducts); |
| 141 | 145 | ||
| 142 | // 3. 记录操作日志上下文 | 146 | // 3. 记录操作日志上下文 |
| 143 | LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(contract, CrmContractSaveReqVO.class)); | 147 | LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(contract, CrmContractSaveReqVO.class)); |
| 144 | LogRecordContext.putVariable("contractName", contract.getName()); | 148 | LogRecordContext.putVariable("contractName", contract.getName()); |
| 145 | } | 149 | } |
| 146 | 150 | ||
| 147 | - private void updateContractProduct(CrmContractSaveReqVO updateReqVO, Long contractId) { | ||
| 148 | - if (CollUtil.isEmpty(updateReqVO.getProducts())) { | ||
| 149 | - return; | ||
| 150 | - } | ||
| 151 | - List<CrmContractProductDO> newProductList = convertContractProductList(updateReqVO, contractId); | ||
| 152 | - List<CrmContractProductDO> oldProductList = contractProductMapper.selectListByContractId(contractId); | ||
| 153 | - List<List<CrmContractProductDO>> diffList = diffList(oldProductList, newProductList, (oldObj, newObj) -> { | ||
| 154 | - boolean match = ObjUtil.equal(oldObj.getProductId(), newObj.getProductId()); | ||
| 155 | - if (match) { | ||
| 156 | - newObj.setId(oldObj.getId()); // 设置一下老的编号更新时需要使用 | ||
| 157 | - } | ||
| 158 | - return match; | ||
| 159 | - }); | 151 | + private void updateContractProduct(Long id, List<CrmContractProductDO> newList) { |
| 152 | + List<CrmContractProductDO> oldList = contractProductMapper.selectListByContractId(id); | ||
| 153 | + List<List<CrmContractProductDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 | ||
| 154 | + (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | ||
| 160 | if (CollUtil.isNotEmpty(diffList.get(0))) { | 155 | if (CollUtil.isNotEmpty(diffList.get(0))) { |
| 156 | + diffList.get(0).forEach(o -> o.setContractId(id)); | ||
| 161 | contractProductMapper.insertBatch(diffList.get(0)); | 157 | contractProductMapper.insertBatch(diffList.get(0)); |
| 162 | } | 158 | } |
| 163 | if (CollUtil.isNotEmpty(diffList.get(1))) { | 159 | if (CollUtil.isNotEmpty(diffList.get(1))) { |
| 164 | contractProductMapper.updateBatch(diffList.get(1)); | 160 | contractProductMapper.updateBatch(diffList.get(1)); |
| 165 | } | 161 | } |
| 166 | if (CollUtil.isNotEmpty(diffList.get(2))) { | 162 | if (CollUtil.isNotEmpty(diffList.get(2))) { |
| 167 | - contractProductMapper.deleteBatchIds(convertList(diffList.get(2), CrmContractProductDO::getId)); | 163 | + contractProductMapper.deleteBatchIds(convertSet(diffList.get(2), CrmContractProductDO::getId)); |
| 168 | } | 164 | } |
| 169 | } | 165 | } |
| 170 | 166 | ||
| 171 | // TODO @合同待定:缺一个取消合同的接口;只有草稿、审批中可以取消;CrmAuditStatusEnum | 167 | // TODO @合同待定:缺一个取消合同的接口;只有草稿、审批中可以取消;CrmAuditStatusEnum |
| 172 | 168 | ||
| 173 | - private List<CrmContractProductDO> convertContractProductList(CrmContractSaveReqVO reqVO, Long contractId) { | ||
| 174 | - // 校验商品存在 | ||
| 175 | - Set<Long> productIds = convertSet(reqVO.getProducts(), CrmContractSaveReqVO.Product::getProductId); | ||
| 176 | - List<CrmProductDO> productList = productService.getProductList(productIds); | ||
| 177 | - if (CollUtil.isEmpty(productIds) || productList.size() != productIds.size()) { | ||
| 178 | - throw exception(PRODUCT_NOT_EXISTS); | ||
| 179 | - } | ||
| 180 | - Map<Long, CrmProductDO> productMap = convertMap(productList, CrmProductDO::getId); | ||
| 181 | - // TODO 芋艿 | ||
| 182 | - return null; | ||
| 183 | -// return convertList(reqVO.getProducts(), productItem -> { | ||
| 184 | -// CrmProductDO product = productMap.get(productItem.getId()); | ||
| 185 | -// return BeanUtils.toBean(product, CrmContractProductDO.class) | ||
| 186 | -// .setId(null).setProductId(productItem.getId()).setContractId(contractId) | ||
| 187 | -// .setCount(productItem.getCount()).setDiscountPercent(productItem.getDiscountPercent()) | ||
| 188 | -// // TODO 芋艿:这里临时注释掉 | ||
| 189 | -// .setTotalPrice(MoneyUtils.calculator(null, productItem.getCount(), productItem.getDiscountPercent())); | ||
| 190 | -// }); | ||
| 191 | - } | ||
| 192 | - | ||
| 193 | /** | 169 | /** |
| 194 | * 校验关联数据是否存在 | 170 | * 校验关联数据是否存在 |
| 195 | * | 171 | * |
| @@ -197,17 +173,38 @@ public class CrmContractServiceImpl implements CrmContractService { | @@ -197,17 +173,38 @@ public class CrmContractServiceImpl implements CrmContractService { | ||
| 197 | */ | 173 | */ |
| 198 | private void validateRelationDataExists(CrmContractSaveReqVO reqVO) { | 174 | private void validateRelationDataExists(CrmContractSaveReqVO reqVO) { |
| 199 | // 1. 校验客户 | 175 | // 1. 校验客户 |
| 200 | - if (reqVO.getCustomerId() != null && customerService.getCustomer(reqVO.getCustomerId()) == null) { | ||
| 201 | - throw exception(CUSTOMER_NOT_EXISTS); | 176 | + if (reqVO.getCustomerId() != null) { |
| 177 | + customerService.validateCustomer(reqVO.getCustomerId()); | ||
| 202 | } | 178 | } |
| 203 | // 2. 校验负责人 | 179 | // 2. 校验负责人 |
| 204 | - if (reqVO.getOwnerUserId() != null && adminUserApi.getUser(reqVO.getOwnerUserId()) == null) { | ||
| 205 | - throw exception(USER_NOT_EXISTS); | 180 | + if (reqVO.getOwnerUserId() != null) { |
| 181 | + adminUserApi.validateUser(reqVO.getOwnerUserId()); | ||
| 206 | } | 182 | } |
| 207 | // 3. 如果有关联商机,则需要校验存在 | 183 | // 3. 如果有关联商机,则需要校验存在 |
| 208 | - if (reqVO.getBusinessId() != null && businessService.getBusiness(reqVO.getBusinessId()) == null) { | ||
| 209 | - throw exception(BUSINESS_NOT_EXISTS); | 184 | + if (reqVO.getBusinessId() != null) { |
| 185 | + businessService.validateBusiness(reqVO.getBusinessId()); | ||
| 186 | + } | ||
| 187 | + // 4. 校验签约相关字段 | ||
| 188 | + if (reqVO.getSignContactId() != null) { | ||
| 189 | + contactService.validateContact(reqVO.getSignContactId()); | ||
| 210 | } | 190 | } |
| 191 | + if (reqVO.getSignUserId() != null) { | ||
| 192 | + adminUserApi.validateUser(reqVO.getSignUserId()); | ||
| 193 | + } | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + private List<CrmContractProductDO> validateContractProducts(List<CrmContractSaveReqVO.Product> list) { | ||
| 197 | + // 1. 校验产品存在 | ||
| 198 | + productService.validProductList(convertSet(list, CrmContractSaveReqVO.Product::getProductId)); | ||
| 199 | + // 2. 转化为 CrmContractProductDO 列表 | ||
| 200 | + return convertList(list, o -> BeanUtils.toBean(o, CrmContractProductDO.class, | ||
| 201 | + item -> item.setTotalPrice(MoneyUtils.priceMultiply(item.getContractPrice(), item.getCount())))); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + private void calculateTotalPrice(CrmContractDO contract, List<CrmContractProductDO> contractProducts) { | ||
| 205 | + contract.setTotalProductPrice(getSumValue(contractProducts, CrmContractProductDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)); | ||
| 206 | + BigDecimal discountPrice = MoneyUtils.priceMultiplyPercent(contract.getTotalProductPrice(), contract.getDiscountPercent()); | ||
| 207 | + contract.setTotalPrice(contract.getTotalProductPrice().subtract(discountPrice)); | ||
| 211 | } | 208 | } |
| 212 | 209 | ||
| 213 | @Override | 210 | @Override |