<?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.ContractMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.Contract">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 02 19:56:05 CST 2018.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="serial_number" jdbcType="INTEGER" property="serialNumber" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="creater" jdbcType="VARCHAR" property="creater" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="principal" jdbcType="VARCHAR" property="principal" />
    <result column="uid" jdbcType="VARCHAR" property="uid" />
    <result column="sign_date" jdbcType="TIMESTAMP" property="signDate" />
    <result column="sign_comment" jdbcType="VARCHAR" property="signComment" />
    <result column="complete_date" jdbcType="TIMESTAMP" property="completeDate" />
    <result column="complete_comment" jdbcType="VARCHAR" property="completeComment" />
    <result column="deleted_sign" jdbcType="INTEGER" property="deletedSign" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="contacts" jdbcType="VARCHAR" property="contacts" />
    <result column="contact_mobile" jdbcType="VARCHAR" property="contactMobile" />
    <result column="task_distribution" jdbcType="INTEGER" property="taskDistribution" />
  </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 Wed May 02 19:56:05 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 Wed May 02 19:56:05 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 Wed May 02 19:56:05 CST 2018.
    -->
    id, serial_number, create_time, update_time, creater, name, type, principal, uid, 
    sign_date, sign_comment, complete_date, complete_comment, deleted_sign, order_no, 
    status, contacts, contact_mobile, task_distribution
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.ContractExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 02 19:56:05 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from contract
    <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 Wed May 02 19:56:05 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from contract
    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 Wed May 02 19:56:05 CST 2018.
    -->
    delete from contract
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.ContractExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 02 19:56:05 CST 2018.
    -->
    delete from contract
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.Contract">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 02 19:56:05 CST 2018.
    -->
    insert into contract (id, serial_number, create_time, 
      update_time, creater, name, 
      type, principal, uid, 
      sign_date, sign_comment, complete_date, 
      complete_comment, deleted_sign, order_no, 
      status, contacts, contact_mobile, 
      task_distribution)
    values (#{id,jdbcType=VARCHAR}, #{serialNumber,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{creater,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{type,jdbcType=VARCHAR}, #{principal,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, 
      #{signDate,jdbcType=TIMESTAMP}, #{signComment,jdbcType=VARCHAR}, #{completeDate,jdbcType=TIMESTAMP}, 
      #{completeComment,jdbcType=VARCHAR}, #{deletedSign,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR}, 
      #{status,jdbcType=INTEGER}, #{contacts,jdbcType=VARCHAR}, #{contactMobile,jdbcType=VARCHAR}, 
      #{taskDistribution,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.Contract">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 02 19:56:05 CST 2018.
    -->
    insert into contract
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="serialNumber != null">
        serial_number,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="creater != null">
        creater,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="principal != null">
        principal,
      </if>
      <if test="uid != null">
        uid,
      </if>
      <if test="signDate != null">
        sign_date,
      </if>
      <if test="signComment != null">
        sign_comment,
      </if>
      <if test="completeDate != null">
        complete_date,
      </if>
      <if test="completeComment != null">
        complete_comment,
      </if>
      <if test="deletedSign != null">
        deleted_sign,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="contacts != null">
        contacts,
      </if>
      <if test="contactMobile != null">
        contact_mobile,
      </if>
      <if test="taskDistribution != null">
        task_distribution,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="serialNumber != null">
        #{serialNumber,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="creater != null">
        #{creater,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="principal != null">
        #{principal,jdbcType=VARCHAR},
      </if>
      <if test="uid != null">
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="signDate != null">
        #{signDate,jdbcType=TIMESTAMP},
      </if>
      <if test="signComment != null">
        #{signComment,jdbcType=VARCHAR},
      </if>
      <if test="completeDate != null">
        #{completeDate,jdbcType=TIMESTAMP},
      </if>
      <if test="completeComment != null">
        #{completeComment,jdbcType=VARCHAR},
      </if>
      <if test="deletedSign != null">
        #{deletedSign,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="contacts != null">
        #{contacts,jdbcType=VARCHAR},
      </if>
      <if test="contactMobile != null">
        #{contactMobile,jdbcType=VARCHAR},
      </if>
      <if test="taskDistribution != null">
        #{taskDistribution,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.ContractExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 02 19:56:05 CST 2018.
    -->
    select count(*) from contract
    <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 Wed May 02 19:56:05 CST 2018.
    -->
    update contract
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.serialNumber != null">
        serial_number = #{record.serialNumber,jdbcType=INTEGER},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.creater != null">
        creater = #{record.creater,jdbcType=VARCHAR},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.type != null">
        type = #{record.type,jdbcType=VARCHAR},
      </if>
      <if test="record.principal != null">
        principal = #{record.principal,jdbcType=VARCHAR},
      </if>
      <if test="record.uid != null">
        uid = #{record.uid,jdbcType=VARCHAR},
      </if>
      <if test="record.signDate != null">
        sign_date = #{record.signDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.signComment != null">
        sign_comment = #{record.signComment,jdbcType=VARCHAR},
      </if>
      <if test="record.completeDate != null">
        complete_date = #{record.completeDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.completeComment != null">
        complete_comment = #{record.completeComment,jdbcType=VARCHAR},
      </if>
      <if test="record.deletedSign != null">
        deleted_sign = #{record.deletedSign,jdbcType=INTEGER},
      </if>
      <if test="record.orderNo != null">
        order_no = #{record.orderNo,jdbcType=VARCHAR},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </if>
      <if test="record.contacts != null">
        contacts = #{record.contacts,jdbcType=VARCHAR},
      </if>
      <if test="record.contactMobile != null">
        contact_mobile = #{record.contactMobile,jdbcType=VARCHAR},
      </if>
      <if test="record.taskDistribution != null">
        task_distribution = #{record.taskDistribution,jdbcType=INTEGER},
      </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 Wed May 02 19:56:05 CST 2018.
    -->
    update contract
    set id = #{record.id,jdbcType=VARCHAR},
      serial_number = #{record.serialNumber,jdbcType=INTEGER},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      creater = #{record.creater,jdbcType=VARCHAR},
      name = #{record.name,jdbcType=VARCHAR},
      type = #{record.type,jdbcType=VARCHAR},
      principal = #{record.principal,jdbcType=VARCHAR},
      uid = #{record.uid,jdbcType=VARCHAR},
      sign_date = #{record.signDate,jdbcType=TIMESTAMP},
      sign_comment = #{record.signComment,jdbcType=VARCHAR},
      complete_date = #{record.completeDate,jdbcType=TIMESTAMP},
      complete_comment = #{record.completeComment,jdbcType=VARCHAR},
      deleted_sign = #{record.deletedSign,jdbcType=INTEGER},
      order_no = #{record.orderNo,jdbcType=VARCHAR},
      status = #{record.status,jdbcType=INTEGER},
      contacts = #{record.contacts,jdbcType=VARCHAR},
      contact_mobile = #{record.contactMobile,jdbcType=VARCHAR},
      task_distribution = #{record.taskDistribution,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.Contract">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 02 19:56:05 CST 2018.
    -->
    update contract
    <set>
      <if test="serialNumber != null">
        serial_number = #{serialNumber,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="creater != null">
        creater = #{creater,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=VARCHAR},
      </if>
      <if test="principal != null">
        principal = #{principal,jdbcType=VARCHAR},
      </if>
      <if test="uid != null">
        uid = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="signDate != null">
        sign_date = #{signDate,jdbcType=TIMESTAMP},
      </if>
      <if test="signComment != null">
        sign_comment = #{signComment,jdbcType=VARCHAR},
      </if>
      <if test="completeDate != null">
        complete_date = #{completeDate,jdbcType=TIMESTAMP},
      </if>
      <if test="completeComment != null">
        complete_comment = #{completeComment,jdbcType=VARCHAR},
      </if>
      <if test="deletedSign != null">
        deleted_sign = #{deletedSign,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="contacts != null">
        contacts = #{contacts,jdbcType=VARCHAR},
      </if>
      <if test="contactMobile != null">
        contact_mobile = #{contactMobile,jdbcType=VARCHAR},
      </if>
      <if test="taskDistribution != null">
        task_distribution = #{taskDistribution,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.Contract">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 02 19:56:05 CST 2018.
    -->
    update contract
    set serial_number = #{serialNumber,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      creater = #{creater,jdbcType=VARCHAR},
      name = #{name,jdbcType=VARCHAR},
      type = #{type,jdbcType=VARCHAR},
      principal = #{principal,jdbcType=VARCHAR},
      uid = #{uid,jdbcType=VARCHAR},
      sign_date = #{signDate,jdbcType=TIMESTAMP},
      sign_comment = #{signComment,jdbcType=VARCHAR},
      complete_date = #{completeDate,jdbcType=TIMESTAMP},
      complete_comment = #{completeComment,jdbcType=VARCHAR},
      deleted_sign = #{deletedSign,jdbcType=INTEGER},
      order_no = #{orderNo,jdbcType=VARCHAR},
      status = #{status,jdbcType=INTEGER},
      contacts = #{contacts,jdbcType=VARCHAR},
      contact_mobile = #{contactMobile,jdbcType=VARCHAR},
      task_distribution = #{taskDistribution,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
  </update>
 
  <select id="findManageContractListByPage" parameterType="String" resultType="com.goafanti.contract.bo.ContractManageListBo">
   select c.id, c.uid, oi.unit_name as unitName, 
   		  oi.licence_province as province, c.serial_number as serialNumber, c.type,
   		  c.sign_date as signDate, a.name as founder, 
   		  c.depict, c.status, c.complete_date as completeDate, c.contacts
   from contract c 
		LEFT JOIN organization_identity oi on oi.uid = c.uid
		LEFT JOIN admin a on a.id = c.founder
    <if test="principal != null">	
		LEFT JOIN contract_log cl on cl.cid = c.id
   </if>	
  where c.deleted_sign = 0  
  <if test="principal != null">
	and cl.principal = #{principal,jdbcType=VARCHAR}
  </if>
  <if test="serialNumber !=null">
    and c.serialNumber = #{serialNumber,jdbcType=INTEGER}
  </if>
  <if test="id !=null">
    and c.id = #{id,jdbcType=VARCHAR}
  </if>
  <if test="type !=null">
    and c.type = #{type,jdbcType=INTEGER}
  </if>
   <if test="uid !=null">
    and c.uid = #{uid,jdbcType=INTEGER}
  </if>
   <if test="status !=null">
    and c.status= #{status ,jdbcType=INTEGER}
  </if>
   <if test="cStart !=null">
    and c.sign_date <![CDATA[ >= ]]> #{cStart,jdbcType=TIMESTAMP}
  </if>
   <if test="cEnd !=null">
    and c.sign_date <![CDATA[ < ]]> #{cEnd,jdbcType=TIMESTAMP}
  </if>
   <if test="province !=null">
    and oi.licence_province= #{province,jdbcType=INTEGER}
  </if>
   <if test="unitName !=null">
    and oi.unit_name= #{unitName,jdbcType=VARCAHR}
  </if>
  <if test="principal != null">
	group by c.id, oi.id
  </if>
	order by c.serial_number DESC
  <if test="page_sql!=null">
	${page_sql}
  </if>
  </select>
  
  <select id="findManageContractCount" parameterType="String" resultType="java.lang.Integer">
   select count(distinct(c.id))
   from contract c 
		LEFT JOIN organization_identity oi on oi.uid = c.uid
		LEFT JOIN admin a on a.id = c.founder
    <if test="principal != null">	
		LEFT JOIN contract_log cl on cl.cid = c.id
   </if>	
  where c.deleted_sign = 0  
  <if test="principal != null">
	and cl.principal = #{principal,jdbcType=VARCHAR}
  </if>
 <if test="id !=null">
    and c.id = #{id,jdbcType=VARCHAR}
  </if>
  <if test="serialNumber !=null">
    and c.serialNumber = #{serialNumber,jdbcType=INTEGER}
  </if>
   <if test="type !=null">
    and c.type = #{type,jdbcType=INTEGER}
  </if>
   <if test="uid !=null">
    and c.uid = #{uid,jdbcType=INTEGER}
  </if>
   <if test="status !=null">
    and c.status= #{status ,jdbcType=INTEGER}
  </if>
   <if test="cStart !=null">
    and c.sign_date <![CDATA[ >= ]]> #{cStart,jdbcType=TIMESTAMP}
  </if>
   <if test="cEnd !=null">
    and c.sign_date <![CDATA[ < ]]> #{cEnd,jdbcType=TIMESTAMP}
  </if>
   <if test="province !=null">
    and oi.licence_province= #{province,jdbcType=INTEGER}
  </if>
   <if test="unitName !=null">
    and oi.unit_name= #{unitName,jdbcType=VARCAHR}
  </if>
  </select>
  
  <select id="selectContractDetail" parameterType="java.lang.String" resultType="com.goafanti.contract.bo.ContractDetail">
  	select  
			c.id, c.uid, c.serial_number as serialNumber,  
			oi.unit_name as unitName, oi.org_code as orgCode, oi.postal_address as address,
			c.type, c.sign_date as signDate, a.name as founder, 
			c.depict, c.status, c.patent_num as patentNum, 
			c.patent_status as patentStatus, c.copyright_num as copyrightNum, c.copyright_status as copyrightStatus, 
			c.cognizance_year as cognizanceYear, c.cognizance_status as cognizanceStatus, c.tech_project_num as techProjectNum, 
			c.tech_project_status as techProjectStatus, c.comment, c.complete_date as completeDate,
      c.contacts, c.previous_fee as previousFee
	from contract c 
	LEFT JOIN organization_identity oi on oi.uid = c.uid 
	LEFT JOIN admin a on a.id = c.founder
	where c.deleted_sign = 0 and c.id = #{id,jdbcType=VARCHAR}
  </select>
  
  
  <select id="selectContractSerialNumber" parameterType="java.lang.String" resultType="com.goafanti.contract.bo.ContractSerialNumber">
  	 select c.id as contractId, c.serial_number as serialNumber
   from contract c 
    <if test="_parameter != null">	
		LEFT JOIN contract_log cl on cl.cid = c.id
   </if>
   where c.deleted_sign = 0
   <if test="_parameter !=null">	
   	and cl.principal = #{_parameter,jdbcType=VARCHAR}
   </if>
    <if test="_parameter != null">
	group by c.id
  </if>
   order by c.serial_number desc
  </select>
  
  <update id="batchDeleteByPrimaryKey" parameterType="java.util.List">
  	update contract set deleted_sign = 1
  	where  id in 
	<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
		#{item}
	</foreach>
  </update>
  
   <select id="findClientContractListByPage" parameterType="String" resultType="com.goafanti.contract.bo.ContractClientListBo">
   select c.id, c.uid,  c.serial_number as serialNumber, c.type,
   		  c.sign_date as signDate,
   		  c.depict, c.status, c.complete_date as completeDate, c.contacts
   from contract c 
	  where c.deleted_sign = 0  
	  <if test="serialNumber !=null">
	    and c.serial_number = #{serialNumber,jdbcType=INTEGER}
	  </if>
	  <if test="id !=null">
	    and c.id = #{id,jdbcType=VARCHAR}
	  </if>
	  <if test="type !=null">
	    and c.type = #{type,jdbcType=INTEGER}
	  </if>
	   <if test="uid !=null">
	    and c.uid = #{uid,jdbcType=INTEGER}
	  </if>
	   <if test="status !=null">
	    and c.status= #{status ,jdbcType=INTEGER}
	  </if>
	   <if test="cStart !=null">
	    and c.sign_date <![CDATA[ >= ]]> #{cStart,jdbcType=TIMESTAMP}
	  </if>
	   <if test="cEnd !=null">
	    and c.sign_date <![CDATA[ < ]]> #{cEnd,jdbcType=TIMESTAMP}
	  </if>
	   <if test="lStart !=null">
	    and c.complete_date <![CDATA[ >= ]]> #{lStart,jdbcType=TIMESTAMP}
	  </if>
	   <if test="lEnd !=null">
	    and c.complete_date <![CDATA[ < ]]> #{lEnd,jdbcType=TIMESTAMP}
	  </if>
	  
		order by c.serial_number DESC
	  <if test="page_sql!=null">
		${page_sql}
	  </if>
  </select>
  
  <select id="findClientContractCount" parameterType="String" resultType="java.lang.Integer">
   select count(1)
   from contract c 
	  where c.deleted_sign = 0  
	  <if test="serialNumber !=null">
	    and c.serial_number = #{serialNumber,jdbcType=INTEGER}
	  </if>
	  <if test="id !=null">
	    and c.id = #{id,jdbcType=VARCHAR}
	  </if>
	  <if test="type !=null">
	    and c.type = #{type,jdbcType=INTEGER}
	  </if>
	   <if test="uid !=null">
	    and c.uid = #{uid,jdbcType=INTEGER}
	  </if>
	   <if test="status !=null">
	    and c.status= #{status ,jdbcType=INTEGER}
	  </if>
	   <if test="cStart !=null">
	    and c.sign_date <![CDATA[ > ]]> #{cStart,jdbcType=TIMESTAMP}
	  </if>
	   <if test="cEnd !=null">
	    and c.sign_date <![CDATA[ < ]]> #{cEnd,jdbcType=TIMESTAMP}
	  </if>
	   <if test="lStart !=null">
	    and c.complete_date <![CDATA[ >= ]]> #{lStart,jdbcType=TIMESTAMP}
	  </if>
	   <if test="lEnd !=null">
	    and c.complete_date <![CDATA[ < ]]> #{lEnd,jdbcType=TIMESTAMP}
	  </if>
  </select>
  
  <select id="findByUidAndYear" resultMap="BaseResultMap">
  	  select 
    <include refid="Base_Column_List" />
    from contract
    where uid = #{uid,jdbcType=VARCHAR}
    and cognizance_year = #{year,jdbcType=INTEGER}
    and deleted_sign = 0
  </select>
  
  <select id="findLatelyRecordByUid" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    	<include refid="Base_Column_List" />
    from contract 
    where cognizance_year =  
	   	(
	   	select
	   		Max(cognizance_year)
	   	from contract
	   	where uid = #{uid,jdbcType=VARCHAR}
	   	and deleted_sign = 0
	   	)
	and uid = #{uid,jdbcType=VARCHAR} and deleted_sign = 0
  </select>
  <insert id="batchInsert" parameterType="com.goafanti.common.model.ContractTask">
 	 insert into contract_task(
			id,
			contract_id,
			commodity_id,
			commodity_name,
			commodity_mode,
			commodity_type,
			commodity_quantity,
			task_status,
			task_comment,
			create_time,
			publish_status
		)
	values
    <foreach collection="list" index="index" item="item" separator=",">
      (
      	#{item.id,jdbcType=VARCHAR}, 
      	#{item.contractId,jdbcType=VARCHAR},
		#{item.commodityId,jdbcType=VARCHAR},
		#{item.commodityName,jdbcType=VARCHAR}, 
		#{item.commodityMode,jdbcType=VARCHAR}, 
		#{item.commodityType,jdbcType=INTEGER},
		#{item.commodityQuantity,jdbcType=INTEGER},
		#{item.taskStatus,jdbcType=INTEGER},
		#{item.taskComment,jdbcType=VARCHAR},
		#{item.createTime,jdbcType=TIMESTAMP},
		#{item.publishStatus,jdbcType=INTEGER}
	  )
    </foreach>
   </insert>
   
   <update id="updateRepairData">
		update contract set task_distribution = #{taskDistribution,jdbcType=VARCHAR} where id = #{contractId,jdbcType=VARCHAR} 
   </update>
  
   <select id="selectTaskAllCount" parameterType="java.lang.String" resultType="java.lang.Integer">
		select
			count( 0 ) as all_count
		from
			contract_task a left join contract b on
			a.contract_id = b.id
		where
			a.deleted_sign <![CDATA[ <> ]]> 1
			and a.contract_id = #{contractId,jdbcType=VARCHAR}	
   </select>
   
   <select id="selectTaskDisCount" parameterType="java.lang.String" resultType="java.lang.Integer">
		select
			count( 0 ) as dis_count
		from
			contract_task a left join contract b on
			a.contract_id = b.id
		where
			a.deleted_sign <![CDATA[ <> ]]> 1
			and a.task_status <![CDATA[ <> ]]> 0
			and a.contract_id = #{contractId,jdbcType=VARCHAR}
   </select>
</mapper>