<?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.ruoyi.syzy.mapper.BBusiMbtiRecordDetailsMapper">

  <resultMap type="BBusiMbtiRecordDetails" id="BBusiMbtiRecordDetailsResult">
    <result property="id" column="id" />
    <result property="customerCode" column="customerCode" />
    <result property="recordCode" column="recordCode" />
    <result property="stepId" column="stepId" />
    <result property="stepTitle" column="stepTitle" />
    <result property="questionId" column="questionId" />
    <result property="questionTitle" column="questionTitle" />
    <result property="optionA" column="option_a" />
    <result property="optionB" column="option_b" />
    <result property="valueA" column="value_a" />
    <result property="valueB" column="value_b" />
    <result property="answer" column="answer" />
    <result property="status" column="status" />
  </resultMap>

  <sql id="selectBBusiMbtiRecordDetailsVo">
    select id, customerCode, recordCode, stepId, stepTitle, questionId, questionTitle, option_a, option_b, value_a, value_b, answer, status from
    b_busi_mbti_record_details
  </sql>

  <select id="selectBBusiMbtiRecordDetailsList" parameterType="BBusiMbtiRecordDetails" resultMap="BBusiMbtiRecordDetailsResult">
    <include refid="selectBBusiMbtiRecordDetailsVo" />
    <where>
      <if test="customerCode != null  and customerCode != ''"> and customerCode = #{customerCode}</if>
      <if test="recordCode != null  and recordCode != ''"> and recordCode = #{recordCode}</if>
      <if test="stepId != null "> and stepId = #{stepId}</if>
      <if test="stepTitle != null  and stepTitle != ''"> and stepTitle = #{stepTitle}</if>
      <if test="questionId != null "> and questionId = #{questionId}</if>
      <if test="questionTitle != null  and questionTitle != ''"> and questionTitle = #{questionTitle}</if>
      <if test="optionA != null  and optionA != ''"> and option_a = #{optionA}</if>
      <if test="optionB != null  and optionB != ''"> and option_b = #{optionB}</if>
      <if test="valueA != null  and valueA != ''"> and value_a = #{valueA}</if>
      <if test="valueB != null  and valueB != ''"> and value_b = #{valueB}</if>
      <if test="answer != null  and answer != ''"> and answer = #{answer}</if>
      <if test="status != null "> and status = #{status}</if>
    </where>
    order by id
  </select>

  <select id="selectBBusiMbtiRecordDetailsById" parameterType="Long" resultMap="BBusiMbtiRecordDetailsResult">
    <include refid="selectBBusiMbtiRecordDetailsVo" />
    where id = #{id}
  </select>

  <insert id="insertBBusiMbtiRecordDetails" parameterType="BBusiMbtiRecordDetails" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_mbti_record_details
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="customerCode != null and customerCode != ''">customerCode,</if>
      <if test="recordCode != null and recordCode != ''">recordCode,</if>
      <if test="stepId != null">stepId,</if>
      <if test="stepTitle != null and stepTitle != ''">stepTitle,</if>
      <if test="questionId != null">questionId,</if>
      <if test="questionTitle != null">questionTitle,</if>
      <if test="optionA != null">option_a,</if>
      <if test="optionB != null">option_b,</if>
      <if test="valueA != null">value_a,</if>
      <if test="valueB != null">value_b,</if>
      <if test="answer != null">answer,</if>
      <if test="status != null">status,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="customerCode != null and customerCode != ''">#{customerCode},</if>
      <if test="recordCode != null and recordCode != ''">#{recordCode},</if>
      <if test="stepId != null">#{stepId},</if>
      <if test="stepTitle != null and stepTitle != ''">#{stepTitle},</if>
      <if test="questionId != null">#{questionId},</if>
      <if test="questionTitle != null">#{questionTitle},</if>
      <if test="optionA != null">#{optionA},</if>
      <if test="optionB != null">#{optionB},</if>
      <if test="valueA != null">#{valueA},</if>
      <if test="valueB != null">#{valueB},</if>
      <if test="answer != null">#{answer},</if>
      <if test="status != null">#{status},</if>
    </trim>
  </insert>

  <insert id="insertBatch" parameterType="java.util.Collection" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO b_busi_mbti_record_details(customerCode, recordCode, stepId,stepTitle,
    questionId,questionTitle,option_a,option_b,value_a,value_b,answer,status)
    VALUES
    <foreach collection="list" item="item" index="index" separator=",">
      (#{item.customerCode}, #{item.recordCode}, #{item.stepId}, #{item.stepTitle},
      #{item.questionId},#{item.questionTitle},#{item.optionA},#{item.optionB},#{item.valueA},#{item.valueB}
      ,#{item.answer}, #{item.status})
    </foreach>
    ON DUPLICATE KEY UPDATE customerCode = VALUES(customerCode), recordCode = VALUES(recordCode), questionId = VALUES(questionId)
  </insert>

  <update id="updateBBusiMbtiRecordDetails" parameterType="BBusiMbtiRecordDetails">
    update b_busi_mbti_record_details
    <trim prefix="SET" suffixOverrides=",">
      <if test="customerCode != null and customerCode != ''">customerCode = #{customerCode},</if>
      <if test="recordCode != null and recordCode != ''">recordCode = #{recordCode},</if>
      <if test="stepId != null">stepId = #{stepId},</if>
      <if test="stepTitle != null and stepTitle != ''">stepTitle = #{stepTitle},</if>
      <if test="questionId != null">questionId = #{questionId},</if>
      <if test="questionTitle != null">questionTitle = #{questionTitle},</if>
      <if test="optionA != null">option_a = #{optionA},</if>
      <if test="optionB != null">option_b = #{optionB},</if>
      <if test="valueA != null">value_a = #{valueA},</if>
      <if test="valueB != null">value_b = #{valueB},</if>
      <if test="answer != null">answer = #{answer},</if>
      <if test="status != null">status = #{status},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBBusiMbtiRecordDetailsById" parameterType="Long">
    delete from b_busi_mbti_record_details where id = #{id}
  </delete>

  <delete id="deleteBBusiMbtiRecordDetailsByIds" parameterType="String">
    delete from b_busi_mbti_record_details where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
</mapper>