<?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.muchinfo.mtp3interface.mapper.ISubareagroupMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.muchinfo.mtp3pojos.entity.Subareagroup">
        <id column="SUBAREAGROUPID" property="subareagroupid" />
        <result column="SUBAREAGROUPTYPE" property="subareagrouptype" />
        <result column="SUBAREAGROUPNAME" property="subareagroupname" />
        <result column="REMARK" property="remark" />
        <result column="CREATORID" property="creatorid" />
        <result column="CREATETIME" property="createtime" />
        <result column="AREAUSERID" property="areauserid" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        SUBAREAGROUPID, SUBAREAGROUPTYPE, SUBAREAGROUPNAME, REMARK, CREATORID, CREATETIME, AREAUSERID
    </sql>

    <select id="getSubGroupPage" resultType="com.muchinfo.mtp3pojos.vo.profitshar.ProfitSharGroupResult">
        select t.*,s.username from subareagroup t
        left join systemmanager s on t.creatorid = s.autoid
        <where>
            <if test="subareagroupname!=null and subareagroupname!=''">
                and t.subareagroupname like '%'||#{subareagroupname}||'%'
            </if>
            <if test="areauserid!=null">
                and t.areauserid=#{areauserid}
            </if>
        </where>
    </select>

    <select id="getMemberPage" resultType="com.muchinfo.mtp3pojos.vo.profitshar.ProfitSharMemberResult">
        select t.userid, u.userid ||'/' || u.accountname as accountname
        from subareagroupdetail t
        left join useraccount u on t.userid = u.userid
        <where>
            <if test="subareagroupid!=null">
                and t.subareagroupid=#{subareagroupid}
            </if>
        </where>
    </select>

    <select id="getDivideConfigPage" resultType="com.muchinfo.mtp3pojos.vo.profitshar.ProfitSharInitConfigResult">
        select t.*,g.subareagroupname, s.username
        from subdivideconfig t
        left join subareagroup g on t.subareagroupid=g.subareagroupid
        left join systemmanager s on t.creatorid = s.autoid
        <where>
            <if test="areauserid != null">
                and g.areauserid = #{areauserid}
            </if>
        </where>
    </select>

</mapper>
