PostMapper.xml 5.03 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.PostMapper">
	<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Post">
		<id column="poId" property="id" />
		<result column="deId" property="deid" />
		<result column="poCode" property="code" />
		<result column="poName" property="name" />
		<result column="poSort" property="sort" />
		<result column="ptRemark1" property="remark1" />
		<result column="ptRemark2" property="remark2" />
		<result column="ptRemark3" property="remark3" />
		<result column="ptUpTime" property="uptime" />
		<result column="ptUpdater" property="updater" />
	</resultMap>
	<select id="selectByDeId" resultMap="BaseResultMap"
		parameterType="java.lang.String">
		SELECT poId,poName
		FROM
		mtPost
		where deId in
		<foreach item="item" index="index" collection="array" open="("
			separator="," close=")">
			#{item}
		</foreach>
		order by poSort ASC
	</select>

	<sql id="Base_Column_List">
		poId, deId, poCode, poName, poSort, ptRemark1, ptRemark2,
		ptRemark3,
		ptUpTime, ptUpdater
	</sql>

	<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
		select
		<include refid="Base_Column_List" />
		from mtPost
		where poId = #{id,jdbcType=INTEGER}
	</select>

	<insert id="insertPost" parameterType="cn.runsa.portal.base.entity.Post">
		<selectKey resultType="java.lang.Integer" keyProperty="id"
			order="AFTER">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into mtPost (deId, poCode,
		poName, poSort, ptRemark1,
		ptRemark2,
		ptRemark3, ptUpTime,
		ptUpdater)
		values (#{deid,jdbcType=INTEGER},
		#{code,jdbcType=VARCHAR},
		#{name,jdbcType=VARCHAR},
		#{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.Post">
		update mtPost set poName = #{name,jdbcType=VARCHAR},ptUpTime = now()
		<if test="code != null">
			,poCode = #{code,jdbcType=VARCHAR}
		</if>
		<if test="sort != null">
			,poSort = #{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 poId = #{id,jdbcType=INTEGER}
	</update>

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

	<select id="existsPoName" resultType="Boolean" parameterType="cn.runsa.portal.base.entity.Post">
		SELECT COUNT(a.deId) FROM mtpost a,mtdept b WHERE a.deId = b.deId AND
		b.coId = #{coId,jdbcType=INTEGER} AND a.poName =
		#{name,jdbcType=VARCHAR}
		<if test="id!=null and id!=''">
			AND a.poId != #{id}
		</if>
	</select>
	
	<select id="existsPoCode" resultType="Boolean" parameterType="cn.runsa.portal.base.entity.Post">
		SELECT COUNT(a.deId) FROM mtpost a,mtdept b WHERE a.deId = b.deId AND
		b.coId = #{coId,jdbcType=INTEGER} AND a.poCode =
		#{code,jdbcType=VARCHAR}
		<if test="id!=null and id!=''">
			AND a.poId != #{id}
		</if>
	</select>

	<select id="existsEmployee" resultType="Boolean"
		parameterType="cn.runsa.portal.base.entity.Post">
		SELECT COUNT(*) FROM mtEmployeePost WHERE poId = #{poId}
	</select>

	<select id="existsEmployeeBydeIds" resultType="Boolean"
		parameterType="java.util.List">
		SELECT COUNT(b.emId) FROM mtpost a,mtemployeepost b
		WHERE a.poId =
		b.poId AND a.deId IN
		<foreach item="item" collection="list" separator="," open="("
			close=")" index="">
			#{item}
		</foreach>
	</select>

	<select id="selectMaxSort" resultType="java.lang.Integer">
		SELECT MAX(poSort) FROM
		mtpost WHERE deId = #{deId,jdbcType=INTEGER}
	</select>

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

	<select id="selectPreviousPost" resultMap="BaseResultMap"
		parameterType="cn.runsa.portal.base.entity.Post">
		SELECT
		<include refid="Base_Column_List" />
		FROM mtpost WHERE poSort = ( SELECT MAX(poSort) FROM mtpost
		WHERE
		poSort <![CDATA[<]]>
		#{sort,jdbcType=INTEGER} ) AND deId = #{deid,jdbcType=INTEGER} ORDER
		BY poSort
	</select>

	<select id="selectNextPost" resultMap="BaseResultMap"
		parameterType="cn.runsa.portal.base.entity.Post">
		SELECT
		<include refid="Base_Column_List" />
		FROM mtpost WHERE poSort = ( SELECT MIN(poSort) FROM mtpost
		WHERE
		poSort <![CDATA[>]]>
		#{sort,jdbcType=INTEGER} ) AND deId = #{deid,jdbcType=INTEGER} ORDER
		BY poSort
	</select>

	<delete id="deleteEmployeePostBydeId">
		delete from mtEmployeePost WHERE emId = #{emId,jdbcType=INTEGER}
		AND poId IN (SELECT poId FROM mtpost WHERE #{deId,jdbcType=INTEGER})
	</delete>
</mapper>