<?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.testor.module.environment.dao.TBasicEnvironmentManageDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.environment.model.domain.TBasicEnvironmentManage">
        <id column="org_id" property="orgId"/>
        <id column="location" property="location"/>
        <id column="troubleshoot" property="troubleshoot"/>
        <id column="sensitive_areas" property="sensitiveAreas"/>
        <id column="check_case" property="checkCase"/>
        <id column="licence" property="licence"/>
        <id column="pollution" property="pollution"/>
        <id column="risk_point" property="riskPoint"/>
        <id column="intake" property="intake"/>
        <id column="drain" property="drain"/>
        <id column="dust" property="dust"/>
        <id column="SO2" property="so2"/>
        <id column="NOX" property="nox"/>
        <id column="VOCs" property="vocs"/>
        <id column="flue_count" property="flueCount"/>
        <id column="flue_deal" property="flueDeal"/>
        <id column="CODcr" property="codcr"/>
        <id column="NH3_N" property="nh3N"/>
        <id column="waste_count" property="wasteCount"/>
        <id column="waste_deal" property="wasteDeal"/>
        <id column="boiler_stage" property="boilerStage"/>
        <id column="boiler_ton" property="boilerTon"/>
        <id column="then_status" property="thenStatus"/>
        <id column="biology_stage" property="biologyStage"/>
        <id column="biology_ton" property="biologyTon"/>
        <id column="fuel_stage" property="fuelStage"/>
        <id column="fuel_ton" property="fuelTon"/>
        <id column="major_id" property="majorId"/>
        <id column="major_name" property="majorName"/>
        <id column="major_phone" property="majorPhone"/>
        <id column="branched_leader_id" property="branchedLeaderId"/>
        <id column="branched_leader_name" property="branchedLeaderName"/>
        <id column="branched_leader_phone" property="branchedLeaderPhone"/>
        <id column="dept_person_id" property="deptPersonId"/>
        <id column="dept_person_name" property="deptPersonName"/>
        <id column="dept_person_phone" property="deptPersonPhone"/>
        <id column="environ_person_id" property="environPersonId"/>
        <id column="environ_person_name" property="environPersonName"/>
        <id column="environ_person_phone" property="environPersonPhone"/>
        <id column="org_name" property="orgName"/>
    </resultMap>

    <select id="getList" parameterType="com.testor.module.environment.model.dto.TBasicEnvironmentManageParam"
            resultType="com.testor.module.environment.model.domain.TBasicEnvironmentManage">
        select mm.org_id,mm.org_name,basi.*
        from t_sys_org mm
        left join t_basic_environment_manage basi
        on mm.org_id = basi.org_id
        where mm.is_dept = '0'
        and mm.org_id in (select org.org_id
        from t_sys_org org
        where org.parent_ids like concat('%', #{orgId}, '%')
        or org.org_id = #{orgId})
        <if test="companyIds!=null and companyIds.size>0">
            AND mm.org_id in
            <foreach open="(" close=")" separator="," collection="companyIds" item="item" index="index">
                #{item}
            </foreach>
        </if>
        <if test="param.location!=null and param.location!=''">
            AND basi.location = #{param.location}
        </if>
        <if test="param.sensitiveAreas!=null and param.sensitiveAreas!=''">
            AND basi.sensitive_areas = #{param.sensitiveAreas}
        </if>
        <if test="param.checkCase!=null and param.checkCase!=''">
            AND basi.check_case = #{param.checkCase}
        </if>
        <if test="param.licence!=null and param.licence!=''">
            AND basi.licence = #{param.licence}
        </if>
        order by mm.update_date desc
    </select>
</mapper>