Blame view

src/main/resources/mybatis/system/DeptMapper.xml 7.57 KB
tangying authored
1
2
3
4
5
6
<?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">
mahuandong authored
7
	<resultMap type="com.huaheng.pc.system.dept.domain.Dept" id="DeptResult">
tangying authored
8
9
10
11
12
13
14
15
16
17
18
19
20
21
		<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" />
22
		<result column="maintenanceDate" jdbcType="TIMESTAMP" property="maintenanceDate" />
tangying authored
23
	</resultMap>
xcq authored
24
tangying authored
25
	<sql id="selectDeptVo">
26
        select t.id, t.parentId, t.ancestors, t.code, t.deptName, t.orderNum, t.leader, t.phone, t.email, t.enable, t.createBy, t.createTime, t.maintenanceDate from sys_dept t
tangying authored
27
28
29
30
31
    </sql>

	<select id="selectDeptAll" resultMap="DeptResult">
		<include refid="selectDeptVo"/>
	</select>
xcq authored
32
mahuandong authored
33
	<select id="selectDeptList" parameterType="com.huaheng.pc.system.dept.domain.Dept" resultMap="DeptResult">
tangying authored
34
35
36
37
38
39
40
41
42
43
        <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>
xcq authored
44
tangying authored
45
46
47
	<select id="checkDeptExistUser" parameterType="Integer" resultType="int">
		select count(1) from sys_user where deptId = #{deptId} and deleted=0
	</select>
xcq authored
48
mahuandong authored
49
	<select id="selectDeptCount" parameterType="com.huaheng.pc.system.dept.domain.Dept" resultType="int">
tangying authored
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
		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>
xcq authored
78
tangying authored
79
80
81
82
83
84
	<select id="checkDeptNameUnique" parameterType="String" resultMap="DeptResult">
	    <include refid="selectDeptVo"/>
		where deptName=#{deptName}
	</select>

	<select id="selectDeptById" parameterType="Integer" resultMap="DeptResult">
xcq authored
85
		select t.id, t.parentId, t.ancestors, t.deptName, t.orderNum, t.leader, t.phone, t.email, t.enable,t.code,
tangying authored
86
87
88
89
			(select deptName from sys_dept where id = t.parentId) parent_name
		from sys_dept t
		where id = #{id}
	</select>
xcq authored
90
mahuandong authored
91
	<insert id="insertDept" parameterType="com.huaheng.pc.system.dept.domain.Dept">
tangying authored
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
 		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>
xcq authored
118
mahuandong authored
119
	<update id="updateDept" parameterType="com.huaheng.pc.system.dept.domain.Dept">
tangying authored
120
121
122
123
124
125
126
127
128
129
130
131
 		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>
132
 			<if test='maintenanceDate != null and maintenanceDate != ""'>maintenanceDate = #{maintenanceDate},</if>
tangying authored
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
 			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>
xcq authored
149
tangying authored
150
151
152
153
154
155
156
	<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>
xcq authored
157
tangying authored
158
159
160
161
162
	<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>
163
164
		<if test='updateTime != null '>updateTime,</if>
		<if test='maintenanceDate != null'>maintenanceDate</if>
tangying authored
165
166
167
168
		)values(
		<if test='code != null and code != ""'>#{code},</if>
		<if test='deptName != null and deptName != ""'>#{deptName},</if>
		<if test='createTime != null '>#{createTime},</if>
169
170
		<if test='updateTime != null '>#{updateTime},</if>
		<if test='maintenanceDate != null '>#{maintenanceDate}</if>
tangying authored
171
172
173
		)
	</insert>
174
175
176
177
178
179
180
181
182
183
184
185
	<update id="updateDepts" parameterType="com.huaheng.pc.system.dept.domain.Dept">
		update sys_dept
		<set>
			<if test='deptName != null and deptName !=" " '>deptName = #{deptName},</if>
			<if test='maintenanceDate != null'>maintenanceDate = #{maintenanceDate}</if>
		</set>
		<where>
			<if test="id != null">
				id = #{id}
			</if>
		</where>
	</update>
xcq authored
186
</mapper>