<?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.huatek.busi.mapper.SimulateResultMapper">
    <sql id="Base_Column_List">
        A.id AS mainId,
        A.equipment_type AS equipmentType,
        A.p_id AS pId,
        A.data_item_id AS dataItemId,
        A.simulate_result_json AS simulateResultJson,
        A.file_path AS filePath,
        A.file_name AS fileName,
        A.create_user AS mainCreateUser,
        A.create_time AS mainCreateTime,
        B.id AS childId,
        B.data_item_json AS dataItemJson,
        B.create_user AS childCreateUser,
        B.create_time AS childCreateTime
    </sql>

    <select id="list" parameterType="com.huatek.busi.where.SimulateResultSelectVo" resultType="com.huatek.busi.dto.SimulateResultDto">
        SELECT
            <include refid="Base_Column_List"/>
        FROM
            x_simulate_result A
            LEFT JOIN x_simulate_input_data_item B ON A.data_item_id = B.id
        WHERE
        <if test="equipmentType != null and equipmentType != ''">
            A.equipment_type = #{equipmentType}
        </if>
        <if test="startDate != null">
            and DATE_FORMAT(A.create_time,'%Y-%m-%d') &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            and DATE_FORMAT(A.create_time,'%Y-%m-%d') &lt; #{endDate}
        </if>
        <if test="pId != null and pId != ''">
            AND A.p_id = #{pId}
        </if>
        <if test="dataItemId != null and dataItemId != ''">
            AND A.data_item_id = #{dataItemId}
        </if>
        ORDER BY
            A.create_time DESC
    </select>

    <select id="findOilList" parameterType="com.huatek.busi.where.SimulateResultSelectVo" resultType="com.huatek.busi.dto.SimulateResultDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_simulate_result A
        LEFT JOIN x_simulate_input_data_item B ON A.data_item_id = B.id
        WHERE
        <if test="equipmentType != null and equipmentType != ''">
            A.equipment_type = #{equipmentType}
        </if>
        <if test="startDate != null">
            and DATE_FORMAT(A.create_time,'%Y-%m-%d') &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            and DATE_FORMAT(A.create_time,'%Y-%m-%d') &lt; #{endDate}
        </if>
        <if test="pId != null and pId != ''">
            AND A.p_id = #{pId}
        </if>
        <if test="dataItemId != null and dataItemId != ''">
            AND A.data_item_id = #{dataItemId}
        </if>
        ORDER BY
        A.create_time DESC
    </select>

    <select id="drivepipeList" parameterType="com.huatek.busi.where.SimulateResultSelectVo" resultType="com.huatek.busi.entity.BusiDrivepipeEvaluationResults">
        SELECT
            main_tree_id AS mainTreeId,
            insulate,
            insulate_a AS insulateA,
            insulate_b AS insulateB,
            h2,
            h2_a AS h2A,
            h2_b AS h2B,
            c2h2,
            c2h2_a AS c2h2A,
            c2h2_b AS c2h2B,
            ch4,
            ch4_a AS ch4A,
            ch4_b AS ch4B,
            health_score_insulate AS healthScoreInsulate,
            health_score_h2 AS healthScoreH2,
            health_score_ch4 AS healthScoreCH4,
            health_score_c2h2 AS healthScoreC2H2,
            hours,
            b_value AS bValue,
            result,
            evaluate_date AS evaluateDate
        FROM
            busi_drivepipe_evaluation_results
        WHERE
        <if test="mainTreeId != null and mainTreeId != ''">
            main_tree_id = #{mainTreeId}
        </if>
        <if test="startDate != null">
            and DATE_FORMAT(evaluate_date,'%Y-%m-%d') &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            and DATE_FORMAT(evaluate_date,'%Y-%m-%d') &lt; #{endDate}
        </if>
        ORDER BY
            evaluate_date DESC
    </select>

    <select id="listSimulate"   resultType="com.huatek.busi.dto.SimulateResultDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_simulate_result A
        LEFT JOIN x_simulate_input_data_item B ON A.data_item_id = B.id
        WHERE
        <if test="equipmentType != null and equipmentType != ''">
            A.equipment_type = #{equipmentType}
        </if>
        <if test="pId != null and pId != ''">
            AND A.p_id = #{pId}
        </if>
        ORDER BY
        A.create_time DESC
    </select>


    <select id="simulate"   resultType="java.util.Map">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_simulate_result A
        LEFT JOIN x_simulate_input_data_item B ON A.data_item_id = B.id
        WHERE
        A.id =#{mainId}
    </select>

    <select id="findFilePath"   resultType="string">
        SELECT
        file_path
        FROM
        x_simulate_result
        WHERE
        id = #{id}
        AND p_id = #{pid}
    </select>

    <select id="findAssessList"   resultType="com.huatek.busi.vo.AssessInputDataVo">
        SELECT
            id,
            name,
            basic_value AS basicValue,
            type,
            status,
            name_id AS nameId,
            factory_value AS factoryValue,
            real_value AS realValue,
            judgment,
            num,
            value,
            weight,
            create_time AS createTime,
            create_user AS createUser
        FROM
            x_assess_input_data
        WHERE
            num = ( SELECT MAX( num ) FROM x_assess_input_data )
        AND `status` = '1'
        GROUP BY
            name_id
        ORDER BY
            type,
            name_id ASC
    </select>

    <select id="findAssessAllList"   resultType="com.huatek.busi.entity.AssessInputData">
        SELECT
            id,
            name,
            basic_value AS basicValue,
            type,
            status,
            name_id AS nameId,
            factory_value AS factoryValue,
            real_value AS realValue,
            judgment,
            num,
            value,
            weight,
            create_time AS createTime,
            create_user AS createUser
        FROM
            x_assess_input_data
        WHERE
            num = ( SELECT MAX( num ) FROM x_assess_input_data )
        ORDER BY
            type,
            name_id ASC
    </select>

    <select id="findListByJudgment"   resultType="com.huatek.busi.entity.AssessInputData">
        SELECT
            id,
            name,
            basic_value AS basicValue,
            type,
            status,
            name_id AS nameId,
            factory_value AS factoryValue,
            real_value AS realValue,
            judgment,
            num,
            value,
            weight,
            create_time AS createTime,
            create_user AS createUser
        FROM
            x_assess_input_data
        WHERE
        <if test="nameId != null and nameId != ''">
            name_id = #{nameId}
        </if>
        <if test="num != null and num != ''">
            AND num = #{num}
        </if>
    </select>

    <select id="findMaxCount"   resultType="string">
        SELECT
            MAX( name_id ) AS count
        FROM
            x_assess_input_data
        WHERE
            num = (
            SELECT
                MAX( num )
            FROM
            x_assess_input_data
            )
    </select>

    <select id="findMaxNum"   resultType="string">
        SELECT
            MAX( num )
        FROM
            x_assess_input_data
    </select>
</mapper>
