📖 CRM:code review 合同逻辑

This commit is contained in:
YunaiV 2024-02-17 19:14:48 +08:00
parent c6041da3c4
commit 0fba56cda8
11 changed files with 33 additions and 21 deletions

View File

@ -77,6 +77,7 @@ public class CrmBusinessSaveReqVO {
@Schema(description = "联系人编号", example = "110")
private Long contactId; // 使用场景联系人详情添加商机时如果需要关联两者需要传递 contactId 字段
// TODO @puhui999传递 items 就行啦
@Schema(description = "产品列表")
private List<CrmBusinessProductItem> productItems;
@ -86,7 +87,7 @@ public class CrmBusinessSaveReqVO {
@AllArgsConstructor
public static class CrmBusinessProductItem {
@Schema(description = "产品编号", example = "20529")
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529")
@NotNull(message = "产品编号不能为空")
private Long id;

View File

@ -46,6 +46,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static java.util.Collections.singletonList;
@Tag(name = "管理后台 - CRM 合同")
@RestController
@ -102,7 +103,7 @@ public class CrmContractController {
}
// 2. 拼接合同信息
List<CrmContractRespVO> respVOList = buildContractDetailList(Collections.singletonList(contract));
List<CrmContractRespVO> respVOList = buildContractDetailList(singletonList(contract));
return success(respVOList.get(0));
}

View File

@ -132,6 +132,7 @@ public class CrmContractRespVO {
@Schema(description = "产品列表")
private List<CrmContractProductItemRespVO> productItems;
// TODO @puhui999可以直接叫 Item
@Schema(description = "产品列表")
@Data
@NoArgsConstructor

View File

@ -61,9 +61,8 @@ public interface CrmContractConvert {
List<CrmProductDO> productList) {
respVO.setProductItems(CollectionUtils.convertList(productList, product -> {
CrmContractRespVO.CrmContractProductItemRespVO productItemRespVO = BeanUtils.toBean(product, CrmContractRespVO.CrmContractProductItemRespVO.class);
findAndThen(contractProductMap, product.getId(), contractProduct -> {
productItemRespVO.setCount(contractProduct.getCount()).setDiscountPercent(contractProduct.getDiscountPercent());
});
findAndThen(contractProductMap, product.getId(), contractProduct ->
productItemRespVO.setCount(contractProduct.getCount()).setDiscountPercent(contractProduct.getDiscountPercent()));
return productItemRespVO;
}));
}

View File

@ -57,6 +57,8 @@ public class CrmContractProductDO extends BaseDO {
private Integer discountPercent;
/**
* 总计价格折扣后价格
*
* TODO @puhui999可以写下计算公式哈
*/
private Integer totalPrice;

View File

@ -16,15 +16,17 @@ import java.util.List;
@Mapper
public interface CrmBusinessProductMapper extends BaseMapperX<CrmBusinessProductDO> {
default void deleteByBusinessId(Long id) { // TODO @lzxhqs第一个方法和类之间最好空一行
delete(CrmBusinessProductDO::getBusinessId, id);
// TODO @puhui999用不到的方法看看是不是删除哈
default void deleteByBusinessId(Long getBusinessId) { // TODO @lzxhqs第一个方法和类之间最好空一行
delete(CrmBusinessProductDO::getBusinessId, getBusinessId);
}
default CrmBusinessProductDO selectByBusinessId(Long id) {
return selectOne(CrmBusinessProductDO::getBusinessId, id);
default CrmBusinessProductDO selectByBusinessId(Long getBusinessId) {
return selectOne(CrmBusinessProductDO::getBusinessId, getBusinessId);
}
default List<CrmBusinessProductDO> selectListByBusinessId(Long businessId) {
// TODO @puhui999可以简化selectList(CrmBusinessProductDO::getBusinessId, businessId)
return selectList(new LambdaQueryWrapperX<CrmBusinessProductDO>().eq(CrmBusinessProductDO::getBusinessId, businessId));
}

View File

@ -16,6 +16,7 @@ import java.util.List;
@Mapper
public interface CrmContractProductMapper extends BaseMapperX<CrmContractProductDO> {
// TODO @puhui999用不到的方法看看是不是删除哈
default void deleteByContractId(Long contractId) { // TODO @lzxhqs第一个方法和类之间最好空一行
delete(CrmContractProductDO::getContractId, contractId);
}

View File

@ -81,13 +81,13 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
businessMapper.insert(business);
// 1.2 插入商机关联商品
if (CollUtil.isNotEmpty(createReqVO.getProductItems())) { // 如果有的话
List<CrmBusinessProductDO> productList = convertBusinessProductList(createReqVO.getProductItems(), business.getId());
List<CrmBusinessProductDO> productList = buildBusinessProductList(createReqVO.getProductItems(), business.getId());
businessProductMapper.insertBatch(productList);
// 更新合同商品总金额
businessMapper.updateById(new CrmBusinessDO().setId(business.getId()).setProductPrice(
getSumValue(productList, CrmBusinessProductDO::getTotalPrice, Integer::sum)));
}
// TODO 商机待定在联系人的详情页如果直接新建商机则需要关联下这里要搞个 CrmContactBusinessDO
// TODO @puhui999在联系人的详情页如果直接新建商机则需要关联下这里要搞个 CrmContactBusinessDO
createContactBusiness(business.getId(), createReqVO.getContactId());
// 2. 创建数据权限
@ -95,7 +95,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType())
.setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
// 4. 记录操作日志上下文
// 3. 记录操作日志上下文
LogRecordContext.putVariable("business", business);
return business.getId();
}
@ -121,7 +121,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class);
businessMapper.updateById(updateObj);
// 2.2 更新商机关联商品
List<CrmBusinessProductDO> productList = convertBusinessProductList(updateReqVO.getProductItems(), updateObj.getId());
List<CrmBusinessProductDO> productList = buildBusinessProductList(updateReqVO.getProductItems(), updateObj.getId());
updateBusinessProduct(productList, updateObj.getId());
// TODO @商机待定如果状态发生变化插入商机状态变更记录表
@ -175,7 +175,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
}
}
private List<CrmBusinessProductDO> convertBusinessProductList(List<CrmBusinessSaveReqVO.CrmBusinessProductItem> productItems, Long businessId) {
private List<CrmBusinessProductDO> buildBusinessProductList(List<CrmBusinessSaveReqVO.CrmBusinessProductItem> productItems,
Long businessId) {
// 校验商品存在
Set<Long> productIds = convertSet(productItems, CrmBusinessSaveReqVO.CrmBusinessProductItem::getId);
List<CrmProductDO> productList = productService.getProductList(productIds);
@ -235,7 +236,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
@Override
public void updateBusinessProduct(CrmBusinessUpdateProductReqBO updateProductReqBO) {
// 更新商机关联商品
List<CrmBusinessProductDO> productList = convertBusinessProductList(
List<CrmBusinessProductDO> productList = buildBusinessProductList(
BeanUtils.toBean(updateProductReqBO.getProductItems(), CrmBusinessSaveReqVO.CrmBusinessProductItem.class), updateProductReqBO.getId());
updateBusinessProduct(productList, updateProductReqBO.getId());
}

View File

@ -23,6 +23,7 @@ public class CrmBusinessUpdateProductReqBO {
@NotNull(message = "商机编号不能为空")
private Long id;
// TODO @芋艿再想想
@NotEmpty(message = "产品列表不能为空")
private List<CrmBusinessProductItem> productItems;

View File

@ -61,7 +61,10 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_E
@Validated
public class CrmContractServiceImpl implements CrmContractService {
public static final String CONTRACT_APPROVE = "contract-approve"; // 合同审批流程标识
/**
* BPM 合同审批流程标识
*/
public static final String CONTRACT_APPROVE = "contract-approve";
@Resource
private CrmContractMapper contractMapper;
@ -149,11 +152,11 @@ public class CrmContractServiceImpl implements CrmContractService {
List<CrmContractProductDO> newProductList = convertContractProductList(updateReqVO, contractId);
List<CrmContractProductDO> oldProductList = contractProductMapper.selectListByContractId(contractId);
List<List<CrmContractProductDO>> diffList = diffList(oldProductList, newProductList, (oldObj, newObj) -> {
boolean equal = ObjUtil.equal(oldObj.getProductId(), newObj.getProductId());
if (equal) {
boolean match = ObjUtil.equal(oldObj.getProductId(), newObj.getProductId());
if (match) {
newObj.setId(oldObj.getId()); // 设置一下老的编号更新时需要使用
}
return equal;
return match;
});
if (CollUtil.isNotEmpty(diffList.get(0))) {
contractProductMapper.insertBatch(diffList.get(0));

View File

@ -266,10 +266,10 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
CrmCustomerDO customer = initCustomer(importCustomer, importReqVO.getOwnerUserId());
customerMapper.insert(customer);
respVO.getCreateCustomerNames().add(importCustomer.getName());
if (importReqVO.getOwnerUserId() != null) {
// 1.2 创建数据权限
if (importReqVO.getOwnerUserId() != null) {
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
.setBizId(customer.getId()).setUserId(importReqVO.getOwnerUserId()).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
.setBizId(customer.getId()).setUserId(importReqVO.getOwnerUserId()).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
}
// 1.3 记录操作日志
getSelf().importCustomerLog(customer, false);