EmployeeMapper.xml 10.6 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.EmployeeMapper" >
  <resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Employee" >
    <id column="emId" property="id" />
    <result column="emCode" property="code"/>
    <result column="emName" property="name"/>
    <result column="emSex" property="sex"/>
    <result column="emExtId" property="extid"/>
    <result column="coId" property="coid" />
    <result column="emEntryDate" property="entrydate"/>
    <result column="emLeaveDate" property="leavedate"/>
    <result column="ptEmail" property="email"/>
    <result column="ptPhone" property="phone"/>
    <result column="emCtType" property="cttype" />
    <result column="emCtCode" property="ctcode" />
    <result column="emRelman" property="relman" />
    <result column="emRelTel" property="reltel" />
    <result column="ptPost" property="post" />
    <result column="diId" property="diid"/>
    <result column="ptAddr" property="addr"/>
    <result column="emLostPhone" property="lostphone"/>
    <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" />
    
    <association property="cou" javaType="cn.runsa.portal.base.entity.Country">
    	<id column="coId" property="id" />
    	<result column="coName" property="name"/>
    </association>
    
    <association property="pro" javaType="cn.runsa.portal.base.entity.Province">
    	<id column="prId" property="id" />
    	<result column="prName" property="name"/>
    </association>
    
    <association property="city" javaType="cn.runsa.portal.base.entity.City">
    	<id column="ciId" property="id" />
    	<result column="ciName" property="name"/>
    </association>
    
    <association property="corp" javaType="cn.runsa.portal.base.entity.Corp">
    	<id column="coId" property="id" />
    	<result column="coName" property="name"/>
    </association>
    
    <collection property="pld" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.EmployeeDept">
    	<id column="emId"  property="id"/>
    	<result column="deId" property="deid" />
    </collection>
    
    <collection property="plp" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.EmployeePost">
    	<id column="emId"  property="id"/>
    	<result column="poId" property="poid" />
    </collection>
    
    <collection property="uname" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Username">
    	<id column="usnId"  property="id"/>
    	<result column="usnName" property="name" />
    	<result column="usnType" property="type" />
    	<result column="usnValid" property="valid" />
    </collection>
    
    <collection property="depts" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Dept">
    	<id column="deId"  property="id"/>
    	<result column="deName" property="name" />
    </collection>
    
    <collection property="posts" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Post">
    	<id column="poId"  property="id"/>
    	<result column="poName" property="name" />
    </collection>
    
    <collection property="users" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Users">
    	<id column="usId"  property="id"/>
    </collection>
  </resultMap>
  
  <select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
	 	SELECT
		t1.emId,
		t1.emCode,
		t1.emName,
		t1.emEntryDate,
		t1.emLeaveDate,
		t1.emCtType,
		t1.emCtCode,
		t1.emRelman,
		t1.emRelTel,
		t1.emSex,
		t1.ptPost,
		t1.diId,
		t1.ptAddr,
		t1.ptRemark1,
		t2.coId,
		t2.coName,
		t4.deId,
		t4.deName,
		t6.poId,
		t6.poName,
		t7.usnId,
		t7.usnType,
		t7.usnName,
		t7.usnValid,
		t10.usId
		FROM
			mtEmployee t1
		LEFT JOIN mtCorp t2 ON t2.coId = t1.coId
		LEFT JOIN mtEmployeeDept t3 ON t3.emId = t1.emId
		LEFT JOIN mtDept t4 ON t4.deId = t3.deId
		LEFT JOIN mtEmployeePost t5 ON t5.emId = t1.emId
		LEFT JOIN mtPost t6 ON t6.poId = t5.poId
		LEFT JOIN smUsername t7 ON t7.emId = t1.emId
		LEFT JOIN smUsers t10 on t10.emId = t1.emId
		where t1.emId=#{emid}
  </select>
  
  <select id="selectExitEmp" resultMap="BaseResultMap" parameterType="cn.runsa.portal.base.entity.Employee" >
	 	SELECT
		t1.emId,
		t1.emCode,
		t1.emName,
		t1.emEntryDate,
		t1.emLeaveDate,
		t1.emCtType,
		t1.emCtCode,
		t1.emRelman,
		t1.emRelTel,
		t1.emSex,
		t1.ptPost,
		t1.diId,
		t1.ptAddr,
		t1.ptRemark1,
		t2.coId,
		t2.coName,
		t4.deId,
		t4.deName,
		t6.poId,
		t6.poName,
		t7.usnId,
		t7.usnType,
		t7.usnName,
		t7.usnValid,
		t10.usId
		FROM
			mtEmployee t1
		LEFT JOIN mtCorp t2 ON t2.coId = t1.coId
		LEFT JOIN mtEmployeeDept t3 ON t3.emId = t1.emId
		LEFT JOIN mtDept t4 ON t4.deId = t3.deId
		LEFT JOIN mtEmployeePost t5 ON t5.emId = t1.emId
		LEFT JOIN mtPost t6 ON t6.poId = t5.poId
		LEFT JOIN smUsername t7 ON t7.emId = t1.emId
		LEFT JOIN smUsers t10 on t10.emId = t1.emId
		where t1.coId = #{coid} and t1.emCode=#{code} and t1.emName=#{name}
  </select>
  
  <insert id="insertEmp" parameterType="cn.runsa.portal.base.entity.Employee">
	<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
	      SELECT LAST_INSERT_ID()
	</selectKey>
    insert into mtEmployee(emCode,emName,emSex,emExtId
                              ,coId,emEntryDate,emLeaveDate,ptEmail,ptPhone
                              ,emCtType,emCtCode,emRelman,emRelTel,ptPost,diId,ptAddr,emLostPhone,ptRemark1
                              ,ptRemark2,ptRemark3,ptUpTime,ptUpdater)
    values(#{code},#{name},#{sex},#{extid},#{coid},#{entrydate},#{leavedate},#{email},
           #{phone},#{cttype},#{ctcode},#{relman},#{reltel},#{post},
           #{diid},#{addr},#{lostphone},#{remark1},#{remark2},#{remark3},now(),#{updater})
  </insert>
  <insert id="insertEdept" parameterType="cn.runsa.portal.base.entity.Employee">
      insert into mtEmployeeDept (emId,deId) values
      <foreach collection="pld" item="item" separator=",">
         (#{id},#{item.deid})
      </foreach>
  </insert>
  <insert id="insertEpost" parameterType="cn.runsa.portal.base.entity.Employee">
      insert into mtEmployeePost (emId,poId) values
      <foreach collection="plp" item="item" separator=",">
         (#{id},#{item.poid})
      </foreach>
  </insert>
  <insert id="insertUname" parameterType="map">
      insert into smUsername (usId,emId,usnName,usnType) values
      <foreach collection="uname" item="item" separator=",">
         (#{usid},#{emid},#{item.name},#{item.type})
      </foreach>
  </insert>
  
  <update id="updateEmp" parameterType="cn.runsa.portal.base.entity.Employee">
    update mtEmployee set ptUpTime=now(),ptUpdater=#{updater}
    <if test="code!=null and code!=''">
		,emCode=#{code}
	</if>
	<if test="name!=null and name!=''">
		,emName=#{name}
	</if>
		,emSex=#{sex}
		,emExtId=#{extid}
	<if test="coid!=null">
		,coId=#{coid}
	</if>
	<if test="entrydate!=null">
		,emEntryDate=#{entrydate}
	</if>
		,emLeaveDate=#{leavedate}
		,ptEmail=#{email}
		,ptPhone=#{phone}
		,emCtType=#{cttype}
		,emCtCode=#{ctcode}
		,emRelman=#{relman}
		,emRelTel=#{reltel}
		,ptPost=#{post}
		,diId=#{diid}
		,ptAddr=#{addr}
		,emLostPhone=#{lostphone}
		,ptRemark1=#{remark1}
		,ptRemark2=#{remark2}
		,ptRemark3=#{remark3}
     where emId = #{id} 
  </update>
  
  <update id="updateUname" parameterType="map">
      <foreach collection="uname" item="item" separator=",">
      	update smUsername
      	<set>
      		usId=#{usid},usnName=#{item.name},usnType=#{item.type}
      	</set>
         where usnId=#{item.id}
      </foreach>
  </update>
  
  <delete id="deleteDept" parameterType="java.lang.Integer">
     delete from mtEmployeeDept where emId=#{id}
  </delete>
  <delete id="deletePost" parameterType="java.lang.Integer">
     delete from mtEmployeePost where emId=#{id}
  </delete>
  <delete id="deleteUName" parameterType="java.lang.Integer">
     delete from smUsername where emId=#{id}
  </delete>
  <delete id="deleteEmp" parameterType="java.lang.Integer">
     delete from mtEmployee where emId=#{id}
  </delete>
  
  <select id="existsUsers" resultType="java.lang.Integer" parameterType="java.lang.Integer" >
   select 
 		COUNT(*)
   from smUsers
   		where emId = #{id}
 </select>
 
 <select id="selectByDiid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
   select 
 		* 
   from vDistrict
   		where diId = #{id}
 </select>
 
 <select id="existsEmps" resultType="java.lang.Integer" parameterType="cn.runsa.portal.base.entity.Employee">
   select 
 		COUNT(*)
   from mtEmployee
   		where coId = #{coid} and emCode=#{code} and emName=#{name}
 </select>
 
 <select id="existsCode" resultType="java.lang.Integer" parameterType="map">
   select 
 		COUNT(*)
   from mtEmployee
   		where emCode=#{code} and coId=#{coid}
 </select>
 
 <select id="existsCodeAll" resultType="java.lang.Integer" parameterType="map">
   select 
 		COUNT(*)
   from mtEmployee
   		where emCode=#{code}
 </select>
 
 <select id="existsCodeWithPhone" resultType="java.lang.Integer" parameterType="map">
   select 
 		COUNT(*)
   from smUsername
   		where usnName=#{code} and usnType=2
 </select>
 
 <select id="existsCtCode" resultType="java.lang.Integer" parameterType="map">
   select 
 		COUNT(*)
   from mtEmployee
   		where CAST(emCtCode AS CHAR)=#{ctcode} and coId=#{coid}
 </select>
 
 <select id="existsNamePhone" resultType="java.lang.Integer" parameterType="map">
   SELECT
		COUNT(1)
   FROM
		mtEmployee t1
   LEFT JOIN smUsername t2 ON t1.emId = t2.emId
   AND t2.usnType = 2
   AND t2.usnValid = 1
   <if test="coid!=null and coid!=''">
   		AND t1.coId=#{coid}
   </if>
   where t2.usnName=#{name}
 </select>
 
 <select id="existsNameEmail" resultType="java.lang.Integer" parameterType="map">
   SELECT
		COUNT(1)
   FROM
		mtEmployee t1
   LEFT JOIN smUsername t2 ON t1.emId = t2.emId
   AND t2.usnType = 3
   AND t2.usnValid = 1
   <if test="coid!=null and coid!=''">
   		AND t1.coId=#{coid}
   </if>
   where t2.usnName=#{name}
 </select>
 
 <select id="existsNameEmailNoCoid" resultType="java.lang.Integer" parameterType="map">
   SELECT
		COUNT(1)
   FROM
		mtEmployee t1
   LEFT JOIN smUsername t2 ON t1.emId = t2.emId
   AND t2.usnType = 3
   AND t2.usnValid = 1
   where t2.usnName=#{name} and t1.emName=#{emname} and t1.coId!=#{coid}
 </select>
 
 <select id="existsNamePhoneNoCoid" resultType="java.lang.Integer" parameterType="map">
   SELECT
		COUNT(1)
   FROM
		mtEmployee t1
   LEFT JOIN smUsername t2 ON t1.emId = t2.emId
   AND t2.usnType = 2
   AND t2.usnValid = 1
   where t2.usnName=#{name} and t1.emName=#{emname} and t1.coId!=#{coid}
 </select>
 
</mapper>