<?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.szqyCsjl.mapper.JwtdSzqyCsjlMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="jwtdSzqyCsjlResultMap" type="org.springblade.modules.szqyCsjl.pojo.entity.JwtdSzqyCsjlEntity">
        <result column="jyz_id" property="jyzId"/>
        <result column="gmflx" property="gmflx"/>
        <result column="gmfmc" property="gmfmc"/>
        <result column="gmfzjh" property="gmfzjh"/>
        <result column="gmflxdh" property="gmflxdh"/>
        <result column="gmsj" property="gmsj"/>
        <result column="gmqyxh" property="gmqyxh"/>
        <result column="gmss" property="gmss"/>
        <result column="gmyt" property="gmyt"/>
        <result column="jyczybh" property="jyczybh"/>
        <result column="jyczyxm" property="jyczyxm"/>
        <result column="sfhggy" property="sfhggy"/>
        <result column="zmzp" property="zmzp"/>
    </resultMap>

    <select id="selectJwtdSzqyCsjlPage" resultMap="jwtdSzqyCsjlResultMap">
        select
            jsc.*,
            jsj.jyzmc,
            jsj.ssqx,
            jsj.sspcs,
            jsj.sssq,
            jsj.jyzzp,
            jsj.jyzxz,
            jsj.fzrxm,
            jsj.zjhm,
            jsj.fzrdh,
            jsj.zrmj,
            jsj.jh,
            pcs.dept_name as sspcsMc,
            sq.dept_name as sssqMc,
            br.city_name || br.name as ssqxMc
        from jwtd_szqy_csjl jsc
        left join jwtd_szqy_jyz jsj on jsc.shtyxydm = jsj.shtyxydm
        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 jsc.is_deleted = 0
        <if test="jwtdSzqyCsjl.gmfmc != null and jwtdSzqyCsjl.gmfmc != ''">
            and jsc.gmfmc like '%' || #{jwtdSzqyCsjl.gmfmc} || '%'
        </if>
        <if test="jwtdSzqyCsjl.gmflx != null and jwtdSzqyCsjl.gmflx != ''">
            and jsc.gmflx = #{jwtdSzqyCsjl.gmflx}
        </if>
        <if test="jwtdSzqyCsjl.gmqyxh != null and jwtdSzqyCsjl.gmqyxh != ''">
            and jsc.gmqyxh = #{jwtdSzqyCsjl.gmqyxh}
        </if>
        <if test="jwtdSzqyCsjl.gmyt != null and jwtdSzqyCsjl.gmyt != ''">
            and jsc.gmyt = #{jwtdSzqyCsjl.gmyt}
        </if>
        <if test="jwtdSzqyCsjl.startTime != null and jwtdSzqyCsjl.startTime != '' and jwtdSzqyCsjl.endTime != null and jwtdSzqyCsjl.endTime != ''">
            and jsc.gmsj between #{jwtdSzqyCsjl.startTime} and #{jwtdSzqyCsjl.endTime}
        </if>
        <if test="jwtdSzqyCsjl.jyzmc != null and jwtdSzqyCsjl.jyzmc != ''">
            and jsj.jyzmc like '%' || #{jwtdSzqyCsjl.jyzmc} || '%'
        </if>
        <if test="jwtdSzqyCsjl.ssqx != null and jwtdSzqyCsjl.ssqx != ''">
            and jsj.ssqx = #{jwtdSzqyCsjl.ssqx}
        </if>
        <if test="jwtdSzqyCsjl.sspcs != null and jwtdSzqyCsjl.sspcs != ''">
            and jsj.sspcs = #{jwtdSzqyCsjl.sspcs}
        </if>
        <if test="jwtdSzqyCsjl.sssq != null and jwtdSzqyCsjl.sssq != ''">
            and jsj.sssq = #{jwtdSzqyCsjl.sssq}
        </if>
    </select>

    <select id="exportJwtdSzqyCsjl" resultType="org.springblade.modules.szqyCsjl.excel.JwtdSzqyCsjlExcel">
        SELECT * FROM jwtd_szqy_csjl ${ew.customSqlSegment}
    </select>

    <select id="detailById" resultMap="jwtdSzqyCsjlResultMap">
        select
            *
        from jwtd_szqy_csjl jsc
        left join jwtd_szqy_jyz jsj on jsc.shtyxydm = jsj.shtyxydm
        where jsc.is_deleted = 0 and jsc.id = #{id}
    </select>
</mapper>
