<?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.zcloud.mapper.datasource.risk.RiskpointLogMapper">

    <!--表名 -->
    <sql id="tableName">
        BUS_RISKPOINT_LOG
    </sql>

    <!--数据字典表名 -->
    <sql id="dicTableName">
        SYS_DICTIONARIES
    </sql>

    <!-- 字段 -->
    <sql id="Field">
        f.RISKPOINT_ID,
		f.RISK_UNIT_ID,
		f.IDENTIFICATION_ID,
		f.RISK_DESCR,
		f.RISK_POSITION_ID,
		f.LEVELID,
		f.MEASURES,
		f.ACCIDENTS,
		f.EME_MEASURES,
		f.DEPARTMENT_ID,
		f.USER_ID,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.CORPINFO_ID,
		f.LONGITUDE,
		f.LATITUDE,
		f.ACCIDENTS_NAME,
		f.SORT,
		f.RES_ISDELETE,
		f.RES_ID,
		f.LIKELIHOOD,
		f.EXPOSURE,
		f.CONSEQUENCE,
		f.DANGER,
		f.TYPE,
		f.IS_NEW,
		f.RISKPOINT_LOG_ID,
		f.RISK_CAUSES,
		f.RISK_CAUSES_NAME,
		f.LEVEL_NAME,
		f.RISKPOINT_ANALYSIS_ID
    </sql>

    <!-- 字段用于新增 -->
    <sql id="Field2">
        RISKPOINT_ID,
		RISK_UNIT_ID,
		IDENTIFICATION_ID,
		RISK_DESCR,
		RISK_POSITION_ID,
		LEVELID,
		MEASURES,
		ACCIDENTS,
		EME_MEASURES,
		DEPARTMENT_ID,
		USER_ID,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		CORPINFO_ID,
		LONGITUDE,
		LATITUDE,
		ACCIDENTS_NAME,
		SORT,
		RES_ISDELETE,
		RES_ID,
		LIKELIHOOD,
		EXPOSURE,
		CONSEQUENCE,
		DANGER,
		TYPE,
		IS_NEW,
		RISKPOINT_LOG_ID,
		RISK_CAUSES,
		RISK_CAUSES_NAME,
		LEVEL_NAME,
        RISKPOINT_ANALYSIS_ID
    </sql>

    <!-- 字段值 -->
    <sql id="FieldValue">
        #{RISKPOINT_ID}
        ,
        #{RISK_UNIT_ID},
        #{IDENTIFICATION_ID},
        #{RISK_DESCR},
        #{RISK_POSITION_ID},
        #{LEVELID},
        #{MEASURES},
        #{ACCIDENTS},
        #{EME_MEASURES},
        #{DEPARTMENT_ID},
        #{USER_ID},
        #{ISDELETE},
        #{CREATOR},
        #{CREATTIME},
        #{OPERATOR},
        #{OPERATTIME},
        #{CORPINFO_ID},
        #{LONGITUDE},
        #{LATITUDE},
        #{ACCIDENTS_NAME},
        #{SORT},
        #{RES_ISDELETE},
        #{RES_ID},
        #{LIKELIHOOD},
        #{EXPOSURE},
        #{CONSEQUENCE},
        #{DANGER},
        #{TYPE},
        #{IS_NEW},
        #{RISKPOINT_LOG_ID},
        #{RISK_CAUSES},
        #{RISK_CAUSES_NAME},
        #{LEVEL_NAME},
        #{RISKPOINT_ANALYSIS_ID}
    </sql>

    <!-- 新增-->
    <insert id="save" parameterType="pd">
        insert into
        <include refid="tableName"></include>
        (
        <include refid="Field2"></include>
        ) values (
        <include refid="FieldValue"></include>
        )
    </insert>

    <!-- 删除-->
    <delete id="delete" parameterType="pd">
        update
        <include refid="tableName"></include>
        set
        ISDELETE = '1'
        where
        RISKPOINT_LOG_ID = #{RISKPOINT_LOG_ID}
    </delete>

    <!-- 批量删除 -->
    <delete id="deleteAll" parameterType="String">
        update
        <include refid="tableName"></include>
        set
        ISDELETE = '1'
        where
        RISKPOINT_LOG_ID in
        <foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <!-- 修改 -->
    <update id="edit" parameterType="pd">
        update
        <include refid="tableName"></include>
        set
        RISKPOINT_ID = #{RISKPOINT_ID},
        RISK_UNIT_ID = #{RISK_UNIT_ID},
        IDENTIFICATION_ID = #{IDENTIFICATION_ID},
        RISK_DESCR = #{RISK_DESCR},
        RISK_POSITION_ID = #{RISK_POSITION_ID},
        LEVELID = #{LEVELID},
        MEASURES = #{MEASURES},
        ACCIDENTS = #{ACCIDENTS},
        EME_MEASURES = #{EME_MEASURES},
        DEPARTMENT_ID = #{DEPARTMENT_ID},
        USER_ID = #{USER_ID},
        ISDELETE = #{ISDELETE},
        CREATOR = #{CREATOR},
        CREATTIME = #{CREATTIME},
        OPERATOR = #{OPERATOR},
        OPERATTIME = #{OPERATTIME},
        CORPINFO_ID = #{CORPINFO_ID},
        LONGITUDE = #{LONGITUDE},
        LATITUDE = #{LATITUDE},
        ACCIDENTS_NAME = #{ACCIDENTS_NAME},
        SORT = #{SORT},
        RES_ISDELETE = #{RES_ISDELETE},
        RES_ID = #{RES_ID},
        LIKELIHOOD = #{LIKELIHOOD},
        EXPOSURE = #{EXPOSURE},
        CONSEQUENCE = #{CONSEQUENCE},
        DANGER = #{DANGER},
        TYPE = #{TYPE},
        IS_NEW = #{IS_NEW},
        RISK_CAUSES = #{RISK_CAUSES},
        RISK_CAUSES_NAME = #{RISK_CAUSES_NAME},
        LEVEL_NAME = #{LEVEL_NAME},
        RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID},
        RISKPOINT_LOG_ID = RISKPOINT_LOG_ID
        where
        RISKPOINT_LOG_ID = #{RISKPOINT_LOG_ID}
    </update>
    <update id="updateByRiskpointId">
        update
        <include refid="tableName"></include>
        set
        IS_NEW = #{IS_NEW}
        where
        RISKPOINT_ID = #{RISKPOINT_ID}
    </update>

    <!-- 通过ID获取数据 -->
    <select id="findById" parameterType="pd" resultType="pd">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include>
        f
        where
        f.RISKPOINT_LOG_ID = #{RISKPOINT_LOG_ID}
    </select>

    <!-- 列表 -->
    <select id="datalistPage" parameterType="page" resultType="pd">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include>
        f
        where f.ISDELETE = '0'
    </select>

    <!-- 列表(全部) -->
    <select id="listAll" parameterType="pd" resultType="pd">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include>
        f
    </select>
    <select id="findByCondition" parameterType="pd" resultType="pd">
        select
        <include refid="Field"></include>,
        od.NAME as DEPT_NAME_ALL,
        su.NAME as DEPT_USER_NAME,
        sd.NAME as RISK_CAUSES_CNAME
        from
        <include refid="tableName"></include> f
        left join oa_department od on od.DEPARTMENT_ID = f.DEPARTMENT_ID
        left join sys_user su on su.USER_ID = f.USER_ID
        left join sys_dictionaries sd on sd.DICTIONARIES_ID = f.RISK_CAUSES
        where f.ISDELETE = '0'
        <if test="RISKPOINT_ID != null and RISKPOINT_ID != ''">
            and f.RISKPOINT_ID = #{RISKPOINT_ID}
        </if>
        <if test="RISKPOINT_ANALYSIS_ID != null and RISKPOINT_ANALYSIS_ID != ''">
            and f.RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID}
        </if>
        <if test="IS_NEW != null and IS_NEW != ''">
            and f.IS_NEW = #{IS_NEW}
        </if>
        <if test="RISKPOINT_ANALYSIS_ID != null and RISKPOINT_ANALYSIS_ID != ''">
            and f.RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID}
        </if>
    </select>

</mapper>
