<?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.jwtdJwgk.mapper.JwtdJwgkMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="jwtdJwgkResultMap" type="org.springblade.modules.jwtdJwgk.pojo.entity.JwtdJwgkEntity">
        <result column="name" property="name"/>
        <result column="sex" property="sex"/>
        <result column="jh" property="jh"/>
        <result column="phone" property="phone"/>
        <result column="gxsq_id" property="gxsqId"/>
        <result column="jws_id" property="jwsId"/>
        <result column="pcs_id" property="pcsId"/>
        <result column="zwlb" property="zwlb"/>
        <result column="gzzz" property="gzzz"/>
        <result column="zp" property="zp"/>
    </resultMap>

    <select id="selectJwtdJwgkPage" resultMap="jwtdJwgkResultMap">
        select
            bu.id,
            bu.name,
            bu.sex,
            bu.jh,
            bu.phone,
            bu.gxsq_id,
            bu.jws_id,
            bu.pcs_id,
            bu.zp,
            bu.zwlb,
            bu.gzzz,
            bd.dept_name as ssdwMc,
            gxsq.dept_name as gxsqMc,
            jj.jwsmc,
            zwbdb.dict_value as zwlbmc,
            gzbdb.dict_value as gzzzmc
        from jwtd_jwgk bu
        left join blade_dept bd on bd.id = bu.pcs_id
        left join blade_dept gxsq on gxsq.id = bu.gxsq_id
        left join jdrh.jlrh_jws jj on jj.id = bu.jws_id
        left join blade_dict_biz zwbdb on bu.zwlb = zwbdb.dict_key and zwbdb.code = 'zwlb'
        left join blade_dict_biz gzbdb on bu.gzzz = gzbdb.dict_key and gzbdb.code = 'gwzz'
        where bu.is_deleted = 0
        <if test="jwtdJwgk.name != null and jwtdJwgk.name != ''">
            and bu.name like '%' || #{jwtdJwgk.name} || '%'
        </if>
        <if test="jwtdJwgk.sex != null and jwtdJwgk.sex != ''">
            and bu.sex = #{jwtdJwgk.sex}
        </if>
        <if test="jwtdJwgk.phone != null and jwtdJwgk.phone != ''">
            and bu.phone = #{jwtdJwgk.phone}
        </if>
        <if test="jwtdJwgk.pcsId != null and jwtdJwgk.pcsId != ''">
            and bu.pcs_id = #{jwtdJwgk.pcsId}
        </if>
        <if test="jwtdJwgk.jwsId != null and jwtdJwgk.jwsId != ''">
            and bu.jws_id = #{jwtdJwgk.jwsId}
        </if>
        <if test="jwtdJwgk.gxsqId != null and jwtdJwgk.gxsqId != ''">
            and bu.gxsq_id = #{jwtdJwgk.gxsqId}
        </if>
    </select>

    <select id="exportJwtdJwgk" resultType="org.springblade.modules.jwtdJwgk.excel.JwtdJwgkExcel">
        SELECT * FROM jwtd_jwgk ${ew.customSqlSegment}
    </select>

    <select id="selectJh" resultMap="jwtdJwgkResultMap">
        select jh from jwtd_jwgk where is_deleted = 0 and jh = #{jh}
    </select>
</mapper>
