<?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.BBusiHollandQuestionsMapper">

  <resultMap type="BBusiHollandQuestions" id="BBusiHollandQuestionsResult">
    <result property="id" column="id" />
    <result property="stepId" column="stepId" />
    <result property="no" column="no" />
    <result property="title" column="title" />
    <result property="ruleCode" column="ruleCode" />
    <result property="status" column="status" />
  </resultMap>

  <resultMap id="BBusiHollandQuestionsBBusiHollandQuestionOptionsResult" type="BBusiHollandQuestions" extends="BBusiHollandQuestionsResult">
    <collection property="options" notNullColumn="sub_id" javaType="java.util.List" resultMap="BBusiHollandQuestionOptionsResult" />
  </resultMap>

  <resultMap type="BBusiHollandQuestionOptions" id="BBusiHollandQuestionOptionsResult">
    <result property="id" column="sub_id" />
    <result property="questionId" column="sub_questionId" />
    <result property="no" column="sub_no" />
    <result property="label" column="sub_label" />
    <result property="status" column="sub_status" />
  </resultMap>

  <sql id="selectBBusiHollandQuestionsVo">
    select id, stepId, no, title, ruleCode, status from b_busi_holland_questions
  </sql>

  <select id="selectBBusiHollandQuestionsList" parameterType="BBusiHollandQuestions" resultMap="BBusiHollandQuestionsResult">
    <include refid="selectBBusiHollandQuestionsVo" />
    <where>
      <if test="stepId != null "> and stepId = #{stepId}</if>
      <if test="no != null "> and no = #{no}</if>
      <if test="title != null  and title != ''"> and title = #{title}</if>
      <if test="ruleCode != null  and ruleCode != ''"> and ruleCode = #{ruleCode}</if>
      <if test="status != null "> and status = #{status}</if>
    </where>
  </select>
  

  <select id="selectBBusiHollandQuestionsById" parameterType="Long" resultMap="BBusiHollandQuestionsBBusiHollandQuestionOptionsResult">
    select a.id, a.stepId, a.no, a.title, a.ruleCode, a.status,
    b.id as sub_id, b.questionId as sub_questionId, b.no as sub_no, b.label as sub_label, b.status as sub_status
    from b_busi_holland_questions a
    left join b_busi_holland_question_options b on b.questionId = a.id and b.status > 0
    where a.id = #{id}
  </select>
  
  <select id="selectBBusiHollandQuestionsByIdList" parameterType="java.util.Collection" resultMap="BBusiHollandQuestionsBBusiHollandQuestionOptionsResult">
    select a.id, a.stepId, a.no, a.title, a.ruleCode, a.status,
    b.id as sub_id, b.questionId as sub_questionId, b.no as sub_no, b.label as sub_label, b.status as sub_status
    from b_busi_holland_questions a
    left join b_busi_holland_question_options b on b.questionId = a.id and b.status > 0
    where a.id in
    <foreach item="questionId" collection="idList" open="(" separator="," close=")">
      #{questionId}
    </foreach>
  </select>
  
  
  
  <select id="selectQuestionsByStepId" parameterType="Long" resultMap="BBusiHollandQuestionsBBusiHollandQuestionOptionsResult">
    select a.id, a.stepId, a.no, a.title, a.ruleCode, a.status,
    b.id as sub_id, b.questionId as sub_questionId, b.no as sub_no, b.label as sub_label, b.status as sub_status
    from b_busi_holland_questions a
    left join b_busi_holland_question_options b on b.questionId = a.id and b.status > 0
    where a.stepId = #{stepId} and a.status > 0
    order by a.no ,b.no
  </select>

  <insert id="insertBBusiHollandQuestions" parameterType="BBusiHollandQuestions" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_holland_questions
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="stepId != null">stepId,</if>
      <if test="no != null">no,</if>
      <if test="title != null">title,</if>
      <if test="ruleCode != null">ruleCode,</if>
      <if test="status != null">status,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="stepId != null">#{stepId},</if>
      <if test="no != null">#{no},</if>
      <if test="title != null">#{title},</if>
      <if test="ruleCode != null">#{ruleCode},</if>
      <if test="status != null">#{status},</if>
    </trim>
  </insert>

  <update id="updateBBusiHollandQuestions" parameterType="BBusiHollandQuestions">
    update b_busi_holland_questions
    <trim prefix="SET" suffixOverrides=",">
      <if test="stepId != null">stepId = #{stepId},</if>
      <if test="no != null">no = #{no},</if>
      <if test="title != null">title = #{title},</if>
      <if test="ruleCode != null">ruleCode = #{ruleCode},</if>
      <if test="status != null">status = #{status},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBBusiHollandQuestionsById" parameterType="Long">
    delete from b_busi_holland_questions where id = #{id}
  </delete>

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

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

  <delete id="deleteBBusiHollandQuestionOptionsByQuestionId" parameterType="Long">
    delete from b_busi_holland_question_options where questionId = #{questionId}
  </delete>

  <insert id="batchBBusiHollandQuestionOptions">
    insert into b_busi_holland_question_options( id, questionId, no, label, status) values
    <foreach item="item" index="index" collection="list" separator=",">
      ( #{item.id}, #{item.questionId}, #{item.no}, #{item.label}, #{item.status})
    </foreach>
  </insert>
</mapper>