1
0

feat(web): 适配flowable

This commit is contained in:
2024-12-26 00:00:11 +08:00
parent 6dccb0ecad
commit 7e962884b1
7 changed files with 70 additions and 8 deletions

View File

@@ -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" />

View File

@@ -1,5 +1,6 @@
package com.eshore.gringotts.web.domain.controller;
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;
@@ -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;
@@ -25,15 +29,23 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("confirmation")
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();

View File

@@ -63,7 +63,7 @@ public class CheckOrder extends SimpleEntity {
* JSON 结构 Map<String, Object>
*/
@Column(nullable = false)
private String context;
private String context = "{}";
@Column(nullable = false)
@Enumerated(EnumType.STRING)

View File

@@ -52,7 +52,8 @@ public class FlowDatabaseRepository implements FlowRepository {
return checkOrderNodeRepository.findById(Long.valueOf(source.getNodeId())).orElseThrow(() -> new RuntimeException(""));
}
private void mapTo(CheckOrder order, Flow flow) throws JsonProcessingException {
private Flow mapTo(CheckOrder order) throws JsonProcessingException {
Flow flow = new Flow();
flow.setName(order.getName());
flow.setDescription(order.getDescription());
flow.setNodes(order.getNodes()
@@ -75,6 +76,7 @@ public class FlowDatabaseRepository implements FlowRepository {
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 {
@@ -119,8 +121,6 @@ public class FlowDatabaseRepository implements FlowRepository {
@Override
public Flow findById(String id) {
CheckOrder order = checkOrderService.detailOrThrow(Long.parseLong(id));
Flow flow = new Flow();
mapTo(order, flow);
return flow;
return mapTo(order);
}
}

View File

@@ -1,6 +1,8 @@
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;
@@ -11,9 +13,22 @@ import lombok.Getter;
@Getter
public class UserCheckFlowNode extends AbstractFlowNode {
private final User user;
private final ConfirmationService confirmationService;
public UserCheckFlowNode(String nodeId, User user) {
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);
}
}

View File

@@ -25,7 +25,11 @@ public class CheckOrderService extends SimpleServiceSupport<CheckOrder> {
@Transactional(rollbackOn = Throwable.class)
public void startFlow(CheckOrder order) {
Long id = save(order);
startFlow(order.getId());
}
@Transactional(rollbackOn = Throwable.class)
public void startFlow(Long id) {
flowService.startFlow(id.toString());
}

View File

@@ -3,9 +3,18 @@ package com.eshore.gringotts.web.domain.service;
import cn.hutool.core.util.ObjectUtil;
import com.eshore.gringotts.web.domain.base.service.LogicDeleteService;
import com.eshore.gringotts.web.domain.entity.Confirmation;
import com.eshore.gringotts.web.domain.entity.User;
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.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.eclipse.collections.api.factory.Maps;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Service;
/**
@@ -16,10 +25,14 @@ import org.springframework.stereotype.Service;
@Service
public class ConfirmationService extends LogicDeleteService<Confirmation> {
private final ConfirmationRepository confirmationRepository;
private final CheckOrderService checkOrderService;
private final ObjectMapper mapper;
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager) {
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
super(confirmationRepository, userService, entityManager);
this.confirmationRepository = confirmationRepository;
this.checkOrderService = checkOrderService;
this.mapper = builder.build();
}
@Override
@@ -30,6 +43,19 @@ public class ConfirmationService extends LogicDeleteService<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("数据资源已绑定确权申请,无法再次申请");