DeptMapper.xml
6.89 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?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="com.huaheng.pc.system.dept.domain.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="com.huaheng.pc.system.dept.domain.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 deptId = #{deptId} and deleted=0
</select>
<select id="selectDeptCount" parameterType="com.huaheng.pc.system.dept.domain.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>
<update id="updatesDept" parameterType="com.huaheng.pc.system.dept.domain.Dept">
update sys_dept
<set>
<if test='code != null and code != "0"'>code = #{code},</if>
<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>
<if test="id != null">
id = #{id}
</if>
</where>
</update>
<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="com.huaheng.pc.system.dept.domain.Dept">
insert into sys_dept(
<if test='code != null and code != ""'>code,</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="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='code != null and code != ""'>#{code},</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="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="com.huaheng.pc.system.dept.domain.Dept">
update sys_dept
<set>
<if test='code != null and code != "0"'>code = #{code},</if>
<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>
<if test="id != null">
id = #{id}
</if>
<if test="code != null">
code = #{code}
</if>
</where>
</update>
<!--where id = #{id}-->
<delete id="deleteDeptById" parameterType="Integer">
delete from sys_dept where id = #{id}
</delete>
<select id="selectDeptId" parameterType="String" resultType="java.lang.Integer">
select id from sys_dept where code = #{code}
</select>
<select id="selectDepts" parameterType="String" resultType="com.huaheng.pc.system.dept.domain.Dept">
select * from sys_dept where code = #{code}
</select>
<insert id="insertDepts" parameterType="com.huaheng.pc.system.dept.domain.Dept" >
insert into sys_dept(
<if test='code != null and code != ""'>code,</if>
<if test='deptName != null and deptName != ""'>deptName,</if>
<if test='createTime != null '>createTime,</if>
<if test='updateTime != null '>updateTime</if>
)values(
<if test='code != null and code != ""'>#{code},</if>
<if test='deptName != null and deptName != ""'>#{deptName},</if>
<if test='createTime != null '>#{createTime},</if>
<if test='updateTime != null '>#{updateTime}</if>
)
</insert>
</mapper>