<?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="com.tofly.feesapi.yhgl.mapper.YhXzbgLogMapper">

    <resultMap id="yhxzbgLogMap" type="com.tofly.feesapi.yhgl.entity.YhXzbgLog">
        <id property="bh" column="BH"/>
        <result property="oldSjmc" column="OLD_SJMC"/>
        <result property="newSjmc" column="NEW_SJMC"/>
        <result property="oldSjmc1" column="OLD_SJMC1"/>
        <result property="oldSjmc2" column="OLD_SJMC2"/>
        <result property="newSjmc1" column="NEW_SJMC1"/>
        <result property="newSjmc2" column="NEW_SJMC2"/>
        <result property="lxdh" column="LXDH"/>
        <result property="oldSj" column="OLD_SJ"/>
        <result property="oldYslx" column="OLD_YSLX"/>
        <result property="oldYslxmc" column="OLD_YSLXMC"/>
        <result property="newSj" column="NEW_SJ"/>
        <result property="oldSj1" column="OLD_SJ1"/>
        <result property="oldSj2" column="OLD_SJ2"/>
        <result property="newSj1" column="NEW_SJ1"/>
        <result property="newSj2" column="NEW_SJ2"/>
        <result property="newYslx" column="NEW_YSLX"/>
        <result property="newYslxmc" column="NEW_YSLXMC"/>
        <result property="source" column="SOURCE"/>
        <result property="wxid" column="WXID"/>
        <result property="newYbdjbz" column="NEW_YBDJBZ"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="bgfx" column="BGFX"/>
        <result property="cbkid" column="CBKID"/>
        <result property="bgyy" column="BGYY"/>
        <result property="oldYbdjbz" column="OLD_YBDJBZ"/>
        <result property="ssgs" column="SSGS"/>
        <result property="sscbpq" column="SSCBPQ"/>
        <result property="sscbb" column="SSCBB"/>
        <result property="yhbh" column="YHBH"/>
        <result property="oldSjbm" column="OLD_SJBM"/>
        <result property="newSjbm" column="NEW_SJBM"/>
        <result property="bgsj" column="BGSJ"/>
        <result property="czrybm" column="CZRYBM"/>
        <result property="czryxm" column="CZRYXM"/>
        <result property="bz" column="BZ"/>
        <result property="gdbh" column="GDBH"/>
        <result property="gdzt" column="GDZT"/>
        <result property="oldSjbm1" column="OLD_SJBM1"/>
        <result property="oldSjbm2" column="OLD_SJBM2"/>
        <result property="newSjbm1" column="NEW_SJBM1"/>
        <result property="newSjbm2" column="NEW_SJBM2"/>
        <result property="scds" column="SCDS"/>
        <result property="bcds" column="BCDS"/>
        <result property="bgnr" column="BGNR"/>
        <result property="newSlbl" column="NEW_SLBL"/>
        <result property="newSlbl1" column="NEW_SLBL1"/>
        <result property="newSlbl2" column="NEW_SLBL2"/>
    </resultMap>

    <select id="selectYhSj" resultType="com.tofly.feesapi.yhgl.entity.vo.YhXzbhSjVo">
        select a.yhbh, a.cbkid, b.name sjmc, b.code sjbm, c.name yslxmc, c.code yslx
        from yh_cbkxx a
                 left join bm_sj b on a.sjbm = b.code
                 left join bm_yslx c on b.yslx = c.code
        WHERE a.yhbh = #{yhbh}
    </select>

    <select id="getYhxzbgLogtj" resultType="com.tofly.feesapi.yhgl.entity.vo.YhXzbgLogSelect">
        SELECT
            yhbh,
            yhxm,
            yhdz,
            (case
                when old_ybdjbz='0' then '普通'
                when old_ybdjbz='1' then '每月混合'
                else '未知'
            end )oldHhlxmc,
            (case
                when new_ybdjbz='0' then '普通'
                when new_ybdjbz='1' then '每月混合'
                else '未知'
            end)newHhlxmc,
            old_yslxmc oldYslxmc,
            new_yslxmc newYslxmc,
            (case
                when bgfx = '0' then '不变'
                when bgfx = '1' then '低改高'
                when bgfx = '2' then '高改低'
                else '未知'
            end) bgfx,
            bgnr,
            bgyy,
            bz,
            bgsj,
            czryxm
        FROM
            yh_xzbg_log
        <where>
            <if test="filter.ssgs != null and filter.ssgs != ''">
                and ssgs = #{filter.ssgs}
            </if>
            <if test="filter.sscbpq != null and filter.sscbpq != ''">
                and sscbpq = #{filter.sscbpq}
            </if>
            <if test="filter.sscbb != null and filter.sscbb != ''">
                and sscbb = #{filter.sscbb}
            </if>
            <if test="filter.oldYslx != null and filter.oldYslx != ''">
                and old_yslx = #{filter.oldYslx}
            </if>
            <if test="filter.newYslx != null and filter.newYslx != ''">
                and new_yslx = #{filter.newYslx}
            </if>
            <if test="filter.czrybm != null and filter.czrybm != ''">
                and czrybm = #{filter.czrybm}
            </if>
            <if test="filter.bgfx != null and filter.bgfx != ''">
                and bgfx = #{filter.bgfx}
            </if>
            <if test="filter.searchText != null and filter.searchText != ''">
                and (
                yhbh like '%${filter.searchText}%'
                or yhxm like '%${filter.searchText}%'
                or yhdz like '%${filter.searchText}%'
                or old_yslxmc like '%${filter.searchText}%'
                or new_yslxmc like '%${filter.searchText}%'
                )
            </if>

            <if test="filter.czsjStart != null and filter.czsjEnd != null">
                and bgsj between #{filter.czsjStart} and #{filter.czsjEnd}
            </if>
            <if test="filter.gdzt != null and filter.gdzt != ''">
                and gdzt = #{filter.gdzt}
            </if>
        </where>
    </select>

</mapper>
