|
@@ -0,0 +1,711 @@
|
|
|
|
|
+package com.jtzx.crm.module.sys.service;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
|
|
+import cc.uncarbon.framework.core.exception.BusinessException;
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
|
+import com.jtzx.crm.module.sys.entity.*;
|
|
|
|
|
+import com.jtzx.crm.module.sys.mapper.*;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.response.BindUserBO;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.response.SelectBO;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.response.SysCustomerSelectBO;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Comparator;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 查询用户绑定的省市,小组数据
|
|
|
|
|
+ */
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class SysCustomerUserCommonService {
|
|
|
|
|
+
|
|
|
|
|
+ private final DictProvinceRegionMapper dictProvinceRegionMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final DictCityRegionMapper dictCityRegionMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final SysParamBaseDataMapper sysParamBaseDataMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final SysUserGroupRelationMapper sysUserGroupRelationMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final SysGroupMapper sysGroupMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final SysUserMapper sysUserMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final SysUserRoleRelationMapper sysUserRoleRelationMapper;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询当前用户绑定的城市id集合,已处理权限(公海列表,我的客户页面查询列表使用),这两页面不需要区分小组长
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<Long> queryUserCityIds(Long provinceId) {
|
|
|
|
|
+ List<Long> cityIds = Lists.newArrayList();
|
|
|
|
|
+ SysCustomerSelectBO selectBO = this.querySelectDataByType1(false, false);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(selectBO.getRegionData())) {
|
|
|
|
|
+ selectBO.getRegionData().stream()
|
|
|
|
|
+ .filter(x -> provinceId != null && provinceId.equals(x.getId()))
|
|
|
|
|
+ .forEach(provinceRegion ->
|
|
|
|
|
+ provinceRegion.getSubData()
|
|
|
|
|
+ .forEach(city -> cityIds.add(city.getId())));
|
|
|
|
|
+ }
|
|
|
|
|
+ return cityIds;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询当前用户绑定的城市id集合,已处理权限(客户跟进页面查询列表使用),这个页面需要区分小组长
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<Long> queryUserCityIds1(Long provinceId) {
|
|
|
|
|
+ List<Long> cityIds = Lists.newArrayList();
|
|
|
|
|
+ SysCustomerSelectBO selectBO = this.querySelectDataByType2(false, false);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(selectBO.getRegionData())) {
|
|
|
|
|
+ selectBO.getRegionData().stream()
|
|
|
|
|
+ .filter(x -> provinceId != null && provinceId.equals(x.getId()))
|
|
|
|
|
+ .forEach(provinceRegion ->
|
|
|
|
|
+ provinceRegion.getSubData()
|
|
|
|
|
+ .forEach(city -> cityIds.add(city.getId())));
|
|
|
|
|
+ }
|
|
|
|
|
+ return cityIds;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据当前用户的一个(多个)城市id查询小组组长或全部小组绑定的人员信息,这个是带权限的,小组组长(绑定的小组下面的所有成员)或者管理员(所有组下面的成员)
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<BindUserBO> queryBindUserListByCityId(List<Long> cityIds) {
|
|
|
|
|
+ //获取用户角色
|
|
|
|
|
+ List<String> roles = UserContextHolder.getUserContext().getRoles();
|
|
|
|
|
+ //管理员
|
|
|
|
|
+ if (roles.contains("Admin")) {
|
|
|
|
|
+ return this.queryBindUserListByCityIdOrGroupId(cityIds, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ //小组组长
|
|
|
|
|
+ if (roles.contains("GroupManager")) {
|
|
|
|
|
+ List<SysUserRoleRelationEntity> userRoleRelationEntities =
|
|
|
|
|
+ sysUserRoleRelationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserRoleRelationEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysUserRoleRelationEntity::getGroupId,
|
|
|
|
|
+ SysUserRoleRelationEntity::getUserId
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysUserRoleRelationEntity::getUserId, UserContextHolder.getUserId())
|
|
|
|
|
+ .eq(SysUserRoleRelationEntity::getRoleValue, "GroupManager")
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(userRoleRelationEntities)) {
|
|
|
|
|
+ List<Long> groupIds =
|
|
|
|
|
+ userRoleRelationEntities.stream().map(SysUserRoleRelationEntity::getGroupId)
|
|
|
|
|
+ .distinct().toList();
|
|
|
|
|
+ return this.queryBindUserListByCityIdOrGroupId(cityIds, groupIds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //普通成员
|
|
|
|
|
+ if (roles.contains("Member")) {
|
|
|
|
|
+ List<SysUserGroupRelationEntity> groupRelationEntityList =
|
|
|
|
|
+ sysUserGroupRelationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserGroupRelationEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysUserGroupRelationEntity::getId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getGroupId
|
|
|
|
|
+ )
|
|
|
|
|
+ .in(CollUtil.isNotEmpty(cityIds), SysUserGroupRelationEntity::getCityId, cityIds)
|
|
|
|
|
+ .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId())
|
|
|
|
|
+ .orderByAsc(SysUserGroupRelationEntity::getProvinceId)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(groupRelationEntityList)) {
|
|
|
|
|
+ List<Long> groupIds =
|
|
|
|
|
+ groupRelationEntityList.stream()
|
|
|
|
|
+ .map(SysUserGroupRelationEntity::getGroupId)
|
|
|
|
|
+ .distinct().toList();
|
|
|
|
|
+ return this.queryBindUserListByCityIdOrGroupId(cityIds, groupIds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据非当前用户一个(多个)城市id一个(多个)小组id查询绑定的人员信息,这个是不带权限的
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @param groupIds
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<BindUserBO> queryBindUserListByCityIdOrGroupId(List<Long> cityIds, List<Long> groupIds) {
|
|
|
|
|
+
|
|
|
|
|
+ List<SysUserGroupRelationEntity> groupRelationEntityList =
|
|
|
|
|
+ sysUserGroupRelationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserGroupRelationEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysUserGroupRelationEntity::getId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getGroupId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getProvinceId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getCityId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getUserId
|
|
|
|
|
+ )
|
|
|
|
|
+ .in(CollUtil.isNotEmpty(cityIds), SysUserGroupRelationEntity::getCityId, cityIds)
|
|
|
|
|
+ .in(CollUtil.isNotEmpty(groupIds), SysUserGroupRelationEntity::getGroupId, groupIds)
|
|
|
|
|
+ .orderByAsc(SysUserGroupRelationEntity::getProvinceId)
|
|
|
|
|
+ );
|
|
|
|
|
+ List<BindUserBO> resultData = Lists.newArrayList();
|
|
|
|
|
+ if (CollUtil.isNotEmpty(groupRelationEntityList)) {
|
|
|
|
|
+ List<Long> userIds =
|
|
|
|
|
+ groupRelationEntityList.stream()
|
|
|
|
|
+ .map(SysUserGroupRelationEntity::getUserId)
|
|
|
|
|
+ .distinct().toList();
|
|
|
|
|
+ List<SysUserEntity> sysUserEntityList =
|
|
|
|
|
+ sysUserMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysUserEntity::getId,
|
|
|
|
|
+ SysUserEntity::getUserName
|
|
|
|
|
+ )
|
|
|
|
|
+ .in(SysUserEntity::getId, userIds)
|
|
|
|
|
+ );
|
|
|
|
|
+ groupRelationEntityList.forEach(e -> {
|
|
|
|
|
+ if (CollUtil.isNotEmpty(sysUserEntityList)) {
|
|
|
|
|
+ sysUserEntityList.stream()
|
|
|
|
|
+ .filter(x -> x.getId().equals(e.getUserId()))
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .ifPresent(user -> {
|
|
|
|
|
+ BindUserBO bo = BindUserBO.builder().build();
|
|
|
|
|
+ bo.setId(user.getId());
|
|
|
|
|
+ bo.setUsername(user.getUserName());
|
|
|
|
|
+ bo.setProvinceId(e.getProvinceId());
|
|
|
|
|
+ bo.setCityId(e.getCityId());
|
|
|
|
|
+ bo.setGroupId(e.getGroupId());
|
|
|
|
|
+ resultData.add(bo);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return resultData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询顶部筛选条件的省,市,小组,人员数据,适用于公海客户,我的(私域)客户页面的顶部筛选条件的查询
|
|
|
|
|
+ * 根据身份权限查询用户的省市绑定用户信息(成员和小组组长权限相同),只区分管理员和非管理员权限
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public SysCustomerSelectBO querySelectDataByType1(Boolean allStatus, Boolean userStatus) {
|
|
|
|
|
+ //获取用户角色
|
|
|
|
|
+ List<String> roles = UserContextHolder.getUserContext().getRoles();
|
|
|
|
|
+ if (CollUtil.isEmpty(roles)) {
|
|
|
|
|
+ return SysCustomerSelectBO.builder().build();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> provinceIds = Lists.newArrayList();
|
|
|
|
|
+ List<Long> cityIds = Lists.newArrayList();
|
|
|
|
|
+ List<Long> groupIds = Lists.newArrayList();
|
|
|
|
|
+ //管理员
|
|
|
|
|
+ if (roles.contains("Admin")) {
|
|
|
|
|
+ return this.handleAdminRole(provinceIds, cityIds, groupIds, allStatus, userStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ //普通成员或小组组长
|
|
|
|
|
+ if (roles.contains("Member") || roles.contains("GroupManager")) {
|
|
|
|
|
+ return this.handleMemberRole(provinceIds, cityIds, groupIds, allStatus, userStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ return SysCustomerSelectBO.builder().build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询顶部筛选条件的省,市,小组,人员数据,适用于 客户跟进 页面的顶部筛选条件的查询
|
|
|
|
|
+ * 根据身份权限查询用户的省市绑定用户信息,区分管理员,小组组长,普通成员角色权限
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public SysCustomerSelectBO querySelectDataByType2(Boolean allStatus, Boolean userStatus) {
|
|
|
|
|
+ //获取用户角色
|
|
|
|
|
+ List<String> roles = UserContextHolder.getUserContext().getRoles();
|
|
|
|
|
+ if (CollUtil.isEmpty(roles)) {
|
|
|
|
|
+ throw new BusinessException(400, "无权查看");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> provinceIds = Lists.newArrayList();
|
|
|
|
|
+ List<Long> cityIds = Lists.newArrayList();
|
|
|
|
|
+ List<Long> groupIds = Lists.newArrayList();
|
|
|
|
|
+ //管理员
|
|
|
|
|
+ if (roles.contains("Admin")) {
|
|
|
|
|
+ return this.handleAdminRole(provinceIds, cityIds, groupIds, allStatus, userStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ //小组组长
|
|
|
|
|
+ if (roles.contains("GroupManager")) {
|
|
|
|
|
+ return this.handeGroupManagerRole(provinceIds, cityIds, allStatus, userStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ //普通成员
|
|
|
|
|
+ if (roles.contains("Member")) {
|
|
|
|
|
+ return this.handleMemberRole(provinceIds, cityIds, groupIds, allStatus, userStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ return SysCustomerSelectBO.builder().build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 学段信息
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<SelectBO> handleStageData() {
|
|
|
|
|
+ List<SelectBO> stageData = Lists.newArrayList();
|
|
|
|
|
+ //查询所有学段信息
|
|
|
|
|
+ List<SysParamBaseDataEntity> stageDataList = this.queryParamBaseData(0);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(stageDataList)) {
|
|
|
|
|
+ SelectBO all = SelectBO.builder().build();
|
|
|
|
|
+ all.setName("全部");
|
|
|
|
|
+ all.setSortCode(0);
|
|
|
|
|
+ all.setSelectStatus(true);
|
|
|
|
|
+ stageData.add(all);
|
|
|
|
|
+ stageDataList.forEach(e -> {
|
|
|
|
|
+ SelectBO bo = SelectBO.builder().build();
|
|
|
|
|
+ bo.setId(e.getId());
|
|
|
|
|
+ bo.setName(e.getTitle());
|
|
|
|
|
+ bo.setSortCode(e.getSortCode());
|
|
|
|
|
+ bo.setSelectStatus(false);
|
|
|
|
|
+ stageData.add(bo);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return stageData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 产品信息
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<SelectBO> handleProductData() {
|
|
|
|
|
+ List<SelectBO> stageData = Lists.newArrayList();
|
|
|
|
|
+ //查询所有学段信息
|
|
|
|
|
+ List<SysParamBaseDataEntity> stageDataList = this.queryParamBaseData(1);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(stageDataList)) {
|
|
|
|
|
+ SelectBO all = SelectBO.builder().build();
|
|
|
|
|
+ all.setName("全部");
|
|
|
|
|
+ all.setSortCode(0);
|
|
|
|
|
+ all.setSelectStatus(true);
|
|
|
|
|
+ stageData.add(all);
|
|
|
|
|
+ stageDataList.forEach(e -> {
|
|
|
|
|
+ SelectBO bo = SelectBO.builder().build();
|
|
|
|
|
+ bo.setId(e.getId());
|
|
|
|
|
+ bo.setName(e.getTitle());
|
|
|
|
|
+ bo.setSortCode(e.getSortCode());
|
|
|
|
|
+ bo.setSelectStatus(false);
|
|
|
|
|
+ stageData.add(bo);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return stageData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 类型信息,首单客户,存量客户
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<SelectBO> handleTypeData() {
|
|
|
|
|
+ List<SelectBO> typeData = Lists.newArrayList();
|
|
|
|
|
+ //查询所有类型信息
|
|
|
|
|
+ SelectBO all = SelectBO.builder().build();
|
|
|
|
|
+ all.setName("全部");
|
|
|
|
|
+ all.setSortCode(0);
|
|
|
|
|
+ all.setSelectStatus(true);
|
|
|
|
|
+ typeData.add(all);
|
|
|
|
|
+
|
|
|
|
|
+ SelectBO firstBO = SelectBO.builder().build();
|
|
|
|
|
+ firstBO.setId(1L);
|
|
|
|
|
+ firstBO.setName("首单客户");
|
|
|
|
|
+ firstBO.setSortCode(1);
|
|
|
|
|
+ firstBO.setSelectStatus(false);
|
|
|
|
|
+ typeData.add(firstBO);
|
|
|
|
|
+
|
|
|
|
|
+ SelectBO selectBO = SelectBO.builder().build();
|
|
|
|
|
+ selectBO.setId(2L);
|
|
|
|
|
+ selectBO.setName("存量客户");
|
|
|
|
|
+ selectBO.setSortCode(2);
|
|
|
|
|
+ selectBO.setSelectStatus(false);
|
|
|
|
|
+ typeData.add(selectBO);
|
|
|
|
|
+ return typeData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理管理员角色
|
|
|
|
|
+ * @param provinceIds
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @param groupIds
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public SysCustomerSelectBO handleAdminRole(List<Long> provinceIds,
|
|
|
|
|
+ List<Long> cityIds,
|
|
|
|
|
+ List<Long> groupIds,
|
|
|
|
|
+ Boolean allStatus,
|
|
|
|
|
+ Boolean userStatus) {
|
|
|
|
|
+
|
|
|
|
|
+ List<DictProvinceRegionEntity> provinceRegionEntityList =
|
|
|
|
|
+ dictProvinceRegionMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(DictProvinceRegionEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ DictProvinceRegionEntity::getId,
|
|
|
|
|
+ DictProvinceRegionEntity::getCode
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(DictProvinceRegionEntity::getUseStatus, 1)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(provinceRegionEntityList)) {
|
|
|
|
|
+ this.handleAdmin(provinceRegionEntityList, provinceIds, cityIds, groupIds);
|
|
|
|
|
+ return this.handleResultData(provinceIds, cityIds, groupIds, allStatus, userStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ return SysCustomerSelectBO.builder().build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理小组组长角色
|
|
|
|
|
+ * @param provinceIds
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public SysCustomerSelectBO handeGroupManagerRole(List<Long> provinceIds,
|
|
|
|
|
+ List<Long> cityIds,
|
|
|
|
|
+ Boolean allStatus,
|
|
|
|
|
+ Boolean userStatus) {
|
|
|
|
|
+ List<SysUserRoleRelationEntity> groupManagerRelationEntityList =
|
|
|
|
|
+ sysUserRoleRelationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserRoleRelationEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysUserRoleRelationEntity::getUserId,
|
|
|
|
|
+ SysUserRoleRelationEntity::getGroupId
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysUserRoleRelationEntity::getUserId, UserContextHolder.getUserId())//当前登陆的用户id
|
|
|
|
|
+ .eq(SysUserRoleRelationEntity::getRoleValue, "GroupManager")
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(groupManagerRelationEntityList)) {
|
|
|
|
|
+ List<Long> groupIds =
|
|
|
|
|
+ groupManagerRelationEntityList.stream()
|
|
|
|
|
+ .map(SysUserRoleRelationEntity::getGroupId)
|
|
|
|
|
+ .distinct().toList();
|
|
|
|
|
+ //开通的省市都有相同的小组,所有这里查询开通的省市查询使用管理员的查询
|
|
|
|
|
+ return this.handleAdminRole(provinceIds, cityIds, groupIds, allStatus, userStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ return SysCustomerSelectBO.builder().build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理普通成员角色
|
|
|
|
|
+ * @param provinceIds
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @param groupIds
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public SysCustomerSelectBO handleMemberRole(List<Long> provinceIds,
|
|
|
|
|
+ List<Long> cityIds,
|
|
|
|
|
+ List<Long> groupIds,
|
|
|
|
|
+ Boolean allStatus,
|
|
|
|
|
+ Boolean userStatus) {
|
|
|
|
|
+ List<SysUserGroupRelationEntity> userGroupRelationEntityList =
|
|
|
|
|
+ sysUserGroupRelationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserGroupRelationEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysUserGroupRelationEntity::getGroupId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getProvinceId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getCityId
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysUserGroupRelationEntity::getUserId, UserContextHolder.getUserId()) //当前登陆的用户id
|
|
|
|
|
+ .orderByAsc(SysUserGroupRelationEntity::getProvinceId)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(userGroupRelationEntityList)) {
|
|
|
|
|
+ this.handleMemberData(userGroupRelationEntityList, provinceIds, cityIds, groupIds);
|
|
|
|
|
+ return this.handleResultData(provinceIds, cityIds, groupIds, allStatus, userStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ return SysCustomerSelectBO.builder().build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理省市和和成员,小组
|
|
|
|
|
+ * @param provinceIds
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @param groupIds
|
|
|
|
|
+ */
|
|
|
|
|
+ public SysCustomerSelectBO handleResultData(List<Long> provinceIds,
|
|
|
|
|
+ List<Long> cityIds,
|
|
|
|
|
+ List<Long> groupIds,
|
|
|
|
|
+ Boolean allStatus, Boolean userStatus) {
|
|
|
|
|
+
|
|
|
|
|
+ SysCustomerSelectBO selectBO = SysCustomerSelectBO.builder().build();
|
|
|
|
|
+ //小组
|
|
|
|
|
+ selectBO.setGroupData(this.handeGroupData(groupIds, allStatus));
|
|
|
|
|
+
|
|
|
|
|
+ List<SysUserEntity> userEntityList =
|
|
|
|
|
+ sysUserMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserEntity.class)
|
|
|
|
|
+ .eq(SysUserEntity::getStatus, 1)
|
|
|
|
|
+ );
|
|
|
|
|
+ //省市
|
|
|
|
|
+ List<SelectBO> regionData = this.handleRegionData(provinceIds, cityIds, allStatus);
|
|
|
|
|
+ //省市
|
|
|
|
|
+ selectBO.setRegionData(regionData);
|
|
|
|
|
+ //成员
|
|
|
|
|
+ List<BindUserBO> userData = Lists.newArrayList();
|
|
|
|
|
+
|
|
|
|
|
+ List<SysUserGroupRelationEntity> groupRelationEntityList =
|
|
|
|
|
+ sysUserGroupRelationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserGroupRelationEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysUserGroupRelationEntity::getGroupId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getProvinceId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getCityId,
|
|
|
|
|
+ SysUserGroupRelationEntity::getUserId
|
|
|
|
|
+ )
|
|
|
|
|
+ .in(SysUserGroupRelationEntity::getProvinceId, provinceIds)
|
|
|
|
|
+ .in(SysUserGroupRelationEntity::getCityId, cityIds)
|
|
|
|
|
+ .orderByAsc(SysUserGroupRelationEntity::getProvinceId)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (userStatus) {
|
|
|
|
|
+ regionData.forEach(province ->
|
|
|
|
|
+ province.getSubData().forEach(city -> {
|
|
|
|
|
+ if (CollUtil.isNotEmpty(groupIds) && CollUtil.isNotEmpty(groupRelationEntityList)) {
|
|
|
|
|
+
|
|
|
|
|
+ groupRelationEntityList.stream()
|
|
|
|
|
+ .filter(x -> x.getProvinceId().equals(province.getId()))
|
|
|
|
|
+ .filter(x -> x.getCityId().equals(city.getId()))
|
|
|
|
|
+ .filter(x -> CollUtil.isNotEmpty(groupIds) && groupIds.contains(x.getGroupId()))
|
|
|
|
|
+ .sorted(Comparator.comparing(SysUserGroupRelationEntity::getCreatedAt))
|
|
|
|
|
+ .collect(Collectors.groupingBy(SysUserGroupRelationEntity::getGroupId, LinkedHashMap::new, Collectors.toList()))
|
|
|
|
|
+ .forEach((key, value) -> {
|
|
|
|
|
+ if (allStatus) {
|
|
|
|
|
+ BindUserBO userBO = BindUserBO.builder().build();
|
|
|
|
|
+ userBO.setProvinceId(province.getId());
|
|
|
|
|
+ userBO.setCityId(city.getId());
|
|
|
|
|
+ userBO.setGroupId(key);
|
|
|
|
|
+ userBO.setUsername("全部");
|
|
|
|
|
+ userBO.setSortCode(0);
|
|
|
|
|
+ userBO.setSelectStatus(true);
|
|
|
|
|
+ userData.add(userBO);
|
|
|
|
|
+ }
|
|
|
|
|
+ AtomicInteger sortCode = new AtomicInteger(0);
|
|
|
|
|
+ value.forEach(user -> {
|
|
|
|
|
+ if (CollUtil.isNotEmpty(userEntityList)) {
|
|
|
|
|
+ userEntityList.stream()
|
|
|
|
|
+ .filter(x -> x.getId().equals(user.getUserId()))
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .ifPresent(e -> {
|
|
|
|
|
+ BindUserBO userBO = BindUserBO.builder().build();
|
|
|
|
|
+ userBO.setId(user.getUserId());
|
|
|
|
|
+ userBO.setProvinceId(user.getProvinceId());
|
|
|
|
|
+ userBO.setCityId(user.getCityId());
|
|
|
|
|
+ userBO.setGroupId(user.getGroupId());
|
|
|
|
|
+ userBO.setUsername(e.getUserName());
|
|
|
|
|
+ userBO.setSelectStatus(false);
|
|
|
|
|
+ userBO.setSortCode(sortCode.incrementAndGet());
|
|
|
|
|
+ userData.add(userBO);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+ selectBO.setMemberData(userData);
|
|
|
|
|
+ return selectBO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理普通成员数据
|
|
|
|
|
+ * @param provinceIds
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @param groupIds
|
|
|
|
|
+ */
|
|
|
|
|
+ public void handleMemberData(List<SysUserGroupRelationEntity> userGroupRelationEntityList,
|
|
|
|
|
+ List<Long> provinceIds,
|
|
|
|
|
+ List<Long> cityIds,
|
|
|
|
|
+ List<Long> groupIds) {
|
|
|
|
|
+
|
|
|
|
|
+ //普通成员没有配置小组,所有的id集合都是空
|
|
|
|
|
+ if (CollUtil.isNotEmpty(userGroupRelationEntityList)) {
|
|
|
|
|
+ if (provinceIds != null) {
|
|
|
|
|
+ provinceIds.addAll(
|
|
|
|
|
+ userGroupRelationEntityList.stream()
|
|
|
|
|
+ .map(SysUserGroupRelationEntity::getProvinceId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct().toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (cityIds != null) {
|
|
|
|
|
+ cityIds.addAll(
|
|
|
|
|
+ userGroupRelationEntityList.stream()
|
|
|
|
|
+ .map(SysUserGroupRelationEntity::getCityId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct().toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (groupIds != null) {
|
|
|
|
|
+ groupIds.addAll(
|
|
|
|
|
+ userGroupRelationEntityList.stream()
|
|
|
|
|
+ .map(SysUserGroupRelationEntity::getGroupId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .distinct().toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理管理员角色数据
|
|
|
|
|
+ * @param provinceIds
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @param groupIds
|
|
|
|
|
+ */
|
|
|
|
|
+ public void handleAdmin(List<DictProvinceRegionEntity> provinceRegionEntityList,
|
|
|
|
|
+ List<Long> provinceIds,
|
|
|
|
|
+ List<Long> cityIds,
|
|
|
|
|
+ List<Long> groupIds) {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //如果没有添加小组,管理员查询,可能小组id也为空
|
|
|
|
|
+ if (groupIds != null) {
|
|
|
|
|
+ List<SysGroupEntity> groupEntityList = sysGroupMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysGroupEntity.class)
|
|
|
|
|
+ .orderByAsc(SysGroupEntity::getSortCode)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(groupEntityList)) {
|
|
|
|
|
+ groupIds.addAll(
|
|
|
|
|
+ groupEntityList.stream().map(SysGroupEntity::getId).toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> provinceCodes = provinceRegionEntityList.stream()
|
|
|
|
|
+ .map(DictProvinceRegionEntity::getCode).toList();
|
|
|
|
|
+ if (provinceIds != null) {
|
|
|
|
|
+ provinceIds.addAll(provinceRegionEntityList.stream()
|
|
|
|
|
+ .map(DictProvinceRegionEntity::getId).toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<DictCityRegionEntity> cityRegionEntityList =
|
|
|
|
|
+ dictCityRegionMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(DictCityRegionEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ DictCityRegionEntity::getId
|
|
|
|
|
+ )
|
|
|
|
|
+ .in(DictCityRegionEntity::getParentCode, provinceCodes)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (cityIds != null) {
|
|
|
|
|
+ cityIds.addAll(cityRegionEntityList.stream()
|
|
|
|
|
+ .map(DictCityRegionEntity::getId).toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理小组
|
|
|
|
|
+ * @param groupIds
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<SelectBO> handeGroupData(List<Long> groupIds,
|
|
|
|
|
+ Boolean allStatus) {
|
|
|
|
|
+ List<SelectBO> groupData = Lists.newArrayList();
|
|
|
|
|
+ //小组
|
|
|
|
|
+ if (CollUtil.isNotEmpty(groupIds)) {
|
|
|
|
|
+ if (allStatus) {
|
|
|
|
|
+ SelectBO selectBO = SelectBO.builder()
|
|
|
|
|
+ .name("全部")
|
|
|
|
|
+ .sortCode(0)
|
|
|
|
|
+ .selectStatus(true)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ groupData.add(selectBO);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<SysGroupEntity> groupEntityList = sysGroupMapper.selectByIds(groupIds);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(groupEntityList)) {
|
|
|
|
|
+ groupEntityList.stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(SysGroupEntity::getSortCode))
|
|
|
|
|
+ .forEach(group -> {
|
|
|
|
|
+ SelectBO groupBO = SelectBO.builder().build();
|
|
|
|
|
+ groupBO.setId(group.getId());
|
|
|
|
|
+ groupBO.setName(group.getTitle());
|
|
|
|
|
+ groupBO.setSortCode(group.getSortCode());
|
|
|
|
|
+ groupBO.setSelectStatus(false);
|
|
|
|
|
+ groupData.add(groupBO);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return groupData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理省市
|
|
|
|
|
+ * @param provinceIds
|
|
|
|
|
+ * @param cityIds
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<SelectBO> handleRegionData(List<Long> provinceIds,
|
|
|
|
|
+ List<Long> cityIds,
|
|
|
|
|
+ Boolean allStatus) {
|
|
|
|
|
+ List<SelectBO> regionData = Lists.newArrayList();
|
|
|
|
|
+ //省份
|
|
|
|
|
+ List<DictProvinceRegionEntity> regionEntityList = dictProvinceRegionMapper.selectByIds(provinceIds);
|
|
|
|
|
+ //城市
|
|
|
|
|
+ List<DictCityRegionEntity> dictCityRegionEntities = dictCityRegionMapper.selectByIds(cityIds);
|
|
|
|
|
+ regionEntityList.stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(DictProvinceRegionEntity::getSortCode))
|
|
|
|
|
+ .forEach(province -> {
|
|
|
|
|
+ SelectBO selectBO = SelectBO.builder()
|
|
|
|
|
+ .name("全部")
|
|
|
|
|
+ .sortCode(0)
|
|
|
|
|
+ .selectStatus(true)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ if (allStatus) {
|
|
|
|
|
+ regionData.add(selectBO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SelectBO provinceBO = SelectBO.builder().build();
|
|
|
|
|
+ provinceBO.setId(province.getId());
|
|
|
|
|
+ provinceBO.setName(province.getName());
|
|
|
|
|
+ provinceBO.setSortCode(province.getSortCode());
|
|
|
|
|
+ provinceBO.setSelectStatus(false);
|
|
|
|
|
+ List<SelectBO> subData = Lists.newArrayList();
|
|
|
|
|
+ AtomicInteger sortCode = new AtomicInteger(0);
|
|
|
|
|
+ dictCityRegionEntities.stream()
|
|
|
|
|
+ .filter(x -> x.getParentCode().equals(province.getCode()))
|
|
|
|
|
+ .sorted(Comparator.comparing(DictCityRegionEntity::getCode))
|
|
|
|
|
+ .forEach(city -> {
|
|
|
|
|
+ if (allStatus) {
|
|
|
|
|
+ subData.add(selectBO);
|
|
|
|
|
+ }
|
|
|
|
|
+ SelectBO cityBo = SelectBO.builder().build();
|
|
|
|
|
+ cityBo.setId(city.getId());
|
|
|
|
|
+ cityBo.setName(city.getName());
|
|
|
|
|
+ cityBo.setSortCode(sortCode.incrementAndGet());
|
|
|
|
|
+ cityBo.setSelectStatus(false);
|
|
|
|
|
+ subData.add(cityBo);
|
|
|
|
|
+ });
|
|
|
|
|
+ provinceBO.setSubData(subData);
|
|
|
|
|
+ regionData.add(provinceBO);
|
|
|
|
|
+ });
|
|
|
|
|
+ return regionData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询参数配置的基础信息数据
|
|
|
|
|
+ * @param type 类型:0-学段,1-产品,2-职务,3-跟进
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<SysParamBaseDataEntity> queryParamBaseData(Integer type) {
|
|
|
|
|
+ //查询所有在基础配置信息
|
|
|
|
|
+ return
|
|
|
|
|
+ sysParamBaseDataMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysParamBaseDataEntity.class)
|
|
|
|
|
+ .select(
|
|
|
|
|
+ SysParamBaseDataEntity::getId,
|
|
|
|
|
+ SysParamBaseDataEntity::getTitle
|
|
|
|
|
+ )
|
|
|
|
|
+ .eq(SysParamBaseDataEntity::getType, type)
|
|
|
|
|
+ .orderByAsc(SysParamBaseDataEntity::getSortCode)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+}
|