<?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.patrol.business.dao.mapper.RiskFactorCmMapper">

    <select id="getById" resultType="com.yeejoin.amos.patrol.business.entity.mybatis.RiskFactorCmBo">
        select
            *
        from
            spc_risk_factors_cm
        where
            id = #{id}
        limit 1
    </select>

    <select id="listControlMeasuresIdsByMap" resultType="java.lang.Long">
        select
            distinct control_measures_id as controlMeasuresId
        from
            spc_risk_factors_cm
        where
            risk_factors_id = #{riskFactorId}
        and
            evaluate_id = #{evaluateId}
    </select>

    <select id="listByEvaluateIdAndAndRiskFactorsId" resultType="com.yeejoin.amos.patrol.business.entity.mybatis.RiskFactorCmBo">
        select
            a.id,
            a.control_measures_id as controlMeasuresId,
            a.measures_content_id as measuresContentId,
            a.risk_factors_id as riskFactorsId,
            a.evaluate_id as evaluateId,
            a.env_ensure_status as envEnsureStatus,
            a.site_ensure_status as siteEnsureStatus,
            a.change_idea as changeIdea,
            b.content as measuresContent
        from
            spc_risk_factors_cm as a
        left join
            spc_measures_content as b on a.measures_content_id = b.id
        where
            a.risk_factors_id = #{riskFactorsId}
        and
            a.evaluate_id = #{evaluateId}
    </select>

    <update id="updateStatusByMap">
        update
            spc_risk_factors_cm
        set
            status = #{status}
        where
            risk_factors_id = #{riskFactorId}
        and
            evaluate_id = #{evaluateId}
        and
            measures_content_id = #{measuresContentId}
    </update>

    <select id="countOutControl" resultType="java.lang.Long">
        select
            count(1)
        from
            spc_risk_factors_cm
        where
            risk_factors_id = #{riskFactorId}
        and
            evaluate_id = #{evaluateId}
        and
            status != '1'
    </select>
</mapper>