<?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.YhGroupMapper">

    <resultMap id="yhGroupMap" type="com.tofly.feesapi.yhgl.entity.YhGroup">
        <id property="id" column="ID"/>
        <result property="yhbh" column="YHBH"/>
        <result property="isdisabled" column="ISDISABLED"/>
        <result property="czry" column="CZRY"/>
        <result property="czrymc" column="CZRYMC"/>
        <result property="czsj" column="CZSJ"/>
    </resultMap>

    <select id="getMaxid" resultType="java.lang.String">
        select max(ID) + 1
        from YH_GROUP
    </select>


    <select id="getPage" resultType="com.tofly.feesapi.yhgl.entity.vo.YhGroupSelect">
        select a.id,
        a.yhbh,
        a.isdisabled,
        a.czry,
        a.czrymc,
        a.czsj,
        b.yhxm,
        b.yhdz,
        b.lxdh,
        count(c.id) yhsl
        from yh_group a
        left join yh_group_accounts c on a.id = c.group_id
        left join yh_khjbxx b on a.yhbh = b.yhbh
        <where>
            <if test="filter.searchText != null and filter.searchText != ''">
                and (
                a.yhbh like '%${filter.searchText}%'
                or b.yhxm like '%${filter.searchText}%'
                or b.yhdz like '%${filter.searchText}%'
                or b.lxdh like '%${filter.searchText}%'
                )
            </if>
            <if test="filter.yhbh != null and filter.yhbh != ''">
                and a.yhbh = #{filter.yhbh}
            </if>
        </where>
        group by a.id,
        a.yhbh,
        a.isdisabled,
        a.czry,
        a.czrymc,
        a.czsj,
        b.yhxm,
        b.yhdz,
        b.lxdh
    </select>
</mapper>
