项目中常见的Mapper文件和接口
ConfigMapper
//参数配置 数据层
@Mapper
public interface ConfigMapper{
//查询参数配置信息
Config selectConfig(Config config);
//查询参数配置列表
List<Config> selectConfigList(Config config);
//根据键名查询
Config checkConfigKeyUnique(String configKey);
//新增
int insertConfig(Config config);
//修改
int updateConfig(Config config);
//批量删除
int deleteConfigByIds(String[] configIds);
}
<?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.xxxx.mapper.ConfigMapper"><!--对应类的包名-->
<resultMap type="com.xxxx.domain.Config" id="configResult"><!--类属性名和数据库字段名的对应-->
<id property="configId" column="config_id" />
<result property="configName" column="config_name" />
<result property="configKey" column="config_key" />
<result property="configValue" column="config_value" />
<result property="configType" column="config_type" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectConfigVo"> <!--提取公共sql-->
SELECT config_id,
config_name,
config_key,
config_value,
config_type,
create_by,
create_time,
update_by,
update_time,
remark
FROM sys_config
</sql>
<sql id="sqlwhereSearch"><!--提取公共查询条件-->
<where>
<if test="configId != null">
AND config_id = #{configId}
</if>
<if test="configKey !=null and configKey != ''">
AND config_key = #{configKey}
</if>
</where>
</sql>
<!--正式和接口方法对应的增删改查-->
<select id="selectConfig" parameterType="com.ruoyi.system.domain.Config" resultMap="ConfigResult">
<include refid="selectConfigVo"/>
<include refid="sqlwhereSearch"/>
</select>
<select id="selectConfigList" parameterType="com.ruoyi.system.domain.Config" resultMap="ConfigResult">
<include refid="selectConfigVo"/>
<where>
<if test="configName != null and configName != ''">
AND config_name LIKE concat('%', #{configName}, '%')
</if>
<if test="configType != null and configType != ''">
AND config_type = #{configType}
</if>
<if test="configKey != null and configKey != ''">
AND config_key LIKE concat('%', #{configKey}, '%')
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d')
</if>
</where>
</select>
<select id="checkConfigKeyUnique" parameterType="String" resultMap="ConfigResult">
<include refid="selectConfigVo"/>
WHERE config_key = #{configKey}
</select>
<insert id="insertConfig" parameterType="com.ruoyi.system.domain.Config">
INSERT INTO sys_config (
<if test="configName != null and configName != '' ">config_name,</if>
<if test="configKey != null and configKey != '' ">config_key,</if>
<if test="configValue != null and configValue != '' ">config_value,</if>
<if test="configType != null and configType != '' ">config_type,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
create_time
)VALUES(
<if test="configName != null and configName != ''">#{configName},</if>
<if test="configKey != null and configKey != ''">#{configKey},</if>
<if test="configValue != null and configValue != ''">#{configValue},</if>
<if test="configType != null and configType != ''">#{configType},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate()
)
</insert>
<update id="updateConfig" parameterType="com.ruoyi.system.domain.Config">
UPDATE sys_config
<set>
<if test="configName != null and configName != ''">config_name = #{configName},</if>
<if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
<if test="configValue != null and configValue != ''">config_value = #{configValue},</if>
<if test="configType != null and configType != ''">config_type = #{configType},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
update_time = sysdate()
</set>
WHERE config_id = #{configId}
</update>
<delete id="deleteConfigByIds" parameterType="String">
DELETE FROM sys_config WHERE config_id IN
<foreach item="configId" collection="array" open="(" separator="," close=")">
#{configId}
</foreach>
</delete>
</mapper>
DeptMapper
@Mapper
public interface DeptMapper {
/**
* 查询部门人数
*
* @param dept 部门信息
* @return 结果
*/
int selectDeptCount(Dept dept);
/**
* 查询部门是否存在用户
*
* @param deptId 部门ID
* @return 结果
*/
int checkDeptExistUser(Long deptId);
/**
* 查询部门管理数据
*
* @param dept 部门信息
* @return 部门信息集合
*/
List<Dept> selectDeptList(Dept dept);
/**
* 删除部门管理信息
*
* @param deptId 部门ID
* @return 结果
*/
int deleteDeptById(Long deptId);
/**
* 新增部门信息
*
* @param dept 部门信息
* @return 结果
*/
int insertDept(Dept dept);
/**
* 修改部门信息
*
* @param dept 部门信息
* @return 结果
*/
int updateDept(Dept dept);
/**
* 修改子元素关系
*
* @param depts 子元素
* @return 结果
*/
int updateDeptChildren(@Param("depts") List<Dept> depts);
/**
* 根据部门ID查询信息
*
* @param deptId 部门ID
* @return 部门信息
*/
Dept selectDeptById(Long deptId);
/**
* 校验部门名称是否唯一
*
* @param deptName 部门名称
* @param parentId 父部门ID
* @return 结果
*/
Dept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId);
/**
* 根据角色ID查询部门
*
* @param roleId 角色ID
* @return 部门列表
*/
List<String> selectRoleDeptTree(Long roleId);
/**
* 修改所在部门的父级部门状态
*
* @param dept 部门
*/
void updateDeptStatus(Dept dept);
/**
* 根据ID查询所有子部门
*
* @param id
* @return
*/
List<Dept> selectChildrenDeptById(Long id);
/**
* 根据角色编号查询所有部门ID
*
* @param roleId
* @return
* @author zmr
*/
Set<String> selectRoleDeptIds(Long roleId);
/**
* 清除默认
*/
void clearDefault();
/**
* 查找默认角色
*
* @return 默认角色,若不存在则返回null
*/
Dept findDefault();
}
<?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.ruoyi.system.mapper.DeptMapper">
<resultMap type="com.ruoyi.system.domain.Dept" id="DeptResult">
<id property="deptId" column="dept_id" />
<result property="parentId" column="parent_id" />
<result property="ancestors" column="ancestors" />
<result property="deptName" column="dept_name" />
<result property="orderNum" column="order_num" />
<result property="leader" column="leader" />
<result property="leaderId" column="leader_id" />
<result property="phone" column="phone" />
<result property="email" column="email" />
<result property="status" column="status" />
<result property="isDefault" column="is_default" />
<result property="delFlag" column="del_flag" />
<result property="parentName" column="parent_name" />
<result property="parkId" column="park_id" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectDeptVo">
SELECT d.dept_id,
d.parent_id,
d.ancestors,
d.dept_name,
d.order_num,
d.leader,
d.leader_id,
d.phone,
d.email,
d.status,
d.is_default,
d.del_flag,
d.park_id,
d.create_by,
d.create_time
FROM sys_dept d
</sql>
<select id="selectRoleDeptTree" parameterType="Long" resultType="String">
SELECT concat(d.dept_id, d.dept_name) AS dept_name
FROM sys_dept d
LEFT JOIN sys_role_dept rd ON d.dept_id = rd.dept_id
WHERE d.del_flag = '0'
AND rd.role_id = #{roleId}
ORDER BY d.parent_id, d.order_num
</select>
<select id="selectDeptList" parameterType="com.ruoyi.system.domain.Dept" resultMap="DeptResult">
<include refid="selectDeptVo"/>
WHERE d.del_flag = '0'
<if test="parentId != null and parentId != 0">
AND parent_id = #{parentId}
</if>
<if test="deptName != null and deptName != ''">
AND dept_name like concat('%', #{deptName}, '%')
</if>
<if test="status != null and status != ''">
AND status = #{status}
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
ORDER BY order_num
</select>
<select id="checkDeptExistUser" parameterType="Long" resultType="int">
SELECT COUNT(1) FROM sys_user WHERE dept_id = #{deptId} AND del_flag = '0'
</select>
<select id="selectDeptCount" parameterType="com.ruoyi.system.domain.Dept" resultType="int">
SELECT COUNT(1) FROM sys_dept WHERE del_flag = '0'
<if test="deptId != null and deptId != 0"> AND dept_id = #{deptId} </if>
<if test="parentId != null and parentId != 0"> AND parent_id = #{parentId} </if>
</select>
<select id="checkDeptNameUnique" resultMap="DeptResult">
<include refid="selectDeptVo"/>
WHERE dept_name=#{deptName} AND parent_id = #{parentId}
</select>
<select id="selectDeptById" parameterType="Long" resultMap="DeptResult">
SELECT d.dept_id,
d.parent_id,
d.ancestors,
d.dept_name,
d.order_num,
d.leader,
d.leader_id,
d.phone,
d.email,
d.status,
d.is_default,
(SELECT dept_name FROM sys_dept WHERE dept_id = d.parent_id) parent_name
FROM sys_dept d
WHERE d.dept_id = #{deptId}
</select>
<select id="selectChildrenDeptById" parameterType="Long" resultMap="DeptResult">
SELECT * FROM sys_dept
<where>
FIND_IN_SET(#{id},ancestors)
</where>
</select>
<select id="selectRoleDeptIds" parameterType="Long" resultType="String">
SELECT d.dept_id
FROM sys_dept d
LEFT JOIN sys_role_dept rd ON d.dept_id = rd.dept_id
WHERE d.del_flag = '0'
AND rd.role_id = #{roleId}
ORDER BY d.parent_id, d.order_num
</select>
<select id="findDefault" resultMap="DeptResult">
<include refid="selectDeptVo"/>
WHERE d.is_default = TRUE
</select>
<insert id="insertDept" parameterType="com.ruoyi.system.domain.Dept">
insert into sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="parentId != null and parentId != 0">parent_id,</if>
<if test="deptName != null and deptName != ''">dept_name,</if>
<if test="ancestors != null and ancestors != ''">ancestors,</if>
<if test="orderNum != null and orderNum != ''">order_num,</if>
<if test="leader != null and leader != ''">leader,</if>
<if test="leaderId != null">leader_id,</if>
<if test="phone != null and phone != ''">phone,</if>
<if test="email != null and email != ''">email,</if>
<if test="status != null">status,</if>
<if test="isDefault != null">is_default,</if>
<if test="parkId != null">park_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="deptId != null and deptId != 0">#{deptId},</if>
<if test="parentId != null and parentId != 0">#{parentId},</if>
<if test="deptName != null and deptName != ''">#{deptName},</if>
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
<if test="orderNum != null and orderNum != ''">#{orderNum},</if>
<if test="leader != null and leader != ''">#{leader},</if>
<if test="leaderId != null">#{leaderId},</if>
<if test="phone != null and phone != ''">#{phone},</if>
<if test="email != null and email != ''">#{email},</if>
<if test="status != null">#{status},</if>
<if test="isDefault != null">#{isDefault},</if>
<if test="parkId != null">#{parkId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateDept" parameterType="com.ruoyi.system.domain.Dept">
UPDATE sys_dept
<set>
<if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
<if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
<if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
<if test="leader != null">leader = #{leader},</if>
<if test="leaderId != null">leader_id = #{leaderId},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="email != null">email = #{email},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="isDefault != null ">is_default = #{isDefault},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE dept_id = #{deptId}
</update>
<update id="updateDeptChildren" parameterType="java.util.List">
UPDATE sys_dept SET ancestors =
<foreach collection="depts" item="item" index="index" separator=" " open="case dept_id" close="end">
WHEN #{item.deptId} THEN #{item.ancestors}
</foreach>
WHERE dept_id IN
<foreach collection="depts" item="item" index="index" separator="," open="(" close=")">
#{item.deptId}
</foreach>
</update>
<delete id="deleteDeptById" parameterType="Long">
UPDATE sys_dept SET del_flag = '2' WHERE dept_id = #{deptId}
</delete>
<update id="updateDeptStatus" parameterType="com.ruoyi.system.domain.Dept">
UPDATE sys_dept
<set>
<if test="status != null and status != ''">status = #{status},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE dept_id IN (${ancestors})
</update>
<update id="clearDefault">
UPDATE sys_dept SET is_default = FALSE WHERE is_default = TRUE
</update>
</mapper>
DistrictsMapper
/**
* 地区 数据层
*
* @author ruoyi
* @date 2018-12-19
*/
@Mapper
public interface DistrictsMapper {
/**
* 查询地区信息
*
* @param id 地区ID
* @return 地区信息
*/
Districts selectDistrictsById(Integer id);
/**
* 查询地区列表
*
* @return 地区集合
*/
List<DistrictsVO> selectDistrictsVOList();
/**
* 查询地区列表
*
* @param districts 地区信息
* @return 地区集合
*/
List<Districts> selectDistrictsList(Districts districts);
/**
* 查询地区列表
*
* @param ids 地区信息
* @return 地区集合
*/
List<Districts> selectDistrictsByIds(List<Integer> ids);
/**
* 新增地区
*
* @param districts 地区信息
* @return 结果
*/
int insertDistricts(Districts districts);
/**
* 修改地区
*
* @param districts 地区信息
* @return 结果
*/
int updateDistricts(Districts districts);
/**
* 删除地区
*
* @param id 地区ID
* @return 结果
*/
int deleteDistrictsById(Integer id);
/**
* 批量删除地区
*
* @param ids 需要删除的数据ID
* @return 结果
*/
int deleteDistrictsByIds(String[] ids);
}
<?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.ruoyi.system.mapper.DistrictsMapper">
<resultMap type="Districts" id="DistrictsResult">
<result property="id" column="id" />
<result property="pid" column="pid" />
<result property="deep" column="deep" />
<result property="name" column="name" />
<result property="pname" column="pname" />
<result property="pinyin" column="pinyin" />
<result property="pinyinShor" column="pinyin_shor" />
<result property="extName" column="ext_name" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="operator" column="operator" />
</resultMap>
<sql id="selectDistrictsVo">
SELECT d.id,
d.pid,
d.deep,
d.name,
d.pinyin,
d.pinyin_shor,
d.ext_name,
d.create_time,
d.update_time,
d.operator,
p.name AS pname
FROM sys_districts d
LEFT JOIN sys_districts p ON d.pid = p.id
</sql>
<select id="selectDistrictsList" parameterType="Districts" resultMap="DistrictsResult">
<include refid="selectDistrictsVo"/>
<where>
<if test="id != null "> AND d.id = #{id}</if>
<if test="pid != null "> AND d.pid = #{pid}</if>
<if test="deep != null "> AND d.deep = #{deep}</if>
<if test="name != null and name != '' "> AND d.name LIKE concat('%',#{name},'%')</if>
<if test="pinyin != null and pinyin != '' "> AND d.pinyin = #{pinyin}</if>
<if test="pinyinShor != null and pinyinShor != '' "> AND d.pinyin_shor = #{pinyinShor}</if>
<if test="createTime != null "> AND d.create_time >= #{createTime}</if>
<if test="updateTime != null "> AND d.update_time <= #{updateTime}</if>
<if test="operator != null and operator != '' "> AND operator = #{operator}</if>
</where>
</select>
<select id="selectDistrictsById" parameterType="Integer" resultMap="DistrictsResult">
<include refid="selectDistrictsVo"/>
WHERE d.id = #{id}
</select>
<select id="selectDistrictsVOList" resultType="com.ruoyi.system.domain.vo.DistrictsVO">
SELECT d.id AS value,
d.pid,
d.name AS label
FROM sys_districts d
</select>
<select id="selectDistrictsByIds" resultMap="DistrictsResult" parameterType="list">
<include refid="selectDistrictsVo"/>
WHERE d.id IN
<foreach item="id" collection="list" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertDistricts" parameterType="Districts">
INSERT INTO sys_districts
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null ">id,</if>
<if test="pid != null ">pid,</if>
<if test="deep != null ">deep,</if>
<if test="name != null and name != '' ">name,</if>
<if test="pinyin != null and pinyin != '' ">pinyin,</if>
<if test="pinyinShor != null and pinyinShor != '' ">pinyin_shor,</if>
<if test="extName != null and extName != '' ">ext_name,</if>
<if test="createTime != null ">create_time,</if>
<if test="updateTime != null ">update_time,</if>
<if test="operator != null and operator != '' ">operator,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null ">#{id},</if>
<if test="pid != null ">#{pid},</if>
<if test="deep != null ">#{deep},</if>
<if test="name != null and name != '' ">#{name},</if>
<if test="pinyin != null and pinyin != '' ">#{pinyin},</if>
<if test="pinyinShor != null and pinyinShor != '' ">#{pinyinShor},</if>
<if test="extName != null and extName != '' ">#{extName},</if>
<if test="createTime != null ">#{createTime},</if>
<if test="updateTime != null ">#{updateTime},</if>
<if test="operator != null and operator != '' ">#{operator},</if>
</trim>
</insert>
<update id="updateDistricts" parameterType="Districts">
UPDATE sys_districts
<trim prefix="SET" suffixOverrides=",">
<if test="pid != null ">pid = #{pid},</if>
<if test="deep != null ">deep = #{deep},</if>
<if test="name != null and name != '' ">name = #{name},</if>
<if test="pinyin != null and pinyin != '' ">pinyin = #{pinyin},</if>
<if test="pinyinShor != null and pinyinShor != '' ">pinyin_shor = #{pinyinShor},</if>
<if test="extName != null and extName != '' ">ext_name = #{extName},</if>
<if test="createTime != null ">create_time = #{createTime},</if>
<if test="updateTime != null ">update_time = #{updateTime},</if>
<if test="operator != null and operator != '' ">operator = #{operator},</if>
</trim>
WHERE id = #{id}
</update>
<delete id="deleteDistrictsById" parameterType="Integer">
DELETE FROM sys_districts WHERE id = #{id}
</delete>
<delete id="deleteDistrictsByIds" parameterType="String">
DELETE FROM sys_districts WHERE id IN
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
LoginInfoMapper
**
* 系统访问日志情况信息 数据层
*
* @author ruoyi
*/
@Mapper
public interface LoginInfoMapper {
/**
* 新增系统登录日志
*
* @param loginInfo 访问日志对象
*/
void insertLoginInfo(LoginInfo loginInfo);
/**
* 查询系统登录日志集合
*
* @param loginInfo 访问日志对象
* @return 登录记录集合
*/
List<LoginInfo> selectLoginInfoList(LoginInfo loginInfo);
/**
* 批量删除系统登录日志
*
* @param ids 需要删除的数据
* @return 结果
*/
int deleteLoginInfoByIds(String[] ids);
/**
* 清空系统登录日志
*
* @return 结果
*/
int cleanLoginInfo();
}
<?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.ruoyi.system.mapper.LoginInfoMapper">
<resultMap type="com.ruoyi.system.domain.LoginInfo" id="LoginInfoResult">
<id property="infoId" column="info_id" />
<result property="loginName" column="login_name" />
<result property="status" column="status" />
<result property="ipaddr" column="ipaddr" />
<result property="loginLocation" column="login_location" />
<result property="browser" column="browser" />
<result property="os" column="os" />
<result property="msg" column="msg" />
<result property="loginTime" column="login_time" />
</resultMap>
<insert id="insertLoginInfo" parameterType="com.ruoyi.system.domain.LoginInfo">
INSERT INTO sys_login_info (login_name, status, ipaddr, login_location, browser, os, msg, login_time)
VALUES (#{loginName}, #{status}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, #{msg}, sysdate())
</insert>
<select id="selectLoginInfoList" parameterType="com.ruoyi.system.domain.LoginInfo" resultMap="LoginInfoResult">
SELECT info_id,
login_name,
ipaddr,
login_location,
browser,
os,
status,
msg,
login_time
FROM sys_login_info
<where>
<if test="ipaddr != null and ipaddr != ''">
AND ipaddr LIKE concat('%', #{ipaddr}, '%')
</if>
<if test="status != null and status != ''">
AND status = #{status}
</if>
<if test="loginName != null and loginName != ''">
AND login_name LIKE concat('%', #{loginName}, '%')
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(login_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(login_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d')
</if>
</where>
</select>
<delete id="deleteLoginInfoByIds" parameterType="String">
DELETE FROM sys_login_info WHERE info_id IN
<foreach collection="array" item="infoId" open="(" separator="," close=")">
#{infoId}
</foreach>
</delete>
<update id="cleanLoginInfo">
TRUNCATE TABLE sys_login_info
</update>
</mapper>
MenuMapper
/**
* 菜单表 数据层
*
* @author ruoyi
*/
@Mapper
public interface MenuMapper {
/**
* 查询系统所有菜单(含按钮)
*
* @return 菜单列表
*/
List<Menu> selectMenuAll();
/**
* 查询系统正常显示菜单(不含按钮)
*
* @return 菜单列表
*/
List<Menu> selectMenuNormalAll();
/**
* 根据用户ID查询菜单
*
* @param userId 用户
* @return 菜单列表
*/
List<Menu> selectMenusByUserId(Long userId);
/**
* 根据用户ID查询权限
*
* @param userId 用户ID
* @return 权限列表
*/
List<String> selectPermsByUserId(Long userId);
/**
* 根据角色ID查询菜单
*
* @param roleId 角色ID
* @return 权限列表
*/
List<Menu> selectMenuIdsByRoleId(Long roleId);
/**
* 根据角色ID查询菜单
*
* @param roleId 角色ID
* @return 菜单列表
*/
List<String> selectMenuTree(Long roleId);
/**
* 查询系统菜单列表
*
* @param menu 菜单信息
* @return 菜单列表
*/
List<Menu> selectMenuList(Menu menu);
/**
* 删除菜单管理信息
*
* @param menuId 菜单ID
* @return 结果
*/
int deleteMenuById(Long menuId);
/**
* 根据菜单ID查询信息
*
* @param menuId 菜单ID
* @return 菜单信息
*/
Menu selectMenuById(Long menuId);
/**
* 查询菜单数量
*
* @param parentId 菜单父ID
* @return 结果
*/
int selectCountMenuByParentId(Long parentId);
/**
* 新增菜单信息
*
* @param menu 菜单信息
* @return 结果
*/
int insertMenu(Menu menu);
/**
* 修改菜单信息
*
* @param menu 菜单信息
* @return 结果
*/
int updateMenu(Menu menu);
/**
* 校验菜单名称是否唯一
*
* @param menuName 菜单名称
* @param parentId 父菜单ID
* @return 结果
*/
Menu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId);
}
<?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.ruoyi.system.mapper.MenuMapper">
<resultMap type="com.ruoyi.system.domain.Menu" id="MenuResult">
<id property="menuId" column="menu_id" />
<result property="menuName" column="menu_name" />
<result property="parentName" column="parent_name" />
<result property="parentId" column="parent_id" />
<result property="orderNum" column="order_num" />
<result property="menuType" column="menu_type" />
<result property="target" column="target" />
<result property="menuKey" column="menu_key" />
<result property="component" column="component" />
<result property="visible" column="visible" />
<result property="perms" column="perms" />
<result property="icon" column="icon" />
<result property="path" column="path" />
<result property="redirect" column="redirect" />
<result property="hiddenChildren" column="hidden_children" />
<result property="hiddenHeader" column="hidden_header" />
<result property="parkId" column="park_id" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="updateBy" column="update_by" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectMenuVo">
SELECT menu_id,
menu_name,
parent_id,
target,
order_num,
menu_type,
menu_key,
component,
visible,
ifnull(perms, '') AS perms,
icon,
path,
redirect,
hidden_children,
hidden_header,
create_by,
create_time
FROM sys_menu m
</sql>
<select id="selectMenusByUserId" parameterType="Long" resultMap="MenuResult">
SELECT DISTINCT m.menu_id,
m.parent_id,
m.menu_name,
m.perms,
m.menu_type,
m.menu_key,
m.component,
m.target,
m.icon,
m.path,
m.redirect,
m.hidden_children,
m.hidden_header,
m.order_num,
m.visible,
m.create_time
FROM sys_menu m
LEFT JOIN sys_role_menu rm ON m.menu_id = rm.menu_id
LEFT JOIN sys_user_role ur ON rm.role_id = ur.role_id
LEFT JOIN sys_role ro ON ur.role_id = ro.role_id
WHERE ur.user_id = #{userId}
AND m.menu_type IN ('M', 'C')
AND ro.status = 0
AND length(m.menu_key) > 0
ORDER BY m.order_num
</select>
<select id="selectMenuNormalAll" resultMap="MenuResult">
SELECT DISTINCT m.menu_id,
m.parent_id,
m.menu_name,
m.menu_key,
m.component,
m.target,
m.visible,
m.perms,
m.menu_type,
m.icon,
m.path,
m.redirect,
m.hidden_children,
m.hidden_header,
m.order_num,
m.create_time
FROM sys_menu m
WHERE m.menu_type IN ('M', 'C')
AND length(m.menu_key) > 0
ORDER BY m.order_num
</select>
<select id="selectMenuAll" resultMap="MenuResult">
<include refid="selectMenuVo" />
<!-- 数据范围过滤 -->
${params.dataScope}
ORDER BY order_num
</select>
<select id="selectPermsByUserId" parameterType="Long" resultType="String">
SELECT DISTINCT m.perms
FROM sys_menu m
LEFT JOIN sys_role_menu rm ON m.menu_id = rm.menu_id
LEFT JOIN sys_user_role ur ON rm.role_id = ur.role_id
WHERE ur.user_id = #{userId}
</select>
<select id="selectMenuIdsByRoleId" parameterType="Long" resultMap="MenuResult">
SELECT DISTINCT m.menu_id, m.parent_id
FROM sys_menu m
LEFT JOIN sys_role_menu rm ON m.menu_id = rm.menu_id
WHERE rm.role_id = #{roleId}
</select>
<select id="selectMenuTree" parameterType="Long" resultType="String">
SELECT concat(m.menu_id, ifnull(m.perms, '')) AS perms
FROM sys_menu m
LEFT JOIN sys_role_menu rm ON m.menu_id = rm.menu_id
WHERE rm.role_id = #{roleId}
ORDER BY m.parent_id, m.order_num
</select>
<select id="selectMenuList" parameterType="com.ruoyi.system.domain.Menu" resultMap="MenuResult">
<include refid="selectMenuVo" />
<where>
<if test="menuKey != null and menuKey != ''">
AND menu_key=#{menuKey}
</if>
<if test="menuName != null and menuName != ''">
AND menu_name like concat('%', #{menuName}, '%')
</if>
<if test="visible != null and visible != ''">
AND visible = #{visible}
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
</where>
ORDER BY order_num
</select>
<delete id="deleteMenuById" parameterType="Long">
DELETE FROM sys_menu WHERE menu_id = #{menuId} OR parent_id = #{menuId}
</delete>
<select id="selectMenuById" parameterType="Long" resultMap="MenuResult">
SELECT t.menu_id,
t.parent_id,
t.menu_name,
t.order_num,
t.target,
t.menu_type,
t.visible,
t.perms,
t.icon,
t.path,
t.redirect,
t.hidden_children,
t.hidden_header,
t.remark,
(SELECT menu_name FROM sys_menu WHERE menu_id = t.parent_id) parent_name
FROM sys_menu t
WHERE t.menu_id = #{menuId}
</select>
<select id="selectCountMenuByParentId" resultType="Integer">
SELECT count(1) FROM sys_menu WHERE parent_id = #{menuId}
</select>
<select id="checkMenuNameUnique" parameterType="com.ruoyi.system.domain.Menu" resultMap="MenuResult">
<include refid="selectMenuVo" />
WHERE menu_name=#{menuName} AND parent_id = #{parentId}
</select>
<update id="updateMenu" parameterType="com.ruoyi.system.domain.Menu">
UPDATE sys_menu
<set>
<if test="menuName != null and menuName != ''">menu_name = #{menuName},</if>
<if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
<if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
<if test="menuType != null and menuType != ''">menu_type = #{menuType},</if>
<if test="target != null">target = #{target},</if>
<if test="menuKey != null and menuKey != ''">menu_key = #{menuKey},</if>
<if test="component != null">component = #{component},</if>
<if test="visible != null">visible = #{visible},</if>
<if test="perms !=null">perms = #{perms},</if>
<if test="icon !=null and icon != ''">icon = #{icon},</if>
<if test="path !=null">path = #{path},</if>
<if test="redirect !=null">redirect = #{redirect},</if>
<if test="hiddenChildren !=null">hidden_children = #{hiddenChildren},</if>
<if test="hiddenHeader !=null">hidden_header = #{hiddenHeader},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE menu_id = #{menuId}
</update>
<insert id="insertMenu" parameterType="com.ruoyi.system.domain.Menu">
INSERT INTO sys_menu(
<if test="menuId != null and menuId != 0">menu_id,</if>
<if test="parentId != null and parentId != 0">parent_id,</if>
<if test="menuName != null and menuName != ''">menu_name,</if>
<if test="orderNum != null and orderNum != ''">order_num,</if>
<if test="menuType != null and menuType != ''">menu_type,</if>
<if test="target != null and target != ''">target,</if>
<if test="menuKey != null and menuKey != ''">menu_key,</if>
<if test="component != null and component != ''">component ,</if>
<if test="visible != null">visible,</if>
<if test="perms !=null and perms != ''">perms,</if>
<if test="icon != null and icon != ''">icon,</if>
<if test="path !=null and path != ''">path,</if>
<if test="redirect !=null and redirect != ''">redirect,</if>
<if test="hiddenChildren !=null">hidden_children,</if>
<if test="hiddenHeader !=null">hidden_header,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="parkId != null">park_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
<if test="menuId != null and menuId != 0">#{menuId},</if>
<if test="parentId != null and parentId != 0">#{parentId},</if>
<if test="menuName != null and menuName != ''">#{menuName},</if>
<if test="orderNum != null and orderNum != ''">#{orderNum},</if>
<if test="menuType != null and menuType != ''">#{menuType},</if>
<if test="target != null and target != ''">#{target},</if>
<if test="menuKey != null and menuKey != ''">#{menuKey},</if>
<if test="component != null and component != ''">#{component},</if>
<if test="visible != null">#{visible},</if>
<if test="perms !=null and perms != ''">#{perms},</if>
<if test="icon != null and icon != ''">#{icon},</if>
<if test="path !=null and path != ''">#{path},</if>
<if test="redirect !=null and redirect != ''">#{redirect},</if>
<if test="hiddenChildren !=null">#{hiddenChildren},</if>
<if test="hiddenHeader !=null">#{hiddenHeader},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="parkId != null">#{parkId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
</mapper>
NoticeMapper
/**
* 公告 数据层
*
* @author ruoyi
*/
@Mapper
public interface NoticeMapper {
/**
* 查询公告信息
*
* @param noticeId 公告ID
* @return 公告信息
*/
Notice selectNoticeById(Long noticeId);
/**
* 查询公告列表
*
* @param notice 公告信息
* @return 公告集合
*/
List<Notice> selectNoticeList(Notice notice);
/**
* 新增公告
*
* @param notice 公告信息
* @return 结果
*/
int insertNotice(Notice notice);
/**
* 修改公告
*
* @param notice 公告信息
* @return 结果
*/
int updateNotice(Notice notice);
/**
* 批量删除公告
*
* @param noticeIds 需要删除的数据ID
* @return 结果
*/
int deleteNoticeByIds(String[] noticeIds);
}
<?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.ruoyi.system.mapper.NoticeMapper">
<resultMap type="com.ruoyi.system.domain.Notice" id="NoticeResult">
<result property="noticeId" column="notice_id"/>
<result property="noticeTitle" column="notice_title"/>
<result property="noticeType" column="notice_type"/>
<result property="noticeContent" column="notice_content"/>
<result property="status" column="status"/>
<result property="parkId" column="park_id" />
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectNoticeVo">
SELECT
notice_id,
notice_title,
notice_type,
notice_content,
status,
park_id,
create_by,
create_time,
update_by,
update_time,
remark
FROM sys_notice n
</sql>
<select id="selectNoticeById" parameterType="Long" resultMap="NoticeResult">
<include refid="selectNoticeVo"/>
WHERE notice_id = #{noticeId}
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectNoticeList" parameterType="com.ruoyi.system.domain.Notice" resultMap="NoticeResult">
<include refid="selectNoticeVo"/>
<where>
<if test="noticeTitle != null and noticeTitle != ''">
AND notice_title like concat('%', #{noticeTitle}, '%')
</if>
<if test="noticeType != null and noticeType != ''">
AND notice_type = #{noticeType}
</if>
<if test="createBy != null and createBy != ''">
AND create_by like concat('%', #{createBy}, '%')
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
</where>
</select>
<insert id="insertNotice" parameterType="com.ruoyi.system.domain.Notice">
INSERT INTO sys_notice (
<if test="noticeTitle != null and noticeTitle != '' ">notice_title,</if>
<if test="noticeType != null and noticeType != '' ">notice_type,</if>
<if test="noticeContent != null and noticeContent != '' ">notice_content,</if>
<if test="status != null and status != '' ">status,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="parkId != null">park_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
<if test="noticeTitle != null and noticeTitle != ''">#{noticeTitle},</if>
<if test="noticeType != null and noticeType != ''">#{noticeType},</if>
<if test="noticeContent != null and noticeContent != ''">#{noticeContent},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="parkId != null">#{parkId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateNotice" parameterType="com.ruoyi.system.domain.Notice">
UPDATE sys_notice
<set>
<if test="noticeTitle != null and noticeTitle != ''">notice_title = #{noticeTitle},</if>
<if test="noticeType != null and noticeType != ''">notice_type = #{noticeType},</if>
<if test="noticeContent != null">notice_content = #{noticeContent},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE notice_id = #{noticeId}
</update>
<delete id="deleteNoticeByIds" parameterType="String">
DELETE FROM sys_notice WHERE notice_id IN
<foreach item="noticeId" collection="array" open="(" separator="," close=")">
#{noticeId}
</foreach>
</delete>
</mapper>
RoleDeptMapper
/**
* 角色与部门关联表 数据层
*
* @author ruoyi
*/
@Mapper
public interface RoleDeptMapper {
/**
* 通过角色ID删除角色和部门关联
*
* @param roleId 角色ID
* @return 结果
*/
int deleteRoleDeptByRoleId(Long roleId);
/**
* 批量删除角色部门关联信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
int deleteRoleDept(Long[] ids);
/**
* 查询部门使用数量
*
* @param deptId 部门ID
* @return 结果
*/
int selectCountRoleDeptByDeptId(Long deptId);
/**
* 批量新增角色部门信息
*
* @param roleDeptList 角色部门列表
* @return 结果
*/
int batchRoleDept(List<RoleDept> roleDeptList);
}
<?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.ruoyi.system.mapper.RoleDeptMapper">
<resultMap type="com.ruoyi.system.domain.RoleDept" id="SysRoleDeptResult">
<result property="roleId" column="role_id"/>
<result property="deptId" column="dept_id"/>
</resultMap>
<delete id="deleteRoleDeptByRoleId" parameterType="Long">
DELETE FROM sys_role_dept WHERE role_id=#{roleId}
</delete>
<select id="selectCountRoleDeptByDeptId" resultType="Integer">
SELECT COUNT(1) FROM sys_role_dept WHERE dept_id=#{deptId}
</select>
<delete id="deleteRoleDept" parameterType="Long">
DELETE FROM sys_role_dept WHERE role_id IN
<foreach collection="array" item="roleId" open="(" separator="," close=")">
#{roleId}
</foreach>
</delete>
<insert id="batchRoleDept">
INSERT INTO sys_role_dept(role_id, dept_id) VALUES
<foreach item="item" index="index" collection="list" separator=",">
(#{item.roleId},#{item.deptId})
</foreach>
</insert>
</mapper>
RoleMapper
/**
* 角色表 数据层
*
* @author ruoyi
*/
@Mapper
public interface RoleMapper {
/**
* 根据条件分页查询角色数据
*
* @param role 角色信息
* @return 角色数据集合信息
*/
List<Role> selectRoleList(Role role);
/**
* 根据用户ID查询角色
*
* @param userId 用户ID
* @return 角色列表
*/
List<Role> selectRolesByUserId(Long userId);
/**
* 通过角色ID查询角色
*
* @param roleId 角色ID
* @return 角色对象信息
*/
Role selectRoleById(Long roleId);
/**
* 通过角色ID删除角色
*
* @param roleId 角色ID
* @return 结果
*/
int deleteRoleById(Long roleId);
/**
* 批量角色用户信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
int deleteRoleByIds(Long[] ids);
/**
* 修改角色信息
*
* @param role 角色信息
* @return 结果
*/
int updateRole(Role role);
/**
* 新增角色信息
*
* @param role 角色信息
* @return 结果
*/
int insertRole(Role role);
/**
* 校验角色名称是否唯一
*
* @param roleName 角色名称
* @return 角色信息
*/
Role checkRoleNameUnique(String roleName);
/**
* 校验角色权限是否唯一
*
* @param roleKey 角色权限
* @return 角色信息
*/
Role checkRoleKeyUnique(String roleKey);
/**
* 清除默认
*/
void clearDefault();
/**
* 查找默认角色
*
* @return 默认角色,若不存在则返回null
*/
Role findDefault();
}
<?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.ruoyi.system.mapper.RoleMapper">
<resultMap type="com.ruoyi.system.domain.Role" id="RoleResult">
<id property="roleId" column="role_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="isDefault" column="is_default" />
<result property="delFlag" column="del_flag" />
<result property="parkId" column="park_id" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectRoleContactVo">
SELECT DISTINCT r.role_id,
r.role_name,
r.role_key,
r.role_sort,
r.data_scope,
r.status,
r.is_default,
r.del_flag,
r.park_id,
r.create_time,
r.remark
FROM sys_role r
LEFT JOIN sys_user_role ur
ON ur.role_id = r.role_id
LEFT JOIN sys_user u
ON u.user_id = ur.user_id
LEFT JOIN sys_dept d
ON u.dept_id = d.dept_id
</sql>
<sql id="selectRoleVo">
SELECT r.role_id,
r.role_name,
r.role_key,
r.role_sort,
r.data_scope,
r.status,
r.is_default,
r.del_flag,
r.create_time,
r.remark
FROM sys_role r
</sql>
<select id="selectRoleList" parameterType="com.ruoyi.system.domain.Role" resultMap="RoleResult">
<include refid="selectRoleContactVo"/>
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="dataScope != null and dataScope != ''">
AND r.data_scope = #{dataScope}
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(r.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
</if>
<if test="parkId != null and parkId != ''">
AND r.park_id = #{parkId }
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectRolesByUserId" parameterType="Long" resultMap="RoleResult">
<include refid="selectRoleContactVo"/>
WHERE r.del_flag = '0' AND ur.user_id = #{userId}
</select>
<select id="selectRoleById" parameterType="Long" resultMap="RoleResult">
<include refid="selectRoleVo"/>
WHERE r.del_flag = '0' AND r.role_id = #{roleId}
</select>
<select id="checkRoleNameUnique" parameterType="String" resultMap="RoleResult">
<include refid="selectRoleVo"/>
WHERE r.role_name=#{roleName}
</select>
<select id="checkRoleKeyUnique" parameterType="String" resultMap="RoleResult">
<include refid="selectRoleVo"/>
WHERE r.role_key=#{roleKey}
</select>
<select id="findDefault" resultMap="RoleResult">
<include refid="selectRoleVo"/>
WHERE r.is_default = TRUE
</select>
<delete id="deleteRoleById" parameterType="Long">
DELETE FROM sys_role WHERE role_id = #{roleId}
</delete>
<delete id="deleteRoleByIds" parameterType="Long">
UPDATE sys_role SET del_flag = '2' WHERE role_id IN
<foreach collection="array" item="roleId" open="(" separator="," close=")">
#{roleId}
</foreach>
</delete>
<insert id="insertRole" parameterType="com.ruoyi.system.domain.Role" useGeneratedKeys="true" keyProperty="roleId">
INSERT INTO sys_role(
<if test="roleId != null and roleId != 0">role_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="isDefault != null">is_default,</if>
<if test="parkId != null">park_id,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
<if test="roleId != null and roleId != 0">#{roleId},</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="isDefault != null">#{isDefault},</if>
<if test="parkId != null">#{parkId},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateRole" parameterType="com.ruoyi.system.domain.Role">
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="isDefault != null ">is_default = #{isDefault},</if>
<if test="parkId != null ">park_id = #{parkId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE role_id = #{roleId}
</update>
<update id="clearDefault">
UPDATE sys_role SET is_default = FALSE WHERE is_default = TRUE
</update>
</mapper>
RoleMenuMapper
/**
* 角色与菜单关联表 数据层
*
* @author ruoyi
*/
@Mapper
public interface RoleMenuMapper {
/**
* 通过角色ID删除角色和菜单关联
*
* @param roleId 角色ID
* @return 结果
*/
int deleteRoleMenuByRoleId(Long roleId);
/**
* 批量删除角色菜单关联信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
int deleteRoleMenu(Long[] ids);
/**
* 查询菜单使用数量
*
* @param menuId 菜单ID
* @return 结果
*/
int selectCountRoleMenuByMenuId(Long menuId);
/**
* 批量新增角色菜单信息
*
* @param roleMenuList 角色菜单列表
* @return 结果
*/
int batchRoleMenu(List<RoleMenu> roleMenuList);
}
<?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.ruoyi.system.mapper.RoleMenuMapper">
<resultMap type="com.ruoyi.system.domain.RoleMenu" id="SysRoleMenuResult">
<result property="roleId" column="role_id" />
<result property="menuId" column="menu_id" />
</resultMap>
<delete id="deleteRoleMenuByRoleId" parameterType="Long">
DELETE FROM sys_role_menu WHERE role_id=#{roleId}
</delete>
<select id="selectCountRoleMenuByMenuId" resultType="Integer">
SELECT COUNT(1) FROM sys_role_menu WHERE menu_id=#{menuId}
</select>
<delete id="deleteRoleMenu" parameterType="Long">
DELETE FROM sys_role_menu WHERE role_id IN
<foreach collection="array" item="roleId" open="(" separator="," close=")">
#{roleId}
</foreach>
</delete>
<insert id="batchRoleMenu">
INSERT INTO sys_role_menu(role_id, menu_id) VALUES
<foreach item="item" index="index" collection="list" separator=",">
(#{item.roleId}, #{item.menuId})
</foreach>
</insert>
</mapper>
SnMapper
/**
* 序列号Mapper接口
*
* @author ruoyi
* @date 2020-05-12
*/
@Mapper
public interface SnMapper {
/**
* 查询序列号
*
* @param type 序列号类型
* @return 序列号
*/
Sn selectSnByType(Sn.Type type);
/**
* 修改序列号
*
* @param sn 序列号
* @return 结果
*/
int updateSn(Sn sn);
}
<?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.ruoyi.system.mapper.SnMapper">
<resultMap type="Sn" id="SnResult">
<result property="id" column="id" />
<result property="type" column="type"
typeHandler="com.ruoyi.common.handlers.MybatisEnumTypeHandler"/>
<result property="lastValue" column="last_value" />
<result property="version" column="version" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectSnVo">
SELECT id, type, last_value, version, create_time, update_time FROM sys_sn
</sql>
<select id="selectSnByType" resultMap="SnResult">
<include refid="selectSnVo"/>
WHERE `type` = #{type}
</select>
<update id="updateSn" parameterType="Sn">
UPDATE sys_sn
<trim prefix="SET" suffixOverrides=",">
<if test="lastValue != null ">last_value = #{lastValue},</if>
<if test="version != null ">version = #{version} + 1,</if>
<if test="updateTime != null ">update_time = #{updateTime},</if>
</trim>
WHERE
id = #{id}
AND version = #{version}
</update>
</mapper>