<?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.project.business.mapper.TpParaRelatedLogicMapper">

    <resultMap type="TpParaRelatedLogic" id="TpParaRelatedLogicResult">
        <result property="id" column="id"/>
        <result property="caseId" column="case_id"/>
        <result property="paraCode" column="para_code"/>
        <result property="operation" column="operation"/>
        <result property="value" column="value"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectTpParaRelatedLogicVo">
        select id,
               case_id,
               para_code,
               operation,
               value,
               del_flag,
               create_time,
               create_by,
               update_time,
               update_by,
               remark
        from tp_para_related_logic
    </sql>

    <resultMap type="com.ruoyi.project.business.dto.TpParaRelatedLogicDto" extends="TpParaRelatedLogicResult"
               id="TpParaRelatedLogicResultDto">
        <result property="inputType" column="input_type"/>
        <result property="paraId" column="para_id"/>
        <result property="paraName" column="para_name"/>
        <result property="paraNameUS" column="para_nameUS"/>
        <result property="paraNameRU" column="para_nameRU"/>
        <result property="paraNameES" column="para_nameES"/>
        <result property="label" column="label"/>
        <result property="labelUS" column="labelUS"/>
        <result property="labelRU" column="labelRU"/>
        <result property="labelES" column="labelES"/>
        <collection property="options" select="queryValueOption" column="para_id"/>
    </resultMap>


    <select id="queryMoreInfo" parameterType="long" resultMap="TpParaRelatedLogicResultDto">
        SELECT case_id,
        tpl.id as para_id,
        tprl.id,
        tprl.para_code,
        operation,
        tprl.`VALUE`,
        tpl.input_type,
        tpl.para_name,
        tpl.para_nameES,
        tpl.para_nameRU,
        tpl.para_nameUS,
        tpsi.label,
        tpsi.labelES,
        tpsi.labelRU,
        tpsi.labelUS
        FROM tp_para_related_logic tprl
        INNER JOIN tp_para_library tpl on tpl.para_code = tprl.para_code
        left JOIN tp_para_select_item tpsi on tpsi.para_id = tpl.id and tpsi.`value` = tprl.`value`
        where tprl.del_flag='0' and case_id in
        <foreach collection="caseId" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>


    <resultMap type="com.ruoyi.project.business.domain.TpParaSelectItem" id="TpParaSelectItemBaseResult">
        <result property="id" column="id"/>
        <result property="paraId" column="para_id"/>
        <result property="value" column="value"/>
        <result property="label" column="label"/>
        <result property="labelUS" column="labelUS"/>
        <result property="labelRU" column="labelRU"/>
        <result property="labelES" column="labelES"/>
        <result property="sortNumber" column="sort_number"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <select id="queryValueOption" parameterType="long" resultMap="TpParaSelectItemBaseResult">
        SELECT *
        from tp_para_select_item tpsi
        WHERE para_id = #{paraId}
    </select>

</mapper>