<?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.IdleContractNoMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.IdleContractNo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 07 16:15:44 CST 2020.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="abbreviation" jdbcType="VARCHAR" property="abbreviation" />
    <result column="used_order_no" jdbcType="VARCHAR" property="usedOrderNo" />
    <result column="contract_no" jdbcType="VARCHAR" property="contractNo" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="year" jdbcType="INTEGER" property="year" />
  </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 Jan 07 16:15:44 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 Tue Jan 07 16:15:44 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 Tue Jan 07 16:15:44 CST 2020.
    -->
    id, abbreviation, used_order_no, contract_no, aid, create_time, year
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.IdleContractNoExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 07 16:15:44 CST 2020.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from idle_contract_no
    <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 Tue Jan 07 16:15:44 CST 2020.
    -->
    select 
    <include refid="Base_Column_List" />
    from idle_contract_no
    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 Tue Jan 07 16:15:44 CST 2020.
    -->
    delete from idle_contract_no
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.IdleContractNoExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 07 16:15:44 CST 2020.
    -->
    delete from idle_contract_no
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.IdleContractNo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 07 16:15:44 CST 2020.
    -->
    insert into idle_contract_no (id, abbreviation, used_order_no, 
      contract_no, aid, create_time, 
      year)
    values (#{id,jdbcType=INTEGER}, #{abbreviation,jdbcType=VARCHAR}, #{usedOrderNo,jdbcType=VARCHAR}, 
      #{contractNo,jdbcType=VARCHAR}, #{aid,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{year,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.IdleContractNo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 07 16:15:44 CST 2020.
    -->
    insert into idle_contract_no
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="abbreviation != null">
        abbreviation,
      </if>
      <if test="usedOrderNo != null">
        used_order_no,
      </if>
      <if test="contractNo != null">
        contract_no,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="year != null">
        year,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="abbreviation != null">
        #{abbreviation,jdbcType=VARCHAR},
      </if>
      <if test="usedOrderNo != null">
        #{usedOrderNo,jdbcType=VARCHAR},
      </if>
      <if test="contractNo != null">
        #{contractNo,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="year != null">
        #{year,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.IdleContractNoExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 07 16:15:44 CST 2020.
    -->
    select count(*) from idle_contract_no
    <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 Jan 07 16:15:44 CST 2020.
    -->
    update idle_contract_no
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.abbreviation != null">
        abbreviation = #{record.abbreviation,jdbcType=VARCHAR},
      </if>
      <if test="record.usedOrderNo != null">
        used_order_no = #{record.usedOrderNo,jdbcType=VARCHAR},
      </if>
      <if test="record.contractNo != null">
        contract_no = #{record.contractNo,jdbcType=VARCHAR},
      </if>
      <if test="record.aid != null">
        aid = #{record.aid,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.year != null">
        year = #{record.year,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 Tue Jan 07 16:15:44 CST 2020.
    -->
    update idle_contract_no
    set id = #{record.id,jdbcType=INTEGER},
      abbreviation = #{record.abbreviation,jdbcType=VARCHAR},
      used_order_no = #{record.usedOrderNo,jdbcType=VARCHAR},
      contract_no = #{record.contractNo,jdbcType=VARCHAR},
      aid = #{record.aid,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      year = #{record.year,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.IdleContractNo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 07 16:15:44 CST 2020.
    -->
    update idle_contract_no
    <set>
      <if test="abbreviation != null">
        abbreviation = #{abbreviation,jdbcType=VARCHAR},
      </if>
      <if test="usedOrderNo != null">
        used_order_no = #{usedOrderNo,jdbcType=VARCHAR},
      </if>
      <if test="contractNo != null">
        contract_no = #{contractNo,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="year != null">
        year = #{year,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.IdleContractNo">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jan 07 16:15:44 CST 2020.
    -->
    update idle_contract_no
    set abbreviation = #{abbreviation,jdbcType=VARCHAR},
      used_order_no = #{usedOrderNo,jdbcType=VARCHAR},
      contract_no = #{contractNo,jdbcType=VARCHAR},
      aid = #{aid,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      year = #{year,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="selectByAbbreviation" resultType="com.goafanti.common.model.IdleContractNo">
	select a.id,a.abbreviation,a.used_order_no usedOrderNo,a.aid,a.create_time createTime,a.contract_no contractNo from idle_contract_no a
	where abbreviation= #{abbreviation,jdbcType=VARCHAR}  and `year`= #{year ,jdbcType=INTEGER}
	and a.contract_no=(select max(contract_no)from idle_contract_no where abbreviation= #{abbreviation,jdbcType=VARCHAR} and `year`= #{year ,jdbcType=INTEGER})
  </select>
</mapper>