mirror of
https://github.com/1Panel-dev/CordysCRM.git
synced 2026-05-24 03:38:42 +08:00
refactor: personal add module judgement
This commit is contained in:
@@ -30,4 +30,10 @@ public class CustomerRepeatResponse {
|
||||
@Schema(description = "商机重复数据数量")
|
||||
private int opportunityCount;
|
||||
|
||||
@Schema(description = "线索模块是否开启")
|
||||
private boolean clueModuleEnable;
|
||||
|
||||
@Schema(description = "商机模块是否开启")
|
||||
private boolean opportunityModuleEnable;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ import io.cordys.common.exception.IResultCode;
|
||||
public enum SystemResultCode implements IResultCode {
|
||||
|
||||
ROLE_EXIST(101001, "role.exist"),
|
||||
INTERNAL_ROLE_PERMISSION(101002, "internal.role.permission.error");
|
||||
INTERNAL_ROLE_PERMISSION(101002, "internal.role.permission.error"),
|
||||
MODULE_ENABLE(101003, "internal.role.permission.error");
|
||||
|
||||
|
||||
private final int code;
|
||||
|
||||
@@ -2,18 +2,22 @@ package io.cordys.crm.system.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.cordys.common.constants.InternalUser;
|
||||
import io.cordys.common.constants.ModuleKey;
|
||||
import io.cordys.common.constants.PermissionConstants;
|
||||
import io.cordys.common.exception.GenericException;
|
||||
import io.cordys.common.pager.PageUtils;
|
||||
import io.cordys.common.pager.Pager;
|
||||
import io.cordys.common.pager.PagerWithOption;
|
||||
import io.cordys.context.OrganizationContext;
|
||||
import io.cordys.crm.clue.dto.response.ClueListResponse;
|
||||
import io.cordys.crm.clue.dto.response.ClueRepeatListResponse;
|
||||
import io.cordys.crm.customer.dto.response.CustomerRepeatResponse;
|
||||
import io.cordys.crm.follow.dto.request.FollowUpPlanPageRequest;
|
||||
import io.cordys.crm.follow.dto.response.FollowUpPlanListResponse;
|
||||
import io.cordys.crm.follow.service.FollowUpPlanService;
|
||||
import io.cordys.crm.opportunity.dto.response.OpportunityRepeatResponse;
|
||||
import io.cordys.crm.system.constants.SystemResultCode;
|
||||
import io.cordys.crm.system.domain.Module;
|
||||
import io.cordys.crm.system.dto.request.PersonalInfoRequest;
|
||||
import io.cordys.crm.system.dto.request.PersonalPasswordRequest;
|
||||
import io.cordys.crm.system.dto.request.RepeatCustomerDetailPageRequest;
|
||||
@@ -21,11 +25,15 @@ import io.cordys.crm.system.dto.request.RepeatCustomerPageRequest;
|
||||
import io.cordys.crm.system.dto.response.UserResponse;
|
||||
import io.cordys.crm.system.mapper.ExtUserRoleMapper;
|
||||
import io.cordys.crm.system.service.PersonalCenterService;
|
||||
import io.cordys.mybatis.BaseMapper;
|
||||
import io.cordys.mybatis.lambda.LambdaQueryWrapper;
|
||||
import io.cordys.security.SessionUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -48,14 +56,22 @@ public class PersonalCenterController {
|
||||
@Resource
|
||||
private ExtUserRoleMapper extUserRoleMapper;
|
||||
|
||||
@Resource
|
||||
private BaseMapper<Module> moduleMapper;
|
||||
|
||||
|
||||
@PostMapping("/repeat/customer")
|
||||
@Operation(summary = "获取重复客户相关数据")
|
||||
@RequiresPermissions(value = {PermissionConstants.CUSTOMER_MANAGEMENT_READ, PermissionConstants.OPPORTUNITY_MANAGEMENT_READ, PermissionConstants.CLUE_MANAGEMENT_READ}, logical = Logical.OR)
|
||||
public Pager<List<CustomerRepeatResponse>> getRepeatCustomer(@Validated @RequestBody RepeatCustomerPageRequest request) {
|
||||
List<String> permissions = extUserRoleMapper.selectPermissionsByUserId(SessionUtils.getUserId());
|
||||
LambdaQueryWrapper<Module> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(Module::getOrganizationId, OrganizationContext.getOrganizationId());
|
||||
queryWrapper.eq(Module::getEnable, true);
|
||||
List<Module> modules = moduleMapper.selectListByLambda(queryWrapper);
|
||||
List<String> keyList = modules.stream().map(Module::getModuleKey).toList();
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize());
|
||||
return PageUtils.setPageInfo(page, personalCenterService.getRepeatCustomer(request,permissions,OrganizationContext.getOrganizationId(), SessionUtils.getUserId()));
|
||||
return PageUtils.setPageInfo(page, personalCenterService.getRepeatCustomer(request,permissions,keyList,OrganizationContext.getOrganizationId(), SessionUtils.getUserId()));
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +79,19 @@ public class PersonalCenterController {
|
||||
@Operation(summary = "获取重复线索相关数据")
|
||||
@RequiresPermissions(value = {PermissionConstants.CLUE_MANAGEMENT_READ})
|
||||
public Pager<List<ClueRepeatListResponse>> getRepeatClue(@Validated @RequestBody RepeatCustomerPageRequest request) {
|
||||
List<String> permissions = extUserRoleMapper.selectPermissionsByUserId(SessionUtils.getUserId());
|
||||
LambdaQueryWrapper<Module> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(Module::getOrganizationId, OrganizationContext.getOrganizationId());
|
||||
queryWrapper.eq(Module::getEnable, true);
|
||||
queryWrapper.eq(Module::getModuleKey, ModuleKey.CLUE.getKey());
|
||||
List<Module> modules = moduleMapper.selectListByLambda(queryWrapper);
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize());
|
||||
return PageUtils.setPageInfo(page, personalCenterService.getRepeatClue(request,OrganizationContext.getOrganizationId()));
|
||||
//模块关闭,但是有权限,返回指定code
|
||||
if ((permissions.indexOf(PermissionConstants.CLUE_MANAGEMENT_READ) > 0 || StringUtils.equalsIgnoreCase(SessionUtils.getUserId(), InternalUser.ADMIN.getValue()) && CollectionUtils.isEmpty(modules))) {
|
||||
throw new GenericException(SystemResultCode.MODULE_ENABLE);
|
||||
}else {
|
||||
return PageUtils.setPageInfo(page, personalCenterService.getRepeatClue(request,OrganizationContext.getOrganizationId()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.cordys.aspectj.constants.LogType;
|
||||
import io.cordys.aspectj.context.OperationLogContext;
|
||||
import io.cordys.aspectj.dto.LogContextInfo;
|
||||
import io.cordys.common.constants.InternalUser;
|
||||
import io.cordys.common.constants.ModuleKey;
|
||||
import io.cordys.common.constants.PermissionConstants;
|
||||
import io.cordys.common.dto.OptionCountDTO;
|
||||
import io.cordys.common.dto.OptionDTO;
|
||||
@@ -19,6 +20,8 @@ import io.cordys.crm.customer.mapper.ExtCustomerMapper;
|
||||
import io.cordys.crm.opportunity.dto.response.OpportunityRepeatResponse;
|
||||
import io.cordys.crm.opportunity.mapper.ExtOpportunityMapper;
|
||||
import io.cordys.crm.system.constants.RepeatType;
|
||||
import io.cordys.crm.system.constants.SystemResultCode;
|
||||
import io.cordys.crm.system.domain.Module;
|
||||
import io.cordys.crm.system.domain.Product;
|
||||
import io.cordys.crm.system.domain.User;
|
||||
import io.cordys.crm.system.dto.request.PersonalInfoRequest;
|
||||
@@ -31,6 +34,7 @@ import io.cordys.crm.system.mapper.ExtProductMapper;
|
||||
import io.cordys.crm.system.mapper.ExtUserMapper;
|
||||
import io.cordys.crm.system.utils.MailSender;
|
||||
import io.cordys.mybatis.BaseMapper;
|
||||
import io.cordys.mybatis.lambda.LambdaQueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -167,20 +171,25 @@ public class PersonalCenterService {
|
||||
return userDetail;
|
||||
}
|
||||
|
||||
public List<CustomerRepeatResponse> getRepeatCustomer(RepeatCustomerPageRequest request, List<String> permissions, String organizationId, String userId) {
|
||||
public List<CustomerRepeatResponse> getRepeatCustomer(RepeatCustomerPageRequest request, List<String> permissions, List<String> keyList, String organizationId, String userId) {
|
||||
//模块关闭,但是有权限,返回指定code
|
||||
if ((permissions.indexOf(PermissionConstants.CUSTOMER_MANAGEMENT_READ) > 0 || StringUtils.equalsIgnoreCase(userId, InternalUser.ADMIN.getValue()) && !keyList.contains(ModuleKey.CUSTOMER.getKey()))) {
|
||||
throw new GenericException(SystemResultCode.MODULE_ENABLE);
|
||||
}
|
||||
//1.查询当前用户权限
|
||||
List<CustomerRepeatResponse> customers;
|
||||
if (permissions.indexOf(PermissionConstants.CUSTOMER_MANAGEMENT_READ) > 0 || StringUtils.equalsIgnoreCase(userId, InternalUser.ADMIN.getValue())) {
|
||||
customers = extCustomerMapper.checkRepeatCustomerByName(request.getName(), organizationId);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<CustomerRepeatResponse> customers = extCustomerMapper.checkRepeatCustomerByName(request.getName(), organizationId);
|
||||
|
||||
//查商机
|
||||
Map<String, String> repeatCountMap = new HashMap<>();
|
||||
if (permissions.indexOf(PermissionConstants.OPPORTUNITY_MANAGEMENT_READ) > 0 || StringUtils.equalsIgnoreCase(userId, InternalUser.ADMIN.getValue())) {
|
||||
if (CollectionUtils.isNotEmpty(customers)) {
|
||||
List<String> customerIds = customers.stream().map(CustomerRepeatResponse::getId).collect(Collectors.toList());
|
||||
List<OptionDTO> repeatCountDTOList = extOpportunityMapper.getRepeatCountMap(customerIds);
|
||||
repeatCountMap = repeatCountDTOList.stream().collect(Collectors.toMap(OptionDTO::getId,OptionDTO::getName));
|
||||
repeatCountMap = repeatCountDTOList.stream().collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,9 +199,12 @@ public class PersonalCenterService {
|
||||
if (CollectionUtils.isNotEmpty(customers)) {
|
||||
List<String> customerNames = customers.stream().map(CustomerRepeatResponse::getName).collect(Collectors.toList());
|
||||
List<OptionDTO> repeatCountDTOList = extClueMapper.getRepeatCountMap(customerNames);
|
||||
clueRepeatCountMap = repeatCountDTOList.stream().collect(Collectors.toMap(OptionDTO::getId,OptionDTO::getName));
|
||||
clueRepeatCountMap = repeatCountDTOList.stream().collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName));
|
||||
}
|
||||
}
|
||||
boolean clueModuleEnable = keyList.contains(ModuleKey.CLUE.getKey());
|
||||
|
||||
boolean opportunityModuleEnable = keyList.contains(ModuleKey.BUSINESS.getKey());
|
||||
|
||||
for (CustomerRepeatResponse customer : customers) {
|
||||
if (StringUtils.equalsIgnoreCase(customer.getName(), request.getName())) {
|
||||
@@ -205,6 +217,9 @@ public class PersonalCenterService {
|
||||
customer.setOpportunityCount(Integer.parseInt(StringUtils.isBlank(opportunity) ? "0" : opportunity));
|
||||
String clue = clueRepeatCountMap.get(customer.getName());
|
||||
customer.setClueCount(Integer.parseInt(StringUtils.isBlank(clue) ? "0" : clue));
|
||||
customer.setOpportunityModuleEnable(opportunityModuleEnable);
|
||||
customer.setClueModuleEnable(clueModuleEnable);
|
||||
|
||||
}
|
||||
return customers;
|
||||
}
|
||||
|
||||
@@ -109,6 +109,8 @@ module.form.not_exist=Module form does not exist
|
||||
module.form.business_field.deleted=Form business fields cannot be deleted
|
||||
module.field.not_exist=Module field does not exist
|
||||
module.field.not_match_type=Mismatched field types
|
||||
module.has.closed=Module is closed
|
||||
|
||||
|
||||
# permission name
|
||||
permission.system.name=System
|
||||
|
||||
@@ -110,6 +110,8 @@ module.form.not_exist=模块表单不存在
|
||||
module.form.business_field.deleted=表单业务字段无法删除
|
||||
module.field.not_exist=字段不存在
|
||||
module.field.not_match_type=不匹配的字段类型
|
||||
module.has.closed=模块已关闭
|
||||
|
||||
|
||||
# permission name
|
||||
permission.system.name=系统管理
|
||||
|
||||
Reference in New Issue
Block a user