<?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.jwtdSpgl.mapper.JwtdSpglMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="jwtdSpglResultMap" type="org.springblade.modules.jwtdSpgl.pojo.entity.JwtdSpglEntity">
        <result column="spmc" property="spmc"/>
        <result column="spms" property="spms"/>
        <result column="lqdd" property="lqdd"/>
        <result column="spkcl" property="spkcl"/>
        <result column="dhsxjf" property="dhsxjf"/>
        <result column="spzt" property="spzt"/>
        <result column="spzp" property="spzp"/>
        <result column="spydhsl" property="spydhsl"/>
    </resultMap>

    <select id="selectJwtdSpglPage" resultMap="jwtdSpglResultMap">
        select
            js.*,
            rd.xz
        from jwtd_spgl js
        left join sspt.rk_dzxx rd on js.lqdd = rd.dzbm
        where js.is_deleted = 0
        <if test="jwtdSpgl.spmc != null and jwtdSpgl.spmc != ''">
            and (js.spmc like '%' || #{jwtdSpgl.spmc} || '%' or js.id :: text = #{jwtdSpgl.spmc})
        </if>
        <if test="jwtdSpgl.minJf != null and jwtdSpgl.minJf != '' and jwtdSpgl.maxJf != null and jwtdSpgl.maxJf != ''">
            and js.dhsxjf :: int8  between #{jwtdSpgl.minJf} :: int8  and #{jwtdSpgl.maxJf} :: int8
        </if>
        <if test="jwtdSpgl.spzt != null and jwtdSpgl.spzt != ''">
            and js.spzt = #{jwtdSpgl.spzt}
        </if>
    </select>

    <select id="exportJwtdSpgl" resultType="org.springblade.modules.jwtdSpgl.excel.JwtdSpglExcel">
        SELECT * FROM jwtd_spgl ${ew.customSqlSegment}
    </select>

    <update id="updateSpxj">
        update jwtd_spgl set spzt = '3' where id = #{id}
    </update>

    <update id="updateSpbh">
        update jwtd_spgl set spzt = '1', spkcl = #{spkcl} where id = #{id}
    </update>

    <select id="selectJwtdSpglPageApp" resultMap="jwtdSpglResultMap">
        select
            js.*,
            rd.xz
        from jwtd_spgl js
        left join sspt.rk_dzxx rd on js.lqdd = rd.dzbm
        where js.is_deleted = 0 and js.spzt = '1'
        <if test="jwtdSpgl.spmc != null and jwtdSpgl.spmc != ''">
            and (js.spmc like '%' || #{jwtdSpgl.spmc} || '%' or js.id :: text = #{jwtdSpgl.spmc})
        </if>
        <if test="jwtdSpgl.minJf != null and jwtdSpgl.minJf != '' and jwtdSpgl.maxJf != null and jwtdSpgl.maxJf != ''">
            and js.dhsxjf :: int8  between #{jwtdSpgl.minJf} :: int8  and #{jwtdSpgl.maxJf} :: int8
        </if>
        <if test="jwtdSpgl.spzt != null and jwtdSpgl.spzt != ''">
            and js.spzt = #{jwtdSpgl.spzt}
        </if>
    </select>

    <update id="updateSpzt">
        update jwtd_spgl set spzt = '2' where id = #{id}
    </update>

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