水利项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
8.0 KiB

2 years ago
<?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.kms.system.mapper.SysRoleMapper">
<resultMap type="com.shuili.common.core.domain.entity.SysRole" id="sysRoleResult">
<id property="id" column="id" />
<result property="roleName" column="role_name" />
<result property="roleKey" column="role_key" />
<result property="roleSort" column="role_sort" />
<result property="dataScope" column="data_scope" />
<result property="status" column="status" />
<result property="delFlag" column="del_flag" />
<result property="createUid" column="create_uid" />
<result property="createTime" column="create_time" />
<result property="updateUid" column="update_uid" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectRoleVo">
select distinct r.id, r.role_name, r.role_key, r.role_sort, r.data_scope,
r.status, r.del_flag, r.create_time
2 years ago
from sys_role r
left join sys_user_role ur on ur.role_id = r.id
left join sys_user u on u.id = ur.user_id
left join sys_dept d on u.dept_id = d.id
</sql>
<select id="findList" parameterType="com.shuili.common.core.domain.entity.SysRole" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
where r.del_flag = '0'
<if test="roleName != null and roleName != ''">
AND r.role_name like concat('%', #{roleName}, '%')
</if>
<if test="status != null and status != ''">
AND r.status = #{status}
</if>
<if test="roleKey != null and roleKey != ''">
AND r.role_key like concat('%', #{roleKey}, '%')
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
<if test="ids != null and ids.size() > 0"><!-- 结束时间检索 -->
and id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="findAllList" parameterType="com.shuili.common.core.domain.entity.SysRole" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
where del_flag = '0'
<if test="roleName != null and roleName != ''">
AND role_name like concat('%', #{roleName}, '%')
</if>
<if test="status != null and status != ''">
AND status = #{status}
</if>
<if test="roleKey != null and roleKey != ''">
AND role_key like concat('%', #{roleKey}, '%')
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
<if test="ids != null and ids.size() > 0"><!-- 结束时间检索 -->
and id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="selectRoleList" parameterType="com.shuili.common.core.domain.entity.SysRole" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
where r.del_flag = '0'
<if test="roleName != null and roleName != ''">
AND r.role_name like concat('%', #{roleName}, '%')
</if>
<if test="status != null and status != ''">
AND r.status = #{status}
</if>
<if test="roleKey != null and roleKey != ''">
AND r.role_key like concat('%', #{roleKey}, '%')
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
order by r.role_sort
</select>
<select id="selectRolePermissionByUserId" parameterType="String" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
WHERE r.del_flag = '0' and ur.user_id = #{userId}
</select>
<select id="selectRoleAll" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
</select>
<select id="selectRoleListByUserId" parameterType="String" resultType="String">
select r.id
from sys_role r
left join sys_user_role ur on ur.role_id = r.id
left join sys_user u on u.id = ur.user_id
where u.id = #{id}
</select>
<select id="selectRoleById" parameterType="String" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
where r.id = #{id}
</select>
<select id="selectRolesByUserName" parameterType="String" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
WHERE r.del_flag = '0' and u.user_name = #{userName}
</select>
<select id="checkRoleNameUnique" parameterType="String" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
where r.role_name=#{roleName} limit 1
</select>
<select id="checkRoleKeyUnique" parameterType="String" resultMap="sysRoleResult">
<include refid="selectRoleVo"/>
where r.role_key=#{roleKey} limit 1
</select>
<insert id="insertRole" parameterType="com.shuili.common.core.domain.entity.SysRole" useGeneratedKeys="true" keyProperty="id">
insert into sys_role(
<if test="id != null and id != ''">id,</if>
<if test="roleName != null and roleName != ''">role_name,</if>
<if test="roleKey != null and roleKey != ''">role_key,</if>
<if test="roleSort != null and roleSort != ''">role_sort,</if>
<if test="dataScope != null and dataScope != ''">data_scope,</if>
<if test="status != null and status != ''">status,</if>
<if test="note != null and note != ''">note,</if>
2 years ago
<if test="createUid != null and createUid != ''">create_uid,</if>
create_time
)values(
<if test="id != null and id != ''">#{id},</if>
<if test="roleName != null and roleName != ''">#{roleName},</if>
<if test="roleKey != null and roleKey != ''">#{roleKey},</if>
<if test="roleSort != null and roleSort != ''">#{roleSort},</if>
<if test="dataScope != null and dataScope != ''">#{dataScope},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="note != null and note != ''">#{note},</if>
2 years ago
<if test="createUid != null and createUid != ''">#{createUid},</if>
sysdate()
)
</insert>
<update id="updateRole" parameterType="com.shuili.common.core.domain.entity.SysRole">
update sys_role
<set>
<if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
<if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
<if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
<if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="note != null">note = #{note},</if>
2 years ago
<if test="updateUid != null and updateUid != ''">update_uid = #{updateUid},</if>
update_time = sysdate()
</set>
where id = #{id}
</update>
<update id="updateRoleStatus" parameterType="com.shuili.common.core.domain.entity.SysRole">
update sys_user set status = #{status} where user_id = #{userId}
</update>
<delete id="deleteRoleById" parameterType="String">
delete from sys_role where id = #{id}
</delete>
<delete id="deleteRoleByIds" parameterType="String">
delete from sys_role where id in
<foreach collection="array" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="getRoleByUserId" parameterType="String" resultMap="sysRoleResult">
SELECT a.*
FROM sys_role a INNER JOIN sys_user_role b ON a.id = b.role_id
WHERE b.user_id=#{userId}
</select>
</mapper>