找人,找意向区域
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.cool.store.enums;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* describe:
|
||||
*
|
||||
* @author zhouyiping
|
||||
* @date 2020/10/13
|
||||
*/
|
||||
public enum AuthRoleEnum {
|
||||
/**
|
||||
* 全企业数据
|
||||
*/
|
||||
ALL("all", "全企业数据"),
|
||||
|
||||
/**
|
||||
* 所在组织架构包含下级
|
||||
*/
|
||||
INCLUDE_SUBORDINATE("include_subordinate","所在组织架构包含下级"),
|
||||
|
||||
|
||||
// /**
|
||||
// * 所在的组织架构不包含下级
|
||||
// */
|
||||
NOT_INCLUDE_SUBORDINATE("not_include_subordinate","所在的组织架构不包含下级"),
|
||||
|
||||
/**
|
||||
* 仅自己的数据
|
||||
*/
|
||||
PERSONAL("personal","仅自己的数据");
|
||||
|
||||
private String code;
|
||||
private String msg;
|
||||
|
||||
protected static final Map<String, AuthRoleEnum> map = Arrays.stream(values()).collect(
|
||||
Collectors.toMap(AuthRoleEnum::getCode, Function.identity()));
|
||||
|
||||
AuthRoleEnum(String code, String msg){
|
||||
this.code=code;
|
||||
this.msg=msg;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
public static AuthRoleEnum getByCode(String code) {
|
||||
return map.get(code);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.cool.store.enums;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author zyp
|
||||
*/
|
||||
public enum UserAuthMappingTypeEnum {
|
||||
/**
|
||||
* 区域
|
||||
*/
|
||||
REGION("region","区域"),
|
||||
/**
|
||||
* 门店
|
||||
*/
|
||||
STORE("store","门店");
|
||||
|
||||
private String code;
|
||||
private String desc;
|
||||
public static final Map<String, UserAuthMappingTypeEnum> map = Arrays.stream(values()).collect(
|
||||
Collectors.toMap(UserAuthMappingTypeEnum::getCode, Function.identity()));
|
||||
|
||||
UserAuthMappingTypeEnum(String code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static UserAuthMappingTypeEnum getByCode(String code) {
|
||||
return map.get(code);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,13 @@ public class RegionAreaConfigDao {
|
||||
regionAreaConfigMapper.deleteRegionAreaConfigByRegionId(regionId);
|
||||
}
|
||||
|
||||
public void deleteByWantShopAreaIds(List<Long> wantShopAreaIds) {
|
||||
if (CollectionUtils.isEmpty(wantShopAreaIds)) {
|
||||
return;
|
||||
}
|
||||
regionAreaConfigMapper.deleteByWantShopAreaIds(wantShopAreaIds);
|
||||
}
|
||||
|
||||
public void batchInsertOrUpdateRegionAreaConfig(List<RegionAreaConfigDO> regionAreaConfigList) {
|
||||
if (CollectionUtils.isEmpty(regionAreaConfigList)) {
|
||||
return;
|
||||
@@ -41,6 +48,13 @@ public class RegionAreaConfigDao {
|
||||
return regionAreaConfigMapper.listAreaByRegionId(regionId);
|
||||
}
|
||||
|
||||
public List<RegionAreaConfigDO> listAreaByRegionIdList(List<Long> regionIdList){
|
||||
if (CollectionUtils.isEmpty(regionIdList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return regionAreaConfigMapper.listAreaByRegionIdList(regionIdList);
|
||||
}
|
||||
|
||||
public Long getByWantShopAreaId(Long wantShopAreaId){
|
||||
if (wantShopAreaId == null) {
|
||||
return 0L;
|
||||
|
||||
@@ -41,10 +41,15 @@ public interface RegionAreaConfigMapper {
|
||||
|
||||
void deleteRegionAreaConfigByRegionId(@Param("regionId") Long regionId);
|
||||
|
||||
void deleteByWantShopAreaIds(@Param("wantShopAreaIds") List<Long> wantShopAreaIds);
|
||||
|
||||
void batchInsertOrUpdateRegionAreaConfig(@Param("regionAreaConfigList") List<RegionAreaConfigDO> regionAreaConfigList);
|
||||
|
||||
List<RegionAreaConfigDO> listAreaByRegionId(@Param("regionId") Long regionId);
|
||||
|
||||
Long getByWantShopAreaId(@Param("wantShopAreaId") Long wantShopAreaId);
|
||||
|
||||
List<RegionAreaConfigDO> listAreaByRegionIdList(@Param("regionIdList") List<Long> regionIdList);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.cool.store.mapper;
|
||||
|
||||
import com.cool.store.entity.UserAuthMappingDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 人员权限映射表
|
||||
*
|
||||
* @author zyp
|
||||
* @Description 人员权限映射
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserAuthMappingMapper {
|
||||
|
||||
/**
|
||||
* 根据UserId获取权限
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<UserAuthMappingDO> listUserAuthMappingByUserId(@Param("userId") String userId);
|
||||
|
||||
/**
|
||||
* 根据UserId和权限来源获取权限
|
||||
|
||||
* @param userId
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
List<UserAuthMappingDO> listByUserIdAndSource( @Param("userId") String userId, @Param("source") String source);
|
||||
/**
|
||||
* 查询用户区域
|
||||
|
||||
* @param userList
|
||||
* @return
|
||||
*/
|
||||
List<UserAuthMappingDO> listUserAuthMappingByUserIdList(@Param("userList") List<String> userList);
|
||||
|
||||
List<UserAuthMappingDO> listUserAuthMappingByMappingList(@Param("mappingIdList") List<String> mappingIdList,
|
||||
@Param("type") String type);
|
||||
|
||||
/**
|
||||
*查询不包含可视化范围的区域人员
|
||||
|
||||
* @param mappingIdList
|
||||
* @return
|
||||
*/
|
||||
List<UserAuthMappingDO> listUserAuthMappingByAuth(@Param("type") String type,
|
||||
@Param("mappingIdList") List<String> mappingIdList,
|
||||
@Param("positionType")String positionType,
|
||||
@Param("notRoleAuth")String notRoleAuth);
|
||||
|
||||
|
||||
List<UserAuthMappingDO> listUserAuthMappingByUserList(@Param("userIdList") List<String> userIdList);
|
||||
|
||||
|
||||
List<UserAuthMappingDO> listUserAuthMappingByUserAndType(@Param("userId") String userId,
|
||||
@Param("type") String type);
|
||||
/**
|
||||
* 根据用户id获得权限映射信息主键列表
|
||||
|
||||
* @param userId
|
||||
* @return: java.util.List<java.lang.Long>
|
||||
* @Author: xugangkun
|
||||
* @Date: 2021/3/25 14:24
|
||||
*/
|
||||
List<Long> selectIdsByUserId( @Param("userId") String userId);
|
||||
|
||||
|
||||
List<Long> selectIdsByUserIds( @Param("userIds") List<String> userIds);
|
||||
|
||||
UserAuthMappingDO getUserAuthByUserIdAndMappingId(
|
||||
@Param("userId") String userId,
|
||||
@Param("mappingId") String mappingId,
|
||||
@Param("type") String type);
|
||||
|
||||
/**
|
||||
* 分页订正 门店类型的权限
|
||||
* @param enterpriseId
|
||||
* @return
|
||||
*/
|
||||
List<UserAuthMappingDO> listStoreAuthByEid(@Param("enterpriseId") String enterpriseId);
|
||||
|
||||
List<UserAuthMappingDO> getAllAuthMapping(@Param("enterpriseId") String enterpriseId);
|
||||
|
||||
List<String> getUserIdsByMappingIds(@Param("mappingIdList") List<String> mappingIdList);
|
||||
|
||||
List<UserAuthMappingDO> getUserAuthByMappingIds(@Param("mappingIdList") List<String> mappingIdList);
|
||||
|
||||
List<String> getMappingIdsByUserId(@Param("userId")String userId);
|
||||
|
||||
|
||||
List<String> getRegionIdByUserId(@Param("userId") String userId);
|
||||
|
||||
/**
|
||||
* 根据UserId和权限来源获取权限
|
||||
|
||||
* @param userIdList
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
List<UserAuthMappingDO> listByUserIdListAndSource(@Param("userIdList") List<String> userIdList, @Param("source") String source);
|
||||
|
||||
List<UserAuthMappingDO> getAllByUserIds(@Param("userIdsByRoleIdList") List<String> userIdsByRoleIdList);
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
<resultMap id="BaseResultMap" type="com.cool.store.entity.RegionAreaConfigDO">
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="region_id" jdbcType="BIGINT" property="regionId" />
|
||||
<result column="region_path" jdbcType="VARCHAR" property="regionPath" />
|
||||
<result column="want_shop_area_id" jdbcType="BIGINT" property="wantShopAreaId" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
@@ -12,7 +13,7 @@
|
||||
<result column="deleted" jdbcType="BIT" property="deleted" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, region_id, want_shop_area_id, create_time, update_time, create_user_id, update_user_id,
|
||||
id, region_id, region_path, want_shop_area_id, create_time, update_time, create_user_id, update_user_id,
|
||||
deleted
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
|
||||
@@ -34,6 +35,9 @@
|
||||
<if test="regionId != null">
|
||||
region_id,
|
||||
</if>
|
||||
<if test="regionPath != null">
|
||||
region_path,
|
||||
</if>
|
||||
<if test="wantShopAreaId != null">
|
||||
want_shop_area_id,
|
||||
</if>
|
||||
@@ -57,6 +61,9 @@
|
||||
<if test="regionId != null">
|
||||
#{regionId,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="regionPath != null">
|
||||
#{regionPath,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="wantShopAreaId != null">
|
||||
#{wantShopAreaId,jdbcType=BIGINT},
|
||||
</if>
|
||||
@@ -83,6 +90,9 @@
|
||||
<if test="regionId != null">
|
||||
region_id = #{regionId,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="regionPath != null">
|
||||
region_path = #{regionPath,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="wantShopAreaId != null">
|
||||
want_shop_area_id = #{wantShopAreaId,jdbcType=BIGINT},
|
||||
</if>
|
||||
@@ -112,6 +122,9 @@
|
||||
<if test="null != regionId">
|
||||
and t.region_id = #{regionId,jdbcType=BIGINT}
|
||||
</if>
|
||||
<if test="null != regionPath">
|
||||
and t.region_path = #{regionPath,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="null != wantShopAreaId">
|
||||
and t.want_shop_area_id = #{wantShopAreaId,jdbcType=BIGINT}
|
||||
</if>
|
||||
@@ -139,6 +152,14 @@
|
||||
where region_id = #{regionId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByWantShopAreaIds">
|
||||
delete from xfsg_region_area_config
|
||||
where want_shop_area_id in
|
||||
<foreach collection="wantShopAreaIds" item="wantShopAreaId" open="(" separator="," close=")">
|
||||
#{wantShopAreaId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="batchInsertOrUpdateRegionAreaConfig">
|
||||
insert into xfsg_region_area_config
|
||||
(
|
||||
@@ -176,4 +197,17 @@
|
||||
from xfsg_region_area_config
|
||||
where want_shop_area_id = #{wantShopAreaId}
|
||||
</select>
|
||||
|
||||
<select id="listAreaByRegionIdList" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from xfsg_region_area_config
|
||||
where 1 = 1
|
||||
<if test="regionIdList != null and regionIdList.size >0 ">
|
||||
<foreach collection="regionIdList" item="regionId" separator=" or " open="and (" close=" )">
|
||||
region_path like concat('%/', #{regionId}, '/%')
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,187 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.cool.store.mapper.UserAuthMappingMapper" >
|
||||
<resultMap id="baseResult" type="com.cool.store.entity.UserAuthMappingDO">
|
||||
<result property="id" column="id"/>
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="mappingId" column="mapping_id"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="source" column="source"/>
|
||||
<result property="createId" column="create_id"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateId" column="update_id"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="listUserAuthMappingByUserId" resultMap="baseResult">
|
||||
select * from user_auth_mapping_${enterpriseId}
|
||||
where user_id=#{userId}
|
||||
</select>
|
||||
<select id="listUserAuthMappingByUserIdList" resultMap="baseResult">
|
||||
select * from user_auth_mapping_${enterpriseId}
|
||||
<where>
|
||||
<if test="userList!=null and userList.size>0">
|
||||
<foreach collection="userList" item="userId" open="user_id in (" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="listUserAuthMappingByMappingList" resultMap="baseResult">
|
||||
select * from user_auth_mapping_${enterpriseId}
|
||||
<where>
|
||||
<if test="mappingIdList!=null and mappingIdList.size>0">
|
||||
<foreach collection="mappingIdList" item="mappingId" open="mapping_id in (" separator="," close=")">
|
||||
#{mappingId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="type!=null and type!=''">
|
||||
and type =#{type}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="listUserAuthMappingByAuth" resultMap="baseResult">
|
||||
select a.id,a.user_id,mapping_id,a.type from user_auth_mapping_${enterpriseId} a
|
||||
join enterprise_user_${enterpriseId} e on a.user_id= e.user_id
|
||||
JOIN enterprise_user_role_${enterpriseId} ur on e.user_id =ur.user_id
|
||||
JOIN sys_role_${enterpriseId} b on ur.role_id=b.id
|
||||
<where>
|
||||
e.user_status= '1' and e.active= true
|
||||
<if test="mappingIdList!=null and mappingIdList.size>0">
|
||||
<foreach collection="mappingIdList" item="mappingId" open="and a.mapping_id in (" separator="," close=")">
|
||||
#{mappingId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="positionType!=null and positionType!=''">
|
||||
and b.position_type =#{positionType}
|
||||
</if>
|
||||
<if test="notRoleAuth!=null and notRoleAuth!=''">
|
||||
and b.role_auth !=#{notRoleAuth}
|
||||
</if>
|
||||
<if test="type!=null and type!=''">
|
||||
and a.type =#{type}
|
||||
</if>
|
||||
|
||||
|
||||
</where>
|
||||
</select>
|
||||
<select id="listUserAuthMappingByUserList" resultMap="baseResult">
|
||||
select * from user_auth_mapping_${enterpriseId}
|
||||
<where>
|
||||
<if test="userIdList!=null and userIdList.size>0">
|
||||
<foreach collection="userIdList" item="userId" open="user_id in (" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="listUserAuthMappingByUserAndType" resultMap="baseResult">
|
||||
select * from user_auth_mapping_${enterpriseId}
|
||||
<where>
|
||||
<if test="userId!=null and userId !=''">
|
||||
and user_id=#{userId}
|
||||
</if>
|
||||
<if test="type!=null and type!=''">
|
||||
and type =#{type}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectIdsByUserId" resultType="java.lang.Long">
|
||||
select id from user_auth_mapping_${enterpriseId} where user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectIdsByUserIds" resultType="java.lang.Long">
|
||||
select id from user_auth_mapping_${enterpriseId} where user_id in
|
||||
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="listByUserIdAndSource" resultMap="baseResult">
|
||||
select *
|
||||
from user_auth_mapping_${enterpriseId}
|
||||
where user_id = #{userId}
|
||||
and source = #{source}
|
||||
</select>
|
||||
|
||||
<select id="getUserAuthByUserIdAndMappingId" resultMap="baseResult">
|
||||
select * from user_auth_mapping_${enterpriseId}
|
||||
where user_id = #{userId} and mapping_id =#{mappingId} and type =#{type}
|
||||
</select>
|
||||
|
||||
<select id="listStoreAuthByEid" resultMap="baseResult">
|
||||
select * FROM
|
||||
user_auth_mapping_${enterpriseId}
|
||||
WHERE type = 'store'
|
||||
order by id asc
|
||||
</select>
|
||||
|
||||
<select id="getAllAuthMapping" resultMap="baseResult">
|
||||
select *
|
||||
from user_auth_mapping_${enterpriseId}
|
||||
</select>
|
||||
|
||||
<select id="getUserIdsByMappingIds" resultType="string">
|
||||
select
|
||||
user_id
|
||||
from
|
||||
user_auth_mapping_${enterpriseId}
|
||||
where
|
||||
mapping_id in
|
||||
<foreach collection="mappingIdList" item="mappingId" open="(" separator="," close=")">
|
||||
#{mappingId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="getUserAuthByMappingIds" resultMap="baseResult">
|
||||
select
|
||||
user_id,
|
||||
mapping_id
|
||||
from
|
||||
user_auth_mapping_${enterpriseId}
|
||||
where
|
||||
mapping_id in
|
||||
<foreach collection="mappingIdList" item="mappingId" open="(" separator="," close=")">
|
||||
#{mappingId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="getMappingIdsByUserId" resultType="string">
|
||||
select
|
||||
mapping_id
|
||||
from
|
||||
user_auth_mapping_${enterpriseId}
|
||||
where
|
||||
user_id = #{userId}
|
||||
</select>
|
||||
<select id="getRegionIdByUserId" resultType="java.lang.String">
|
||||
select mapping_id
|
||||
from user_auth_mapping_${enterpriseId}
|
||||
where user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="listByUserIdListAndSource" resultMap="baseResult">
|
||||
select *
|
||||
from user_auth_mapping_${enterpriseId}
|
||||
where `source` =#{source}
|
||||
and user_id in
|
||||
<foreach collection="userIdList" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getAllByUserIds" resultMap="baseResult">
|
||||
select *
|
||||
from user_auth_mapping_${enterpriseId}
|
||||
<where>
|
||||
user_id in
|
||||
<foreach collection="userIdsByRoleIdList" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</where>
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -24,6 +24,9 @@ public class RegionAreaConfigDO implements Serializable {
|
||||
@ApiModelProperty("区域ID 战区id")
|
||||
private Long regionId;
|
||||
|
||||
@ApiModelProperty("区域路径")
|
||||
private String regionPath;
|
||||
|
||||
@ApiModelProperty("意向开店区域 省市code")
|
||||
private Long wantShopAreaId;
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.cool.store.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* describe:人员权限映射表
|
||||
*
|
||||
* @author zhouyiping
|
||||
* @date 2020/10/10
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserAuthMappingDO {
|
||||
private Long id;
|
||||
private String userId;
|
||||
private String mappingId;
|
||||
private String type;
|
||||
private String source;
|
||||
private String createId;
|
||||
private Long createTime;
|
||||
private String updateId;
|
||||
private Long updateTime;
|
||||
|
||||
public UserAuthMappingDO(String userId, String mappingId, String type, String source, String createId, Long createTime) {
|
||||
this.userId = userId;
|
||||
this.mappingId = mappingId;
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
this.createId = createId;
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
public interface SysRoleService {
|
||||
|
||||
Boolean checkIsAdmin(String userId);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.UserAuthMappingDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* describe:
|
||||
*
|
||||
* @author wxp
|
||||
* @date 2020/11/11
|
||||
*/
|
||||
public interface UserAuthMappingService {
|
||||
|
||||
/**
|
||||
* 获取用户权限
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<UserAuthMappingDO> listUserAuthMappingByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 提供 根据职位 意向区域 查 对应人的接口 同时返回人名字
|
||||
* @param roleId
|
||||
* @param wantShopAreaId
|
||||
* @return
|
||||
*/
|
||||
EnterpriseUserDO listUserByRoleIdAndAreaId(Long roleId, Long wantShopAreaId);
|
||||
|
||||
/**
|
||||
* 根据 人 查 这个人管辖区域 对应的意向区域省市code 团队线索
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Long> listWantShopAreaIdByUserId(String userId);
|
||||
|
||||
}
|
||||
@@ -2,7 +2,11 @@ package com.cool.store.service.impl;
|
||||
|
||||
import com.cool.store.context.LoginUserInfo;
|
||||
import com.cool.store.dao.RegionAreaConfigDao;
|
||||
import com.cool.store.dao.RegionDao;
|
||||
import com.cool.store.entity.RegionAreaConfigDO;
|
||||
import com.cool.store.entity.RegionDO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.request.RegionAreaConfigAddRequest;
|
||||
import com.cool.store.service.RegionAreaConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -27,17 +31,25 @@ public class RegionAreaConfigServiceImpl implements RegionAreaConfigService {
|
||||
@Resource
|
||||
private RegionAreaConfigDao regionAreaConfigDao;
|
||||
|
||||
@Resource
|
||||
private RegionDao regionDao;
|
||||
|
||||
@Override
|
||||
public Boolean saveOrUpdateRegionAreaConfig(RegionAreaConfigAddRequest regionAreaConfigAddRequest, LoginUserInfo user) {
|
||||
RegionDO regionDO = regionDao.getRegionById(regionAreaConfigAddRequest.getRegionId());
|
||||
if(regionDO == null){
|
||||
throw new ServiceException(ErrorCodeEnum.REGION_NOT_EXIST);
|
||||
}
|
||||
List<Long> areaIdList = regionAreaConfigAddRequest.getAreaIdList();
|
||||
if(CollectionUtils.isEmpty(areaIdList)){
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
regionAreaConfigDao.deleteRegionAreaConfigByRegionId(regionAreaConfigAddRequest.getRegionId());
|
||||
regionAreaConfigDao.deleteByWantShopAreaIds(areaIdList);
|
||||
List<RegionAreaConfigDO> regionAreaConfigList = new ArrayList<>();
|
||||
for (Long areaId: areaIdList) {
|
||||
RegionAreaConfigDO regionAreaConfigDO = new RegionAreaConfigDO();
|
||||
regionAreaConfigDO.setRegionId(regionAreaConfigAddRequest.getRegionId());
|
||||
regionAreaConfigDO.setRegionPath(regionDO.getFullRegionPath());
|
||||
regionAreaConfigDO.setWantShopAreaId(areaId);
|
||||
regionAreaConfigDO.setCreateUserId(user.getUserId());
|
||||
regionAreaConfigDO.setUpdateUserId(user.getUserId());
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.cool.store.entity.SysRoleDO;
|
||||
import com.cool.store.enums.Role;
|
||||
import com.cool.store.mapper.SysRoleMapper;
|
||||
import com.cool.store.service.SysRoleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色service
|
||||
* @author wxp
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysRoleServiceImpl implements SysRoleService {
|
||||
|
||||
@Resource
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
|
||||
@Override
|
||||
public Boolean checkIsAdmin(String userId) {
|
||||
// 1.取出所有用户角色
|
||||
// 2.匹配是否有管理员角色
|
||||
List<SysRoleDO> sysRoleDOList = sysRoleMapper.listRoleByUserId(userId);
|
||||
return ListUtils.emptyIfNull(sysRoleDOList)
|
||||
.stream()
|
||||
.anyMatch(role-> StringUtils.equals(Role.MASTER.getRoleEnum(),role.getRoleEnum()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dao.RegionAreaConfigDao;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.RegionAreaConfigDO;
|
||||
import com.cool.store.entity.RegionDO;
|
||||
import com.cool.store.entity.UserAuthMappingDO;
|
||||
import com.cool.store.enums.AuthRoleEnum;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.enums.Role;
|
||||
import com.cool.store.enums.UserAuthMappingTypeEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.mapper.RegionMapper;
|
||||
import com.cool.store.mapper.SysRoleMapper;
|
||||
import com.cool.store.mapper.UserAuthMappingMapper;
|
||||
import com.cool.store.service.UserAuthMappingService;
|
||||
import com.cool.store.vo.SysRoleVO;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* describe:
|
||||
* @author wxp
|
||||
* @date 2020/11/11
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserAuthMappingServiceImpl implements UserAuthMappingService {
|
||||
|
||||
@Resource
|
||||
private UserAuthMappingMapper userAuthMappingMapper;
|
||||
|
||||
@Resource
|
||||
private RegionAreaConfigDao regionAreaConfigDao;
|
||||
|
||||
@Resource
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
|
||||
@Resource
|
||||
private RegionMapper regionMapper;
|
||||
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserAuthMappingDO> listUserAuthMappingByUserId(String userId) {
|
||||
if(StringUtils.isBlank(userId)){
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
return userAuthMappingMapper.listUserAuthMappingByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供 根据职位 意向区域 查 对应人的接口 同时返回人名字
|
||||
* @param roleId
|
||||
* @param wantShopAreaId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public EnterpriseUserDO listUserByRoleIdAndAreaId(Long roleId, Long wantShopAreaId) {
|
||||
if(roleId == null || wantShopAreaId == null){
|
||||
return null;
|
||||
}
|
||||
Long warRegionId = regionAreaConfigDao.getByWantShopAreaId(wantShopAreaId);
|
||||
// 查找有战区权限的人
|
||||
List<String> authWarRegionUserIdList = authWarRegionUser(warRegionId);
|
||||
List<String> userIds = sysRoleMapper.getPositionUserIds(Collections.singletonList(String.valueOf(roleId)));
|
||||
authWarRegionUserIdList.retainAll(userIds);
|
||||
List<EnterpriseUserDO> userDOList = enterpriseUserDAO.getUserInfoByUserIds(authWarRegionUserIdList);
|
||||
// 用redis实现 用户列表轮询返回
|
||||
|
||||
return userDOList.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 人 查 这个人管辖区域 对应的意向区域省市code 团队线索
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Long> listWantShopAreaIdByUserId(String userId) {
|
||||
List<UserAuthMappingDO> userAuthList = this.listUserAuthMappingByUserId(userId);
|
||||
List<String> authRegionIds = ListUtils.emptyIfNull(userAuthList)
|
||||
.stream().map(UserAuthMappingDO::getMappingId)
|
||||
.collect(Collectors.toList());
|
||||
List<Long> authRegionIdList = ListUtils.emptyIfNull(authRegionIds).stream().map(regionId -> Long.valueOf(regionId)).collect(Collectors.toList());
|
||||
List<RegionAreaConfigDO> regionAreaConfigDOList = regionAreaConfigDao.listAreaByRegionIdList(authRegionIdList);
|
||||
List<Long> wantShopAreaIdList = ListUtils.emptyIfNull(regionAreaConfigDOList)
|
||||
.stream().map(RegionAreaConfigDO::getWantShopAreaId)
|
||||
.collect(Collectors.toList());
|
||||
return wantShopAreaIdList;
|
||||
}
|
||||
|
||||
// 查找有战区权限的人
|
||||
public List<String> authWarRegionUser(Long warRegionId) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(Objects.isNull(warRegionId)){
|
||||
return result;
|
||||
}
|
||||
RegionDO regionDO = regionMapper.getByRegionId(warRegionId);
|
||||
if(regionDO == null){
|
||||
throw new ServiceException(ErrorCodeEnum.REGION_NOT_EXIST);
|
||||
}
|
||||
//将拥有管理员角色、角色属性为全企业数据的人查询出来
|
||||
List<SysRoleVO> roleUserByRoleId = sysRoleMapper.getRoleUserByRoleEnum(Role.MASTER.getRoleEnum(), null);
|
||||
List<SysRoleVO> roleUserByRoleAuth = sysRoleMapper.getRoleUserByRoleAuth(AuthRoleEnum.ALL.getCode(), null);
|
||||
//组合出拥有所有门店信息的人
|
||||
List<String> allWarRegionUserIdList = getAllWarRegionAuthUserIdList(roleUserByRoleId, roleUserByRoleAuth);
|
||||
//查询出有门店权限配置的的人员
|
||||
// 1.将门店区域切分出门店所属于的区域ID
|
||||
// 2.将配置了区域的人 查询出来
|
||||
List<String> fullAreaIdList = StrUtil.splitTrim(regionDO.getRegionPath(),"/");
|
||||
List<String> lastAreaIdList = Collections.singletonList(String.valueOf(regionDO.getId()));
|
||||
//除不包含子区域的可视化范围的区域配置。
|
||||
List<UserAuthMappingDO> regionUserAuthMappingList =
|
||||
userAuthMappingMapper.listUserAuthMappingByAuth(UserAuthMappingTypeEnum.REGION.getCode(), fullAreaIdList, null, AuthRoleEnum.NOT_INCLUDE_SUBORDINATE.getCode());
|
||||
//不包含子区域的的直属连接门店的区域下的配置(会重复一些选择了上面数据)
|
||||
List<UserAuthMappingDO> notIncludeRegionUserAuthMappingList =
|
||||
userAuthMappingMapper.listUserAuthMappingByAuth(UserAuthMappingTypeEnum.REGION.getCode(), lastAreaIdList, null, null);
|
||||
List<String> authWarRegionUserIdList = mapAuthStoreUserDTO(regionUserAuthMappingList, allWarRegionUserIdList, notIncludeRegionUserAuthMappingList);
|
||||
return authWarRegionUserIdList;
|
||||
}
|
||||
|
||||
|
||||
private List<String> getAllWarRegionAuthUserIdList(List<SysRoleVO> roleUserByRoleId, List<SysRoleVO> roleUserByRoleAuth) {
|
||||
List<String> allUserIdList= new ArrayList<>();
|
||||
List<String> masterUserList = ListUtils.emptyIfNull(roleUserByRoleId).stream()
|
||||
.map(SysRoleVO::getEnterpriseDOs)
|
||||
.flatMap(Collection::stream)
|
||||
.map(EnterpriseUserDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
List<String> roleAllUserList = ListUtils.emptyIfNull(roleUserByRoleAuth).stream()
|
||||
.map(SysRoleVO::getEnterpriseDOs)
|
||||
.flatMap(Collection::stream)
|
||||
.map(EnterpriseUserDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(masterUserList)) {
|
||||
allUserIdList.addAll(masterUserList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(roleAllUserList)) {
|
||||
allUserIdList.addAll(roleAllUserList);
|
||||
}
|
||||
return ListUtils.emptyIfNull(allUserIdList)
|
||||
.stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<String> mapAuthStoreUserDTO(
|
||||
List<UserAuthMappingDO> regionUserAuthMappingList,
|
||||
List<String> allWarRegionUserIdList,
|
||||
List<UserAuthMappingDO> notIncludeRegionUserAuthMappingList) {
|
||||
//组装全部的人员信息
|
||||
List<String> authUserIdList = new ArrayList<>();
|
||||
//组装拥有所有门店信息的人
|
||||
if (CollectionUtils.isNotEmpty(allWarRegionUserIdList)) {
|
||||
authUserIdList.addAll(allWarRegionUserIdList);
|
||||
}
|
||||
//组装配置了区域权限的人(除了不包含子区域可视化范围)
|
||||
List<String> regionUserIdList = ListUtils.emptyIfNull(regionUserAuthMappingList).stream()
|
||||
.map(UserAuthMappingDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(regionUserIdList)) {
|
||||
authUserIdList.addAll(regionUserIdList);
|
||||
}
|
||||
//组装配置了区域权限的人(不包含子区域可视化范围)
|
||||
List<String> notIncludeRegionUserIdList = ListUtils.emptyIfNull(notIncludeRegionUserAuthMappingList).stream()
|
||||
.map(UserAuthMappingDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(notIncludeRegionUserIdList)) {
|
||||
authUserIdList.addAll(notIncludeRegionUserIdList);
|
||||
}
|
||||
//去除重复数据
|
||||
List<String> distinctUserIdList = ListUtils.emptyIfNull(authUserIdList).stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
return distinctUserIdList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user