admin
昨天 768498719683f85e5ed19c73eb3d14cdbf420df4
提交 | 用户 | 时间
e57a89 1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE mapper
3         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5 <mapper namespace="com.jcdm.system.mapper.SysDeptMapper">
6
7     <resultMap type="SysDept" id="SysDeptResult">
8         <id     property="deptId"     column="dept_id"     />
9         <result property="parentId"   column="parent_id"   />
10         <result property="ancestors"  column="ancestors"   />
11         <result property="deptName"   column="dept_name"   />
12         <result property="orderNum"   column="order_num"   />
13         <result property="leader"     column="leader"      />
14         <result property="phone"      column="phone"       />
15         <result property="email"      column="email"       />
16         <result property="status"     column="status"      />
17         <result property="delFlag"    column="del_flag"    />
18         <result property="parentName" column="parent_name" />
19         <result property="createBy"   column="create_by"   />
20         <result property="createTime" column="create_time" />
21         <result property="updateBy"   column="update_by"   />
22         <result property="updateTime" column="update_time" />
23     </resultMap>
24
25     <sql id="selectDeptVo">
26         select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
27         from sys_dept d
28     </sql>
29
30     <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
31         <include refid="selectDeptVo"/>
32         where d.del_flag = '0'
33         <if test="deptId != null and deptId != 0">
34             AND dept_id = #{deptId}
35         </if>
36         <if test="parentId != null and parentId != 0">
37             AND parent_id = #{parentId}
38         </if>
39         <if test="deptName != null and deptName != ''">
40             AND dept_name like concat('%', #{deptName}, '%')
41         </if>
42         <if test="status != null and status != ''">
43             AND status = #{status}
44         </if>
45         <!-- 数据范围过滤 -->
46         ${params.dataScope}
47         order by d.parent_id, d.order_num
48     </select>
49
50     <select id="selectDeptListByRoleId" resultType="Long">
51         select d.dept_id
52         from sys_dept d
53         left join sys_role_dept rd on d.dept_id = rd.dept_id
54         where rd.role_id = #{roleId}
55         <if test="deptCheckStrictly">
56             and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId})
57         </if>
58         order by d.parent_id, d.order_num
59     </select>
60
61     <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
62         select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
63                (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
64         from sys_dept d
65         where d.dept_id = #{deptId}
66     </select>
67
68     <select id="checkDeptExistUser" parameterType="Long" resultType="int">
69         select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
70     </select>
71
72     <select id="hasChildByDeptId" parameterType="Long" resultType="int">
73         select top(1) count(1) from sys_dept
74         where del_flag = '0' and parent_id = #{deptId}
75     </select>
76
77     <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
78         select * from sys_dept where charindex(',' + convert(nvarchar, #{deptId}), ',' + ancestors) > 0
79     </select>
80
81     <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
82         select count(*) from sys_dept where status = 0 and del_flag = '0' and charindex(',' + convert(nvarchar, #{deptId}), ',' + ancestors) > 0
83     </select>
84
85     <select id="checkDeptNameUnique" resultMap="SysDeptResult">
86         select top(1) d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
87         from sys_dept d
88         where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0'
89     </select>
90
91     <insert id="insertDept" parameterType="SysDept">
92         insert into sys_dept(
93         <if test="deptId != null and deptId != 0">dept_id,</if>
94         <if test="parentId != null and parentId != 0">parent_id,</if>
95         <if test="deptName != null and deptName != ''">dept_name,</if>
96         <if test="ancestors != null and ancestors != ''">ancestors,</if>
97         <if test="orderNum != null">order_num,</if>
98         <if test="leader != null and leader != ''">leader,</if>
99         <if test="phone != null and phone != ''">phone,</if>
100         <if test="email != null and email != ''">email,</if>
101         <if test="status != null">status,</if>
102         <if test="createBy != null and createBy != ''">create_by,</if>
103         create_time
104         )values(
105         <if test="deptId != null and deptId != 0">#{deptId},</if>
106         <if test="parentId != null and parentId != 0">#{parentId},</if>
107         <if test="deptName != null and deptName != ''">#{deptName},</if>
108         <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
109         <if test="orderNum != null">#{orderNum},</if>
110         <if test="leader != null and leader != ''">#{leader},</if>
111         <if test="phone != null and phone != ''">#{phone},</if>
112         <if test="email != null and email != ''">#{email},</if>
113         <if test="status != null">#{status},</if>
114         <if test="createBy != null and createBy != ''">#{createBy},</if>
115         getdate()
116         )
117     </insert>
118
119     <update id="updateDept" parameterType="SysDept">
120         update sys_dept
121         <set>
122             <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
123             <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
124             <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
125             <if test="orderNum != null">order_num = #{orderNum},</if>
126             <if test="leader != null">leader = #{leader},</if>
127             <if test="phone != null">phone = #{phone},</if>
128             <if test="email != null">email = #{email},</if>
129             <if test="status != null and status != ''">status = #{status},</if>
130             <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
131             update_time = getdate()
132         </set>
133         where dept_id = #{deptId}
134     </update>
135
136     <update id="updateDeptChildren" parameterType="java.util.List">
137         update sys_dept set ancestors =
138         <foreach collection="depts" item="item" index="index"
139                  separator=" " open="case dept_id" close="end">
140             when #{item.deptId} then #{item.ancestors}
141         </foreach>
142         where dept_id in
143         <foreach collection="depts" item="item" index="index"
144                  separator="," open="(" close=")">
145             #{item.deptId}
146         </foreach>
147     </update>
148
149     <update id="updateDeptStatusNormal" parameterType="Long">
150         update sys_dept set status = '0' where dept_id in
151         <foreach collection="array" item="deptId" open="(" separator="," close=")">
152             #{deptId}
153         </foreach>
154     </update>
155
156     <delete id="deleteDeptById" parameterType="Long">
157         update sys_dept set del_flag = '2' where dept_id = #{deptId}
158     </delete>
159
160 </mapper>