<?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.cool.store.mapper.HyPartnerCertificationInfoMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.HyPartnerCertificationInfoDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="partner_id" jdbcType="VARCHAR" property="partnerId" />
    <result column="partner_line_id" jdbcType="BIGINT" property="partnerLineId" />
    <result column="partner_interview_id" jdbcType="BIGINT" property="partnerInterviewId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, partner_id, partner_line_id, partner_interview_id, qualify_verify_id, intention_contract_no, data_source, certification_info_record_json, create_time, update_time
  </sql>
  <insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
    insert into hy_partner_certification_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="record.partnerId != null">
        partner_id,
      </if>
      <if test="record.partnerLineId != null">
        partner_line_id,
      </if>
      <if test="record.partnerInterviewId != null">
        partner_interview_id,
      </if>
      <if test="record.qualifyVerifyId != null">
        qualify_verify_id,
      </if>
      <if test="record.intentionContractNo != null">
        intention_contract_no,
      </if>
      <if test="record.dataSource != null">
        data_source,
      </if>
      <if test="record.certificationInfoRecordJson != null">
        certification_info_record_json,
      </if>
      <if test="record.createTime != null">
        create_time,
      </if>
      <if test="record.updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="record.partnerId != null">
        #{record.partnerId},
      </if>
      <if test="record.partnerLineId != null">
        #{record.partnerLineId},
      </if>
      <if test="record.partnerInterviewId != null">
        #{record.partnerInterviewId},
      </if>
      <if test="record.qualifyVerifyId != null">
        #{record.qualifyVerifyId},
      </if>
      <if test="record.intentionContractNo != null">
        #{record.intentionContractNo},
      </if>
      <if test="record.dataSource != null">
        #{record.dataSource},
      </if>
      <if test="record.certificationInfoRecordJson != null">
        #{record.certificationInfoRecordJson},
      </if>
      <if test="record.createTime != null">
        #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        #{record.updateTime},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective">
    update hy_partner_certification_info
    <set>
      <if test="record.partnerId != null">
        partner_id = #{record.partnerId},
      </if>
      <if test="record.partnerLineId != null">
        partner_line_id = #{record.partnerLineId},
      </if>
      <if test="record.partnerInterviewId != null">
        partner_interview_id = #{record.partnerInterviewId},
      </if>
      <if test="record.qualifyVerifyId != null">
        qualify_verify_id = #{record.qualifyVerifyId},
      </if>
      <if test="record.intentionContractNo != null">
        intention_contract_no = #{record.intentionContractNo},
      </if>
      <if test="record.dataSource != null">
        data_source = #{record.dataSource},
      </if>
      <if test="record.certificationInfoRecordJson != null">
        certification_info_record_json = #{record.certificationInfoRecordJson},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime},
      </if>
    </set>
    <where>
      1 = 0
      <if test="record.id != null">
        or id = #{record.id}
      </if>
      <if test="record.partnerLineId != null">
        or partner_line_id = #{record.partnerLineId}
      </if>
    </where>
  </update>

  <!-- 根据资质审核流程 id 获取面试会议 id -->
  <select id="getInterviewIdByQualifyVerifyId" resultType="java.lang.String">
    select partner_interview_id
      from hy_partner_certification_info
      where qualify_verify_id = #{qualifyVerifyId}
  </select>

  <!-- 根据资质审核流程 id 获取面试会议计划 id -->
  <select id="getInterviewPlanIdByQualifyVerifyId" resultType="java.lang.String">
    select interview_plan_id
      from hy_partner_interview
      where id = (
        select partner_interview_id
          from hy_partner_certification_info
          where qualify_verify_id = #{qualifyVerifyId}
      )
      and deleted = 0
  </select>
    <select id="selectByPartnerLineId" resultType="com.cool.store.entity.HyPartnerCertificationInfoDO">
    select
      <include refid="Base_Column_List" />
    from hy_partner_certification_info
    where partner_line_id = #{partnerLineId}
    </select>

  <update id="updateLineId">
    update hy_partner_interview
    set partner_line_id = #{newLineId}  , partner_id = #{newPartnerId}
    where partner_line_id = #{oldLineId}
  </update>
</mapper>