提交 6c61a954 编写于 作者: cxt104926's avatar cxt104926

菜单管理

上级 02b671ed
-- stu_class 班级表
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('100000000000', '信息技术学院', '', 1, 'SE45yZijRbqGr6XzP0FC2Q', '', '11:07:29', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('100010000000', '网络工程系', '100000000000', 2, 'INIT20200908', '', '13:44:47', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('100020000000', '物联网工程系', '100000000000', 2, 'INIT20200908', '', '13:44:29', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('200000000000', '经济管理学院', '', 1, 'INIT20200908', '', '13:25:32', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('200010000000', '金融系', '200000000000', 2, 'INIT20200908', '', '13:45:58', '巴扎黑', '16:21:18', '巴扎黑');
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('200020000000', '会计学系', '200000000000', 2, 'INIT20200908', '', '13:46:10', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('300000000000', '外国语学院', '', 1, 'INIT20200908', '', '13:25:45', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('300010000000', '外语翻译系', '300000000000', 2, 'INIT20200908', '', '13:46:38', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('4ISr5_0PSfSx-otmhznqZQ', '网络一班', '100010000000', 2, 'INIT20200908', '2020', '16:14:54', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('9cfYz55YRhm--Tr1qEmSuQ', '物联网二班', '100020000000', 3, 'INIT20200908', '2020', '16:15:52', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('BwFS2b-3Q--VnW08L0Tqww', '会计学二班', '200020000000', 2, 'INIT20200908', '2020', '16:14:01', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('i4VORBYQR6GKKW6uVa7GkA', '金融班', '200010000000', 3, 'INIT20200908', '2020', '16:18:55', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('IPIFC_9nTqOJZfHOTmZnzw', '翻译班', '300010000000', 3, 'INIT20200908', '2020', '16:16:27', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('wFd6crq-RVeu8_ilZrGQHA', '会计学一班', '200020000000', 2, 'INIT20200908', '2020', '16:08:31', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('xpRlKZcqSr-fV84gwguipg', '物联网一班', '100020000000', 3, 'INIT20200908', '2020', '16:15:48', '巴扎黑', NULL, NULL);
INSERT INTO stusystem.stu_class
(id, name, pid, sign, user_id, grade, create_time, create_by, update_time, update_by)
VALUES('_dkvCK7LS0K65tPx-jLliQ', '网络二班', '100010000000', 3, 'INIT20200908', '2020', '16:15:23', '巴扎黑', NULL, NULL);
package com.stu.stusystem.controller.system;
import com.github.pagehelper.PageInfo;
import com.stu.stusystem.common.ApiResult;
import com.stu.stusystem.common.OffsetPage;
import com.stu.stusystem.model.system.Menu;
import com.stu.stusystem.service.system.MenuService;
import com.stu.stusystem.service.system.dto.MenuDTO;
import com.stu.stusystem.service.system.dto.StuClassDTO;
import com.stu.stusystem.service.system.dto.StuClassQuery;
import com.stu.stusystem.service.system.vo.MenuVO;
import com.stu.stusystem.service.system.vo.StuClassVO;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author: cxt
......@@ -13,5 +26,43 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/menu")
public class MenuController {
private MenuService menuService;
@ApiOperation("分页查询")
@GetMapping("/get")
public PageInfo<MenuVO> getMenuPage(OffsetPage query,String name) {
return this.menuService.getMenuPage(query,name);
}
@ApiOperation("修改菜单")
@PutMapping("/update")
public ApiResult<String> updateMenu(@RequestBody MenuDTO dto) {
this.menuService.updateMenu(dto);
return ApiResult.success();
}
@ApiOperation("删除菜单")
@DeleteMapping("/delete")
public ApiResult<String> deleteMenu(@RequestParam("id") String id) {
this.menuService.deleteMenu(id);
return ApiResult.success();
}
@ApiOperation("新增菜单")
@PostMapping("/add")
public ApiResult<String> saveMenu(@RequestBody MenuDTO dto) {
this.menuService.saveMenu(dto);
return ApiResult.success();
}
@ApiOperation("查询树形菜单")
@GetMapping("/get/treeMenu")
public List<Object> getTreeMenu(){
return this.menuService.getTreeMenu();
}
@Autowired
public void setMenuService(MenuService menuService) {
this.menuService = menuService;
}
}
package com.stu.stusystem.mapper.system;
import com.stu.stusystem.common.CommonMapper;
import com.stu.stusystem.model.em.TreeModel;
import com.stu.stusystem.model.system.Menu;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @author cxt
* @date 2021/3/29
*/
public interface MenuMapper extends CommonMapper<Menu> {
@Select("select id,name,pid from menu")
List<TreeModel> getTreeMenu();
}
......@@ -6,6 +6,7 @@ import com.stu.stusystem.service.system.dto.UserManagerQuery;
import com.stu.stusystem.service.system.vo.StuUserVO;
import org.apache.ibatis.annotations.Param;
import javax.annotation.Resource;
import java.util.List;
/**
......
package com.stu.stusystem.model.system;
import com.stu.stusystem.common.BaseModel;
import com.stu.stusystem.common.OffsetPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author cxt
* @date 2021/3/29
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Menu extends BaseModel {
private String id;
// 图标
private String iconImg;
// 名称
private String name;
// 页面url
private String url;
// 父级id
private String pid;
// 菜单类型(M:目录,C:菜单,B:按钮)
private String menuType;
// 是否启用
private Boolean isVisible;
// 排序
private Integer orderNum;
}
package com.stu.stusystem.service.system;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.stu.stusystem.common.ApiException;
import com.stu.stusystem.common.OffsetPage;
import com.stu.stusystem.mapper.system.MenuMapper;
import com.stu.stusystem.model.em.TreeModel;
import com.stu.stusystem.model.system.Menu;
import com.stu.stusystem.model.system.StuUser;
import com.stu.stusystem.service.system.dto.MenuDTO;
import com.stu.stusystem.service.system.vo.MenuVO;
import com.stu.stusystem.util.CopyBeanUtil;
import com.stu.stusystem.util.TreeModelUtil;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
import java.util.Date;
import java.util.List;
/**
* @author cxt
* @date 2021/3/29
*/
@Service
public class MenuService {
private MenuMapper menuMapper;
/**
* 分页查询
*/
public PageInfo<MenuVO> getMenuPage(OffsetPage query, String name) {
PageHelper.startPage(query.getPage(), query.getLimit());
Example example = new Example(Menu.class);
Example.Criteria criteria = example.createCriteria();
if (name != null) {
criteria.andEqualTo("name", name);
}
example.orderBy("create_time").desc();
List<Menu> menus = this.menuMapper.selectByExample(example);
List<MenuVO> menuVOS = CopyBeanUtil.copyList(menus, new MenuVO());
return new PageInfo<>(menuVOS);
}
/**
* 更新菜单
*/
public void updateMenu(MenuDTO dto) {
Menu menu = this.menuMapper.selectByPrimaryKey(dto.getId());
if (menu == null) {
throw new ApiException("没有找到更新资源");
}
CopyBeanUtil.copy(dto, menu);
StuUser user = (StuUser) SecurityUtils.getSubject().getPrincipal();
menu.setUpdateBy(user.getName());
menu.setCreateTime(new Date());
int i = this.menuMapper.updateByExample(menu, new Example.Builder(Menu.class)
.where(WeekendSqls.<Menu>custom().andEqualTo(Menu::getId, dto.getId())).build());
if (i != 1) {
throw new ApiException(ApiException.UPDATE_FAIL);
}
}
/**
* 删除菜单
*/
public void deleteMenu(String id) {
int i = this.menuMapper.deleteByPrimaryKey(id);
if (i != 1) {
throw new ApiException(ApiException.DELETE_FAIL);
}
}
/**
* 新增菜单
*/
public void saveMenu(MenuDTO dto) {
List<Menu> menus = this.menuMapper.selectByExample(new Example.Builder(Menu.class)
.where(WeekendSqls.<Menu>custom().andEqualTo(Menu::getName, dto.getName())).build());
if (menus.size() != 0) {
throw new ApiException("您添加的菜单已存在");
}
Menu menu = new Menu();
CopyBeanUtil.copy(dto, menu);
StuUser user = (StuUser) SecurityUtils.getSubject().getPrincipal();
menu.setCreateBy(user.getName());
menu.setCreateTime(new Date());
this.menuMapper.insert(menu);
}
/**
* 查询树形菜单
*/
public List<Object> getTreeMenu() {
List<TreeModel> treeMenu = this.menuMapper.getTreeMenu();
return TreeModelUtil.buildTreeList(treeMenu);
}
@Autowired
public void setMenuMapper(MenuMapper menuMapper) {
this.menuMapper = menuMapper;
}
}
package com.stu.stusystem.service.system.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author cxt
* @date 2021/3/29
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MenuDTO {
private String id;
@ApiModelProperty("图标")
private String iconImg;
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("页面url")
private String url;
@ApiModelProperty("父级id")
private String pid;
@ApiModelProperty("菜单类型(M:目录,C:菜单,B:按钮)")
private String menuType;
@ApiModelProperty("是否启用")
private Boolean isVisible;
@ApiModelProperty("排序")
private Integer orderNum;
}
package com.stu.stusystem.service.system.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author cxt
* @date 2021/3/29
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MenuVO {
private String id;
@ApiModelProperty("图标")
private String iconImg;
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("页面url")
private String url;
@ApiModelProperty("父级id")
private String pid;
@ApiModelProperty("菜单类型(M:目录,C:菜单,B:按钮)")
private String menuType;
@ApiModelProperty("是否启用")
private Boolean isVisible;
@ApiModelProperty("排序")
private Integer orderNum;
}
......@@ -12,12 +12,12 @@
Added the entity menu.
-->
<changeSet id="2021-03" author="cxt">
<createTable tableName="stu_class" remarks="菜单表">
<createTable tableName="menu" remarks="菜单表">
<column name="id" type="varchar(22)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="icon_img" type="tinyint(1)" remarks="图标">
<column name="icon_img" type="varchar(50)" remarks="图标">
<constraints nullable="true"/>
</column>
......@@ -33,45 +33,17 @@
<constraints nullable="true"/>
</column>
<column name="menu_type" type="tinyint(1)" remarks="菜单类型(M:目录,C:菜单,B:按钮)">
<column name="menu_type" type="varchar(1)" remarks="菜单类型(M:目录,C:菜单,B:按钮)">
<constraints nullable="false"/>
</column>
<column name="is_use" type="tinyint(1)" remarks="是否启用">
<column name="is_visible" type="tinyint(1)" remarks="是否启用">
<constraints nullable="false"/>
</column>
/** 显示顺序 */
private String orderNum;
/** 菜单URL */
private String url;
/** 打开方式(menuItem页签 menuBlank新窗口) */
private String target;
/** 类型(M目录 C菜单 F按钮) */
private String menuType;
/** 菜单状态(0显示 1隐藏) */
private String visible;
/** 是否刷新(0刷新 1不刷新) */
private String isRefresh;
/** 权限字符串 */
private String perms;
/** 菜单图标 */
private String icon;
<column name="order_num" type="int(11)" remarks="排序">
<constraints nullable="false"/>
</column>
<column name="create_time" type="time" remarks="创建时间">
<constraints nullable="false"/>
......
......@@ -7,5 +7,6 @@
<include file="classpath:config/liquibase/20200907_creat_table_StuUser.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/20200914_creat_table_log.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/20210323_creat_table_stuClass.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/20210329_creat_table_menu.xml" relativeToChangelogFile="false"/>
</databaseChangeLog>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册