1
0

feat(web): 增加审批快照的生成

This commit is contained in:
2025-01-08 15:41:48 +08:00
parent 509410de9a
commit b16dba4ef1
10 changed files with 229 additions and 86 deletions

View File

@@ -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,

View File

@@ -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'),
},
]),
],
},

View File

@@ -19,4 +19,6 @@ public abstract class CheckingService<ENTITY extends LogicDeleteEntity> extends
abstract public void submit(Long id) throws Exception;
abstract public void retract(Long id) throws Exception;
abstract protected Object archive(ENTITY entity);
}

View File

@@ -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<CheckOrderController
return AmisResponse.responseSuccess();
}
@GetMapping("/history/{instanceId}")
public AmisResponse<List<FlowableHistory>> history(@PathVariable String instanceId) {
return AmisResponse.responseSuccess(flowableManager.listHistories(instanceId));
}
@SneakyThrows
private ListItem toListItem(FlowableInstance instance) {
FlowableNode node = flowableManager.getNode(instance.getCurrentNodeId());

View File

@@ -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<Authentication> {
flowableManager.create(userCheckNode, roleCheckNode);
}
@Override
protected ImmutableList<Predicate> listPredicate(Root<Authentication> 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<Authentication> {
}
@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<Authentication> {
}
@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("数据资源已绑定该账号的授权申请,无法再次申请");

View File

@@ -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<Confirmation> {
}
@Override
protected ImmutableList<Predicate> listPredicate(Root<Confirmation> 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.<String, Object>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<Confirmation> {
}
@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())) {

View File

@@ -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<DataResource> {
return Lists.immutable.empty();
}
Subquery<Confirmation> confirmationSubquery = query.subquery(Confirmation.class);
Root<Confirmation> confirmationRoot = confirmationSubquery.from(Confirmation.class);
confirmationSubquery.select(confirmationRoot)
.where(
builder.equal(confirmationRoot.get(Confirmation_.target), root),
EntityHelper.checkNeededEntityPrediction(confirmationRoot, builder, loginUser)
);
Subquery<Authentication> authenticationSubquery = query.subquery(Authentication.class);
Root<Authentication> 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)
));
}

View File

@@ -55,7 +55,7 @@ public class WareService extends CheckingService<Ware> {
}
@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<Ware> {
}
@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;

View File

@@ -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<Object, Object> wrapper(ImmutableMap<Object, Object>... body) {
MapBuilder<Object, Object> builder = MapUtil.builder();
builder.put("type", "wrapper");
builder.put("size", "none");
builder.put("body", body);
return Maps.immutable.ofMap(builder.build());
}
public static ImmutableMap<Object, Object> divider() {
return Maps.immutable.of("type", "divider");
}
@SafeVarargs
public static ImmutableMap<Object, Object> property(ImmutableMap<Object, Object>... items) {
return property(null, items);
}
public static ImmutableMap<Object, Object> property(ImmutableList<ImmutableMap<Object, Object>> items) {
return property(null, items);
}
@SafeVarargs
public static ImmutableMap<Object, Object> property(String title, ImmutableMap<Object, Object>... items) {
return property(title, Lists.immutable.of(items));
}
public static ImmutableMap<Object, Object> property(String title, ImmutableList<ImmutableMap<Object, Object>> items) {
MapBuilder<Object, Object> 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<Object, Object> property(ResourceType type) {
type = Hibernate.unproxy(type, ResourceType.class);
MutableList<ImmutableMap<Object, Object>> 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<Object, Object> property(ResourceFormat format) {
format = Hibernate.unproxy(format, ResourceFormat.class);
MutableList<ImmutableMap<Object, Object>> 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<Object, Object> property(SimpleEntity entity) {
return property(
propertyItem("创建人", entity.getCreatedUser().getUsername(), 2),
propertyItem("创建时间", entity.getCreatedTime()),
propertyItem("修改人", entity.getModifiedUser().getUsername(), 2),
propertyItem("修改时间", entity.getModifiedTime())
);
}
public static ImmutableMap<Object, Object> propertyItem(String label, Object content) {
return propertyItem(label, content, null);
}
public static ImmutableMap<Object, Object> propertyItem(String label, Object content, Integer span) {
MapBuilder<Object, Object> 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());
}
}

View File

@@ -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<? extends CheckingNeededEntity> 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)
)
) */
);
}
}