<?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.yeejoin.amos.maintenance.business.dao.mapper.CheckInputMapper">

    <select id="getByCheckIdAndItemId" resultType="com.yeejoin.amos.maintenance.business.dto.InputCheckDto">
        select
            a.input_id as itemId,
            a.check_id as checkId,
            b.point_id as pointId,
            b.route_id as route_id,
            c.point_classify_id as pointClassifyId
        from
            p_check_input as a
        left join
            p_check as b on a.check_id = b.id
        left join
            p_route_point_item as c on a.route_point_item_id = c.id
        where
            a.check_id = #{checkId}
        and
            a.input_id = #{itemId}
    </select>
    <select id="getByCheckIdAndItemIdAndRoutePointItemId"
            resultType="com.yeejoin.amos.maintenance.business.dto.InputCheckDto">
        SELECT
        a.input_id AS itemId,
        a.check_id AS checkId,
        a.remark,
        a.route_point_item_id AS routePointItemId,
        a.id AS checkInputId,
        a.input_value inputValue,
        b.point_id AS pointId,
        b.route_id AS route_id,
        a.point_classify_id AS pointClassifyId,
        e.risk_source_id as riskSourceId
        --         e.evaluate_id AS evaluateId
        FROM
        p_check_input AS a
        LEFT JOIN p_check AS b ON a.check_id = b.id
        LEFT JOIN p_point_classify AS d ON a.point_classify_id = d.id
        LEFT JOIN p_point as e on e.id = b.point_id
--         LEFT JOIN f_risk_factors AS e ON e.id = d.original_id
        <where>
            <if test="checkId != null">
                and a.check_id = #{checkId}
            </if>
            <if test="itemId != null">
                and a.input_id = #{itemId}
            </if>
            <if test="routePointItemId != null">
                and a.route_point_item_id = #{routePointItemId}
            </if>
            <if test="checkInputId != null">
                and a.id = #{checkInputId}
            </if>
        </where>
        limit 1
    </select>
</mapper>