<?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.szqyJyz.mapper.JwtdSzqyJyzMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="jwtdSzqyJyzResultMap" type="org.springblade.modules.szqyJyz.pojo.entity.JwtdSzqyJyzEntity">
        <result column="jyzmc" property="jyzmc"/>
        <result column="jyzxz" property="jyzxz"/>
        <result column="jyzzp" property="jyzzp"/>
        <result column="fzrxm" property="fzrxm"/>
        <result column="zjhm" property="zjhm"/>
        <result column="zrmj" property="zrmj"/>
        <result column="jh" property="jh"/>
        <result column="ssqx" property="ssqx"/>
        <result column="sspcs" property="sspcs"/>
        <result column="sssq" property="sssq"/>
    </resultMap>

    <select id="selectJwtdSzqyJyzPage" resultMap="jwtdSzqyJyzResultMap">
        select
            jsj.*,
            pcs.dept_name as sspcsMc,
            sq.dept_name as sssqMc,
            br.city_name || br.name as ssqxMc
        from jwtd_szqy_jyz jsj
        left join blade_dept pcs on jsj.sspcs = pcs.id
        left join blade_dept sq on jsj.sssq = sq.id
        left join blade_region br on jsj.ssqx :: text = br.code
        where jsj.is_deleted = 0
        <if test="jwtdSzqyJyz.jyzmc != null and jwtdSzqyJyz.jyzmc != ''">
            and jsj.jyzmc like '%' || #{jwtdSzqyJyz.jyzmc} || '%'
        </if>
        <if test="jwtdSzqyJyz.jyzxz != null and jwtdSzqyJyz.jyzxz != ''">
            and jsj.jyzxz like '%' || #{jwtdSzqyJyz.jyzxz} || '%'
        </if>
        <if test="jwtdSzqyJyz.fzrxm != null and jwtdSzqyJyz.fzrxm != ''">
            and jsj.fzrxm = #{jwtdSzqyJyz.fzrxm}
        </if>
        <if test="jwtdSzqyJyz.zjhm != null and jwtdSzqyJyz.zjhm != ''">
            and jsj.zjhm = #{jwtdSzqyJyz.zjhm}
        </if>
        <if test="jwtdSzqyJyz.fzrdh != null and jwtdSzqyJyz.fzrdh != ''">
            and jsj.zjhm = #{jwtdSzqyJyz.fzrdh}
        </if>
        <if test="jwtdSzqyJyz.ssqx != null and jwtdSzqyJyz.ssqx != ''">
            and jsj.ssqx = #{jwtdSzqyJyz.ssqx}
        </if>
        <if test="jwtdSzqyJyz.sspcs != null and jwtdSzqyJyz.sspcs != ''">
            and jsj.sspcs = #{jwtdSzqyJyz.sspcs}
        </if>
        <if test="jwtdSzqyJyz.sssq != null and jwtdSzqyJyz.sssq != ''">
            and jsj.sssq = #{jwtdSzqyJyz.sssq}
        </if>
    </select>

    <select id="exportJwtdSzqyJyz" resultType="org.springblade.modules.szqyJyz.excel.JwtdSzqyJyzExcel">
        SELECT * FROM jwtd_szqy_jyz ${ew.customSqlSegment}
    </select>

    <select id="selectCsjlById" resultType="org.springblade.modules.szqyCsjl.pojo.entity.JwtdSzqyCsjlEntity">
        select * from jwpt.jwtd_szqy_csjl jsc where jsc.is_deleted = 0 and jsc.shtyxydm = #{shtyxydm}
    </select>

    <select id="selectShtyxydm" resultType="java.lang.String">
        select shtyxydm from jwpt.jwtd_szqy_jyz jsj where jsj.is_deleted = 0 and jsj.shtyxydm = #{shtyxydm}
    </select>

    <select id="getJyzByDeptId" resultMap="jwtdSzqyJyzResultMap">
        select * from jwtd_szqy_jyz where is_deleted = 0 and shtyxydm = #{deptId}
    </select>
</mapper>
