<?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.HyPartnerIntentInfoMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.HyPartnerIntentInfoDO">
    <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="live_area" jdbcType="VARCHAR" property="liveArea" />
    <result column="want_shop_area" jdbcType="VARCHAR" property="wantShopArea" />
    <result column="accept_adjust_type" jdbcType="TINYINT" property="acceptAdjustType" />
    <result column="is_have_want_shop" jdbcType="TINYINT" property="isHaveWantShop" />
    <result column="want_shop_info" jdbcType="VARCHAR" property="wantShopInfo" />
    <result column="max_budget" jdbcType="VARCHAR" property="maxBudget" />
    <result column="money_source" jdbcType="VARCHAR" property="moneySource" />
    <result column="money_prove" jdbcType="VARCHAR" property="moneyProve" />
    <result column="education" jdbcType="VARCHAR" property="education" />
    <result column="work_year" jdbcType="VARCHAR" property="workYear" />
    <result column="is_have_work_exp" jdbcType="TINYINT" property="isHaveWorkExp" />
    <result column="work_exp" jdbcType="VARCHAR" property="workExp" />
    <result column="is_consumer" jdbcType="TINYINT" property="isConsumer" />
    <result column="other_band" jdbcType="VARCHAR" property="otherBand" />
    <result column="brand_strength" jdbcType="VARCHAR" property="brandStrength" />
    <result column="need_improve" jdbcType="VARCHAR" property="needImprove" />
    <result column="strength" jdbcType="VARCHAR" property="strength" />
    <result column="weakness" jdbcType="VARCHAR" property="weakness" />
    <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, live_area, want_shop_area, accept_adjust_type, is_have_want_shop, 
    want_shop_info, max_budget, money_source, money_prove, education, work_year, is_have_work_exp, 
    work_exp, is_consumer, other_band, brand_strength, need_improve, strength, weakness, 
    create_time, update_time
  </sql>
  <select id="selectByPrimaryKeySelective" resultMap="BaseResultMap">
    select
      <include refid="Base_Column_List"></include>
    from hy_partner_intent_info
    <where>
      and id = #{id}
    </where>
  </select>
  <insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
    insert into hy_partner_intent_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.liveArea != null">
        live_area,
      </if>
      <if test="record.wantShopArea != null">
        want_shop_area,
      </if>
      <if test="record.acceptAdjustType != null">
        accept_adjust_type,
      </if>
      <if test="record.isHaveWantShop != null">
        is_have_want_shop,
      </if>
      <if test="record.wantShopInfo != null">
        want_shop_info,
      </if>
      <if test="record.maxBudget != null">
        max_budget,
      </if>
      <if test="record.moneySource != null">
        money_source,
      </if>
      <if test="record.moneyProve != null">
        money_prove,
      </if>
      <if test="record.education != null">
        education,
      </if>
      <if test="record.workYear != null">
        work_year,
      </if>
      <if test="record.isHaveWorkExp != null">
        is_have_work_exp,
      </if>
      <if test="record.workExp != null">
        work_exp,
      </if>
      <if test="record.isConsumer != null">
        is_consumer,
      </if>
      <if test="record.otherBand != null">
        other_band,
      </if>
      <if test="record.brandStrength != null">
        brand_strength,
      </if>
      <if test="record.needImprove != null">
        need_improve,
      </if>
      <if test="record.strength != null">
        strength,
      </if>
      <if test="record.weakness != null">
        weakness,
      </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.liveArea != null">
        #{record.liveArea},
      </if>
      <if test="record.wantShopArea != null">
        #{record.wantShopArea},
      </if>
      <if test="record.acceptAdjustType != null">
        #{record.acceptAdjustType},
      </if>
      <if test="record.isHaveWantShop != null">
        #{record.isHaveWantShop},
      </if>
      <if test="record.wantShopInfo != null">
        #{record.wantShopInfo},
      </if>
      <if test="record.maxBudget != null">
        #{record.maxBudget},
      </if>
      <if test="record.moneySource != null">
        #{record.moneySource},
      </if>
      <if test="record.moneyProve != null">
        #{record.moneyProve},
      </if>
      <if test="record.education != null">
        #{record.education},
      </if>
      <if test="record.workYear != null">
        #{record.workYear},
      </if>
      <if test="record.isHaveWorkExp != null">
        #{record.isHaveWorkExp},
      </if>
      <if test="record.workExp != null">
        #{record.workExp},
      </if>
      <if test="record.isConsumer != null">
        #{record.isConsumer},
      </if>
      <if test="record.otherBand != null">
        #{record.otherBand},
      </if>
      <if test="record.brandStrength != null">
        #{record.brandStrength},
      </if>
      <if test="record.needImprove != null">
        #{record.needImprove},
      </if>
      <if test="record.strength != null">
        #{record.strength},
      </if>
      <if test="record.weakness != null">
        #{record.weakness},
      </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_intent_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.liveArea != null">
        live_area = #{record.liveArea},
      </if>
      <if test="record.wantShopArea != null">
        want_shop_area = #{record.wantShopArea},
      </if>
      <if test="record.acceptAdjustType != null">
        accept_adjust_type = #{record.acceptAdjustType},
      </if>
      <if test="record.isHaveWantShop != null">
        is_have_want_shop = #{record.isHaveWantShop},
      </if>
      <if test="record.wantShopInfo != null">
        want_shop_info = #{record.wantShopInfo},
      </if>
      <if test="record.maxBudget != null">
        max_budget = #{record.maxBudget},
      </if>
      <if test="record.moneySource != null">
        money_source = #{record.moneySource},
      </if>
      <if test="record.moneyProve != null">
        money_prove = #{record.moneyProve},
      </if>
      <if test="record.education != null">
        education = #{record.education},
      </if>
      <if test="record.workYear != null">
        work_year = #{record.workYear},
      </if>
      <if test="record.isHaveWorkExp != null">
        is_have_work_exp = #{record.isHaveWorkExp},
      </if>
      <if test="record.workExp != null">
        work_exp = #{record.workExp},
      </if>
      <if test="record.isConsumer != null">
        is_consumer = #{record.isConsumer},
      </if>
      <if test="record.otherBand != null">
        other_band = #{record.otherBand},
      </if>
      <if test="record.brandStrength != null">
        brand_strength = #{record.brandStrength},
      </if>
      <if test="record.needImprove != null">
        need_improve = #{record.needImprove},
      </if>
      <if test="record.strength != null">
        strength = #{record.strength},
      </if>
      <if test="record.weakness != null">
        weakness = #{record.weakness},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime},
      </if>
    </set>
    where id = #{record.id}
  </update>

  <select id="selectPartnerIntentApplyInfoList" resultType="com.cool.store.dto.partner.PartnerIntentApplyInfoDTO">
    select
    a.id as partnerLineId,
    a.partner_id as partnerId,
    a.workflow_stage as workflowStage,
    a.workflow_status as workflowStatus,
    b.id as id,
    b.create_time as partnerSubmitTime,
    b.deadline as deadline,
    hpuinfo.live_area as liveArea,
    hpuinfo.want_shop_area as wantShopArea,
    hpuinfo.accept_adjust_type as acceptAdjustType
    from  hy_partner_line_info a
    left join  hy_partner_intent_info b  on  a.id = b.partner_line_id
    LEFT JOIN hy_partner_user_info hpuinfo ON a.partner_id = hpuinfo.partner_id
    where deleted = 0 and line_status!=3
    <if test="userId!=null and userId!=''">
      and a.investment_manager = #{userId}
    </if>
    <if test="workflowStage!=null and workflowStage!=''">
      and a.workflow_stage= #{workflowStage}
    </if>
    <if test="workflowStatus!=null and workflowStatus!=''">
      and a.workflow_status = #{workflowStatus}
    </if>
    order by b.create_time
  </select>

  <select id="selectByLineId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"></include>
    from hy_partner_intent_info
    <where>
      and partner_line_id = #{lineId}
    </where>
  </select>

  <select id="getByPartnerIdAndLineId" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List"></include>
    from hy_partner_intent_info
    where partner_id = #{partnerId} and partner_line_id = #{partnerLineId}
  </select>


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



</mapper>