<?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="org.springblade.modules.ldInfo.mapper.LdInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="LdInfoResultMap" type="org.springblade.modules.ldInfo.entity.LdInfoEntity">
    </resultMap>


    <select id="selectLdInfoPage" resultMap="LdInfoResultMap">
        select * from ld_info where is_deleted = 0
    </select>


    <select id="exportLdInfo" resultType="org.springblade.modules.ldInfo.excel.LdInfoExcel">
        SELECT * FROM ld_info ${ew.customSqlSegment}
    </select>

    <select id="selectLdWithNoXxy" resultType="org.springblade.modules.ldInfo.vo.LdInfoVO">
        SELECT
            li.id,
            li.b_name AS bName,
            li.unit,
            li.sqmc,
            li.sq_id,
            li.ss_org_name,
            li.ss_org_id,
            li.ld_jd,
            li.ld_wd
        FROM
            ld_info li
        LEFT JOIN xxy_info xi ON xi.ld_id = li.id
        LEFT JOIN blade_dept bd ON bd.id = li.sq_id
        WHERE
                li.is_deleted = 0
            AND xi.id IS NULL
            AND ((#{params.deptId} LIKE '%' || bd.id || '%') OR (bd.ancestors LIKE '%' || #{params.deptId} || '%'))
        <if test="null != params.bName and '' != params.bName">
            AND li.b_name LIKE '%' || #{params.bName} || '%'
        </if>
        <if test="null != params.unit and '' != params.unit">
            AND li.unit LIKE '%' || #{params.unit} || '%'
        </if>
        <if test="null != params.sqmc and '' != params.sqmc">
            AND li.sqmc LIKE '%' || #{params.sqmc} || '%'
        </if>
    </select>

</mapper>
