修改代码生成模板.
This commit is contained in:
@@ -43,4 +43,6 @@ public interface ErrorMessage {
|
||||
|
||||
String USER_ABSENT = "用户不存在";
|
||||
|
||||
String UNABLE_OPERATE_ADMIN_ROLE = "无法操作管理员账号";
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.orion.lang.constant.Const;
|
||||
import com.orion.lang.utils.ext.yml.YmlExt;
|
||||
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.ops.module.infra.enums.RoleStatusEnum;
|
||||
import com.orion.ops.module.infra.enums.UserStatusEnum;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.io.File;
|
||||
@@ -38,12 +40,12 @@ public class CodeGenerator {
|
||||
String module = "infra";
|
||||
// 生成的表
|
||||
GenTable[] tables = {
|
||||
// new GenTable("system_user", "用户", "user")
|
||||
// .vue("user", "user")
|
||||
// .enums(UserStatusEnum.class),
|
||||
// new GenTable("system_role", "角色", "role")
|
||||
// .vue("user", "role")
|
||||
// .enums(RoleStatusEnum.class),
|
||||
new GenTable("system_user", "用户", "user")
|
||||
.vue("user", "user")
|
||||
.enums(UserStatusEnum.class),
|
||||
new GenTable("system_role", "角色", "role")
|
||||
.vue("user", "role")
|
||||
.enums(RoleStatusEnum.class),
|
||||
// new GenTable("system_menu", "菜单", "menu"),
|
||||
};
|
||||
// jdbc 配置 - 使用配置文件
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
import useVisible from '@/hooks/visible';
|
||||
import formRules from '../types/form.rules';
|
||||
import { create${vue.featureFirstUpper}, update${vue.featureFirstUpper} } from '@/api/${vue.module}/${vue.feature}';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
|
||||
const { visible, setVisible } = useVisible();
|
||||
const { loading, setLoading } = useLoading();
|
||||
@@ -111,10 +112,12 @@
|
||||
if (isAddHandle.value) {
|
||||
// 新增
|
||||
await create${vue.featureFirstUpper}(formModel as any);
|
||||
Message.success('创建成功');
|
||||
emits('added');
|
||||
} else {
|
||||
// 修改
|
||||
await update${vue.featureFirstUpper}(formModel as any);
|
||||
Message.success('修改成功');
|
||||
emits('updated');
|
||||
}
|
||||
// 清空
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
@reset="fetchTableData">
|
||||
#foreach($field in ${table.fields})
|
||||
<!-- $field.comment -->
|
||||
<a-form-item field="${field.propertyName}" label="${field.comment}" label-col-flex="60px">
|
||||
<a-form-item field="${field.propertyName}" label="${field.comment}" label-col-flex="50px">
|
||||
#if("$field.propertyType" == "Integer" || "$field.propertyType" == "Long")
|
||||
<a-input-number v-model="formModel.${field.propertyName}" placeholder="请输入${field.comment}" allow-clear/>
|
||||
#elseif("$field.propertyType" == "Date")
|
||||
@@ -26,9 +26,11 @@
|
||||
<!-- 表格 -->
|
||||
<a-card class="general-card table-card">
|
||||
<template #title>
|
||||
<!-- 左侧标题 -->
|
||||
<div class="table-title">
|
||||
${table.comment}列表
|
||||
</div>
|
||||
<!-- 右侧按钮 -->
|
||||
<div class="table-bar-handle">
|
||||
<a-space>
|
||||
<!-- 新增 -->
|
||||
@@ -87,9 +89,10 @@
|
||||
position="left"
|
||||
type="warning"
|
||||
@ok="deleteRow(record)">
|
||||
<a-button type="text" size="mini"
|
||||
status="danger"
|
||||
v-permission="['${package.ModuleName}:${typeHyphen}:delete']">
|
||||
<a-button v-permission="['${package.ModuleName}:${typeHyphen}:delete']"
|
||||
type="text"
|
||||
size="mini"
|
||||
status="danger">
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<${vue.feature}-table ref="table"
|
||||
@openAdd="() => modal.openAdd()"
|
||||
@openUpdate="(e) => modal.openUpdate(e)" />
|
||||
<!-- 添加修改框 -->
|
||||
<!-- 添加修改模态框 -->
|
||||
<${vue.feature}-form-modal ref="modal"
|
||||
@added="() => table.addedCallback()"
|
||||
@updated="() => table.updatedCallback()" />
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: '${vue.module}${vue.featureAllUpper}'
|
||||
name: '${vue.module}${vue.featureFirstUpper}'
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -19,13 +19,14 @@ const columns = [
|
||||
tooltip: true,
|
||||
#elseif(${field.propertyType} == 'Date')
|
||||
render: ({ record }) => {
|
||||
return dateFormat(new Date(record.${field.propertyName}));
|
||||
return record.${field.propertyName} && dateFormat(new Date(record.${field.propertyName}));
|
||||
},
|
||||
#end
|
||||
}, #end#end{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
slotName: 'createTime',
|
||||
align: 'center',
|
||||
render: ({ record }) => {
|
||||
return dateFormat(new Date(record.createTime));
|
||||
},
|
||||
@@ -33,8 +34,9 @@ const columns = [
|
||||
title: '修改时间',
|
||||
dataIndex: 'updateTime',
|
||||
slotName: 'updateTime',
|
||||
align: 'center',
|
||||
render: ({ record }) => {
|
||||
return dateFormat(new Date(record.createTime));
|
||||
return dateFormat(new Date(record.updateTime));
|
||||
},
|
||||
}, {
|
||||
title: '创建人',
|
||||
|
||||
@@ -37,9 +37,6 @@ public class SystemMenuController {
|
||||
@Resource
|
||||
private SystemMenuService systemMenuService;
|
||||
|
||||
@Resource
|
||||
private SystemRoleMenuService systemRoleMenuService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建菜单")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-menu:create')")
|
||||
@@ -56,18 +53,11 @@ public class SystemMenuController {
|
||||
|
||||
@PutMapping("/update-status")
|
||||
@Operation(summary = "通过 id 级联更新菜单状态")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-menu:update')")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-menu:update-status')")
|
||||
public Integer updateSystemMenuStatus(@RequestBody SystemMenuUpdateStatusRequest request) {
|
||||
return systemMenuService.updateSystemMenuStatus(request);
|
||||
}
|
||||
|
||||
@PostMapping("/bind")
|
||||
@Operation(summary = "绑定角色菜单")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-menu:bind')")
|
||||
public Integer bindRoleMenu(@RequestBody SystemMenuBindRequest request) {
|
||||
return systemRoleMenuService.bindRoleMenu(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "通过 id 查询菜单")
|
||||
|
||||
@@ -4,11 +4,13 @@ import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||
import com.orion.ops.framework.common.constant.IgnoreLogMode;
|
||||
import com.orion.ops.module.infra.entity.request.menu.SystemRoleBindMenuRequest;
|
||||
import com.orion.ops.module.infra.entity.request.role.SystemRoleCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.role.SystemRoleQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.request.role.SystemRoleStatusRequest;
|
||||
import com.orion.ops.module.infra.entity.request.role.SystemRoleUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.SystemRoleVO;
|
||||
import com.orion.ops.module.infra.service.SystemRoleMenuService;
|
||||
import com.orion.ops.module.infra.service.SystemRoleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -40,6 +42,9 @@ public class SystemRoleController {
|
||||
@Resource
|
||||
private SystemRoleService systemRoleService;
|
||||
|
||||
@Resource
|
||||
private SystemRoleMenuService systemRoleMenuService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建角色")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-role:create')")
|
||||
@@ -86,6 +91,13 @@ public class SystemRoleController {
|
||||
return systemRoleService.getSystemRolePage(request);
|
||||
}
|
||||
|
||||
@GetMapping("/get-menu-id")
|
||||
@Operation(summary = "获取角色菜单id")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-role:query')")
|
||||
public List<Long> getRoleMenuIdList(@RequestParam("roleId") Long roleId) {
|
||||
return systemRoleMenuService.getRoleMenuIdList(roleId);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "通过 id 删除角色")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@@ -94,5 +106,12 @@ public class SystemRoleController {
|
||||
return systemRoleService.deleteSystemRole(id);
|
||||
}
|
||||
|
||||
@PutMapping("/bind")
|
||||
@Operation(summary = "绑定角色菜单")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-role:bind-menu')")
|
||||
public Integer bindRoleMenu(@RequestBody SystemRoleBindMenuRequest request) {
|
||||
return systemRoleMenuService.bindRoleMenu(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单 绑定角色请求对象
|
||||
* 角色 绑定菜单请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -22,8 +22,8 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "SystemMenuBindRequest", description = "菜单 绑定角色请求对象")
|
||||
public class SystemMenuBindRequest implements Serializable {
|
||||
@Schema(name = "SystemRoleBindMenuRequest", description = "角色 绑定菜单请求对象")
|
||||
public class SystemRoleBindMenuRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "roleId")
|
||||
@@ -31,6 +31,6 @@ public class SystemMenuBindRequest implements Serializable {
|
||||
|
||||
@NotEmpty
|
||||
@Schema(description = "菜单id集合")
|
||||
private List<Long> idList;
|
||||
private List<Long> menuIdList;
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.orion.ops.module.infra.service;
|
||||
|
||||
import com.orion.ops.module.infra.entity.request.menu.SystemMenuBindRequest;
|
||||
import com.orion.ops.module.infra.entity.request.menu.SystemRoleBindMenuRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色菜单关联 服务类
|
||||
@@ -17,6 +19,14 @@ public interface SystemRoleMenuService {
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer bindRoleMenu(SystemMenuBindRequest request);
|
||||
Integer bindRoleMenu(SystemRoleBindMenuRequest request);
|
||||
|
||||
/**
|
||||
* 获取角色菜单 id
|
||||
*
|
||||
* @param roleId roleId
|
||||
* @return menuIdList
|
||||
*/
|
||||
List<Long> getRoleMenuIdList(Long roleId);
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.orion.ops.module.infra.entity.domain.SystemMenuDO;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemRoleDO;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemRoleMenuDO;
|
||||
import com.orion.ops.module.infra.entity.dto.SystemMenuCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.menu.SystemMenuBindRequest;
|
||||
import com.orion.ops.module.infra.entity.request.menu.SystemRoleBindMenuRequest;
|
||||
import com.orion.ops.module.infra.service.PermissionService;
|
||||
import com.orion.ops.module.infra.service.SystemRoleMenuService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -52,16 +52,21 @@ public class SystemRoleMenuServiceImpl implements SystemRoleMenuService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer bindRoleMenu(SystemMenuBindRequest request) {
|
||||
public Integer bindRoleMenu(SystemRoleBindMenuRequest request) {
|
||||
Long roleId = request.getRoleId();
|
||||
List<Long> menuIdList = request.getIdList();
|
||||
List<Long> menuIdList = request.getMenuIdList();
|
||||
// 检查角色是否存在
|
||||
SystemRoleDO role = Valid.notNull(systemRoleDAO.selectById(roleId), ErrorMessage.ROLE_ABSENT);
|
||||
// 查询菜单列表
|
||||
List<SystemMenuDO> menuList = systemMenuDAO.selectBatchIds(menuIdList);
|
||||
List<SystemMenuDO> menuList;
|
||||
if (menuIdList.isEmpty()) {
|
||||
menuList = Lists.empty();
|
||||
} else {
|
||||
menuList = systemMenuDAO.selectBatchIds(menuIdList);
|
||||
if (menuIdList.size() != menuList.size()) {
|
||||
throw ErrorCode.CONFLICT.exception();
|
||||
}
|
||||
}
|
||||
// 查询角色菜单
|
||||
List<Long> beforeMenuIdList = systemRoleMenuDAO.of()
|
||||
.wrapper(Conditions.eq(SystemRoleMenuDO::getRoleId, roleId))
|
||||
@@ -106,4 +111,12 @@ public class SystemRoleMenuServiceImpl implements SystemRoleMenuService {
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getRoleMenuIdList(Long roleId) {
|
||||
return systemRoleMenuDAO.selectList(Conditions.eq(SystemRoleMenuDO::getRoleId, roleId))
|
||||
.stream()
|
||||
.map(SystemRoleMenuDO::getMenuId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.orion.ops.module.infra.convert.SystemRoleConvert;
|
||||
import com.orion.ops.module.infra.dao.SystemRoleDAO;
|
||||
import com.orion.ops.module.infra.dao.SystemRoleMenuDAO;
|
||||
import com.orion.ops.module.infra.dao.SystemUserRoleDAO;
|
||||
import com.orion.ops.module.infra.define.RoleDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemRoleDO;
|
||||
import com.orion.ops.module.infra.entity.request.role.SystemRoleCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.role.SystemRoleQueryRequest;
|
||||
@@ -95,6 +96,8 @@ public class SystemRoleServiceImpl implements SystemRoleService {
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
SystemRoleDO record = systemRoleDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 检查是否为管理员账号
|
||||
Valid.isTrue(!RoleDefine.isAdmin(record.getCode()), ErrorMessage.UNABLE_OPERATE_ADMIN_ROLE);
|
||||
// 转换
|
||||
SystemRoleDO updateRecord = SystemRoleConvert.MAPPER.to(request);
|
||||
Integer status = updateRecord.getStatus();
|
||||
@@ -135,8 +138,7 @@ public class SystemRoleServiceImpl implements SystemRoleService {
|
||||
.eq(SystemRoleDO::getId, request.getId())
|
||||
.like(SystemRoleDO::getName, request.getName())
|
||||
.eq(SystemRoleDO::getCode, request.getCode())
|
||||
.eq(SystemRoleDO::getStatus, request.getStatus())
|
||||
.orderByDesc(SystemRoleDO::getId);
|
||||
.eq(SystemRoleDO::getStatus, request.getStatus());
|
||||
// 查询
|
||||
return systemRoleDAO.of()
|
||||
.wrapper(wrapper)
|
||||
@@ -151,6 +153,8 @@ public class SystemRoleServiceImpl implements SystemRoleService {
|
||||
SystemRoleDO record = systemRoleDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
String code = record.getCode();
|
||||
// 检查是否为管理员账号
|
||||
Valid.isTrue(!RoleDefine.isAdmin(code), ErrorMessage.UNABLE_OPERATE_ADMIN_ROLE);
|
||||
// 删除角色
|
||||
int effect = systemRoleDAO.deleteById(id);
|
||||
log.info("SystemRoleService-deleteSystemRole id: {}, effect: {}", id, effect);
|
||||
|
||||
Reference in New Issue
Block a user