<?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.th.demo.mapping.system.SysMenuMapper">
  <resultMap id="BaseResultMap" type="com.th.demo.model.system.SysMenu" >
    <id column="ID" property="id" jdbcType="VARCHAR" />
    <result column="MENU_PID" property="menuPid" jdbcType="VARCHAR" />
    <result column="MENU_CODE" property="menuCode" jdbcType="VARCHAR" />
    <result column="MENU_NAME" property="menuName" jdbcType="VARCHAR" />
    <result column="MENU_OPEN_CS" property="menuOpenCs" jdbcType="VARCHAR" />
    <result column="MENU_OPEN_BS" property="menuOpenBs" jdbcType="VARCHAR" />
    <result column="MENU_OPEN_IOS" property="menuOpenIos" jdbcType="VARCHAR" />
    <result column="MENU_OPEN_AND" property="menuOpenAnd" jdbcType="VARCHAR" />
    <result column="MENU_APP" property="menuApp" jdbcType="DECIMAL" />
    <result column="MENU_APP_ORDER" property="menuAppOrder" jdbcType="DECIMAL" />
    <result column="MENU_APP_IMG" property="menuAppImg" jdbcType="VARCHAR" />
    <result column="ADD_ID" property="addId" jdbcType="VARCHAR" />
    <result column="ADD_TIME" property="addTime" jdbcType="TIMESTAMP" />
    <result column="MODIFY_ID" property="modifyId" jdbcType="VARCHAR" />
    <result column="MODIFY_TIME" property="modifyTime" jdbcType="TIMESTAMP" />
    <result column="CANCEL_ID" property="cancelId" jdbcType="VARCHAR" />
    <result column="CANCEL_TIME" property="cancelTime" jdbcType="TIMESTAMP" />
    <result column="CANCEL_FLAG" property="cancelFlag" jdbcType="VARCHAR" />
    <result column="ATTR1" property="attr1" jdbcType="VARCHAR" />
    <result column="ATTR2" property="attr2" jdbcType="VARCHAR" />
    <result column="ATTR3" property="attr3" jdbcType="VARCHAR" />
    <result column="ATTR4" property="attr4" jdbcType="DECIMAL" />
    <result column="ATTR5" property="attr5" jdbcType="DECIMAL" />
    <result column="ATTR6" property="attr6" jdbcType="DECIMAL" />
    <result column="MENU_BS_ICON" property="menuBsIcon" jdbcType="VARCHAR" />
    <result column="MENU_SHOW" property="menuShow" jdbcType="DECIMAL" />
  </resultMap>
  <sql id="Base_Column_List" >
    ID, MENU_PID, MENU_CODE, MENU_NAME, MENU_OPEN_CS, MENU_OPEN_BS, MENU_OPEN_IOS, MENU_OPEN_AND,
    MENU_APP, MENU_APP_ORDER, MENU_APP_IMG, ADD_ID, ADD_TIME, MODIFY_ID, MODIFY_TIME,
    CANCEL_ID, CANCEL_TIME, CANCEL_FLAG, ATTR1, ATTR2, ATTR3, ATTR4, ATTR5, ATTR6, MENU_BS_ICON,
    MENU_SHOW
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from sys_menu
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from sys_menu
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.th.demo.model.system.SysMenu" >
    insert into sys_menu (ID, MENU_PID, MENU_CODE,
    MENU_NAME, MENU_OPEN_CS, MENU_OPEN_BS,
    MENU_OPEN_IOS, MENU_OPEN_AND, MENU_APP,
    MENU_APP_ORDER, MENU_APP_IMG, ADD_ID,
    ADD_TIME, MODIFY_ID, MODIFY_TIME,
    CANCEL_ID, CANCEL_TIME, CANCEL_FLAG,
    ATTR1, ATTR2, ATTR3,
    ATTR4, ATTR5, ATTR6,
    MENU_BS_ICON, MENU_SHOW)
    values (REPLACE(UUID(),'-',''), #{menuPid,jdbcType=VARCHAR}, #{menuCode,jdbcType=VARCHAR},
    #{menuName,jdbcType=VARCHAR}, #{menuOpenCs,jdbcType=VARCHAR}, #{menuOpenBs,jdbcType=VARCHAR},
    #{menuOpenIos,jdbcType=VARCHAR}, #{menuOpenAnd,jdbcType=VARCHAR}, #{menuApp,jdbcType=DECIMAL},
    #{menuAppOrder,jdbcType=DECIMAL}, #{menuAppImg,jdbcType=VARCHAR}, #{addId,jdbcType=VARCHAR},
    #{addTime,jdbcType=TIMESTAMP}, #{modifyId,jdbcType=VARCHAR}, #{modifyTime,jdbcType=TIMESTAMP},
    #{cancelId,jdbcType=VARCHAR}, #{cancelTime,jdbcType=TIMESTAMP}, #{cancelFlag,jdbcType=VARCHAR},
    #{attr1,jdbcType=VARCHAR}, #{attr2,jdbcType=VARCHAR}, #{attr3,jdbcType=VARCHAR},
    #{attr4,jdbcType=DECIMAL}, #{attr5,jdbcType=DECIMAL}, #{attr6,jdbcType=DECIMAL},
    #{menuBsIcon,jdbcType=VARCHAR}, #{menuShow,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" parameterType="com.th.demo.model.system.SysMenu" >
    insert into sys_menu
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        ID,
      </if>
      <if test="menuPid != null" >
        MENU_PID,
      </if>
      <if test="menuCode != null" >
        MENU_CODE,
      </if>
      <if test="menuName != null" >
        MENU_NAME,
      </if>
      <if test="menuOpenCs != null" >
        MENU_OPEN_CS,
      </if>
      <if test="menuOpenBs != null" >
        MENU_OPEN_BS,
      </if>
      <if test="menuOpenIos != null" >
        MENU_OPEN_IOS,
      </if>
      <if test="menuOpenAnd != null" >
        MENU_OPEN_AND,
      </if>
      <if test="menuApp != null" >
        MENU_APP,
      </if>
      <if test="menuAppOrder != null" >
        MENU_APP_ORDER,
      </if>
      <if test="menuAppImg != null" >
        MENU_APP_IMG,
      </if>
      <if test="addId != null" >
        ADD_ID,
      </if>
      <if test="addTime != null" >
        ADD_TIME,
      </if>
      <if test="modifyId != null" >
        MODIFY_ID,
      </if>
      <if test="modifyTime != null" >
        MODIFY_TIME,
      </if>
      <if test="cancelId != null" >
        CANCEL_ID,
      </if>
      <if test="cancelTime != null" >
        CANCEL_TIME,
      </if>
      <if test="cancelFlag != null" >
        CANCEL_FLAG,
      </if>
      <if test="attr1 != null" >
        ATTR1,
      </if>
      <if test="attr2 != null" >
        ATTR2,
      </if>
      <if test="attr3 != null" >
        ATTR3,
      </if>
      <if test="attr4 != null" >
        ATTR4,
      </if>
      <if test="attr5 != null" >
        ATTR5,
      </if>
      <if test="attr6 != null" >
        ATTR6,
      </if>
      <if test="menuBsIcon != null" >
        MENU_BS_ICON,
      </if>
      <if test="menuShow != null" >
        MENU_SHOW,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="menuPid != null" >
        #{menuPid,jdbcType=VARCHAR},
      </if>
      <if test="menuCode != null" >
        #{menuCode,jdbcType=VARCHAR},
      </if>
      <if test="menuName != null" >
        #{menuName,jdbcType=VARCHAR},
      </if>
      <if test="menuOpenCs != null" >
        #{menuOpenCs,jdbcType=VARCHAR},
      </if>
      <if test="menuOpenBs != null" >
        #{menuOpenBs,jdbcType=VARCHAR},
      </if>
      <if test="menuOpenIos != null" >
        #{menuOpenIos,jdbcType=VARCHAR},
      </if>
      <if test="menuOpenAnd != null" >
        #{menuOpenAnd,jdbcType=VARCHAR},
      </if>
      <if test="menuApp != null" >
        #{menuApp,jdbcType=DECIMAL},
      </if>
      <if test="menuAppOrder != null" >
        #{menuAppOrder,jdbcType=DECIMAL},
      </if>
      <if test="menuAppImg != null" >
        #{menuAppImg,jdbcType=VARCHAR},
      </if>
      <if test="addId != null" >
        #{addId,jdbcType=VARCHAR},
      </if>
      <if test="addTime != null" >
        #{addTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyId != null" >
        #{modifyId,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null" >
        #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelId != null" >
        #{cancelId,jdbcType=VARCHAR},
      </if>
      <if test="cancelTime != null" >
        #{cancelTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelFlag != null" >
        #{cancelFlag,jdbcType=VARCHAR},
      </if>
      <if test="attr1 != null" >
        #{attr1,jdbcType=VARCHAR},
      </if>
      <if test="attr2 != null" >
        #{attr2,jdbcType=VARCHAR},
      </if>
      <if test="attr3 != null" >
        #{attr3,jdbcType=VARCHAR},
      </if>
      <if test="attr4 != null" >
        #{attr4,jdbcType=DECIMAL},
      </if>
      <if test="attr5 != null" >
        #{attr5,jdbcType=DECIMAL},
      </if>
      <if test="attr6 != null" >
        #{attr6,jdbcType=DECIMAL},
      </if>
      <if test="menuBsIcon != null" >
        #{menuBsIcon,jdbcType=VARCHAR},
      </if>
      <if test="menuShow != null" >
        #{menuShow,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.th.demo.model.system.SysMenu" >
    update sys_menu
    <set >
      <if test="menuPid != null" >
        MENU_PID = #{menuPid,jdbcType=VARCHAR},
      </if>
      <if test="menuCode != null" >
        MENU_CODE = #{menuCode,jdbcType=VARCHAR},
      </if>
      <if test="menuName != null" >
        MENU_NAME = #{menuName,jdbcType=VARCHAR},
      </if>
      <if test="menuOpenCs != null" >
        MENU_OPEN_CS = #{menuOpenCs,jdbcType=VARCHAR},
      </if>
      <if test="menuOpenBs != null" >
        MENU_OPEN_BS = #{menuOpenBs,jdbcType=VARCHAR},
      </if>
      <if test="menuOpenIos != null" >
        MENU_OPEN_IOS = #{menuOpenIos,jdbcType=VARCHAR},
      </if>
      <if test="menuOpenAnd != null" >
        MENU_OPEN_AND = #{menuOpenAnd,jdbcType=VARCHAR},
      </if>
      <if test="menuApp != null" >
        MENU_APP = #{menuApp,jdbcType=DECIMAL},
      </if>
      <if test="menuAppOrder != null" >
        MENU_APP_ORDER = #{menuAppOrder,jdbcType=DECIMAL},
      </if>
      <if test="menuAppImg != null" >
        MENU_APP_IMG = #{menuAppImg,jdbcType=VARCHAR},
      </if>
      <if test="addId != null" >
        ADD_ID = #{addId,jdbcType=VARCHAR},
      </if>
      <if test="addTime != null" >
        ADD_TIME = #{addTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyId != null" >
        MODIFY_ID = #{modifyId,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null" >
        MODIFY_TIME = #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelId != null" >
        CANCEL_ID = #{cancelId,jdbcType=VARCHAR},
      </if>
      <if test="cancelTime != null" >
        CANCEL_TIME = #{cancelTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelFlag != null" >
        CANCEL_FLAG = #{cancelFlag,jdbcType=VARCHAR},
      </if>
      <if test="attr1 != null" >
        ATTR1 = #{attr1,jdbcType=VARCHAR},
      </if>
      <if test="attr2 != null" >
        ATTR2 = #{attr2,jdbcType=VARCHAR},
      </if>
      <if test="attr3 != null" >
        ATTR3 = #{attr3,jdbcType=VARCHAR},
      </if>
      <if test="attr4 != null" >
        ATTR4 = #{attr4,jdbcType=DECIMAL},
      </if>
      <if test="attr5 != null" >
        ATTR5 = #{attr5,jdbcType=DECIMAL},
      </if>
      <if test="attr6 != null" >
        ATTR6 = #{attr6,jdbcType=DECIMAL},
      </if>
      <if test="menuBsIcon != null" >
        MENU_BS_ICON = #{menuBsIcon,jdbcType=VARCHAR},
      </if>
      <if test="menuShow != null" >
        MENU_SHOW = #{menuShow,jdbcType=DECIMAL},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.th.demo.model.system.SysMenu" >
    update sys_menu
    set MENU_PID = #{menuPid,jdbcType=VARCHAR},
      MENU_CODE = #{menuCode,jdbcType=VARCHAR},
      MENU_NAME = #{menuName,jdbcType=VARCHAR},
      MENU_OPEN_CS = #{menuOpenCs,jdbcType=VARCHAR},
      MENU_OPEN_BS = #{menuOpenBs,jdbcType=VARCHAR},
      MENU_OPEN_IOS = #{menuOpenIos,jdbcType=VARCHAR},
      MENU_OPEN_AND = #{menuOpenAnd,jdbcType=VARCHAR},
      MENU_APP = #{menuApp,jdbcType=DECIMAL},
      MENU_APP_ORDER = #{menuAppOrder,jdbcType=DECIMAL},
      MENU_APP_IMG = #{menuAppImg,jdbcType=VARCHAR},
      ADD_ID = #{addId,jdbcType=VARCHAR},
      ADD_TIME = #{addTime,jdbcType=TIMESTAMP},
      MODIFY_ID = #{modifyId,jdbcType=VARCHAR},
      MODIFY_TIME = #{modifyTime,jdbcType=TIMESTAMP},
      CANCEL_ID = #{cancelId,jdbcType=VARCHAR},
      CANCEL_TIME = #{cancelTime,jdbcType=TIMESTAMP},
      CANCEL_FLAG = #{cancelFlag,jdbcType=VARCHAR},
      ATTR1 = #{attr1,jdbcType=VARCHAR},
      ATTR2 = #{attr2,jdbcType=VARCHAR},
      ATTR3 = #{attr3,jdbcType=VARCHAR},
      ATTR4 = #{attr4,jdbcType=DECIMAL},
      ATTR5 = #{attr5,jdbcType=DECIMAL},
      ATTR6 = #{attr6,jdbcType=DECIMAL},
      MENU_BS_ICON = #{menuBsIcon,jdbcType=VARCHAR},
      MENU_SHOW = #{menuShow,jdbcType=DECIMAL}
    where ID = #{id,jdbcType=VARCHAR}
  </update>

  <select id="selectAll" resultMap="BaseResultMap" parameterType="java.lang.Integer">
    select
    <include refid="Base_Column_List"/>
    from sys_menu WHERE   ifnull( cancel_flag,0)!=9
    order by menu_code asc

  </select>

  <select id="selectByUserId" resultMap="BaseResultMap" >
    select distinct  m.*
    from sys_menu m,sys_role_menu r,sys_user_role ur
    where m.id=r.menu_id and  ur.role_id=r.role_id
    and ur.user_id = #{param1,jdbcType=VARCHAR}
      and ifnull(m.menu_app,0) != 9  and  ifnull(m.cancel_flag,'0')!= '9'
      order by menu_pid,menu_code asc
  </select>

  <select id="selectByRoleId" resultMap="BaseResultMap">
    select
    m.*
    from sys_menu m,sys_role_menu r
    where m.id=r.menu_id
    and r.role_id = #{param1,jdbcType=VARCHAR} order by menu_code asc
  </select>

  <select id="selectByMenuPid" resultMap="BaseResultMap">
    select * from sys_menu
    where menu_pid = #{param1,jdbcType=VARCHAR}
    and ifnull(cancel_flag ,'0') !='9'  order by menu_code asc
  </select>
  <select id="selectMainMenu" resultMap="BaseResultMap"  >
    select
    <include refid="Base_Column_List" />
    from sys_menu where CANCEL_FLAG != '9' order by menu_code asc

  </select>

  <select id="selectMenuPage" resultMap="BaseResultMap">
    SELECT * FROM sys_menu WHERE menu_pid = #{param1,jdbcType=VARCHAR} and  CANCEL_FLAG != '9' ORDER BY menu_code
  </select>


  <select id="selectMenuPageTotal" resultType="java.lang.Integer">
    select count(*)
    from sys_menu where  menu_pid = #{param1,jdbcType=VARCHAR}

  </select>




  <select id="selectAppMenuByUserId"  resultMap="BaseResultMap">
    select DISTINCT  m.*
    from sys_menu m,sys_role_menu r,sys_user_role ur
    where m.id=r.menu_id and  ur.role_id=r.role_id
    and ur.user_id = #{param1,jdbcType=INTEGER} and m.menu_app = 1
      and menu_pid != '0' order by m.menu_app_order asc
  </select>






  <select id="selectTableName" resultType="java.lang.String">
    select TABLE_NAME from information_schema.tables where table_name like 'T_UG%'
  </select>

  <update id="deleteByUpdate9">
    update sys_menu
    set  CANCEL_ID = #{cancelId,jdbcType=VARCHAR},
      CANCEL_TIME = #{cancelTime,jdbcType=TIMESTAMP},
      CANCEL_FLAG = #{cancelFlag,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=VARCHAR}
  </update>





  <select id="selectByMenuCode"  resultMap="BaseResultMap">
    select *  from sys_menu t where t.menu_code = #{param1,jdbcType=VARCHAR}
    and ifnull(t.cancel_flag,'0') = '0'
  </select>

  <select id="selectByUserIdForRoleMenu" resultMap="BaseResultMap" >
    select distinct  m.*
    from sys_menu m,sys_role_menu r,sys_user_role ur
    where m.id=r.menu_id and  ur.role_id=r.role_id
    and ur.user_id = #{param1,jdbcType=VARCHAR}
      and ifnull(m.menu_app,0) != 9  and  ifnull(m.cancel_flag,'0')!= '9'
      and m.menu_code not like '%F80%' and m.menu_code not like '%F90%'
      order by menu_pid,menu_code asc
  </select>


</mapper>