Skip to content

Commit

Permalink
Merge pull request #63 from Jzow/master
Browse files Browse the repository at this point in the history
Add menu data and api and view data object
  • Loading branch information
Jzow authored Sep 30, 2023
2 parents f305b38 + f652e4c commit cc64342
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 29 deletions.
22 changes: 22 additions & 0 deletions api/src/main/java/com/wansensoft/api/system/SysMenuController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.wansensoft.api.system

import com.wansensoft.dto.menu.AddOrUpdateMenuDTO
import com.wansensoft.service.system.KtSysMenuService
import com.wansensoft.utils.response.Response
import org.springframework.web.bind.annotation.*


@RestController
@RequestMapping("/menu")
class SysMenuController(private val menuService: KtSysMenuService) {

@PostMapping("addOrUpdate")
fun addOrUpdate(@RequestBody addOrUpdateDeptDTO: AddOrUpdateMenuDTO?): Response<String> {
return menuService.addOrSaveMenu(addOrUpdateDeptDTO)
}

@PostMapping("delete")
fun deleteMenu(@RequestParam(value = "id", required = true) id: Int?): Response<String> {
return menuService.deleteMenu(id)
}
}
33 changes: 33 additions & 0 deletions domain/src/main/java/com/wansensoft/dto/menu/AddOrUpdateMenuDTO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.wansensoft.dto.menu

import lombok.Data

@Data
class AddOrUpdateMenuDTO {

val id : Int? = null

val menuType : Int? = null

val name : String? = null

val title: String? = null

val parentId: Int? = null

val sort: Int? = null

val icon: String? = null

val path: String? = null

val component: String? = null

val status: Int? = null

val blank: Int? = null

val ignoreKeepAlive: Int? = null

val hideMenu: Int? = null
}
25 changes: 16 additions & 9 deletions domain/src/main/java/com/wansensoft/entities/system/SysMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.io.Serial;
Expand All @@ -30,6 +32,7 @@
*/
@TableName("sys_menu")
@Data
@EqualsAndHashCode(callSuper = false)
public class SysMenu implements Serializable {

@Serial
Expand Down Expand Up @@ -93,7 +96,7 @@ public class SysMenu implements Serializable {
* 状态(0-启用,1-停用)
*/
@TableField("status")
private Boolean status;
private Integer status;

/**
* 图标
Expand All @@ -105,43 +108,47 @@ public class SysMenu implements Serializable {
* 隐藏路由不在菜单显示
*/
@TableField("hide_menu")
private Boolean hideMenu;
private Integer hideMenu;


@TableField("blank")
private Integer blank;

/**
* 隐藏该路由在面包屑上面的显示
*/
@TableField("hide_breadcrumb")
private Boolean hideBreadcrumb;
private Integer hideBreadcrumb;

/**
* 是否忽略KeepAlive缓存
*/
@TableField("ignore_keep_alive")
private Boolean ignoreKeepAlive;
private Integer ignoreKeepAlive;

/**
* 隐藏路由不在标签页显示
*/
@TableField("hide_tab")
private Boolean hideTab;
private Integer hideTab;

/**
* 如果该路由会携带参数,且需要在tab页上面显示。则需要设置为true
*/
@TableField("carry_param")
private Boolean carryParam;
private Integer carryParam;

/**
* 隐藏所有子菜单
*/
@TableField("hide_children_in_menu")
private Boolean hideChildrenInMenu;
private Integer hideChildrenInMenu;

/**
* 是否固定标签
*/
@TableField("affix")
private Boolean affix;
private Integer affix;

/**
* 内嵌iframe的地址
Expand Down Expand Up @@ -183,5 +190,5 @@ public class SysMenu implements Serializable {
* 删除标记,0未删除,1删除
*/
@TableField("delete_flag")
private Boolean deleteFlag;
private Integer deleteFlag;
}
18 changes: 16 additions & 2 deletions domain/src/main/java/com/wansensoft/vo/MenuVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
Expand All @@ -33,6 +36,8 @@ public class MenuVO {

private String name;

private String title;

private String path;

private String component;
Expand All @@ -43,9 +48,18 @@ public class MenuVO {

private Integer menuType;

private String type;

private String redirect;

private Integer status;

private Integer hideMenu;

private Integer blank;

private Integer ignoreKeepAlive;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime;

private JSONObject meta;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansensoft.api.system;
package com.wansensoft.service.system

import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.service.IService
import com.wansensoft.dto.menu.AddOrUpdateMenuDTO
import com.wansensoft.entities.system.SysMenu
import com.wansensoft.utils.response.Response

import org.springframework.web.bind.annotation.RestController;
interface KtSysMenuService : IService<SysMenu>{

/**
* <p>
* 功能模块表 前端控制器
* </p>
*
* @author James Zow
* @since 2023-09-05
*/
@RestController
@RequestMapping("/sys-menu")
public class SysMenuController {
fun addOrSaveMenu(addOrUpdateMenuDTO: AddOrUpdateMenuDTO?): Response<String>

}
fun deleteMenu(id: Int?): Response<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansensoft.service.system.impl

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.wansensoft.dto.menu.AddOrUpdateMenuDTO
import com.wansensoft.entities.role.SysRoleMenuRel
import com.wansensoft.entities.system.SysMenu
import com.wansensoft.mappers.system.SysMenuMapper
import com.wansensoft.service.role.KtSysRoleMenuRelService
import com.wansensoft.service.system.KtSysMenuService
import com.wansensoft.utils.constants.CommonConstants
import com.wansensoft.utils.enums.BaseCodeEnum
import com.wansensoft.utils.enums.MenuCodeEnum
import com.wansensoft.utils.response.Response
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime

@Service
open class KtSysMenuServiceImpl(
private val roleMenuRelService: KtSysRoleMenuRelService,
) :ServiceImpl<SysMenuMapper, SysMenu>(), KtSysMenuService {

@Transactional
override fun addOrSaveMenu(addOrUpdateMenuDTO: AddOrUpdateMenuDTO?): Response<String> {
addOrUpdateMenuDTO?.let { dto ->
if (dto.id == null) {
val menu = SysMenu().apply{
name = dto.name
title = dto.title
icon = dto.icon
parentId = dto.parentId
menuType = dto.menuType
path = dto.path
component = dto.component
status = dto.status
sort = dto.sort
hideMenu = dto.hideMenu
ignoreKeepAlive = dto.ignoreKeepAlive
blank = dto.blank
createTime = LocalDateTime.now()
}
val saveResult = save(menu);
if (!saveResult) {
return Response.responseMsg(MenuCodeEnum.ADD_MENU_ERROR)
} else {
// Add this menu to the administrator by default
val menuIds = StringBuilder()
menuIds.append(roleMenuRelService.getById(0).menuId)
menuIds.append("[" + menu.id + "]")
roleMenuRelService.lambdaUpdate()
.eq(SysRoleMenuRel::getRoleId, 0)
.set(SysRoleMenuRel::getMenuId, menuIds.toString())
.update()
return Response.responseMsg(MenuCodeEnum.ADD_MENU_SUCCESS)
}
} else {
// update
val updateResult = lambdaUpdate().apply {
eq(SysMenu::getId, dto.id)
set(SysMenu::getName, dto.name)
set(SysMenu::getTitle, dto.title)
set(SysMenu::getIcon, dto.icon)
set(SysMenu::getParentId, dto.parentId)
set(SysMenu::getMenuType, dto.menuType)
set(SysMenu::getPath, dto.path)
set(SysMenu::getComponent, dto.component)
set(SysMenu::getStatus, dto.status)
set(SysMenu::getSort, dto.sort)
set(SysMenu::getHideMenu, dto.hideMenu)
set(SysMenu::getIgnoreKeepAlive, dto.ignoreKeepAlive)
set(SysMenu::getBlank, dto.blank)
set(SysMenu::getUpdateTime, LocalDateTime.now())
}.update()

if (!updateResult) {
return Response.responseMsg(MenuCodeEnum.UPDATE_MENU_ERROR)
} else {
return Response.responseMsg(MenuCodeEnum.UPDATE_MENU_SUCCESS)
}
}
}
return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL)
}

override fun deleteMenu(id: Int?): Response<String> {
id?.let {
val deleteResult = lambdaUpdate()
.eq(SysMenu::getId, id)
.set(SysMenu::getDeleteFlag, CommonConstants.DELETED)
.update()

return if (deleteResult) {
Response.responseMsg(MenuCodeEnum.DELETE_MENU_SUCCESS)
} else {
Response.responseMsg(MenuCodeEnum.DELETE_MENU_ERROR)
}
}
return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wansensoft.service.user.ISysUserRoleRelService;
import com.wansensoft.service.user.ISysUserService;
import com.wansensoft.utils.constants.CommonConstants;
import com.wansensoft.utils.response.Response;
import com.wansensoft.vo.MenuVO;
import org.aspectj.util.FileUtil;
Expand Down Expand Up @@ -92,20 +93,30 @@ public Response<JSONObject> menuList() {
.distinct()
.collect(Collectors.toList());

var menus = menuMapper.selectBatchIds(distinctNumbers);
var menus = lambdaQuery()
.in(SysMenu::getId, distinctNumbers)
.eq(SysMenu::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();

if(!menus.isEmpty()) {
menus.forEach(menu -> {
// JSON Assembly
var meta = getMetaJsonObject(menu);
var menuVo = MenuVO.builder()
.id(menu.getId())
.name(menu.getName())
.title(menu.getTitle())
.menuType(menu.getMenuType())
.path(menu.getPath())
.component(menu.getComponent())
.icon(menu.getIcon())
.sort(menu.getSort())
.redirect(menu.getRedirect())
.createTime(menu.getCreateTime())
.status(menu.getStatus())
.hideMenu(menu.getHideMenu())
.blank(menu.getBlank())
.ignoreKeepAlive(menu.getIgnoreKeepAlive())
.meta(meta)
.build();
if(menu.getParentId() != null) {
Expand All @@ -129,11 +140,10 @@ public Response<JSONObject> menuList() {
*/
private static JSONObject getMetaJsonObject(SysMenu menu) {
var meta = new JSONObject();
// 这里的title和menu里的title一样
meta.put("title", menu.getTitle());
meta.put("icon", menu.getIcon());
meta.put("hideMenu", menu.getHideMenu());
meta.put("hideBreadcrumb", menu.getHideBreadcrumb());
meta.put("ignoreKeepAlive", menu.getIgnoreKeepAlive());
meta.put("hideTab", menu.getHideTab());
meta.put("carryParam", menu.getCarryParam());
meta.put("hideChildrenInMenu", menu.getHideChildrenInMenu());
Expand Down
Loading

0 comments on commit cc64342

Please sign in to comment.