大调整
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.cool.store.mapper;
|
||||
|
||||
import com.cool.store.dto.enterprise.EnterpriseUserRole;
|
||||
import com.cool.store.entity.SysRoleDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -8,26 +7,30 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @date 2023-05-19 03:00
|
||||
* @date 2023-06-08 10:54
|
||||
*/
|
||||
public interface SysRoleMapper {
|
||||
/**
|
||||
*
|
||||
* 默认插入方法,只会给有值的字段赋值
|
||||
* 会对传进来的字段做判空处理,如果字段为空,则使用数据库默认字段或者null
|
||||
* dateTime:2023-05-19 03:00
|
||||
* dateTime:2023-06-08 10:54
|
||||
*/
|
||||
int insertSelective(@Param("record") SysRoleDO record);
|
||||
int batchInsertSelective(@Param("insertOrUpdateList") List<SysRoleDO> insertOrUpdateList);
|
||||
|
||||
/**
|
||||
*
|
||||
* 默认更新方法,根据主键更新,不会把null值更新到数据库,避免覆盖之前有值的
|
||||
* dateTime:2023-05-19 03:00
|
||||
* dateTime:2023-06-08 10:54
|
||||
*/
|
||||
int updateByPrimaryKeySelective(@Param("record") SysRoleDO record);
|
||||
int updateByPrimaryKeySelective(SysRoleDO record);
|
||||
|
||||
Integer deleteRole(@Param("roleType")Integer roleType, @Param("roleIds") List<String> roleIds);
|
||||
|
||||
SysRoleDO getHighestPrioritySysRoleDoByUserId(@Param("userId") String userId);
|
||||
|
||||
SysRoleDO getRoleByRoleEnum(@Param("roleEnum") String roleEnum);
|
||||
/**
|
||||
* 获取用户权限
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
SysRoleDO getHighestPriorityRoleByUserId(@Param("userId") String userId);
|
||||
}
|
||||
@@ -3,198 +3,130 @@
|
||||
<mapper namespace="com.cool.store.mapper.SysRoleMapper">
|
||||
<resultMap id="BaseResultMap" type="com.cool.store.entity.SysRoleDO">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<result column="role_id" jdbcType="VARCHAR" property="roleId"/>
|
||||
<result column="role_name" jdbcType="VARCHAR" property="roleName"/>
|
||||
<result column="is_internal" jdbcType="BIT" property="isInternal"/>
|
||||
<result column="role_auth" jdbcType="VARCHAR" property="roleAuth"/>
|
||||
<result column="source" jdbcType="CHAR" property="source"/>
|
||||
<result column="position_type" jdbcType="VARCHAR" property="positionType"/>
|
||||
<result column="app_menu" jdbcType="VARCHAR" property="appMenu"/>
|
||||
<result column="syn_ding_role_id" jdbcType="BIGINT" property="synDingRoleId"/>
|
||||
<result column="priority" jdbcType="INTEGER" property="priority"/>
|
||||
<result column="role_type" jdbcType="TINYINT" property="roleType"/>
|
||||
<result column="third_unique_id" jdbcType="VARCHAR" property="thirdUniqueId"/>
|
||||
<result column="deleted" jdbcType="BIT" property="deleted"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
|
||||
<result column="role_enum" jdbcType="VARCHAR" property="roleEnum"/>
|
||||
<result column="create_user" jdbcType="VARCHAR" property="createUser"/>
|
||||
<result column="update_user" jdbcType="VARCHAR" property="updateUser"/>
|
||||
<result column="third_unique_id" jdbcType="VARCHAR" property="thirdUniqueId"/>
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, role_name, is_internal, role_auth, source, position_type, app_menu, syn_ding_role_id,
|
||||
priority, create_time, update_time, role_enum, create_user, update_user, third_unique_id
|
||||
id, role_id, role_name, role_type, third_unique_id, deleted, create_time, update_time, create_user,
|
||||
update_user
|
||||
</sql>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
|
||||
insert into sys_role
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="record.roleName != null">
|
||||
role_name,
|
||||
</if>
|
||||
<if test="record.isInternal != null">
|
||||
is_internal,
|
||||
</if>
|
||||
<if test="record.roleAuth != null">
|
||||
role_auth,
|
||||
</if>
|
||||
<if test="record.source != null">
|
||||
source,
|
||||
</if>
|
||||
<if test="record.positionType != null">
|
||||
position_type,
|
||||
</if>
|
||||
<if test="record.appMenu != null">
|
||||
app_menu,
|
||||
</if>
|
||||
<if test="record.synDingRoleId != null">
|
||||
syn_ding_role_id,
|
||||
</if>
|
||||
<if test="record.priority != null">
|
||||
priority,
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
<if test="record.roleEnum != null">
|
||||
role_enum,
|
||||
</if>
|
||||
<if test="record.createUser != null">
|
||||
create_user,
|
||||
</if>
|
||||
<if test="record.updateUser != null">
|
||||
update_user,
|
||||
</if>
|
||||
<if test="record.thirdUniqueId != null">
|
||||
third_unique_id,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="record.roleName != null">
|
||||
#{record.roleName},
|
||||
</if>
|
||||
<if test="record.isInternal != null">
|
||||
#{record.isInternal},
|
||||
</if>
|
||||
<if test="record.roleAuth != null">
|
||||
#{record.roleAuth},
|
||||
</if>
|
||||
<if test="record.source != null">
|
||||
#{record.source},
|
||||
</if>
|
||||
<if test="record.positionType != null">
|
||||
#{record.positionType},
|
||||
</if>
|
||||
<if test="record.appMenu != null">
|
||||
#{record.appMenu},
|
||||
</if>
|
||||
<if test="record.synDingRoleId != null">
|
||||
#{record.synDingRoleId},
|
||||
</if>
|
||||
<if test="record.priority != null">
|
||||
#{record.priority},
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
#{record.createTime},
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
#{record.updateTime},
|
||||
</if>
|
||||
<if test="record.roleEnum != null">
|
||||
#{record.roleEnum},
|
||||
</if>
|
||||
<if test="record.createUser != null">
|
||||
#{record.createUser},
|
||||
</if>
|
||||
<if test="record.updateUser != null">
|
||||
#{record.updateUser},
|
||||
</if>
|
||||
<if test="record.thirdUniqueId != null">
|
||||
#{record.thirdUniqueId},
|
||||
</if>
|
||||
</trim>
|
||||
<insert id="batchInsertSelective">
|
||||
<foreach collection="insertOrUpdateList" separator=";" item="record">
|
||||
insert into sys_role
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="record.roleId != null">
|
||||
role_id,
|
||||
</if>
|
||||
<if test="record.roleName != null">
|
||||
role_name,
|
||||
</if>
|
||||
<if test="record.roleType != null">
|
||||
role_type,
|
||||
</if>
|
||||
<if test="record.thirdUniqueId != null">
|
||||
third_unique_id,
|
||||
</if>
|
||||
<if test="record.deleted != null">
|
||||
deleted,
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
<if test="record.createUser != null">
|
||||
create_user,
|
||||
</if>
|
||||
<if test="record.updateUser != null">
|
||||
update_user,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="record.roleId != null">
|
||||
#{record.roleId},
|
||||
</if>
|
||||
<if test="record.roleName != null">
|
||||
#{record.roleName},
|
||||
</if>
|
||||
<if test="record.roleType != null">
|
||||
#{record.roleType},
|
||||
</if>
|
||||
<if test="record.thirdUniqueId != null">
|
||||
#{record.thirdUniqueId},
|
||||
</if>
|
||||
<if test="record.deleted != null">
|
||||
#{record.deleted},
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
#{record.createTime},
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
#{record.updateTime},
|
||||
</if>
|
||||
<if test="record.createUser != null">
|
||||
#{record.createUser},
|
||||
</if>
|
||||
<if test="record.updateUser != null">
|
||||
#{record.updateUser},
|
||||
</if>
|
||||
</trim>
|
||||
ON DUPLICATE KEY UPDATE role_name = values(role_name), deleted = values(deleted)
|
||||
</foreach>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective">
|
||||
update sys_role
|
||||
<set>
|
||||
<if test="record.roleName != null">
|
||||
role_name = #{record.roleName},
|
||||
<if test="roleId != null">
|
||||
role_id = #{roleId},
|
||||
</if>
|
||||
<if test="record.isInternal != null">
|
||||
is_internal = #{record.isInternal},
|
||||
<if test="roleName != null">
|
||||
role_name = #{roleName},
|
||||
</if>
|
||||
<if test="record.roleAuth != null">
|
||||
role_auth = #{record.roleAuth},
|
||||
<if test="roleType != null">
|
||||
role_type = #{roleType},
|
||||
</if>
|
||||
<if test="record.source != null">
|
||||
source = #{record.source},
|
||||
<if test="thirdUniqueId != null">
|
||||
third_unique_id = #{thirdUniqueId},
|
||||
</if>
|
||||
<if test="record.positionType != null">
|
||||
position_type = #{record.positionType},
|
||||
<if test="deleted != null">
|
||||
deleted = #{deleted},
|
||||
</if>
|
||||
<if test="record.appMenu != null">
|
||||
app_menu = #{record.appMenu},
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime},
|
||||
</if>
|
||||
<if test="record.synDingRoleId != null">
|
||||
syn_ding_role_id = #{record.synDingRoleId},
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
<if test="record.priority != null">
|
||||
priority = #{record.priority},
|
||||
<if test="createUser != null">
|
||||
create_user = #{createUser},
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
create_time = #{record.createTime},
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
update_time = #{record.updateTime},
|
||||
</if>
|
||||
<if test="record.roleEnum != null">
|
||||
role_enum = #{record.roleEnum},
|
||||
</if>
|
||||
<if test="record.createUser != null">
|
||||
create_user = #{record.createUser},
|
||||
</if>
|
||||
<if test="record.updateUser != null">
|
||||
update_user = #{record.updateUser},
|
||||
</if>
|
||||
<if test="record.thirdUniqueId != null">
|
||||
third_unique_id = #{record.thirdUniqueId},
|
||||
<if test="updateUser != null">
|
||||
update_user = #{updateUser},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{record.id}
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="getHighestPrioritySysRoleDoByUserId" resultMap="BaseResultMap">
|
||||
select
|
||||
c.id as id,
|
||||
c.role_name as roleName,
|
||||
c.role_auth as roleAuth,
|
||||
c.position_type as positionType,
|
||||
c.app_menu as appMenu,
|
||||
c.role_enum as roleEnum
|
||||
from
|
||||
enterprise_user a
|
||||
left join enterprise_user_role b on a.user_id =b.user_id
|
||||
left join sys_role c on c.id=b.role_id
|
||||
where
|
||||
a.user_id= #{userId} and a.active = true
|
||||
order by
|
||||
c.priority is null, c.priority, position_type desc
|
||||
LIMIT 1
|
||||
</select>
|
||||
<update id="deleteRole">
|
||||
update sys_role set deleted = 1 where role_type = #{roleType} and role_id not in
|
||||
<foreach collection="roleIds" open="(" close=")" separator="," item="roleId">#{roleId}</foreach>
|
||||
</update>
|
||||
|
||||
<select id="getRoleByRoleEnum" resultMap="BaseResultMap">
|
||||
<select id="getHighestPriorityRoleByUserId" resultMap="BaseResultMap">
|
||||
select
|
||||
id as id,
|
||||
role_name as roleName,
|
||||
role_auth as roleAuth,
|
||||
is_internal as isInternal,
|
||||
`source` as source,
|
||||
priority as priority,
|
||||
app_menu as appMenu,
|
||||
position_type as positionType,
|
||||
role_enum as roleEnum
|
||||
r.*
|
||||
from
|
||||
sys_role
|
||||
sys_role r inner join enterprise_user_role e on r.role_id = e.role_id
|
||||
where
|
||||
role_enum = #{roleEnum}
|
||||
e.user_id = #{userId}
|
||||
limit 1
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -5,128 +5,109 @@
|
||||
<id column="id" jdbcType="INTEGER" property="id"/>
|
||||
<result column="region_id" jdbcType="VARCHAR" property="regionId"/>
|
||||
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
|
||||
<result column="type" jdbcType="INTEGER" property="type"/>
|
||||
<result column="deleted" jdbcType="BIT" property="deleted"/>
|
||||
<result column="create_id" jdbcType="VARCHAR" property="createId"/>
|
||||
<result column="create_time" jdbcType="BIGINT" property="createTime"/>
|
||||
<result column="update_id" jdbcType="VARCHAR" property="updateId"/>
|
||||
<result column="update_time" jdbcType="BIGINT" property="updateTime"/>
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, region_id, user_id, create_id, create_time, update_id, update_time
|
||||
id, region_id, user_id, type, deleted, create_id, create_time, update_id, update_time
|
||||
</sql>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
|
||||
insert into user_region_mapping
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="record.regionId != null">
|
||||
region_id,
|
||||
</if>
|
||||
<if test="record.userId != null">
|
||||
user_id,
|
||||
</if>
|
||||
<if test="record.createId != null">
|
||||
create_id,
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="record.updateId != null">
|
||||
update_id,
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="record.regionId != null">
|
||||
#{record.regionId},
|
||||
</if>
|
||||
<if test="record.userId != null">
|
||||
#{record.userId},
|
||||
</if>
|
||||
<if test="record.createId != null">
|
||||
#{record.createId},
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
#{record.createTime},
|
||||
</if>
|
||||
<if test="record.updateId != null">
|
||||
#{record.updateId},
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
#{record.updateTime},
|
||||
</if>
|
||||
</trim>
|
||||
<insert id="batchInsertOrUpdateUserRegion">
|
||||
<foreach collection="insertOrUpdateList" item="record" separator=";">
|
||||
insert into user_region_mapping
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="record.regionId != null">
|
||||
region_id,
|
||||
</if>
|
||||
<if test="record.userId != null">
|
||||
user_id,
|
||||
</if>
|
||||
<if test="record.type != null">
|
||||
type,
|
||||
</if>
|
||||
<if test="record.deleted != null">
|
||||
deleted,
|
||||
</if>
|
||||
<if test="record.createId != null">
|
||||
create_id,
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="record.updateId != null">
|
||||
update_id,
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="record.regionId != null">
|
||||
#{record.regionId},
|
||||
</if>
|
||||
<if test="record.userId != null">
|
||||
#{record.userId},
|
||||
</if>
|
||||
<if test="record.type != null">
|
||||
#{record.type},
|
||||
</if>
|
||||
<if test="record.deleted != null">
|
||||
#{record.deleted},
|
||||
</if>
|
||||
<if test="record.createId != null">
|
||||
#{record.createId},
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
#{record.createTime},
|
||||
</if>
|
||||
<if test="record.updateId != null">
|
||||
#{record.updateId},
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
#{record.updateTime},
|
||||
</if>
|
||||
</trim>
|
||||
ON DUPLICATE KEY UPDATE type = values(type), deleted = values(deleted)
|
||||
</foreach>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective">
|
||||
update user_region_mapping
|
||||
<set>
|
||||
<if test="record.regionId != null">
|
||||
region_id = #{record.regionId},
|
||||
<if test="regionId != null">
|
||||
region_id = #{regionId},
|
||||
</if>
|
||||
<if test="record.userId != null">
|
||||
user_id = #{record.userId},
|
||||
<if test="userId != null">
|
||||
user_id = #{userId},
|
||||
</if>
|
||||
<if test="record.createId != null">
|
||||
create_id = #{record.createId},
|
||||
<if test="type != null">
|
||||
type = #{type},
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
create_time = #{record.createTime},
|
||||
<if test="deleted != null">
|
||||
deleted = #{deleted},
|
||||
</if>
|
||||
<if test="record.updateId != null">
|
||||
update_id = #{record.updateId},
|
||||
<if test="createId != null">
|
||||
create_id = #{createId},
|
||||
</if>
|
||||
<if test="record.updateTime != null">
|
||||
update_time = #{record.updateTime},
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime},
|
||||
</if>
|
||||
<if test="updateId != null">
|
||||
update_id = #{updateId},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{record.id}
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deletedByUserIds">
|
||||
delete from user_region_mapping where user_id in
|
||||
<foreach collection="userIds" open="(" close=")" separator="," item="userId">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="batchInsertRegionMapping">
|
||||
insert into user_region_mapping
|
||||
(
|
||||
region_id,
|
||||
user_id,
|
||||
create_time,
|
||||
update_time,
|
||||
create_id,
|
||||
update_id
|
||||
)
|
||||
values
|
||||
<foreach collection="userRegionMappingDOS" item="entity" separator=",">
|
||||
(
|
||||
#{entity.regionId},
|
||||
#{entity.userId},
|
||||
#{entity.createTime},
|
||||
#{entity.updateTime},
|
||||
#{entity.createId},
|
||||
#{entity.updateId}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="listUserRegionMappingByUserId" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from user_region_mapping
|
||||
<if test="userIds !=null and userIds.size >0">
|
||||
where user_id in
|
||||
<foreach collection="userIds" open="(" close=")" separator="," item="userId">
|
||||
#{userId}
|
||||
</foreach>
|
||||
<delete id="deleteUserRegion">
|
||||
update user_region_mapping set deleted = 1 where region_id = #{regionId} and type = #{type}
|
||||
<if test="excludeUserIds != null and excludeUserIds.size() > 0">
|
||||
and user_id not in <foreach collection="excludeUserIds" separator="," open="(" close=")" item="userId" >#{userId}</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<delete id="deletedByIds">
|
||||
delete from user_region_mapping where id in
|
||||
<foreach collection="ids" open="(" close=")" separator="," item="id">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user