1
0

refactor(web): 重构审核流程

- 移除 AuthenticationRepository 和 ConfirmationRepository 中的 updateStateById 方法
- 更新 AuthenticationService 和 ConfirmationService 中的状态更新逻辑
- 修改 CheckOrder 实体,使用 State 枚举替代布尔型 over 字段
- 更新相关前端组件,适应新的审核状态
This commit is contained in:
2024-12-09 10:38:21 +08:00
parent 6ec672ebfa
commit 3e43d437e6
13 changed files with 76 additions and 59 deletions

View File

@@ -2,15 +2,11 @@ package com.eshore.gringotts.web.domain.authentication.repository;
import com.eshore.gringotts.web.domain.authentication.entity.Authentication;
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
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;
/**
@@ -31,13 +27,4 @@ public interface AuthenticationRepository extends SimpleRepository<Authenticatio
@Override
@EntityGraph(value = "authentication.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<Authentication> findOne(Specification<Authentication> specification);
@Transactional
@Modifying
@Query("update Authentication authentication \n" +
"set authentication.state = ?2, \n" +
" authentication.modifiedUser = ?3, \n" +
" authentication.modifiedTime = current_timestamp \n" +
"where authentication.id = ?1")
void updateStateById(Long id, Authentication.State state, User modifiedUser);
}

View File

@@ -62,7 +62,7 @@ public class AuthenticationService extends LogicDeleteService<Authentication> im
public void submit(Long id) throws JsonProcessingException {
Authentication authentication = detailOrThrow(id);
authentication.setState(CheckingNeededEntity.State.OWNER_CHECKING);
checkOrderService.save(new CheckOrder(
Long orderId = checkOrderService.save(new CheckOrder(
"authentication_owner_check",
StrUtil.format("数据资源「{}」的授权申请", authentication.getTarget().getName()),
CheckOrder.Type.AUTHENTICATION,
@@ -70,43 +70,54 @@ public class AuthenticationService extends LogicDeleteService<Authentication> im
"com.eshore.gringotts.web.domain.authentication.service.AuthenticationService",
authentication.getCreatedUser()
));
CheckOrder order = checkOrderService.detailOrThrow(orderId);
authentication.setOrder(order);
save(authentication);
}
@Transactional(rollbackOn = Throwable.class)
public void retract(Long id) {
authenticationRepository.updateStateById(id, Authentication.State.DRAFT, userService.currentLoginUser());
Authentication authentication = detailOrThrow(id);
authentication.setState(Authentication.State.DRAFT);
save(authentication);
CheckOrder order = authentication.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) {
Long id = (Long) parameters.get("authenticationId");
User user = userService.currentLoginUser();
Authentication authentication = detailOrThrow(id);
if (StrUtil.equals(order.getKeyword(), "authentication_owner_check")) {
switch (operation) {
case APPLY:
authenticationRepository.updateStateById(id, Authentication.State.CHECKING, user);
authentication.setState(Authentication.State.CHECKING);
order.setKeyword("authentication_checker_check");
order.setTarget(CheckOrder.Target.ROLE);
order.setTargetRole(User.Role.CHECKER);
checkOrderService.save(order);
break;
case REJECT:
authenticationRepository.updateStateById(id, Authentication.State.DRAFT, user);
authentication.setState(Authentication.State.DRAFT);
order.setState(CheckOrder.State.OVER);
break;
}
} else if (StrUtil.equals(order.getKeyword(), "authentication_checker_check")) {
switch (operation) {
case APPLY:
authenticationRepository.updateStateById(id, Authentication.State.NORMAL, user);
checkOrderService.over(order.getId());
authentication.setState(Authentication.State.NORMAL);
order.setState(CheckOrder.State.OVER);
break;
case REJECT:
authenticationRepository.updateStateById(id, Authentication.State.DRAFT, user);
checkOrderService.over(order.getId());
authentication.setState(Authentication.State.DRAFT);
order.setState(CheckOrder.State.OVER);
break;
}
}
save(authentication);
checkOrderService.save(order);
}
public static final class AuthenticationDuplicatedException extends RuntimeException {

View File

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

View File

@@ -59,7 +59,7 @@ public class CheckOrderController implements ListController<CheckOrderController
item.setDescription(order.getDescription());
item.setType(order.getType());
item.setParameters(mapper.readValue(order.getParameters(), new TypeReference<>() {}));
item.setOver(order.getOver());
item.setState(order.getState());
item.setCreatedUsername(order.getCreatedUser().getUsername());
item.setCreatedTime(order.getCreatedTime());
item.setModifiedUsername(order.getModifiedUser().getUsername());
@@ -80,7 +80,7 @@ public class CheckOrderController implements ListController<CheckOrderController
private String description;
private CheckOrder.Type type;
private ImmutableMap<String, Object> parameters;
private Boolean over;
private CheckOrder.State state;
private LocalDateTime createdTime;
private String createdUsername;
private LocalDateTime modifiedTime;

View File

@@ -70,7 +70,8 @@ public class CheckOrder extends SimpleEntity {
private User.Role targetRole;
@Column(nullable = false)
private Boolean over = false;
@Enumerated(EnumType.STRING)
private State state = State.CHECKING;
public CheckOrder(
String keyword,
@@ -120,4 +121,10 @@ public class CheckOrder extends SimpleEntity {
USER,
ROLE,
}
public enum State {
CHECKING,
RETRACT,
OVER,
}
}

View File

@@ -34,6 +34,6 @@ public interface CheckOrderRepository extends SimpleRepository<CheckOrder, Long>
@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);
@Query("update CheckOrder check set check.state = ?2, check.modifiedUser = ?3, check.modifiedTime = current_timestamp where check.id = ?1")
void overById(Long id, CheckOrder.State state, User modifiedUser);
}

View File

@@ -71,7 +71,11 @@ public class CheckOrderService extends SimpleServiceSupport<CheckOrder> {
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, userService.currentLoginUser());
checkOrderRepository.overById(id, CheckOrder.State.OVER, userService.currentLoginUser());
}
}

View File

@@ -2,15 +2,11 @@ package com.eshore.gringotts.web.domain.confirmation.repository;
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
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;
/**
@@ -33,13 +29,4 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
Optional<Confirmation> findOne(Specification<Confirmation> specification);
Boolean existsByTarget_Id(Long id);
@Transactional
@Modifying
@Query("update Confirmation confirmation \n" +
"set confirmation.state = ?2, \n" +
" confirmation.modifiedUser = ?3, \n" +
" confirmation.modifiedTime = current_timestamp \n" +
"where confirmation.id = ?1")
void updateStateById(Long id, Confirmation.State state, User modifiedUser);
}

View File

@@ -2,6 +2,7 @@ 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.entity.CheckingNeededEntity;
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;
@@ -27,14 +28,12 @@ import org.springframework.stereotype.Service;
@Service("com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService")
public class ConfirmationService extends SimpleServiceSupport<Confirmation> implements CheckingService {
private final ConfirmationRepository confirmationRepository;
private final UserService userService;
private final CheckOrderService checkOrderService;
private final ObjectMapper mapper;
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
super(confirmationRepository, userService);
this.confirmationRepository = confirmationRepository;
this.userService = userService;
this.checkOrderService = checkOrderService;
this.mapper = builder.build();
}
@@ -51,7 +50,7 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> impl
public void submit(Long id) throws JsonProcessingException {
Confirmation confirmation = detailOrThrow(id);
confirmation.setState(Confirmation.State.CHECKING);
checkOrderService.save(new CheckOrder(
Long orderId = checkOrderService.save(new CheckOrder(
"confirmation_check",
StrUtil.format("数据资源「{}」的确权申请", confirmation.getTarget().getName()),
CheckOrder.Type.CONFIRMATION,
@@ -59,27 +58,40 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> impl
"com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService",
User.Role.ADMINISTRATOR
));
CheckOrder order = checkOrderService.detailOrThrow(orderId);
confirmation.setOrder(order);
save(confirmation);
}
@Transactional(rollbackOn = Throwable.class)
public void retract(Long id) {
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
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:
confirmationRepository.updateStateById(id, Confirmation.State.NORMAL, userService.currentLoginUser());
checkOrderService.over(order.getId());
confirmation.setState(Confirmation.State.NORMAL);
order.setState(CheckOrder.State.OVER);
break;
case REJECT:
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
checkOrderService.over(order.getId());
confirmation.setState(Confirmation.State.DRAFT);
order.setState(CheckOrder.State.OVER);
break;
}
save(confirmation);
checkOrderService.save(order);
}
}