!810 fix:修复 issues 提到的一些公众号上的问题

Merge pull request !810 from puhui999/develop
This commit is contained in:
芋道源码 2024-01-07 13:23:53 +00:00 committed by Gitee
commit 3c7f63c356
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
47 changed files with 791 additions and 610 deletions

View File

@ -6,6 +6,7 @@ import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
/**
@ -121,4 +122,8 @@ public class LocalDateTimeUtils {
return date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);
}
public static Long between(LocalDateTime dateTime) {
return LocalDateTimeUtil.between(dateTime, LocalDateTime.now(), ChronoUnit.DAYS);
}
}

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.framework.operatelog.config;
import cn.iocoder.yudao.framework.operatelog.core.service.ILogRecordServiceImpl;
import cn.iocoder.yudao.framework.operatelog.core.service.LogRecordServiceImpl;
import com.mzt.logapi.service.ILogRecordService;
import com.mzt.logapi.starter.annotation.EnableLogRecord;
import lombok.extern.slf4j.Slf4j;
@ -21,7 +21,7 @@ public class YudaoOperateLogV2Configuration {
@Bean
@Primary
public ILogRecordService iLogRecordServiceImpl() {
return new ILogRecordServiceImpl();
return new LogRecordServiceImpl();
}
}

View File

@ -2,7 +2,8 @@ package cn.iocoder.yudao.framework.operatelog.core.service;
import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
import com.mzt.logapi.beans.LogRecord;
@ -13,7 +14,6 @@ import lombok.extern.slf4j.Slf4j;
import java.util.List;
// TODO @puhui999LogRecordServiceImpl 改成这个名字哈
/**
* 操作日志 ILogRecordService 实现类
*
@ -22,7 +22,7 @@ import java.util.List;
* @author HUIHUI
*/
@Slf4j
public class ILogRecordServiceImpl implements ILogRecordService {
public class LogRecordServiceImpl implements ILogRecordService {
@Resource
private OperateLogApi operateLogApi;
@ -46,9 +46,13 @@ public class ILogRecordServiceImpl implements ILogRecordService {
}
private static void fillUserFields(OperateLogV2CreateReqDTO reqDTO) {
// TODO @puhui999使用 SecurityFrameworkUtils因为要考虑rpcmqjob它其实不是 web
reqDTO.setUserId(WebFrameworkUtils.getLoginUserId());
reqDTO.setUserType(WebFrameworkUtils.getLoginUserType());
// 使用 SecurityFrameworkUtils因为要考虑rpcmqjob它其实不是 web
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
if (loginUser == null) {
return;
}
reqDTO.setUserId(loginUser.getId());
reqDTO.setUserType(loginUser.getUserType());
}
public static void fillModuleFields(OperateLogV2CreateReqDTO reqDTO, LogRecord logRecord) {

View File

@ -41,7 +41,7 @@ public interface ErrorCodeConstants {
ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_005, "客户【{}】放入公海失败,原因:客户已锁定");
ErrorCode CUSTOMER_UPDATE_OWNER_USER_FAIL = new ErrorCode(1_020_006_006, "更新客户【{}】负责人失败, 原因:系统异常");
ErrorCode CUSTOMER_LOCK_FAIL_IS_LOCK = new ErrorCode(1_020_006_007, "锁定客户失败,它已经处于锁定状态");
ErrorCode CUSTOMER_UNLOCK_FAIL_IS_UNLOCK = new ErrorCode(1_020_006_008, "客户失败,它已经处于未锁定状态");
ErrorCode CUSTOMER_UNLOCK_FAIL_IS_UNLOCK = new ErrorCode(1_020_006_008, "锁客户失败,它已经处于未锁定状态");
ErrorCode CUSTOMER_LOCK_EXCEED_LIMIT = new ErrorCode(1_020_006_009, "锁定客户失败,超出锁定规则上限");
ErrorCode CUSTOMER_OWNER_EXCEED_LIMIT = new ErrorCode(1_020_006_010, "操作失败,超出客户数拥有上限");

View File

@ -2,32 +2,72 @@ package cn.iocoder.yudao.module.crm.enums;
/**
* CRM 操作日志枚举
* 目的统一管理也减少 Service 里各种复杂字符串
*
* @author HUIHUI
*/
public interface LogRecordConstants {
//======================= 客户模块类型 =======================
// TODO puhui999: 确保模块命名方式为 module + 子模块名称的方式统一定义模块名称是为了方便查询各自记录的操作日志列如说查询客户张三的操作日志就可以 module + bizId
String CRM_LEADS = "CRM 线索";
String CRM_CUSTOMER = "CRM 客户";
String CRM_CONTACT = "CRM 联系人";
String CRM_BUSINESS = "CRM 商机";
String CRM_CONTRACT = "CRM 合同";
String CRM_PRODUCT = "CRM 产品";
String CRM_RECEIVABLE = "CRM 回款";
String CRM_RECEIVABLE_PLAN = "CRM 回款计划";
// ======================= CRM_LEADS 线索 =======================
//======================= 客户转移操作日志 =======================
String CRM_LEADS_TYPE = "CRM 线索";
String TRANSFER_CUSTOMER_LOG_SUCCESS = "把客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
// ======================= CRM_CUSTOMER 客户 =======================
// TODO @puhui999这里格式是不是可以这样;目的是统一管理也减少 Service 里各种复杂字符串
// ======================= Customer 客户 =======================
String CUSTOMER_TYPE = "CRM 客户";
String CUSTOMER_CREATE_SUB_TYPE = "创建客户";
String CUSTOMER_CREATE_SUCCESS = "更新了客户{_DIFF{#updateReqVO}}";
String CRM_CUSTOMER_TYPE = "CRM 客户";
String CRM_CUSTOMER_CREATE_SUB_TYPE = "创建客户";
String CRM_CUSTOMER_CREATE_SUCCESS = "创建了客户{{#customer.name}}";
String CRM_CUSTOMER_UPDATE_SUB_TYPE = "更新客户";
String CRM_CUSTOMER_UPDATE_SUCCESS = "更新了客户【{{#customerName}}】: {_DIFF{#updateReqVO}}";
String CRM_CUSTOMER_DELETE_SUB_TYPE = "删除客户";
String CRM_CUSTOMER_DELETE_SUCCESS = "删除了客户【{{#customerName}}】";
String CRM_CUSTOMER_TRANSFER_SUB_TYPE = "转移客户";
String CRM_CUSTOMER_TRANSFER_SUCCESS = "将客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
String CRM_CUSTOMER_LOCK_SUB_TYPE = "{{#crmCustomer.lockStatus ? '解锁客户' : '锁定客户'}}";
String CRM_CUSTOMER_LOCK_SUCCESS = "{{#crmCustomer.lockStatus ? '将客户【' + #crmCustomer.name + '】解锁' : '将客户【' + #crmCustomer.name + '】锁定'}}";
String CRM_CUSTOMER_POOL_SUB_TYPE = "客户放入公海";
String CRM_CUSTOMER_POOL_SUCCESS = "将客户【{{#customerName}}】放入了公海";
String CRM_CUSTOMER_RECEIVE_SUB_TYPE = "{{#ownerUserName != null ? '分配客户' : '领取客户'}}";
String CRM_CUSTOMER_RECEIVE_SUCCESS = "{{#ownerUserName != null ? '将客户【' + #customer.name + '】分配给【' + #ownerUserName + '】' : '领取客户【' + #customer.name + '】'}}";
String CUSTOMER_UPDATE_SUB_TYPE = "更新客户";
// ======================= CRM_CUSTOMER_LIMIT_CONFIG 客户限制配置 =======================
String CRM_CUSTOMER_LIMIT_CONFIG_TYPE = "CRM 客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUB_TYPE = "创建客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUCCESS = "创建了【{{#limitType}}】类型的客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUB_TYPE = "更新客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUCCESS = "更新了客户限制配置: {_DIFF{#updateReqVO}}";
String CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUB_TYPE = "删除客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUCCESS = "删除了【{{#limitType}}】类型的客户限制配置";
// ======================= CRM_CUSTOMER_POOL_CONFIG 客户公海规则 =======================
String CRM_CUSTOMER_POOL_CONFIG_TYPE = "CRM 客户公海规则";
String CRM_CUSTOMER_POOL_CONFIG_SUB_TYPE = "{{#isPoolConfigUpdate ? '更新客户公海规则' : '创建客户公海规则'}}";
String CRM_CUSTOMER_POOL_CONFIG_SUCCESS = "{{#isPoolConfigUpdate ? '更新了客户公海规则' : '创建了客户公海规则'}}";
// ======================= CRM_CONTACT 联系人 =======================
String CRM_CONTACT_TYPE = "CRM 联系人";
// ======================= CRM_BUSINESS 商机 =======================
String CRM_BUSINESS_TYPE = "CRM 商机";
// ======================= CRM_CONTRACT 合同 =======================
String CRM_CONTRACT_TYPE = "CRM 合同";
// ======================= CRM_PRODUCT 产品 =======================
String CRM_PRODUCT_TYPE = "CRM 产品";
// ======================= CRM_RECEIVABLE 回款 =======================
String CRM_RECEIVABLE_TYPE = "CRM 回款";
// ======================= CRM_RECEIVABLE_PLAN 回款计划 =======================
String CRM_RECEIVABLE_PLAN_TYPE = "CRM 回款计划";
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.crm.enums.customer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
@ -36,6 +38,12 @@ public enum CrmCustomerLimitConfigTypeEnum implements IntArrayValuable {
*/
private final String name;
public static String getNameByType(Integer type) {
CrmCustomerLimitConfigTypeEnum typeEnum = CollUtil.findOne(CollUtil.newArrayList(CrmCustomerLimitConfigTypeEnum.values()),
item -> ObjUtil.equal(item.type, type));
return typeEnum == null ? null : typeEnum.getName();
}
@Override
public int[] array() {
return ARRAYS;

View File

@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
@ -19,7 +22,6 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
@ -36,11 +38,10 @@ import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
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 cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER_TYPE;
@Tag(name = "管理后台 - CRM 客户")
@RestController
@ -50,7 +51,8 @@ public class CrmCustomerController {
@Resource
private CrmCustomerService customerService;
@Resource
private CrmCustomerPoolConfigService customerPoolConfigService;
@Resource
private DeptApi deptApi;
@Resource
@ -58,28 +60,24 @@ public class CrmCustomerController {
@Resource
private OperateLogApi operateLogApi;
// TODO @puhui999 CrmCustomerCreateReqVOCrmCustomerUpdateReqVOCrmCustomerRespVO 按照新的规范搞一下哈
@PostMapping("/create")
@Operation(summary = "创建客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录@puhui999注解都先删除先记录没关系我们下个迭代就都删除掉操作日志了
@PreAuthorize("@ss.hasPermission('crm:customer:create')")
public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerCreateReqVO createReqVO) {
public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerSaveReqVO createReqVO) {
return success(customerService.createCustomer(createReqVO, getLoginUserId()));
}
@PutMapping("/update")
@Operation(summary = "更新客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> updateCustomer(@Valid @RequestBody CrmCustomerUpdateReqVO updateReqVO) {
public CommonResult<Boolean> updateCustomer(@Valid @RequestBody CrmCustomerSaveReqVO updateReqVO) {
customerService.updateCustomer(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@Parameter(name = "id", description = "编号", required = true)
@Parameter(name = "id", description = "客户编号", required = true)
@PreAuthorize("@ss.hasPermission('crm:customer:delete')")
public CommonResult<Boolean> deleteCustomer(@RequestParam("id") Long id) {
customerService.deleteCustomer(id);
@ -103,7 +101,6 @@ public class CrmCustomerController {
return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap));
}
// TODO @puhui999这个查询会查出多个微信发你图了
@GetMapping("/page")
@Operation(summary = "获得客户分页")
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
@ -115,11 +112,37 @@ public class CrmCustomerController {
}
// 2. 拼接数据
// TODO @puhui999距离进入公海的时间
// 距离进入公海的时间
Map<Long, Long> poolDayMap = getPoolDayMap(pageResult);
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId())));
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap));
return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap, poolDayMap));
}
private Map<Long, Long> getPoolDayMap(PageResult<CrmCustomerDO> pageResult) {
Map<Long, Long> poolDayMap = null;
CrmCustomerPoolConfigDO customerPoolConfig = customerPoolConfigService.getCustomerPoolConfig();
if (customerPoolConfig != null && customerPoolConfig.getEnabled()) { // 有公海配置的情况
poolDayMap = convertMap(pageResult.getList(), CrmCustomerDO::getId, item -> {
long dealExpireDay = 0;
if (!item.getDealStatus()) { // 检查是否成交
dealExpireDay = customerPoolConfig.getDealExpireDays() - LocalDateTimeUtils.between(item.getCreateTime());
}
long contactExpireDay = customerPoolConfig.getContactExpireDays() - LocalDateTimeUtils.between(item.getContactLastTime());
return dealExpireDay == 0 ? contactExpireDay : Math.min(dealExpireDay, contactExpireDay);
});
}
return poolDayMap;
}
@GetMapping(value = "/list-all-simple")
@Operation(summary = "获取客户精简信息列表", description = "只包含有读权限的客户,主要用于前端的下拉选项")
public CommonResult<List<CrmCustomerSimpleRespVO>> getSimpleDeptList() {
CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
List<CrmCustomerDO> list = customerService.getCustomerPage(reqVO, getLoginUserId()).getList();
return success(BeanUtils.toBean(list, CrmCustomerSimpleRespVO.class));
}
@GetMapping("/export-excel")
@ -131,32 +154,32 @@ public class CrmCustomerController {
pageVO.setPageSize(PAGE_SIZE_NONE); // 不分页
List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
// 导出 Excel
List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerExcelVO.class, datas);
List<CrmCustomerRespVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerRespVO.class, datas);
}
@PutMapping("/transfer")
@Operation(summary = "转移客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> transfer(@Valid @RequestBody CrmCustomerTransferReqVO reqVO) {
customerService.transferCustomer(reqVO, getLoginUserId());
return success(true);
}
// TODO @puhui999是不是接口只要传递 bizId Controller 自己组装出 OperateLogV2PageReqDTO
@GetMapping("/operate-log-page")
@Operation(summary = "获得客户操作日志")
@Parameter(name = "id", description = "客户编号", required = true)
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(CrmCustomerOperateLogPageReqVO reqVO) {
reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
reqVO.setBizType(CRM_CUSTOMER);
return success(operateLogApi.getOperateLogPage(BeanUtils.toBean(reqVO, OperateLogV2PageReqDTO.class)));
public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(@RequestParam("id") Long id) {
OperateLogV2PageReqDTO reqDTO = new OperateLogV2PageReqDTO();
reqDTO.setPageSize(PAGE_SIZE_NONE); // 不分页
reqDTO.setBizType(CRM_CUSTOMER_TYPE);
reqDTO.setBizId(id);
return success(operateLogApi.getOperateLogPage(reqDTO));
}
@PutMapping("/lock")
@Operation(summary = "锁定/解锁客户")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> lockCustomer(@Valid @RequestBody CrmCustomerLockReqVO lockReqVO) {
customerService.lockCustomer(lockReqVO, getLoginUserId());
@ -167,7 +190,6 @@ public class CrmCustomerController {
@PutMapping("/put-pool")
@Operation(summary = "数据放入公海")
@OperateLog(enable = false) // TODO 关闭原有日志记录
@Parameter(name = "id", description = "客户编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> putCustomerPool(@RequestParam("id") Long id) {
@ -180,32 +202,16 @@ public class CrmCustomerController {
@Parameter(name = "ids", description = "编号数组", required = true, example = "1,2,3")
@PreAuthorize("@ss.hasPermission('crm:customer:receive')")
public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids) {
customerService.receiveCustomer(ids, getLoginUserId());
customerService.receiveCustomer(ids, getLoginUserId(), Boolean.TRUE);
return success(true);
}
// TODO @puhui999需要搞个 VO
@PutMapping("/distribute")
@Operation(summary = "分配公海给对应负责人")
@Parameters({
@Parameter(name = "ids", description = "客户编号数组", required = true, example = "1,2,3"),
@Parameter(name = "ownerUserId", description = "分配的负责人编号", required = true, example = "12345")
})
@PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids,
@RequestParam(value = "ownerUserId") Long ownerUserId) {
customerService.receiveCustomer(ids, ownerUserId);
public CommonResult<Boolean> distributeCustomer(@Valid @RequestBody CrmCustomerDistributeReqVO distributeReqVO) {
customerService.receiveCustomer(distributeReqVO.getIds(), distributeReqVO.getOwnerUserId(), Boolean.FALSE);
return success(true);
}
// TODO 芋艿这个接口要调整下
@GetMapping("/query-all-list")
@Operation(summary = "查询客户列表")
@PreAuthorize("@ss.hasPermission('crm:customer:all')")
public CommonResult<List<CrmCustomerQueryAllRespVO>> queryAll() {
List<CrmCustomerDO> crmCustomerDOList = customerService.getCustomerList();
List<CrmCustomerQueryAllRespVO> data = CrmCustomerConvert.INSTANCE.convertQueryAll(crmCustomerDOList);
return success(data);
}
}

View File

@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerLimitConfigConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerLimitConfigService;
@ -17,12 +16,12 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.Collection;
import java.util.Map;
@ -43,18 +42,17 @@ public class CrmCustomerLimitConfigController {
@Resource
private AdminUserApi adminUserApi;
// TODO @puhui999可以把 vo 改下哈
@PostMapping("/create")
@Operation(summary = "创建客户限制配置")
@PreAuthorize("@ss.hasPermission('crm:customer-limit-config:create')")
public CommonResult<Long> createCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigCreateReqVO createReqVO) {
public CommonResult<Long> createCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigSaveReqVO createReqVO) {
return success(customerLimitConfigService.createCustomerLimitConfig(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新客户限制配置")
@PreAuthorize("@ss.hasPermission('crm:customer-limit-config:update')")
public CommonResult<Boolean> updateCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
public CommonResult<Boolean> updateCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigSaveReqVO updateReqVO) {
customerLimitConfigService.updateCustomerLimitConfig(updateReqVO);
return success(true);
}

View File

@ -8,13 +8,12 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfig
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - CRM 客户公海配置")
@ -26,7 +25,6 @@ public class CrmCustomerPoolConfigController {
@Resource
private CrmCustomerPoolConfigService customerPoolConfigService;
// TODO @puhui999可以把 vo 改下哈
@GetMapping("/get")
@Operation(summary = "获取客户公海规则设置")
@PreAuthorize("@ss.hasPermission('crm:customer-pool-config:query')")

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import jakarta.validation.constraints.NotNull;
@Schema(description = "管理后台 - CRM 客户创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerCreateReqVO extends CrmCustomerBaseVO {
@Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@NotNull(message = "负责人不能为空")
private Long ownerUserId;
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - CRM 客户分配公海给对应负责人 Request VO")
@Data
public class CrmCustomerDistributeReqVO {
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024]")
@NotNull(message = "客户编号不能为空")
private List<Long> ids;
@Schema(description = "负责人", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "负责人不能为空")
private Long ownerUserId;
}

View File

@ -1,93 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
// TODO 芋艿导出最后做等基本确认的差不多之后
/**
* CRM 客户 Excel VO
*
* @author Wanwan
*/
@Data
public class CrmCustomerExcelVO {
@ExcelProperty("编号")
private Long id;
@ExcelProperty("客户名称")
private String name;
@ExcelProperty(value = "跟进状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean followUpStatus;
@ExcelProperty(value = "锁定状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean lockStatus;
@ExcelProperty(value = "成交状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean dealStatus;
@ExcelProperty(value = "所属行业", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY)
private Integer industryId;
@ExcelProperty(value = "客户等级", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL)
private Integer level;
@ExcelProperty(value = "客户来源", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE)
private Integer source;
@ExcelProperty("手机")
private String mobile;
@ExcelProperty("电话")
private String telephone;
@ExcelProperty("网址")
private String website;
@ExcelProperty("QQ")
private String qq;
@ExcelProperty("wechat")
private String wechat;
@ExcelProperty("email")
private String email;
@ExcelProperty("客户描述")
private String description;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("负责人的用户编号")
private Long ownerUserId;
@ExcelProperty("地区编号")
private Integer areaId;
@ExcelProperty("详细地址")
private String detailAddress;
@ExcelProperty("最后跟进时间")
private LocalDateTime contactLastTime;
@ExcelProperty("下次联系时间")
private LocalDateTime contactNextTime;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - crm 客户操作日志分页 Request VO")
@Data
public class CrmCustomerOperateLogPageReqVO extends PageParam {
@Schema(description = "模块数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long bizId;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long userId;
@Schema(description = "模块类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private String bizType;
}

View File

@ -1,17 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
// TODO 芋艿这块要统一下
@Schema(description = "管理后台 - CRM 全部客户 Response VO")
@Data
public class CrmCustomerQueryAllRespVO{
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private Long id;
@Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
private String name;
}

View File

@ -1,9 +1,12 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@ -12,45 +15,124 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Schema(description = "管理后台 - CRM 客户 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerRespVO extends CrmCustomerBaseVO {
@ExcelIgnoreUnannotated
public class CrmCustomerRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@ExcelProperty("编号")
private Long id;
@Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@ExcelProperty("客户名称")
private String name;
@Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@ExcelProperty(value = "跟进状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean followUpStatus;
@Schema(description = "锁定状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@Schema(description = "锁定状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@ExcelProperty(value = "锁定状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean lockStatus;
@Schema(description = "成交状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@Schema(description = "成交状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@ExcelProperty(value = "成交状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean dealStatus;
@Schema(description = "所属行业", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@ExcelProperty(value = "所属行业", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY)
private Integer industryId;
@Schema(description = "客户等级", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@ExcelProperty(value = "客户等级", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL)
private Integer level;
@Schema(description = "客户来源", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@ExcelProperty(value = "客户来源", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE)
private Integer source;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("手机")
private String mobile;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("电话")
private String telephone;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("网址")
private String website;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("QQ")
private String qq;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("wechat")
private String wechat;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("email")
private String email;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("客户描述")
private String description;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("备注")
private String remark;
@Schema(description = "负责人的用户编号", example = "25682")
@ExcelProperty("负责人的用户编号")
private Long ownerUserId;
@Schema(description = "负责人名字", example = "25682")
@ExcelProperty("负责人名字")
private String ownerUserName;
@Schema(description = "负责人部门")
@ExcelProperty("负责人部门")
private String ownerUserDeptName;
@Schema(description = "地区编号", example = "1024")
@ExcelProperty("地区编号")
private Integer areaId;
@Schema(description = "地区名称", example = "北京市")
@ExcelProperty("地区名称")
private String areaName;
@Schema(description = "详细地址", example = "北京市成华大道")
@ExcelProperty("详细地址")
private String detailAddress;
@Schema(description = "最后跟进时间")
@ExcelProperty("最后跟进时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime contactLastTime;
@Schema(description = "下次联系时间")
@ExcelProperty("下次联系时间")
private LocalDateTime contactNextTime;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("更新时间")
private LocalDateTime updateTime;
@Schema(description = "创建人")
@Schema(description = "创建人", example = "1024")
@ExcelProperty("创建人")
private String creator;
@Schema(description = "创建人名字")
@Schema(description = "创建人名字", example = "芋道源码")
@ExcelProperty("创建人名字")
private String creatorName;
@Schema(description = "距离加入公海时间", example = "1")
private Long poolDay;
}

View File

@ -21,12 +21,12 @@ import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY;
/**
* 客户 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Schema(description = "管理后台 - CRM 客户新增/修改 Request VO")
@Data
public class CrmCustomerBaseVO {
public class CrmCustomerSaveReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private Long id;
@Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
@DiffLogField(name = "客户名称")
@ -99,4 +99,7 @@ public class CrmCustomerBaseVO {
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime contactNextTime;
@Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private Long ownerUserId;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Schema(description = "管理后台 - 客户精简信息 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CrmCustomerSimpleRespVO {
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
private String name;
}

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import jakarta.validation.constraints.NotNull;
@Schema(description = "管理后台 - CRM 客户更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerUpdateReqVO extends CrmCustomerBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
@NotNull(message = "编号不能为空")
private Long id;
}

View File

@ -1,14 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 客户限制配置创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerLimitConfigCreateReqVO extends CrmCustomerLimitConfigBaseVO {
}

View File

@ -3,22 +3,36 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 客户限制配置 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerLimitConfigRespVO extends CrmCustomerLimitConfigBaseVO {
public class CrmCustomerLimitConfigRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
private Long id;
@Schema(description = "规则类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "规则类型不能为空")
private Integer type;
@Schema(description = "规则适用人群")
private List<Long> userIds;
@Schema(description = "规则适用部门")
private List<Long> deptIds;
@Schema(description = "数量上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
@NotNull(message = "数量上限不能为空")
private Integer maxCount;
@Schema(description = "成交客户是否占有拥有客户数(当 type = 1 时)")
private Boolean dealCountEnabled;
@Schema(description = "规则适用人群名称")
private List<AdminUserRespDTO> users;

View File

@ -1,33 +1,39 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
import com.mzt.logapi.starter.annotation.DiffLogField;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import jakarta.validation.constraints.NotNull;
import java.util.List;
/**
* 客户限制配置 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Schema(description = "管理后台 - 客户限制配置创建/更新 Request VO")
@Data
public class CrmCustomerLimitConfigBaseVO {
public class CrmCustomerLimitConfigSaveReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
private Long id;
@Schema(description = "规则类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@DiffLogField(name = "规则类型")
@NotNull(message = "规则类型不能为空")
private Integer type;
@Schema(description = "规则适用人群")
@DiffLogField(name = "规则适用人群", function = "getAdminUserById")
private List<Long> userIds;
@Schema(description = "规则适用部门")
@DiffLogField(name = "规则适用部门", function = "getDeptById")
private List<Long> deptIds;
@Schema(description = "数量上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
@DiffLogField(name = "数量上限")
@NotNull(message = "数量上限不能为空")
private Integer maxCount;
@Schema(description = "成交客户是否占有拥有客户数(当 type = 1 时)")
@DiffLogField(name = "成交客户是否占有拥有客户数")
private Boolean dealCountEnabled;
}

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import jakarta.validation.constraints.NotNull;
@Schema(description = "管理后台 - 客户限制配置更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerLimitConfigUpdateReqVO extends CrmCustomerLimitConfigBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
@NotNull(message = "编号不能为空")
private Long id;
}

View File

@ -1,31 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import jakarta.validation.constraints.NotNull;
/**
* 客户公海配置 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class CrmCustomerPoolConfigBaseVO {
@Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "是否启用客户公海不能为空")
private Boolean enabled;
@Schema(description = "未跟进放入公海天数", example = "2")
private Integer contactExpireDays;
@Schema(description = "未成交放入公海天数", example = "2")
private Integer dealExpireDays;
@Schema(description = "是否开启提前提醒", example = "true")
private Boolean notifyEnabled;
@Schema(description = "提前提醒天数", example = "2")
private Integer notifyDays;
}

View File

@ -1,14 +1,27 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - CRM 客户公海规则 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerPoolConfigRespVO extends CrmCustomerPoolConfigBaseVO {
public class CrmCustomerPoolConfigRespVO {
@Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "是否启用客户公海不能为空")
private Boolean enabled;
@Schema(description = "未跟进放入公海天数", example = "2")
private Integer contactExpireDays;
@Schema(description = "未成交放入公海天数", example = "2")
private Integer dealExpireDays;
@Schema(description = "是否开启提前提醒", example = "true")
private Boolean notifyEnabled;
@Schema(description = "提前提醒天数", example = "2")
private Integer notifyDays;
}

View File

@ -1,34 +1,61 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mzt.logapi.starter.annotation.DiffLogField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.Objects;
@Schema(description = "管理后台 - CRM 客户公海配置的保存 Request VO")
@Schema(description = "管理后台 - CRM 客户公海配置的创建/更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerPoolConfigSaveReqVO extends CrmCustomerPoolConfigBaseVO {
public class CrmCustomerPoolConfigSaveReqVO {
// TODO @puhui999AssertTrue 必须 is 开头哈注意需要 json 忽略下避免被序列化
@AssertTrue(message = "客户公海规则设置不正确")
// TODO @puhui999这个方法是不是拆成 2 一个校验 contactExpireDays一个校验 dealExpireDays
public boolean poolEnableValid() {
@Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@DiffLogField(name = "是否启用客户公海")
@NotNull(message = "是否启用客户公海不能为空")
private Boolean enabled;
@Schema(description = "未跟进放入公海天数", example = "2")
@DiffLogField(name = "未跟进放入公海天数")
private Integer contactExpireDays;
@Schema(description = "未成交放入公海天数", example = "2")
@DiffLogField(name = "未成交放入公海天数")
private Integer dealExpireDays;
@Schema(description = "是否开启提前提醒", example = "true")
@DiffLogField(name = "是否开启提前提醒")
private Boolean notifyEnabled;
@Schema(description = "提前提醒天数", example = "2")
@DiffLogField(name = "提前提醒天数")
private Integer notifyDays;
@AssertTrue(message = "未成交放入公海天数不能为空")
@JsonIgnore
public boolean isDealExpireDaysValid() {
if (!BooleanUtil.isTrue(getEnabled())) {
return true;
}
return ObjectUtil.isAllNotEmpty(getContactExpireDays(), getDealExpireDays());
return Objects.nonNull(getDealExpireDays());
}
@AssertTrue(message = "客户公海规则设置不正确")
// TODO @puhui999这个方法是不是改成 isNotifyDaysValid() 更好点本质校验的是 notifyDays 是否为空
public boolean notifyEnableValid() {
@AssertTrue(message = "未跟进放入公海天数不能为空")
@JsonIgnore
public boolean isContactExpireDaysValid() {
if (!BooleanUtil.isTrue(getEnabled())) {
return true;
}
return Objects.nonNull(getContactExpireDays());
}
@AssertTrue(message = "提前提醒天数不能为空")
@JsonIgnore
public boolean isNotifyDaysValid() {
if (!BooleanUtil.isTrue(getNotifyEnabled())) {
return true;
}

View File

@ -103,7 +103,6 @@ public class CrmPermissionController {
// 拼接数据
List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId));
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId));
// TODO @puhui999可能 postIds 为空的时候会导致报错看看怎么 fix
Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream);
Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds);
return success(CrmPermissionConvert.INSTANCE.convert(permission, userList, deptMap, postMap));

View File

@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.crm.convert.customer;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@ -29,9 +31,7 @@ public interface CrmCustomerConvert {
CrmCustomerConvert INSTANCE = Mappers.getMapper(CrmCustomerConvert.class);
CrmCustomerDO convert(CrmCustomerCreateReqVO bean);
CrmCustomerDO convert(CrmCustomerUpdateReqVO bean);
CrmCustomerDO convert(CrmCustomerSaveReqVO bean);
CrmCustomerRespVO convert(CrmCustomerDO bean);
@ -51,7 +51,7 @@ public interface CrmCustomerConvert {
findAndThen(userMap, Long.parseLong(customer.getCreator()), user -> customer.setCreatorName(user.getNickname()));
}
List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list);
List<CrmCustomerRespVO> convertList02(List<CrmCustomerDO> list);
@Mapping(target = "bizId", source = "reqVO.id")
CrmPermissionTransferReqBO convert(CrmCustomerTransferReqVO reqVO, Long userId);
@ -66,9 +66,12 @@ public interface CrmCustomerConvert {
}
default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
Map<Long, DeptRespDTO> deptMap) {
Map<Long, DeptRespDTO> deptMap, Map<Long, Long> poolDayMap) {
PageResult<CrmCustomerRespVO> result = convertPage(pageResult);
result.getList().forEach(item -> setUserInfo(item, userMap, deptMap));
result.getList().forEach(item -> {
setUserInfo(item, userMap, deptMap);
findAndThen(poolDayMap, item.getId(), item::setPoolDay);
});
return result;
}
@ -76,6 +79,4 @@ public interface CrmCustomerConvert {
CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO);
List<CrmCustomerQueryAllRespVO> convertQueryAll(List<CrmCustomerDO> crmCustomerDO);
}

View File

@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.crm.convert.customer;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
@ -24,9 +23,7 @@ public interface CrmCustomerLimitConfigConvert {
CrmCustomerLimitConfigConvert INSTANCE = Mappers.getMapper(CrmCustomerLimitConfigConvert.class);
CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigCreateReqVO bean);
CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigUpdateReqVO bean);
CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigSaveReqVO bean);
CrmCustomerLimitConfigRespVO convert(CrmCustomerLimitConfigDO bean);

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.crm.convert.permission;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO;
@ -15,6 +16,7 @@ import com.google.common.collect.Multimaps;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -50,6 +52,10 @@ public interface CrmPermissionConvert {
item.setDeptName(deptRespDTO.getName());
});
List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds());
if (CollUtil.isEmpty(postRespList)) {
item.setPostNames(Collections.emptySet());
return;
}
item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName));
});
return item;

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
/**
@ -28,6 +29,12 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> {
.eq(CrmPermissionDO::getBizId, bizId));
}
default List<CrmPermissionDO> selectByBizTypeAndBizIds(Integer bizType, Collection<Long> bizIds) {
return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
.eq(CrmPermissionDO::getBizType, bizType)
.in(CrmPermissionDO::getBizId, bizIds));
}
default List<CrmPermissionDO> selectListByBizTypeAndUserId(Integer bizType, Long userId) {
return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
.eq(CrmPermissionDO::getBizType, bizType)

View File

@ -18,12 +18,10 @@ import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_DENIED;
@ -46,16 +44,29 @@ public class CrmPermissionAspect {
Map<String, Object> expressionValues = parseExpressions(joinPoint, crmPermission);
Integer bizType = StrUtil.isEmpty(crmPermission.bizTypeValue()) ?
crmPermission.bizType()[0].getType() : (Integer) expressionValues.get(crmPermission.bizTypeValue()); // 模块类型
Long bizId = (Long) expressionValues.get(crmPermission.bizId()); // 模块数据编号
// 处理兼容多个 bizId 的情况
Object object = expressionValues.get(crmPermission.bizId());// 模块数据编号
Set<Long> bizIds = new HashSet<>();
if (object instanceof Collection<?>) {
bizIds.addAll(convertSet((Collection<?>) object, item -> Long.parseLong(item.toString())));
} else {
bizIds.add(Long.parseLong(object.toString()));
}
Integer permissionLevel = crmPermission.level().getLevel(); // 需要的权限级别
List<CrmPermissionDO> permissionList = crmPermissionService.getPermissionListByBiz(bizType, bizIds);
Map<Long, List<CrmPermissionDO>> multiMap = convertMultiMap(permissionList, CrmPermissionDO::getBizId);
bizIds.forEach(bizId -> {
validatePermission(bizType, multiMap.get(bizId), permissionLevel);
});
}
// 1.1 如果是超级管理员则直接通过
private void validatePermission(Integer bizType, List<CrmPermissionDO> bizPermissions, Integer permissionLevel) {
// 1. 如果是超级管理员则直接通过
if (CrmPermissionUtils.isCrmAdmin()) {
return;
}
// 1.2 获取数据权限
List<CrmPermissionDO> bizPermissions = crmPermissionService.getPermissionListByBiz(bizType, bizId);
if (CollUtil.isEmpty(bizPermissions)) { // 没有数据权限的情况
// 1.1 没有数据权限的情况
if (CollUtil.isEmpty(bizPermissions)) {
// 公海数据如果没有团队成员大家也因该有读权限才对
if (CrmPermissionLevelEnum.isRead(permissionLevel)) {
return;
@ -63,7 +74,7 @@ public class CrmPermissionAspect {
// 没有数据权限的情况下超出了读权限直接报错避免后面校验空指针
throw exception(CRM_PERMISSION_DENIED, CrmBizTypeEnum.getNameByType(bizType));
} else { // 有数据权限但是没有负责人的情况
} else { // 1.2 有数据权限但是没有负责人的情况
if (!anyMatch(bizPermissions, item -> CrmPermissionLevelEnum.isOwner(item.getLevel()))) {
if (CrmPermissionLevelEnum.isRead(permissionLevel)) {
return;

View File

@ -1,9 +1,8 @@
package cn.iocoder.yudao.module.crm.service.customer;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
import jakarta.validation.Valid;
@ -22,14 +21,14 @@ public interface CrmCustomerLimitConfigService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createCustomerLimitConfig(@Valid CrmCustomerLimitConfigCreateReqVO createReqVO);
Long createCustomerLimitConfig(@Valid CrmCustomerLimitConfigSaveReqVO createReqVO);
/**
* 更新客户限制配置
*
* @param updateReqVO 更新信息
*/
void updateCustomerLimitConfig(@Valid CrmCustomerLimitConfigUpdateReqVO updateReqVO);
void updateCustomerLimitConfig(@Valid CrmCustomerLimitConfigSaveReqVO updateReqVO);
/**
* 删除客户限制配置

View File

@ -2,25 +2,29 @@ package cn.iocoder.yudao.module.crm.service.customer;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerLimitConfigConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerLimitConfigMapper;
import cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
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.CUSTOMER_LIMIT_CONFIG_NOT_EXISTS;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
/**
* 客户限制配置 Service 实现类
@ -40,34 +44,44 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
private AdminUserApi adminUserApi;
@Override
// TODO @puhui999操作日志
public Long createCustomerLimitConfig(CrmCustomerLimitConfigCreateReqVO createReqVO) {
@LogRecord(type = CRM_CUSTOMER_LIMIT_CONFIG_TYPE, subType = CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUB_TYPE, bizNo = "{{#limitId}}", success = CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUCCESS)
public Long createCustomerLimitConfig(CrmCustomerLimitConfigSaveReqVO createReqVO) {
validateUserAndDept(createReqVO.getUserIds(), createReqVO.getDeptIds());
// 插入
CrmCustomerLimitConfigDO customerLimitConfig = CrmCustomerLimitConfigConvert.INSTANCE.convert(createReqVO);
customerLimitConfigMapper.insert(customerLimitConfig);
// 记录操作日志上下文
LogRecordContext.putVariable("limitType", CrmCustomerLimitConfigTypeEnum.getNameByType(customerLimitConfig.getType()));
LogRecordContext.putVariable("limitId", customerLimitConfig.getId());
// 返回
return customerLimitConfig.getId();
}
@Override
// TODO @puhui999操作日志
public void updateCustomerLimitConfig(CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
@LogRecord(type = CRM_CUSTOMER_LIMIT_CONFIG_TYPE, subType = CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", success = CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUCCESS)
public void updateCustomerLimitConfig(CrmCustomerLimitConfigSaveReqVO updateReqVO) {
// 校验存在
validateCustomerLimitConfigExists(updateReqVO.getId());
CrmCustomerLimitConfigDO oldLimitConfig = validateCustomerLimitConfigExists(updateReqVO.getId());
validateUserAndDept(updateReqVO.getUserIds(), updateReqVO.getDeptIds());
// 更新
CrmCustomerLimitConfigDO updateObj = CrmCustomerLimitConfigConvert.INSTANCE.convert(updateReqVO);
customerLimitConfigMapper.updateById(updateObj);
// 记录操作日志上下文
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldLimitConfig, CrmCustomerLimitConfigSaveReqVO.class));
}
@Override
// TODO @puhui999操作日志
@LogRecord(type = CRM_CUSTOMER_LIMIT_CONFIG_TYPE, subType = CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUCCESS)
public void deleteCustomerLimitConfig(Long id) {
// 校验存在
validateCustomerLimitConfigExists(id);
CrmCustomerLimitConfigDO limitConfigDO = validateCustomerLimitConfigExists(id);
// 删除
customerLimitConfigMapper.deleteById(id);
// 记录操作日志上下文
LogRecordContext.putVariable("limitType", CrmCustomerLimitConfigTypeEnum.getNameByType(limitConfigDO.getType()));
}
@Override
@ -80,10 +94,12 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
return customerLimitConfigMapper.selectPage(pageReqVO);
}
private void validateCustomerLimitConfigExists(Long id) {
if (customerLimitConfigMapper.selectById(id) == null) {
private CrmCustomerLimitConfigDO validateCustomerLimitConfigExists(Long id) {
CrmCustomerLimitConfigDO limitConfigDO = customerLimitConfigMapper.selectById(id);
if (limitConfigDO == null) {
throw exception(CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
}
return limitConfigDO;
}
/**

View File

@ -5,12 +5,16 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCu
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerPoolConfigMapper;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.starter.annotation.LogRecord;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.Objects;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
/**
* 客户公海配置 Service 实现类
*
@ -19,6 +23,7 @@ import java.util.Objects;
@Service
@Validated
public class CrmCustomerPoolConfigServiceImpl implements CrmCustomerPoolConfigService {
@Resource
private CrmCustomerPoolConfigMapper customerPoolConfigMapper;
@ -38,16 +43,23 @@ public class CrmCustomerPoolConfigServiceImpl implements CrmCustomerPoolConfigSe
* @param saveReqVO 更新信息
*/
@Override
// TODO @puhui999操作日志
@LogRecord(type = CRM_CUSTOMER_POOL_CONFIG_TYPE, subType = CRM_CUSTOMER_POOL_CONFIG_SUB_TYPE, bizNo = "{{#poolConfigId}}", success = CRM_CUSTOMER_POOL_CONFIG_SUCCESS)
public void saveCustomerPoolConfig(CrmCustomerPoolConfigSaveReqVO saveReqVO) {
// 存在则进行更新
CrmCustomerPoolConfigDO dbConfig = getCustomerPoolConfig();
CrmCustomerPoolConfigDO poolConfig = CrmCustomerConvert.INSTANCE.convert(saveReqVO);
if (Objects.nonNull(dbConfig)) {
customerPoolConfigMapper.updateById(CrmCustomerConvert.INSTANCE.convert(saveReqVO).setId(dbConfig.getId()));
customerPoolConfigMapper.updateById(poolConfig.setId(dbConfig.getId()));
// 记录操作日志上下文
LogRecordContext.putVariable("isPoolConfigUpdate", Boolean.TRUE);
LogRecordContext.putVariable("poolConfigId", poolConfig.getId());
return;
}
// 不存在则进行插入
customerPoolConfigMapper.insert(CrmCustomerConvert.INSTANCE.convert(saveReqVO));
customerPoolConfigMapper.insert(poolConfig);
// 记录操作日志上下文
LogRecordContext.putVariable("isPoolConfigUpdate", Boolean.FALSE);
LogRecordContext.putVariable("poolConfigId", poolConfig.getId());
}
}

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.crm.service.customer;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLockReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import jakarta.validation.Valid;
@ -22,14 +25,14 @@ public interface CrmCustomerService {
* @param userId 用户编号
* @return 编号
*/
Long createCustomer(@Valid CrmCustomerCreateReqVO createReqVO, Long userId);
Long createCustomer(@Valid CrmCustomerSaveReqVO createReqVO, Long userId);
/**
* 更新客户
*
* @param updateReqVO 更新信息
*/
void updateCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
void updateCustomer(@Valid CrmCustomerSaveReqVO updateReqVO);
/**
* 删除客户
@ -101,15 +104,8 @@ public interface CrmCustomerService {
*
* @param ids 要领取的客户编号数组
* @param ownerUserId 负责人
* @param isReceive /否领取
*/
void receiveCustomer(List<Long> ids, Long ownerUserId);
/**
* 获取客户列表
*
* @return 客户列表
* @author zyna
*/
List<CrmCustomerDO> getCustomerList();
void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive);
}

View File

@ -1,10 +1,15 @@
package cn.iocoder.yudao.module.crm.service.customer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLockReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
@ -12,9 +17,11 @@ import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission;
import cn.iocoder.yudao.module.crm.framework.permission.core.util.CrmPermissionUtils;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord;
@ -24,12 +31,14 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.TRANSFER_CUSTOMER_LOG_SUCCESS;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_OWNER_LIMIT;
import static java.util.Collections.singletonList;
@ -56,8 +65,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, subType = "创建客户", bizNo = "{{#customerId}}", success = "创建了客户") // TODO @puhui999创建了客户客户名要记录进去不然在展示操作日志的全列表看不清楚是哪个客户哈
public Long createCustomer(CrmCustomerCreateReqVO createReqVO, Long userId) {
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_CREATE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_CREATE_SUCCESS)
public Long createCustomer(CrmCustomerSaveReqVO createReqVO, Long userId) {
createReqVO.setId(null);
// 1. 校验拥有客户是否到达上限
validateCustomerExceedOwnerLimit(createReqVO.getOwnerUserId(), 1);
@ -72,17 +82,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
.setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
// 4. 记录操作日志
LogRecordContext.putVariable("customerId", customer.getId());
// 4. 记录操作日志上下文
LogRecordContext.putVariable("customer", customer);
return customer.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, subType = "更新客户", bizNo = "{{#updateReqVO.id}}", success = "更新了客户{_DIFF{#updateReqVO}}", extra = "{{#extra}}")
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", success = CRM_CUSTOMER_UPDATE_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) {
// TODO @puhui999更新的时候要把 updateReqVO 负责人设置为空避免修改
public void updateCustomer(CrmCustomerSaveReqVO updateReqVO) {
Assert.notNull(updateReqVO.getId(), "客户编号不能为空");
// 更新的时候要把 updateReqVO 负责人设置为空避免修改
updateReqVO.setOwnerUserId(null);
// 1. 校验存在
CrmCustomerDO oldCustomer = validateCustomerExists(updateReqVO.getId());
@ -90,21 +102,18 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO);
customerMapper.updateById(updateObj);
// 3. 记录操作日志
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerUpdateReqVO.class));
// TODO 扩展信息测试 @puhui999看着没啥问题可以删除啦
HashMap<String, Object> extra = new HashMap<>();
extra.put("tips", "随便记录一点啦");
LogRecordContext.putVariable("extra", extra);
// 3. 记录操作日志上下文
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerSaveReqVO.class));
LogRecordContext.putVariable("customerName", oldCustomer.getName());
}
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, subType = "删除客户", bizNo = "{{#id}}", success = "删除了客户")
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_DELETE_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_DELETE_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void deleteCustomer(Long id) {
// 校验存在
validateCustomerExists(id);
CrmCustomerDO customer = validateCustomerExists(id);
// TODO @puhui999如果有联系人商机则不允许删除
// 删除
@ -112,15 +121,145 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
// 删除数据权限
permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), id);
// TODO @puhui999删除跟进记录
// 记录操作日志上下文
LogRecordContext.putVariable("customerName", customer.getName());
}
private CrmCustomerDO validateCustomerExists(Long id) {
CrmCustomerDO customerDO = customerMapper.selectById(id);
if (customerDO == null) {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_CUSTOMER_TRANSFER_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
// 1.1 校验客户是否存在
CrmCustomerDO customer = validateCustomerExists(reqVO.getId());
// 1.2 校验拥有客户是否到达上限
validateCustomerExceedOwnerLimit(reqVO.getNewOwnerUserId(), 1);
// 2.1 数据权限转移
permissionService.transferPermission(
CrmCustomerConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()));
// 2.2 转移后重新设置负责人
customerMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
// 3. TODO 记录转移日志
// 记录操作日志上下文
LogRecordContext.putVariable("crmCustomer", customer);
}
@Override
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_LOCK_SUB_TYPE, bizNo = "{{#lockReqVO.id}}", success = CRM_CUSTOMER_LOCK_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#lockReqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void lockCustomer(CrmCustomerLockReqVO lockReqVO, Long userId) {
// 1.1 校验当前客户是否存在
CrmCustomerDO customer = validateCustomerExists(lockReqVO.getId());
// 1.2 校验当前是否重复操作锁定/解锁状态
if (customer.getLockStatus().equals(lockReqVO.getLockStatus())) {
throw exception(customer.getLockStatus() ? CUSTOMER_LOCK_FAIL_IS_LOCK : CUSTOMER_UNLOCK_FAIL_IS_UNLOCK);
}
// 1.3 校验锁定上限
if (lockReqVO.getLockStatus()) {
validateCustomerExceedLockLimit(userId);
}
// 2. 更新锁定状态
customerMapper.updateById(BeanUtils.toBean(lockReqVO, CrmCustomerDO.class));
// 3. 记录操作日志上下文. tips: 因为这里使用的是老的状态所以记录时反着记录也就是 lockStatus true 那么就是解锁反之为锁定
LogRecordContext.putVariable("crmCustomer", customer);
}
// ==================== 公海相关操作 ====================
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_POOL_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_POOL_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void putCustomerPool(Long id) {
// 1. 校验存在
CrmCustomerDO customer = customerMapper.selectById(id);
if (customer == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
return customerDO;
// 1.2. 校验是否为公海数据
validateCustomerOwnerExists(customer, true);
// 1.3. 校验客户是否锁定
validateCustomerIsLocked(customer, true);
// 2. 设置负责人为 NULL
int updateOwnerUserIncr = customerMapper.updateOwnerUserIdById(customer.getId(), null);
if (updateOwnerUserIncr == 0) {
throw exception(CUSTOMER_UPDATE_OWNER_USER_FAIL);
}
// 3. 删除负责人数据权限
permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
CrmPermissionLevelEnum.OWNER.getLevel());
// TODO @puhui999联系人的负责人也要设置为 null这块和领取是对应的因为领取后负责人也要关联过来
// 记录操作日志上下文
LogRecordContext.putVariable("customerName", customer.getName());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive) {
if (!isReceive && !CrmPermissionUtils.isCrmAdmin()) { // 只有管理员可以分配
throw exception(CRM_PERMISSION_DENIED, CrmBizTypeEnum.CRM_CUSTOMER.getName());
}
// 1.1 校验存在
List<CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
if (customers.size() != ids.size()) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2. 校验负责人是否存在
adminUserApi.validateUserList(singletonList(ownerUserId));
// 1.3. 校验状态
customers.forEach(customer -> {
// 校验是否已有负责人
validateCustomerOwnerExists(customer, false);
// 校验是否锁定
validateCustomerIsLocked(customer, false);
// 校验成交状态
validateCustomerDeal(customer);
});
// 1.4 校验负责人是否到达上限
validateCustomerExceedOwnerLimit(ownerUserId, customers.size());
// 2.1 领取公海数据
List<CrmCustomerDO> updateCustomers = new ArrayList<>();
List<CrmPermissionCreateReqBO> createPermissions = new ArrayList<>();
customers.forEach(customer -> {
// 2.1. 设置负责人
updateCustomers.add(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(ownerUserId));
// 2.2. 创建负责人数据权限
createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
.setBizId(customer.getId()).setUserId(ownerUserId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
});
// 2.2 更新客户负责人
customerMapper.updateBatch(updateCustomers);
// 2.3 创建负责人数据权限
permissionService.createPermissionBatch(createPermissions);
// TODO @芋艿要不要处理关联的联系人
// 3. 记录操作日志
AdminUserRespDTO user = null;
if (!isReceive) {
user = adminUserApi.getUser(ownerUserId);
}
for (CrmCustomerDO customer : customers) {
getSelf().receiveCustomerLog(customer, user == null ? null : user.getNickname());
}
}
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_RECEIVE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_RECEIVE_SUCCESS)
public void receiveCustomerLog(CrmCustomerDO customer, String ownerUserName) {
// 记录操作日志上下文
LogRecordContext.putVariable("customer", customer);
LogRecordContext.putVariable("ownerUserName", ownerUserName);
}
//======================= 查询相关 =======================
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
@ -141,6 +280,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
return customerMapper.selectPage(pageReqVO, userId);
}
//======================= 校验相关 =======================
/**
* 校验客户是否存在
*
@ -151,47 +292,38 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
validateCustomerExists(customerId);
}
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, subType = "转移客户", bizNo = "{{#reqVO.id}}", success = TRANSFER_CUSTOMER_LOG_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
// 1.1 校验客户是否存在
CrmCustomerDO customer = validateCustomerExists(reqVO.getId());
// 1.2 校验拥有客户是否到达上限
validateCustomerExceedOwnerLimit(reqVO.getNewOwnerUserId(), 1);
// 2.1 数据权限转移
permissionService.transferPermission(
CrmCustomerConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()));
// 2.2 转移后重新设置负责人
customerMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
// 3. TODO 记录转移日志
LogRecordContext.putVariable("crmCustomer", customer);
private void validateCustomerOwnerExists(CrmCustomerDO customer, Boolean pool) {
if (customer == null) { // 防御一下
throw exception(CUSTOMER_NOT_EXISTS);
}
// 校验是否为公海数据
if (pool && customer.getOwnerUserId() == null) {
throw exception(CUSTOMER_IN_POOL, customer.getName());
}
// 负责人已存在
if (!pool && customer.getOwnerUserId() != null) {
throw exception(CUSTOMER_OWNER_EXISTS, customer.getName());
}
}
@Override
// TODO @puhui999看看这个能不能根据条件写操作日志
// TODO 如果是 锁定 subType 锁定客户success 将客户锁定
// TODO 如果是 解锁 subType 解锁客户success 将客户解锁
@LogRecord(type = CRM_CUSTOMER, subType = "锁定/解锁客户", bizNo = "{{#updateReqVO.id}}", success = "锁定了客户")
// TODO @puhui999数据权限
public void lockCustomer(CrmCustomerLockReqVO lockReqVO, Long userId) {
// 1.1 校验当前客户是否存在
validateCustomerExists(lockReqVO.getId());
// 1.2 校验当前是否重复操作锁定/解锁状态
CrmCustomerDO customer = customerMapper.selectById(lockReqVO.getId());
if (customer.getLockStatus().equals(lockReqVO.getLockStatus())) {
throw exception(customer.getLockStatus() ? CUSTOMER_LOCK_FAIL_IS_LOCK : CUSTOMER_UNLOCK_FAIL_IS_UNLOCK);
private CrmCustomerDO validateCustomerExists(Long id) {
CrmCustomerDO customerDO = customerMapper.selectById(id);
if (customerDO == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.3 校验锁定上限
if (lockReqVO.getLockStatus()) {
validateCustomerExceedLockLimit(userId);
return customerDO;
}
// 2. 更新锁定状态
customerMapper.updateById(BeanUtils.toBean(lockReqVO, CrmCustomerDO.class));
private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) {
if (customer.getLockStatus()) {
throw exception(pool ? CUSTOMER_LOCKED_PUT_POOL_FAIL : CUSTOMER_LOCKED, customer.getName());
}
}
private void validateCustomerDeal(CrmCustomerDO customer) {
if (customer.getDealStatus()) {
throw exception(CUSTOMER_ALREADY_DEAL);
}
}
/**
@ -235,105 +367,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
}
}
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER, subType = "客户放入公海", bizNo = "{{#id}}", success = "将客户放入了公海") // TODO @puhui999将客户放入了公海
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void putCustomerPool(Long id) {
// 1. 校验存在
CrmCustomerDO customer = customerMapper.selectById(id);
if (customer == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2. 校验是否为公海数据
validateCustomerOwnerExists(customer, true);
// 1.3. 校验客户是否锁定
validateCustomerIsLocked(customer, true);
// 2. 设置负责人为 NULL
int updateOwnerUserIncr = customerMapper.updateOwnerUserIdById(customer.getId(), null);
if (updateOwnerUserIncr == 0) {
throw exception(CUSTOMER_UPDATE_OWNER_USER_FAIL);
}
// 3. 删除负责人数据权限
permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
CrmPermissionLevelEnum.OWNER.getLevel());
// TODO @puhui999联系人的负责人也要设置为 null这块和领取是对应的因为领取后负责人也要关联过来
}
@Override
@Transactional(rollbackFor = Exception.class)
// TODO @puhui999权限校验
// TODO @puhui999如果是分配操作日志是 将客户分配给
// TODO @puhui999如果是领取操作日志是领取客户
// TODO @puhui999如果是多条则需要记录多条操作日志不然 bizId 不好关联
public void receiveCustomer(List<Long> ids, Long ownerUserId) {
// 1.1 校验存在
List<CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
if (customers.size() != ids.size()) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2. 校验负责人是否存在
adminUserApi.validateUserList(singletonList(ownerUserId));
// 1.3. 校验状态
customers.forEach(customer -> {
// 校验是否已有负责人
validateCustomerOwnerExists(customer, false);
// 校验是否锁定
validateCustomerIsLocked(customer, false);
// 校验成交状态
validateCustomerDeal(customer);
});
// 1.4 校验负责人是否到达上限
validateCustomerExceedOwnerLimit(ownerUserId, customers.size());
// 2.1 领取公海数据
List<CrmCustomerDO> updateCustomers = new ArrayList<>();
List<CrmPermissionCreateReqBO> createPermissions = new ArrayList<>();
customers.forEach(customer -> {
// 2.1. 设置负责人
updateCustomers.add(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(ownerUserId));
// 2.2. 创建负责人数据权限
createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
.setBizId(customer.getId()).setUserId(ownerUserId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
});
// 2.2 更新客户负责人
customerMapper.updateBatch(updateCustomers);
// 2.3 创建负责人数据权限
permissionService.createPermissionBatch(createPermissions);
// TODO @芋艿要不要处理关联的联系人
}
private void validateCustomerOwnerExists(CrmCustomerDO customer, Boolean pool) {
if (customer == null) { // 防御一下
throw exception(CUSTOMER_NOT_EXISTS);
}
// 校验是否为公海数据
if (pool && customer.getOwnerUserId() == null) {
throw exception(CUSTOMER_IN_POOL, customer.getName());
}
// 负责人已存在
if (customer.getOwnerUserId() != null) {
throw exception(CUSTOMER_OWNER_EXISTS, customer.getName());
}
}
private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) {
if (customer.getLockStatus()) {
throw exception(pool ? CUSTOMER_LOCKED_PUT_POOL_FAIL : CUSTOMER_LOCKED, customer.getName());
}
}
private void validateCustomerDeal(CrmCustomerDO customer) {
if (customer.getDealStatus()) {
throw exception(CUSTOMER_ALREADY_DEAL);
}
}
@Override
public List<CrmCustomerDO> getCustomerList() {
return customerMapper.selectList();
/**
* 获得自身的代理对象解决 AOP 生效问题
*
* @return 自己
*/
private CrmCustomerServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}

View File

@ -90,6 +90,15 @@ public interface CrmPermissionService {
*/
List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Long bizId);
/**
* 获取数据权限列表通过 数据类型 x 某个数据
*
* @param bizType 数据类型关联 {@link CrmBizTypeEnum}
* @param bizIds 数据编号关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
* @return Crm 数据权限列表
*/
List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Collection<Long> bizIds);
/**
* 获取用户参与的模块数据列表
*

View File

@ -187,6 +187,11 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId);
}
@Override
public List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Collection<Long> bizIds) {
return crmPermissionMapper.selectByBizTypeAndBizIds(bizType, bizIds);
}
@Override
public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId) {
return crmPermissionMapper.selectListByBizTypeAndUserId(bizType, userId);

View File

@ -2,19 +2,17 @@ package cn.iocoder.yudao.module.crm.service.customer;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import jakarta.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -47,7 +45,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
@Test
public void testCreateCustomer_success() {
// 准备参数
CrmCustomerCreateReqVO reqVO = randomPojo(CrmCustomerCreateReqVO.class);
CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class);
// 调用
Long customerId = customerService.createCustomer(reqVO, getLoginUserId());
@ -64,7 +62,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
CrmCustomerDO dbCustomer = randomPojo(CrmCustomerDO.class);
customerMapper.insert(dbCustomer);// @Sql: 先插入出一条存在的数据
// 准备参数
CrmCustomerUpdateReqVO reqVO = randomPojo(CrmCustomerUpdateReqVO.class, o -> {
CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class, o -> {
o.setId(dbCustomer.getId()); // 设置更新的 ID
});
@ -78,7 +76,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
@Test
public void testUpdateCustomer_notExists() {
// 准备参数
CrmCustomerUpdateReqVO reqVO = randomPojo(CrmCustomerUpdateReqVO.class);
CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> customerService.updateCustomer(reqVO), CUSTOMER_NOT_EXISTS);

View File

@ -2,18 +2,16 @@ package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerLimitConfigMapper;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerLimitConfigServiceImpl;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import jakarta.annotation.Resource;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
@ -40,7 +38,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
@Test
public void testCreateCustomerLimitConfig_success() {
// 准备参数
CrmCustomerLimitConfigCreateReqVO reqVO = randomPojo(CrmCustomerLimitConfigCreateReqVO.class);
CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class);
// 调用
Long customerLimitConfigId = customerLimitConfigService.createCustomerLimitConfig(reqVO);
@ -57,7 +55,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
// 准备参数
CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class, o -> {
CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class, o -> {
o.setId(dbCustomerLimitConfig.getId()); // 设置更新的 ID
});
@ -71,7 +69,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
@Test
public void testUpdateCustomerLimitConfig_notExists() {
// 准备参数
CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class);
CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> customerLimitConfigService.updateCustomerLimitConfig(reqVO), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.module.mp.controller.admin.statistics.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -17,7 +17,7 @@ public class MpStatisticsGetReqVO {
@NotNull(message = "公众号账号的编号不能为空")
private Long accountId;
@Schema(description = "查询时间范围")
@Schema(description = "查询时间范围", example = "[2022-07-01 00:00:00, 2022-07-01 23:59:59]")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@NotNull(message = "查询时间范围不能为空")
private LocalDateTime[] date;

View File

@ -11,10 +11,16 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
@Mapper
public interface MpStatisticsConvert {
@ -27,7 +33,7 @@ public interface MpStatisticsConvert {
List<MpStatisticsUpstreamMessageRespVO> convertList03(List<WxDataCubeMsgResult> list);
@Mappings({
@Mapping(source = "refDate", target = "refDate", dateFormat = "yyyy-MM-dd"),
@Mapping(target = "refDate", expression = "java(dateFormat0(bean.getRefDate()))"),
@Mapping(source = "msgUser", target = "messageUser"),
@Mapping(source = "msgCount", target = "messageCount"),
})
@ -35,6 +41,12 @@ public interface MpStatisticsConvert {
List<MpStatisticsInterfaceSummaryRespVO> convertList04(List<WxDataCubeInterfaceResult> list);
@Mapping(source = "refDate", target = "refDate", dateFormat = "yyyy-MM-dd")
@Mapping(target = "refDate", expression = "java(dateFormat0(bean.getRefDate()))")
MpStatisticsInterfaceSummaryRespVO convert(WxDataCubeInterfaceResult bean);
@Named("dateFormat0")
default LocalDateTime dateFormat0(String date) {
return LocalDate.parse(date, DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY)).atStartOfDay();
}
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.mp.service.message;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mp.controller.admin.message.vo.message.MpMessagePageReqVO;
@ -17,6 +18,8 @@ import cn.iocoder.yudao.module.mp.service.account.MpAccountService;
import cn.iocoder.yudao.module.mp.service.material.MpMaterialService;
import cn.iocoder.yudao.module.mp.service.message.bo.MpMessageSendOutReqBO;
import cn.iocoder.yudao.module.mp.service.user.MpUserService;
import jakarta.annotation.Resource;
import jakarta.validation.Validator;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
@ -28,9 +31,6 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import jakarta.validation.Validator;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.MESSAGE_SEND_FAIL;
@ -72,6 +72,12 @@ public class MpMessageServiceImpl implements MpMessageService {
// 获得关联信息
MpAccountDO account = mpAccountService.getAccountFromCache(appId);
Assert.notNull(account, "公众号账号({}) 不存在", appId);
// 订阅事件不记录因为此时公众号粉丝表中还没有此粉丝的数据
if (ObjUtil.equal(wxMessage.getEvent(), WxConsts.EventType.SUBSCRIBE)) {
return;
}
MpUserDO user = mpUserService.getUser(appId, wxMessage.getFromUser());
Assert.notNull(user, "公众号粉丝({}/{}) 不存在", appId, wxMessage.getFromUser());

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.system.api.dept;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
@ -26,6 +28,10 @@ public interface PostApi {
List<PostRespDTO> getPostList(Collection<Long> ids);
default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return MapUtil.empty();
}
List<PostRespDTO> list = getPostList(ids);
return CollectionUtils.convertMap(list, PostRespDTO::getId);
}

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.system.api.logger.dto;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 系统操作日志 Resp DTO
*
@ -64,4 +66,9 @@ public class OperateLogV2RespDTO {
*/
private String userAgent;
/**
* 创建时间
*/
private LocalDateTime createTime;
}

View File

@ -35,10 +35,12 @@ public interface OperateLogConvert {
return BeanUtils.toBean(operateLogPage, OperateLogV2RespDTO.class).setList(setUserInfo(operateLogPage.getList(), userList));
}
private static List<OperateLogV2RespDTO> setUserInfo(List<OperateLogV2DO> logList, List<AdminUserDO> userList) {
OperateLogV2RespDTO convert(OperateLogV2DO operateLogV2DO);
private List<OperateLogV2RespDTO> setUserInfo(List<OperateLogV2DO> logList, List<AdminUserDO> userList) {
Map<Long, AdminUserDO> userMap = convertMap(userList, AdminUserDO::getId);
return CollectionUtils.convertList(logList, item -> {
OperateLogV2RespDTO respDTO = BeanUtils.toBean(item, OperateLogV2RespDTO.class);
OperateLogV2RespDTO respDTO = convert(item);
findAndThen(userMap, item.getUserId(), user -> respDTO.setUserName(user.getNickname()));
return respDTO;
});

View File

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.system.framework.operatelog.core;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import com.mzt.logapi.service.IParseFunction;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 管理员名字的 {@link IParseFunction} 实现类
*
* @author HUIHUI
*/
@Slf4j
@Component
public class DeptParseFunction implements IParseFunction {
@Resource
private DeptApi deptApi;
@Override
public String functionName() {
return "getDeptById";
}
@Override
public String apply(Object value) {
if (StrUtil.isEmptyIfStr(value)) {
return "";
}
// 获取部门信息
DeptRespDTO dept = deptApi.getDept(Long.parseLong(value.toString()));
if (dept == null) {
log.warn("[apply][获取部门{{}}为空", value);
return "";
}
return dept.getName();
}
}