<?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.production.dao.TProductionAccidentDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.production.model.domain.TProductionAccident">
        <id column="org_id" property="orgId"/>
        <id column="org_name" property="orgName"/>
        <id column="data" property="data"/>
    </resultMap>

    <select id="getList" parameterType="com.testor.module.production.model.dto.TProductionAccidentParam"
            resultType="com.testor.module.production.model.domain.TProductionAccident">
        select mm.org_id,mm.org_name,basi.*
        from t_sys_org mm
        left join t_production_accident 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>
        order by mm.tree_level
    </select>
</mapper>