<?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.WApplyMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WApply">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 15 10:51:49 CST 2016.
    -->
    <id column="ApplyID" jdbcType="VARCHAR" property="applyid" />
    <result column="ApplyKey" jdbcType="VARCHAR" property="applykey" />
    <result column="Code" jdbcType="NVARCHAR" property="code" />
    <result column="DepartmentID" jdbcType="NVARCHAR" property="departmentid" />
    <result column="ApplyFlag" jdbcType="TINYINT" property="applyflag" />
    <result column="RegisterNo" jdbcType="VARCHAR" property="registerno" />
    <result column="Creater" jdbcType="TIMESTAMP" property="creater" />
    <result column="LastLocadTime" jdbcType="TIMESTAMP" property="lastlocadtime" />
    <result column="CallBackKey" jdbcType="VARCHAR" property="callbackkey" />
    <result column="CallBackSecret" jdbcType="VARCHAR" property="callbacksecret" />
    <result column="CallBackVer" jdbcType="VARCHAR" property="callbackver" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 15 10:51:49 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 Thu Dec 15 10:51:49 CST 2016.
    -->
    ApplyID, ApplyKey, Code, DepartmentID, ApplyFlag, RegisterNo, Creater, LastLocadTime, 
    CallBackKey, CallBackSecret, CallBackVer
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WApplyExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 15 10:51:49 CST 2016.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_Apply
    <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 Thu Dec 15 10:51:49 CST 2016.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_Apply
    where ApplyID = #{applyid,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 Thu Dec 15 10:51:49 CST 2016.
    -->
    delete from W_Apply
    where ApplyID = #{applyid,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WApply">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 15 10:51:49 CST 2016.
    -->
    insert into W_Apply (ApplyID, ApplyKey, Code, 
      DepartmentID, ApplyFlag, RegisterNo, 
      Creater, LastLocadTime, CallBackKey, 
      CallBackSecret, CallBackVer)
    values (#{applyid,jdbcType=VARCHAR}, #{applykey,jdbcType=VARCHAR}, #{code,jdbcType=NVARCHAR}, 
      #{departmentid,jdbcType=NVARCHAR}, #{applyflag,jdbcType=TINYINT}, #{registerno,jdbcType=VARCHAR}, 
      #{creater,jdbcType=TIMESTAMP}, #{lastlocadtime,jdbcType=TIMESTAMP}, #{callbackkey,jdbcType=VARCHAR}, 
      #{callbacksecret,jdbcType=VARCHAR}, #{callbackver,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WApply">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 15 10:51:49 CST 2016.
    -->
    insert into W_Apply
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="applyid != null">
        ApplyID,
      </if>
      <if test="applykey != null">
        ApplyKey,
      </if>
      <if test="code != null">
        Code,
      </if>
      <if test="departmentid != null">
        DepartmentID,
      </if>
      <if test="applyflag != null">
        ApplyFlag,
      </if>
      <if test="registerno != null">
        RegisterNo,
      </if>
      <if test="creater != null">
        Creater,
      </if>
      <if test="lastlocadtime != null">
        LastLocadTime,
      </if>
      <if test="callbackkey != null">
        CallBackKey,
      </if>
      <if test="callbacksecret != null">
        CallBackSecret,
      </if>
      <if test="callbackver != null">
        CallBackVer,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="applyid != null">
        #{applyid,jdbcType=VARCHAR},
      </if>
      <if test="applykey != null">
        #{applykey,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        #{code,jdbcType=NVARCHAR},
      </if>
      <if test="departmentid != null">
        #{departmentid,jdbcType=NVARCHAR},
      </if>
      <if test="applyflag != null">
        #{applyflag,jdbcType=TINYINT},
      </if>
      <if test="registerno != null">
        #{registerno,jdbcType=VARCHAR},
      </if>
      <if test="creater != null">
        #{creater,jdbcType=TIMESTAMP},
      </if>
      <if test="lastlocadtime != null">
        #{lastlocadtime,jdbcType=TIMESTAMP},
      </if>
      <if test="callbackkey != null">
        #{callbackkey,jdbcType=VARCHAR},
      </if>
      <if test="callbacksecret != null">
        #{callbacksecret,jdbcType=VARCHAR},
      </if>
      <if test="callbackver != null">
        #{callbackver,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WApplyExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 15 10:51:49 CST 2016.
    -->
    select count(*) from W_Apply
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WApply">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 15 10:51:49 CST 2016.
    -->
    update W_Apply
    <set>
      <if test="applykey != null">
        ApplyKey = #{applykey,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        Code = #{code,jdbcType=NVARCHAR},
      </if>
      <if test="departmentid != null">
        DepartmentID = #{departmentid,jdbcType=NVARCHAR},
      </if>
      <if test="applyflag != null">
        ApplyFlag = #{applyflag,jdbcType=TINYINT},
      </if>
      <if test="registerno != null">
        RegisterNo = #{registerno,jdbcType=VARCHAR},
      </if>
      <if test="creater != null">
        Creater = #{creater,jdbcType=TIMESTAMP},
      </if>
      <if test="lastlocadtime != null">
        LastLocadTime = #{lastlocadtime,jdbcType=TIMESTAMP},
      </if>
      <if test="callbackkey != null">
        CallBackKey = #{callbackkey,jdbcType=VARCHAR},
      </if>
      <if test="callbacksecret != null">
        CallBackSecret = #{callbacksecret,jdbcType=VARCHAR},
      </if>
      <if test="callbackver != null">
        CallBackVer = #{callbackver,jdbcType=VARCHAR},
      </if>
    </set>
    where ApplyID = #{applyid,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WApply">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 15 10:51:49 CST 2016.
    -->
    update W_Apply
    set ApplyKey = #{applykey,jdbcType=VARCHAR},
      Code = #{code,jdbcType=NVARCHAR},
      DepartmentID = #{departmentid,jdbcType=NVARCHAR},
      ApplyFlag = #{applyflag,jdbcType=TINYINT},
      RegisterNo = #{registerno,jdbcType=VARCHAR},
      Creater = #{creater,jdbcType=TIMESTAMP},
      LastLocadTime = #{lastlocadtime,jdbcType=TIMESTAMP},
      CallBackKey = #{callbackkey,jdbcType=VARCHAR},
      CallBackSecret = #{callbacksecret,jdbcType=VARCHAR},
      CallBackVer = #{callbackver,jdbcType=VARCHAR}
    where ApplyID = #{applyid,jdbcType=VARCHAR}
  </update>
  
  <select id="selectApplylist" parameterType="java.util.HashMap" resultType="java.util.LinkedHashMap"> 
  	SELECT a.ApplyID, a.ApplyKey, a.Code, a.DepartmentID, 
  		case a.ApplyFlag when 1 then '总公司' when 2 then '门店' end as ApplyFlag, 
  		a.RegisterNo,CONVERT(varchar(10),a.Creater, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10), a.Creater, 108) AS Creater, 
		CONVERT(varchar(10),a.LastLocadTime, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10), a.LastLocadTime, 108) AS LastLocadTime, b.Department
	FROM  W_Apply AS a INNER JOIN
    Department AS b ON a.DepartmentID = b.DepartmentID
    <if test="conditions != null and conditions != ''">
		where			
		${conditions}
	</if>
	order by a.Creater desc
  </select>
</mapper>