<?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.PatentRegistrationMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.PatentRegistration" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="pid" property="pid" jdbcType="VARCHAR" />
    <result column="acceptance_receive_time" property="acceptanceReceiveTime" jdbcType="TIMESTAMP" />
    <result column="acceptance_issue_time" property="acceptanceIssueTime" jdbcType="TIMESTAMP" />
    <result column="acceptance_tracking_number" property="acceptanceTrackingNumber" jdbcType="VARCHAR" />
    <result column="acceptance_express_company" property="acceptanceExpressCompany" jdbcType="VARCHAR" />
    <result column="authorization_receive_time" property="authorizationReceiveTime" jdbcType="TIMESTAMP" />
    <result column="authorization_issue_time" property="authorizationIssueTime" jdbcType="TIMESTAMP" />
    <result column="authorization_tracking_number" property="authorizationTrackingNumber" jdbcType="VARCHAR" />
    <result column="authorization_express_company" property="authorizationExpressCompany" jdbcType="VARCHAR" />
    <result column="certificate_recieve_time" property="certificateRecieveTime" jdbcType="TIMESTAMP" />
    <result column="certificate_issue_time" property="certificateIssueTime" jdbcType="TIMESTAMP" />
    <result column="certificate_tracking_number" property="certificateTrackingNumber" jdbcType="VARCHAR" />
    <result column="certificate_express_company" property="certificateExpressCompany" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, pid, acceptance_receive_time, acceptance_issue_time, acceptance_tracking_number, 
    acceptance_express_company, authorization_receive_time, authorization_issue_time, 
    authorization_tracking_number, authorization_express_company, certificate_recieve_time, 
    certificate_issue_time, certificate_tracking_number, certificate_express_company
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from patent_registration
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from patent_registration
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.PatentRegistration" >
    insert into patent_registration (id, pid, acceptance_receive_time, 
      acceptance_issue_time, acceptance_tracking_number, 
      acceptance_express_company, authorization_receive_time, 
      authorization_issue_time, authorization_tracking_number, 
      authorization_express_company, certificate_recieve_time, 
      certificate_issue_time, certificate_tracking_number, 
      certificate_express_company)
    values (#{id,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR}, #{acceptanceReceiveTime,jdbcType=TIMESTAMP}, 
      #{acceptanceIssueTime,jdbcType=TIMESTAMP}, #{acceptanceTrackingNumber,jdbcType=VARCHAR}, 
      #{acceptanceExpressCompany,jdbcType=VARCHAR}, #{authorizationReceiveTime,jdbcType=TIMESTAMP}, 
      #{authorizationIssueTime,jdbcType=TIMESTAMP}, #{authorizationTrackingNumber,jdbcType=VARCHAR}, 
      #{authorizationExpressCompany,jdbcType=VARCHAR}, #{certificateRecieveTime,jdbcType=TIMESTAMP}, 
      #{certificateIssueTime,jdbcType=TIMESTAMP}, #{certificateTrackingNumber,jdbcType=VARCHAR}, 
      #{certificateExpressCompany,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.PatentRegistration" >
    insert into patent_registration
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="pid != null" >
        pid,
      </if>
      <if test="acceptanceReceiveTime != null" >
        acceptance_receive_time,
      </if>
      <if test="acceptanceIssueTime != null" >
        acceptance_issue_time,
      </if>
      <if test="acceptanceTrackingNumber != null" >
        acceptance_tracking_number,
      </if>
      <if test="acceptanceExpressCompany != null" >
        acceptance_express_company,
      </if>
      <if test="authorizationReceiveTime != null" >
        authorization_receive_time,
      </if>
      <if test="authorizationIssueTime != null" >
        authorization_issue_time,
      </if>
      <if test="authorizationTrackingNumber != null" >
        authorization_tracking_number,
      </if>
      <if test="authorizationExpressCompany != null" >
        authorization_express_company,
      </if>
      <if test="certificateRecieveTime != null" >
        certificate_recieve_time,
      </if>
      <if test="certificateIssueTime != null" >
        certificate_issue_time,
      </if>
      <if test="certificateTrackingNumber != null" >
        certificate_tracking_number,
      </if>
      <if test="certificateExpressCompany != null" >
        certificate_express_company,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="pid != null" >
        #{pid,jdbcType=VARCHAR},
      </if>
      <if test="acceptanceReceiveTime != null" >
        #{acceptanceReceiveTime,jdbcType=TIMESTAMP},
      </if>
      <if test="acceptanceIssueTime != null" >
        #{acceptanceIssueTime,jdbcType=TIMESTAMP},
      </if>
      <if test="acceptanceTrackingNumber != null" >
        #{acceptanceTrackingNumber,jdbcType=VARCHAR},
      </if>
      <if test="acceptanceExpressCompany != null" >
        #{acceptanceExpressCompany,jdbcType=VARCHAR},
      </if>
      <if test="authorizationReceiveTime != null" >
        #{authorizationReceiveTime,jdbcType=TIMESTAMP},
      </if>
      <if test="authorizationIssueTime != null" >
        #{authorizationIssueTime,jdbcType=TIMESTAMP},
      </if>
      <if test="authorizationTrackingNumber != null" >
        #{authorizationTrackingNumber,jdbcType=VARCHAR},
      </if>
      <if test="authorizationExpressCompany != null" >
        #{authorizationExpressCompany,jdbcType=VARCHAR},
      </if>
      <if test="certificateRecieveTime != null" >
        #{certificateRecieveTime,jdbcType=TIMESTAMP},
      </if>
      <if test="certificateIssueTime != null" >
        #{certificateIssueTime,jdbcType=TIMESTAMP},
      </if>
      <if test="certificateTrackingNumber != null" >
        #{certificateTrackingNumber,jdbcType=VARCHAR},
      </if>
      <if test="certificateExpressCompany != null" >
        #{certificateExpressCompany,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.PatentRegistration" >
    update patent_registration
    <set >
      <if test="pid != null" >
        pid = #{pid,jdbcType=VARCHAR},
      </if>
      <if test="acceptanceReceiveTime != null" >
        acceptance_receive_time = #{acceptanceReceiveTime,jdbcType=TIMESTAMP},
      </if>
      <if test="acceptanceIssueTime != null" >
        acceptance_issue_time = #{acceptanceIssueTime,jdbcType=TIMESTAMP},
      </if>
      <if test="acceptanceTrackingNumber != null" >
        acceptance_tracking_number = #{acceptanceTrackingNumber,jdbcType=VARCHAR},
      </if>
      <if test="acceptanceExpressCompany != null" >
        acceptance_express_company = #{acceptanceExpressCompany,jdbcType=VARCHAR},
      </if>
      <if test="authorizationReceiveTime != null" >
        authorization_receive_time = #{authorizationReceiveTime,jdbcType=TIMESTAMP},
      </if>
      <if test="authorizationIssueTime != null" >
        authorization_issue_time = #{authorizationIssueTime,jdbcType=TIMESTAMP},
      </if>
      <if test="authorizationTrackingNumber != null" >
        authorization_tracking_number = #{authorizationTrackingNumber,jdbcType=VARCHAR},
      </if>
      <if test="authorizationExpressCompany != null" >
        authorization_express_company = #{authorizationExpressCompany,jdbcType=VARCHAR},
      </if>
      <if test="certificateRecieveTime != null" >
        certificate_recieve_time = #{certificateRecieveTime,jdbcType=TIMESTAMP},
      </if>
      <if test="certificateIssueTime != null" >
        certificate_issue_time = #{certificateIssueTime,jdbcType=TIMESTAMP},
      </if>
      <if test="certificateTrackingNumber != null" >
        certificate_tracking_number = #{certificateTrackingNumber,jdbcType=VARCHAR},
      </if>
      <if test="certificateExpressCompany != null" >
        certificate_express_company = #{certificateExpressCompany,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.PatentRegistration" >
    update patent_registration
    set pid = #{pid,jdbcType=VARCHAR},
      acceptance_receive_time = #{acceptanceReceiveTime,jdbcType=TIMESTAMP},
      acceptance_issue_time = #{acceptanceIssueTime,jdbcType=TIMESTAMP},
      acceptance_tracking_number = #{acceptanceTrackingNumber,jdbcType=VARCHAR},
      acceptance_express_company = #{acceptanceExpressCompany,jdbcType=VARCHAR},
      authorization_receive_time = #{authorizationReceiveTime,jdbcType=TIMESTAMP},
      authorization_issue_time = #{authorizationIssueTime,jdbcType=TIMESTAMP},
      authorization_tracking_number = #{authorizationTrackingNumber,jdbcType=VARCHAR},
      authorization_express_company = #{authorizationExpressCompany,jdbcType=VARCHAR},
      certificate_recieve_time = #{certificateRecieveTime,jdbcType=TIMESTAMP},
      certificate_issue_time = #{certificateIssueTime,jdbcType=TIMESTAMP},
      certificate_tracking_number = #{certificateTrackingNumber,jdbcType=VARCHAR},
      certificate_express_company = #{certificateExpressCompany,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="findRecieveSendList" resultType="com.goafanti.patent.bo.PatentRecieveSendBo">
  	select 
  		p.id as pid ,
  		p.uid as uid, 
  		o.id as oid, 
  		r.id as rid, 
  		p.serial_number as serialNumber ,
  		p.patent_number as patentNumber ,
        o.licence_province as locationProvince , 
        o.unit_name as unitName ,
        p.patent_catagory as patentCatagory , 
        p.patent_name as patentName,
 	    r.acceptance_receive_time as acceptanceReceiveTime , 
 	    r.acceptance_issue_time as acceptanceIssueTime, 
  	    r.acceptance_tracking_number as acceptanceTrackingNumber , 
  	    r.acceptance_express_company as acceptanceExpressCompany,
        r.authorization_receive_time as authorizationReceiveTime , 
        r.authorization_issue_time as authorizationIssueTime, 
        r.authorization_tracking_number as authorizationTrackingNumber , 
        r.authorization_express_company as authorizationExpressCompany,
        r.certificate_recieve_time as certificateRecieveTime, 
        r.certificate_issue_time as certificateIssueTime, 
        r.certificate_tracking_number as certificateTrackingNumber, 
        r.certificate_express_company as certificateExpressCompany
		from patent_info p 
		LEFT  JOIN patent_registration r  on p.id = r.pid
		LEFT JOIN organization_identity o on o.uid = p.uid
		<if test="principal != null">
			left join contract_log l on p.contract_id=l.cid
		</if>
		 where p.deleted_sign = 0
		<if test="principal != null">
			group by p.id,o.id,r.id
		</if>
		order by p.serial_number DESC
		<if test="page_sql!=null">
			${page_sql}
		</if>
  </select>
  
  <select id="findRecieveSendCount" resultType="java.lang.Integer">
  	select count(distinct(p.id))
	from patent_info p 
	LEFT  JOIN patent_registration r  on p.id = r.pid
	LEFT JOIN organization_identity o on o.uid = p.uid 
	<if test="principal != null">
		left join contract_log l on p.contract_id=l.cid
	</if>
	where p.deleted_sign = 0
	<if test="principal != null">
			group by p.id
	</if>
  </select>
  
  <insert id="batchInsert" parameterType="com.goafanti.common.model.PatentRegistration">
     insert into patent_registration (id, pid, acceptance_receive_time, 
      acceptance_issue_time, acceptance_tracking_number, 
      acceptance_express_company, authorization_receive_time, 
      authorization_issue_time, authorization_tracking_number, 
      authorization_express_company, certificate_recieve_time, 
      certificate_issue_time, certificate_tracking_number, 
      certificate_express_company)
	values 
    <foreach item="item" index="index" collection="list" separator=",">
      (
      #{item.id,jdbcType=VARCHAR}, #{item.pid,jdbcType=VARCHAR}, #{item.acceptanceReceiveTime,jdbcType=TIMESTAMP}, 
      #{item.acceptanceIssueTime,jdbcType=TIMESTAMP}, #{item.acceptanceTrackingNumber,jdbcType=VARCHAR}, 
      #{item.acceptanceExpressCompany,jdbcType=VARCHAR}, #{item.authorizationReceiveTime,jdbcType=TIMESTAMP}, 
      #{item.authorizationIssueTime,jdbcType=TIMESTAMP}, #{item.authorizationTrackingNumber,jdbcType=VARCHAR}, 
      #{item.authorizationExpressCompany,jdbcType=VARCHAR}, #{item.certificateRecieveTime,jdbcType=TIMESTAMP}, 
      #{item.certificateIssueTime,jdbcType=TIMESTAMP}, #{item.certificateTrackingNumber,jdbcType=VARCHAR}, 
      #{item.certificateExpressCompany,jdbcType=VARCHAR}
      )
    </foreach>
  </insert>
  
</mapper>