feat(web): 增加工单审批流结构
This commit is contained in:
@@ -187,6 +187,11 @@ export const checkTypeMapping = [
|
|||||||
mappingItem('授权审查', 'AUTHENTICATION', 'bg-purple-500'),
|
mappingItem('授权审查', 'AUTHENTICATION', 'bg-purple-500'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const checkOverMapping = [
|
||||||
|
mappingItem('完结', 'true', 'bg-success'),
|
||||||
|
mappingItem('进行中', 'false', 'bg-primary'),
|
||||||
|
]
|
||||||
|
|
||||||
function api(method, url) {
|
function api(method, url) {
|
||||||
return {
|
return {
|
||||||
method: method,
|
method: method,
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ useAmis(information => {
|
|||||||
tabs: [
|
tabs: [
|
||||||
// tabOverview(),
|
// tabOverview(),
|
||||||
// tabMarket(),
|
// tabMarket(),
|
||||||
tabData(),
|
|
||||||
tabCheck(),
|
tabCheck(),
|
||||||
|
tabData(),
|
||||||
tabPermissions(),
|
tabPermissions(),
|
||||||
tabUser(),
|
tabUser(),
|
||||||
tabSettings(),
|
tabSettings(),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
apiGet,
|
apiGet,
|
||||||
apiPost,
|
|
||||||
checkerOnly,
|
checkerOnly,
|
||||||
|
checkOverMapping,
|
||||||
checkTypeMapping,
|
checkTypeMapping,
|
||||||
crudCommonOptions,
|
crudCommonOptions,
|
||||||
mappingField
|
mappingField
|
||||||
@@ -17,14 +17,14 @@ export function tabCheck() {
|
|||||||
body: [
|
body: [
|
||||||
{
|
{
|
||||||
type: 'crud',
|
type: 'crud',
|
||||||
api: apiGet('${base}/check/list'),
|
api: apiGet('${base}/check_order/list'),
|
||||||
...crudCommonOptions(),
|
...crudCommonOptions(),
|
||||||
headerToolbar: [
|
headerToolbar: [
|
||||||
'reload',
|
'reload',
|
||||||
],
|
],
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'description',
|
||||||
label: '描述',
|
label: '描述',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -33,6 +33,12 @@ export function tabCheck() {
|
|||||||
align: 'center',
|
align: 'center',
|
||||||
...mappingField('type', checkTypeMapping)
|
...mappingField('type', checkTypeMapping)
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: '状态',
|
||||||
|
width: 80,
|
||||||
|
align: 'center',
|
||||||
|
...mappingField('over', checkOverMapping)
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: '操作',
|
label: '操作',
|
||||||
width: 100,
|
width: 100,
|
||||||
@@ -41,6 +47,7 @@ export function tabCheck() {
|
|||||||
className: 'nowrap',
|
className: 'nowrap',
|
||||||
buttons: [
|
buttons: [
|
||||||
{
|
{
|
||||||
|
visibleOn: '${!over}',
|
||||||
type: 'action',
|
type: 'action',
|
||||||
label: '处理',
|
label: '处理',
|
||||||
level: 'link',
|
level: 'link',
|
||||||
@@ -48,19 +55,17 @@ export function tabCheck() {
|
|||||||
'parameters.confirmationId',
|
'parameters.confirmationId',
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: 'each',
|
type: 'action',
|
||||||
name: 'operations',
|
label: '同意',
|
||||||
items: {
|
actionType: 'ajax',
|
||||||
type: 'action',
|
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY')
|
||||||
label: '${item.name}',
|
|
||||||
level: '${item.level}',
|
|
||||||
actionType: 'ajax',
|
|
||||||
api: {
|
|
||||||
...apiPost('${base}/check/operation/${item.operation}'),
|
|
||||||
data: '${parameters}'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '拒绝',
|
||||||
|
actionType: 'ajax',
|
||||||
|
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT')
|
||||||
|
}
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ToString
|
@ToString(callSuper = true)
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class SimpleEntity extends IdOnlyEntity {
|
public class SimpleEntity extends IdOnlyEntity {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.eshore.gringotts.web.domain.base.service;
|
package com.eshore.gringotts.web.domain.base.service;
|
||||||
|
|
||||||
import lombok.Data;
|
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||||
import lombok.Value;
|
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
|
||||||
import org.eclipse.collections.api.map.ImmutableMap;
|
import org.eclipse.collections.api.map.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,40 +10,5 @@ import org.eclipse.collections.api.map.ImmutableMap;
|
|||||||
* @date 2024-11-28
|
* @date 2024-11-28
|
||||||
*/
|
*/
|
||||||
public interface CheckingService {
|
public interface CheckingService {
|
||||||
ImmutableList<CheckOrder> checkingList();
|
void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters);
|
||||||
|
|
||||||
void onChecked(String operation, ImmutableMap<String, Object> parameters);
|
|
||||||
|
|
||||||
@Value
|
|
||||||
class CheckOrder {
|
|
||||||
String name;
|
|
||||||
Type type;
|
|
||||||
ImmutableList<CheckOperation> operations;
|
|
||||||
ImmutableMap<String, Object> parameters;
|
|
||||||
|
|
||||||
public enum Type {
|
|
||||||
CONFIRMATION,
|
|
||||||
AUTHENTICATION,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
class CheckOperation {
|
|
||||||
/**
|
|
||||||
* 全局唯一
|
|
||||||
*/
|
|
||||||
private final String operation;
|
|
||||||
private final String name;
|
|
||||||
private final String level;
|
|
||||||
|
|
||||||
public CheckOperation(String operation, String name) {
|
|
||||||
this(operation, name, "default");
|
|
||||||
}
|
|
||||||
|
|
||||||
public CheckOperation(String operation, String name, String level) {
|
|
||||||
this.operation = operation;
|
|
||||||
this.name = name;
|
|
||||||
this.level = level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
package com.eshore.gringotts.web.domain.check.controller;
|
package com.eshore.gringotts.web.domain.check.controller;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
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.service.CheckingService;
|
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||||
|
import com.eshore.gringotts.web.domain.check.service.CheckOrderService;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.Data;
|
||||||
|
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.eclipse.collections.api.map.MutableMap;
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
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.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -26,36 +26,46 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("check")
|
@RequestMapping("check_order")
|
||||||
public class CheckController implements ListController<CheckingService.CheckOrder> {
|
public class CheckController implements ListController<CheckController.ListItem> {
|
||||||
private final ImmutableList<CheckingService> checkingServices;
|
private final CheckOrderService checkOrderService;
|
||||||
private final MutableMap<String, CheckingService> serviceMap = Maps.mutable.<String, CheckingService>empty().asSynchronized();
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
public CheckController(ApplicationContext applicationContext) {
|
public CheckController(CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||||
this.checkingServices = Lists.immutable.ofAll(applicationContext.getBeansOfType(CheckingService.class).values());
|
this.checkOrderService = checkOrderService;
|
||||||
|
this.mapper = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Override
|
@Override
|
||||||
public AmisResponse<ImmutableList<CheckingService.CheckOrder>> list() throws Exception {
|
public AmisResponse<ImmutableList<CheckController.ListItem>> list() throws Exception {
|
||||||
return AmisResponse.responseSuccess(
|
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem));
|
||||||
checkingServices.flatCollect(checkingService -> {
|
|
||||||
ImmutableList<CheckingService.CheckOrder> orders = checkingService.checkingList();
|
|
||||||
orders.flatCollect(CheckingService.CheckOrder::getOperations)
|
|
||||||
.forEach(operation -> serviceMap.put(operation.getOperation(), checkingService));
|
|
||||||
return orders;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/operation/{operation}")
|
@SneakyThrows
|
||||||
public AmisResponse<Object> operation(@PathVariable String operation, @RequestBody ImmutableMap<String, Object> data) {
|
private ListItem toListItem(CheckOrder order) {
|
||||||
log.info("Check operation: {} data: {} target: {}", operation, data, serviceMap.get(operation).getClass().getSimpleName());
|
ListItem item = new ListItem();
|
||||||
CheckingService service = serviceMap.getOrDefault(operation, null);
|
item.setCheckOrderId(order.getId());
|
||||||
if (ObjectUtil.isNull(service)) {
|
item.setDescription(order.getDescription());
|
||||||
throw new RuntimeException("服务未找到");
|
item.setType(order.getType());
|
||||||
}
|
item.setParameters(mapper.readValue(order.getParameters(), new TypeReference<>() {}));
|
||||||
service.onChecked(operation, data);
|
item.setOver(order.getOver());
|
||||||
|
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();
|
return AmisResponse.responseSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static final class ListItem {
|
||||||
|
private Long checkOrderId;
|
||||||
|
private String description;
|
||||||
|
private CheckOrder.Type type;
|
||||||
|
private ImmutableMap<String, Object> parameters;
|
||||||
|
private Boolean over;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.check.entity;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.core.Constants;
|
||||||
|
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||||
|
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.ConstraintMode;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EntityListeners;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
|
import javax.persistence.ForeignKey;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.NamedAttributeNode;
|
||||||
|
import javax.persistence.NamedEntityGraph;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-29
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Entity
|
||||||
|
@DynamicUpdate
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@Table(name = Constants.TABLE_PREFIX + "check_order")
|
||||||
|
@NamedEntityGraph(name = "check_order.list", attributeNodes = {
|
||||||
|
@NamedAttributeNode(value = "createdUser"),
|
||||||
|
})
|
||||||
|
@NamedEntityGraph(name = "check_order.detail", attributeNodes = {
|
||||||
|
@NamedAttributeNode(value = "createdUser"),
|
||||||
|
@NamedAttributeNode(value = "modifiedUser"),
|
||||||
|
})
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CheckOrder extends SimpleEntity {
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String key;
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String description;
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private Type type;
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Boolean over = false;
|
||||||
|
|
||||||
|
public CheckOrder(
|
||||||
|
String key,
|
||||||
|
String description,
|
||||||
|
Type type,
|
||||||
|
String parameters,
|
||||||
|
String targetClass,
|
||||||
|
User targetUser
|
||||||
|
) {
|
||||||
|
this.key = key;
|
||||||
|
this.description = description;
|
||||||
|
this.type = type;
|
||||||
|
this.parameters = parameters;
|
||||||
|
this.target = Target.USER;
|
||||||
|
this.targetClass = targetClass;
|
||||||
|
this.targetUser = targetUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckOrder(
|
||||||
|
String key,
|
||||||
|
String description,
|
||||||
|
Type type,
|
||||||
|
String parameters,
|
||||||
|
String targetClass,
|
||||||
|
User.Role targetRole
|
||||||
|
) {
|
||||||
|
this.key = key;
|
||||||
|
this.description = description;
|
||||||
|
this.type = type;
|
||||||
|
this.parameters = parameters;
|
||||||
|
this.target = Target.ROLE;
|
||||||
|
this.targetClass = targetClass;
|
||||||
|
this.targetRole = targetRole;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Operation {
|
||||||
|
APPLY,
|
||||||
|
REJECT,
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
CONFIRMATION,
|
||||||
|
AUTHENTICATION,
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Target {
|
||||||
|
USER,
|
||||||
|
ROLE,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.check.repository;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||||
|
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||||
|
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-29
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
|
@Repository
|
||||||
|
public interface CheckOrderRepository extends SimpleRepository<CheckOrder, Long> {
|
||||||
|
@Override
|
||||||
|
@EntityGraph(value = "check_order.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||||
|
List<CheckOrder> findAll(Specification<CheckOrder> specification);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@EntityGraph(value = "check_order.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||||
|
List<CheckOrder> findAll(Specification<CheckOrder> specification, Sort sort);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@EntityGraph(value = "check_order.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||||
|
Optional<CheckOrder> findOne(Specification<CheckOrder> specification);
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Modifying
|
||||||
|
@Query("update CheckOrder check set check.over = true, check.modifiedUser = ?2, check.modifiedTime = current_timestamp where check.id = ?1")
|
||||||
|
void overById(Long id, User modifiedUser);
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.check.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.check.entity.CheckOrder;
|
||||||
|
import com.eshore.gringotts.web.domain.check.repository.CheckOrderRepository;
|
||||||
|
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 over(Long id) {
|
||||||
|
checkOrderRepository.overById(id, userService.currentLoginUser());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
|||||||
import com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService;
|
import com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService;
|
||||||
import com.eshore.gringotts.web.domain.resource.service.DataResourceService;
|
import com.eshore.gringotts.web.domain.resource.service.DataResourceService;
|
||||||
import com.eshore.gringotts.web.domain.upload.service.DataFileService;
|
import com.eshore.gringotts.web.domain.upload.service.DataFileService;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@@ -40,7 +41,7 @@ public class ConfirmationController extends SimpleControllerSupport<Confirmation
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/submit/{id}")
|
@GetMapping("/submit/{id}")
|
||||||
public AmisResponse<Object> submit(@PathVariable Long id) {
|
public AmisResponse<Object> submit(@PathVariable Long id) throws JsonProcessingException {
|
||||||
confirmationService.submit(id);
|
confirmationService.submit(id);
|
||||||
return AmisResponse.responseSuccess();
|
return AmisResponse.responseSuccess();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ToString
|
@ToString(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@DynamicUpdate
|
@DynamicUpdate
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
|||||||
@@ -4,14 +4,19 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||||
|
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||||
|
import com.eshore.gringotts.web.domain.check.service.CheckOrderService;
|
||||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||||
import com.eshore.gringotts.web.domain.confirmation.repository.ConfirmationRepository;
|
import com.eshore.gringotts.web.domain.confirmation.repository.ConfirmationRepository;
|
||||||
|
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
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.Maps;
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
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.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,15 +24,19 @@ import org.springframework.stereotype.Service;
|
|||||||
* @date 2024-11-26
|
* @date 2024-11-26
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service("com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService")
|
||||||
public class ConfirmationService extends SimpleServiceSupport<Confirmation> implements CheckingService {
|
public class ConfirmationService extends SimpleServiceSupport<Confirmation> implements CheckingService {
|
||||||
private final ConfirmationRepository confirmationRepository;
|
private final ConfirmationRepository confirmationRepository;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final CheckOrderService checkOrderService;
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService) {
|
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||||
super(confirmationRepository, userService);
|
super(confirmationRepository, userService);
|
||||||
this.confirmationRepository = confirmationRepository;
|
this.confirmationRepository = confirmationRepository;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.checkOrderService = checkOrderService;
|
||||||
|
this.mapper = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,8 +47,20 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> impl
|
|||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void submit(Long id) {
|
@Transactional(rollbackOn = Throwable.class)
|
||||||
confirmationRepository.updateStateById(id, Confirmation.State.CHECKING, userService.currentLoginUser());
|
public void submit(Long id) throws JsonProcessingException {
|
||||||
|
Confirmation confirmation = detailOrThrow(id);
|
||||||
|
log.info("confirmation: {}", confirmation);
|
||||||
|
confirmation.setState(Confirmation.State.CHECKING);
|
||||||
|
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.confirmation.service.ConfirmationService",
|
||||||
|
User.Role.ADMINISTRATOR
|
||||||
|
));
|
||||||
|
save(confirmation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void retract(Long id) {
|
public void retract(Long id) {
|
||||||
@@ -47,33 +68,19 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableList<CheckOrder> checkingList() {
|
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
|
||||||
return Lists.immutable.ofAll(
|
if (StrUtil.equals(order.getKey(), "confirmation_check")) {
|
||||||
confirmationRepository.findAll(
|
Long id = (Long) parameters.get("confirmationId");
|
||||||
(root, query, builder) -> builder.equal(root.get("state"), Confirmation.State.CHECKING)
|
switch (operation) {
|
||||||
)
|
case APPLY:
|
||||||
)
|
confirmationRepository.updateStateById(id, Confirmation.State.NORMAL, userService.currentLoginUser());
|
||||||
.collect(confirmation -> new CheckOrder(
|
checkOrderService.over(order.getId());
|
||||||
StrUtil.format("资源名为「{}」的确权申请", confirmation.getTarget().getName()),
|
break;
|
||||||
CheckOrder.Type.CONFIRMATION,
|
case REJECT:
|
||||||
Lists.immutable.of(
|
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
|
||||||
new CheckOperation("confirmation_check_apply", "通过"),
|
checkOrderService.over(order.getId());
|
||||||
new CheckOperation("confirmation_check_reject", "拒绝", "danger")
|
break;
|
||||||
),
|
}
|
||||||
Maps.immutable.of("confirmationId", confirmation.getId())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChecked(String operation, ImmutableMap<String, Object> parameters) {
|
|
||||||
Long id = (Long) parameters.get("confirmationId");
|
|
||||||
switch (operation) {
|
|
||||||
case "confirmation_check_apply":
|
|
||||||
confirmationRepository.updateStateById(id, Confirmation.State.NORMAL, userService.currentLoginUser());
|
|
||||||
break;
|
|
||||||
case "confirmation_check_reject":
|
|
||||||
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ToString
|
@ToString(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
@DynamicUpdate
|
@DynamicUpdate
|
||||||
|
|||||||
Reference in New Issue
Block a user