mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	CRM-商机:新增商机转移接口
This commit is contained in:
		| @@ -23,6 +23,7 @@ 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 = "管理后台 - 商机") | ||||
| @RestController | ||||
| @@ -80,11 +81,19 @@ public class CrmBusinessController { | ||||
|     @PreAuthorize("@ss.hasPermission('crm:business:export')") | ||||
|     @OperateLog(type = EXPORT) | ||||
|     public void exportBusinessExcel(@Valid CrmBusinessExportReqVO exportReqVO, | ||||
|               HttpServletResponse response) throws IOException { | ||||
|                                     HttpServletResponse response) throws IOException { | ||||
|         List<CrmBusinessDO> list = businessService.getBusinessList(exportReqVO); | ||||
|         // 导出 Excel | ||||
|         List<CrmBusinessExcelVO> datas = CrmBusinessConvert.INSTANCE.convertList02(list); | ||||
|         ExcelUtils.write(response, "商机.xls", "数据", CrmBusinessExcelVO.class, datas); | ||||
|     } | ||||
|  | ||||
|     @PutMapping("/transfer") | ||||
|     @Operation(summary = "商机转移") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:business:update')") | ||||
|     public CommonResult<Boolean> transfer(@Valid @RequestBody CrmBusinessTransferReqVO reqVO) { | ||||
|         businessService.businessTransfer(reqVO, getLoginUserId()); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -5,12 +5,21 @@ import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.ToString; | ||||
|  | ||||
| import java.util.Set; | ||||
|  | ||||
| @Schema(description = "管理后台 - 商机创建 Request VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| public class CrmBusinessCreateReqVO extends CrmBusinessBaseVO { | ||||
|  | ||||
|     @Schema(description = "只读权限的用户编号数组") | ||||
|     private Set<Long> roUserIds; | ||||
|  | ||||
|     @Schema(description = "读写权限的用户编号数组") | ||||
|     private Set<Long> rwUserIds; | ||||
|  | ||||
|  | ||||
|     // TODO @ljileo:新建的时候,应该可以传递添加的产品; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,20 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.business.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.Data; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| @Schema(description = "管理后台 - 商机转移 Request VO") | ||||
| @Data | ||||
| public class CrmBusinessTransferReqVO { | ||||
|  | ||||
|     @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; // 新的负责人 | ||||
|  | ||||
| } | ||||
| @@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode; | ||||
| import lombok.ToString; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
| import java.util.Set; | ||||
|  | ||||
| @Schema(description = "管理后台 - 商机更新 Request VO") | ||||
| @Data | ||||
| @@ -17,6 +18,13 @@ public class CrmBusinessUpdateReqVO extends CrmBusinessBaseVO { | ||||
|     @NotNull(message = "主键不能为空") | ||||
|     private Long id; | ||||
|  | ||||
|     @Schema(description = "只读权限的用户编号数组") | ||||
|     private Set<Long> roUserIds; | ||||
|  | ||||
|     @Schema(description = "读写权限的用户编号数组") | ||||
|     private Set<Long> rwUserIds; | ||||
|  | ||||
|  | ||||
|     // TODO @ljileo:修改的时候,应该可以传递添加的产品; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import lombok.Data; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| @Schema(description = "管理后台 - 联系转移 Request VO") | ||||
| @Schema(description = "管理后台 - 联系人转移 Request VO") | ||||
| @Data | ||||
| public class CrmContactTransferReqVO { | ||||
|  | ||||
|   | ||||
| @@ -1,13 +1,14 @@ | ||||
| package cn.iocoder.yudao.module.crm.convert.business; | ||||
|  | ||||
| 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.business.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.factory.Mappers; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Set; | ||||
|  | ||||
| /** | ||||
|  * 商机 Convert | ||||
| @@ -29,4 +30,12 @@ public interface CrmBusinessConvert { | ||||
|  | ||||
|     List<CrmBusinessExcelVO> convertList02(List<CrmBusinessDO> list); | ||||
|  | ||||
|     default CrmBusinessDO convert(CrmBusinessDO business, CrmBusinessTransferReqVO reqVO, Long userId) { | ||||
|         Set<Long> rwUserIds = business.getRwUserIds(); | ||||
|         rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人 | ||||
|         rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人 | ||||
|         return new CrmBusinessDO().setId(business.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人 | ||||
|                 .setRwUserIds(rwUserIds); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -34,7 +34,7 @@ public interface ContactConvert { | ||||
|  | ||||
|     default ContactDO convert(ContactDO contact, CrmContactTransferReqVO reqVO, Long userId) { | ||||
|         Set<Long> rwUserIds = contact.getRwUserIds(); | ||||
|         rwUserIds.removeIf(item -> ObjUtil.equal(item, userId.toString())); // 移除老负责人 | ||||
|         rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人 | ||||
|         rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人 | ||||
|         return new ContactDO().setId(contact.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人 | ||||
|                 .setRwUserIds(rwUserIds); | ||||
|   | ||||
| @@ -34,7 +34,7 @@ public interface ContractConvert { | ||||
|  | ||||
|     default ContractDO convert(ContractDO contract, CrmContractTransferReqVO reqVO, Long userId) { | ||||
|         Set<Long> rwUserIds = contract.getRwUserIds(); | ||||
|         rwUserIds.removeIf(item -> ObjUtil.equal(item, userId.toString())); // 移除老负责人 | ||||
|         rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人 | ||||
|         rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人 | ||||
|         return new ContractDO().setId(contract.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人 | ||||
|                 .setRwUserIds(rwUserIds); | ||||
|   | ||||
| @@ -1,14 +1,17 @@ | ||||
| package cn.iocoder.yudao.module.crm.dal.dataobject.business; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatus.CrmBusinessStatusDO; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatustype.CrmBusinessStatusTypeDO; | ||||
| 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; | ||||
|  | ||||
| /** | ||||
|  * 商机 DO | ||||
| @@ -85,16 +88,14 @@ public class CrmBusinessDO extends BaseDO { | ||||
|     private Long ownerUserId; | ||||
|     /** | ||||
|      * 只读权限的用户编号数组 | ||||
|      * | ||||
|      * TODO @lijie:应该是 List<Long>,然后使用下对应的 typehandler | ||||
|      */ | ||||
|     private String roUserIds; | ||||
|     @TableField(typeHandler = JsonLongSetTypeHandler.class) | ||||
|     private Set<Long> roUserIds; | ||||
|     /** | ||||
|      * 读写权限的用户编号数组 | ||||
|      * | ||||
|      * TODO @lijie:应该是 List<Long>,然后使用下对应的 typehandler | ||||
|      */ | ||||
|     private String rwUserIds; | ||||
|     @TableField(typeHandler = JsonLongSetTypeHandler.class) | ||||
|     private Set<Long> rwUserIds; | ||||
|     /** | ||||
|      * 1赢单2输单3无效 | ||||
|      * | ||||
|   | ||||
| @@ -1,10 +1,7 @@ | ||||
| package cn.iocoder.yudao.module.crm.service.business; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessCreateReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessExportReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessPageReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | ||||
|  | ||||
| import javax.validation.Valid; | ||||
| @@ -72,4 +69,12 @@ public interface CrmBusinessService { | ||||
|      */ | ||||
|     List<CrmBusinessDO> getBusinessList(CrmBusinessExportReqVO exportReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 商机转移 | ||||
|      * | ||||
|      * @param reqVO  请求 | ||||
|      * @param userId 用户编号 | ||||
|      */ | ||||
|     void businessTransfer(CrmBusinessTransferReqVO reqVO, Long userId); | ||||
|      | ||||
| } | ||||
|   | ||||
| @@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.service.business; | ||||
| 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.business.vo.CrmBusinessCreateReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessExportReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessPageReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | ||||
| import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper; | ||||
| 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.BUSINESS_NOT_EXISTS; | ||||
| import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | ||||
| import static cn.iocoder.yudao.module.crm.framework.utils.AuthUtil.isReadAndWrite; | ||||
|  | ||||
| /** | ||||
|  * 商机 Service 实现类 | ||||
| @@ -32,6 +32,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||||
|     @Resource | ||||
|     private CrmBusinessMapper businessMapper; | ||||
|  | ||||
|     @Resource | ||||
|     private AdminUserApi adminUserApi; | ||||
|  | ||||
|     @Override | ||||
|     public Long createBusiness(CrmBusinessCreateReqVO createReqVO) { | ||||
|         // 插入 | ||||
| @@ -58,10 +61,12 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||||
|         businessMapper.deleteById(id); | ||||
|     } | ||||
|  | ||||
|     private void validateBusinessExists(Long id) { | ||||
|         if (businessMapper.selectById(id) == null) { | ||||
|     private CrmBusinessDO validateBusinessExists(Long id) { | ||||
|         CrmBusinessDO crmBusiness = businessMapper.selectById(id); | ||||
|         if (crmBusiness == null) { | ||||
|             throw exception(BUSINESS_NOT_EXISTS); | ||||
|         } | ||||
|         return crmBusiness; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -87,4 +92,26 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||||
|         return businessMapper.selectList(exportReqVO); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void businessTransfer(CrmBusinessTransferReqVO reqVO, Long userId) { | ||||
|         // 1. 校验商机是否存在 | ||||
|         CrmBusinessDO business = validateBusinessExists(reqVO.getId()); | ||||
|         // 1.2. 校验用户是否拥有读写权限 | ||||
|         if (!isReadAndWrite(business.getRwUserIds(), userId)) { | ||||
|             throw exception(BUSINESS_TRANSFER_FAIL_PERMISSION_DENIED); | ||||
|         } | ||||
|         // 2. 校验新负责人是否存在 | ||||
|         AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId()); | ||||
|         if (user == null) { | ||||
|             throw exception(BUSINESS_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS); | ||||
|         } | ||||
|  | ||||
|         // 3. 更新新的负责人 | ||||
|         CrmBusinessDO updateBusiness = CrmBusinessConvert.INSTANCE.convert(business, reqVO, userId); | ||||
|         businessMapper.updateById(updateBusiness); | ||||
|  | ||||
|         // 4. TODO 记录商机转移日志 | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -110,8 +110,8 @@ public class ContactServiceImpl implements ContactService { | ||||
|         } | ||||
|  | ||||
|         // 3. 更新新的负责人 | ||||
|         ContactDO updateContract = ContactConvert.INSTANCE.convert(contact, reqVO, userId); | ||||
|         contactMapper.updateById(updateContract); | ||||
|         ContactDO updateContact = ContactConvert.INSTANCE.convert(contact, reqVO, userId); | ||||
|         contactMapper.updateById(updateContact); | ||||
|  | ||||
|         // 4. TODO 记录联系人转移日志 | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 puhui999
					puhui999