<?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="com.fuxi.ws.data.dao.QVisitorrecordMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.QVisitorrecord">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="VisitorID" jdbcType="VARCHAR" property="visitorid" />
    <result column="EmployeeID" jdbcType="VARCHAR" property="employeeid" />
    <result column="Number" jdbcType="INTEGER" property="number" />
    <result column="Reason" jdbcType="TINYINT" property="reason" />
    <result column="Statc" jdbcType="TINYINT" property="statc" />
    <result column="ComeTime" jdbcType="TIMESTAMP" property="cometime" />
    <result column="LeaveTime" jdbcType="TIMESTAMP" property="leavetime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    ID, VisitorID, EmployeeID, Number, Reason, Statc, ComeTime, LeaveTime
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.QVisitorrecordExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from Q_VisitorRecord
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    select 
    <include refid="Base_Column_List" />
    from Q_VisitorRecord
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    delete from Q_VisitorRecord
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.QVisitorrecord">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    insert into Q_VisitorRecord (ID, VisitorID, EmployeeID, 
      Number, Reason, Statc, 
      ComeTime, LeaveTime)
    values (#{id,jdbcType=VARCHAR}, #{visitorid,jdbcType=VARCHAR}, #{employeeid,jdbcType=VARCHAR}, 
      #{number,jdbcType=INTEGER}, #{reason,jdbcType=TINYINT}, #{statc,jdbcType=TINYINT}, 
      #{cometime,jdbcType=TIMESTAMP}, #{leavetime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.QVisitorrecord">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    insert into Q_VisitorRecord
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="visitorid != null">
        VisitorID,
      </if>
      <if test="employeeid != null">
        EmployeeID,
      </if>
      <if test="number != null">
        Number,
      </if>
      <if test="reason != null">
        Reason,
      </if>
      <if test="statc != null">
        Statc,
      </if>
      <if test="cometime != null">
        ComeTime,
      </if>
      <if test="leavetime != null">
        LeaveTime,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="visitorid != null">
        #{visitorid,jdbcType=VARCHAR},
      </if>
      <if test="employeeid != null">
        #{employeeid,jdbcType=VARCHAR},
      </if>
      <if test="number != null">
        #{number,jdbcType=INTEGER},
      </if>
      <if test="reason != null">
        #{reason,jdbcType=TINYINT},
      </if>
      <if test="statc != null">
        #{statc,jdbcType=TINYINT},
      </if>
      <if test="cometime != null">
        #{cometime,jdbcType=TIMESTAMP},
      </if>
      <if test="leavetime != null">
        #{leavetime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.QVisitorrecordExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    select count(*) from Q_VisitorRecord
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.QVisitorrecord">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    update Q_VisitorRecord
    <set>
      <if test="visitorid != null">
        VisitorID = #{visitorid,jdbcType=VARCHAR},
      </if>
      <if test="employeeid != null">
        EmployeeID = #{employeeid,jdbcType=VARCHAR},
      </if>
      <if test="number != null">
        Number = #{number,jdbcType=INTEGER},
      </if>
      <if test="reason != null">
        Reason = #{reason,jdbcType=TINYINT},
      </if>
      <if test="statc != null">
        Statc = #{statc,jdbcType=TINYINT},
      </if>
      <if test="cometime != null">
        ComeTime = #{cometime,jdbcType=TIMESTAMP},
      </if>
      <if test="leavetime != null">
        LeaveTime = #{leavetime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.QVisitorrecord">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Sun Oct 09 10:29:54 CST 2016.
    -->
    update Q_VisitorRecord
    set VisitorID = #{visitorid,jdbcType=VARCHAR},
      EmployeeID = #{employeeid,jdbcType=VARCHAR},
      Number = #{number,jdbcType=INTEGER},
      Reason = #{reason,jdbcType=TINYINT},
      Statc = #{statc,jdbcType=TINYINT},
      ComeTime = #{cometime,jdbcType=TIMESTAMP},
      LeaveTime = #{leavetime,jdbcType=TIMESTAMP}
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="selRecordById" parameterType="java.lang.String" resultType="java.util.LinkedHashMap">
  	select a.id,a.cometime,a.number,b.vname,b.vmobile,b.idcard,b.company,b.photourl,c.name,c.mobilphone,
  	case a.statc when 1 then '确认中' when 2 then '已同意' when 3 then '已拒绝' when 4 then '会见中' else '已离开' end as statc,
  	case a.reason when 1 then '公务' when 2 then '亲友访问' when 3 then '面试' else '其他' end as reason,
  	d.department
  	from Q_visitorrecord as a left join employee as c on a.employeeid = c.employeeid
  	left join Q_visitor as b on a.visitorid = b.visitorid 
  	left join department as d on c.departmentid = d.departmentid
  	where a.id = #{id,jdbcType=VARCHAR}
  </select>
  
  <select id="selGroupByTime" resultType="java.util.LinkedHashMap">
  	select a.id,convert(varchar(10),a.cometime,121) as time,convert(varchar(5),a.cometime,108) as cometime,
  	convert(varchar(5),a.leavetime,108) as leavetime,b.vname,b.photourl,
  	case a.statc when 1 then '确认中' when 2 then '已同意' when 3 then '已拒绝' when 4 then '会见中' else '已离开' end as statc
  	from Q_VisitorRecord as a left join Q_visitor as b on a.visitorid = b.visitorid	
  	left join employee as c on a.employeeid = c.employeeid
  	<if test="userid != null and userid != ''">
  		where c.userid = ${userid}
  	</if>
  	order by cometime desc
  </select>
  
  <select id="backselrecord" resultType="java.util.LinkedHashMap">
  	select a.vname,a.vmobile,a.company,a.idcard,
  	convert(varchar(10),b.cometime,121) + '<![CDATA[<br/>]]>' + convert(varchar(5),b.cometime,108) as cometime,
  	b.number,
  	convert(varchar(10),b.leavetime,121) + '<![CDATA[<br/>]]>' + convert(varchar(5),b.leavetime,108) as leavetime,c.name,d.department,
  	case b.reason when 1 then '公务' when 2 then '亲友访问' when 3 then '面试' else '其他' end as reason,
  	case b.statc when 1 then '确认中' when 2 then '已同意' when 3 then '已拒绝' when 4 then '会见中'
  	else '已离开' end as statc
  	from Q_VisitorRecord as b left join Q_Visitor as a on b.VisitorID = a.VisitorID left join Employee as c
  	on c.EmployeeID = b.EmployeeID left join Department as d on c.DepartmentID = d.DepartmentID
  	<if test="conditions != null and conditions != ''">
  		where ${conditions}
  	</if>
  	order by b.cometime desc
  </select>
  
  
</mapper>