<?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.base.mapper.SystemMapper">

  <resultMap id="systemMap" type="com.tofly.base.entity.System">
                  <id property="id" column="ID"/>
                                                                                                                                          <result property="systemName" column="SYSTEM_NAME"/>
                        <result property="notes" column="NOTES"/>
                        <result property="createTime" column="CREATE_TIME"/>
                        <result property="createUser" column="CREATE_USER"/>
                        <result property="code" column="CODE"/>
                        <result property="icon" column="ICON"/>
                        <result property="mouseIcon" column="MOUSE_ICON"/>
                        <result property="sort" column="SORT"/>
                        <result property="systemType" column="SYSTEM_TYPE"/>
                        <result property="statusFlag" column="STATUS_FLAG"/>
                        <result property="loginIcon" column="LOGIN_ICON"/>
                        <result property="loginMouseIcon" column="LOGIN_MOUSE_ICON"/>
                        <result property="platform" column="PLATFORM"/>
            </resultMap>

    <select id="getSystemListByUser" resultMap="systemMap">
            select *
              from TF_SMPN_SYSTEM_X s
             where s.status_flag = '1'
               and exists (select 1
                      from TF_SMPN_USER_X      u,
                           TF_SMPN_USERROLE_X ur,
                           TF_SMPN_ROLE_X      r,
                           TF_SMPN_MENU_X      m,
                           TF_SMPN_ROLEMENU_X rm
                     where u.id = ur.user_id
                       and ur.role_id = r.id
                       and rm.role_id = r.id
                       and rm.menu_id = m.id
                       and m.sys_id = s.id
                       and u.status_flag = '1'
                       and r.status_flag = '1'
                       and m.status_flag = '1'
                       and u.id=#{id})
                and s.platform=#{platform}
                order by sort

    </select>


    <select id="listSystemPage" resultType="map" databaseId="oracle">
        select s.*,
         (select notes from tf_smpn_code_x where key='0014' and  value=s.platform) platform_nammeame,
         (select notes from tf_smpn_code_x where key='0011' and  value=s.STATUS_FLAG) status_flag_name
         from TF_SMPN_SYSTEM_X s
         order by sort
    </select>

    <select id="listSystemPage" resultType="map" databaseId="mysql">
        select s.*,
         (select notes from TF_SMPN_CODE_X where `key`='0014' and  `value`=s.platform) platform_nammeame,
         (select notes from TF_SMPN_CODE_X where `key`='0011' and  `value`=s.STATUS_FLAG) status_flag_name
         from TF_SMPN_SYSTEM_X s
         order by sort
    </select>
</mapper>
