<?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.mapper.SydwMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="blogResultMap" type="org.springblade.modules.entity.SydwEntity">
        <result column="id" property="id"/>
    </resultMap>

    <select id="selectSydwPage" resultType="org.springblade.modules.entity.SydwEntity">
        select
            ys.id,
            ys.dzbm,
            ys.dwmc,
            ys.tyshxydm,
            ys.dwlx,
            ( select count(0) from jdrh.ybss_cyry yc where yc.is_deleted = 0 and yc.tyshxydm = ys.tyshxydm) as cyry,
            rd.xz
        from jdrh.ybss_sydw ys
        left join sspt.rk_dzxx rd on rd.dzbm = ys.dzbm
        where ys.is_deleted = 0
        <if test="sydwEntity.dwmc != null and sydwEntity.dwmc != ''">
            and ys.dwmc like '%' || #{sydwEntity.dwmc} || '%'
        </if>
        <if test="sydwEntity.tyshxydm != null and sydwEntity.tyshxydm != ''">
            and ys.tyshxydm = #{sydwEntity.tyshxydm}
        </if>
        <if test="sydwEntity.dwlx != null and sydwEntity.dwlx != ''">
            and ys.dwlx = #{sydwEntity.dwlx}
        </if>
    </select>

    <select id="sydwDetail" resultType="org.springblade.modules.entity.SydwEntity">
        select * from jdrh.ybss_sydw where is_deleted = 0 and id = #{id}
    </select>

    <select id="selectCyryByDzbm" resultType="org.springblade.modules.entity.CyryEntity">
        select * from jdrh.ybss_cyry where is_deleted = 0 and tyshxydm = #{tyshxydm}
    </select>

    <select id="cyryDetail" resultType="org.springblade.modules.entity.CyryEntity">
        select * from jdrh.ybss_cyry where is_deleted = 0 and id = #{id}
    </select>

    <select id="selectDwDz" resultType="org.springblade.modules.vo.DwdzVO">
        SELECT
            rd.xz,
            rd.dzbm
        FROM
            sspt.rk_ldphxx rl
        LEFT JOIN blade_user bu ON bu.dept_id = rl.pcsjgdm
        LEFT JOIN sspt.rk_dzxx rd ON rl.xlh = rd.ldphxlh
        WHERE
            rl.pcsjgdm = #{deptId} and rd.dzbm is not null
    </select>

    <select id="selectCyrylsByDzbm" resultType="org.springblade.modules.entity.CyryEntity">
        select * from jdrh.ybss_cyry where is_deleted = 1 and tyshxydm = #{tyshxydm}
    </select>

    <select id="djxx" resultType="org.springblade.modules.vo.UserVO">
        select
            bu.sfzh
        from blade_user bu
        where bu.is_deleted = 0 and bu.id = #{id}
    </select>

    <select id="getMphxlhByLdphxlh" resultType="org.springblade.modules.entity.SydwEntity">
        select dzbm from sspt.rk_dzxx where ldphxlh = coalesce (nullif (#{ldphxlh}, ''), '0'):: int8
    </select>

    <select id="selectFwInfo" resultType="org.springblade.modules.entity.SydwEntity">
        select
        ys.id,
        ys.dzbm,
        ys.dwmc,
        ys.tyshxydm,
        ys.dwlx,
        ( select count(0) from jdrh.ybss_cyry yc where yc.is_deleted = 0 and yc.tyshxydm = ys.tyshxydm) as cyry,
        rd.xz
        from jdrh.ybss_sydw ys
        left join sspt.rk_dzxx rd on rd.dzbm = ys.dzbm
        where ys.is_deleted = 0 and ys.dzbm = #{dzbm}
        <if test="sydwEntity.dwmc != null and sydwEntity.dwmc != ''">
            and ys.dwmc like '%' || #{sydwEntity.dwmc} || '%'
        </if>
        <if test="sydwEntity.tyshxydm != null and sydwEntity.tyshxydm != ''">
            and ys.tyshxydm = #{sydwEntity.tyshxydm}
        </if>
        <if test="sydwEntity.dwlx != null and sydwEntity.dwlx != ''">
            and ys.dwlx = #{sydwEntity.dwlx}
        </if>
    </select>

    <select id="getFwxzByRkDzxx" resultType="java.lang.String">
        select xz from sspt.rk_dzxx where dzbm = #{dzbm} limit 1
    </select>
</mapper>
