mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	CRM-联系人:新增联系人转移接口
This commit is contained in:
		| @@ -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<Boolean> transfer(@Valid @RequestBody CrmContactTransferReqVO reqVO) { | ||||
|         contactService.contactTransfer(reqVO, getLoginUserId()); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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<Long> roUserIds; | ||||
|  | ||||
|     @Schema(description = "读写权限的用户编号数组") | ||||
|     private Set<Long> rwUserIds; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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<Long> roUserIds; | ||||
|  | ||||
|     @Schema(description = "读写权限的用户编号数组") | ||||
|     private Set<Long> rwUserIds; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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; // 新的负责人 | ||||
|  | ||||
| } | ||||
| @@ -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<ContactExcelVO> convertList02(List<ContactDO> list); | ||||
|  | ||||
|     default ContactDO convert(ContactDO contact, CrmContactTransferReqVO reqVO, Long userId) { | ||||
|         Set<Long> 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); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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<Long> roUserIds; | ||||
|     /** | ||||
|      * 读写权限的用户编号数组 | ||||
|      */ | ||||
|     @TableField(typeHandler = JsonLongSetTypeHandler.class) | ||||
|     private Set<Long> rwUserIds; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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<ContactDO> getContactList(ContactExportReqVO exportReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 联系人编号 | ||||
|      * | ||||
|      * @param reqVO  请求 | ||||
|      * @param userId 用户编号 | ||||
|      */ | ||||
|     void contactTransfer(CrmContactTransferReqVO reqVO, Long userId); | ||||
|      | ||||
| } | ||||
|   | ||||
| @@ -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 记录联系人转移日志 | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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 记录合同转移日志 | ||||
|  | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 puhui999
					puhui999