Compare commits
2 Commits
b16dba4ef1
...
order
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e962884b1 | |||
| 6dccb0ecad |
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@@ -1,6 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="mavenCentral" />
|
||||
<option name="name" value="mavenCentral" />
|
||||
|
||||
@@ -261,19 +261,13 @@ export const permissionStateMapping = [
|
||||
export const checkTypeMapping = [
|
||||
mappingItem('确权审查', 'CONFIRMATION', 'bg-blue-500'),
|
||||
mappingItem('授权审查', 'AUTHENTICATION', 'bg-purple-500'),
|
||||
mappingItem('上架审查', 'WARE', 'bg-green-500'),
|
||||
mappingItem('上架审查', 'MARKET', 'bg-green-500'),
|
||||
]
|
||||
|
||||
export const checkOverMapping = [
|
||||
mappingItem('进行中', 'RUNNING', 'bg-warning'),
|
||||
mappingItem('已撤销', 'TERMINAL', 'bg-primary'),
|
||||
mappingItem('已办结', 'COMPLETED', 'bg-success'),
|
||||
]
|
||||
|
||||
export const checkActionMapping = [
|
||||
mappingItem('同意', 'APPROVE', 'bg-green-500'),
|
||||
mappingItem('驳回', 'REJECT', 'bg-red-500'),
|
||||
mappingItem('撤回', 'TERMINAL', 'bg-blue-500'),
|
||||
mappingItem('进行中', 'CHECKING', 'bg-warning'),
|
||||
mappingItem('已撤销', 'RETRACT', 'bg-primary'),
|
||||
mappingItem('已办结', 'OVER', 'bg-success'),
|
||||
]
|
||||
|
||||
function api(method, url) {
|
||||
|
||||
@@ -1,49 +1,16 @@
|
||||
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 [
|
||||
{
|
||||
@@ -64,14 +31,7 @@ export function tabCheck() {
|
||||
stringField('modifiedUsername', '最后操作人', 100),
|
||||
operationField('操作', undefined, [
|
||||
{
|
||||
visibleOn: "${state === 'COMPLETED'}",
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...detailDialog(),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'CONFIRMATION' && state === 'RUNNING'}",
|
||||
visibleOn: "${type === 'CONFIRMATION' && state === 'CHECKING'}",
|
||||
type: 'action',
|
||||
label: '处理',
|
||||
level: 'link',
|
||||
@@ -83,7 +43,7 @@ export function tabCheck() {
|
||||
label: '同意',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/approve/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
{
|
||||
@@ -91,14 +51,21 @@ export function tabCheck() {
|
||||
label: '拒绝',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/reject/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'AUTHENTICATION' && state === 'RUNNING'}",
|
||||
visibleOn: "${type === 'CONFIRMATION' && state !== NORMAL}",
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...confirmationDetailDialog('parameters.confirmationId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'AUTHENTICATION' && state === 'CHECKING'}",
|
||||
type: 'action',
|
||||
label: '处理',
|
||||
level: 'link',
|
||||
@@ -110,7 +77,7 @@ export function tabCheck() {
|
||||
label: '同意',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/approve/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
{
|
||||
@@ -118,14 +85,21 @@ export function tabCheck() {
|
||||
label: '拒绝',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/reject/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'WARE' && state === 'RUNNING'}",
|
||||
visibleOn: "${type === 'AUTHENTICATION' && state !== NORMAL}",
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...authenticationDetailDialog('parameters.authenticationId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'MARKET' && state === 'CHECKING'}",
|
||||
type: 'action',
|
||||
label: '处理',
|
||||
level: 'link',
|
||||
@@ -137,7 +111,7 @@ export function tabCheck() {
|
||||
label: '同意',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/approve/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
{
|
||||
@@ -145,12 +119,19 @@ export function tabCheck() {
|
||||
label: '拒绝',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/reject/${instanceId}'),
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
{
|
||||
visibleOn: "${type === 'MARKET' && state !== NORMAL}",
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...wareDetailDialog('parameters.wareId'),
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
<artifactId>gringotts-web</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>flowable</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.eshore</groupId>
|
||||
<artifactId>gringotts-configuration</artifactId>
|
||||
@@ -20,10 +25,6 @@
|
||||
<groupId>com.eshore</groupId>
|
||||
<artifactId>gringotts-forest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>flowable-spring-boot-jpa-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -22,14 +21,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-14
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {
|
||||
"com.eshore.gringotts",
|
||||
"com.lanyuanxiaoyao.flowable.jpa"
|
||||
})
|
||||
@EntityScan({
|
||||
"com.eshore.gringotts.web.domain.entity",
|
||||
"com.lanyuanxiaoyao.flowable.jpa.entity"
|
||||
})
|
||||
@SpringBootApplication(scanBasePackages = {"com.eshore.gringotts"})
|
||||
@EnableFenix
|
||||
@EnableJpaAuditing
|
||||
@EnableAsync
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* @author wn
|
||||
* @version 20241224
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class CheckingController<ENTITY extends CheckingNeededEntity, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> extends SimpleControllerSupport<ENTITY, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
|
||||
private final CheckingService<ENTITY> checkingService;
|
||||
|
||||
public CheckingController(CheckingService<ENTITY> service) {
|
||||
super(service);
|
||||
this.checkingService = service;
|
||||
}
|
||||
|
||||
@GetMapping("/submit/{id}")
|
||||
public AmisResponse<Object> submit(@PathVariable Long id) throws Exception {
|
||||
checkingService.submit(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@GetMapping("/retract/{id}")
|
||||
public AmisResponse<Object> retract(@PathVariable Long id) throws Exception {
|
||||
checkingService.retract(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import com.eshore.gringotts.web.domain.entity.order.CheckOrder;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToOne;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -22,7 +26,9 @@ public class CheckingNeededEntity extends LogicDeleteEntity {
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.DRAFT;
|
||||
|
||||
private String flowableInstanceId;
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@ToString.Exclude
|
||||
private CheckOrder order;
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.order.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* 需要审查
|
||||
@@ -20,5 +22,7 @@ public abstract class CheckingService<ENTITY extends LogicDeleteEntity> extends
|
||||
|
||||
abstract public void retract(Long id) throws Exception;
|
||||
|
||||
abstract protected Object archive(ENTITY entity);
|
||||
abstract public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters);
|
||||
|
||||
abstract public ImmutableMap<String, Object> archive(ENTITY entity);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.eshore.gringotts.web.domain.controller;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.controller.CheckingController;
|
||||
import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport;
|
||||
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||
@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("authentication")
|
||||
public class AuthenticationController extends CheckingController<Authentication, AuthenticationController.SaveItem, AuthenticationController.ListItem, AuthenticationController.DetailItem> {
|
||||
public class AuthenticationController extends SimpleControllerSupport<Authentication, AuthenticationController.SaveItem, AuthenticationController.ListItem, AuthenticationController.DetailItem> {
|
||||
private final DataResourceService dataResourceService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
|
||||
@@ -3,21 +3,18 @@ package com.eshore.gringotts.web.domain.controller;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
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 com.eshore.gringotts.web.domain.entity.order.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.order.node.CheckOrderNode;
|
||||
import com.eshore.gringotts.web.domain.service.CheckOrderService;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
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.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -35,81 +32,60 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("check_order")
|
||||
public class CheckOrderController implements ListController<CheckOrderController.ListItem> {
|
||||
private final UserService userService;
|
||||
private final SpringFlowableManager flowableManager;
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public CheckOrderController(UserService userService, SpringFlowableManager flowableManager) {
|
||||
this.userService = userService;
|
||||
this.flowableManager = flowableManager;
|
||||
public CheckOrderController(CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Override
|
||||
public AmisResponse<ImmutableList<CheckOrderController.ListItem>> list() throws Exception {
|
||||
User user = userService.currentLoginUser();
|
||||
return AmisResponse.responseSuccess(
|
||||
Lists.immutable.ofAll(flowableManager.listInstances(
|
||||
(root, query, builder) -> {
|
||||
if (User.isAdministrator(user)) {
|
||||
return null;
|
||||
}
|
||||
return builder.or(
|
||||
builder.like(root.get("extra"), user.getRole().name()),
|
||||
builder.like(root.get("extra"), user.getId().toString())
|
||||
);
|
||||
}
|
||||
)).collect(this::toListItem)
|
||||
);
|
||||
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@Override
|
||||
public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query query) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem));
|
||||
}
|
||||
|
||||
@GetMapping("/approve/{instanceId}")
|
||||
public AmisResponse<Object> approve(@PathVariable String instanceId) {
|
||||
flowableManager.approve(instanceId);
|
||||
@GetMapping("/approve/{id}")
|
||||
public AmisResponse<Object> approve(@PathVariable Long id) {
|
||||
checkOrderService.approve(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@GetMapping("/reject/{instanceId}")
|
||||
public AmisResponse<Object> reject(@PathVariable String instanceId) {
|
||||
flowableManager.reject(instanceId);
|
||||
@GetMapping("/reject/{id}")
|
||||
public AmisResponse<Object> reject(@PathVariable Long id) {
|
||||
checkOrderService.reject(id);
|
||||
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());
|
||||
private ListItem toListItem(CheckOrder order) {
|
||||
ListItem item = new ListItem();
|
||||
item.setInstanceId(instance.getInstanceId());
|
||||
item.setName(node.getName());
|
||||
item.setDescription(node.getDescription());
|
||||
item.setType(instance.getMetadata().getStringOrDefault("type", "unknown"));
|
||||
item.setParameters(Maps.immutable.ofAll(instance.getMetadata().getMetadata()));
|
||||
item.setState(instance.getStatus());
|
||||
item.setCreatedUsername(instance.getMetadata().getStringOrDefault("createdUsername", ""));
|
||||
item.setCreatedTime(instance.getCreatedTime());
|
||||
item.setModifiedUsername(instance.getMetadata().getStringOrDefault("modifiedUsername", ""));
|
||||
item.setModifiedTime(instance.getUpdatedTime());
|
||||
item.setCheckOrderId(order.getId());
|
||||
item.setDescription(order.getDescription());
|
||||
item.setCurrentNode(order.getCurrentNode());
|
||||
item.setParameters(mapper.readValue(order.getContext(), new TypeReference<>() {}));
|
||||
item.setState(order.getState());
|
||||
item.setCreatedUsername(order.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(order.getCreatedTime());
|
||||
item.setModifiedUsername(order.getModifiedUser().getUsername());
|
||||
item.setModifiedTime(order.getModifiedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class ListItem {
|
||||
private String instanceId;
|
||||
private String name;
|
||||
private Long checkOrderId;
|
||||
private String description;
|
||||
private String type;
|
||||
private CheckOrderNode currentNode;
|
||||
private ImmutableMap<String, Object> parameters;
|
||||
private FlowableInstance.Status state;
|
||||
private CheckOrder.State state;
|
||||
private LocalDateTime createdTime;
|
||||
private String createdUsername;
|
||||
private LocalDateTime modifiedTime;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.controller;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.controller.CheckingController;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport;
|
||||
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||
@@ -8,12 +9,15 @@ import com.eshore.gringotts.web.domain.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.service.ConfirmationService;
|
||||
import com.eshore.gringotts.web.domain.service.DataFileService;
|
||||
import com.eshore.gringotts.web.domain.service.DataResourceService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -24,16 +28,24 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("confirmation")
|
||||
public class ConfirmationController extends CheckingController<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
|
||||
public class ConfirmationController extends SimpleControllerSupport<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
|
||||
private final ConfirmationService confirmationService;
|
||||
private final DataResourceService dataResourceService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
public ConfirmationController(ConfirmationService service, DataResourceService dataResourceService, DataFileService dataFileService) {
|
||||
super(service);
|
||||
this.confirmationService = service;
|
||||
this.dataResourceService = dataResourceService;
|
||||
this.dataFileService = dataFileService;
|
||||
}
|
||||
|
||||
@GetMapping("submit/{id}")
|
||||
public AmisResponse<Object> submit(@PathVariable Long id) throws JsonProcessingException {
|
||||
confirmationService.submit(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Confirmation fromSaveItem(SaveItem item) throws Exception {
|
||||
Confirmation confirmation = new Confirmation();
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.eshore.gringotts.web.domain.controller;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.configuration.HostConfiguration;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.CheckingController;
|
||||
import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||
import com.eshore.gringotts.web.domain.entity.Ware;
|
||||
@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("ware")
|
||||
public class WareController extends CheckingController<Ware, WareController.SaveItem, WareController.ListItem, WareController.DetailItem> {
|
||||
public class WareController extends SimpleControllerSupport<Ware, WareController.SaveItem, WareController.ListItem, WareController.DetailItem> {
|
||||
private final HostConfiguration hostConfiguration;
|
||||
private final WareService wareService;
|
||||
private final DataResourceService dataResourceService;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.eshore.gringotts.web.domain.entity;
|
||||
package com.eshore.gringotts.web.domain.entity.order;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.entity.order.node.CheckOrderNode;
|
||||
import java.util.List;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
@@ -13,6 +15,7 @@ import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
@@ -38,74 +41,34 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "check_order.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "nodes"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
@NoArgsConstructor
|
||||
public class CheckOrder extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private String keyword;
|
||||
private String name;
|
||||
@Column(nullable = false)
|
||||
private String description;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Type type;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private CheckOrderNode currentNode;
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "order")
|
||||
@ToString.Exclude
|
||||
private List<CheckOrderNode> nodes;
|
||||
/**
|
||||
* JSON 结构 Map<String, Object>
|
||||
*/
|
||||
@Column(nullable = false)
|
||||
private String parameters;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Target target;
|
||||
@Column(nullable = false)
|
||||
private String targetClass;
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private User targetUser;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private User.Role targetRole;
|
||||
private String context = "{}";
|
||||
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.CHECKING;
|
||||
|
||||
public CheckOrder(
|
||||
String keyword,
|
||||
String description,
|
||||
Type type,
|
||||
String parameters,
|
||||
String targetClass,
|
||||
User targetUser
|
||||
) {
|
||||
this.keyword = keyword;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
this.parameters = parameters;
|
||||
this.target = Target.USER;
|
||||
this.targetClass = targetClass;
|
||||
this.targetUser = targetUser;
|
||||
}
|
||||
|
||||
public CheckOrder(
|
||||
String keyword,
|
||||
String description,
|
||||
Type type,
|
||||
String parameters,
|
||||
String targetClass,
|
||||
User.Role targetRole
|
||||
) {
|
||||
this.keyword = keyword;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
this.parameters = parameters;
|
||||
this.target = Target.ROLE;
|
||||
this.targetClass = targetClass;
|
||||
this.targetRole = targetRole;
|
||||
}
|
||||
|
||||
public enum Operation {
|
||||
APPLY,
|
||||
REJECT,
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.eshore.gringotts.web.domain.entity.order.node;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity;
|
||||
import com.eshore.gringotts.web.domain.entity.order.CheckOrder;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20241225
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.TABLE_PREFIX + "check_order_node")
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
public abstract class CheckOrderNode extends IdOnlyEntity {
|
||||
@Column(nullable = false)
|
||||
private Integer sequence;
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private CheckOrder order;
|
||||
|
||||
public abstract Type getCheckType();
|
||||
|
||||
public enum Type {
|
||||
USER,
|
||||
ROLE,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.eshore.gringotts.web.domain.entity.order.node;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 指定用户审核
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20241225
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "check_order_node_role")
|
||||
public class RoleCheckOrderNode extends CheckOrderNode {
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private User.Role target;
|
||||
|
||||
@Override
|
||||
public Type getCheckType() {
|
||||
return Type.ROLE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.eshore.gringotts.web.domain.entity.order.node;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 指定用户审核
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20241225
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "check_order_node_user")
|
||||
public class UserCheckOrderNode extends CheckOrderNode {
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private User target;
|
||||
|
||||
@Override
|
||||
public Type getCheckType() {
|
||||
return Type.USER;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.flowable;
|
||||
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAccessor;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250106
|
||||
*/
|
||||
@Service
|
||||
public class CheckRoleAssessor implements FlowableAccessor {
|
||||
private final UserService userService;
|
||||
|
||||
public CheckRoleAssessor(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean access(FlowableInstance flowableInstance, FlowableNode flowableNode, FlowableAction flowableAction) {
|
||||
User.Role role = userService.currentLoginUser().getRole();
|
||||
return User.Role.ADMINISTRATOR.equals(role) || User.Role.CHECKER.equals(role);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.eshore.gringotts.web.domain.flowable;
|
||||
|
||||
import com.eshore.gringotts.web.domain.entity.order.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.order.node.CheckOrderNode;
|
||||
import com.eshore.gringotts.web.domain.entity.order.node.RoleCheckOrderNode;
|
||||
import com.eshore.gringotts.web.domain.entity.order.node.UserCheckOrderNode;
|
||||
import com.eshore.gringotts.web.domain.flowable.node.RoleCheckFlowNode;
|
||||
import com.eshore.gringotts.web.domain.flowable.node.UserCheckFlowNode;
|
||||
import com.eshore.gringotts.web.domain.repository.CheckOrderNodeRepository;
|
||||
import com.eshore.gringotts.web.domain.service.CheckOrderService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lanyuanxiaoyao.flowable.model.Flow;
|
||||
import com.lanyuanxiaoyao.flowable.model.FlowStatus;
|
||||
import com.lanyuanxiaoyao.flowable.node.FlowNode;
|
||||
import com.lanyuanxiaoyao.flowable.repository.FlowRepository;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.SneakyThrows;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20241225
|
||||
*/
|
||||
@Service
|
||||
public class FlowDatabaseRepository implements FlowRepository {
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final CheckOrderNodeRepository checkOrderNodeRepository;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public FlowDatabaseRepository(CheckOrderService checkOrderService, CheckOrderNodeRepository checkOrderNodeRepository, Jackson2ObjectMapperBuilder builder) {
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.checkOrderNodeRepository = checkOrderNodeRepository;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
private FlowNode mapTo(CheckOrderNode source) {
|
||||
switch (source.getCheckType()) {
|
||||
case USER:
|
||||
return new UserCheckFlowNode(source.getId().toString(), ((UserCheckOrderNode) source).getTarget());
|
||||
case ROLE:
|
||||
return new RoleCheckFlowNode(source.getId().toString(), ((RoleCheckOrderNode) source).getTarget());
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported check type: " + source.getCheckType());
|
||||
}
|
||||
}
|
||||
|
||||
private CheckOrderNode mapTo(FlowNode source) {
|
||||
return checkOrderNodeRepository.findById(Long.valueOf(source.getNodeId())).orElseThrow(() -> new RuntimeException(""));
|
||||
}
|
||||
|
||||
private Flow mapTo(CheckOrder order) throws JsonProcessingException {
|
||||
Flow flow = new Flow();
|
||||
flow.setName(order.getName());
|
||||
flow.setDescription(order.getDescription());
|
||||
flow.setNodes(order.getNodes()
|
||||
.stream()
|
||||
.map(this::mapTo)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
flow.setCurrentNode(mapTo(order.getCurrentNode()).getNodeId());
|
||||
switch (order.getState()) {
|
||||
case CHECKING:
|
||||
flow.setStatus(FlowStatus.PENDING);
|
||||
break;
|
||||
case RETRACT:
|
||||
flow.setStatus(FlowStatus.REJECTED);
|
||||
break;
|
||||
case OVER:
|
||||
flow.setStatus(FlowStatus.APPROVED);
|
||||
break;
|
||||
}
|
||||
flow.setContextVariables(mapper.readValue(order.getContext(), new TypeReference<>() {}));
|
||||
flow.setCreateTime(order.getCreatedTime());
|
||||
flow.setUpdateTime(order.getModifiedTime());
|
||||
return flow;
|
||||
}
|
||||
|
||||
private void mapTo(Flow flow, CheckOrder order) throws JsonProcessingException {
|
||||
order.setName(flow.getName());
|
||||
order.setDescription(flow.getDescription());
|
||||
order.setNodes(Lists.mutable.ofAll(flow.getNodes()).collect(this::mapTo));
|
||||
order.setCurrentNode(mapTo(flow.getCurrentNodeObject()));
|
||||
switch (flow.getStatus()) {
|
||||
case APPROVED:
|
||||
order.setState(CheckOrder.State.OVER);
|
||||
break;
|
||||
case PENDING:
|
||||
order.setState(CheckOrder.State.CHECKING);
|
||||
break;
|
||||
case REJECTED:
|
||||
order.setState(CheckOrder.State.RETRACT);
|
||||
break;
|
||||
}
|
||||
order.setContext(mapper.writeValueAsString(flow.getContextVariables()));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public Flow save(Flow flow) {
|
||||
CheckOrder order = new CheckOrder();
|
||||
mapTo(flow, order);
|
||||
Long id = checkOrderService.save(order);
|
||||
flow.setId(id.toString());
|
||||
return flow;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public Flow update(Flow flow) {
|
||||
CheckOrder order = checkOrderService.detailOrThrow(Long.parseLong(flow.getId()));
|
||||
mapTo(flow, order);
|
||||
checkOrderService.save(order);
|
||||
return flow;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public Flow findById(String id) {
|
||||
CheckOrder order = checkOrderService.detailOrThrow(Long.parseLong(id));
|
||||
return mapTo(order);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.flowable;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.eshore.gringotts.web.domain.service.UserService;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAccessor;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250106
|
||||
*/
|
||||
@Service
|
||||
public class UserAssessor implements FlowableAccessor {
|
||||
public static final String KEY = "user_access_key";
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public UserAssessor(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean access(FlowableInstance flowableInstance, FlowableNode flowableNode, FlowableAction flowableAction) {
|
||||
FlowableMetadata metadata = flowableInstance.getMetadata();
|
||||
return NumberUtil.equals(userService.currentLoginUser().getId(), metadata.getLong(KEY));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.eshore.gringotts.web.domain.flowable.node;
|
||||
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.lanyuanxiaoyao.flowable.node.AbstractFlowNode;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20241225
|
||||
*/
|
||||
@Getter
|
||||
public class RoleCheckFlowNode extends AbstractFlowNode {
|
||||
private final User.Role role;
|
||||
|
||||
public RoleCheckFlowNode(String nodeId, User.Role role) {
|
||||
super(nodeId);
|
||||
this.role = role;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.eshore.gringotts.web.domain.flowable.node;
|
||||
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.service.ConfirmationService;
|
||||
import com.lanyuanxiaoyao.flowable.model.FlowContext;
|
||||
import com.lanyuanxiaoyao.flowable.node.AbstractFlowNode;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20241225
|
||||
*/
|
||||
@Getter
|
||||
public class UserCheckFlowNode extends AbstractFlowNode {
|
||||
private final User user;
|
||||
private final ConfirmationService confirmationService;
|
||||
|
||||
public UserCheckFlowNode(String nodeId, User user, ConfirmationService confirmationService) {
|
||||
super(nodeId);
|
||||
this.user = user;
|
||||
this.confirmationService = confirmationService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApprove(FlowContext context) {
|
||||
super.onApprove(context);
|
||||
Long confirmationId = context.getVariable("confirmationId", Long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReject(FlowContext context) {
|
||||
super.onReject(context);
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,9 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.Authentication;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.transaction.Transactional;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
@@ -30,14 +27,4 @@ public interface AuthenticationRepository extends SimpleRepository<Authenticatio
|
||||
@Override
|
||||
@EntityGraph(value = "authentication.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<Authentication> findOne(Specification<Authentication> specification);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Authentication confirmation set confirmation.state = ?2 where confirmation.id = ?1 and confirmation.deleted = false")
|
||||
void updateStateById(Long id, Authentication.State state);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Authentication confirmation set confirmation.flowableInstanceId = ?2 where confirmation.id = ?1 and confirmation.deleted = false")
|
||||
void updateInstanceIdById(Long id, String instanceId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.eshore.gringotts.web.domain.repository;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.order.node.CheckOrderNode;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20241225
|
||||
*/
|
||||
@Repository
|
||||
public interface CheckOrderNodeRepository extends SimpleRepository<CheckOrderNode, Long> {
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.eshore.gringotts.web.domain.repository;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.entity.order.CheckOrder;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
@@ -4,12 +4,9 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.Confirmation;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.transaction.Transactional;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
@@ -31,15 +28,5 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
|
||||
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<Confirmation> findOne(Specification<Confirmation> specification);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Confirmation confirmation set confirmation.state = ?2 where confirmation.id = ?1 and confirmation.deleted = false")
|
||||
void updateStateById(Long id, Confirmation.State state);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Confirmation confirmation set confirmation.flowableInstanceId = ?2 where confirmation.id = ?1 and confirmation.deleted = false")
|
||||
void updateInstanceIdById(Long id, String instanceId);
|
||||
|
||||
Boolean existsByTarget_Id(Long targetId);
|
||||
Boolean existsByTarget_Id(Long id);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,9 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.entity.Ware;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.transaction.Transactional;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@@ -26,14 +23,4 @@ public interface WareRepository extends SimpleRepository<Ware, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "ware.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<Ware> findOne(Specification<Ware> specification);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Ware ware set ware.state = ?2 where ware.id = ?1 and ware.deleted = false")
|
||||
void updateStateById(Long id, Ware.State state);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Ware ware set ware.flowableInstanceId = ?2 where ware.id = ?1 and ware.deleted = false")
|
||||
void updateInstanceIdById(Long id, String instanceId);
|
||||
}
|
||||
@@ -1,26 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
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.base.service.LogicDeleteService;
|
||||
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;
|
||||
import com.eshore.gringotts.web.domain.flowable.UserAssessor;
|
||||
import com.eshore.gringotts.web.domain.repository.AuthenticationRepository;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableListener;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -29,37 +14,14 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AuthenticationService extends CheckingService<Authentication> {
|
||||
private static final String AUTHENTICATION_FLOW_ID = "4ba86acd-1420-450b-98f9-0ed41772fe53";
|
||||
|
||||
public class AuthenticationService extends LogicDeleteService<Authentication> {
|
||||
private final AuthenticationRepository authenticationRepository;
|
||||
private final UserService userService;
|
||||
private final SpringFlowableManager flowableManager;
|
||||
|
||||
public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager, SpringFlowableManager flowableManager) {
|
||||
public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager) {
|
||||
super(repository, userService, manager);
|
||||
this.authenticationRepository = repository;
|
||||
this.userService = userService;
|
||||
|
||||
this.flowableManager = flowableManager;
|
||||
FlowableNode userCheckNode = FlowableNode.builder()
|
||||
.nodeId(AUTHENTICATION_FLOW_ID)
|
||||
.name("用户审查")
|
||||
.description("用户审查")
|
||||
.listeners(Lists.mutable.of(AuthenticationService.AuthenticationFlowUserCheckListener.class.getName()))
|
||||
.accessor(UserAssessor.class.getName())
|
||||
.targets(Maps.mutable.of(
|
||||
FlowableAction.APPROVE, "f087b0e4-0efa-4b26-945f-642436aa4aef"
|
||||
))
|
||||
.build();
|
||||
FlowableNode roleCheckNode = FlowableNode.builder()
|
||||
.nodeId("f087b0e4-0efa-4b26-945f-642436aa4aef")
|
||||
.name("授权审查")
|
||||
.description("授权审查")
|
||||
.listeners(Lists.mutable.of(AuthenticationService.AuthenticationFlowRoleCheckListener.class.getName()))
|
||||
.accessor(CheckRoleAssessor.class.getName())
|
||||
.build();
|
||||
flowableManager.create(userCheckNode, roleCheckNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,79 +41,9 @@ public class AuthenticationService extends CheckingService<Authentication> {
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submit(Long id) {
|
||||
User user = userService.currentLoginUser();
|
||||
Authentication authentication = detailOrThrow(id);
|
||||
String instanceId = flowableManager.start(
|
||||
AUTHENTICATION_FLOW_ID,
|
||||
MapUtil.<String, Object>builder()
|
||||
.put("authenticationId", id)
|
||||
.put("type", "AUTHENTICATION")
|
||||
.put("createdUsername", user.getUsername())
|
||||
.put("modifiedUsername", user.getUsername())
|
||||
.put(UserAssessor.KEY, authentication.getTarget().getCreatedUser().getId())
|
||||
.build(),
|
||||
authentication.getTarget().getCreatedUser().getId().toString()
|
||||
);
|
||||
authenticationRepository.updateInstanceIdById(id, instanceId);
|
||||
authenticationRepository.updateStateById(id, Confirmation.State.CHECKING);
|
||||
}
|
||||
|
||||
@Override
|
||||
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("数据资源已绑定该账号的授权申请,无法再次申请");
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
public static final class AuthenticationFlowUserCheckListener extends FlowableListener.AbstractFlowableListener {
|
||||
private final AuthenticationRepository authenticationRepository;
|
||||
|
||||
public AuthenticationFlowUserCheckListener(AuthenticationRepository authenticationRepository) {
|
||||
this.authenticationRepository = authenticationRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||
FlowableMetadata metadata = instance.getMetadata();
|
||||
Long authenticationId = metadata.getLong("authenticationId");
|
||||
if (FlowableAction.APPROVE.equals(action)) {
|
||||
instance.setExtra(User.Role.CHECKER.name());
|
||||
} else {
|
||||
authenticationRepository.updateStateById(authenticationId, Confirmation.State.DRAFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
public static final class AuthenticationFlowRoleCheckListener extends FlowableListener.AbstractFlowableListener {
|
||||
private final AuthenticationRepository authenticationRepository;
|
||||
|
||||
public AuthenticationFlowRoleCheckListener(AuthenticationRepository authenticationRepository) {
|
||||
this.authenticationRepository = authenticationRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||
FlowableMetadata metadata = instance.getMetadata();
|
||||
Long authenticationId = metadata.getLong("authenticationId");
|
||||
if (FlowableAction.APPROVE.equals(action)) {
|
||||
authenticationRepository.updateStateById(authenticationId, CheckingNeededEntity.State.NORMAL);
|
||||
} else {
|
||||
authenticationRepository.updateStateById(authenticationId, Confirmation.State.DRAFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import com.eshore.gringotts.web.domain.entity.order.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.flowable.FlowDatabaseRepository;
|
||||
import com.eshore.gringotts.web.domain.repository.CheckOrderRepository;
|
||||
import com.lanyuanxiaoyao.flowable.service.FlowService;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-29
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CheckOrderService extends SimpleServiceSupport<CheckOrder> {
|
||||
private final FlowService flowService;
|
||||
|
||||
public CheckOrderService(CheckOrderRepository repository, UserService userService, FlowDatabaseRepository flowDatabaseRepository) {
|
||||
super(repository, userService);
|
||||
this.flowService = new FlowService(flowDatabaseRepository);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void startFlow(CheckOrder order) {
|
||||
startFlow(order.getId());
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void startFlow(Long id) {
|
||||
flowService.startFlow(id.toString());
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void approve(Long id) {
|
||||
flowService.approve(id.toString());
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void reject(Long id) {
|
||||
flowService.reject(id.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,20 @@
|
||||
package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
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.base.service.LogicDeleteService;
|
||||
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.entity.order.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.entity.order.node.RoleCheckOrderNode;
|
||||
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;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -27,67 +23,16 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ConfirmationService extends CheckingService<Confirmation> {
|
||||
private static final String CONFIRMATION_FLOW_ID = "69d8ded5-35fd-4f03-b11a-be0ed91a4b8b";
|
||||
|
||||
public class ConfirmationService extends LogicDeleteService<Confirmation> {
|
||||
private final ConfirmationRepository confirmationRepository;
|
||||
private final SpringFlowableManager flowableManager;
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager, SpringFlowableManager flowableManager) {
|
||||
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(confirmationRepository, userService, entityManager);
|
||||
this.confirmationRepository = confirmationRepository;
|
||||
|
||||
this.flowableManager = flowableManager;
|
||||
FlowableNode node = FlowableNode.builder()
|
||||
.nodeId(CONFIRMATION_FLOW_ID)
|
||||
.name("确权审查")
|
||||
.description("确权审查")
|
||||
.listeners(Lists.mutable.of(ConfirmationService.ConfirmationFlowRoleCheckListener.class.getName()))
|
||||
.accessor(CheckRoleAssessor.class.getName())
|
||||
.build();
|
||||
flowableManager.create(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
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(),
|
||||
User.Role.CHECKER.name()
|
||||
);
|
||||
confirmationRepository.updateInstanceIdById(id, instanceId);
|
||||
confirmationRepository.updateStateById(id, Confirmation.State.CHECKING);
|
||||
}
|
||||
|
||||
@Override
|
||||
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)
|
||||
);
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,29 +43,22 @@ public class ConfirmationService extends CheckingService<Confirmation> {
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void submit(Long id) throws JsonProcessingException {
|
||||
CheckOrder order = new CheckOrder();
|
||||
order.setName("确权申请");
|
||||
order.setDescription("确权申请");
|
||||
order.setNodes(Lists.mutable.of(
|
||||
new RoleCheckOrderNode(User.Role.CHECKER)
|
||||
));
|
||||
order.setContext(mapper.writeValueAsString(Maps.immutable.of("confirmationId", id)));
|
||||
checkOrderService.save(order);
|
||||
checkOrderService.startFlow(order);
|
||||
}
|
||||
|
||||
public static final class ConfirmationDuplicatedException extends RuntimeException {
|
||||
public ConfirmationDuplicatedException() {
|
||||
super("数据资源已绑定确权申请,无法再次申请");
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
public static final class ConfirmationFlowRoleCheckListener extends FlowableListener.AbstractFlowableListener {
|
||||
private final ConfirmationRepository confirmationRepository;
|
||||
|
||||
public ConfirmationFlowRoleCheckListener(ConfirmationRepository confirmationRepository) {
|
||||
this.confirmationRepository = confirmationRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||
FlowableMetadata metadata = instance.getMetadata();
|
||||
Long confirmationId = metadata.getLong("confirmationId");
|
||||
if (action == FlowableAction.APPROVE) {
|
||||
confirmationRepository.updateStateById(confirmationId, Confirmation.State.NORMAL);
|
||||
} else {
|
||||
confirmationRepository.updateStateById(confirmationId, Confirmation.State.DRAFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ 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;
|
||||
@@ -55,8 +56,26 @@ 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.equal(root.get(DataResource_.createdUser), loginUser),
|
||||
builder.exists(confirmationSubquery),
|
||||
builder.exists(authenticationSubquery)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
package com.eshore.gringotts.web.domain.service;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.entity.User;
|
||||
import com.eshore.gringotts.web.domain.base.service.LogicDeleteService;
|
||||
import com.eshore.gringotts.web.domain.entity.Ware;
|
||||
import com.eshore.gringotts.web.domain.flowable.UserAssessor;
|
||||
import com.eshore.gringotts.web.domain.repository.WareRepository;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableListener;
|
||||
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 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;
|
||||
|
||||
/**
|
||||
@@ -25,27 +15,12 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WareService extends CheckingService<Ware> {
|
||||
private static final String WARE_FLOW_ID = "870e7376-1713-48ed-9e60-e602981c6ecc";
|
||||
|
||||
public class WareService extends LogicDeleteService<Ware> {
|
||||
private final WareRepository wareRepository;
|
||||
private final UserService userService;
|
||||
private final SpringFlowableManager flowableManager;
|
||||
|
||||
public WareService(WareRepository repository, UserService userService, EntityManager entityManager, SpringFlowableManager flowableManager) {
|
||||
public WareService(WareRepository repository, UserService userService, EntityManager entityManager) {
|
||||
super(repository, userService, entityManager);
|
||||
this.wareRepository = repository;
|
||||
this.userService = userService;
|
||||
|
||||
this.flowableManager = flowableManager;
|
||||
FlowableNode node = FlowableNode.builder()
|
||||
.nodeId(WARE_FLOW_ID)
|
||||
.name("上架审查")
|
||||
.description("上架审查")
|
||||
.listeners(Lists.mutable.of(WareService.WareFlowUserCheckListener.class.getName()))
|
||||
.accessor(UserAssessor.class.getName())
|
||||
.build();
|
||||
flowableManager.create(node);
|
||||
}
|
||||
|
||||
public ImmutableList<Ware> listPublic() {
|
||||
@@ -53,54 +28,4 @@ public class WareService extends CheckingService<Ware> {
|
||||
wareRepository.findAll((root, query, builder) -> builder.equal(root.get("state"), Ware.State.NORMAL))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submit(Long id) {
|
||||
User user = userService.currentLoginUser();
|
||||
Ware ware = detailOrThrow(id);
|
||||
String instanceId = flowableManager.start(
|
||||
WARE_FLOW_ID,
|
||||
MapUtil.<String, Object>builder()
|
||||
.put("wareId", id)
|
||||
.put("type", "WARE")
|
||||
.put("createdUsername", user.getUsername())
|
||||
.put("modifiedUsername", user.getUsername())
|
||||
.put(UserAssessor.KEY, ware.getResource().getCreatedUser().getId())
|
||||
.build(),
|
||||
ware.getResource().getCreatedUser().getId().toString()
|
||||
);
|
||||
wareRepository.updateInstanceIdById(id, instanceId);
|
||||
wareRepository.updateStateById(id, Ware.State.CHECKING);
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
public WareFlowUserCheckListener(WareRepository wareRepository) {
|
||||
this.wareRepository = wareRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||
FlowableMetadata metadata = instance.getMetadata();
|
||||
Long wareId = metadata.getLong("wareId");
|
||||
if (FlowableAction.APPROVE.equals(action)) {
|
||||
wareRepository.updateStateById(wareId, Ware.State.NORMAL);
|
||||
} else {
|
||||
wareRepository.updateStateById(wareId, Ware.State.DRAFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ 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.User;
|
||||
import com.eshore.gringotts.web.domain.entity.order.CheckOrder;
|
||||
import java.util.function.Supplier;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
@@ -25,14 +28,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)
|
||||
) */
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
7
pom.xml
7
pom.xml
@@ -60,13 +60,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Private Dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>flowable-spring-boot-jpa-starter</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Reference in New Issue
Block a user