Commit 77f98c4d129307a1128af4ba6e88d8bfb52d8737
1 parent
f76a7cd9
✨ CRM:完善商机的新增、修改逻辑
Showing
7 changed files
with
84 additions
and
11 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessStatusController.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.controller.admin.business; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| ... | ... | @@ -29,6 +30,7 @@ import java.util.Map; |
| 29 | 30 | |
| 30 | 31 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 31 | 32 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 33 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 32 | 34 | |
| 33 | 35 | @Tag(name = "管理后台 - CRM 商机状态") |
| 34 | 36 | @RestController |
| ... | ... | @@ -62,7 +64,7 @@ public class CrmBusinessStatusController { |
| 62 | 64 | @DeleteMapping("/delete") |
| 63 | 65 | @Operation(summary = "删除商机状态") |
| 64 | 66 | @Parameter(name = "id", description = "编号", required = true) |
| 65 | - @PreAuthorize("@ss.hasPermission('crm:business-status-type:delete')") | |
| 67 | + @PreAuthorize("@ss.hasPermission('crm:business-status:delete')") | |
| 66 | 68 | public CommonResult<Boolean> deleteBusinessStatusType(@RequestParam("id") Long id) { |
| 67 | 69 | businessStatusTypeService.deleteBusinessStatusType(id); |
| 68 | 70 | return success(true); |
| ... | ... | @@ -71,7 +73,7 @@ public class CrmBusinessStatusController { |
| 71 | 73 | @GetMapping("/get") |
| 72 | 74 | @Operation(summary = "获得商机状态") |
| 73 | 75 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 74 | - @PreAuthorize("@ss.hasPermission('crm:business-status-type:query')") | |
| 76 | + @PreAuthorize("@ss.hasPermission('crm:business-status:query')") | |
| 75 | 77 | public CommonResult<CrmBusinessStatusRespVO> getBusinessStatusType(@RequestParam("id") Long id) { |
| 76 | 78 | CrmBusinessStatusTypeDO statusType = businessStatusTypeService.getBusinessStatusType(id); |
| 77 | 79 | if (statusType == null) { |
| ... | ... | @@ -84,10 +86,13 @@ public class CrmBusinessStatusController { |
| 84 | 86 | |
| 85 | 87 | @GetMapping("/page") |
| 86 | 88 | @Operation(summary = "获得商机状态分页") |
| 87 | - @PreAuthorize("@ss.hasPermission('crm:business-status-type:query')") | |
| 88 | - public CommonResult<PageResult<CrmBusinessStatusRespVO>> getBusinessStatusTypePage(@Valid PageParam pageReqVO) { | |
| 89 | + @PreAuthorize("@ss.hasPermission('crm:business-status:query')") | |
| 90 | + public CommonResult<PageResult<CrmBusinessStatusRespVO>> getBusinessStatusPage(@Valid PageParam pageReqVO) { | |
| 89 | 91 | // 1. 查询数据 |
| 90 | 92 | PageResult<CrmBusinessStatusTypeDO> pageResult = businessStatusTypeService.getBusinessStatusTypePage(pageReqVO); |
| 93 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 94 | + return success(PageResult.empty(pageResult.getTotal())); | |
| 95 | + } | |
| 91 | 96 | // 2. 拼接数据 |
| 92 | 97 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( |
| 93 | 98 | convertSet(pageResult.getList(), statusType -> Long.parseLong(statusType.getCreator()))); |
| ... | ... | @@ -101,9 +106,12 @@ public class CrmBusinessStatusController { |
| 101 | 106 | } |
| 102 | 107 | |
| 103 | 108 | @GetMapping("/type-simple-list") |
| 104 | - @Operation(summary = "获得商机状态列表") | |
| 109 | + @Operation(summary = "获得商机状态组列表") | |
| 105 | 110 | public CommonResult<List<CrmBusinessStatusRespVO>> getBusinessStatusTypeSimpleList() { |
| 106 | 111 | List<CrmBusinessStatusTypeDO> list = businessStatusTypeService.getBusinessStatusTypeList(); |
| 112 | + // 过滤掉部门不匹配的 | |
| 113 | + Long deptId = adminUserApi.getUser(getLoginUserId()).getDeptId(); | |
| 114 | + list.removeIf(statusType -> CollUtil.isNotEmpty(statusType.getDeptIds()) && !statusType.getDeptIds().contains(deptId)); | |
| 107 | 115 | return success(BeanUtils.toBean(list, CrmBusinessStatusRespVO.class)); |
| 108 | 116 | } |
| 109 | 117 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/status/CrmBusinessStatusSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.controller.admin.business.vo.status; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | +import jakarta.validation.Valid; | |
| 4 | 5 | import jakarta.validation.constraints.NotEmpty; |
| 5 | 6 | import jakarta.validation.constraints.NotNull; |
| 6 | 7 | import lombok.Data; |
| ... | ... | @@ -24,6 +25,7 @@ public class CrmBusinessStatusSaveReqVO { |
| 24 | 25 | |
| 25 | 26 | @Schema(description = "商机状态集合", requiredMode = Schema.RequiredMode.REQUIRED) |
| 26 | 27 | @NotEmpty(message = "商机状态集合不能为空") |
| 28 | + @Valid | |
| 27 | 29 | private List<Status> statuses; |
| 28 | 30 | |
| 29 | 31 | @Data | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
| ... | ... | @@ -19,11 +19,14 @@ import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; |
| 19 | 19 | import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; |
| 20 | 20 | import cn.iocoder.yudao.module.crm.service.business.bo.CrmBusinessUpdateProductReqBO; |
| 21 | 21 | import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService; |
| 22 | +import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; | |
| 22 | 23 | import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; |
| 24 | +import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | |
| 23 | 25 | import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO; |
| 24 | 26 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 25 | 27 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; |
| 26 | 28 | import cn.iocoder.yudao.module.crm.service.product.CrmProductService; |
| 29 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 27 | 30 | import com.mzt.logapi.context.LogRecordContext; |
| 28 | 31 | import com.mzt.logapi.service.impl.DiffParseFunction; |
| 29 | 32 | import com.mzt.logapi.starter.annotation.LogRecord; |
| ... | ... | @@ -58,15 +61,25 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { |
| 58 | 61 | private CrmBusinessProductMapper businessProductMapper; |
| 59 | 62 | |
| 60 | 63 | @Resource |
| 64 | + private CrmBusinessStatusService businessStatusService; | |
| 65 | + @Resource | |
| 61 | 66 | @Lazy // 延迟加载,避免循环依赖 |
| 62 | 67 | private CrmContractService contractService; |
| 63 | 68 | @Resource |
| 69 | + private CrmCustomerService customerService; | |
| 70 | + @Resource | |
| 71 | + @Lazy // 延迟加载,避免循环依赖 | |
| 72 | + private CrmContactService contactService; | |
| 73 | + @Resource | |
| 64 | 74 | private CrmPermissionService permissionService; |
| 65 | 75 | @Resource |
| 66 | 76 | private CrmContactBusinessService contactBusinessService; |
| 67 | 77 | @Resource |
| 68 | 78 | private CrmProductService productService; |
| 69 | 79 | |
| 80 | + @Resource | |
| 81 | + private AdminUserApi adminUserApi; | |
| 82 | + | |
| 70 | 83 | @Override |
| 71 | 84 | @Transactional(rollbackFor = Exception.class) |
| 72 | 85 | @LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_CREATE_SUB_TYPE, bizNo = "{{#business.id}}", |
| ... | ... | @@ -74,10 +87,12 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { |
| 74 | 87 | public Long createBusiness(CrmBusinessSaveReqVO createReqVO, Long userId) { |
| 75 | 88 | // 1.1 校验产品项的有效性 |
| 76 | 89 | List<CrmBusinessProductDO> businessProducts = validateBusinessProducts(createReqVO.getProducts()); |
| 77 | - // 1.2 TODO 芋艿:校验关联字 | |
| 90 | + // 1.2 校验关联字段 | |
| 91 | + validateBusinessForCreate(createReqVO); | |
| 78 | 92 | |
| 79 | 93 | // 2.1 插入商机 |
| 80 | 94 | CrmBusinessDO business = BeanUtils.toBean(createReqVO, CrmBusinessDO.class).setOwnerUserId(userId); |
| 95 | + business.setStatusId(businessStatusService.getBusinessStatusListByTypeId(createReqVO.getStatusTypeId()).get(0).getId()); // 默认状态 | |
| 81 | 96 | calculateTotalPrice(business, businessProducts); |
| 82 | 97 | businessMapper.insert(business); |
| 83 | 98 | // 2.2 插入商机关联商品 |
| ... | ... | @@ -101,6 +116,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { |
| 101 | 116 | |
| 102 | 117 | // TODO @lzxhqs:CrmContactBusinessService 调用这个;这样逻辑才能收敛哈; |
| 103 | 118 | private void createContactBusiness(Long businessId, Long contactId) { |
| 119 | + if (contactId == null) { | |
| 120 | + return; | |
| 121 | + } | |
| 104 | 122 | CrmContactBusinessDO contactBusiness = new CrmContactBusinessDO(); |
| 105 | 123 | contactBusiness.setBusinessId(businessId); |
| 106 | 124 | contactBusiness.setContactId(contactId); |
| ... | ... | @@ -113,11 +131,13 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { |
| 113 | 131 | success = CRM_BUSINESS_UPDATE_SUCCESS) |
| 114 | 132 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) |
| 115 | 133 | public void updateBusiness(CrmBusinessSaveReqVO updateReqVO) { |
| 134 | + updateReqVO.setOwnerUserId(null).setStatusTypeId(null); // 不允许更新的字段 | |
| 116 | 135 | // 1.1 校验存在 |
| 117 | 136 | CrmBusinessDO oldBusiness = validateBusinessExists(updateReqVO.getId()); |
| 118 | 137 | // 1.2 校验产品项的有效性 |
| 119 | 138 | List<CrmBusinessProductDO> businessProducts = validateBusinessProducts(updateReqVO.getProducts()); |
| 120 | - // 1.3 TODO 芋艿:校验关联字 | |
| 139 | + // 1.3 校验关联字段 | |
| 140 | + validateBusinessForCreate(updateReqVO); | |
| 121 | 141 | |
| 122 | 142 | // 2.1 更新商机 |
| 123 | 143 | CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class); |
| ... | ... | @@ -148,6 +168,25 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { |
| 148 | 168 | } |
| 149 | 169 | } |
| 150 | 170 | |
| 171 | + private void validateBusinessForCreate(CrmBusinessSaveReqVO saveReqVO) { | |
| 172 | + // 校验商机状态 | |
| 173 | + if (saveReqVO.getStatusTypeId() != null) { | |
| 174 | + businessStatusService.validateBusinessStatusType(saveReqVO.getStatusTypeId()); | |
| 175 | + } | |
| 176 | + // 校验客户 | |
| 177 | + if (saveReqVO.getCustomerId() != null) { | |
| 178 | + customerService.validateCustomer(saveReqVO.getCustomerId()); | |
| 179 | + } | |
| 180 | + // 校验联系人 | |
| 181 | + if (saveReqVO.getContactId() != null) { | |
| 182 | + contactService.validateContact(saveReqVO.getContactId()); | |
| 183 | + } | |
| 184 | + // 校验负责人 | |
| 185 | + if (saveReqVO.getOwnerUserId() != null) { | |
| 186 | + adminUserApi.validateUser(saveReqVO.getOwnerUserId()); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + | |
| 151 | 190 | private List<CrmBusinessProductDO> validateBusinessProducts(List<CrmBusinessSaveReqVO.Product> list) { |
| 152 | 191 | // 1. 校验产品存在 |
| 153 | 192 | productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.Product::getProductId)); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessStatusService.java
| ... | ... | @@ -51,6 +51,13 @@ public interface CrmBusinessStatusService { |
| 51 | 51 | CrmBusinessStatusTypeDO getBusinessStatusType(Long id); |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | + * 校验商机状态组 | |
| 55 | + * | |
| 56 | + * @param id 编号 | |
| 57 | + */ | |
| 58 | + void validateBusinessStatusType(Long id); | |
| 59 | + | |
| 60 | + /** | |
| 54 | 61 | * 获得商机状态组列表 |
| 55 | 62 | * |
| 56 | 63 | * @return 商机状态组列表 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessStatusServiceImpl.java
| ... | ... | @@ -68,7 +68,7 @@ public class CrmBusinessStatusServiceImpl implements CrmBusinessStatusService { |
| 68 | 68 | @Transactional(rollbackFor = Exception.class) |
| 69 | 69 | public void updateBusinessStatus(CrmBusinessStatusSaveReqVO updateReqVO) { |
| 70 | 70 | // 1.1 校验存在 |
| 71 | - validateBusinessStatusTypeNameUnique(updateReqVO.getId()); | |
| 71 | + validateBusinessStatusTypeExists(updateReqVO.getId()); | |
| 72 | 72 | // 1.2 校验名称是否存在 |
| 73 | 73 | validateBusinessStatusTypeNameUnique(updateReqVO.getName(), updateReqVO.getId()); |
| 74 | 74 | // 1.3 设置状态的排序 |
| ... | ... | @@ -104,7 +104,7 @@ public class CrmBusinessStatusServiceImpl implements CrmBusinessStatusService { |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - private void validateBusinessStatusTypeNameUnique(Long id) { | |
| 107 | + private void validateBusinessStatusTypeExists(Long id) { | |
| 108 | 108 | if (businessStatusTypeMapper.selectById(id) == null) { |
| 109 | 109 | throw exception(BUSINESS_STATUS_TYPE_NOT_EXISTS); |
| 110 | 110 | } |
| ... | ... | @@ -123,7 +123,7 @@ public class CrmBusinessStatusServiceImpl implements CrmBusinessStatusService { |
| 123 | 123 | @Transactional(rollbackFor = Exception.class) |
| 124 | 124 | public void deleteBusinessStatusType(Long id) { |
| 125 | 125 | // 1.1 校验存在 |
| 126 | - validateBusinessStatusTypeNameUnique(id); | |
| 126 | + validateBusinessStatusTypeExists(id); | |
| 127 | 127 | // 1.2 已经使用,无法更新 |
| 128 | 128 | if (businessService.getBusinessCountByStatusTypeId(id) > 0) { |
| 129 | 129 | throw exception(BUSINESS_STATUS_DELETE_FAIL_USED); |
| ... | ... | @@ -141,13 +141,18 @@ public class CrmBusinessStatusServiceImpl implements CrmBusinessStatusService { |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | @Override |
| 144 | + public void validateBusinessStatusType(Long id) { | |
| 145 | + validateBusinessStatusTypeExists(id); | |
| 146 | + } | |
| 147 | + | |
| 148 | + @Override | |
| 144 | 149 | public List<CrmBusinessStatusTypeDO> getBusinessStatusTypeList() { |
| 145 | 150 | return businessStatusTypeMapper.selectList(); |
| 146 | 151 | } |
| 147 | 152 | |
| 148 | 153 | @Override |
| 149 | 154 | public PageResult<CrmBusinessStatusTypeDO> getBusinessStatusTypePage(PageParam pageReqVO) { |
| 150 | - return null; | |
| 155 | + return businessStatusTypeMapper.selectPage(pageReqVO); | |
| 151 | 156 | } |
| 152 | 157 | |
| 153 | 158 | @Override | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java
| ... | ... | @@ -230,6 +230,11 @@ public class CrmContactServiceImpl implements CrmContactService { |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | @Override |
| 233 | + public void validateContact(Long id) { | |
| 234 | + validateContactExists(id); | |
| 235 | + } | |
| 236 | + | |
| 237 | + @Override | |
| 233 | 238 | public List<CrmContactDO> getContactListByIds(Collection<Long> ids, Long userId) { |
| 234 | 239 | if (CollUtil.isEmpty(ids)) { |
| 235 | 240 | return ListUtil.empty(); | ... | ... |