-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from Jzow/master
Add menu data and api and view data object
- Loading branch information
Showing
9 changed files
with
260 additions
and
29 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
api/src/main/java/com/wansensoft/api/system/SysMenuController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
domain/src/main/java/com/wansensoft/dto/menu/AddOrUpdateMenuDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
service/src/main/java/com/wansensoft/service/system/impl/KtSysMenuServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.