UsernameMapper.xml 4.14 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.UsernameMapper" >
  <resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Username" >
  	<id column="usnId" property="id"></id>
    <result column="usId" property="usid" jdbcType="INTEGER" />
    <result column="usnName" property="name" jdbcType="VARCHAR" />
    <result column="usnType" property="type" jdbcType="SMALLINT" />
    <result column="emId" property="emid" jdbcType="INTEGER" />
    <result column="usnValid" property="valid" jdbcType="BIT" />
  </resultMap>
  <insert id="insert" parameterType="cn.runsa.portal.base.entity.Username" >
    insert into smUsername (usId, usnName, usnType, 
      emId, usnValid)
    values (#{usid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=SMALLINT}, 
      #{emid,jdbcType=INTEGER}, #{valid,jdbcType=BIT})
  </insert>
  <insert id="insertSelective" parameterType="cn.runsa.portal.base.entity.Username" >
    insert into smUsername
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="usid != null" >
        usId,
      </if>
      <if test="name != null" >
        usnName,
      </if>
      <if test="type != null" >
        usnType,
      </if>
      <if test="emid != null" >
        emId,
      </if>
      <if test="valid != null" >
        usnValid,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="usid != null" >
        #{usid,jdbcType=INTEGER},
      </if>
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        #{type,jdbcType=SMALLINT},
      </if>
      <if test="emid != null" >
        #{emid,jdbcType=INTEGER},
      </if>
      <if test="valid != null" >
        #{valid,jdbcType=BIT},
      </if>
    </trim>
  </insert>
  <update id="updateValid" parameterType="cn.runsa.portal.base.entity.Username" >
  	update smUsername set usnValid = #{valid,jdbcType=BIT} where usnName = #{name,jdbcType=VARCHAR}
  </update>
  <select id="selectAll" parameterType="cn.runsa.portal.base.entity.Username" resultMap="BaseResultMap">
  	select * from smUsername
  	<where>
  		<if test="emid != null">
  			and emId = #{emid}
  		</if>
  		<if test="type != null">
  			and usnType = #{type}
  		</if>
  		<if test="name != null">
  			and usnName = #{name}
  		</if>
  		<if test="valid != null">
  			and usnValid = #{valid}
  		</if>
  	</where>
  	order by emId asc,usnType asc
  </select>
  <select id="selectAllByUsername" resultMap="BaseResultMap">
  	SELECT t1.* FROM smUsername t1
	INNER JOIN smUsername t2 ON t1.emId=t2.emId and t2.usnName=#{username}
	INNER JOIN mtEmployee t3 on t1.emId=t3.emId and now() between ifnull(t3.emEntryDate,now()) and ifnull(t3.emLeaveDate,now())
	WHERE t1.usnValid=1 and exists(
	    SELECT 1 FROM smUsers 
	    WHERE emId=t1.emId AND now() between ifnull(usStartDate,now()) and ifnull(usEndDate,now()) AND ptValid=1 AND usFrozen=0
	)
	<if test="null!=type">
  		AND t1.usnType=#{type}
  	</if>
	ORDER BY usnType DESC
  </select>
  <select id="existsByName" resultType="java.lang.Integer" parameterType="cn.runsa.portal.base.entity.Username">
	SELECT count(*) FROM smUsername usn 
	LEFT JOIN smUsers us ON us.emId = usn.emId 
	WHERE usn.usnType=#{type} AND usn.usnName =#{name,jdbcType=VARCHAR} AND usn.usnValid = #{valid,jdbcType=BIT}
  </select>
  <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  	SELECT t1.* FROM smUsername t1 where usnId=#{id}
  </select>
  
  <select id="selectPhoneOrEmailByUsername" resultMap="BaseResultMap">
  	SELECT t1.* FROM smUsername t1
	INNER JOIN smUsername t2 ON t1.emId=t2.emId and t2.usnName=#{username}
	INNER JOIN mtEmployee t3 on t1.emId=t3.emId and now() between ifnull(t3.emEntryDate,now()) and ifnull(t3.emLeaveDate,now())
	WHERE t1.usnValid=1 and exists(
	    SELECT 1 FROM smUsers 
	    WHERE emId=t1.emId AND now() between ifnull(usStartDate,now()) and ifnull(usEndDate,now()) AND ptValid=1 AND usFrozen=0
	)
  	AND t1.usnType IN (2,3) and t1.usnName=#{username}
	ORDER BY usnType DESC
  </select>
</mapper>