DeptMapper.xml 6.89 KB
<?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>