<?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.TChangeDunMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TChangeDun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="did" jdbcType="INTEGER" property="did" />
    <result column="cid" jdbcType="INTEGER" property="cid" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="tid" jdbcType="INTEGER" property="tid" />
    <result column="ctid" jdbcType="INTEGER" property="ctid" />
    <result column="project_type" jdbcType="INTEGER" property="projectType" />
    <result column="dun_type" jdbcType="INTEGER" property="dunType" />
    <result column="wait_day" jdbcType="INTEGER" property="waitDay" />
    <result column="effective_count" jdbcType="INTEGER" property="effectiveCount" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
    <result column="money" jdbcType="DECIMAL" property="money" />
    <result column="appropriation_ratio" jdbcType="DECIMAL" property="appropriationRatio" />
    <result column="customize_name" jdbcType="VARCHAR" property="customizeName" />
    <result column="customize_time" jdbcType="TIMESTAMP" property="customizeTime" />
  </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 Mon May 18 15:26:46 CST 2020.
    -->
    <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 Mon May 18 15:26:46 CST 2020.
    -->
    <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 Mon May 18 15:26:46 CST 2020.
    -->
    id, did, cid, order_no, tid, ctid, project_type, dun_type, wait_day, effective_count, 
    aid, status, type, create_time, start_time, money, appropriation_ratio, customize_name, 
    customize_time
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.TChangeDunExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_change_dun
    <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.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    select 
    <include refid="Base_Column_List" />
    from t_change_dun
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    delete from t_change_dun
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.TChangeDunExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    delete from t_change_dun
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TChangeDun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    insert into t_change_dun (id, did, cid, 
      order_no, tid, ctid, 
      project_type, dun_type, wait_day, 
      effective_count, aid, status, 
      type, create_time, start_time, 
      money, appropriation_ratio, customize_name, 
      customize_time)
    values (#{id,jdbcType=INTEGER}, #{did,jdbcType=INTEGER}, #{cid,jdbcType=INTEGER}, 
      #{orderNo,jdbcType=VARCHAR}, #{tid,jdbcType=INTEGER}, #{ctid,jdbcType=INTEGER}, 
      #{projectType,jdbcType=INTEGER}, #{dunType,jdbcType=INTEGER}, #{waitDay,jdbcType=INTEGER}, 
      #{effectiveCount,jdbcType=INTEGER}, #{aid,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, 
      #{type,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{startTime,jdbcType=TIMESTAMP}, 
      #{money,jdbcType=DECIMAL}, #{appropriationRatio,jdbcType=DECIMAL}, #{customizeName,jdbcType=VARCHAR}, 
      #{customizeTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TChangeDun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    insert into t_change_dun
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="did != null">
        did,
      </if>
      <if test="cid != null">
        cid,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="tid != null">
        tid,
      </if>
      <if test="ctid != null">
        ctid,
      </if>
      <if test="projectType != null">
        project_type,
      </if>
      <if test="dunType != null">
        dun_type,
      </if>
      <if test="waitDay != null">
        wait_day,
      </if>
      <if test="effectiveCount != null">
        effective_count,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="startTime != null">
        start_time,
      </if>
      <if test="money != null">
        money,
      </if>
      <if test="appropriationRatio != null">
        appropriation_ratio,
      </if>
      <if test="customizeName != null">
        customize_name,
      </if>
      <if test="customizeTime != null">
        customize_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="did != null">
        #{did,jdbcType=INTEGER},
      </if>
      <if test="cid != null">
        #{cid,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="tid != null">
        #{tid,jdbcType=INTEGER},
      </if>
      <if test="ctid != null">
        #{ctid,jdbcType=INTEGER},
      </if>
      <if test="projectType != null">
        #{projectType,jdbcType=INTEGER},
      </if>
      <if test="dunType != null">
        #{dunType,jdbcType=INTEGER},
      </if>
      <if test="waitDay != null">
        #{waitDay,jdbcType=INTEGER},
      </if>
      <if test="effectiveCount != null">
        #{effectiveCount,jdbcType=INTEGER},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="startTime != null">
        #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="money != null">
        #{money,jdbcType=DECIMAL},
      </if>
      <if test="appropriationRatio != null">
        #{appropriationRatio,jdbcType=DECIMAL},
      </if>
      <if test="customizeName != null">
        #{customizeName,jdbcType=VARCHAR},
      </if>
      <if test="customizeTime != null">
        #{customizeTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.TChangeDunExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    select count(*) from t_change_dun
    <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 Mon May 18 15:26:46 CST 2020.
    -->
    update t_change_dun
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.did != null">
        did = #{record.did,jdbcType=INTEGER},
      </if>
      <if test="record.cid != null">
        cid = #{record.cid,jdbcType=INTEGER},
      </if>
      <if test="record.orderNo != null">
        order_no = #{record.orderNo,jdbcType=VARCHAR},
      </if>
      <if test="record.tid != null">
        tid = #{record.tid,jdbcType=INTEGER},
      </if>
      <if test="record.ctid != null">
        ctid = #{record.ctid,jdbcType=INTEGER},
      </if>
      <if test="record.projectType != null">
        project_type = #{record.projectType,jdbcType=INTEGER},
      </if>
      <if test="record.dunType != null">
        dun_type = #{record.dunType,jdbcType=INTEGER},
      </if>
      <if test="record.waitDay != null">
        wait_day = #{record.waitDay,jdbcType=INTEGER},
      </if>
      <if test="record.effectiveCount != null">
        effective_count = #{record.effectiveCount,jdbcType=INTEGER},
      </if>
      <if test="record.aid != null">
        aid = #{record.aid,jdbcType=VARCHAR},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </if>
      <if test="record.type != null">
        type = #{record.type,jdbcType=INTEGER},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.startTime != null">
        start_time = #{record.startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.money != null">
        money = #{record.money,jdbcType=DECIMAL},
      </if>
      <if test="record.appropriationRatio != null">
        appropriation_ratio = #{record.appropriationRatio,jdbcType=DECIMAL},
      </if>
      <if test="record.customizeName != null">
        customize_name = #{record.customizeName,jdbcType=VARCHAR},
      </if>
      <if test="record.customizeTime != null">
        customize_time = #{record.customizeTime,jdbcType=TIMESTAMP},
      </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 Mon May 18 15:26:46 CST 2020.
    -->
    update t_change_dun
    set id = #{record.id,jdbcType=INTEGER},
      did = #{record.did,jdbcType=INTEGER},
      cid = #{record.cid,jdbcType=INTEGER},
      order_no = #{record.orderNo,jdbcType=VARCHAR},
      tid = #{record.tid,jdbcType=INTEGER},
      ctid = #{record.ctid,jdbcType=INTEGER},
      project_type = #{record.projectType,jdbcType=INTEGER},
      dun_type = #{record.dunType,jdbcType=INTEGER},
      wait_day = #{record.waitDay,jdbcType=INTEGER},
      effective_count = #{record.effectiveCount,jdbcType=INTEGER},
      aid = #{record.aid,jdbcType=VARCHAR},
      status = #{record.status,jdbcType=INTEGER},
      type = #{record.type,jdbcType=INTEGER},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      start_time = #{record.startTime,jdbcType=TIMESTAMP},
      money = #{record.money,jdbcType=DECIMAL},
      appropriation_ratio = #{record.appropriationRatio,jdbcType=DECIMAL},
      customize_name = #{record.customizeName,jdbcType=VARCHAR},
      customize_time = #{record.customizeTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TChangeDun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    update t_change_dun
    <set>
      <if test="did != null">
        did = #{did,jdbcType=INTEGER},
      </if>
      <if test="cid != null">
        cid = #{cid,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="tid != null">
        tid = #{tid,jdbcType=INTEGER},
      </if>
      <if test="ctid != null">
        ctid = #{ctid,jdbcType=INTEGER},
      </if>
      <if test="projectType != null">
        project_type = #{projectType,jdbcType=INTEGER},
      </if>
      <if test="dunType != null">
        dun_type = #{dunType,jdbcType=INTEGER},
      </if>
      <if test="waitDay != null">
        wait_day = #{waitDay,jdbcType=INTEGER},
      </if>
      <if test="effectiveCount != null">
        effective_count = #{effectiveCount,jdbcType=INTEGER},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="startTime != null">
        start_time = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="money != null">
        money = #{money,jdbcType=DECIMAL},
      </if>
      <if test="appropriationRatio != null">
        appropriation_ratio = #{appropriationRatio,jdbcType=DECIMAL},
      </if>
      <if test="customizeName != null">
        customize_name = #{customizeName,jdbcType=VARCHAR},
      </if>
      <if test="customizeTime != null">
        customize_time = #{customizeTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TChangeDun">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 15:26:46 CST 2020.
    -->
    update t_change_dun
    set did = #{did,jdbcType=INTEGER},
      cid = #{cid,jdbcType=INTEGER},
      order_no = #{orderNo,jdbcType=VARCHAR},
      tid = #{tid,jdbcType=INTEGER},
      ctid = #{ctid,jdbcType=INTEGER},
      project_type = #{projectType,jdbcType=INTEGER},
      dun_type = #{dunType,jdbcType=INTEGER},
      wait_day = #{waitDay,jdbcType=INTEGER},
      effective_count = #{effectiveCount,jdbcType=INTEGER},
      aid = #{aid,jdbcType=VARCHAR},
      status = #{status,jdbcType=INTEGER},
      type = #{type,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      start_time = #{startTime,jdbcType=TIMESTAMP},
      money = #{money,jdbcType=DECIMAL},
      appropriation_ratio = #{appropriationRatio,jdbcType=DECIMAL},
      customize_name = #{customizeName,jdbcType=VARCHAR},
      customize_time = #{customizeTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
   <insert id="insertSelectiveList" parameterType="java.util.List">
    insert into t_change_dun (did, cid, 
      order_no, tid, project_type, 
      dun_type, wait_day, effective_count, 
      aid, status, create_time, 
      start_time, money, appropriation_ratio,
      customize_name,customize_time
      )values
      <foreach collection="list" index="index" item="item" separator=",">
      ( #{item.did,jdbcType=INTEGER}, #{item.cid,jdbcType=INTEGER}, 
      #{item.orderNo,jdbcType=VARCHAR}, #{item.tid,jdbcType=INTEGER}, #{item.projectType,jdbcType=INTEGER}, 
      #{item.dunType,jdbcType=INTEGER}, #{item.waitDay,jdbcType=INTEGER}, #{item.effectiveCount,jdbcType=INTEGER}, 
      #{item.aid,jdbcType=VARCHAR}, #{item.status,jdbcType=INTEGER}, now(), 
      #{item.startTime,jdbcType=TIMESTAMP}, #{item.money,jdbcType=DECIMAL}, #{item.appropriationRatio,jdbcType=DECIMAL},
      #{item.customizeName,jdbcType=VARCHAR},#{item.customizeTime,jdbcType=TIMESTAMP}
      )
    </foreach>
  </insert>
  
  <select id="selectByCid" resultType="com.goafanti.order.bo.TChangeDunOut">
	select a.id,a.order_no orderNo,ifnull(a.tid,c.tid)tid, a.project_type projectType, a.dun_type dunType, a.wait_day waitDay, 
  	  b.set_up_amount setUpAmount, a.effective_count effectiveCount, a.aid, a.create_time createTime,a.type,a.ctid,a.did,
  	  ifnull(b.commodity_name,c.commodity_name) commodityName,a.money,a.status, a.appropriation_ratio appropriationRatio
  	  ,date_format(a.customize_time,'%Y-%m-%d') customizeTimes, a.customize_name customizeName,a.customize_time customizeTime
  	  from t_change_dun a left join t_order_task b on a.tid=b.id left join t_change_task c on a.ctid=c.id
    	where a.cid= #{id} order by a.id
  </select>

  <update id="updateByTid">
  		update t_change_dun set type= #{type} 
  		where 1=1 
  		<if test="tid !=null">
  		and tid= #{tid}
  		</if>
  		<if test="cid !=null">
  		and cid= #{cid}
  		</if>
  </update>
  
   <update id="updateByCTid">
  		update t_change_dun set tid= #{tid} 
  		where 1=1 
  		<if test="ctid !=null">
  		and ctid= #{ctid}
  		</if>
  </update>
    <delete id="deleteByCtid" parameterType="java.lang.Integer">
    delete from t_change_dun
    where ctid = #{id,jdbcType=INTEGER}
  </delete>
 
</mapper>