<?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.persagy.dmp.rwd.simple.dao.SystemCustomMapper">
    <resultMap id="BaseResultMap" type="com.persagy.dmp.digital.entity.ObjectDigital">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="localId" column="local_id" jdbcType="VARCHAR"/>
        <result property="localName" column="local_name" jdbcType="VARCHAR"/>
        <result property="groupCode" column="group_code" jdbcType="VARCHAR"/>
        <result property="projectId" column="project_id" jdbcType="VARCHAR"/>
        <result property="objType" column="obj_type" jdbcType="VARCHAR"/>
        <result property="classCode" column="class_code" jdbcType="VARCHAR"/>
        <result property="grouping" column="grouping" jdbcType="INTEGER"/>
        <result property="sequenceId" column="sequenceId" jdbcType="INTEGER"/>
        <result property="infos" column="infos" jdbcType="VARCHAR" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="virtualCodes" column="virtual_codes" jdbcType="VARCHAR" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="createApp" column="create_app" jdbcType="VARCHAR"/>
        <result property="updateApp" column="update_app" jdbcType="VARCHAR"/>
        <result property="creator" column="creator" jdbcType="VARCHAR"/>
        <result property="creationTime" column="creation_time" jdbcType="CHAR"/>
        <result property="modifier" column="modifier" jdbcType="VARCHAR"/>
        <result property="modifiedTime" column="modified_time" jdbcType="CHAR"/>
        <result property="valid" column="valid" jdbcType="TINYINT"/>
        <result property="ts" column="ts" jdbcType="TIMESTAMP"/>
        <result property="modelId" column="modelId" jdbcType="VARCHAR"/>
        <result property="objFromIds" column="objFromIds" jdbcType="VARCHAR" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="objToIds" column="objToIds" jdbcType="VARCHAR" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="relObjs" column="relObjs" jdbcType="VARCHAR"  typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="bimLocation" column="bimLocation" jdbcType="VARCHAR"  typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="outLines" column="outLines" jdbcType="VARCHAR"  typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
        <result property="objTypeClassCodes" column="objTypeClassCodes" jdbcType="VARCHAR"  typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
    </resultMap>
    <resultMap id="count" type="com.persagy.dmp.digital.entity.ObjectDigital">
        <result property="totalCount" column="totalCount" jdbcType="INTEGER"/>
    </resultMap>
    <!-- 确定建筑不确定楼层 buildingId is not null , floorId is null -->
    <select id="querySystemNotSureFloor" resultMap="BaseResultMap">
        select * from dt_object
        where 1=1
        <include refid="commonWhereSql"/>
        <if test="null!=param.classCode and param.classCode.length>0">
            AND class_code = #{param.classCode}
        </if>
        AND id in
        (select obj_from from dt_relation where rel_code='Sy2Bd' AND graph_code='MechInArch' AND obj_to=#{param.buildingId} AND obj_from not in
        (select obj_from from dt_relation where rel_code='Sy2Fl' AND graph_code='MechInArch' )  order by id asc
        )
    </select>

    <!-- 不确定建筑 buildingId is null-->
    <select id="querySystemNotSureBuilding" resultMap="BaseResultMap">
        SELECT * FROM `dt_object`
        where 1=1
            <include refid="commonWhereSql"/>
            <if test="null!=param.classCode and param.classCode.length>0">
                AND class_code = #{param.classCode}
            </if>
            AND id not in (select obj_from from dt_relation where rel_code='Sy2Bd' AND graph_code='MechInArch' order by id asc) ORDER BY id asc
    </select>

    <sql id="commonWhereSql">
        <if test="null!=param.objType and param.objType.length>0">
            AND obj_type=#{param.objType}
        </if>
        <if test="null!=param.projectId and param.projectId.length>0">
            AND project_id=#{param.projectId}
        </if>
        <if test="null!=param.groupCode and param.groupCode.length>0">
            AND group_code=#{param.groupCode}
        </if>
    </sql>

</mapper>