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

    <resultMap type="TpParaValidation" id="TpParaValidationResult">
        <result property="id" column="id"/>
        <result property="caseName" column="case_name"/>
        <result property="conditionFormula" column="condition_formula"/>
        <result property="conditionFormulaAnalysis" column="condition_formula_analysis"/>
        <result property="resultFalseUS" column="result_falseUS"/>
        <result property="resultFalseRU" column="result_falseRU"/>
        <result property="resultFalseES" column="result_falseES"/>
        <result property="resultFalse" column="result_false"/>
        <result property="status" column="status"/>
        <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"/>
        <result property="quotationFlag" column="quotation_flag"/>
        <result property="civilFlag" column="civil_flag"/>
    </resultMap>

    <sql id="selectTpParaValidationVo">
        select id,
               case_name,
               condition_formula,
               result_falseUS,
               result_falseRU,
               result_falseES,
               result_false,
               status,
               del_flag,
               create_time,
               create_by,
               update_time,
               update_by,
               remark
        from tp_para_validation
    </sql>

    <select id="selectTpParaValidationList" parameterType="TpParaValidation" resultMap="TpParaValidationResult">
        <include refid="selectTpParaValidationVo"/>
        <where>
            <if test="caseName != null  and caseName != ''">and case_name like concat('%', #{caseName}, '%')</if>
            <if test="conditionFormula != null  and conditionFormula != ''">and condition_formula =
                #{conditionFormula}
            </if>
            <if test="resultFalseus != null  and resultFalseus != ''">and result_falseUS = #{resultFalseus}</if>
            <if test="resultFalseru != null  and resultFalseru != ''">and result_falseRU = #{resultFalseru}</if>
            <if test="resultFalsees != null  and resultFalsees != ''">and result_falseES = #{resultFalsees}</if>
            <if test="resultFalse != null  and resultFalse != ''">and result_false = #{resultFalse}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
        </where>
    </select>

    <select id="selectTpParaValidationById" parameterType="Long" resultMap="TpParaValidationResult">
        <include refid="selectTpParaValidationVo"/>
        where id = #{id}
    </select>

    <insert id="insertTpParaValidation" parameterType="TpParaValidation" useGeneratedKeys="true" keyProperty="id">
        insert into tp_para_validation
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="caseName != null">case_name,</if>
            <if test="conditionFormula != null">condition_formula,</if>
            <if test="resultFalseus != null">result_falseUS,</if>
            <if test="resultFalseru != null">result_falseRU,</if>
            <if test="resultFalsees != null">result_falseES,</if>
            <if test="resultFalse != null">result_false,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">

            <if test="caseName != null">#{caseName},</if>
            <if test="conditionFormula != null">#{conditionFormula},</if>
            <if test="resultFalseus != null">#{resultFalseus},</if>
            <if test="resultFalseru != null">#{resultFalseru},</if>
            <if test="resultFalsees != null">#{resultFalsees},</if>
            <if test="resultFalse != null">#{resultFalse},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTpParaValidation" parameterType="TpParaValidation">
        update tp_para_validation
        <trim prefix="SET" suffixOverrides=",">
            <if test="caseName != null">case_name = #{caseName},</if>
            <if test="conditionFormula != null">condition_formula = #{conditionFormula},</if>
            <if test="resultFalseus != null">result_falseUS = #{resultFalseus},</if>
            <if test="resultFalseru != null">result_falseRU = #{resultFalseru},</if>
            <if test="resultFalsees != null">result_falseES = #{resultFalsees},</if>
            <if test="resultFalse != null">result_false = #{resultFalse},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTpParaValidationById" parameterType="Long">
        delete
        from tp_para_validation
        where id = #{id}
    </delete>

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

    <resultMap type="com.ruoyi.project.business.dto.TpParaValidationDto" id="TpParaValidationDtoResult"
               extends="TpParaValidationResult">

    </resultMap>

    <select id="getTableList" parameterType="com.ruoyi.project.business.dto.TpParaValidationDto"
            resultMap="TpParaValidationDtoResult">
        select tpv.*
        from tp_para_validation tpv
        left join sys_user su on tpv.update_by = su.user_id
        where tpv.del_flag = '0'
        <if test="caseName!=null and caseName !=''">
            and tpv.case_name like concat ('%', #{caseName}, '%')
        </if>
          <if test="ids != null and ids.size() > 0">
              and tpv.id in
              <foreach collection="ids" item="id" open="(" separator="," close=")">
                  #{id}
              </foreach>
          </if>
        <if test="status !=null and status !=''">
            and tpv.status =#{status}
        </if>
        <if test="quotationFlag !=null and quotationFlag !=''">
            and tpv.quotation_flag = #{quotationFlag}
        </if>
        <if test="civilFlag !=null and civilFlag !=''">
            and tpv.civil_flag = #{civilFlag}
        </if>
        <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
            and date_format(tpv.update_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
        </if>
        <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
            and date_format(tpv.update_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
        </if>
        <if test="updateByName !=null and updateByName !=''">
            and su.nick_name like concat ('%', #{updateByName}, '%')
        </if>
        order by tpv.id desc

    </select>
    <select id="listByElevatorModelId" resultMap="TpParaValidationResult">
        SELECT *
        FROM tp_para_validation
        WHERE del_flag = '0'
        and status = '0'
        and id in (SELECT para_validation_id FROM tp_para_validation_elevator tpve WHERE elevator_model_id = #{id})
        <if test="quotationFlag != null and quotationFlag">
            and quotation_flag = '1'
        </if>
        <if test="quotationFlag != null and !quotationFlag">
            and civil_flag = '1'
        </if>
    </select>
</mapper>