<?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.lightinit.hsdataplatform.mapper.MenuMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.Menu">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="menucode" jdbcType="VARCHAR" property="menucode" />
    <result column="menuname" jdbcType="VARCHAR" property="menuname" />
    <result column="menuicon" jdbcType="VARCHAR" property="menuicon" />
    <result column="menuaction" jdbcType="VARCHAR" property="menuaction" />
    <result column="menutype" jdbcType="INTEGER" property="menutype" />
    <result column="menusequence" jdbcType="INTEGER" property="menusequence" />
    <result column="menushow" jdbcType="INTEGER" property="menushow" />
    <result column="parentmenu" jdbcType="BIGINT" property="parentmenu" />
    <result column="menushowtype" jdbcType="VARCHAR" property="menushowtype" />
    <result column="addtime" jdbcType="TIMESTAMP" property="addtime" />
    <collection property="children" column="id" ofType="com.lightinit.hsdataplatform.entity.Menu" select="com.lightinit.hsdataplatform.mapper.MenuMapper.selectByParentId"></collection>
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, menucode, menuname, menuicon, menuaction, menutype, menusequence, menushow, parentmenu, 
    menushowtype, addtime
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdataplatform.entity.MenuExample" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from menu
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from menu
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from menu
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.MenuExample">
    delete from menu
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.Menu">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into menu (id, menucode, menuname, 
      menuicon, menuaction, menutype, 
      menusequence, menushow, parentmenu, 
      menushowtype, addtime)
    values (#{id,jdbcType=BIGINT}, #{menucode,jdbcType=VARCHAR}, #{menuname,jdbcType=VARCHAR}, 
      #{menuicon,jdbcType=VARCHAR}, #{menuaction,jdbcType=VARCHAR}, #{menutype,jdbcType=INTEGER}, 
      #{menusequence,jdbcType=INTEGER}, #{menushow,jdbcType=INTEGER}, #{parentmenu,jdbcType=BIGINT}, 
      #{menushowtype,jdbcType=VARCHAR}, #{addtime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.Menu">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into menu
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="menucode != null">
        menucode,
      </if>
      <if test="menuname != null">
        menuname,
      </if>
      <if test="menuicon != null">
        menuicon,
      </if>
      <if test="menuaction != null">
        menuaction,
      </if>
      <if test="menutype != null">
        menutype,
      </if>
      <if test="menusequence != null">
        menusequence,
      </if>
      <if test="menushow != null">
        menushow,
      </if>
      <if test="parentmenu != null">
        parentmenu,
      </if>
      <if test="menushowtype != null">
        menushowtype,
      </if>
      <if test="addtime != null">
        addtime,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="menucode != null">
        #{menucode,jdbcType=VARCHAR},
      </if>
      <if test="menuname != null">
        #{menuname,jdbcType=VARCHAR},
      </if>
      <if test="menuicon != null">
        #{menuicon,jdbcType=VARCHAR},
      </if>
      <if test="menuaction != null">
        #{menuaction,jdbcType=VARCHAR},
      </if>
      <if test="menutype != null">
        #{menutype,jdbcType=INTEGER},
      </if>
      <if test="menusequence != null">
        #{menusequence,jdbcType=INTEGER},
      </if>
      <if test="menushow != null">
        #{menushow,jdbcType=INTEGER},
      </if>
      <if test="parentmenu != null">
        #{parentmenu,jdbcType=BIGINT},
      </if>
      <if test="menushowtype != null">
        #{menushowtype,jdbcType=VARCHAR},
      </if>
      <if test="addtime != null">
        #{addtime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.MenuExample" resultType="java.lang.Long">
    select count(*) from menu
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update menu
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.menucode != null">
        menucode = #{record.menucode,jdbcType=VARCHAR},
      </if>
      <if test="record.menuname != null">
        menuname = #{record.menuname,jdbcType=VARCHAR},
      </if>
      <if test="record.menuicon != null">
        menuicon = #{record.menuicon,jdbcType=VARCHAR},
      </if>
      <if test="record.menuaction != null">
        menuaction = #{record.menuaction,jdbcType=VARCHAR},
      </if>
      <if test="record.menutype != null">
        menutype = #{record.menutype,jdbcType=INTEGER},
      </if>
      <if test="record.menusequence != null">
        menusequence = #{record.menusequence,jdbcType=INTEGER},
      </if>
      <if test="record.menushow != null">
        menushow = #{record.menushow,jdbcType=INTEGER},
      </if>
      <if test="record.parentmenu != null">
        parentmenu = #{record.parentmenu,jdbcType=BIGINT},
      </if>
      <if test="record.menushowtype != null">
        menushowtype = #{record.menushowtype,jdbcType=VARCHAR},
      </if>
      <if test="record.addtime != null">
        addtime = #{record.addtime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update menu
    set id = #{record.id,jdbcType=BIGINT},
      menucode = #{record.menucode,jdbcType=VARCHAR},
      menuname = #{record.menuname,jdbcType=VARCHAR},
      menuicon = #{record.menuicon,jdbcType=VARCHAR},
      menuaction = #{record.menuaction,jdbcType=VARCHAR},
      menutype = #{record.menutype,jdbcType=INTEGER},
      menusequence = #{record.menusequence,jdbcType=INTEGER},
      menushow = #{record.menushow,jdbcType=INTEGER},
      parentmenu = #{record.parentmenu,jdbcType=BIGINT},
      menushowtype = #{record.menushowtype,jdbcType=VARCHAR},
      addtime = #{record.addtime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataplatform.entity.Menu">
    update menu
    <set>
      <if test="menucode != null">
        menucode = #{menucode,jdbcType=VARCHAR},
      </if>
      <if test="menuname != null">
        menuname = #{menuname,jdbcType=VARCHAR},
      </if>
      <if test="menuicon != null">
        menuicon = #{menuicon,jdbcType=VARCHAR},
      </if>
      <if test="menuaction != null">
        menuaction = #{menuaction,jdbcType=VARCHAR},
      </if>
      <if test="menutype != null">
        menutype = #{menutype,jdbcType=INTEGER},
      </if>
      <if test="menusequence != null">
        menusequence = #{menusequence,jdbcType=INTEGER},
      </if>
      <if test="menushow != null">
        menushow = #{menushow,jdbcType=INTEGER},
      </if>
      <if test="parentmenu != null">
        parentmenu = #{parentmenu,jdbcType=BIGINT},
      </if>
      <if test="menushowtype != null">
        menushowtype = #{menushowtype,jdbcType=VARCHAR},
      </if>
      <if test="addtime != null">
        addtime = #{addtime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.Menu">
    update menu
    set menucode = #{menucode,jdbcType=VARCHAR},
      menuname = #{menuname,jdbcType=VARCHAR},
      menuicon = #{menuicon,jdbcType=VARCHAR},
      menuaction = #{menuaction,jdbcType=VARCHAR},
      menutype = #{menutype,jdbcType=INTEGER},
      menusequence = #{menusequence,jdbcType=INTEGER},
      menushow = #{menushow,jdbcType=INTEGER},
      parentmenu = #{parentmenu,jdbcType=BIGINT},
      menushowtype = #{menushowtype,jdbcType=VARCHAR},
      addtime = #{addtime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="selectByParentId" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from menu where parentmenu = #{parentmenu,jdbcType=BIGINT} AND menushow=1 ORDER BY menusequence ASC
  </select>
  <select id="selectByUserMenu" parameterType="java.lang.String" resultMap="BaseResultMap">
    SELECT m.* FROM menu m JOIN role_module rm ON m.id=rm.moduleid JOIN admin_role ar ON rm.roleid=ar.roleid JOIN admin a ON ar.userid=a.id WHERE m.menutype=0 AND a.username= #{username,jdbcType=VARCHAR}
  </select>
  <select id="selectModuleActionList" resultType="com.lightinit.hsdataplatform.model.admin.ModuleActionListItemModel">
    SELECT m.menucode, m.menuname, m.menuaction, ma.id, ma.module_id, ma.action_name, ma.action_code, ma.action_url
    FROM menu m
    LEFT JOIN module_action ma ON m.id = ma.module_id
    ORDER BY m.menusequence DESC, m.id, ma.id
  </select>
</mapper>