DeptMapper.xml 6.67 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="cn.runsa.portal.base.dao.DeptMapper">
	<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Dept">
		<id column="deId" property="id" jdbcType="INTEGER" />
		<result column="coId" property="coid" jdbcType="INTEGER" />
		<result column="deName" property="name" jdbcType="VARCHAR" />
		<result column="deLevel" property="level" jdbcType="INTEGER" />
		<result column="deParent" property="parent" jdbcType="INTEGER" />
		<result column="deSort" property="sort" jdbcType="INTEGER" />
		<result column="ptRemark1" property="remark1" jdbcType="VARCHAR" />
		<result column="ptRemark2" property="remark2" jdbcType="VARCHAR" />
		<result column="ptRemark3" property="remark3" jdbcType="VARCHAR" />
		<result column="ptUpTime" property="uptime" jdbcType="TIMESTAMP" />
		<result column="ptUpdater" property="updater" jdbcType="INTEGER" />
	</resultMap>
	<sql id="Base_Column_List">
		deId, coId, deName, deLevel, deParent, deSort, ptRemark1,
		ptRemark2,
		ptRemark3, ptUpTime,
		ptUpdater
	</sql>
	<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
		select
		<include refid="Base_Column_List" />
		from mtdept
		where deId = #{id,jdbcType=INTEGER}
	</select>

	<delete id="deleteById" parameterType="java.lang.Integer">
		delete from mtdept
		where
		deId = #{id,jdbcType=INTEGER}
	</delete>

	<insert id="insertDept" parameterType="cn.runsa.portal.base.entity.Dept">
		<selectKey resultType="java.lang.Integer" keyProperty="id"
			order="AFTER">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into mtdept (coId, deName,
		deLevel, deParent, deSort,
		ptRemark1,
		ptRemark2, ptRemark3,
		ptUpTime, ptUpdater)
		values
		(#{coid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
		#{level,jdbcType=INTEGER}, #{parent,jdbcType=INTEGER},
		#{sort,jdbcType=INTEGER},
		#{remark1,jdbcType=VARCHAR},
		#{remark2,jdbcType=VARCHAR}, #{remark3,jdbcType=VARCHAR},
		now(),
		#{updater,jdbcType=INTEGER})
	</insert>

	<update id="updateById" parameterType="cn.runsa.portal.base.entity.Dept">
		update mtdept set deName = #{name,jdbcType=VARCHAR},deParent =
		#{parent,jdbcType=INTEGER},ptUpTime=now()
		<if test="level != null">
			,deLevel = #{level,jdbcType=INTEGER}
		</if>
		<if test="sort != null">
			,deSort = #{sort,jdbcType=INTEGER}
		</if>
		<if test="remark1 != null">
			,ptRemark1 = #{remark1,jdbcType=VARCHAR}
		</if>
		<if test="remark2 != null">
			,ptRemark2 = #{remark2,jdbcType=VARCHAR}
		</if>
		<if test="remark3 != null">
			,ptRemark3 = #{remark3,jdbcType=VARCHAR}
		</if>
		<if test="updater != null">
			,ptUpdater = #{updater,jdbcType=INTEGER}
		</if>
		where deId = #{id,jdbcType=INTEGER}
	</update>

	<select id="selectDeptsByPid" resultMap="BaseResultMap"
		useCache="true">
		select
		<include refid="Base_Column_List" />
		from mtdept
		where coId = #{coid,jdbcType=INTEGER}
		<if test="pid!=null and pid!=''">
			AND deParent = #{pid,jdbcType=INTEGER}
		</if>
		<if test="pid==null or pid==''">
			AND deParent IS NULL
		</if>
		ORDER BY deSort
	</select>

	<select id="existsDeName" resultType="Boolean"
		parameterType="cn.runsa.portal.base.entity.Dept">
		SELECT COUNT(*) FROM mtdept WHERE coId = #{coid} AND deName = #{name}
		<if test="id!=null and id!=''">
			AND deId != #{id}
		</if>
	</select>

	<select id="selectDeptIdsByPid" resultType="java.lang.Integer"
		parameterType="java.lang.Integer">
		select deId
		from mtDeptInfo
		where deParent =
		#{pid,jdbcType=INTEGER}
	</select>

	<delete id="deleteByIds" parameterType="java.util.List">
		delete from mtdept
		where
		deId IN
		<foreach item="item" collection="list" separator="," open="("
			close=")" index="">
			#{item}
		</foreach>
	</delete>

	<delete id="deleteDeptInfoByIds" parameterType="java.util.List">
		delete from mtDeptInfo
		where
		deId IN
		<foreach item="item" collection="list" separator="," open="("
			close=")" index="">
			#{item}
		</foreach>
	</delete>

	<select id="existsEmployee" resultType="Boolean" parameterType="java.util.List">
		SELECT COUNT(*) FROM mtEmployeeDept WHERE deId IN
		<foreach item="item" collection="list" separator="," open="("
			close=")" index="">
			#{item}
		</foreach>
	</select>

	<insert id="insertDeptInfo" parameterType="cn.runsa.portal.base.entity.Dept">
		insert into mtDeptInfo
		(deId,deParent,deLevel) SELECT #{id},deParent,deLevel FROM mtdeptinfo
		WHERE deId = #{parent}
	</insert>

	<insert id="insertDeptInfoSelf">
		insert into mtDeptInfo (deId,deParent,deLevel) values
		(#{deId},#{deId},#{deLevel})
	</insert>

	<select id="selectMaxLevel" resultType="java.lang.Integer"
		parameterType="java.lang.Integer">
		select MAX(deLevel) FROM mtDeptInfo where deId =
		#{deId,jdbcType=INTEGER}
	</select>

	<select id="selectMaxSort" resultType="java.lang.Integer">
		SELECT MAX(deSort) FROM mtdept WHERE coId = #{coid,jdbcType=INTEGER}
		<if test="pid!=null and pid!=''">
			AND deParent = #{pid,jdbcType=INTEGER}
		</if>
		<if test="pid==null or pid==''">
			AND deParent IS NULL
		</if>
	</select>

	<select id="selectPreviousDept" resultMap="BaseResultMap"
		parameterType="cn.runsa.portal.base.entity.Dept">
		select
		<include refid="Base_Column_List" />
		from mtdept
		where deSort = (SELECT MAX(deSort) FROM mtdept where deSort <![CDATA[<]]>
		#{sort,jdbcType=INTEGER}
		<if test="parent!=null and parent!=''">
			AND deParent = #{parent,jdbcType=INTEGER}
		</if>
		<if test="parent==null or parent==''">
			AND deParent IS NULL
		</if>
		ORDER BY deSort)
		<if test="parent!=null and parent!=''">
			AND deParent = #{parent,jdbcType=INTEGER}
		</if>
		<if test="parent==null or parent==''">
			AND deParent IS NULL
		</if>
		AND coId = #{coid,jdbcType=INTEGER}
	</select>

	<select id="selectNextDept" resultMap="BaseResultMap"
		parameterType="cn.runsa.portal.base.entity.Dept">
		select
		<include refid="Base_Column_List" />
		from mtdept
		where deSort = (SELECT MIN(deSort) FROM mtdept where deSort <![CDATA[>]]>
		#{sort,jdbcType=INTEGER}
		<if test="parent!=null and parent!=''">
			AND deParent = #{parent,jdbcType=INTEGER}
		</if>
		<if test="parent==null or parent==''">
			AND deParent IS NULL
		</if>
		ORDER BY deSort)
		<if test="parent!=null and parent!=''">
			AND deParent = #{parent,jdbcType=INTEGER}
		</if>
		<if test="parent==null or parent==''">
			AND deParent IS NULL
		</if>
		AND coId = #{coid,jdbcType=INTEGER}
	</select>

	<delete id="deleteEmployeeDeptById">
		delete from mtEmployeeDept where deId =
		#{deId,jdbcType=INTEGER} AND emId = #{emId,jdbcType=INTEGER}
	</delete>
	
	<insert id="insertEmployeeDept">
		INSERT INTO mtemployeedept(emId,deId) VALUES (#{emId,jdbcType=INTEGER},#{deId,jdbcType=INTEGER})
	</insert>
</mapper>