<?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.PatentNewMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.PatentNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 08 14:33:37 CST 2019.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="patent_no" jdbcType="VARCHAR" property="patentNo" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="apply_date" jdbcType="DATE" property="applyDate" />
    <result column="authorization_date" jdbcType="DATE" property="authorizationDate" />
    <result column="patent_amount" jdbcType="DECIMAL" property="patentAmount" />
    <result column="applicant" jdbcType="VARCHAR" property="applicant" />
    <result column="province" jdbcType="INTEGER" property="province" />
    <result column="contact_mobile" jdbcType="VARCHAR" property="contactMobile" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="certificate_url" jdbcType="VARCHAR" property="certificateUrl" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="years" jdbcType="INTEGER" property="years" />
  </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 08 14:33:37 CST 2019.
    -->
    <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 08 14:33:37 CST 2019.
    -->
    <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 08 14:33:37 CST 2019.
    -->
    id, patent_no, name, type, status, apply_date, authorization_date, patent_amount, 
    applicant, province, contact_mobile, email, certificate_url, create_time, update_time, 
    aid, years
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.PatentNewExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 08 14:33:37 CST 2019.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from patent_new
    <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 Wed May 08 14:33:37 CST 2019.
    -->
    select 
    <include refid="Base_Column_List" />
    from patent_new
    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 Wed May 08 14:33:37 CST 2019.
    -->
    delete from patent_new
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.PatentNewExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 08 14:33:37 CST 2019.
    -->
    delete from patent_new
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.PatentNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 08 14:33:37 CST 2019.
    -->
    insert into patent_new (id, patent_no, name, 
      type, status, apply_date, 
      authorization_date, patent_amount, applicant, 
      province, contact_mobile, email, 
      certificate_url, create_time, update_time, 
      aid, years)
    values (#{id,jdbcType=INTEGER}, #{patentNo,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{type,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{applyDate,jdbcType=DATE}, 
      #{authorizationDate,jdbcType=DATE}, #{patentAmount,jdbcType=DECIMAL}, #{applicant,jdbcType=VARCHAR}, 
      #{province,jdbcType=INTEGER}, #{contactMobile,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, 
      #{certificateUrl,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, 
      #{aid,jdbcType=VARCHAR}, #{years,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.PatentNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 08 14:33:37 CST 2019.
    -->
    insert into patent_new
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="patentNo != null">
        patent_no,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="applyDate != null">
        apply_date,
      </if>
      <if test="authorizationDate != null">
        authorization_date,
      </if>
      <if test="patentAmount != null">
        patent_amount,
      </if>
      <if test="applicant != null">
        applicant,
      </if>
      <if test="province != null">
        province,
      </if>
      <if test="contactMobile != null">
        contact_mobile,
      </if>
      <if test="email != null">
        email,
      </if>
      <if test="certificateUrl != null">
        certificate_url,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="years != null">
        years,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="patentNo != null">
        #{patentNo,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="applyDate != null">
        #{applyDate,jdbcType=DATE},
      </if>
      <if test="authorizationDate != null">
        #{authorizationDate,jdbcType=DATE},
      </if>
      <if test="patentAmount != null">
        #{patentAmount,jdbcType=DECIMAL},
      </if>
      <if test="applicant != null">
        #{applicant,jdbcType=VARCHAR},
      </if>
      <if test="province != null">
        #{province,jdbcType=INTEGER},
      </if>
      <if test="contactMobile != null">
        #{contactMobile,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="certificateUrl != null">
        #{certificateUrl,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="years != null">
        #{years,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.PatentNewExample" 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 08 14:33:37 CST 2019.
    -->
    select count(*) from patent_new
    <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 08 14:33:37 CST 2019.
    -->
    update patent_new
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.patentNo != null">
        patent_no = #{record.patentNo,jdbcType=VARCHAR},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.type != null">
        type = #{record.type,jdbcType=INTEGER},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </if>
      <if test="record.applyDate != null">
        apply_date = #{record.applyDate,jdbcType=DATE},
      </if>
      <if test="record.authorizationDate != null">
        authorization_date = #{record.authorizationDate,jdbcType=DATE},
      </if>
      <if test="record.patentAmount != null">
        patent_amount = #{record.patentAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.applicant != null">
        applicant = #{record.applicant,jdbcType=VARCHAR},
      </if>
      <if test="record.province != null">
        province = #{record.province,jdbcType=INTEGER},
      </if>
      <if test="record.contactMobile != null">
        contact_mobile = #{record.contactMobile,jdbcType=VARCHAR},
      </if>
      <if test="record.email != null">
        email = #{record.email,jdbcType=VARCHAR},
      </if>
      <if test="record.certificateUrl != null">
        certificate_url = #{record.certificateUrl,jdbcType=VARCHAR},
      </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.aid != null">
        aid = #{record.aid,jdbcType=VARCHAR},
      </if>
      <if test="record.years != null">
        years = #{record.years,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 08 14:33:37 CST 2019.
    -->
    update patent_new
    set id = #{record.id,jdbcType=INTEGER},
      patent_no = #{record.patentNo,jdbcType=VARCHAR},
      name = #{record.name,jdbcType=VARCHAR},
      type = #{record.type,jdbcType=INTEGER},
      status = #{record.status,jdbcType=INTEGER},
      apply_date = #{record.applyDate,jdbcType=DATE},
      authorization_date = #{record.authorizationDate,jdbcType=DATE},
      patent_amount = #{record.patentAmount,jdbcType=DECIMAL},
      applicant = #{record.applicant,jdbcType=VARCHAR},
      province = #{record.province,jdbcType=INTEGER},
      contact_mobile = #{record.contactMobile,jdbcType=VARCHAR},
      email = #{record.email,jdbcType=VARCHAR},
      certificate_url = #{record.certificateUrl,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      aid = #{record.aid,jdbcType=VARCHAR},
      years = #{record.years,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.PatentNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 08 14:33:37 CST 2019.
    -->
    update patent_new
    <set>
      <if test="patentNo != null">
        patent_no = #{patentNo,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="applyDate != null">
        apply_date = #{applyDate,jdbcType=DATE},
      </if>
      <if test="authorizationDate != null">
        authorization_date = #{authorizationDate,jdbcType=DATE},
      </if>
      <if test="patentAmount != null">
        patent_amount = #{patentAmount,jdbcType=DECIMAL},
      </if>
      <if test="applicant != null">
        applicant = #{applicant,jdbcType=VARCHAR},
      </if>
      <if test="province != null">
        province = #{province,jdbcType=INTEGER},
      </if>
      <if test="contactMobile != null">
        contact_mobile = #{contactMobile,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="certificateUrl != null">
        certificate_url = #{certificateUrl,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="years != null">
        years = #{years,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.PatentNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed May 08 14:33:37 CST 2019.
    -->
    update patent_new
    set patent_no = #{patentNo,jdbcType=VARCHAR},
      name = #{name,jdbcType=VARCHAR},
      type = #{type,jdbcType=INTEGER},
      status = #{status,jdbcType=INTEGER},
      apply_date = #{applyDate,jdbcType=DATE},
      authorization_date = #{authorizationDate,jdbcType=DATE},
      patent_amount = #{patentAmount,jdbcType=DECIMAL},
      applicant = #{applicant,jdbcType=VARCHAR},
      province = #{province,jdbcType=INTEGER},
      contact_mobile = #{contactMobile,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      certificate_url = #{certificateUrl,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      aid = #{aid,jdbcType=VARCHAR},
      years = #{years,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  <select id="selectPatentNewList" resultType="com.goafanti.patent.bo.PatentNewBo">
	  	  select a.id,a.patent_no as patentNo,a.name,a.type,a.status,
	  date_format(a.apply_date,'%Y-%m-%d') as applyDates,
	  date_format(a.authorization_date ,'%Y-%m-%d ')as authorizationDates,a.patent_amount as patentAmount,a.province,
	a.applicant,a.contact_mobile as contactMobile,a.email,a.certificate_url as certificateUrl,
	date_format(a.create_time,'%Y-%m-%d %H:%I:%S') as createTimeS,a.apply_date as applyDate,c.name depName,
	date_format(a.update_time,'%Y-%m-%d %H:%I:%S') as updateTimeS,b.name as aname
	from patent_new a left join admin b on a.aid=b.id
	left join department c on b.department_id=c.id
	<if test="shiro ==1">
     left join admin e on e.department_id=c.id
	</if>
	where 1=1
	<if test="shiro ==0">
     and  a.aid = #{aid,jdbcType=VARCHAR}
	</if>
	<if test="shiro ==1">
     and  e.id = #{aid,jdbcType=VARCHAR}
	</if>
    <if test="status != null">
     and a.status=#{status}
     </if>
       <if test="type != null">
     and a.type=#{type}
     </if>
     <if test="startDate != null and endDate != null">
     and a.apply_date between  #{startDate} and  #{endDate}
     </if>
     <if test="name != null">
     and a.applicant  like concat('%',#{name},'%')
     </if>
     <if test="patentNo != null">
     and a.patent_no like concat('%',#{patentNo},'%')
     </if>
     <if test="aname != null">
     and b.name like concat('%',#{aname},'%')
     </if>
     <if test="departmentId != null">
     and b.department_id= #{departmentId}
     </if>
	order by a.status ,a.create_time
	<if test="page_sql!=null">
			${page_sql}
		</if>
  </select>
    <select id="selectPatentNewCount" resultType="java.lang.Integer">
	  select count(*)
	from patent_new a left join admin b on a.aid=b.id
	left join department c on b.department_id=c.id
	<if test="shiro ==1">
     left join admin e on e.department_id=c.id
	</if>
	where 1=1
	<if test="shiro ==0">
     and  a.aid = #{aid,jdbcType=VARCHAR}
	</if>
	<if test="shiro ==1">
     and  e.id = #{aid,jdbcType=VARCHAR}
	</if>
    <if test="status != null">
     and a.status=#{status}
     </if>
       <if test="type != null">
     and a.type=#{type}
     </if>
     <if test="startDate != null and endDate != null">
     and a.apply_date between  #{startDate} and  #{endDate}
     </if>
     <if test="name != null">
     and a.applicant  like concat('%',#{name},'%')
     </if>
     <if test="patentNo != null">
     and a.patent_no like concat('%',#{patentNo},'%')
     </if>
     <if test="aname != null">
     and b.name like concat('%',#{aname},'%')
     </if>
     <if test="departmentId != null">
     and b.department_id= #{departmentId}
     </if>
	</select>
	
	<select id="AllselectStartPatentNew" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from patent_new where status =0
    </select>
    <select id="AllselectEndPatentNew" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from patent_new where status =1
    </select>
    
    <update id="updateAdmin">
    update patent_new set aid= #{transferId}
	where aid= #{aid} 
    </update>
</mapper>