From 36a76c5ce63e8988e3c086cdb90d1a3080b0e254 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sun, 29 Oct 2023 01:42:22 +0800 Subject: [PATCH] =?UTF-8?q?CRM-=E8=81=94=E7=B3=BB=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=81=94=E7=B3=BB=E4=BA=BA=E8=BD=AC=E7=A7=BB?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/crm/enums/ErrorCodeConstants.java | 3 ++ .../admin/contact/ContactController.java | 48 +++++++++++-------- .../admin/contact/vo/ContactCreateReqVO.java | 14 ++++-- .../admin/contact/vo/ContactUpdateReqVO.java | 14 ++++-- .../contact/vo/CrmContactTransferReqVO.java | 20 ++++++++ .../crm/convert/contact/ContactConvert.java | 19 ++++++-- .../crm/dal/dataobject/contact/ContactDO.java | 14 ++++++ .../crm/service/contact/ContactService.java | 16 +++++-- .../service/contact/ContactServiceImpl.java | 41 +++++++++++++--- .../service/contract/ContractServiceImpl.java | 17 +++++-- 10 files changed, 160 insertions(+), 46 deletions(-) create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java index dcb03a74d..f5b5e078b 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java @@ -12,6 +12,7 @@ public interface ErrorCodeConstants { // ========== 合同管理 1-020-000-000 ========== ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在"); ErrorCode CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_000_001, "合同转移失败,原因:没有转移权限"); + ErrorCode CONTRACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_000_002, "合同转移失败,原因:负责人不存在"); // ========== 线索管理 1-020-001-000 ========== ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); @@ -26,6 +27,8 @@ public interface ErrorCodeConstants { // ========== 联系人管理 1-020-003-000 ========== ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在"); + ErrorCode CONTACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_003_001, "联系人转移失败,原因:没有转移权限"); + ErrorCode CONTACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_003_002, "联系人转移失败,原因:负责人不存在"); // TODO @liuhongfeng:错误码分段; ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_030_000_001, "回款管理不存在"); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java index bafec03c1..f28d27ef8 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java @@ -1,32 +1,30 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact; -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; - -import javax.validation.constraints.*; -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; -import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; import cn.iocoder.yudao.module.crm.service.contact.ContactService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - crm联系人") @RestController @@ -99,4 +97,12 @@ public class ContactController { ExcelUtils.write(response, "crm联系人.xls", "数据", ContactExcelVO.class, datas); } + @PutMapping("/transfer") + @Operation(summary = "联系人转移") + @PreAuthorize("@ss.hasPermission('crm:contact:update')") + public CommonResult transfer(@Valid @RequestBody CrmContactTransferReqVO reqVO) { + contactService.contactTransfer(reqVO, getLoginUserId()); + return success(true); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactCreateReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactCreateReqVO.java index 424d945dc..64ea71084 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactCreateReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactCreateReqVO.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact.vo; -import lombok.*; -import java.util.*; import io.swagger.v3.oas.annotations.media.Schema; -import javax.validation.constraints.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.Set; @Schema(description = "管理后台 - crm联系人创建 Request VO") @Data @@ -11,4 +13,10 @@ import javax.validation.constraints.*; @ToString(callSuper = true) public class ContactCreateReqVO extends ContactBaseVO { + @Schema(description = "只读权限的用户编号数组") + private Set roUserIds; + + @Schema(description = "读写权限的用户编号数组") + private Set rwUserIds; + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactUpdateReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactUpdateReqVO.java index 19db67297..60afd06f2 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactUpdateReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactUpdateReqVO.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact.vo; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import javax.validation.constraints.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.Set; @Schema(description = "管理后台 - crm联系人更新 Request VO") @Data @@ -14,4 +16,10 @@ public class ContactUpdateReqVO extends ContactBaseVO { @Schema(description = "主键", example = "23210") private Long id; + @Schema(description = "只读权限的用户编号数组") + private Set roUserIds; + + @Schema(description = "读写权限的用户编号数组") + private Set rwUserIds; + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java new file mode 100644 index 000000000..517d77576 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.crm.controller.admin.contact.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 联系转移 Request VO") +@Data +public class CrmContactTransferReqVO { + + @Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") + @NotNull(message = "联系人编号不能为空") + private Long id; + + @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") + @NotNull(message = "新负责人的用户编号不能为空") + private Long ownerUserId; // 新的负责人 + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java index 3892806c0..2718b339a 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java @@ -1,13 +1,14 @@ package cn.iocoder.yudao.module.crm.convert.contact; -import java.util.*; - +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; +import java.util.Set; /** * crm联系人 Convert @@ -31,4 +32,12 @@ public interface ContactConvert { List convertList02(List list); + default ContactDO convert(ContactDO contact, CrmContactTransferReqVO reqVO, Long userId) { + Set rwUserIds = contact.getRwUserIds(); + rwUserIds.removeIf(item -> ObjUtil.equal(item, userId.toString())); // 移除老负责人 + rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人 + return new ContactDO().setId(contact.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人 + .setRwUserIds(rwUserIds); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/ContactDO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/ContactDO.java index 2e7d2cfef..6c56ebe98 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/ContactDO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/ContactDO.java @@ -1,12 +1,15 @@ package cn.iocoder.yudao.module.crm.dal.dataobject.contact; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler; import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; import java.time.LocalDateTime; +import java.util.Set; /** * crm 联系人 DO @@ -77,4 +80,15 @@ public class ContactDO extends BaseDO { */ private LocalDateTime lastTime; + /** + * 只读权限的用户编号数组 + */ + @TableField(typeHandler = JsonLongSetTypeHandler.class) + private Set roUserIds; + /** + * 读写权限的用户编号数组 + */ + @TableField(typeHandler = JsonLongSetTypeHandler.class) + private Set rwUserIds; + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java index 97a221ee4..63b3449f2 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.crm.service.contact; -import java.util.*; -import javax.validation.*; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; /** * crm联系人 Service 接口 @@ -67,4 +69,12 @@ public interface ContactService { */ List getContactList(ContactExportReqVO exportReqVO); + /** + * 联系人编号 + * + * @param reqVO 请求 + * @param userId 用户编号 + */ + void contactTransfer(CrmContactTransferReqVO reqVO, Long userId); + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java index b21fee020..eb2b97cbe 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java @@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.service.contact; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactExportReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactUpdateReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; import cn.iocoder.yudao.module.crm.dal.mysql.contact.ContactMapper; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -18,7 +17,8 @@ import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS; +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.crm.framework.utils.AuthUtil.isReadAndWrite; /** * crm联系人 Service 实现类 @@ -32,6 +32,9 @@ public class ContactServiceImpl implements ContactService { @Resource private ContactMapper contactMapper; + @Resource + private AdminUserApi adminUserApi; + @Override public Long createContact(ContactCreateReqVO createReqVO) { // TODO @customerId:需要校验存在 @@ -61,10 +64,12 @@ public class ContactServiceImpl implements ContactService { contactMapper.deleteById(id); } - private void validateContactExists(Long id) { - if (contactMapper.selectById(id) == null) { + private ContactDO validateContactExists(Long id) { + ContactDO contact = contactMapper.selectById(id); + if (contact == null) { throw exception(CONTACT_NOT_EXISTS); } + return contact; } @Override @@ -90,4 +95,26 @@ public class ContactServiceImpl implements ContactService { return contactMapper.selectList(exportReqVO); } + @Override + public void contactTransfer(CrmContactTransferReqVO reqVO, Long userId) { + // 1. 校验联系人是否存在 + ContactDO contact = validateContactExists(reqVO.getId()); + // 1.2. 校验用户是否拥有读写权限 + if (!isReadAndWrite(contact.getRwUserIds(), userId)) { + throw exception(CONTACT_TRANSFER_FAIL_PERMISSION_DENIED); + } + // 2. 校验新负责人是否存在 + AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId()); + if (user == null) { + throw exception(CONTACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS); + } + + // 3. 更新新的负责人 + ContactDO updateContract = ContactConvert.INSTANCE.convert(contact, reqVO, userId); + contactMapper.updateById(updateContract); + + // 4. TODO 记录联系人转移日志 + + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImpl.java index 4dadd6923..8cee161f0 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImpl.java @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*; import cn.iocoder.yudao.module.crm.convert.contract.ContractConvert; import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO; import cn.iocoder.yudao.module.crm.dal.mysql.contract.ContractMapper; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -15,8 +17,7 @@ import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTRACT_NOT_EXISTS; -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED; +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.crm.framework.utils.AuthUtil.isReadAndWrite; /** @@ -31,6 +32,9 @@ public class ContractServiceImpl implements ContractService { @Resource private ContractMapper contractMapper; + @Resource + private AdminUserApi adminUserApi; + @Override public Long createContract(ContractCreateReqVO createReqVO) { // 插入 @@ -96,12 +100,17 @@ public class ContractServiceImpl implements ContractService { if (!isReadAndWrite(contract.getRwUserIds(), userId)) { throw exception(CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED); } + // 2. 校验新负责人是否存在 + AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId()); + if (user == null) { + throw exception(CONTRACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS); + } - // 2. 更新新的负责人 + // 3. 更新新的负责人 ContractDO updateContract = ContractConvert.INSTANCE.convert(contract, reqVO, userId); contractMapper.updateById(updateContract); - // 3. TODO 记录合同转移日志 + // 4. TODO 记录合同转移日志 }