<?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.jjdb.mapper.JjdbMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="jjdbResultMap" type="org.springblade.modules.jjdb.entity.JjdbEntity">
        <result column="sjdbh" property="sjdbh"/>
        <result column="bjsj" property="bjsj"/>
        <result column="bjrxm" property="bjrxm"/>
        <result column="lxdh" property="lxdh"/>
        <result column="afdd" property="afdd"/>
        <result column="bjnr" property="bjnr"/>
        <result column="bjlbdm" property="bjlbdm"/>
        <result column="fksj" property="fksj"/>
        <result column="fkdwdm" property="fkdwdm"/>
        <result column="cjrxm" property="cjrxm"/>
        <result column="cjqk" property="cjqk"/>
        <result column="cljgdm" property="cljgdm"/>
        <result column="jj_sjgxsj" property="jjSjgxsj"/>
        <result column="fk_sjgxsj" property="fkSjgxsj"/>

        <result column="sfcz" property="sfcz"/>
        <result column="zzsq" property="zzsq"/>
        <result column="pdly" property="pdly"/>
        <result column="sfmdjf" property="sfmdjf"/>
    </resultMap>


    <select id="selectJjdbPage" resultMap="jjdbResultMap">
        SELECT
        jw.*
        FROM
        PUBLIC.jjdb_xw jw
        LEFT JOIN "public".jz_gajgdmzd jg ON jg.gajgdm = jw.fkdwdm
        LEFT JOIN jdrh.blade_dept pcs ON pcs.ID = jg.gajg_xwdm
        WHERE ((#{params.deptId} LIKE '%' || pcs.id || '%') OR (pcs.ancestors LIKE '%' || #{params.deptId} || '%'))
        <if test="null != params.sfmdjf and '' != params.sfmdjf">
            AND jw.sfmdjf = #{params.sfmdjf}
        </if>
        <if test="null != params.sfcz and '' != params.sfcz">
            AND jw.sfcz = #{params.sfcz}
        </if>
        ORDER BY
        jw.sfcz,
        jw.bjsj DESC
    </select>


    <select id="getDetail" resultMap="jjdbResultMap">
        select * from public.jjdb_xw where sjdbh = #{sjdbh}
    </select>

    <update id="updateBySjdbh">
        update public.jjdb_xw set
            sfcz = #{sfcz},
            zzsq = #{zzsq},
            pdly = #{pdly},
            sfmdjf = #{sfmdjf}
        where sjdbh = #{sjdbh}
    </update>

    <select id="getSq" resultType="org.springblade.modules.system.vo.SqVO">
        SELECT
            sq.id,
            sq.dept_name
        FROM
            blade_dept sq
        WHERE sq.ancestors LIKE '%' || #{params.deptId} || '%'
        AND sq.dept_category = 7
    </select>
</mapper>
