首页展示导航信息

master
Administrator 12 months ago
parent 6dc95c02ea
commit f5485c2158

@ -28,7 +28,9 @@ public enum ExceptionEnums {
SEARCH_UPDATE_ERROR(-20,"修改文档信息失败!"), SEARCH_UPDATE_ERROR(-20,"修改文档信息失败!"),
KAPACHA_ERROR(-100,"验证码错误!"), KAPACHA_ERROR(-100,"验证码错误!"),
AUTHEN_ERROR(-101,"用户名或密码错误!") AUTHEN_ERROR(-101,"用户名或密码错误!"),
NOT_LOGIN(-102,"用户未登录!"),
USER_MENU_ERROR(-103,"查询用户的菜单信息失败!")
; ;
private Integer code; private Integer code;

@ -20,6 +20,16 @@ public class R {
return new ResultVO(0,""); return new ResultVO(0,"");
} }
/**
*
* @return
*/
public static ResultVO ok(Object data){
ResultVO vo = ok();
vo.setData(data);
return vo;
}
/** /**
* *
* @param enums * @param enums

@ -16,6 +16,9 @@ public class ResultVO {
private String msg; private String msg;
private Object data;
public ResultVO(Integer code, String msg) { public ResultVO(Integer code, String msg) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;

@ -6,17 +6,21 @@ import com.mashibing.common.enums.ExceptionEnums;
import com.mashibing.common.util.R; import com.mashibing.common.util.R;
import com.mashibing.common.vo.ResultVO; import com.mashibing.common.vo.ResultVO;
import com.mashibing.webmaster.dto.UserDTO; import com.mashibing.webmaster.dto.UserDTO;
import com.mashibing.webmaster.entity.SmsUser;
import com.mashibing.webmaster.service.SmsMenuService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* *
@ -29,7 +33,16 @@ import javax.validation.Valid;
@Slf4j @Slf4j
public class SmsUserController { public class SmsUserController {
@Autowired
private SmsMenuService menuService;
/**
*
*
* @param userDTO
* @param bindingResult
* @return
*/
@PostMapping("/login") @PostMapping("/login")
public ResultVO login(@RequestBody @Valid UserDTO userDTO, BindingResult bindingResult) { public ResultVO login(@RequestBody @Valid UserDTO userDTO, BindingResult bindingResult) {
// * 1、请求参数的非空校验 // * 1、请求参数的非空校验
@ -45,7 +58,7 @@ public class SmsUserController {
return R.error(ExceptionEnums.KAPACHA_ERROR); return R.error(ExceptionEnums.KAPACHA_ERROR);
} }
// * 3、基于用户名和密码做Shiro的认证操作 // * 3、基于用户名和密码做Shiro的认证操作
UsernamePasswordToken token = new UsernamePasswordToken(userDTO.getUsername(),userDTO.getPassword()); UsernamePasswordToken token = new UsernamePasswordToken(userDTO.getUsername(), userDTO.getPassword());
token.setRememberMe(userDTO.getRememberMe()); token.setRememberMe(userDTO.getRememberMe());
try { try {
SecurityUtils.getSubject().login(token); SecurityUtils.getSubject().login(token);
@ -59,4 +72,47 @@ public class SmsUserController {
} }
/**
*
*
* @return
*/
@GetMapping("/user/info")
public ResultVO info() {
//1、基于SecurityUtils获取用户信息
Subject subject = SecurityUtils.getSubject();
SmsUser smsUser = (SmsUser) subject.getPrincipal();
if (smsUser == null) {
log.info("【获取登录用户信息】 用户未登录!!");
return R.error(ExceptionEnums.NOT_LOGIN);
}
//2、封装结果返回
Map<String, Object> data = new HashMap<>();
data.put("nickname", smsUser.getNickname());
data.put("username", smsUser.getUsername());
return R.ok(data);
}
/**
*
* @return
*/
@GetMapping("/menu/user")
public ResultVO menuUser() {
// 基于用户的id根据角色表信息查询到菜单表中的详细内容
SmsUser smsUser = (SmsUser) SecurityUtils.getSubject().getPrincipal();
if (smsUser == null) {
log.info("【获取用户菜单信息】 用户未登录!!");
return R.error(ExceptionEnums.NOT_LOGIN);
}
// 封装为具体的下述的这种结构
List<Map<String, Object>> data = menuService.findUserMenu(smsUser.getId());
if (data == null){
log.error("【获取用户菜单信息】 查询用户菜单失败!! id = {}",smsUser.getId());
return R.error(ExceptionEnums.USER_MENU_ERROR);
}
// 返回结果
return R.ok(data);
}
} }

@ -3,6 +3,8 @@ package com.mashibing.webmaster.mapper;
import com.mashibing.webmaster.entity.SmsMenu; import com.mashibing.webmaster.entity.SmsMenu;
import com.mashibing.webmaster.entity.SmsMenuExample; import com.mashibing.webmaster.entity.SmsMenuExample;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
public interface SmsMenuMapper { public interface SmsMenuMapper {
@ -27,4 +29,11 @@ public interface SmsMenuMapper {
int updateByPrimaryKeySelective(SmsMenu row); int updateByPrimaryKeySelective(SmsMenu row);
int updateByPrimaryKey(SmsMenu row); int updateByPrimaryKey(SmsMenu row);
/**
* id
* @param id
* @return
*/
List<Map<String, Object>> findMenuByUserId(@Param("userId") Integer id);
} }

@ -0,0 +1,18 @@
package com.mashibing.webmaster.service;
import java.util.List;
import java.util.Map;
/**
* Service
* @author zjw
* @description
*/
public interface SmsMenuService {
/**
* id
* @param id Id
* @return
*/
List<Map<String, Object>> findUserMenu(Integer id);
}

@ -0,0 +1,59 @@
package com.mashibing.webmaster.service.impl;
import com.mashibing.webmaster.mapper.SmsMenuMapper;
import com.mashibing.webmaster.service.SmsMenuService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
/**
* @author zjw
* @description
*/
@Service
public class SmsMenuServiceImpl implements SmsMenuService {
@Resource
private SmsMenuMapper menuMapper;
@Override
public List<Map<String, Object>> findUserMenu(Integer id) {
//1、将多表查询的结果直接映射只查询type为0和type为1的数据 查询到的结果顺序是type正序排序
List<Map<String, Object>> list = menuMapper.findMenuByUserId(id);
//2、封装外层的父级菜单封装到当前的List集合
List<Map<String, Object>> data = new ArrayList<>();
//3、使用迭代器遍历所有的菜单信息封装父级菜单
ListIterator<Map<String, Object>> parentIterator = list.listIterator();
while (parentIterator.hasNext()) {
Map<String, Object> menu = parentIterator.next();
if ((int) menu.get("type") == 0) {
// 是父级菜单
data.add(menu);
parentIterator.remove();
} else {
break;
}
}
//4、存放二级菜单
for (Map<String, Object> parentMenu : data) {
List<Map<String, Object>> sonMenuList = new ArrayList<>();
ListIterator<Map<String, Object>> sonIterator = list.listIterator();
while (sonIterator.hasNext()) {
Map<String, Object> sonMenu = sonIterator.next();
if ((long) parentMenu.get("id") == (long) sonMenu.get("parentId")) {
sonMenuList.add(sonMenu);
sonIterator.remove();
}
}
parentMenu.put("list", sonMenuList);
}
//5、返回data
return data;
}
}

@ -1,117 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mashibing.webmaster.mapper.SmsMenuMapper"> <mapper namespace="com.mashibing.webmaster.mapper.SmsMenuMapper">
<resultMap id="BaseResultMap" type="com.mashibing.webmaster.entity.SmsMenu"> <resultMap id="BaseResultMap" type="com.mashibing.webmaster.entity.SmsMenu">
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name"/>
<result column="parent_id" jdbcType="BIGINT" property="parentId" /> <result column="parent_id" jdbcType="BIGINT" property="parentId"/>
<result column="url" jdbcType="VARCHAR" property="url" /> <result column="url" jdbcType="VARCHAR" property="url"/>
<result column="icon" jdbcType="VARCHAR" property="icon" /> <result column="icon" jdbcType="VARCHAR" property="icon"/>
<result column="type" jdbcType="INTEGER" property="type" /> <result column="type" jdbcType="INTEGER" property="type"/>
<result column="sort" jdbcType="INTEGER" property="sort" /> <result column="sort" jdbcType="INTEGER" property="sort"/>
<result column="created" jdbcType="TIMESTAMP" property="created" /> <result column="created" jdbcType="TIMESTAMP" property="created"/>
<result column="create_id" jdbcType="BIGINT" property="createId" /> <result column="create_id" jdbcType="BIGINT" property="createId"/>
<result column="updated" jdbcType="TIMESTAMP" property="updated" /> <result column="updated" jdbcType="TIMESTAMP" property="updated"/>
<result column="update_id" jdbcType="BIGINT" property="updateId" /> <result column="update_id" jdbcType="BIGINT" property="updateId"/>
<result column="is_delete" jdbcType="TINYINT" property="isDelete" /> <result column="is_delete" jdbcType="TINYINT" property="isDelete"/>
<result column="extend1" jdbcType="VARCHAR" property="extend1" /> <result column="extend1" jdbcType="VARCHAR" property="extend1"/>
<result column="extend2" jdbcType="VARCHAR" property="extend2" /> <result column="extend2" jdbcType="VARCHAR" property="extend2"/>
<result column="extend3" jdbcType="VARCHAR" property="extend3" /> <result column="extend3" jdbcType="VARCHAR" property="extend3"/>
<result column="extend4" jdbcType="VARCHAR" property="extend4" /> <result column="extend4" jdbcType="VARCHAR" property="extend4"/>
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
<foreach collection="oredCriteria" item="criteria" separator="or"> <foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid"> <if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")"> <trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion"> <foreach collection="criteria.criteria" item="criterion">
<choose> <choose>
<when test="criterion.noValue"> <when test="criterion.noValue">
and ${criterion.condition} and ${criterion.condition}
</when> </when>
<when test="criterion.singleValue"> <when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value}
</when> </when>
<when test="criterion.betweenValue"> <when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
#{listItem} separator=",">
</foreach> #{listItem}
</when> </foreach>
</choose> </when>
</choose>
</foreach>
</trim>
</if>
</foreach> </foreach>
</trim> </where>
</if> </sql>
</foreach> <sql id="Update_By_Example_Where_Clause">
</where> <where>
</sql> <foreach collection="example.oredCriteria" item="criteria" separator="or">
<sql id="Update_By_Example_Where_Clause"> <if test="criteria.valid">
<where> <trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="example.oredCriteria" item="criteria" separator="or"> <foreach collection="criteria.criteria" item="criterion">
<if test="criteria.valid"> <choose>
<trim prefix="(" prefixOverrides="and" suffix=")"> <when test="criterion.noValue">
<foreach collection="criteria.criteria" item="criterion"> and ${criterion.condition}
<choose> </when>
<when test="criterion.noValue"> <when test="criterion.singleValue">
and ${criterion.condition} and ${criterion.condition} #{criterion.value}
</when> </when>
<when test="criterion.singleValue"> <when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when> </when>
<when test="criterion.betweenValue"> <when test="criterion.listValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition}
</when> <foreach close=")" collection="criterion.value" item="listItem" open="("
<when test="criterion.listValue"> separator=",">
and ${criterion.condition} #{listItem}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> </foreach>
#{listItem} </when>
</foreach> </choose>
</when> </foreach>
</choose> </trim>
</if>
</foreach> </foreach>
</trim> </where>
</if> </sql>
</foreach> <sql id="Base_Column_List">
</where>
</sql>
<sql id="Base_Column_List">
id, name, parent_id, url, icon, type, sort, created, create_id, updated, update_id, id, name, parent_id, url, icon, type, sort, created, create_id, updated, update_id,
is_delete, extend1, extend2, extend3, extend4 is_delete, extend1, extend2, extend3, extend4
</sql> </sql>
<select id="selectByExample" parameterType="com.mashibing.webmaster.entity.SmsMenuExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.mashibing.webmaster.entity.SmsMenuExample"
select resultMap="BaseResultMap">
<if test="distinct"> select
distinct <if test="distinct">
</if> distinct
<include refid="Base_Column_List" /> </if>
from sms_menu <include refid="Base_Column_List"/>
<if test="_parameter != null"> from sms_menu
<include refid="Example_Where_Clause" /> <if test="_parameter != null">
</if> <include refid="Example_Where_Clause"/>
<if test="orderByClause != null"> </if>
order by ${orderByClause} <if test="orderByClause != null">
</if> order by ${orderByClause}
</select> </if>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> </select>
select <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<include refid="Base_Column_List" /> select
from sms_menu <include refid="Base_Column_List"/>
where id = #{id,jdbcType=INTEGER} from sms_menu
</select> where id = #{id,jdbcType=INTEGER}
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from sms_menu delete from sms_menu
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<delete id="deleteByExample" parameterType="com.mashibing.webmaster.entity.SmsMenuExample"> <delete id="deleteByExample" parameterType="com.mashibing.webmaster.entity.SmsMenuExample">
delete from sms_menu delete from sms_menu
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="com.mashibing.webmaster.entity.SmsMenu"> <insert id="insert" parameterType="com.mashibing.webmaster.entity.SmsMenu">
insert into sms_menu (id, name, parent_id, insert into sms_menu (id, name, parent_id,
url, icon, type, sort, url, icon, type, sort,
created, create_id, updated, created, create_id, updated,
@ -125,245 +128,246 @@
#{extend2,jdbcType=VARCHAR}, #{extend3,jdbcType=VARCHAR}, #{extend4,jdbcType=VARCHAR} #{extend2,jdbcType=VARCHAR}, #{extend3,jdbcType=VARCHAR}, #{extend4,jdbcType=VARCHAR}
) )
</insert> </insert>
<insert id="insertSelective" parameterType="com.mashibing.webmaster.entity.SmsMenu"> <insert id="insertSelective" parameterType="com.mashibing.webmaster.entity.SmsMenu">
insert into sms_menu insert into sms_menu
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
id, id,
</if> </if>
<if test="name != null"> <if test="name != null">
name, name,
</if> </if>
<if test="parentId != null"> <if test="parentId != null">
parent_id, parent_id,
</if> </if>
<if test="url != null"> <if test="url != null">
url, url,
</if> </if>
<if test="icon != null"> <if test="icon != null">
icon, icon,
</if> </if>
<if test="type != null"> <if test="type != null">
type, type,
</if> </if>
<if test="sort != null"> <if test="sort != null">
sort, sort,
</if> </if>
<if test="created != null"> <if test="created != null">
created, created,
</if> </if>
<if test="createId != null"> <if test="createId != null">
create_id, create_id,
</if> </if>
<if test="updated != null"> <if test="updated != null">
updated, updated,
</if> </if>
<if test="updateId != null"> <if test="updateId != null">
update_id, update_id,
</if> </if>
<if test="isDelete != null"> <if test="isDelete != null">
is_delete, is_delete,
</if> </if>
<if test="extend1 != null"> <if test="extend1 != null">
extend1, extend1,
</if> </if>
<if test="extend2 != null"> <if test="extend2 != null">
extend2, extend2,
</if> </if>
<if test="extend3 != null"> <if test="extend3 != null">
extend3, extend3,
</if> </if>
<if test="extend4 != null"> <if test="extend4 != null">
extend4, extend4,
</if> </if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
#{id,jdbcType=INTEGER}, #{id,jdbcType=INTEGER},
</if> </if>
<if test="name != null"> <if test="name != null">
#{name,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
</if> </if>
<if test="parentId != null"> <if test="parentId != null">
#{parentId,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT},
</if> </if>
<if test="url != null"> <if test="url != null">
#{url,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR},
</if> </if>
<if test="icon != null"> <if test="icon != null">
#{icon,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR},
</if> </if>
<if test="type != null"> <if test="type != null">
#{type,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
</if> </if>
<if test="sort != null"> <if test="sort != null">
#{sort,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER},
</if> </if>
<if test="created != null"> <if test="created != null">
#{created,jdbcType=TIMESTAMP}, #{created,jdbcType=TIMESTAMP},
</if> </if>
<if test="createId != null"> <if test="createId != null">
#{createId,jdbcType=BIGINT}, #{createId,jdbcType=BIGINT},
</if> </if>
<if test="updated != null"> <if test="updated != null">
#{updated,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP},
</if> </if>
<if test="updateId != null"> <if test="updateId != null">
#{updateId,jdbcType=BIGINT}, #{updateId,jdbcType=BIGINT},
</if> </if>
<if test="isDelete != null"> <if test="isDelete != null">
#{isDelete,jdbcType=TINYINT}, #{isDelete,jdbcType=TINYINT},
</if> </if>
<if test="extend1 != null"> <if test="extend1 != null">
#{extend1,jdbcType=VARCHAR}, #{extend1,jdbcType=VARCHAR},
</if> </if>
<if test="extend2 != null"> <if test="extend2 != null">
#{extend2,jdbcType=VARCHAR}, #{extend2,jdbcType=VARCHAR},
</if> </if>
<if test="extend3 != null"> <if test="extend3 != null">
#{extend3,jdbcType=VARCHAR}, #{extend3,jdbcType=VARCHAR},
</if> </if>
<if test="extend4 != null"> <if test="extend4 != null">
#{extend4,jdbcType=VARCHAR}, #{extend4,jdbcType=VARCHAR},
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.mashibing.webmaster.entity.SmsMenuExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="com.mashibing.webmaster.entity.SmsMenuExample"
select count(*) from sms_menu resultType="java.lang.Long">
<if test="_parameter != null"> select count(*) from sms_menu
<include refid="Example_Where_Clause" /> <if test="_parameter != null">
</if> <include refid="Example_Where_Clause"/>
</select> </if>
<update id="updateByExampleSelective" parameterType="map"> </select>
update sms_menu <update id="updateByExampleSelective" parameterType="map">
<set> update sms_menu
<if test="row.id != null"> <set>
id = #{row.id,jdbcType=INTEGER}, <if test="row.id != null">
</if> id = #{row.id,jdbcType=INTEGER},
<if test="row.name != null"> </if>
<if test="row.name != null">
name = #{row.name,jdbcType=VARCHAR},
</if>
<if test="row.parentId != null">
parent_id = #{row.parentId,jdbcType=BIGINT},
</if>
<if test="row.url != null">
url = #{row.url,jdbcType=VARCHAR},
</if>
<if test="row.icon != null">
icon = #{row.icon,jdbcType=VARCHAR},
</if>
<if test="row.type != null">
type = #{row.type,jdbcType=INTEGER},
</if>
<if test="row.sort != null">
sort = #{row.sort,jdbcType=INTEGER},
</if>
<if test="row.created != null">
created = #{row.created,jdbcType=TIMESTAMP},
</if>
<if test="row.createId != null">
create_id = #{row.createId,jdbcType=BIGINT},
</if>
<if test="row.updated != null">
updated = #{row.updated,jdbcType=TIMESTAMP},
</if>
<if test="row.updateId != null">
update_id = #{row.updateId,jdbcType=BIGINT},
</if>
<if test="row.isDelete != null">
is_delete = #{row.isDelete,jdbcType=TINYINT},
</if>
<if test="row.extend1 != null">
extend1 = #{row.extend1,jdbcType=VARCHAR},
</if>
<if test="row.extend2 != null">
extend2 = #{row.extend2,jdbcType=VARCHAR},
</if>
<if test="row.extend3 != null">
extend3 = #{row.extend3,jdbcType=VARCHAR},
</if>
<if test="row.extend4 != null">
extend4 = #{row.extend4,jdbcType=VARCHAR},
</if>
</set>
<if test="example != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
update sms_menu
set id = #{row.id,jdbcType=INTEGER},
name = #{row.name,jdbcType=VARCHAR}, name = #{row.name,jdbcType=VARCHAR},
</if>
<if test="row.parentId != null">
parent_id = #{row.parentId,jdbcType=BIGINT}, parent_id = #{row.parentId,jdbcType=BIGINT},
</if>
<if test="row.url != null">
url = #{row.url,jdbcType=VARCHAR}, url = #{row.url,jdbcType=VARCHAR},
</if>
<if test="row.icon != null">
icon = #{row.icon,jdbcType=VARCHAR}, icon = #{row.icon,jdbcType=VARCHAR},
</if>
<if test="row.type != null">
type = #{row.type,jdbcType=INTEGER}, type = #{row.type,jdbcType=INTEGER},
</if>
<if test="row.sort != null">
sort = #{row.sort,jdbcType=INTEGER}, sort = #{row.sort,jdbcType=INTEGER},
</if>
<if test="row.created != null">
created = #{row.created,jdbcType=TIMESTAMP}, created = #{row.created,jdbcType=TIMESTAMP},
</if>
<if test="row.createId != null">
create_id = #{row.createId,jdbcType=BIGINT}, create_id = #{row.createId,jdbcType=BIGINT},
</if>
<if test="row.updated != null">
updated = #{row.updated,jdbcType=TIMESTAMP}, updated = #{row.updated,jdbcType=TIMESTAMP},
</if>
<if test="row.updateId != null">
update_id = #{row.updateId,jdbcType=BIGINT}, update_id = #{row.updateId,jdbcType=BIGINT},
</if>
<if test="row.isDelete != null">
is_delete = #{row.isDelete,jdbcType=TINYINT}, is_delete = #{row.isDelete,jdbcType=TINYINT},
</if>
<if test="row.extend1 != null">
extend1 = #{row.extend1,jdbcType=VARCHAR}, extend1 = #{row.extend1,jdbcType=VARCHAR},
</if>
<if test="row.extend2 != null">
extend2 = #{row.extend2,jdbcType=VARCHAR}, extend2 = #{row.extend2,jdbcType=VARCHAR},
</if>
<if test="row.extend3 != null">
extend3 = #{row.extend3,jdbcType=VARCHAR}, extend3 = #{row.extend3,jdbcType=VARCHAR},
</if> extend4 = #{row.extend4,jdbcType=VARCHAR}
<if test="row.extend4 != null"> <if test="example != null">
extend4 = #{row.extend4,jdbcType=VARCHAR}, <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
</set> </update>
<if test="example != null"> <update id="updateByPrimaryKeySelective" parameterType="com.mashibing.webmaster.entity.SmsMenu">
<include refid="Update_By_Example_Where_Clause" /> update sms_menu
</if> <set>
</update> <if test="name != null">
<update id="updateByExample" parameterType="map"> name = #{name,jdbcType=VARCHAR},
update sms_menu </if>
set id = #{row.id,jdbcType=INTEGER}, <if test="parentId != null">
name = #{row.name,jdbcType=VARCHAR}, parent_id = #{parentId,jdbcType=BIGINT},
parent_id = #{row.parentId,jdbcType=BIGINT}, </if>
url = #{row.url,jdbcType=VARCHAR}, <if test="url != null">
icon = #{row.icon,jdbcType=VARCHAR}, url = #{url,jdbcType=VARCHAR},
type = #{row.type,jdbcType=INTEGER}, </if>
sort = #{row.sort,jdbcType=INTEGER}, <if test="icon != null">
created = #{row.created,jdbcType=TIMESTAMP}, icon = #{icon,jdbcType=VARCHAR},
create_id = #{row.createId,jdbcType=BIGINT}, </if>
updated = #{row.updated,jdbcType=TIMESTAMP}, <if test="type != null">
update_id = #{row.updateId,jdbcType=BIGINT}, type = #{type,jdbcType=INTEGER},
is_delete = #{row.isDelete,jdbcType=TINYINT}, </if>
extend1 = #{row.extend1,jdbcType=VARCHAR}, <if test="sort != null">
extend2 = #{row.extend2,jdbcType=VARCHAR}, sort = #{sort,jdbcType=INTEGER},
extend3 = #{row.extend3,jdbcType=VARCHAR}, </if>
extend4 = #{row.extend4,jdbcType=VARCHAR} <if test="created != null">
<if test="example != null"> created = #{created,jdbcType=TIMESTAMP},
<include refid="Update_By_Example_Where_Clause" /> </if>
</if> <if test="createId != null">
</update> create_id = #{createId,jdbcType=BIGINT},
<update id="updateByPrimaryKeySelective" parameterType="com.mashibing.webmaster.entity.SmsMenu"> </if>
update sms_menu <if test="updated != null">
<set> updated = #{updated,jdbcType=TIMESTAMP},
<if test="name != null"> </if>
name = #{name,jdbcType=VARCHAR}, <if test="updateId != null">
</if> update_id = #{updateId,jdbcType=BIGINT},
<if test="parentId != null"> </if>
parent_id = #{parentId,jdbcType=BIGINT}, <if test="isDelete != null">
</if> is_delete = #{isDelete,jdbcType=TINYINT},
<if test="url != null"> </if>
url = #{url,jdbcType=VARCHAR}, <if test="extend1 != null">
</if> extend1 = #{extend1,jdbcType=VARCHAR},
<if test="icon != null"> </if>
icon = #{icon,jdbcType=VARCHAR}, <if test="extend2 != null">
</if> extend2 = #{extend2,jdbcType=VARCHAR},
<if test="type != null"> </if>
type = #{type,jdbcType=INTEGER}, <if test="extend3 != null">
</if> extend3 = #{extend3,jdbcType=VARCHAR},
<if test="sort != null"> </if>
sort = #{sort,jdbcType=INTEGER}, <if test="extend4 != null">
</if> extend4 = #{extend4,jdbcType=VARCHAR},
<if test="created != null"> </if>
created = #{created,jdbcType=TIMESTAMP}, </set>
</if> where id = #{id,jdbcType=INTEGER}
<if test="createId != null"> </update>
create_id = #{createId,jdbcType=BIGINT}, <update id="updateByPrimaryKey" parameterType="com.mashibing.webmaster.entity.SmsMenu">
</if>
<if test="updated != null">
updated = #{updated,jdbcType=TIMESTAMP},
</if>
<if test="updateId != null">
update_id = #{updateId,jdbcType=BIGINT},
</if>
<if test="isDelete != null">
is_delete = #{isDelete,jdbcType=TINYINT},
</if>
<if test="extend1 != null">
extend1 = #{extend1,jdbcType=VARCHAR},
</if>
<if test="extend2 != null">
extend2 = #{extend2,jdbcType=VARCHAR},
</if>
<if test="extend3 != null">
extend3 = #{extend3,jdbcType=VARCHAR},
</if>
<if test="extend4 != null">
extend4 = #{extend4,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.mashibing.webmaster.entity.SmsMenu">
update sms_menu update sms_menu
set name = #{name,jdbcType=VARCHAR}, set name = #{name,jdbcType=VARCHAR},
parent_id = #{parentId,jdbcType=BIGINT}, parent_id = #{parentId,jdbcType=BIGINT},
@ -382,4 +386,23 @@
extend4 = #{extend4,jdbcType=VARCHAR} extend4 = #{extend4,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
<!-- /**-->
<!-- * 根据用户id查询当前用户的一级和二级菜单-->
<!-- * @param id-->
<!-- * @return-->
<!-- */-->
<!-- List<Map<String, Object>> findMenuByUserId(@Param("userId") Integer id)-->
<select id="findMenuByUserId" resultType="java.util.Map">
select
m.id id, m.name, m.parent_id parentId, m.url, m.icon, m.type
from
sms_menu m
inner join sms_role_menu rm on m.id = rm.menu_id
inner join sms_user_role ur on ur.role_id = rm.role_id
where
ur.user_id = 1
and m.type in (0,1)
order by m.type
</select>
</mapper> </mapper>

@ -83,10 +83,10 @@ INSERT INTO `sms_menu` VALUES ('6', '新增', '2', null, null, '2', '1000', '202
INSERT INTO `sms_menu` VALUES ('7', '修改', '2', null, null, '2', '1000', '2023-07-28 08:29:20', '1', '2023-07-28 08:29:36', '1', '0', null, null, null, null); INSERT INTO `sms_menu` VALUES ('7', '修改', '2', null, null, '2', '1000', '2023-07-28 08:29:20', '1', '2023-07-28 08:29:36', '1', '0', null, null, null, null);
INSERT INTO `sms_menu` VALUES ('8', '删除', '2', null, null, '2', '1000', '2023-07-28 08:29:34', '1', '2023-07-28 08:29:37', '1', '0', null, null, null, null); INSERT INTO `sms_menu` VALUES ('8', '删除', '2', null, null, '2', '1000', '2023-07-28 08:29:34', '1', '2023-07-28 08:29:37', '1', '0', null, null, null, null);
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_user_role` -- Table structure for `sms_user_role`
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `sys_user_role`; DROP TABLE IF EXISTS `sms_user_role`;
CREATE TABLE `sys_user_role` ( CREATE TABLE `sms_user_role` (
`user_id` bigint(11) NOT NULL COMMENT '用户id', `user_id` bigint(11) NOT NULL COMMENT '用户id',
`role_id` bigint(11) NOT NULL COMMENT '角色id', `role_id` bigint(11) NOT NULL COMMENT '角色id',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间,默认系统时间', `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间,默认系统时间',
@ -98,14 +98,14 @@ CREATE TABLE `sys_user_role` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户角色关系表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户角色关系表';
-- ---------------------------- -- ----------------------------
-- Records of sys_user_role -- Records of sms_user_role
-- ---------------------------- -- ----------------------------
INSERT INTO `sys_user_role` VALUES ('1', '1', '2023-07-28 08:25:41', '1', '2023-07-28 08:25:41', '1', '0'); INSERT INTO `sms_user_role` VALUES ('1', '1', '2023-07-28 08:25:41', '1', '2023-07-28 08:25:41', '1', '0');
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_role_menu` -- Table structure for `sms_role_menu`
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `sys_role_menu`; DROP TABLE IF EXISTS `sms_role_menu`;
CREATE TABLE `sys_role_menu` ( CREATE TABLE `sms_role_menu` (
`role_id` bigint(11) NOT NULL COMMENT '角色id', `role_id` bigint(11) NOT NULL COMMENT '角色id',
`menu_id` bigint(11) NOT NULL COMMENT '菜单id', `menu_id` bigint(11) NOT NULL COMMENT '菜单id',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间,默认系统时间', `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间,默认系统时间',
@ -117,13 +117,13 @@ CREATE TABLE `sys_role_menu` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户角色关系表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户角色关系表';
-- ---------------------------- -- ----------------------------
-- Records of sys_role_menu -- Records of sms_role_menu
-- ---------------------------- -- ----------------------------
INSERT INTO `sys_role_menu` VALUES ('1', '1', '2023-07-28 08:30:34', null, '2023-07-28 08:30:34', null, '0'); INSERT INTO `sms_role_menu` VALUES ('1', '1', '2023-07-28 08:30:34', null, '2023-07-28 08:30:34', null, '0');
INSERT INTO `sys_role_menu` VALUES ('1', '2', '2023-07-28 08:30:38', null, '2023-07-28 08:30:38', null, '0'); INSERT INTO `sms_role_menu` VALUES ('1', '2', '2023-07-28 08:30:38', null, '2023-07-28 08:30:38', null, '0');
INSERT INTO `sys_role_menu` VALUES ('1', '3', '2023-07-28 08:30:40', null, '2023-07-28 08:30:40', null, '0'); INSERT INTO `sms_role_menu` VALUES ('1', '3', '2023-07-28 08:30:40', null, '2023-07-28 08:30:40', null, '0');
INSERT INTO `sys_role_menu` VALUES ('1', '4', '2023-07-28 08:30:44', null, '2023-07-28 08:30:44', null, '0'); INSERT INTO `sms_role_menu` VALUES ('1', '4', '2023-07-28 08:30:44', null, '2023-07-28 08:30:44', null, '0');
INSERT INTO `sys_role_menu` VALUES ('1', '5', '2023-07-28 08:30:46', null, '2023-07-28 08:30:46', null, '0'); INSERT INTO `sms_role_menu` VALUES ('1', '5', '2023-07-28 08:30:46', null, '2023-07-28 08:30:46', null, '0');
INSERT INTO `sys_role_menu` VALUES ('1', '6', '2023-07-28 08:30:48', null, '2023-07-28 08:30:48', null, '0'); INSERT INTO `sms_role_menu` VALUES ('1', '6', '2023-07-28 08:30:48', null, '2023-07-28 08:30:48', null, '0');
INSERT INTO `sys_role_menu` VALUES ('1', '7', '2023-07-28 08:30:50', null, '2023-07-28 08:30:50', null, '0'); INSERT INTO `sms_role_menu` VALUES ('1', '7', '2023-07-28 08:30:50', null, '2023-07-28 08:30:50', null, '0');
INSERT INTO `sys_role_menu` VALUES ('1', '8', '2023-07-28 08:30:50', null, '2023-07-28 08:30:50', null, '0'); INSERT INTO `sms_role_menu` VALUES ('1', '8', '2023-07-28 08:30:50', null, '2023-07-28 08:30:50', null, '0');

@ -37,7 +37,7 @@
<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button"> <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
<span class="sr-only">Toggle navigation</span> <span class="sr-only">Toggle navigation</span>
</a> </a>
<div style="float:left;color:#fff;padding:15px 10px;">欢迎 {{user.username}}</div> <div style="float:left;color:#fff;padding:15px 10px;">欢迎 {{user.nickname}}</div>
<div class="navbar-custom-menu"> <div class="navbar-custom-menu">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="javascript:;" @click="updatePassword"><i class="fa fa-lock"></i> &nbsp;修改密码</a></li> <li><a href="javascript:;" @click="updatePassword"><i class="fa fa-lock"></i> &nbsp;修改密码</a></li>

@ -34,11 +34,11 @@ function getSelectedRow() {
} }
function hasPermission(permission) { function hasPermission(permission) {
if (window.parent.permissions.indexOf(permission) > -1) { // if (window.parent.permissions.indexOf(permission) > -1) {
return true; // return true;
} else { // } else {
return false; // return false;
} // }
} }

@ -43,14 +43,15 @@ var vm = new Vue({
getMenuList: function (event) { getMenuList: function (event) {
//$.getJSON("json/menu_user.json?_"+$.now(), function(r){ //$.getJSON("json/menu_user.json?_"+$.now(), function(r){
$.getJSON("sys/menu/user?_" + $.now(), function (r) { $.getJSON("sys/menu/user?_" + $.now(), function (r) {
vm.menuList = r.menuList; vm.menuList = r.data;
window.permissions = r.permissions; // 先不管这个权限信息
// window.permissions = r.permissions;
}); });
}, },
getUser: function () { getUser: function () {
//$.getJSON("json/user_info.json?_"+$.now(), function(r){ //$.getJSON("json/user_info.json?_"+$.now(), function(r){
$.getJSON("sys/user/info?_" + $.now(), function (r) { $.getJSON("sys/user/info?_" + $.now(), function (r) {
vm.user = r.user; vm.user = r.data;
}); });
}, },
updatePassword: function () { updatePassword: function () {

@ -0,0 +1,29 @@
package com.mashibing.webmaster.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SmsMenuMapperTest {
@Resource
private SmsMenuMapper menuMapper;
@Test
public void findMenuByUserId() {
List<Map<String, Object>> list = menuMapper.findMenuByUserId(1);
for (Map<String, Object> map : list) {
System.out.println(map);
}
}
}

@ -0,0 +1,33 @@
package com.mashibing.webmaster.service;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SmsMenuServiceTest {
@Autowired
private SmsMenuService menuService;
@Test
public void findUserMenu() {
List<Map<String, Object>> data = menuService.findUserMenu(1);
for (Map<String, Object> parentMenu : data) {
System.out.println(parentMenu.get("name"));
List<Map<String, Object>> sonMenuList = (List<Map<String, Object>>) parentMenu.get("list");
for (Map<String, Object> sonMenu : sonMenuList) {
System.out.println(sonMenu);
}
System.out.println("======================");
}
}
}
Loading…
Cancel
Save