<?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.goafanti.common.dao.JtVoucherMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.JtVoucher">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="source" jdbcType="INTEGER" property="source" />
    <result column="money" jdbcType="DECIMAL" property="money" />
    <result column="duration_day" jdbcType="INTEGER" property="durationDay" />
    <result column="active_state" jdbcType="INTEGER" property="activeState" />
    <result column="granting_uid" jdbcType="VARCHAR" property="grantingUid" />
    <result column="limit_use" jdbcType="INTEGER" property="limitUse" />
    <result column="limit_project_id" jdbcType="VARCHAR" property="limitProjectId" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    <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="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    <where>
      <foreach collection="example.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 - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    id, name, source, money, duration_day, active_state, granting_uid, limit_use, limit_project_id
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.JtVoucherExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from jt_voucher
    <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 - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from jt_voucher
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    delete from jt_voucher
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.JtVoucherExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    delete from jt_voucher
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.JtVoucher">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    insert into jt_voucher (id, name, source, 
      money, duration_day, active_state, 
      granting_uid, limit_use, limit_project_id
      )
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{source,jdbcType=INTEGER}, 
      #{money,jdbcType=DECIMAL}, #{durationDay,jdbcType=INTEGER}, #{activeState,jdbcType=INTEGER}, 
      #{grantingUid,jdbcType=VARCHAR}, #{limitUse,jdbcType=INTEGER}, #{limitProjectId,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.JtVoucher">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    insert into jt_voucher
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="source != null">
        source,
      </if>
      <if test="money != null">
        money,
      </if>
      <if test="durationDay != null">
        duration_day,
      </if>
      <if test="activeState != null">
        active_state,
      </if>
      <if test="grantingUid != null">
        granting_uid,
      </if>
      <if test="limitUse != null">
        limit_use,
      </if>
      <if test="limitProjectId != null">
        limit_project_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="source != null">
        #{source,jdbcType=INTEGER},
      </if>
      <if test="money != null">
        #{money,jdbcType=DECIMAL},
      </if>
      <if test="durationDay != null">
        #{durationDay,jdbcType=INTEGER},
      </if>
      <if test="activeState != null">
        #{activeState,jdbcType=INTEGER},
      </if>
      <if test="grantingUid != null">
        #{grantingUid,jdbcType=VARCHAR},
      </if>
      <if test="limitUse != null">
        #{limitUse,jdbcType=INTEGER},
      </if>
      <if test="limitProjectId != null">
        #{limitProjectId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.JtVoucherExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    select count(*) from jt_voucher
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    update jt_voucher
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.source != null">
        source = #{record.source,jdbcType=INTEGER},
      </if>
      <if test="record.money != null">
        money = #{record.money,jdbcType=DECIMAL},
      </if>
      <if test="record.durationDay != null">
        duration_day = #{record.durationDay,jdbcType=INTEGER},
      </if>
      <if test="record.activeState != null">
        active_state = #{record.activeState,jdbcType=INTEGER},
      </if>
      <if test="record.grantingUid != null">
        granting_uid = #{record.grantingUid,jdbcType=VARCHAR},
      </if>
      <if test="record.limitUse != null">
        limit_use = #{record.limitUse,jdbcType=INTEGER},
      </if>
      <if test="record.limitProjectId != null">
        limit_project_id = #{record.limitProjectId,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    update jt_voucher
    set id = #{record.id,jdbcType=VARCHAR},
      name = #{record.name,jdbcType=VARCHAR},
      source = #{record.source,jdbcType=INTEGER},
      money = #{record.money,jdbcType=DECIMAL},
      duration_day = #{record.durationDay,jdbcType=INTEGER},
      active_state = #{record.activeState,jdbcType=INTEGER},
      granting_uid = #{record.grantingUid,jdbcType=VARCHAR},
      limit_use = #{record.limitUse,jdbcType=INTEGER},
      limit_project_id = #{record.limitProjectId,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.JtVoucher">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    update jt_voucher
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="source != null">
        source = #{source,jdbcType=INTEGER},
      </if>
      <if test="money != null">
        money = #{money,jdbcType=DECIMAL},
      </if>
      <if test="durationDay != null">
        duration_day = #{durationDay,jdbcType=INTEGER},
      </if>
      <if test="activeState != null">
        active_state = #{activeState,jdbcType=INTEGER},
      </if>
      <if test="grantingUid != null">
        granting_uid = #{grantingUid,jdbcType=VARCHAR},
      </if>
      <if test="limitUse != null">
        limit_use = #{limitUse,jdbcType=INTEGER},
      </if>
      <if test="limitProjectId != null">
        limit_project_id = #{limitProjectId,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.JtVoucher">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 16 15:59:34 CST 2018.
    -->
    update jt_voucher
    set name = #{name,jdbcType=VARCHAR},
      source = #{source,jdbcType=INTEGER},
      money = #{money,jdbcType=DECIMAL},
      duration_day = #{durationDay,jdbcType=INTEGER},
      active_state = #{activeState,jdbcType=INTEGER},
      granting_uid = #{grantingUid,jdbcType=VARCHAR},
      limit_use = #{limitUse,jdbcType=INTEGER},
      limit_project_id = #{limitProjectId,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  
  <select id="selectVoucherList" resultType="com.goafanti.voucher.bo.JtVoucherListBo">
  select
  	id, name, source, money, duration_day as durationDay, active_state as activeState, granting_uid as grantingUid,
  	limit_use as limitUse, limit_project_id as limitProjectId
   from jt_voucher
   where 1=1
   <if test="uid != null">
   		and  granting_uid = #{uid,jdbcType=VARCHAR} 
	</if>
   <if test="name != null">
		and  name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
	</if>  
	<if test="limitUse != null">
		and  limit_use  = #{limitUse,jdbcType=INTEGER}
	</if>
	<if test="activeState != null">
		and  active_state = #{activeState,jdbcType=INTEGER}
	</if>
	<if test="source != null">
		and  source = #{source,jdbcType=INTEGER}
	</if>
	order by name
  	<if test="page_sql!=null">
		${page_sql}
	</if>
   
  </select>
  <select id="selectVoucherCount" resultType="java.lang.Integer">
  	 select
  	count(*)
   from jt_voucher
   where 1=1
   <if test="uid != null">
		and  granting_uid = #{uid,jdbcType=VARCHAR} 
		</if>
   <if test="name != null">
		and  name like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
	</if>  
	<if test="limitUse != null">
		and  limit_use  = #{limitUse,jdbcType=INTEGER}
	</if>
	<if test="activeState != null">
		and  active_state = #{activeState,jdbcType=INTEGER}
	</if>
	<if test="source != null">
		and  source = #{source,jdbcType=INTEGER}
	</if>
  </select>
  
  <select id="getSourceVoucher" resultType="java.lang.String">
  	select id from jt_voucher where active_state=1 and source= #{source,jdbcType=INTEGER}
  </select>
  <select id="selectVoucherByClassify" resultType="com.goafanti.voucher.bo.JtVoucherListBo">
  select a.id,a.name,a.source,a.active_state as activeState,a.money,a.duration_day as durationDay,
  a.granting_uid as grantingUid,a.limit_use as limitUse,a.limit_project_id as limitProjectId
    from jt_voucher a
    left join jt_business_project b on a.limit_project_id=b.id
    left join jt_business_category c on b.category_id=c.id
    where a.source=4 and a.active_state=1
    <if test="name != null">
    and c.name= #{name,jdbcType=VARCHAR}
    </if>
    <if test="isHot != null">
    and b.is_hot= #{isHot,jdbcType=VARCHAR}
    </if>
    limit #{size,jdbcType=INTEGER}
  </select>
  <select id="selectByName" resultType="com.goafanti.voucher.bo.JtVoucherListBo">
   select a.id,a.name,a.source,a.active_state as activeState,a.money,a.duration_day as durationDay,
  a.granting_uid as grantingUid,a.limit_use as limitUse,a.limit_project_id as limitProjectId
    from jt_voucher a
    where a.source=4 and a.active_state=1
    and a.name= #{name,jdbcType=VARCHAR}
    limit #{size}
  </select>
  
</mapper>