<?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.ddd.safetyControl.infrastructure.repository.riskPointSource.dao.TSafeRiskPointSourceDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.ddd.safetyControl.infrastructure.repository.riskPointSource.entity.TSafeRiskPointSourceDO">
        <id column="id" property="id"/>
        <id column="org_id" property="orgId"/>
        <id column="point_id" property="pointId"/>
        <id column="source_id" property="sourceId"/>
    </resultMap>

    <select id="listAll" resultType="com.testor.ddd.safetyControl.interfaces.model.vo.riskPoint.RiskPointSourceVO"
            parameterType="com.testor.ddd.safetyControl.interfaces.model.dto.riskPointSource.TSafeRiskPointSourceDTOParam">
        select ps.id pointSourceId, rs.id sourceId, rs.name sourceName
        from t_safe_risk_point_source ps ,t_safe_risk_source rs, t_safe_risk_point rp
        <where>
            rs.id = ps.source_id and ps.point_id = rp.id
            and ps.status = '0' and rs.status='0' and rp.status='0'
            <if test="query.pointId!='' and query.pointId!=null">
                and ps.point_id = #{query.pointId}
            </if>
            <if test="query.relationType!='' and query.relationType!=null">
                and rs.relation_type = #{query.relationType}
            </if>
            <if test="query.workshopId!='' and query.workshopId!=null">
                and rs.relation_space_id = #{query.workshopId}
            </if>
            <if test="query.workareaId!='' and query.workareaId!=null">
                and rs.relation_space_parent_id = #{query.workareaId}
            </if>
            <if test="query.equipmentId!='' and query.equipmentId!=null">
                and rs.relation_equipment_id = #{query.equipmentId}
            </if>

            <if test="query.notPointId!='' and query.notPointId!=null">
                and ps.point_id != #{query.notPointId}
            </if>
            <if test="query.condSourceIdList!=null and query.condSourceIdList.size>0">
                and ps.source_id in
                <foreach collection="query.condSourceIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
</mapper>