133 lines
5.6 KiB
XML
Raw Normal View History

2018-07-09 08:44:52 +08:00
<?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.project.system.dept.mapper.DeptMapper">
<resultMap type="Dept" id="DeptResult">
<id property="deptId" column="dept_id" />
<result property="parentId" column="parent_id" />
2018-08-07 22:28:11 +08:00
<result property="ancestors" column="ancestors" />
2018-07-09 08:44:52 +08:00
<result property="deptName" column="dept_name" />
<result property="orderNum" column="order_num" />
<result property="leader" column="leader" />
<result property="phone" column="phone" />
<result property="email" column="email" />
<result property="status" column="status" />
<result property="parentName" column="parent_name" />
<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">
2018-08-07 22:28:11 +08:00
select t.dept_id, t.parent_id, t.ancestors, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status, t.create_by, t.create_time from sys_dept t
2018-07-09 08:44:52 +08:00
</sql>
<select id="selectDeptAll" resultMap="DeptResult">
<include refid="selectDeptVo"/>
</select>
<select id="selectDeptList" parameterType="Dept" resultMap="DeptResult">
<include refid="selectDeptVo"/>
<where>
2018-08-14 11:56:41 +08:00
<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>
</where>
</select>
2018-07-09 08:44:52 +08:00
<select id="checkDeptExistUser" parameterType="Long" resultType="int">
2018-08-06 11:42:15 +08:00
select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
2018-07-09 08:44:52 +08:00
</select>
<select id="selectDeptCount" parameterType="Dept" resultType="int">
2018-08-06 11:42:15 +08:00
select count(1) from sys_dept
2018-07-09 08:44:52 +08:00
<where>
<if test="deptId != null and deptId != 0"> and dept_id = #{deptId} </if>
<if test="parentId != null and parentId != 0"> and parent_id = #{parentId} </if>
</where>
</select>
<select id="checkDeptNameUnique" parameterType="String" resultMap="DeptResult">
<include refid="selectDeptVo"/>
where dept_name=#{deptName}
</select>
<select id="selectDeptById" parameterType="Long" resultMap="DeptResult">
2018-08-07 22:28:11 +08:00
select t.dept_id, t.parent_id, t.ancestors, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status,
2018-07-09 08:44:52 +08:00
(select dept_name from sys_dept where dept_id = t.parent_id) parent_name
from sys_dept t
where dept_id = #{deptId}
</select>
<insert id="insertDept" parameterType="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>
2018-08-07 22:28:11 +08:00
<if test="ancestors != null and ancestors != ''">ancestors,</if>
2018-07-09 08:44:52 +08:00
<if test="orderNum != null and orderNum != ''">order_num,</if>
<if test="leader != null and leader != ''">leader,</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="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>
2018-08-07 22:28:11 +08:00
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
2018-07-09 08:44:52 +08:00
<if test="orderNum != null and orderNum != ''">#{orderNum},</if>
<if test="leader != null and leader != ''">#{leader},</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="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateDept" parameterType="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>
2018-08-07 22:28:11 +08:00
<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
2018-07-09 08:44:52 +08:00
<if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
<if test="leader != null and leader != ''">leader = #{leader},</if>
<if test="phone != null and phone != ''">phone = #{phone},</if>
<if test="email != null and email != ''">email = #{email},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
2018-07-23 20:34:01 +08:00
where dept_id = #{deptId}
2018-07-09 08:44:52 +08:00
</update>
2018-08-14 11:56:41 +08:00
<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>
2018-07-09 08:44:52 +08:00
<delete id="deleteDeptById" parameterType="Long">
delete from sys_dept where dept_id = #{deptId}
</delete>
</mapper>