UsersMapper.xml 11.4 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.UsersMapper" >
  <resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Users" >
    <id column="usId" property="id" jdbcType="INTEGER" />
    <result column="plId" property="plId" jdbcType="INTEGER" />
    <result column="ptValid" property="valid" jdbcType="BIT" />
    <result column="laId" property="laId" jdbcType="INTEGER" />
    <result column="usStartDate" property="startDate" jdbcType="TIMESTAMP" />
    <result column="usEndDate" property="endDate" jdbcType="TIMESTAMP" />
    <result column="usDataDay" property="dataDay" jdbcType="INTEGER" />
    <result column="usFrozen" property="frozen" jdbcType="SMALLINT" />
    <result column="usLogin" property="usLogin" jdbcType="SMALLINT" />
    <result column="ptUpdater" property="updater" jdbcType="INTEGER" />
    <result column="ptUpTime" property="uptime" jdbcType="TIMESTAMP" />
    <association property="employee" javaType="cn.runsa.portal.base.entity.Employee" column="employee">
    	<id column="emId" property="id"  jdbcType="INTEGER" />
    	<result column="emName" property="name" jdbcType="VARCHAR" />
    	<result column="emCode" property="code" jdbcType="VARCHAR" />
    	<result column="ptPhone" property="phone" jdbcType="VARCHAR" />
    	<result column="ptEmail" property="email" jdbcType="VARCHAR" />
    	<result column="entryFlg" property="entryFlg"  jdbcType="INTEGER" />
    	<result column="emEntryDate" property="entrydate" jdbcType="TIMESTAMP" />
    	<result column="emLeaveDate" property="leavedate" jdbcType="TIMESTAMP" />
    	<result column="emLostPhone" property="lostphone" jdbcType="VARCHAR" />
    </association>
    <association property="platform" javaType="cn.runsa.portal.base.entity.Platform">
    	<id column="plId" property="id" />
    	<result column="plName" property="name"/>
    </association>
    <association property="platType" javaType="cn.runsa.portal.base.entity.PlatformType">
    	<id column="pltId" property="id"/>
    </association>
    <association property="corp" javaType="cn.runsa.portal.base.entity.Corp">
    	<id column="coId" property="id" />
    	<result column="coName" property="name"/>
    </association>
    <association property="dept" javaType="cn.runsa.portal.base.entity.Dept">
    	<id column="deId" property="id" />
    	<result column="deName" property="name"/>
    </association>
  </resultMap>
  <sql id="Base_Column_List" >
    usId, plId, ptValid, emId, laId, usStartDate, usEndDate, usDataDay, 
    usFrozen, ptUpdater, ptUpTime
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from smUsers
    where usId = #{id,jdbcType=INTEGER}
  </select>
  <delete id="delete" parameterType="java.lang.Integer" >
    delete from smUsers
    where usId = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="cn.runsa.portal.base.entity.Users" >
    <selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into smUsers (plId, ptValid, emId, 
      laId, usStartDate, 
      usEndDate, usDataDay, usFrozen, 
      ptUpdater, ptUpTime)
    values (#{plId,jdbcType=INTEGER}, #{valid,jdbcType=BIT}, #{emId,jdbcType=INTEGER}, 
      #{laId,jdbcType=INTEGER}, #{startDate,jdbcType=TIMESTAMP}, 
      #{endDate,jdbcType=TIMESTAMP}, #{dataDay,jdbcType=INTEGER}, #{frozen,jdbcType=SMALLINT}, 
      #{updater,jdbcType=INTEGER}, #{uptime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="cn.runsa.portal.base.entity.Users" >
    insert into smUsers
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="platform.id != null" >
        plId,
      </if>
      <if test="valid != null" >
        ptValid,
      </if>
      <if test="employee.id != null" >
        emId,
      </if>
      <if test="laId != null" >
        laId,
      </if>
      <if test="startDate != null" >
        usStartDate,
      </if>
      <if test="endDate != null" >
        usEndDate,
      </if>
      <if test="dataDay != null" >
        usDataDay,
      </if>
      <if test="frozen != null" >
        usFrozen,
      </if>
      <if test="updater != null" >
        ptUpdater,
      </if>
      <if test="uptime != null" >
        ptUpTime,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="platform.id != null" >
        #{platform.id,jdbcType=INTEGER},
      </if>
      <if test="valid != null" >
        #{valid,jdbcType=BIT},
      </if>
      <if test="employee.id != null" >
        #{employee.id,jdbcType=INTEGER},
      </if>
      <if test="laId != null" >
        #{laId,jdbcType=INTEGER},
      </if>
      <if test="startDate != null" >
        #{startDate,jdbcType=TIMESTAMP},
      </if>
      <if test="endDate != null" >
        #{endDate,jdbcType=TIMESTAMP},
      </if>
      <if test="dataDay != null" >
        #{dataDay,jdbcType=INTEGER},
      </if>
      <if test="frozen != null" >
        #{frozen,jdbcType=SMALLINT},
      </if>
      <if test="updater != null" >
        #{updater,jdbcType=INTEGER},
      </if>
      <if test="uptime != null" >
        #{uptime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateSelective" parameterType="cn.runsa.portal.base.entity.Users" >
    update smUsers
    <set >
      <if test="platform != null and platform.id != null" >
        plId = #{platform.id,jdbcType=INTEGER},
      </if>
      <if test="usLogin != null" >
        usLogin = #{usLogin},
      </if>
      <if test="valid != null" >
        ptValid = #{valid,jdbcType=BIT},
      </if>
      <if test="empid != null" >
        emId = #{empid,jdbcType=INTEGER},
      </if>
      <if test="laId != null" >
        laId = #{laId,jdbcType=INTEGER},
      </if>
      <if test="startDate != null">
        usStartDate = #{startDate,jdbcType=TIMESTAMP},
      </if>
      <if test="endDate != null">
        usEndDate = #{endDate,jdbcType=TIMESTAMP},
      </if>
      <if test="dataDay != null" >
        usDataDay = #{dataDay,jdbcType=INTEGER},
      </if>
      <if test="frozen != null" >
        usFrozen = #{frozen,jdbcType=SMALLINT},
      </if>
      <if test="updater != null" >
        ptUpdater = #{updater,jdbcType=INTEGER},
      </if>
      <if test="uptime != null" >
        ptUpTime = #{uptime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where usId = #{id,jdbcType=INTEGER}
  </update>
  <update id="update" parameterType="cn.runsa.portal.base.entity.Users" >
    update smUsers
    set plId = #{plId,jdbcType=INTEGER},
      ptValid = #{valid,jdbcType=BIT},
      emId = #{employee.id,jdbcType=INTEGER},
      laId = #{laId,jdbcType=INTEGER},
      usStartDate = #{startDate,jdbcType=TIMESTAMP},
      usEndDate = #{endDate,jdbcType=TIMESTAMP},
      usDataDay = #{dataDay,jdbcType=INTEGER},
      usFrozen = #{frozen,jdbcType=SMALLINT},
      ptUpdater = #{updater,jdbcType=INTEGER},
      ptUpTime = #{uptime,jdbcType=TIMESTAMP}
    where usId = #{id,jdbcType=INTEGER}
  </update>
  <select id="existsUsername" parameterType="String" resultType="boolean">
  	select (
	  	select count(1) 
	  	from smUsers t1
	  	inner join smUsername t2 on t1.emId=t2.emId and t2.usnName=#{username} <!-- and t2.usnValid=1  -->
	  	where t1.ptValid=1
  	) + (
  		SELECT count(1) FROM mtEmployee WHERE emCode = #{username}
  	) FROM DUAL
  </select>
  <select id="login" resultMap="BaseResultMap">
  	select t1.*,t4.*,t5.plName,t5.pltId
	from smUsers t1
	inner join smUsername t2 on t1.emId=t2.emId and t2.usnName=#{username} <!-- and t2.usnValid=1  -->
	inner join smPassword t3 on (t1.usId=t3.usId or t1.emId=t3.emId) and t3.pwdCode=#{password}
	left join mtEmployee t4 on t1.emId=t4.emId
	inner join smPlatform t5 on t1.plId=t5.plId
	<if test="ptValid != null">
		and t5.ptValid=#{ptValid,jdbcType=INTEGER}
	</if>
	where t1.ptValid=1 <!-- and t1.usFrozen=0 -->
	UNION
	select t1.*,t4.*,t5.plName,t5.pltId
	from smUsers t1
	inner join smPassword t3 on (t1.usId=t3.usId or t1.emId=t3.emId) and t3.pwdCode=#{password}
	INNER JOIN mtEmployee t4 ON t1.emId = t4.emId AND t4.emCode =#{username}
	inner join smPlatform t5 on t1.plId=t5.plId
	<if test="ptValid != null">
		and t5.ptValid=#{ptValid,jdbcType=INTEGER}
	</if>
	where t1.ptValid=1 <!-- and t1.usFrozen=0 -->
  </select>
  <select id="findById" resultMap="BaseResultMap" parameterType="cn.runsa.portal.base.entity.Users">
  	SELECT
		us.usId,
		em.emName,
		em.emId,
		em.emCode,
		pl.plName,
		pl.plId,
		us.laId,
		us.usStartDate,
		us.usEndDate,
		GROUP_CONCAT(DISTINCT usn.usnName) as ptPhone,
		GROUP_CONCAT(DISTINCT usna.usnName) as ptEmail,
		em.emEntryDate,
		em.emLeaveDate,
		GROUP_CONCAT(lost.usnName) emLostPhone,
		co.coId,
		co.coName,
		GROUP_CONCAT(DISTINCT de.deName) deName,
		us.ptValid,
		us.usFrozen,
		us.usDataDay
	FROM
		smUsers us
	INNER JOIN mtEmployee em ON us.emId = em.emId
	LEFT JOIN mtEmployeeDept emd ON em.emId = emd.emId
	LEFT JOIN mtDept de ON emd.deId = de.deId
	LEFT JOIN smPlatform pl ON us.plId = pl.plId 
	LEFT JOIN mtCorp co ON em.coId = co.coId
	LEFT JOIN smUsername usn ON usn.emId = em.emId AND usn.usnValid =1 AND usn.usnType=2
	LEFT JOIN smUsername usna ON usna.emId = em.emId AND usna.usnValid =1 AND usna.usnType=3
	LEFT JOIN smUsername lost ON lost.emId = em.emId AND lost.usnValid =0 AND lost.usnType=2
	WHERE
		us.usId = #{id,jdbcType=INTEGER}
	GROUP BY
		us.usId
  </select>
  <update id="updateFrozenByUsername">
  	update smUsers t1 
	inner join smUsername t2 on t2.emId=t1.emId
	set t1.usFrozen=#{frozen}
	where t2.usnName = #{username}
  </update>
  <select id="existsPassword" resultType="Boolean" parameterType="java.lang.Integer">
  	 SELECT COUNT(*) FROM smPassword WHERE emId =#{id,jdbcType=INTEGER}
  </select>
  <insert id="insertPassword">
    insert into smPassword (emId, pwdCode )
    values (#{emId},#{password})
  </insert>
  <update id="updatePassword">
  	update smPassword set pwdCode=#{password} 
  	where emId=#{emId}
  </update>
  <select id="verifyPassword" resultType="Boolean">
  	select count(*) from smPassword 
  	where emId=#{emId} and pwdCode=#{password} 
  </select>
  <update id="updatePasswordByUser">
  	update smPassword set pwdCode=#{password} 
  	where emId=(select distinct emId from smUsers where usId=#{usId})
  </update>
  <select id="verifyPasswordByUser" resultType="Boolean">
  	select count(*) 
  	from smPassword 
  	where emId=(select distinct emId from smUsers where usId=#{usId}) and pwdCode=#{password}
  </select>
  <select id="judgeLogin" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  	 SELECT usLogin FROM `smUsers` WHERE usId = #{id,jdbcType=INTEGER}
  </select>

	<select id="selectSysManager" resultMap="BaseResultMap">
		SELECT
		a.usId,
		a.plId,
		a.ptValid,
		a.emId,
		a.laId,
		a.usStartDate,
		a.usEndDate,
		a.usDataDay,
		a.usFrozen,
		a.ptUpdater,
		a.ptUpTime,
		b.emName,
		b.emCode,
		b.ptPhone,
		b.ptEmail,
		b.emEntryDate,
		b.emLeaveDate,
		b.emLostPhone
		FROM smusers a,mtemployee b WHERE a.emId = b.emId AND a.usId = 1 AND
		a.plId = 1
	</select>
	
	<select id="verifyPasswordByUserName" resultType="Boolean">
		select count(*) from smPassword 
		where emId=(select distinct emId from smUsers where usId IN
		<foreach collection="list" item="item" index="index" separator="," open="(" close=")">  
			#{item.emid,jdbcType=INTEGER}
		</foreach>
		and pwdCode=#{password}
	</select>
</mapper>