1
0

3 Commits

Author SHA1 Message Date
b16dba4ef1 feat(web): 增加审批快照的生成 2025-01-08 15:41:48 +08:00
509410de9a feat(web): 适配flowable 2025-01-08 10:41:40 +08:00
0aa9ec738a feat(web): 增加flowable依赖 2025-01-03 18:30:05 +08:00
20 changed files with 625 additions and 447 deletions

View File

@@ -261,13 +261,19 @@ export const permissionStateMapping = [
export const checkTypeMapping = [ export const checkTypeMapping = [
mappingItem('确权审查', 'CONFIRMATION', 'bg-blue-500'), mappingItem('确权审查', 'CONFIRMATION', 'bg-blue-500'),
mappingItem('授权审查', 'AUTHENTICATION', 'bg-purple-500'), mappingItem('授权审查', 'AUTHENTICATION', 'bg-purple-500'),
mappingItem('上架审查', 'MARKET', 'bg-green-500'), mappingItem('上架审查', 'WARE', 'bg-green-500'),
] ]
export const checkOverMapping = [ export const checkOverMapping = [
mappingItem('进行中', 'CHECKING', 'bg-warning'), mappingItem('进行中', 'RUNNING', 'bg-warning'),
mappingItem('已撤销', 'RETRACT', 'bg-primary'), mappingItem('已撤销', 'TERMINAL', 'bg-primary'),
mappingItem('已办结', 'OVER', 'bg-success'), 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) { function api(method, url) {

View File

@@ -1,16 +1,49 @@
import { import {
apiGet, apiGet,
checkActionMapping,
checkOverMapping, checkOverMapping,
checkTypeMapping, checkTypeMapping,
crudCommonOptions, crudCommonOptions,
mappingField, mappingField,
operationField, operationField,
readOnlyDialogOptions,
stringField, stringField,
timeField, timeField,
} from "../../components/constants.js"; } from "../../components/constants.js";
import {authenticationDetailDialog, confirmationDetailDialog} from "../../components/permission/dialog-permission.js"; import {authenticationDetailDialog, confirmationDetailDialog} from "../../components/permission/dialog-permission.js";
import {wareDetailDialog} from "../../components/ware/dialog-ware.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() { export function tabCheck() {
return [ return [
{ {
@@ -31,7 +64,14 @@ export function tabCheck() {
stringField('modifiedUsername', '最后操作人', 100), stringField('modifiedUsername', '最后操作人', 100),
operationField('操作', undefined, [ operationField('操作', undefined, [
{ {
visibleOn: "${type === 'CONFIRMATION' && state === 'CHECKING'}", visibleOn: "${state === 'COMPLETED'}",
type: 'action',
label: '查看',
level: 'link',
...detailDialog(),
},
{
visibleOn: "${type === 'CONFIRMATION' && state === 'RUNNING'}",
type: 'action', type: 'action',
label: '处理', label: '处理',
level: 'link', level: 'link',
@@ -43,7 +83,7 @@ export function tabCheck() {
label: '同意', label: '同意',
actionType: 'ajax', actionType: 'ajax',
close: true, close: true,
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'), api: apiGet('${base}/check_order/approve/${instanceId}'),
reload: 'check_order_list', reload: 'check_order_list',
}, },
{ {
@@ -51,21 +91,14 @@ export function tabCheck() {
label: '拒绝', label: '拒绝',
actionType: 'ajax', actionType: 'ajax',
close: true, close: true,
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'), api: apiGet('${base}/check_order/reject/${instanceId}'),
reload: 'check_order_list', reload: 'check_order_list',
}, },
], ],
), ),
}, },
{ {
visibleOn: "${type === 'CONFIRMATION' && state !== NORMAL}", visibleOn: "${type === 'AUTHENTICATION' && state === 'RUNNING'}",
type: 'action',
label: '查看',
level: 'link',
...confirmationDetailDialog('parameters.confirmationId'),
},
{
visibleOn: "${type === 'AUTHENTICATION' && state === 'CHECKING'}",
type: 'action', type: 'action',
label: '处理', label: '处理',
level: 'link', level: 'link',
@@ -77,7 +110,7 @@ export function tabCheck() {
label: '同意', label: '同意',
actionType: 'ajax', actionType: 'ajax',
close: true, close: true,
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'), api: apiGet('${base}/check_order/approve/${instanceId}'),
reload: 'check_order_list', reload: 'check_order_list',
}, },
{ {
@@ -85,21 +118,14 @@ export function tabCheck() {
label: '拒绝', label: '拒绝',
actionType: 'ajax', actionType: 'ajax',
close: true, close: true,
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'), api: apiGet('${base}/check_order/reject/${instanceId}'),
reload: 'check_order_list', reload: 'check_order_list',
}, },
], ],
), ),
}, },
{ {
visibleOn: "${type === 'AUTHENTICATION' && state !== NORMAL}", visibleOn: "${type === 'WARE' && state === 'RUNNING'}",
type: 'action',
label: '查看',
level: 'link',
...authenticationDetailDialog('parameters.authenticationId'),
},
{
visibleOn: "${type === 'MARKET' && state === 'CHECKING'}",
type: 'action', type: 'action',
label: '处理', label: '处理',
level: 'link', level: 'link',
@@ -111,7 +137,7 @@ export function tabCheck() {
label: '同意', label: '同意',
actionType: 'ajax', actionType: 'ajax',
close: true, close: true,
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'), api: apiGet('${base}/check_order/approve/${instanceId}'),
reload: 'check_order_list', reload: 'check_order_list',
}, },
{ {
@@ -119,19 +145,12 @@ export function tabCheck() {
label: '拒绝', label: '拒绝',
actionType: 'ajax', actionType: 'ajax',
close: true, close: true,
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'), api: apiGet('${base}/check_order/reject/${instanceId}'),
reload: 'check_order_list', reload: 'check_order_list',
}, },
], ],
), ),
}, },
{
visibleOn: "${type === 'MARKET' && state !== NORMAL}",
type: 'action',
label: '查看',
level: 'link',
...wareDetailDialog('parameters.wareId'),
},
]), ]),
], ],
}, },

View File

@@ -20,6 +20,10 @@
<groupId>com.eshore</groupId> <groupId>com.eshore</groupId>
<artifactId>gringotts-forest</artifactId> <artifactId>gringotts-forest</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.lanyuanxiaoyao</groupId>
<artifactId>flowable-spring-boot-jpa-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>

View File

@@ -8,6 +8,7 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@@ -21,7 +22,14 @@ import org.springframework.scheduling.annotation.EnableAsync;
* @author lanyuanxiaoyao * @author lanyuanxiaoyao
* @date 2024-11-14 * @date 2024-11-14
*/ */
@SpringBootApplication(scanBasePackages = {"com.eshore.gringotts"}) @SpringBootApplication(scanBasePackages = {
"com.eshore.gringotts",
"com.lanyuanxiaoyao.flowable.jpa"
})
@EntityScan({
"com.eshore.gringotts.web.domain.entity",
"com.lanyuanxiaoyao.flowable.jpa.entity"
})
@EnableFenix @EnableFenix
@EnableJpaAuditing @EnableJpaAuditing
@EnableAsync @EnableAsync

View File

@@ -1,14 +1,10 @@
package com.eshore.gringotts.web.domain.base.entity; package com.eshore.gringotts.web.domain.base.entity;
import com.eshore.gringotts.web.domain.entity.CheckOrder;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.EntityListeners; import javax.persistence.EntityListeners;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
@@ -26,9 +22,7 @@ public class CheckingNeededEntity extends LogicDeleteEntity {
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private State state = State.DRAFT; private State state = State.DRAFT;
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY) private String flowableInstanceId;
@ToString.Exclude
private CheckOrder order;
public enum State { public enum State {
/** /**

View File

@@ -2,10 +2,8 @@ package com.eshore.gringotts.web.domain.base.service;
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity; import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository; import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.entity.CheckOrder;
import com.eshore.gringotts.web.domain.service.UserService; import com.eshore.gringotts.web.domain.service.UserService;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.eclipse.collections.api.map.ImmutableMap;
/** /**
* 需要审查 * 需要审查
@@ -22,7 +20,5 @@ public abstract class CheckingService<ENTITY extends LogicDeleteEntity> extends
abstract public void retract(Long id) throws Exception; abstract public void retract(Long id) throws Exception;
abstract public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters); abstract protected Object archive(ENTITY entity);
abstract public ImmutableMap<String, Object> archive(ENTITY entity);
} }

View File

@@ -3,18 +3,21 @@ package com.eshore.gringotts.web.domain.controller;
import com.eshore.gringotts.web.configuration.amis.AmisResponse; 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.ListController;
import com.eshore.gringotts.web.domain.base.controller.query.Query; import com.eshore.gringotts.web.domain.base.controller.query.Query;
import com.eshore.gringotts.web.domain.entity.CheckOrder; import com.eshore.gringotts.web.domain.entity.User;
import com.eshore.gringotts.web.domain.service.CheckOrderService; import com.eshore.gringotts.web.domain.service.UserService;
import com.fasterxml.jackson.core.JsonProcessingException; import com.lanyuanxiaoyao.flowable.core.model.FlowableHistory;
import com.fasterxml.jackson.core.type.TypeReference; import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
import com.fasterxml.jackson.databind.ObjectMapper; import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
import com.lanyuanxiaoyao.flowable.jpa.SpringFlowableManager;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
import lombok.Data; import lombok.Data;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; 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.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap; 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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@@ -32,55 +35,81 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("check_order") @RequestMapping("check_order")
public class CheckOrderController implements ListController<CheckOrderController.ListItem> { public class CheckOrderController implements ListController<CheckOrderController.ListItem> {
private final CheckOrderService checkOrderService; private final UserService userService;
private final ObjectMapper mapper; private final SpringFlowableManager flowableManager;
public CheckOrderController(CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { public CheckOrderController(UserService userService, SpringFlowableManager flowableManager) {
this.checkOrderService = checkOrderService; this.userService = userService;
this.mapper = builder.build(); this.flowableManager = flowableManager;
} }
@GetMapping("/list") @GetMapping("/list")
@Override @Override
public AmisResponse<ImmutableList<CheckOrderController.ListItem>> list() throws Exception { public AmisResponse<ImmutableList<CheckOrderController.ListItem>> list() throws Exception {
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem)); 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)
);
} }
@PostMapping("/list") @PostMapping("/list")
@Override @Override
public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query query) throws Exception { public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query query) throws Exception {
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem)); throw new UnsupportedOperationException();
}
@GetMapping("/approve/{instanceId}")
public AmisResponse<Object> approve(@PathVariable String instanceId) {
flowableManager.approve(instanceId);
return AmisResponse.responseSuccess();
}
@GetMapping("/reject/{instanceId}")
public AmisResponse<Object> reject(@PathVariable String instanceId) {
flowableManager.reject(instanceId);
return AmisResponse.responseSuccess();
}
@GetMapping("/history/{instanceId}")
public AmisResponse<List<FlowableHistory>> history(@PathVariable String instanceId) {
return AmisResponse.responseSuccess(flowableManager.listHistories(instanceId));
} }
@SneakyThrows @SneakyThrows
private ListItem toListItem(CheckOrder order) { private ListItem toListItem(FlowableInstance instance) {
FlowableNode node = flowableManager.getNode(instance.getCurrentNodeId());
ListItem item = new ListItem(); ListItem item = new ListItem();
item.setCheckOrderId(order.getId()); item.setInstanceId(instance.getInstanceId());
item.setDescription(order.getDescription()); item.setName(node.getName());
item.setType(order.getType()); item.setDescription(node.getDescription());
item.setParameters(mapper.readValue(order.getParameters(), new TypeReference<>() {})); item.setType(instance.getMetadata().getStringOrDefault("type", "unknown"));
item.setState(order.getState()); item.setParameters(Maps.immutable.ofAll(instance.getMetadata().getMetadata()));
item.setCreatedUsername(order.getCreatedUser().getUsername()); item.setState(instance.getStatus());
item.setCreatedTime(order.getCreatedTime()); item.setCreatedUsername(instance.getMetadata().getStringOrDefault("createdUsername", ""));
item.setModifiedUsername(order.getModifiedUser().getUsername()); item.setCreatedTime(instance.getCreatedTime());
item.setModifiedTime(order.getModifiedTime()); item.setModifiedUsername(instance.getMetadata().getStringOrDefault("modifiedUsername", ""));
item.setModifiedTime(instance.getUpdatedTime());
return item; return item;
} }
@GetMapping("/operation/{id}/{operation}")
public AmisResponse<Object> operation(@PathVariable Long id, @PathVariable CheckOrder.Operation operation) throws JsonProcessingException {
log.info("id:{}, operation:{}", id, operation);
checkOrderService.operation(id, operation);
return AmisResponse.responseSuccess();
}
@Data @Data
public static final class ListItem { public static final class ListItem {
private Long checkOrderId; private String instanceId;
private String name;
private String description; private String description;
private CheckOrder.Type type; private String type;
private ImmutableMap<String, Object> parameters; private ImmutableMap<String, Object> parameters;
private CheckOrder.State state; private FlowableInstance.Status state;
private LocalDateTime createdTime; private LocalDateTime createdTime;
private String createdUsername; private String createdUsername;
private LocalDateTime modifiedTime; private LocalDateTime modifiedTime;

View File

@@ -0,0 +1,28 @@
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);
}
}

View File

@@ -0,0 +1,31 @@
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));
}
}

View File

@@ -4,9 +4,12 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.entity.Authentication; import com.eshore.gringotts.web.domain.entity.Authentication;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.transaction.Transactional;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph; 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; import org.springframework.stereotype.Repository;
/** /**
@@ -27,4 +30,14 @@ public interface AuthenticationRepository extends SimpleRepository<Authenticatio
@Override @Override
@EntityGraph(value = "authentication.detail", type = EntityGraph.EntityGraphType.FETCH) @EntityGraph(value = "authentication.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<Authentication> findOne(Specification<Authentication> specification); 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);
} }

View File

@@ -4,9 +4,12 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.entity.Confirmation; import com.eshore.gringotts.web.domain.entity.Confirmation;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.transaction.Transactional;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph; 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; import org.springframework.stereotype.Repository;
/** /**
@@ -28,5 +31,15 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH) @EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<Confirmation> findOne(Specification<Confirmation> specification); Optional<Confirmation> findOne(Specification<Confirmation> specification);
Boolean existsByTarget_Id(Long id); @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);
} }

View File

@@ -4,9 +4,12 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.entity.Ware; import com.eshore.gringotts.web.domain.entity.Ware;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.transaction.Transactional;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph; 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; import org.springframework.stereotype.Repository;
@SuppressWarnings("NullableProblems") @SuppressWarnings("NullableProblems")
@@ -23,4 +26,14 @@ public interface WareRepository extends SimpleRepository<Ware, Long> {
@Override @Override
@EntityGraph(value = "ware.detail", type = EntityGraph.EntityGraphType.FETCH) @EntityGraph(value = "ware.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<Ware> findOne(Specification<Ware> specification); 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);
} }

View File

@@ -1,29 +1,26 @@
package com.eshore.gringotts.web.domain.service; package com.eshore.gringotts.web.domain.service;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity; 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.CheckingService;
import com.eshore.gringotts.web.domain.entity.Authentication; 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.CheckOrder;
import com.eshore.gringotts.web.domain.entity.CheckOrder_;
import com.eshore.gringotts.web.domain.entity.User; 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.eshore.gringotts.web.domain.repository.AuthenticationRepository;
import com.fasterxml.jackson.core.JsonProcessingException; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
import com.fasterxml.jackson.databind.ObjectMapper; 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 javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.ImmutableList; import org.springframework.stereotype.Component;
import org.eclipse.collections.api.map.ImmutableMap;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@@ -31,38 +28,38 @@ import org.springframework.stereotype.Service;
* @date 2024-12-02 * @date 2024-12-02
*/ */
@Slf4j @Slf4j
@Service("com.eshore.gringotts.web.domain.service.AuthenticationService") @Service
public class AuthenticationService extends CheckingService<Authentication> { public class AuthenticationService extends CheckingService<Authentication> {
private static final String AUTHENTICATION_FLOW_ID = "4ba86acd-1420-450b-98f9-0ed41772fe53";
private final AuthenticationRepository authenticationRepository; private final AuthenticationRepository authenticationRepository;
private final UserService userService; private final UserService userService;
private final CheckOrderService checkOrderService; private final SpringFlowableManager flowableManager;
private final ObjectMapper mapper;
public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager, SpringFlowableManager flowableManager) {
super(repository, userService, manager); super(repository, userService, manager);
this.authenticationRepository = repository; this.authenticationRepository = repository;
this.userService = userService; this.userService = userService;
this.checkOrderService = checkOrderService;
this.mapper = builder.build();
}
@Override this.flowableManager = flowableManager;
protected ImmutableList<Predicate> listPredicate(Root<Authentication> root, CriteriaQuery<?> query, CriteriaBuilder builder) { FlowableNode userCheckNode = FlowableNode.builder()
User loginUser = userService.currentLoginUser(); .nodeId(AUTHENTICATION_FLOW_ID)
if (User.isAdministrator(loginUser)) { .name("用户审查")
return Lists.immutable.empty(); .description("用户审查")
} .listeners(Lists.mutable.of(AuthenticationService.AuthenticationFlowUserCheckListener.class.getName()))
return Lists.immutable.of(builder.or( .accessor(UserAssessor.class.getName())
builder.equal(root.get(Authentication_.createdUser), loginUser), .targets(Maps.mutable.of(
builder.and( FlowableAction.APPROVE, "f087b0e4-0efa-4b26-945f-642436aa4aef"
builder.equal(root.get(Authentication_.order).get(CheckOrder_.target), CheckOrder.Target.ROLE), ))
builder.equal(root.get(Authentication_.order).get(CheckOrder_.targetRole), loginUser.getRole()) .build();
), FlowableNode roleCheckNode = FlowableNode.builder()
builder.and( .nodeId("f087b0e4-0efa-4b26-945f-642436aa4aef")
builder.equal(root.get(Authentication_.order).get(CheckOrder_.target), CheckOrder.Target.USER), .name("授权审查")
builder.equal(root.get(Authentication_.order).get(CheckOrder_.targetUser), loginUser) .description("授权审查")
) .listeners(Lists.mutable.of(AuthenticationService.AuthenticationFlowRoleCheckListener.class.getName()))
)); .accessor(CheckRoleAssessor.class.getName())
.build();
flowableManager.create(userCheckNode, roleCheckNode);
} }
@Override @Override
@@ -82,73 +79,34 @@ public class AuthenticationService extends CheckingService<Authentication> {
return super.save(entity); return super.save(entity);
} }
@Transactional(rollbackOn = Throwable.class)
@Override @Override
public void submit(Long id) throws JsonProcessingException { public void submit(Long id) {
User user = userService.currentLoginUser();
Authentication authentication = detailOrThrow(id); Authentication authentication = detailOrThrow(id);
authentication.setState(CheckingNeededEntity.State.OWNER_CHECKING); String instanceId = flowableManager.start(
Long orderId = checkOrderService.save(new CheckOrder( AUTHENTICATION_FLOW_ID,
"authentication_owner_check", MapUtil.<String, Object>builder()
StrUtil.format("数据资源「{}」的授权申请", authentication.getTarget().getName()), .put("authenticationId", id)
CheckOrder.Type.AUTHENTICATION, .put("type", "AUTHENTICATION")
mapper.writeValueAsString(Maps.immutable.of("authenticationId", authentication.getId())), .put("createdUsername", user.getUsername())
"com.eshore.gringotts.web.domain.service.AuthenticationService", .put("modifiedUsername", user.getUsername())
authentication.getCreatedUser() .put(UserAssessor.KEY, authentication.getTarget().getCreatedUser().getId())
)); .build(),
CheckOrder order = checkOrderService.detailOrThrow(orderId); authentication.getTarget().getCreatedUser().getId().toString()
authentication.setOrder(order); );
save(authentication); authenticationRepository.updateInstanceIdById(id, instanceId);
authenticationRepository.updateStateById(id, Confirmation.State.CHECKING);
} }
@Transactional(rollbackOn = Throwable.class)
@Override @Override
public void retract(Long id) { public void retract(Long id) {
Authentication authentication = detailOrThrow(id); Authentication authentication = detailOrThrow(id);
authentication.setState(Authentication.State.DRAFT); flowableManager.terminal(authentication.getFlowableInstanceId());
save(authentication);
CheckOrder order = authentication.getOrder();
order.setState(CheckOrder.State.RETRACT);
checkOrderService.save(order);
} }
@Override @Override
@Transactional(rollbackOn = Throwable.class) protected Object archive(Authentication entity) {
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) { return "";
Long id = (Long) parameters.get("authenticationId");
Authentication authentication = detailOrThrow(id);
if (StrUtil.equals(order.getKeyword(), "authentication_owner_check")) {
switch (operation) {
case APPLY:
authentication.setState(Authentication.State.CHECKING);
order.setKeyword("authentication_checker_check");
order.setTarget(CheckOrder.Target.ROLE);
order.setTargetRole(User.Role.CHECKER);
break;
case REJECT:
authentication.setState(Authentication.State.DRAFT);
order.setState(CheckOrder.State.OVER);
break;
}
} else if (StrUtil.equals(order.getKeyword(), "authentication_checker_check")) {
switch (operation) {
case APPLY:
authentication.setState(Authentication.State.NORMAL);
order.setState(CheckOrder.State.OVER);
break;
case REJECT:
authentication.setState(Authentication.State.DRAFT);
order.setState(CheckOrder.State.OVER);
break;
}
}
save(authentication);
checkOrderService.save(order);
}
@Override
public ImmutableMap<String, Object> archive(Authentication authentication) {
return null;
} }
public static final class AuthenticationDuplicatedException extends RuntimeException { public static final class AuthenticationDuplicatedException extends RuntimeException {
@@ -156,4 +114,44 @@ public class AuthenticationService extends CheckingService<Authentication> {
super("数据资源已绑定该账号的授权申请,无法再次申请"); 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);
}
}
}
} }

View File

@@ -1,82 +0,0 @@
package com.eshore.gringotts.web.domain.service;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.eshore.gringotts.web.domain.base.service.CheckingService;
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
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 com.eshore.gringotts.web.domain.repository.CheckOrderRepository;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
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.eclipse.collections.api.map.ImmutableMap;
import org.springframework.context.ApplicationContext;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Service;
/**
* @author lanyuanxiaoyao
* @date 2024-11-29
*/
@Slf4j
@Service
public class CheckOrderService extends SimpleServiceSupport<CheckOrder> {
private final ApplicationContext applicationContext;
private final ObjectMapper mapper;
private final CheckOrderRepository checkOrderRepository;
private final UserService userService;
public CheckOrderService(CheckOrderRepository repository, UserService userService, ApplicationContext applicationContext, Jackson2ObjectMapperBuilder builder) {
super(repository, userService);
this.applicationContext = applicationContext;
this.mapper = builder.build();
this.checkOrderRepository = repository;
this.userService = userService;
}
@Override
protected ImmutableList<Predicate> listPredicate(Root<CheckOrder> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
User user = userService.currentLoginUser();
if (User.isAdministrator(user)) {
return Lists.immutable.empty();
}
return Lists.immutable.of(builder.or(
builder.equal(root.get(CheckOrder_.createdUser), user),
builder.and(
builder.equal(root.get(CheckOrder_.target), CheckOrder.Target.USER),
builder.equal(root.get(CheckOrder_.targetUser), user)
),
builder.and(
builder.equal(root.get(CheckOrder_.target), CheckOrder.Target.ROLE),
builder.equal(root.get(CheckOrder_.targetRole), user.getRole())
)
));
}
public void operation(Long id, CheckOrder.Operation operation) throws JsonProcessingException {
CheckOrder order = detailOrThrow(id);
CheckingService service = applicationContext.getBean(order.getTargetClass(), CheckingService.class);
if (ObjectUtil.isNull(service)) {
throw new RuntimeException(StrUtil.format("名为「{}」的服务未找到", order.getTargetClass()));
}
ImmutableMap<String, Object> parameters = mapper.readValue(order.getParameters(), new TypeReference<>() {});
service.onChecked(order, operation, parameters);
}
public void retract(Long id) {
checkOrderRepository.overById(id, CheckOrder.State.RETRACT, userService.currentLoginUser());
}
public void over(Long id) {
checkOrderRepository.overById(id, CheckOrder.State.OVER, userService.currentLoginUser());
}
}

View File

@@ -1,31 +1,24 @@
package com.eshore.gringotts.web.domain.service; package com.eshore.gringotts.web.domain.service;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
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.CheckingService;
import com.eshore.gringotts.web.domain.entity.CheckOrder;
import com.eshore.gringotts.web.domain.entity.CheckOrder_;
import com.eshore.gringotts.web.domain.entity.Confirmation; 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.entity.User;
import com.eshore.gringotts.web.domain.flowable.CheckRoleAssessor;
import com.eshore.gringotts.web.domain.repository.ConfirmationRepository; import com.eshore.gringotts.web.domain.repository.ConfirmationRepository;
import com.fasterxml.jackson.core.JsonProcessingException; import com.eshore.gringotts.web.helper.AmisHelper;
import com.fasterxml.jackson.databind.ObjectMapper; 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 javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps; import org.springframework.stereotype.Component;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@@ -33,42 +26,68 @@ import org.springframework.stereotype.Service;
* @date 2024-11-26 * @date 2024-11-26
*/ */
@Slf4j @Slf4j
@Service("com.eshore.gringotts.web.domain.service.ConfirmationService") @Service
public class ConfirmationService extends CheckingService<Confirmation> { public class ConfirmationService extends CheckingService<Confirmation> {
private final ConfirmationRepository confirmationRepository; private static final String CONFIRMATION_FLOW_ID = "69d8ded5-35fd-4f03-b11a-be0ed91a4b8b";
private final CheckOrderService checkOrderService;
private final ObjectMapper mapper;
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { private final ConfirmationRepository confirmationRepository;
private final SpringFlowableManager flowableManager;
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager, SpringFlowableManager flowableManager) {
super(confirmationRepository, userService, entityManager); super(confirmationRepository, userService, entityManager);
this.confirmationRepository = confirmationRepository; this.confirmationRepository = confirmationRepository;
this.checkOrderService = checkOrderService;
this.mapper = builder.build(); 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 @Override
protected ImmutableList<Predicate> listPredicate(Root<Confirmation> root, CriteriaQuery<?> query, CriteriaBuilder builder) { public void submit(Long id) {
User loginUser = userService.currentLoginUser(); Confirmation confirmation = detailOrThrow(id);
if (User.isAdministrator(loginUser)) { User user = userService.currentLoginUser();
return Lists.immutable.empty(); 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);
} }
Join<Confirmation, CheckOrder> orderJoin = root.join(Confirmation_.order, JoinType.LEFT);
return Lists.immutable.of(builder.or( @Override
builder.equal(root.get(Confirmation_.createdUser), loginUser), public void retract(Long id) {
builder.and( Confirmation confirmation = detailOrThrow(id);
builder.isNotNull(orderJoin), flowableManager.terminal(confirmation.getFlowableInstanceId());
builder.or( }
builder.and(
builder.equal(orderJoin.get(CheckOrder_.target), CheckOrder.Target.ROLE), @Override
builder.equal(orderJoin.get(CheckOrder_.targetRole), loginUser.getRole()) protected Object archive(Confirmation entity) {
DataResource resource = entity.getTarget();
return AmisHelper.wrapper(
AmisHelper.property(
AmisHelper.propertyItem("资源名称", resource.getName(), 3),
AmisHelper.propertyItem("资源描述", resource.getDescription(), 3)
), ),
builder.and( AmisHelper.divider(),
builder.equal(orderJoin.get(CheckOrder_.target), CheckOrder.Target.USER), AmisHelper.property(resource.getType()),
builder.equal(orderJoin.get(CheckOrder_.targetUser), loginUser) AmisHelper.divider(),
) AmisHelper.property(resource.getFormat()),
) AmisHelper.divider(),
) AmisHelper.property(entity)
)); );
} }
@Override @Override
@@ -79,65 +98,29 @@ public class ConfirmationService extends CheckingService<Confirmation> {
return super.save(entity); return super.save(entity);
} }
@Transactional(rollbackOn = Throwable.class)
@Override
public void submit(Long id) throws JsonProcessingException {
Confirmation confirmation = detailOrThrow(id);
confirmation.setState(Confirmation.State.CHECKING);
Long orderId = checkOrderService.save(new CheckOrder(
"confirmation_check",
StrUtil.format("数据资源「{}」的确权申请", confirmation.getTarget().getName()),
CheckOrder.Type.CONFIRMATION,
mapper.writeValueAsString(Maps.immutable.of("confirmationId", confirmation.getId())),
"com.eshore.gringotts.web.domain.service.ConfirmationService",
User.Role.CHECKER
));
CheckOrder order = checkOrderService.detailOrThrow(orderId);
confirmation.setOrder(order);
save(confirmation);
}
@Transactional(rollbackOn = Throwable.class)
@Override
public void retract(Long id) {
Confirmation confirmation = detailOrThrow(id);
confirmation.setState(CheckingNeededEntity.State.DRAFT);
save(confirmation);
CheckOrder order = confirmation.getOrder();
order.setState(CheckOrder.State.RETRACT);
checkOrderService.save(order);
}
@Override
@Transactional(rollbackOn = Throwable.class)
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
if (StrUtil.equals(order.getKeyword(), "confirmation_check")) {
Long id = (Long) parameters.get("confirmationId");
Confirmation confirmation = detailOrThrow(id);
switch (operation) {
case APPLY:
confirmation.setState(Confirmation.State.NORMAL);
order.setState(CheckOrder.State.OVER);
break;
case REJECT:
confirmation.setState(Confirmation.State.DRAFT);
order.setState(CheckOrder.State.OVER);
break;
}
save(confirmation);
checkOrderService.save(order);
}
}
@Override
public ImmutableMap<String, Object> archive(Confirmation confirmation) {
return null;
}
public static final class ConfirmationDuplicatedException extends RuntimeException { public static final class ConfirmationDuplicatedException extends RuntimeException {
public ConfirmationDuplicatedException() { public ConfirmationDuplicatedException() {
super("数据资源已绑定确权申请,无法再次申请"); 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);
}
}
}
} }

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.DataResourceRepository;
import com.eshore.gringotts.web.domain.repository.ResourceFormatRepository; import com.eshore.gringotts.web.domain.repository.ResourceFormatRepository;
import com.eshore.gringotts.web.domain.repository.ResourceTypeRepository; import com.eshore.gringotts.web.domain.repository.ResourceTypeRepository;
import com.eshore.gringotts.web.helper.EntityHelper;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@@ -56,26 +55,8 @@ public class DataResourceService extends LogicDeleteService<DataResource> {
return Lists.immutable.empty(); 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( 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)
)); ));
} }

View File

@@ -1,21 +1,22 @@
package com.eshore.gringotts.web.domain.service; package com.eshore.gringotts.web.domain.service;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.map.MapUtil;
import com.eshore.gringotts.web.domain.base.service.CheckingService; import com.eshore.gringotts.web.domain.base.service.CheckingService;
import com.eshore.gringotts.web.domain.entity.CheckOrder;
import com.eshore.gringotts.web.domain.entity.User; import com.eshore.gringotts.web.domain.entity.User;
import com.eshore.gringotts.web.domain.entity.Ware; 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.eshore.gringotts.web.domain.repository.WareRepository;
import com.fasterxml.jackson.core.JsonProcessingException; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
import com.fasterxml.jackson.databind.ObjectMapper; 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 javax.persistence.EntityManager;
import javax.transaction.Transactional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists; 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.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap; import org.springframework.stereotype.Component;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@@ -23,17 +24,28 @@ import org.springframework.stereotype.Service;
* @date 2024-12-13 * @date 2024-12-13
*/ */
@Slf4j @Slf4j
@Service("com.eshore.gringotts.web.domain.service.WareService") @Service
public class WareService extends CheckingService<Ware> { public class WareService extends CheckingService<Ware> {
private final WareRepository wareRepository; private static final String WARE_FLOW_ID = "870e7376-1713-48ed-9e60-e602981c6ecc";
private final CheckOrderService checkOrderService;
private final ObjectMapper mapper;
public WareService(WareRepository repository, UserService userService, EntityManager entityManager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { private final WareRepository wareRepository;
private final UserService userService;
private final SpringFlowableManager flowableManager;
public WareService(WareRepository repository, UserService userService, EntityManager entityManager, SpringFlowableManager flowableManager) {
super(repository, userService, entityManager); super(repository, userService, entityManager);
this.wareRepository = repository; this.wareRepository = repository;
this.checkOrderService = checkOrderService; this.userService = userService;
this.mapper = builder.build();
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() { public ImmutableList<Ware> listPublic() {
@@ -42,59 +54,53 @@ public class WareService extends CheckingService<Ware> {
); );
} }
@Transactional(rollbackOn = Throwable.class)
@Override @Override
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) { public void submit(Long id) {
if (StrUtil.equals(order.getKeyword(), "ware_check")) { User user = userService.currentLoginUser();
Long wareId = (Long) parameters.get("wareId");
Ware ware = detailOrThrow(wareId);
switch (operation) {
case APPLY:
ware.setState(Ware.State.NORMAL);
order.setState(CheckOrder.State.OVER);
break;
case REJECT:
ware.setState(Ware.State.DRAFT);
order.setState(CheckOrder.State.OVER);
break;
}
save(ware);
checkOrderService.save(order);
}
}
@Override
public ImmutableMap<String, Object> archive(Ware ware) {
return null;
}
@Transactional(rollbackOn = Throwable.class)
@Override
public void submit(Long id) throws JsonProcessingException {
Ware ware = detailOrThrow(id); Ware ware = detailOrThrow(id);
ware.setState(Ware.State.CHECKING); String instanceId = flowableManager.start(
Long orderId = checkOrderService.save(new CheckOrder( WARE_FLOW_ID,
"ware_check", MapUtil.<String, Object>builder()
StrUtil.format("数据资源「{}」的上架申请", ware.getName()), .put("wareId", id)
CheckOrder.Type.MARKET, .put("type", "WARE")
mapper.writeValueAsString(Maps.immutable.of("wareId", ware.getId())), .put("createdUsername", user.getUsername())
"com.eshore.gringotts.web.domain.service.WareService", .put("modifiedUsername", user.getUsername())
User.Role.CHECKER .put(UserAssessor.KEY, ware.getResource().getCreatedUser().getId())
)); .build(),
CheckOrder order = checkOrderService.detailOrThrow(orderId); ware.getResource().getCreatedUser().getId().toString()
ware.setOrder(order); );
save(ware); wareRepository.updateInstanceIdById(id, instanceId);
wareRepository.updateStateById(id, Ware.State.CHECKING);
} }
@Transactional(rollbackOn = Throwable.class)
@Override @Override
public void retract(Long id) { public void retract(Long id) {
Ware ware = detailOrThrow(id); Ware ware = detailOrThrow(id);
ware.setState(Ware.State.DRAFT); flowableManager.terminal(ware.getFlowableInstanceId());
save(ware); }
CheckOrder order = ware.getOrder(); @Override
order.setState(CheckOrder.State.RETRACT); protected Object archive(Ware entity) {
checkOrderService.save(order); 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);
}
}
} }
} }

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 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.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 com.eshore.gringotts.web.domain.entity.User;
import java.util.function.Supplier; import java.util.function.Supplier;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
@@ -28,14 +25,14 @@ public class EntityHelper {
public static Predicate checkNeededEntityPrediction(Root<? extends CheckingNeededEntity> root, CriteriaBuilder builder, User loginUser) { public static Predicate checkNeededEntityPrediction(Root<? extends CheckingNeededEntity> root, CriteriaBuilder builder, User loginUser) {
return builder.or( 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_.target), CheckOrder.Target.ROLE),
builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.targetRole), loginUser.getRole()) builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.targetRole), loginUser.getRole())
), ),
builder.and( builder.and(
builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.target), CheckOrder.Target.USER), builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.target), CheckOrder.Target.USER),
builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.targetUser), loginUser) builder.equal(root.get(CheckingNeededEntity_.order).get(CheckOrder_.targetUser), loginUser)
) ) */
); );
} }
} }

View File

@@ -60,6 +60,13 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- Private Dependencies -->
<dependency>
<groupId>com.lanyuanxiaoyao</groupId>
<artifactId>flowable-spring-boot-jpa-starter</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- Spring Dependencies --> <!-- Spring Dependencies -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>