<?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.ehsRisk.mapper.EhsRiskMapper">

    <resultMap type="EhsRisk" id="EhsRiskResult">
        <result property="riskId"    column="risk_id" />
        <result property="riskGrade"    column="risk_grade" />
        <result property="reportAddressType"    column="report_address_type" />
        <result property="riskLocation"    column="risk_location" />
        <result property="tel"    column="tel" />
        <result property="peopleQuantity"    column="people_quantity" />
        <result property="materialsQuantity"    column="materials_quantity" />
        <result property="repairTeam"    column="repair_team" />
        <result property="personResponsible"    column="person_responsible" />
        <result property="villagePersonResponsible"    column="village_person_responsible" />
        <result property="villagePersonResponsible2"    column="village_person_responsible2" />
        <result property="tel2"    column="tel2" />
        <result property="createBy"    column="create_by" />
        <result property="createTime"    column="create_time" />
        <result property="updateBy"    column="update_by" />
        <result property="updateTime"    column="update_time" />
        <result property="remark"    column="remark" />
        <result property="updateBy"    column="update_by" />
        <result property="updateTime"    column="update_time" />
        <result property="remark"    column="remark" />
        <result property="deptId"    column="dept_id" />
        <result property="deptName"    column="dept_name" />
        <result property="createUserId"    column="create_user_id" />
        <result property="updateUserId"    column="update_user_id" />
    </resultMap>

    <sql id="selectEhsRiskVo">
        select r.*, d.dept_name
        from ehs_risk r left join sys_dept d on r.dept_id = d.dept_id

    </sql>

    <select id="selectEhsRiskList" parameterType="EhsRisk" resultMap="EhsRiskResult">
        <include refid="selectEhsRiskVo"/>
        <where>
            <if test="deptId != null "> and r.dept_Id = #{deptId}</if>
            <if test="riskGrade != null "> and risk_grade = #{riskGrade}</if>
            <if test="reportAddressType != null  and reportAddressType != ''"> and report_address_type = #{reportAddressType}</if>
            <if test="riskLocation != null  and riskLocation != ''"> and risk_location like concat('%', #{riskLocation}, '%')</if>
            <if test="tel != null  and tel != ''"> and tel like concat('%', #{tel}, '%')</if>
            <if test="params.beginPeopleQuantity != null and params.beginPeopleQuantity != '' and params.endPeopleQuantity != null and params.endPeopleQuantity != ''"> and people_quantity between #{params.beginPeopleQuantity} and #{params.endPeopleQuantity}</if>
            <if test="params.beginMaterialsQuantity != null and params.beginMaterialsQuantity != '' and params.endMaterialsQuantity != null and params.endMaterialsQuantity != ''"> and materials_quantity between #{params.beginMaterialsQuantity} and #{params.endMaterialsQuantity}</if>
            <if test="params.beginRepairTeam != null and params.beginRepairTeam != '' and params.endRepairTeam != null and params.endRepairTeam != ''"> and repair_team between #{params.beginRepairTeam} and #{params.endRepairTeam}</if>
            <if test="personResponsible != null  and personResponsible != ''"> and person_responsible like concat('%', #{personResponsible}, '%')</if>
            <if test="villagePersonResponsible != null  and villagePersonResponsible != ''"> and village_person_responsible like concat('%', #{villagePersonResponsible}, '%')</if>
            <if test="villagePersonResponsible2 != null  and villagePersonResponsible2 != ''"> and village_person_responsible2 like concat('%', #{villagePersonResponsible2}, '%')</if>
            <if test="tel2 != null  and tel2 != ''"> and tel2 like concat('%', #{tel2}, '%')</if>
        </where>
    </select>

    <select id="selectEhsRiskByRiskId" parameterType="Long" resultMap="EhsRiskResult">
        <include refid="selectEhsRiskVo"/>
        where risk_id = #{riskId}
    </select>
</mapper>
