Commit c0a1d7c0 by 陶光胜

菜单

parent ea6f6f61
package com.gic.auth.dao.mapper;
import com.gic.auth.entity.TabMenu;
import java.util.List;
public interface TabMenuMapper {
/**
* 根据主键删除
*
* @param menuId 主键
* @return 更新条目数
*/
int deleteByPrimaryKey(Integer menuId);
/**
* 插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insert(TabMenu record);
/**
* 动态插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insertSelective(TabMenu record);
/**
* 根据主键查询
*
* @param menuId 主键
* @return 实体对象
*/
TabMenu selectByPrimaryKey(Integer menuId);
/**
* 根据主键动态更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKeySelective(TabMenu record);
/**
* 根据主键更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKey(TabMenu record);
List<TabMenu> listMenu();
}
\ No newline at end of file
package com.gic.auth.entity;
import java.util.Date;
/**
* tab_menu
*/
public class TabMenu {
/**
*
*/
private Integer menuId;
/**
* 菜单名称
*/
private String menuName;
/**
* 所在项目
*/
private String project;
/**
* 菜单路由
*/
private String menuUrl;
/**
* 上级菜单id
*/
private Integer parentId;
/**
* 0当前页1新开页
*/
private Integer target;
/**
*
*/
private String iconUrl;
/**
*
*/
private Integer sort;
/**
* 0删除1有效
*/
private Integer status;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
/**
*
*/
private Integer level;
/**
* 是否显示在菜单栏的菜单,0否1是
*/
private Integer isShow;
public Integer getMenuId() {
return menuId;
}
public void setMenuId(Integer menuId) {
this.menuId = menuId;
}
public String getMenuName() {
return menuName;
}
public void setMenuName(String menuName) {
this.menuName = menuName;
}
public String getProject() {
return project;
}
public void setProject(String project) {
this.project = project;
}
public String getMenuUrl() {
return menuUrl;
}
public void setMenuUrl(String menuUrl) {
this.menuUrl = menuUrl;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public Integer getTarget() {
return target;
}
public void setTarget(Integer target) {
this.target = target;
}
public String getIconUrl() {
return iconUrl;
}
public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public Integer getIsShow() {
return isShow;
}
public void setIsShow(Integer isShow) {
this.isShow = isShow;
}
}
\ No newline at end of file
package com.gic.auth.service;
import com.gic.auth.entity.TabMenu;
import com.gic.auth.entity.TabSysMenu;
import java.util.List;
public interface MenuService {
List<TabMenu> listMenu();
List<TabSysMenu> listMenu();
TabMenu getMenuById(Integer menuId);
TabSysMenu getMenuById(Integer menuId);
}
package com.gic.auth.service.impl;
import com.gic.auth.dao.mapper.TabMenuMapper;
import com.gic.auth.entity.TabMenu;
import com.gic.auth.entity.TabSysMenu;
import com.gic.auth.service.MenuService;
import com.gic.enterprise.dao.mapper.TabSysMenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -10,14 +10,14 @@ import java.util.List;
@Service("menuService")
public class MenuServiceImpl implements MenuService {
@Autowired
private TabMenuMapper tabMenuMapper;
private TabSysMenuMapper tabSysMenuMapper;
@Override
public List<TabMenu> listMenu() {
return this.tabMenuMapper.listMenu();
public List<TabSysMenu> listMenu() {
return this.tabSysMenuMapper.listMenu();
}
@Override
public TabMenu getMenuById(Integer menuId) {
return this.tabMenuMapper.selectByPrimaryKey(menuId);
public TabSysMenu getMenuById(Integer menuId) {
return this.tabSysMenuMapper.selectByPrimaryKey(menuId);
}
}
......@@ -2,10 +2,11 @@ package com.gic.auth.service.outer.impl;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.MenuDTO;
import com.gic.auth.entity.TabMenu;
import com.gic.auth.entity.TabSysMenu;
import com.gic.auth.service.MenuApiService;
import com.gic.auth.service.MenuService;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.utils.UserDetailUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -20,21 +21,22 @@ public class MenuApiServiceImpl implements MenuApiService {
@Override
public ServiceResponse<List<MenuDTO>> getUserMenu(Integer userId, Integer enterpriseId, Integer currentMenu) {
System.out.println(RpcContext.getContext().getAttachments());
List<TabMenu> menuList = this.menuService.listMenu();
System.out.println(UserDetailUtils.getUserDetail());
List<TabSysMenu> menuList = this.menuService.listMenu();
int level = 1;
int parentId = 0;
if(currentMenu != null){
TabMenu menu = this.menuService.getMenuById(currentMenu);
TabSysMenu menu = this.menuService.getMenuById(currentMenu);
parentId = menu.getParentId();
level = menu.getLevel()+1;
}
return ServiceResponse.success(this.treeMenu(menuList, level, parentId));
}
private List<MenuDTO> treeMenu(List<TabMenu> menuList, int level, int parentId){
private List<MenuDTO> treeMenu(List<TabSysMenu> menuList, int level, int parentId){
List<MenuDTO> list = new ArrayList<>();
if(level < 5){
for(TabMenu menu : menuList){
for(TabSysMenu menu : menuList){
if(level == menu.getLevel() && menu.getIsShow().intValue() == 1 && menu.getParentId().intValue() == parentId){
MenuDTO menuDTO = EntityUtil.changeEntityByJSON(MenuDTO.class, menu);
menuDTO.setChildren(this.treeMenu(menuList, menu.getLevel().intValue()+1, menuDTO.getMenuId()));
......
<?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.gic.auth.dao.mapper.TabMenuMapper">
<resultMap id="BaseResultMap" type="com.gic.auth.entity.TabMenu">
<id column="menu_id" jdbcType="INTEGER" property="menuId" />
<result column="menu_name" jdbcType="VARCHAR" property="menuName" />
<result column="project" jdbcType="VARCHAR" property="project" />
<result column="menu_url" jdbcType="VARCHAR" property="menuUrl" />
<result column="parent_id" jdbcType="INTEGER" property="parentId" />
<result column="target" jdbcType="INTEGER" property="target" />
<result column="icon_url" jdbcType="VARCHAR" property="iconUrl" />
<result column="sort" jdbcType="INTEGER" property="sort" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="level" jdbcType="INTEGER" property="level" />
<result column="is_show" jdbcType="INTEGER" property="isShow" />
</resultMap>
<sql id="Base_Column_List">
menu_id, menu_name, project, menu_url, parent_id, target, icon_url, sort, status,
create_time, update_time, level, is_show
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_menu
where menu_id = #{menuId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from tab_menu
where menu_id = #{menuId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.gic.auth.entity.TabMenu">
insert into tab_menu (menu_id, menu_name, project,
menu_url, parent_id, target,
icon_url, sort, status,
create_time, update_time, level,
is_show)
values (#{menuId,jdbcType=INTEGER}, #{menuName,jdbcType=VARCHAR}, #{project,jdbcType=VARCHAR},
#{menuUrl,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER}, #{target,jdbcType=INTEGER},
#{iconUrl,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{level,jdbcType=INTEGER},
#{isShow,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.gic.auth.entity.TabMenu">
insert into tab_menu
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="menuId != null">
menu_id,
</if>
<if test="menuName != null">
menu_name,
</if>
<if test="project != null">
project,
</if>
<if test="menuUrl != null">
menu_url,
</if>
<if test="parentId != null">
parent_id,
</if>
<if test="target != null">
target,
</if>
<if test="iconUrl != null">
icon_url,
</if>
<if test="sort != null">
sort,
</if>
<if test="status != null">
status,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="level != null">
level,
</if>
<if test="isShow != null">
is_show,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="menuId != null">
#{menuId,jdbcType=INTEGER},
</if>
<if test="menuName != null">
#{menuName,jdbcType=VARCHAR},
</if>
<if test="project != null">
#{project,jdbcType=VARCHAR},
</if>
<if test="menuUrl != null">
#{menuUrl,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
#{parentId,jdbcType=INTEGER},
</if>
<if test="target != null">
#{target,jdbcType=INTEGER},
</if>
<if test="iconUrl != null">
#{iconUrl,jdbcType=VARCHAR},
</if>
<if test="sort != null">
#{sort,jdbcType=INTEGER},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="level != null">
#{level,jdbcType=INTEGER},
</if>
<if test="isShow != null">
#{isShow,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.auth.entity.TabMenu">
update tab_menu
<set>
<if test="menuName != null">
menu_name = #{menuName,jdbcType=VARCHAR},
</if>
<if test="project != null">
project = #{project,jdbcType=VARCHAR},
</if>
<if test="menuUrl != null">
menu_url = #{menuUrl,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
parent_id = #{parentId,jdbcType=INTEGER},
</if>
<if test="target != null">
target = #{target,jdbcType=INTEGER},
</if>
<if test="iconUrl != null">
icon_url = #{iconUrl,jdbcType=VARCHAR},
</if>
<if test="sort != null">
sort = #{sort,jdbcType=INTEGER},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="level != null">
level = #{level,jdbcType=INTEGER},
</if>
<if test="isShow != null">
is_show = #{isShow,jdbcType=INTEGER},
</if>
</set>
where menu_id = #{menuId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.gic.auth.entity.TabMenu">
update tab_menu
set menu_name = #{menuName,jdbcType=VARCHAR},
project = #{project,jdbcType=VARCHAR},
menu_url = #{menuUrl,jdbcType=VARCHAR},
parent_id = #{parentId,jdbcType=INTEGER},
target = #{target,jdbcType=INTEGER},
icon_url = #{iconUrl,jdbcType=VARCHAR},
sort = #{sort,jdbcType=INTEGER},
status = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
level = #{level,jdbcType=INTEGER},
is_show = #{isShow,jdbcType=INTEGER}
where menu_id = #{menuId,jdbcType=INTEGER}
</update>
<select id="listMenu" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_menu
where status=1
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment