DeptMapper.xml
4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?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.huaheng.pc.system.dept.mapper.DeptMapper">
<resultMap type="Dept" id="DeptResult">
<id property="id" column="id" />
<result property="parentId" column="parentId" />
<result property="ancestors" column="ancestors" />
<result property="deptName" column="deptName" />
<result property="orderNum" column="orderNum" />
<result property="leader" column="leader" />
<result property="phone" column="phone" />
<result property="email" column="email" />
<result property="enable" column="enable" />
<result property="parentName" column="parent_name" />
<result property="createBy" column="createBy" />
<result property="createTime" column="createTime" />
<result property="updateBy" column="updateBy" />
<result property="updateTime" column="updateTime" />
</resultMap>
<sql id="selectDeptVo">
select t.id, t.parentId, t.ancestors, t.deptName, t.orderNum, t.leader, t.phone, t.email, t.enable, t.createBy, t.createTime from sys_dept t
</sql>
<select id="selectDeptAll" resultMap="DeptResult">
<include refid="selectDeptVo"/>
</select>
<select id="selectDeptList" parameterType="Dept" resultMap="DeptResult">
<include refid="selectDeptVo"/>
<where>
<if test="deptName != null and deptName != ''">
AND deptName like concat('%', #{deptName}, '%')
</if>
<if test="enable != null ">
AND enable = #{enable}
</if>
</where>
</select>
<select id="checkDeptExistUser" parameterType="Integer" resultType="int">
select count(1) from sys_user where id = #{id} and delFlag = '0'
</select>
<select id="selectDeptCount" parameterType="Dept" resultType="int">
select count(1) from sys_dept
<where>
<if test="id != null and id != 0"> and id = #{id} </if>
<if test="parentId != null and parentId != 0"> and parentId = #{parentId} </if>
</where>
</select>
<select id="checkDeptNameUnique" parameterType="String" resultMap="DeptResult">
<include refid="selectDeptVo"/>
where deptName=#{deptName}
</select>
<select id="selectDeptById" parameterType="Integer" resultMap="DeptResult">
select t.id, t.parentId, t.ancestors, t.deptName, t.orderNum, t.leader, t.phone, t.email, t.enable,
(select deptName from sys_dept where id = t.parentId) parent_name
from sys_dept t
where id = #{id}
</select>
<insert id="insertDept" parameterType="Dept">
insert into sys_dept(
<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="phone != null and phone != ''">phone,</if>
<if test="email != null and email != ''">email,</if>
<if test="enable != null">enable,</if>
<if test="createBy != null and createBy != ''">createBy,</if>
createTime
)values(
<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="phone != null and phone != ''">#{phone},</if>
<if test="email != null and email != ''">#{email},</if>
<if test="enable != null">#{enable},</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">parentId = #{parentId},</if>
<if test="deptName != null and deptName != ''">deptName = #{deptName},</if>
<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
<if test="orderNum != null and orderNum != ''">orderNum = #{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="enable != null ">enable = #{enable},</if>
<if test="updateBy != null and updateBy != ''">updateBy = #{updateBy},</if>
updateTime = sysdate()
</set>
where id = #{id}
</update>
<delete id="deleteDeptById" parameterType="Integer">
delete from sys_dept where id = #{id}
</delete>
</mapper>