1
0

feat(web): 增加确权状态审查

This commit is contained in:
2024-11-28 17:39:43 +08:00
parent 00e88078a2
commit 58f2173fb0
10 changed files with 217 additions and 41 deletions

View File

@@ -0,0 +1,45 @@
package com.eshore.gringotts.web.domain.base.service;
import lombok.Data;
import lombok.Value;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;
/**
* 需要审查
*
* @author lanyuanxiaoyao
* @date 2024-11-28
*/
public interface CheckingService {
ImmutableList<CheckOrder> checkingList();
void onChecked(String operation, ImmutableMap<String, Object> parameters);
@Value
class CheckOrder {
String name;
ImmutableList<CheckOperation> operations;
ImmutableMap<String, Object> parameters;
}
@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;
}
}
}

View File

@@ -0,0 +1,61 @@
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.domain.base.controller.ListController;
import com.eshore.gringotts.web.domain.base.service.CheckingService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.MutableMap;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
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.RestController;
/**
* 监管
*
* @author lanyuanxiaoyao
* @date 2024-11-28
*/
@Slf4j
@RestController
@RequestMapping("check")
public class CheckController implements ListController<CheckingService.CheckOrder> {
private final ImmutableList<CheckingService> checkingServices;
private final MutableMap<String, CheckingService> serviceMap = Maps.mutable.<String, CheckingService>empty().asSynchronized();
public CheckController(ApplicationContext applicationContext) {
this.checkingServices = Lists.immutable.ofAll(applicationContext.getBeansOfType(CheckingService.class).values());
}
@GetMapping("/list")
@Override
public AmisResponse<ImmutableList<CheckingService.CheckOrder>> list() throws Exception {
return AmisResponse.responseSuccess(
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}")
public AmisResponse<Object> operation(@PathVariable String operation, @RequestBody ImmutableMap<String, Object> data) {
log.info("Check operation: {} data: {} target: {}", operation, data, serviceMap.get(operation).getClass().getSimpleName());
CheckingService service = serviceMap.getOrDefault(operation, null);
if (ObjectUtil.isNull(service)) {
throw new RuntimeException("服务未找到");
}
service.onChecked(operation, data);
return AmisResponse.responseSuccess();
}
}

View File

@@ -20,6 +20,10 @@ import org.springframework.stereotype.Repository;
@SuppressWarnings("NullableProblems")
@Repository
public interface ConfirmationRepository extends SimpleRepository<Confirmation, Long> {
@Override
@EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH)
List<Confirmation> findAll(Specification<Confirmation> specification);
@Override
@EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH)
List<Confirmation> findAll(Specification<Confirmation> specification, Sort sort);

View File

@@ -1,11 +1,17 @@
package com.eshore.gringotts.web.domain.confirmation.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.confirmation.entity.Confirmation;
import com.eshore.gringotts.web.domain.confirmation.repository.ConfirmationRepository;
import com.eshore.gringotts.web.domain.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.springframework.stereotype.Service;
/**
@@ -14,7 +20,7 @@ import org.springframework.stereotype.Service;
*/
@Slf4j
@Service
public class ConfirmationService extends SimpleServiceSupport<Confirmation> {
public class ConfirmationService extends SimpleServiceSupport<Confirmation> implements CheckingService {
private final ConfirmationRepository confirmationRepository;
private final UserService userService;
@@ -40,6 +46,36 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> {
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
}
@Override
public ImmutableList<CheckOrder> checkingList() {
return Lists.immutable.ofAll(
confirmationRepository.findAll(
(root, query, builder) -> builder.equal(root.get("state"), Confirmation.State.CHECKING)
)
)
.collect(confirmation -> new CheckOrder(
StrUtil.format("资源名为「{}」的确权申请", confirmation.getTarget().getName()),
Lists.immutable.of(
new CheckOperation("confirmation_check_apply", "通过"),
new CheckOperation("confirmation_check_reject", "拒绝", "danger")
),
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;
}
}
public static final class ConfirmationDuplicatedException extends RuntimeException {
public ConfirmationDuplicatedException() {
super("数据资源已绑定确权申请,无法再次申请");

View File

@@ -1,32 +0,0 @@
package com.eshore.gringotts.web.domain.order.entity;
import com.eshore.gringotts.core.Constants;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
/**
* 工单
*
* @author lanyuanxiaoyao
* @date 2024-11-27
*/
@Getter
@Setter
@ToString
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicUpdate
@Table(name = Constants.TABLE_PREFIX + "work_order")
public class WorkOrder extends SimpleEntity {
@Column(nullable = false)
private String name;
private String description;
}