<?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.ScAchievementMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.ScAchievement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jun 26 18:27:47 CST 2018.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="industry" jdbcType="INTEGER" property="industry" />
    <result column="summary" jdbcType="VARCHAR" property="summary" />
    <result column="introduce" jdbcType="VARCHAR" property="introduce" />
    <result column="owner_name" jdbcType="VARCHAR" property="ownerName" />
    <result column="publisher_id" jdbcType="VARCHAR" property="publisherId" />
    <result column="reserve_butt_mode" jdbcType="INTEGER" property="reserveButtMode" />
    <result column="patent_number" jdbcType="VARCHAR" property="patentNumber" />
    <result column="transfer_price" jdbcType="VARCHAR" property="transferPrice" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="delete_sign" jdbcType="INTEGER" property="deleteSign" />
  </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 Jun 26 18:27:47 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 Jun 26 18:27:47 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 Jun 26 18:27:47 CST 2018.
    -->
    id, name, type, industry, summary, introduce, owner_name, publisher_id, reserve_butt_mode, 
    patent_number, transfer_price, create_time, delete_sign
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.ScAchievementExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jun 26 18:27:47 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from sc_achievement
    <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 Jun 26 18:27:47 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from sc_achievement
    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 Jun 26 18:27:47 CST 2018.
    -->
    delete from sc_achievement
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.ScAchievementExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jun 26 18:27:47 CST 2018.
    -->
    delete from sc_achievement
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.ScAchievement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jun 26 18:27:47 CST 2018.
    -->
    insert into sc_achievement (id, name, type, 
      industry, summary, introduce, 
      owner_name, publisher_id, reserve_butt_mode, 
      patent_number, transfer_price, create_time, 
      delete_sign)
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, 
      #{industry,jdbcType=INTEGER}, #{summary,jdbcType=VARCHAR}, #{introduce,jdbcType=VARCHAR}, 
      #{ownerName,jdbcType=VARCHAR}, #{publisherId,jdbcType=VARCHAR}, #{reserveButtMode,jdbcType=INTEGER}, 
      #{patentNumber,jdbcType=VARCHAR}, #{transferPrice,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{deleteSign,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.ScAchievement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jun 26 18:27:47 CST 2018.
    -->
    insert into sc_achievement
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="industry != null">
        industry,
      </if>
      <if test="summary != null">
        summary,
      </if>
      <if test="introduce != null">
        introduce,
      </if>
      <if test="ownerName != null">
        owner_name,
      </if>
      <if test="publisherId != null">
        publisher_id,
      </if>
      <if test="reserveButtMode != null">
        reserve_butt_mode,
      </if>
      <if test="patentNumber != null">
        patent_number,
      </if>
      <if test="transferPrice != null">
        transfer_price,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="deleteSign != null">
        delete_sign,
      </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="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="industry != null">
        #{industry,jdbcType=INTEGER},
      </if>
      <if test="summary != null">
        #{summary,jdbcType=VARCHAR},
      </if>
      <if test="introduce != null">
        #{introduce,jdbcType=VARCHAR},
      </if>
      <if test="ownerName != null">
        #{ownerName,jdbcType=VARCHAR},
      </if>
      <if test="publisherId != null">
        #{publisherId,jdbcType=VARCHAR},
      </if>
      <if test="reserveButtMode != null">
        #{reserveButtMode,jdbcType=INTEGER},
      </if>
      <if test="patentNumber != null">
        #{patentNumber,jdbcType=VARCHAR},
      </if>
      <if test="transferPrice != null">
        #{transferPrice,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleteSign != null">
        #{deleteSign,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.ScAchievementExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jun 26 18:27:47 CST 2018.
    -->
    select count(*) from sc_achievement
    <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 Jun 26 18:27:47 CST 2018.
    -->
    update sc_achievement
    <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.type != null">
        type = #{record.type,jdbcType=VARCHAR},
      </if>
      <if test="record.industry != null">
        industry = #{record.industry,jdbcType=INTEGER},
      </if>
      <if test="record.summary != null">
        summary = #{record.summary,jdbcType=VARCHAR},
      </if>
      <if test="record.introduce != null">
        introduce = #{record.introduce,jdbcType=VARCHAR},
      </if>
      <if test="record.ownerName != null">
        owner_name = #{record.ownerName,jdbcType=VARCHAR},
      </if>
      <if test="record.publisherId != null">
        publisher_id = #{record.publisherId,jdbcType=VARCHAR},
      </if>
      <if test="record.reserveButtMode != null">
        reserve_butt_mode = #{record.reserveButtMode,jdbcType=INTEGER},
      </if>
      <if test="record.patentNumber != null">
        patent_number = #{record.patentNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.transferPrice != null">
        transfer_price = #{record.transferPrice,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deleteSign != null">
        delete_sign = #{record.deleteSign,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 Jun 26 18:27:47 CST 2018.
    -->
    update sc_achievement
    set id = #{record.id,jdbcType=VARCHAR},
      name = #{record.name,jdbcType=VARCHAR},
      type = #{record.type,jdbcType=VARCHAR},
      industry = #{record.industry,jdbcType=INTEGER},
      summary = #{record.summary,jdbcType=VARCHAR},
      introduce = #{record.introduce,jdbcType=VARCHAR},
      owner_name = #{record.ownerName,jdbcType=VARCHAR},
      publisher_id = #{record.publisherId,jdbcType=VARCHAR},
      reserve_butt_mode = #{record.reserveButtMode,jdbcType=INTEGER},
      patent_number = #{record.patentNumber,jdbcType=VARCHAR},
      transfer_price = #{record.transferPrice,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      delete_sign = #{record.deleteSign,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.ScAchievement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jun 26 18:27:47 CST 2018.
    -->
    update sc_achievement
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=VARCHAR},
      </if>
      <if test="industry != null">
        industry = #{industry,jdbcType=INTEGER},
      </if>
      <if test="summary != null">
        summary = #{summary,jdbcType=VARCHAR},
      </if>
      <if test="introduce != null">
        introduce = #{introduce,jdbcType=VARCHAR},
      </if>
      <if test="ownerName != null">
        owner_name = #{ownerName,jdbcType=VARCHAR},
      </if>
      <if test="publisherId != null">
        publisher_id = #{publisherId,jdbcType=VARCHAR},
      </if>
      <if test="reserveButtMode != null">
        reserve_butt_mode = #{reserveButtMode,jdbcType=INTEGER},
      </if>
      <if test="patentNumber != null">
        patent_number = #{patentNumber,jdbcType=VARCHAR},
      </if>
      <if test="transferPrice != null">
        transfer_price = #{transferPrice,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleteSign != null">
        delete_sign = #{deleteSign,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.ScAchievement">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jun 26 18:27:47 CST 2018.
    -->
    update sc_achievement
    set name = #{name,jdbcType=VARCHAR},
      type = #{type,jdbcType=VARCHAR},
      industry = #{industry,jdbcType=INTEGER},
      summary = #{summary,jdbcType=VARCHAR},
      introduce = #{introduce,jdbcType=VARCHAR},
      owner_name = #{ownerName,jdbcType=VARCHAR},
      publisher_id = #{publisherId,jdbcType=VARCHAR},
      reserve_butt_mode = #{reserveButtMode,jdbcType=INTEGER},
      patent_number = #{patentNumber,jdbcType=VARCHAR},
      transfer_price = #{transferPrice,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      delete_sign = #{deleteSign,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="findAchievementListByPage" parameterType="String" resultType="com.goafanti.sc.bo.ScAchievementListBo">
		select a.id,a.name,c.name as industry,a.patent_number as patentNumber,a.owner_name as ownerName,b.contacts,b.telephone
		from sc_achievement a left join sc_publisher b on a.publisher_id=b.id
		left join industry_category c on a.industry=c.id
		where a.delete_sign=0
  	<if test="name != null">
  		and a.name  like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="ownerName != null">
  		and a.owner_name like CONCAT('%',#{ownerName,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="patentNumber != null">
  		and a.patent_number = #{patentNumber,jdbcType=VARCHAR}
  	</if>
	order by a.create_time desc
	<if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  
  <select id="findAchievementCount" parameterType="String" resultType="java.lang.Integer">
  	select count(*)
		from sc_achievement a
		where a.delete_sign=0
  	<if test="name != null">
  		and a.name  like CONCAT('%',#{name,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="ownerName != null">
  		and a.owner_name like CONCAT('%',#{ownerName,jdbcType=VARCHAR},'%')
  	</if>
  	<if test="patentNumber != null">
  		and a.patent_number = #{patentNumber,jdbcType=VARCHAR}
  	</if>
  </select>
  
  <select id="selectById" parameterType="String" resultType="com.goafanti.sc.bo.inputAchievement">
		select a.id,a.name,date_format(a.create_time,'%Y-%m-%d %H:%i:%S') as createDateFormat,a.summary,a.`type`,a.industry,
a.introduce,a.owner_name as ownerName,b.introduce as pIntroduce,a.patent_number as patentNumber,
a.publisher_id as publisherId,a.reserve_butt_mode as reserveButtMode,a.transfer_price as transferPrice,
b.telephone,b.contacts as publisherName,b.email,b.zip_code as zipCode,b.province,b.city,d.name as provinceName,e.name as cityName
from sc_achievement a left join sc_publisher b on a.publisher_id=b.id
left join industry_category c on a.industry=c.id
left join district_glossory d on b.province=d.id
left join district_glossory e on b.province=e.id
  		where  a.id = #{id,jdbcType=VARCHAR}
  </select>
</mapper>