修改代码生成模板.

This commit is contained in:
lijiahang
2023-08-15 18:36:04 +08:00
parent 4facfc66cd
commit bc163d786a
12 changed files with 87 additions and 39 deletions

View File

@@ -43,4 +43,6 @@ public interface ErrorMessage {
String USER_ABSENT = "用户不存在"; String USER_ABSENT = "用户不存在";
String UNABLE_OPERATE_ADMIN_ROLE = "无法操作管理员账号";
} }

View File

@@ -12,6 +12,8 @@ import com.orion.lang.constant.Const;
import com.orion.lang.utils.ext.yml.YmlExt; import com.orion.lang.utils.ext.yml.YmlExt;
import com.orion.ops.framework.mybatis.core.domain.BaseDO; import com.orion.ops.framework.mybatis.core.domain.BaseDO;
import com.orion.ops.framework.mybatis.core.mapper.IMapper; 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 org.apache.ibatis.annotations.Mapper;
import java.io.File; import java.io.File;
@@ -38,12 +40,12 @@ public class CodeGenerator {
String module = "infra"; String module = "infra";
// 生成的表 // 生成的表
GenTable[] tables = { GenTable[] tables = {
// new GenTable("system_user", "用户", "user") new GenTable("system_user", "用户", "user")
// .vue("user", "user") .vue("user", "user")
// .enums(UserStatusEnum.class), .enums(UserStatusEnum.class),
// new GenTable("system_role", "角色", "role") new GenTable("system_role", "角色", "role")
// .vue("user", "role") .vue("user", "role")
// .enums(RoleStatusEnum.class), .enums(RoleStatusEnum.class),
// new GenTable("system_menu", "菜单", "menu"), // new GenTable("system_menu", "菜单", "menu"),
}; };
// jdbc 配置 - 使用配置文件 // jdbc 配置 - 使用配置文件

View File

@@ -54,6 +54,7 @@
import useVisible from '@/hooks/visible'; import useVisible from '@/hooks/visible';
import formRules from '../types/form.rules'; import formRules from '../types/form.rules';
import { create${vue.featureFirstUpper}, update${vue.featureFirstUpper} } from '@/api/${vue.module}/${vue.feature}'; 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 { visible, setVisible } = useVisible();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();
@@ -111,10 +112,12 @@
if (isAddHandle.value) { if (isAddHandle.value) {
// 新增 // 新增
await create${vue.featureFirstUpper}(formModel as any); await create${vue.featureFirstUpper}(formModel as any);
Message.success('创建成功');
emits('added'); emits('added');
} else { } else {
// 修改 // 修改
await update${vue.featureFirstUpper}(formModel as any); await update${vue.featureFirstUpper}(formModel as any);
Message.success('修改成功');
emits('updated'); emits('updated');
} }
// 清空 // 清空

View File

@@ -7,7 +7,7 @@
@reset="fetchTableData"> @reset="fetchTableData">
#foreach($field in ${table.fields}) #foreach($field in ${table.fields})
<!-- $field.comment --> <!-- $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") #if("$field.propertyType" == "Integer" || "$field.propertyType" == "Long")
<a-input-number v-model="formModel.${field.propertyName}" placeholder="请输入${field.comment}" allow-clear/> <a-input-number v-model="formModel.${field.propertyName}" placeholder="请输入${field.comment}" allow-clear/>
#elseif("$field.propertyType" == "Date") #elseif("$field.propertyType" == "Date")
@@ -26,9 +26,11 @@
<!-- 表格 --> <!-- 表格 -->
<a-card class="general-card table-card"> <a-card class="general-card table-card">
<template #title> <template #title>
<!-- 左侧标题 -->
<div class="table-title"> <div class="table-title">
${table.comment}列表 ${table.comment}列表
</div> </div>
<!-- 右侧按钮 -->
<div class="table-bar-handle"> <div class="table-bar-handle">
<a-space> <a-space>
<!-- 新增 --> <!-- 新增 -->
@@ -87,9 +89,10 @@
position="left" position="left"
type="warning" type="warning"
@ok="deleteRow(record)"> @ok="deleteRow(record)">
<a-button type="text" size="mini" <a-button v-permission="['${package.ModuleName}:${typeHyphen}:delete']"
status="danger" type="text"
v-permission="['${package.ModuleName}:${typeHyphen}:delete']"> size="mini"
status="danger">
删除 删除
</a-button> </a-button>
</a-popconfirm> </a-popconfirm>

View File

@@ -4,7 +4,7 @@
<${vue.feature}-table ref="table" <${vue.feature}-table ref="table"
@openAdd="() => modal.openAdd()" @openAdd="() => modal.openAdd()"
@openUpdate="(e) => modal.openUpdate(e)" /> @openUpdate="(e) => modal.openUpdate(e)" />
<!-- 添加修改框 --> <!-- 添加修改模态框 -->
<${vue.feature}-form-modal ref="modal" <${vue.feature}-form-modal ref="modal"
@added="() => table.addedCallback()" @added="() => table.addedCallback()"
@updated="() => table.updatedCallback()" /> @updated="() => table.updatedCallback()" />
@@ -13,7 +13,7 @@
<script lang="ts"> <script lang="ts">
export default { export default {
name: '${vue.module}${vue.featureAllUpper}' name: '${vue.module}${vue.featureFirstUpper}'
}; };
</script> </script>

View File

@@ -19,13 +19,14 @@ const columns = [
tooltip: true, tooltip: true,
#elseif(${field.propertyType} == 'Date') #elseif(${field.propertyType} == 'Date')
render: ({ record }) => { render: ({ record }) => {
return dateFormat(new Date(record.${field.propertyName})); return record.${field.propertyName} && dateFormat(new Date(record.${field.propertyName}));
}, },
#end #end
}, #end#end{ }, #end#end{
title: '创建时间', title: '创建时间',
dataIndex: 'createTime', dataIndex: 'createTime',
slotName: 'createTime', slotName: 'createTime',
align: 'center',
render: ({ record }) => { render: ({ record }) => {
return dateFormat(new Date(record.createTime)); return dateFormat(new Date(record.createTime));
}, },
@@ -33,8 +34,9 @@ const columns = [
title: '修改时间', title: '修改时间',
dataIndex: 'updateTime', dataIndex: 'updateTime',
slotName: 'updateTime', slotName: 'updateTime',
align: 'center',
render: ({ record }) => { render: ({ record }) => {
return dateFormat(new Date(record.createTime)); return dateFormat(new Date(record.updateTime));
}, },
}, { }, {
title: '创建人', title: '创建人',

View File

@@ -37,9 +37,6 @@ public class SystemMenuController {
@Resource @Resource
private SystemMenuService systemMenuService; private SystemMenuService systemMenuService;
@Resource
private SystemRoleMenuService systemRoleMenuService;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建菜单") @Operation(summary = "创建菜单")
@PreAuthorize("@ss.hasPermission('infra:system-menu:create')") @PreAuthorize("@ss.hasPermission('infra:system-menu:create')")
@@ -56,18 +53,11 @@ public class SystemMenuController {
@PutMapping("/update-status") @PutMapping("/update-status")
@Operation(summary = "通过 id 级联更新菜单状态") @Operation(summary = "通过 id 级联更新菜单状态")
@PreAuthorize("@ss.hasPermission('infra:system-menu:update')") @PreAuthorize("@ss.hasPermission('infra:system-menu:update-status')")
public Integer updateSystemMenuStatus(@RequestBody SystemMenuUpdateStatusRequest request) { public Integer updateSystemMenuStatus(@RequestBody SystemMenuUpdateStatusRequest request) {
return systemMenuService.updateSystemMenuStatus(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) @IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/get") @GetMapping("/get")
@Operation(summary = "通过 id 查询菜单") @Operation(summary = "通过 id 查询菜单")

View File

@@ -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.IgnoreLog;
import com.orion.ops.framework.common.annotation.RestWrapper; import com.orion.ops.framework.common.annotation.RestWrapper;
import com.orion.ops.framework.common.constant.IgnoreLogMode; 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.SystemRoleCreateRequest;
import com.orion.ops.module.infra.entity.request.role.SystemRoleQueryRequest; 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.SystemRoleStatusRequest;
import com.orion.ops.module.infra.entity.request.role.SystemRoleUpdateRequest; 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.entity.vo.SystemRoleVO;
import com.orion.ops.module.infra.service.SystemRoleMenuService;
import com.orion.ops.module.infra.service.SystemRoleService; import com.orion.ops.module.infra.service.SystemRoleService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
@@ -40,6 +42,9 @@ public class SystemRoleController {
@Resource @Resource
private SystemRoleService systemRoleService; private SystemRoleService systemRoleService;
@Resource
private SystemRoleMenuService systemRoleMenuService;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建角色") @Operation(summary = "创建角色")
@PreAuthorize("@ss.hasPermission('infra:system-role:create')") @PreAuthorize("@ss.hasPermission('infra:system-role:create')")
@@ -86,6 +91,13 @@ public class SystemRoleController {
return systemRoleService.getSystemRolePage(request); 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") @DeleteMapping("/delete")
@Operation(summary = "通过 id 删除角色") @Operation(summary = "通过 id 删除角色")
@Parameter(name = "id", description = "id", required = true) @Parameter(name = "id", description = "id", required = true)
@@ -94,5 +106,12 @@ public class SystemRoleController {
return systemRoleService.deleteSystemRole(id); 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);
}
} }

View File

@@ -12,7 +12,7 @@ import java.io.Serializable;
import java.util.List; import java.util.List;
/** /**
* 菜单 绑定角色请求对象 * 角色 绑定菜单请求对象
* *
* @author Jiahang Li * @author Jiahang Li
* @version 1.0.0 * @version 1.0.0
@@ -22,8 +22,8 @@ import java.util.List;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "SystemMenuBindRequest", description = "菜单 绑定角色请求对象") @Schema(name = "SystemRoleBindMenuRequest", description = "角色 绑定菜单请求对象")
public class SystemMenuBindRequest implements Serializable { public class SystemRoleBindMenuRequest implements Serializable {
@NotNull @NotNull
@Schema(description = "roleId") @Schema(description = "roleId")
@@ -31,6 +31,6 @@ public class SystemMenuBindRequest implements Serializable {
@NotEmpty @NotEmpty
@Schema(description = "菜单id集合") @Schema(description = "菜单id集合")
private List<Long> idList; private List<Long> menuIdList;
} }

View File

@@ -1,6 +1,8 @@
package com.orion.ops.module.infra.service; 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 * @param request request
* @return effect * @return effect
*/ */
Integer bindRoleMenu(SystemMenuBindRequest request); Integer bindRoleMenu(SystemRoleBindMenuRequest request);
/**
* 获取角色菜单 id
*
* @param roleId roleId
* @return menuIdList
*/
List<Long> getRoleMenuIdList(Long roleId);
} }

View File

@@ -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.SystemRoleDO;
import com.orion.ops.module.infra.entity.domain.SystemRoleMenuDO; 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.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.PermissionService;
import com.orion.ops.module.infra.service.SystemRoleMenuService; import com.orion.ops.module.infra.service.SystemRoleMenuService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -52,15 +52,20 @@ public class SystemRoleMenuServiceImpl implements SystemRoleMenuService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Integer bindRoleMenu(SystemMenuBindRequest request) { public Integer bindRoleMenu(SystemRoleBindMenuRequest request) {
Long roleId = request.getRoleId(); Long roleId = request.getRoleId();
List<Long> menuIdList = request.getIdList(); List<Long> menuIdList = request.getMenuIdList();
// 检查角色是否存在 // 检查角色是否存在
SystemRoleDO role = Valid.notNull(systemRoleDAO.selectById(roleId), ErrorMessage.ROLE_ABSENT); SystemRoleDO role = Valid.notNull(systemRoleDAO.selectById(roleId), ErrorMessage.ROLE_ABSENT);
// 查询菜单列表 // 查询菜单列表
List<SystemMenuDO> menuList = systemMenuDAO.selectBatchIds(menuIdList); List<SystemMenuDO> menuList;
if (menuIdList.size() != menuList.size()) { if (menuIdList.isEmpty()) {
throw ErrorCode.CONFLICT.exception(); menuList = Lists.empty();
} else {
menuList = systemMenuDAO.selectBatchIds(menuIdList);
if (menuIdList.size() != menuList.size()) {
throw ErrorCode.CONFLICT.exception();
}
} }
// 查询角色菜单 // 查询角色菜单
List<Long> beforeMenuIdList = systemRoleMenuDAO.of() List<Long> beforeMenuIdList = systemRoleMenuDAO.of()
@@ -106,4 +111,12 @@ public class SystemRoleMenuServiceImpl implements SystemRoleMenuService {
return effect; return effect;
} }
@Override
public List<Long> getRoleMenuIdList(Long roleId) {
return systemRoleMenuDAO.selectList(Conditions.eq(SystemRoleMenuDO::getRoleId, roleId))
.stream()
.map(SystemRoleMenuDO::getMenuId)
.collect(Collectors.toList());
}
} }

View File

@@ -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.SystemRoleDAO;
import com.orion.ops.module.infra.dao.SystemRoleMenuDAO; import com.orion.ops.module.infra.dao.SystemRoleMenuDAO;
import com.orion.ops.module.infra.dao.SystemUserRoleDAO; 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.domain.SystemRoleDO;
import com.orion.ops.module.infra.entity.request.role.SystemRoleCreateRequest; 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.SystemRoleQueryRequest;
@@ -95,6 +96,8 @@ public class SystemRoleServiceImpl implements SystemRoleService {
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING); Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
SystemRoleDO record = systemRoleDAO.selectById(id); SystemRoleDO record = systemRoleDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT); Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 检查是否为管理员账号
Valid.isTrue(!RoleDefine.isAdmin(record.getCode()), ErrorMessage.UNABLE_OPERATE_ADMIN_ROLE);
// 转换 // 转换
SystemRoleDO updateRecord = SystemRoleConvert.MAPPER.to(request); SystemRoleDO updateRecord = SystemRoleConvert.MAPPER.to(request);
Integer status = updateRecord.getStatus(); Integer status = updateRecord.getStatus();
@@ -135,8 +138,7 @@ public class SystemRoleServiceImpl implements SystemRoleService {
.eq(SystemRoleDO::getId, request.getId()) .eq(SystemRoleDO::getId, request.getId())
.like(SystemRoleDO::getName, request.getName()) .like(SystemRoleDO::getName, request.getName())
.eq(SystemRoleDO::getCode, request.getCode()) .eq(SystemRoleDO::getCode, request.getCode())
.eq(SystemRoleDO::getStatus, request.getStatus()) .eq(SystemRoleDO::getStatus, request.getStatus());
.orderByDesc(SystemRoleDO::getId);
// 查询 // 查询
return systemRoleDAO.of() return systemRoleDAO.of()
.wrapper(wrapper) .wrapper(wrapper)
@@ -151,6 +153,8 @@ public class SystemRoleServiceImpl implements SystemRoleService {
SystemRoleDO record = systemRoleDAO.selectById(id); SystemRoleDO record = systemRoleDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT); Valid.notNull(record, ErrorMessage.DATA_ABSENT);
String code = record.getCode(); String code = record.getCode();
// 检查是否为管理员账号
Valid.isTrue(!RoleDefine.isAdmin(code), ErrorMessage.UNABLE_OPERATE_ADMIN_ROLE);
// 删除角色 // 删除角色
int effect = systemRoleDAO.deleteById(id); int effect = systemRoleDAO.deleteById(id);
log.info("SystemRoleService-deleteSystemRole id: {}, effect: {}", id, effect); log.info("SystemRoleService-deleteSystemRole id: {}, effect: {}", id, effect);