Skip to content

Commit

Permalink
some code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
MactavishCui committed Dec 31, 2024
1 parent 87fa9be commit 5fb14a6
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
package org.dinky.service.impl;

import org.dinky.assertion.Asserts;
import org.dinky.data.constant.BaseConstant;
import org.dinky.data.dto.ApprovalDTO;
import org.dinky.data.dto.TaskDTO;
import org.dinky.data.enums.ApprovalEvent;
import org.dinky.data.enums.ApprovalStatus;
import org.dinky.data.enums.JobLifeCycle;
import org.dinky.data.enums.Status;
import org.dinky.data.exception.BusException;
import org.dinky.data.exception.DinkyException;
import org.dinky.data.model.Approval;
import org.dinky.data.model.SystemConfiguration;
Expand Down Expand Up @@ -146,9 +149,9 @@ public List<User> getTaskReviewerList(Integer tenantId) {
.in(Role::getRoleCode, reviewerRoles)
.eq(Role::getTenantId, tenantId));
// get super admin
User superAdmin = userService.getById(1);
User superAdmin = userService.getById(BaseConstant.ADMIN_ID);
Map<Integer, User> userMap = new HashMap<>();
userMap.put(1, superAdmin);
userMap.put(BaseConstant.ADMIN_ID, superAdmin);
for (Role role : roles) {
List<User> userList = roleService.getUserListByRoleId(role.getId());
for (User user : userList) {
Expand All @@ -174,7 +177,7 @@ public void handleApproveEvent(ApprovalEvent event, ApprovalDTO approvalDTO) {
}
// only one approval in process check
if (event.equals(ApprovalEvent.SUBMIT) && alreadyHaveOneInProcess(approval.getTaskId())) {
throw new DinkyException("Already have a approval in process");
throw new BusException(Status.SYS_APPROVAL_DUPLICATE_APPROVAL_IN_PROCESS);
}
// status machine execute
if (!validPreStatusMap.get(event).contains(ApprovalStatus.fromValue(approval.getStatus()))) {
Expand Down Expand Up @@ -216,7 +219,7 @@ private boolean checkApprovalPermission(Approval approval, ApprovalEvent event)
*/
private boolean isValidReviewer(Integer reviewer) {
// super admin
if (reviewer == 1) {
if (reviewer == BaseConstant.ADMIN_ID) {
return true;
}
List<Role> roleList = roleService.getRoleByUserId(reviewer);
Expand Down
2 changes: 1 addition & 1 deletion dinky-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spring:
# If you use pgsql database, please configure pgsql database connection information in application-postgresql.yml
# If you use the h2 database, please configure the h2 database connection information in application-h2.yml,
# note: the h2 database is only for experience use, and the related data that has been created cannot be migrated, please use it with caution
active: ${DB_ACTIVE:h2} #[h2,mysql,pgsql]
active: ${DB_ACTIVE:h2} #[h2,mysql,postgresql]
include:
- jmx
- flyway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS dinky_approval
-- ----------------------------
INSERT INTO `dinky_sys_menu` (id, parent_id, name, path, component, perms, icon, type, display, order_num, create_time,
update_time, note)
VALUES (176, 4, '审批发布', '/auth/approval', './AuthCenter/Approval', 'auth:approval', 'AuditOutlined', 'C', 0, 169,
VALUES (176, 4, '审批发布', '/auth/approval', './AuthCenter/Approval', 'auth:approval:operate', 'AuditOutlined', 'C', 0, 169,
'2024-12-10 12:13:00', '2024-12-10 12:13:00', NULL);

insert into `dinky_sys_menu` (`id`, `parent_id`, `name`, `path`, `component`, `perms`, `icon`, `type`, `display`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

SET NAMES Utf8mb4;
SET
FOREIGN_KEY_CHECKS = 0;
FOREIGN_KEY_CHECKS = 0;


-- ----------------------------
Expand All @@ -29,79 +29,35 @@ FOREIGN_KEY_CHECKS = 0;

CREATE TABLE IF NOT EXISTS `dinky_approval`
(
`id`
int
(
11
) NOT NULL AUTO_INCREMENT COMMENT 'id',
`task_id` int
(
11
) NOT NULL COMMENT 'task id',
`tenant_id` int
(
11
) NOT NULL default 1 COMMENT 'tenant id',
`previous_task_version` int
(
11
) DEFAULT NULL COMMENT 'previous version of task',
`current_task_version` int
(
11
) NOT NULL COMMENT 'current version to be reviewed of task',
`status` varchar
(
50
) CHARACTER SET Utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'approval status',
`submitter` int
(
11
) NOT NULL COMMENT 'submitter user id',
`submitter_comment` text DEFAULT NULL COMMENT 'submitter comment',
`reviewer` int
(
11
) DEFAULT NULL COMMENT 'reviewer user id',
`reviewer_comment` text DEFAULT NULL COMMENT 'reviewer comment',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
`update_tIme` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'update time',
PRIMARY KEY
(
`id`
)
USING BTREE,
INDEX `task_id_current_version_union_idx`
(
`task_id`,
`current_task_version`
)
USING BTREE,
INDEX `submitter_tenant_id_union_idx`
(
`submitter`,
`tenant_id`
)
USING BTREE,
INDEX `reviewer_tenant_id_union_idx`
(
`reviewer`,
`tenant_id`
)
USING BTREE
) ENGINE = INNODB
AUTO_INCREMENT = 2
CHARACTER SET = Utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = 'approval'
ROW_FORMAT = Dynamic;
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
`task_id` int(11) NOT NULL COMMENT 'task id',
`tenant_id` int(11) NOT NULL default 1 COMMENT 'tenant id',
`previous_task_version` int(11) DEFAULT NULL COMMENT 'previous version of task',
`current_task_version` int(11) NOT NULL COMMENT 'current version to be reviewed of task',
`status` varchar(50) CHARACTER SET Utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'approval status',
`submitter` int(11) NOT NULL COMMENT 'submitter user id',
`submitter_comment` text DEFAULT NULL COMMENT 'submitter comment',
`reviewer` int(11) DEFAULT NULL COMMENT 'reviewer user id',
`reviewer_comment` text DEFAULT NULL COMMENT 'reviewer comment',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
`update_tIme` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'update time',
PRIMARY KEY (`id`) USING BTREE,
INDEX `task_id_current_version_union_idx` (`task_id`, `current_task_version`) USING BTREE,
INDEX `submitter_tenant_id_union_idx` (`submitter`, `tenant_id`) USING BTREE,
INDEX `reviewer_tenant_id_union_idx` (`reviewer`, `tenant_id`) USING BTREE
) ENGINE = INNODB
AUTO_INCREMENT = 2
CHARACTER SET = Utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = 'approval'
ROW_FORMAT = Dynamic;

-- ----------------------------
-- approval menu
-- ----------------------------

INSERT INTO `dinky_sys_menu` (`id`, `parent_id`, `name`, `path`, `component`, `perms`, `icon`, `type`, `display`,
`order_num`, `create_time`, `update_time`, `note`)
VALUES (176, 4, '审批发布', '/auth/approval', './AuthCenter/Approval', 'auth:approval', 'AuditOutlined', 'C', 0, 169,
VALUES (176, 4, '审批发布', '/auth/approval', './AuthCenter/Approval', 'auth:approval:operate', 'AuditOutlined', 'C', 0, 169,
'2024-12-10 12:13:00', '2024-12-10 12:13:00', null);

insert into `dinky_sys_menu` (`id`, `parent_id`, `name`, `path`, `component`, `perms`, `icon`, `type`, `display`,
Expand All @@ -115,4 +71,4 @@ values (178, 177, '编辑', '/settings/globalsetting/approval/edit', null, 'sett
'EditOutlined', 'F', 0, 171, '2024-12-30 23:45:30', '2024-12-30 23:45:30', null);

SET
FOREIGN_KEY_CHECKS = 1;
FOREIGN_KEY_CHECKS = 1;
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS tenant_id_reviewer_union_idx ON public.dinky_a

INSERT INTO public.dinky_sys_menu(id, parent_id, name, path, component, perms, icon, type, display, order_num,
create_time, update_time, note)
VALUES (176, 4, '审批发布', '/auth/approval', './AuthCenter/Approval', 'auth:approval', 'AuditOutlined', 'C', 0, 169,
VALUES (176, 4, '审批发布', '/auth/approval', './AuthCenter/Approval', 'auth:approval:operate', 'AuditOutlined', 'C', 0, 169,
'2024-12-10 12:13:00', '2024-12-10 12:13:00', null);

insert into `dinky_sys_menu` (`id`, `parent_id`, `name`, `path`, `component`, `perms`, `icon`, `type`, `display`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ public class PermissionConstants {
// 查看用户列表
public static final String AUTH_ROLE_VIEW_USER_LIST = "auth:role:viewUser";

/**
* auth approval
*/
public static final String AUTH_APPROVAL = "auth:approval";

/**
* Row Permissions
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public enum Status {
SYS_APPROVAL_SETTINGS_TASK_REVIEWER_ROLES(210, "sys.approval.settings.taskReviewerRoles"),
SYS_APPROVAL_SETTINGS_TASK_REVIEWER_ROLES_NOTE(211, "sys.approval.settings.taskReviewerRoles.note"),
SYS_APPROVAL_TASK_NOT_APPROVED(212, "sys.approval.taskNotApproved"),
;
SYS_APPROVAL_DUPLICATE_APPROVAL_IN_PROCESS(213, "sys.approval.duplicateInProcess");
private final int code;
private final String key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,5 @@ sys.approval.settings.enforceCrossReview=Enforce Cross Review
sys.approval.settings.enforceCrossReview.note=Submitter of an approval are not allowed to be reviewer at the same time when this option is enabled.
sys.approval.settings.taskReviewerRoles=Reviewer Roles
sys.approval.settings.taskReviewerRoles.note=Roles who can review tasks, different roles should be divided by comma. For example: SuperAdmin,Reviewer
sys.approval.taskNotApproved=Current task is not published or published version is not approved, please try again after task being published and approved
sys.approval.taskNotApproved=Current task is not published or published version is not approved, please try again after task being published and approved
sys.approval.duplicateInProcess=Already have an approval in process, please do not submit again
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,4 @@ sys.approval.settings.enforceCrossReview.note=开启强制交叉审核后,不
sys.approval.settings.taskReviewerRoles=具有审批权限的角色名称
sys.approval.settings.taskReviewerRoles.note=具有审批权限的角色名称,多个角色用英文逗号隔开,例如:SuperAdmin,Reviewer
sys.approval.taskNotApproved=当前作业未发布或发布版本未通过审核,不允许运行,请在任务发布且发布版本通过审核后重试

sys.approval.duplicateInProcess=存在仍在进行的审批流程,请勿重复提交
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const ApprovalTable: React.FC<UserFormProps> = (props) => {
setApprovalListState((prevState) => ({...prevState, loading: false}));
};

const handleApprovalOperation = (operation: OperationType, entity: ApprovalBasicInfo) => {
const handleOperationButtonClick = (operation: OperationType, entity: ApprovalBasicInfo) => {
setActiveApprovalState((prevState) => ({...prevState, activeId: entity.id}));
switch (operation) {
case OperationType.SUBMIT:
Expand Down Expand Up @@ -117,13 +117,13 @@ const ApprovalTable: React.FC<UserFormProps> = (props) => {
const handleWithdraw = async (entity: ApprovalBasicInfo) => {
await executeAndCallbackRefresh(async () => {
await handleOption(API_CONSTANTS.APPROVAL_WITHDRAW, l('approval.operation.withdraw'), entity);
})
});
};

const handleCancel = async (entity: ApprovalBasicInfo) => {
await executeAndCallbackRefresh(async () => {
await handleOption(API_CONSTANTS.APPROVAL_CANCEL, l('approval.operation.cancel'), entity);
})
});
};

const queryApproval = async (params, sorter, filter: any) => {
Expand All @@ -139,8 +139,7 @@ const ApprovalTable: React.FC<UserFormProps> = (props) => {
submitterName: userMap?.get(approval.submitter),
reviewerName: userMap?.get(approval.reviewer)
})
})
console.log(convertedQueryRes)
});
return {...queryRes, data: convertedQueryRes};
}

Expand Down Expand Up @@ -171,7 +170,7 @@ const ApprovalTable: React.FC<UserFormProps> = (props) => {
})
}

const handleApprovalEvent = async (record) => {
const handleApprovalSubmit = async (record) => {
await executeAndCallbackRefresh(async () => {
switch (operationState.operationType) {
case OperationType.SUBMIT:
Expand Down Expand Up @@ -203,7 +202,7 @@ const ApprovalTable: React.FC<UserFormProps> = (props) => {
size={'small'}
type={'primary'}
onClick={() => {
handleApprovalOperation(OperationType.SUBMIT, entity);
handleOperationButtonClick(OperationType.SUBMIT, entity);
}}
>
{l('approval.operation.submit')}
Expand All @@ -228,7 +227,7 @@ const ApprovalTable: React.FC<UserFormProps> = (props) => {
size={'small'}
type={'primary'}
onClick={() => {
handleApprovalOperation(OperationType.APPROVE, entity);
handleOperationButtonClick(OperationType.APPROVE, entity);
}}
>
{l('approval.operation.approve')}
Expand All @@ -239,7 +238,7 @@ const ApprovalTable: React.FC<UserFormProps> = (props) => {
size={'small'}
type={'primary'}
onClick={() => {
handleApprovalOperation(OperationType.REJECT, entity);
handleOperationButtonClick(OperationType.REJECT, entity);
}}
danger
>
Expand Down Expand Up @@ -389,7 +388,7 @@ const ApprovalTable: React.FC<UserFormProps> = (props) => {
title={operationState.operationDesc}
activeId={activeApprovalState.activeId}
operationType={operationState.operationType}
handleSubmit={handleApprovalEvent}
handleSubmit={handleApprovalSubmit}
/>
<TaskInfoModal
open={activeApprovalState.taskInfoOpen}
Expand Down
10 changes: 5 additions & 5 deletions dinky-web/src/pages/AuthCenter/Approval/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*
*/

import React, {useState} from "react";
import {Alert, Space} from "antd";
import {l} from "@/utils/intl";
import React, { useState } from "react";
import { Alert, Space } from "antd";
import { l } from "@/utils/intl";
import useHookRequest from "@/hooks/useHookRequest";
import {getAllConfig} from "@/pages/Metrics/service";
import { getAllConfig } from "@/pages/Metrics/service";
import SlowlyAppear from "@/components/Animation/SlowlyAppear";
import {PageContainer, ProCard} from "@ant-design/pro-components";
import { PageContainer, ProCard } from "@ant-design/pro-components";
import ApprovalTable from "@/pages/AuthCenter/Approval/components/ApprovalTable";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import { CenterTab, DataStudioState } from '@/pages/DataStudio/model';
import { Button, Col, Divider, Flex, Row, Skeleton, TabsProps } from 'antd';
import '../index.less';
import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
import { getValueFromLocalStorage, registerEditorKeyBindingAndAction } from '@/utils/function';
import { registerEditorKeyBindingAndAction } from '@/utils/function';
import { Monaco } from '@monaco-editor/react';
import { Panel, PanelGroup } from 'react-resizable-panels';
import {
ApartmentOutlined, AuditOutlined,
ApartmentOutlined,
AuditOutlined,
BugOutlined,
CaretRightOutlined,
ClearOutlined,
Expand Down

0 comments on commit 5fb14a6

Please sign in to comment.