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

    <resultMap id="yhGroupAccountsMap" type="com.tofly.feesapi.yhgl.entity.YhGroupAccounts">
        <id property="id" column="ID"/>
        <result property="groupId" column="GROUP_ID"/>
        <result property="yhbh" column="YHBH"/>
        <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_ACCOUNTS
    </select>

    <select id="getPage" resultType="com.tofly.feesapi.yhgl.entity.vo.YhGroupAccountsSelect">
        select a.id,
        a.group_id groupId,
        a.czry,
        a.czrymc,
        a.czsj,
        c1.yhbh yhbh,
        c1.yhxm yhmc,
        c1.yhdz yhdz,
        c1.lxdh lxdh,
        c2.yhbh groupYhbh,
        c2.yhxm groupYhmc,
        c2.yhdz groupYhdz,
        c2.lxdh groupLxdh
        from yh_group_accounts a
        left join yh_group b on a.group_id = b.id
        left join yh_khjbxx c1 on a.yhbh = c1.yhbh
        left join yh_khjbxx c2 on b.yhbh = c2.yhbh
        <where>
            <if test="filter.searchText != null and filter.searchText != ''">
                and (
                a.yhbh like '%${filter.searchText}%'
                or b.yhbh like '%${filter.searchText}%'
                or c1.yhxm like '%${filter.searchText}%'
                or c1.yhdz like '%${filter.searchText}%'
                or c1.lxdh like '%${filter.searchText}%'
                or c2.yhxm like '%${filter.searchText}%'
                or c2.yhdz like '%${filter.searchText}%'
                or c2.lxdh like '%${filter.searchText}%'
                )
            </if>
            <if test="filter.groupId != null and filter.groupId != ''">
                and a.group_id = #{filter.groupId}
            </if>
            <if test="filter.yhbh != null and filter.yhbh != ''">
                and a.yhbh = #{filter.yhbh}
            </if>
        </where>
    </select>
</mapper>
