From b16dba4ef11dd602b10d47c05a28e591c98d2f54 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Wed, 8 Jan 2025 15:41:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20=E5=A2=9E=E5=8A=A0=E5=AE=A1?= =?UTF-8?q?=E6=89=B9=E5=BF=AB=E7=85=A7=E7=9A=84=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gringotts-frontend/components/constants.js | 6 + gringotts-frontend/pages/index/tab-check.js | 61 +++++--- .../domain/base/service/CheckingService.java | 2 + .../controller/CheckOrderController.java | 7 + .../domain/service/AuthenticationService.java | 26 +--- .../domain/service/ConfirmationService.java | 42 +++--- .../domain/service/DataResourceService.java | 21 +-- .../web/domain/service/WareService.java | 9 +- .../gringotts/web/helper/AmisHelper.java | 134 ++++++++++++++++++ .../gringotts/web/helper/EntityHelper.java | 7 +- 10 files changed, 229 insertions(+), 86 deletions(-) create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/helper/AmisHelper.java diff --git a/gringotts-frontend/components/constants.js b/gringotts-frontend/components/constants.js index efa067d..422d33a 100644 --- a/gringotts-frontend/components/constants.js +++ b/gringotts-frontend/components/constants.js @@ -270,6 +270,12 @@ export const checkOverMapping = [ mappingItem('已办结', 'COMPLETED', 'bg-success'), ] +export const checkActionMapping = [ + mappingItem('同意', 'APPROVE', 'bg-green-500'), + mappingItem('驳回', 'REJECT', 'bg-red-500'), + mappingItem('撤回', 'TERMINAL', 'bg-blue-500'), +] + function api(method, url) { return { method: method, diff --git a/gringotts-frontend/pages/index/tab-check.js b/gringotts-frontend/pages/index/tab-check.js index ae4e96a..22f2085 100644 --- a/gringotts-frontend/pages/index/tab-check.js +++ b/gringotts-frontend/pages/index/tab-check.js @@ -1,16 +1,49 @@ import { apiGet, + checkActionMapping, checkOverMapping, checkTypeMapping, crudCommonOptions, mappingField, operationField, + readOnlyDialogOptions, stringField, timeField, } from "../../components/constants.js"; import {authenticationDetailDialog, confirmationDetailDialog} from "../../components/permission/dialog-permission.js"; import {wareDetailDialog} from "../../components/ware/dialog-ware.js"; +function detailDialog() { + return { + actionType: 'dialog', + dialog: { + title: '详情', + size: 'md', + ...readOnlyDialogOptions(), + body: [ + { + type: 'amis', + name: 'parameters.snapshot', + }, + {type: 'divider'}, + { + type: 'crud', + api: apiGet('${base}/check_order/history/${instanceId}'), + ...crudCommonOptions(), + headerToolbar: [ + 'reload', + ], + columns: [ + mappingField('action', '类型', checkActionMapping), + stringField('comment', '描述'), + timeField('createdTime', '操作时间'), + ] + } + ] + } + } +} + export function tabCheck() { return [ { @@ -30,6 +63,13 @@ export function tabCheck() { timeField('modifiedTime', '最后修改时间'), stringField('modifiedUsername', '最后操作人', 100), operationField('操作', undefined, [ + { + visibleOn: "${state === 'COMPLETED'}", + type: 'action', + label: '查看', + level: 'link', + ...detailDialog(), + }, { visibleOn: "${type === 'CONFIRMATION' && state === 'RUNNING'}", type: 'action', @@ -57,13 +97,6 @@ export function tabCheck() { ], ), }, - { - visibleOn: "${type === 'CONFIRMATION' && state !== NORMAL}", - type: 'action', - label: '查看', - level: 'link', - ...confirmationDetailDialog('parameters.confirmationId'), - }, { visibleOn: "${type === 'AUTHENTICATION' && state === 'RUNNING'}", type: 'action', @@ -91,13 +124,6 @@ export function tabCheck() { ], ), }, - { - visibleOn: "${type === 'AUTHENTICATION' && state !== NORMAL}", - type: 'action', - label: '查看', - level: 'link', - ...authenticationDetailDialog('parameters.authenticationId'), - }, { visibleOn: "${type === 'WARE' && state === 'RUNNING'}", type: 'action', @@ -125,13 +151,6 @@ export function tabCheck() { ], ), }, - { - visibleOn: "${type === 'WARE' && state !== NORMAL}", - type: 'action', - label: '查看', - level: 'link', - ...wareDetailDialog('parameters.wareId'), - }, ]), ], }, diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java index 1aa0adb..0bd1337 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java @@ -19,4 +19,6 @@ public abstract class CheckingService extends abstract public void submit(Long id) throws Exception; abstract public void retract(Long id) throws Exception; + + abstract protected Object archive(ENTITY entity); } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/CheckOrderController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/CheckOrderController.java index cbf2b8f..0e7d048 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/CheckOrderController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/CheckOrderController.java @@ -5,10 +5,12 @@ import com.eshore.gringotts.web.domain.base.controller.ListController; import com.eshore.gringotts.web.domain.base.controller.query.Query; import com.eshore.gringotts.web.domain.entity.User; import com.eshore.gringotts.web.domain.service.UserService; +import com.lanyuanxiaoyao.flowable.core.model.FlowableHistory; import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance; import com.lanyuanxiaoyao.flowable.core.model.FlowableNode; import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager; import java.time.LocalDateTime; +import java.util.List; import lombok.Data; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -78,6 +80,11 @@ public class CheckOrderController implements ListController> history(@PathVariable String instanceId) { + return AmisResponse.responseSuccess(flowableManager.listHistories(instanceId)); + } + @SneakyThrows private ListItem toListItem(FlowableInstance instance) { FlowableNode node = flowableManager.getNode(instance.getCurrentNodeId()); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/AuthenticationService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/AuthenticationService.java index ea27759..0df448c 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/AuthenticationService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/AuthenticationService.java @@ -5,7 +5,6 @@ import cn.hutool.core.util.ObjectUtil; import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity; import com.eshore.gringotts.web.domain.base.service.CheckingService; import com.eshore.gringotts.web.domain.entity.Authentication; -import com.eshore.gringotts.web.domain.entity.Authentication_; import com.eshore.gringotts.web.domain.entity.Confirmation; import com.eshore.gringotts.web.domain.entity.User; import com.eshore.gringotts.web.domain.flowable.CheckRoleAssessor; @@ -18,14 +17,9 @@ import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata; import com.lanyuanxiaoyao.flowable.core.model.FlowableNode; import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager; import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; import lombok.extern.slf4j.Slf4j; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.list.ImmutableList; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; @@ -68,17 +62,6 @@ public class AuthenticationService extends CheckingService { flowableManager.create(userCheckNode, roleCheckNode); } - @Override - protected ImmutableList listPredicate(Root root, CriteriaQuery query, CriteriaBuilder builder) { - User loginUser = userService.currentLoginUser(); - if (User.isAdministrator(loginUser)) { - return Lists.immutable.empty(); - } - return Lists.immutable.of(builder.or( - builder.equal(root.get(Authentication_.createdUser), loginUser) - )); - } - @Override public Long save(Authentication entity) { if (ObjectUtil.isNull(entity.getId()) && authenticationRepository.findOne( @@ -97,7 +80,7 @@ public class AuthenticationService extends CheckingService { } @Override - public void submit(Long id) throws Exception { + public void submit(Long id) { User user = userService.currentLoginUser(); Authentication authentication = detailOrThrow(id); String instanceId = flowableManager.start( @@ -116,11 +99,16 @@ public class AuthenticationService extends CheckingService { } @Override - public void retract(Long id) throws Exception { + public void retract(Long id) { Authentication authentication = detailOrThrow(id); flowableManager.terminal(authentication.getFlowableInstanceId()); } + @Override + protected Object archive(Authentication entity) { + return ""; + } + public static final class AuthenticationDuplicatedException extends RuntimeException { public AuthenticationDuplicatedException() { super("数据资源已绑定该账号的授权申请,无法再次申请"); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/ConfirmationService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/ConfirmationService.java index 6c9ed59..b78f95f 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/ConfirmationService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/ConfirmationService.java @@ -4,10 +4,11 @@ import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import com.eshore.gringotts.web.domain.base.service.CheckingService; import com.eshore.gringotts.web.domain.entity.Confirmation; -import com.eshore.gringotts.web.domain.entity.Confirmation_; +import com.eshore.gringotts.web.domain.entity.DataResource; import com.eshore.gringotts.web.domain.entity.User; import com.eshore.gringotts.web.domain.flowable.CheckRoleAssessor; import com.eshore.gringotts.web.domain.repository.ConfirmationRepository; +import com.eshore.gringotts.web.helper.AmisHelper; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction; import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance; import com.lanyuanxiaoyao.flowable.core.model.FlowableListener; @@ -15,13 +16,8 @@ import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata; import com.lanyuanxiaoyao.flowable.core.model.FlowableNode; import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager; import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; import lombok.extern.slf4j.Slf4j; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.ImmutableList; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; @@ -53,24 +49,15 @@ public class ConfirmationService extends CheckingService { } @Override - protected ImmutableList listPredicate(Root root, CriteriaQuery query, CriteriaBuilder builder) { - User loginUser = userService.currentLoginUser(); - if (User.isAdministrator(loginUser)) { - return Lists.immutable.empty(); - } - return Lists.immutable.of(builder.or( - builder.equal(root.get(Confirmation_.createdUser), loginUser) - )); - } - - @Override - public void submit(Long id) throws Exception { + public void submit(Long id) { + Confirmation confirmation = detailOrThrow(id); User user = userService.currentLoginUser(); String instanceId = flowableManager.start( CONFIRMATION_FLOW_ID, MapUtil.builder() .put("confirmationId", id) .put("type", "CONFIRMATION") + .put("snapshot", archive(confirmation)) .put("createdUsername", user.getUsername()) .put("modifiedUsername", user.getUsername()) .build(), @@ -81,11 +68,28 @@ public class ConfirmationService extends CheckingService { } @Override - public void retract(Long id) throws Exception { + public void retract(Long id) { Confirmation confirmation = detailOrThrow(id); flowableManager.terminal(confirmation.getFlowableInstanceId()); } + @Override + protected Object archive(Confirmation entity) { + DataResource resource = entity.getTarget(); + return AmisHelper.wrapper( + AmisHelper.property( + AmisHelper.propertyItem("资源名称", resource.getName(), 3), + AmisHelper.propertyItem("资源描述", resource.getDescription(), 3) + ), + AmisHelper.divider(), + AmisHelper.property(resource.getType()), + AmisHelper.divider(), + AmisHelper.property(resource.getFormat()), + AmisHelper.divider(), + AmisHelper.property(entity) + ); + } + @Override public Long save(Confirmation entity) { if (ObjectUtil.isNull(entity.getId()) && confirmationRepository.existsByTarget_Id(entity.getTarget().getId())) { diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/DataResourceService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/DataResourceService.java index 2b9a3d3..278be71 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/DataResourceService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/DataResourceService.java @@ -14,7 +14,6 @@ import com.eshore.gringotts.web.domain.entity.type.ResourceType; import com.eshore.gringotts.web.domain.repository.DataResourceRepository; import com.eshore.gringotts.web.domain.repository.ResourceFormatRepository; import com.eshore.gringotts.web.domain.repository.ResourceTypeRepository; -import com.eshore.gringotts.web.helper.EntityHelper; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -56,26 +55,8 @@ public class DataResourceService extends LogicDeleteService { return Lists.immutable.empty(); } - Subquery confirmationSubquery = query.subquery(Confirmation.class); - Root confirmationRoot = confirmationSubquery.from(Confirmation.class); - confirmationSubquery.select(confirmationRoot) - .where( - builder.equal(confirmationRoot.get(Confirmation_.target), root), - EntityHelper.checkNeededEntityPrediction(confirmationRoot, builder, loginUser) - ); - - Subquery authenticationSubquery = query.subquery(Authentication.class); - Root authenticationRoot = authenticationSubquery.from(Authentication.class); - authenticationSubquery.select(authenticationRoot) - .where( - builder.equal(authenticationRoot.get(Authentication_.target), root), - EntityHelper.checkNeededEntityPrediction(authenticationRoot, builder, loginUser) - ); - return Lists.immutable.of(builder.or( - builder.equal(root.get(DataResource_.createdUser), loginUser), - builder.exists(confirmationSubquery), - builder.exists(authenticationSubquery) + builder.equal(root.get(DataResource_.createdUser), loginUser) )); } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/WareService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/WareService.java index e34b185..6d48312 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/WareService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/WareService.java @@ -55,7 +55,7 @@ public class WareService extends CheckingService { } @Override - public void submit(Long id) throws Exception { + public void submit(Long id) { User user = userService.currentLoginUser(); Ware ware = detailOrThrow(id); String instanceId = flowableManager.start( @@ -74,11 +74,16 @@ public class WareService extends CheckingService { } @Override - public void retract(Long id) throws Exception { + public void retract(Long id) { Ware ware = detailOrThrow(id); flowableManager.terminal(ware.getFlowableInstanceId()); } + @Override + protected Object archive(Ware entity) { + return ""; + } + @Component public static final class WareFlowUserCheckListener extends FlowableListener.AbstractFlowableListener { private final WareRepository wareRepository; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/AmisHelper.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/AmisHelper.java new file mode 100644 index 0000000..48e9a32 --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/AmisHelper.java @@ -0,0 +1,134 @@ +package com.eshore.gringotts.web.helper; + +import cn.hutool.core.map.MapBuilder; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.eshore.gringotts.web.domain.base.entity.SimpleEntity; +import com.eshore.gringotts.web.domain.entity.format.ResourceFormat; +import com.eshore.gringotts.web.domain.entity.type.ApiResourceType; +import com.eshore.gringotts.web.domain.entity.type.ResourceType; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.factory.Maps; +import org.eclipse.collections.api.list.ImmutableList; +import org.eclipse.collections.api.list.MutableList; +import org.eclipse.collections.api.map.ImmutableMap; +import org.hibernate.Hibernate; + +/** + * @author lanyuanxiaoyao + * @version 20250108 + */ +public class AmisHelper { + @SafeVarargs + public static ImmutableMap wrapper(ImmutableMap... body) { + MapBuilder builder = MapUtil.builder(); + builder.put("type", "wrapper"); + builder.put("size", "none"); + builder.put("body", body); + return Maps.immutable.ofMap(builder.build()); + } + + public static ImmutableMap divider() { + return Maps.immutable.of("type", "divider"); + } + + @SafeVarargs + public static ImmutableMap property(ImmutableMap... items) { + return property(null, items); + } + + public static ImmutableMap property(ImmutableList> items) { + return property(null, items); + } + + @SafeVarargs + public static ImmutableMap property(String title, ImmutableMap... items) { + return property(title, Lists.immutable.of(items)); + } + + public static ImmutableMap property(String title, ImmutableList> items) { + MapBuilder builder = MapUtil.builder(); + builder.put("type", "property"); + if (StrUtil.isNotBlank(title)) { + builder.put("title", title); + } + if (ObjectUtil.isNotEmpty(items)) { + builder.put("items", items); + } + return Maps.immutable.ofMap(builder.build()); + } + + public static ImmutableMap property(ResourceType type) { + type = Hibernate.unproxy(type, ResourceType.class); + MutableList> items = Lists.mutable.empty(); + switch (type.getResourceType()) { + case API: + ApiResourceType apiResourceType = (ApiResourceType) type; + items.add(propertyItem("资源类型", "API", 3)); + items.add(propertyItem("用户名", apiResourceType.getUsername(), 1)); + items.add(propertyItem("密码", apiResourceType.getPassword(), 2)); + items.add(propertyItem("地址", apiResourceType.getUrl(), 3)); + break; + case FILE: + items.add(propertyItem("资源类型", "文件")); + break; + case DATABASE: + items.add(propertyItem("资源类型", "数据库")); + break; + case HDFS: + items.add(propertyItem("资源类型", "HDFS")); + break; + case FTP: + items.add(propertyItem("资源类型", "FTP")); + break; + } + return property("资源类型定义", items.toImmutable()); + } + + public static ImmutableMap property(ResourceFormat format) { + format = Hibernate.unproxy(format, ResourceFormat.class); + MutableList> items = Lists.mutable.empty(); + switch (format.getFormatType()) { + case NONE: + items.add(propertyItem("格式类型", "文件", 3)); + break; + case LINE: + items.add(propertyItem("格式类型", "文本行", 3)); + break; + case JSON: + items.add(propertyItem("格式类型", "Json")); + break; + case JSON_LINE: + items.add(propertyItem("格式类型", "Json Line")); + break; + case CSV: + items.add(propertyItem("格式类型", "CSV文本")); + break; + } + return property("资源格式定义", items.toImmutable()); + } + + public static ImmutableMap property(SimpleEntity entity) { + return property( + propertyItem("创建人", entity.getCreatedUser().getUsername(), 2), + propertyItem("创建时间", entity.getCreatedTime()), + propertyItem("修改人", entity.getModifiedUser().getUsername(), 2), + propertyItem("修改时间", entity.getModifiedTime()) + ); + } + + public static ImmutableMap propertyItem(String label, Object content) { + return propertyItem(label, content, null); + } + + public static ImmutableMap propertyItem(String label, Object content, Integer span) { + MapBuilder builder = MapUtil.builder(); + builder.put("label", label); + builder.put("content", content); + if (ObjectUtil.isNotNull(span)) { + builder.put("span", span); + } + return Maps.immutable.ofMap(builder.build()); + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/EntityHelper.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/EntityHelper.java index 3df6380..f5a5c0a 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/EntityHelper.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/EntityHelper.java @@ -2,9 +2,6 @@ package com.eshore.gringotts.web.helper; import cn.hutool.core.util.ObjectUtil; import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity; -import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity_; -import com.eshore.gringotts.web.domain.entity.CheckOrder; -import com.eshore.gringotts.web.domain.entity.CheckOrder_; import com.eshore.gringotts.web.domain.entity.User; import java.util.function.Supplier; import javax.persistence.criteria.CriteriaBuilder; @@ -28,14 +25,14 @@ public class EntityHelper { public static Predicate checkNeededEntityPrediction(Root root, CriteriaBuilder builder, User loginUser) { return builder.or( - builder.and( + /* builder.and( builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.target), CheckOrder.Target.ROLE), builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.targetRole), loginUser.getRole()) ), builder.and( builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.target), CheckOrder.Target.USER), builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.targetUser), loginUser) - ) + ) */ ); } }