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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.muchinfo.mtp3pojos.entity.Arearole">
        <id column="USERID" property="userid" />
        <result column="ROLETYPE" property="roletype" />
        <result column="TRADEACCOUNTID" property="tradeaccountid" />
        <result column="CREATETIME" property="createtime" />
        <result column="CREATORID" property="creatorid" />
        <result column="MODIFYTIME" property="modifytime" />
        <result column="MODIFIERID" property="modifierid" />
        <result column="SHOPPASSWORD" property="shoppassword" />
        <result column="ISRETURNSCORE" property="isreturnscore" />
        <result column="TRANSURL" property="transurl" />
        <result column="OUTUSERID" property="outuserid" />
        <result column="PARENTUSERID" property="parentuserid" />
        <result column="ROOTUSERID" property="rootuserid" />
        <result column="SUBLEVELPATH" property="sublevelpath" />
        <result column="ORGTYPE" property="orgtype" />
        <result column="SUBORGTYPE" property="suborgtype" />
        <result column="FROMUSERID" property="fromuserid" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        USERID, ROLETYPE, TRADEACCOUNTID, CREATETIME, CREATORID, MODIFYTIME, MODIFIERID, SHOPPASSWORD, ISRETURNSCORE, TRANSURL, OUTUSERID, PARENTUSERID, ROOTUSERID, SUBLEVELPATH, ORGTYPE, SUBORGTYPE, FROMUSERID
    </sql>

    <select id="getRolesByAreaid" parameterType="java.lang.Long" resultType="string">
        select wm_concat(t.RoleType) roleids
        from AreaRole t
        where t.UserID = #{userid}
    </select>

    <select id="queryMarketsForOperate" resultType="com.muchinfo.mtp3pojos.entity.Market">
        select t.marketid , t.marketname
        from market t
        where t.trademode not in (41,48,51,52,97,99)
          and t.marketid in (select distinct marketid from goods)
        order by t.marketid
    </select>

    <select id="queryGoodsAndMarketInfo" resultType="com.muchinfo.mtp3pojos.entity.Goods">
        select g.goodsid , g.marketid,
               g.goodscode , g.goodsname
        from goods g
                 inner join market m on m.marketid = g.marketid
        where m.trademode not in (41,48,51,52,97,99)
        order by m.marketid, g.goodscode
    </select>

    <select id="queryMarketArea" resultType="com.muchinfo.mtp3pojos.vo.tradingmarket.AreaRoleMarketInitResult"
            parameterType="java.lang.Long">
        SELECT
            ARM.AREAUSERID,
            ARM.ROLETYPE,
            UA.ACCOUNTNAME
        FROM
            AREAROLEMARKET arm, USERACCOUNT ua
        WHERE
            ARM.AREAUSERID = UA.USERID
          AND ARM.MARKETID = #{marketid,jdbcType=BIGINT}
    </select>

</mapper>
