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

@@ -264,8 +264,9 @@ export const checkTypeMapping = [
] ]
export const checkOverMapping = [ export const checkOverMapping = [
mappingItem('完结', 'true', 'bg-success'), mappingItem('进行中', 'CHECKING', 'bg-warning'),
mappingItem('进行中', 'false', 'bg-primary'), mappingItem('已撤销', 'RETRACT', 'bg-primary'),
mappingItem('已办结', 'OVER', 'bg-success'),
] ]
function api(method, url) { function api(method, url) {

View File

@@ -165,7 +165,7 @@ export function confirmationEditeDialog(field = 'id') {
} }
export function authenticationEditeDialog(field = 'id') { export function authenticationEditeDialog(field = 'id') {
return permissionEditeDialog(CONFIRMATION_TYPE, field) return permissionEditeDialog(AUTHENTICATION_TYPE, field)
} }
function permissionEditeDialog(type, field = 'id') { function permissionEditeDialog(type, field = 'id') {

View File

@@ -29,14 +29,14 @@ export function tabCheck() {
columns: [ columns: [
stringField('description', '描述'), stringField('description', '描述'),
mappingField('type', '类型', checkTypeMapping), mappingField('type', '类型', checkTypeMapping),
mappingField('over', '状态', checkOverMapping), mappingField('state', '状态', checkOverMapping),
timeField('createdTime', '创建时间'), timeField('createdTime', '创建时间'),
stringField('createdUsername', '创建人', 100), stringField('createdUsername', '创建人', 100),
timeField('modifiedTime', '最后修改时间'), timeField('modifiedTime', '最后修改时间'),
stringField('modifiedUsername', '最后操作人', 100), stringField('modifiedUsername', '最后操作人', 100),
operationField('操作', undefined, [ operationField('操作', undefined, [
{ {
visibleOn: `\${type == 'CONFIRMATION' && !over}`, visibleOn: `\${type === 'CONFIRMATION' && state === 'CHECKING'}`,
type: 'action', type: 'action',
label: '处理', label: '处理',
level: 'link', level: 'link',
@@ -63,14 +63,14 @@ export function tabCheck() {
), ),
}, },
{ {
visibleOn: `\${type == 'CONFIRMATION' && over}`, visibleOn: `\${type === 'CONFIRMATION' && state !== NORMAL}`,
type: 'action', type: 'action',
label: '查看', label: '查看',
level: 'link', level: 'link',
...confirmationDetailDialog('parameters.confirmationId'), ...confirmationDetailDialog('parameters.confirmationId'),
}, },
{ {
visibleOn: `\${type == 'AUTHENTICATION' && !over}`, visibleOn: `\${type === 'AUTHENTICATION' && state === 'CHECKING'}`,
type: 'action', type: 'action',
label: '处理', label: '处理',
level: 'link', level: 'link',
@@ -97,7 +97,7 @@ export function tabCheck() {
), ),
}, },
{ {
visibleOn: `\${type == 'AUTHENTICATION' && over}`, visibleOn: `\${type === 'AUTHENTICATION' && state !== NORMAL}`,
type: 'action', type: 'action',
label: '查看', label: '查看',
level: 'link', level: 'link',

View File

@@ -63,7 +63,7 @@ export function tabPermissions() {
...authenticationDetailDialog(), ...authenticationDetailDialog(),
}, },
{ {
visibleOn: arrayInCheck([checkState.ownerChecking, checkState.checking], checkState), visibleOn: arrayInCheck([checkState.ownerChecking, checkState.checking], 'state'),
type: 'action', type: 'action',
label: '撤销', label: '撤销',
level: 'link', level: 'link',

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

View File

@@ -1,10 +1,14 @@
package com.eshore.gringotts.web.domain.base.entity; 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.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;
@@ -22,6 +26,10 @@ 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)
@ToString.Exclude
private CheckOrder order;
public enum State { public enum State {
/** /**
* 无确权 * 无确权

View File

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

View File

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

View File

@@ -34,6 +34,6 @@ public interface CheckOrderRepository extends SimpleRepository<CheckOrder, Long>
@Transactional @Transactional
@Modifying @Modifying
@Query("update CheckOrder check set check.over = true, check.modifiedUser = ?2, check.modifiedTime = current_timestamp where check.id = ?1") @Query("update CheckOrder check set check.state = ?2, check.modifiedUser = ?3, check.modifiedTime = current_timestamp where check.id = ?1")
void overById(Long id, User modifiedUser); 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); service.onChecked(order, operation, parameters);
} }
public void retract(Long id) {
checkOrderRepository.overById(id, CheckOrder.State.RETRACT, userService.currentLoginUser());
}
public void over(Long id) { 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.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation; 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.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;
/** /**
@@ -33,13 +29,4 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
Optional<Confirmation> findOne(Specification<Confirmation> specification); Optional<Confirmation> findOne(Specification<Confirmation> specification);
Boolean existsByTarget_Id(Long id); 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.ObjectUtil;
import cn.hutool.core.util.StrUtil; 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.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.entity.CheckOrder;
@@ -27,14 +28,12 @@ import org.springframework.stereotype.Service;
@Service("com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService") @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 CheckOrderService checkOrderService; private final CheckOrderService checkOrderService;
private final ObjectMapper mapper; private final ObjectMapper mapper;
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { 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.checkOrderService = checkOrderService; this.checkOrderService = checkOrderService;
this.mapper = builder.build(); this.mapper = builder.build();
} }
@@ -51,7 +50,7 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> impl
public void submit(Long id) throws JsonProcessingException { public void submit(Long id) throws JsonProcessingException {
Confirmation confirmation = detailOrThrow(id); Confirmation confirmation = detailOrThrow(id);
confirmation.setState(Confirmation.State.CHECKING); confirmation.setState(Confirmation.State.CHECKING);
checkOrderService.save(new CheckOrder( Long orderId = checkOrderService.save(new CheckOrder(
"confirmation_check", "confirmation_check",
StrUtil.format("数据资源「{}」的确权申请", confirmation.getTarget().getName()), StrUtil.format("数据资源「{}」的确权申请", confirmation.getTarget().getName()),
CheckOrder.Type.CONFIRMATION, CheckOrder.Type.CONFIRMATION,
@@ -59,27 +58,40 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> impl
"com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService", "com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService",
User.Role.ADMINISTRATOR User.Role.ADMINISTRATOR
)); ));
CheckOrder order = checkOrderService.detailOrThrow(orderId);
confirmation.setOrder(order);
save(confirmation); save(confirmation);
} }
@Transactional(rollbackOn = Throwable.class)
public void retract(Long id) { 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 @Override
@Transactional(rollbackOn = Throwable.class)
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) { public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
if (StrUtil.equals(order.getKeyword(), "confirmation_check")) { if (StrUtil.equals(order.getKeyword(), "confirmation_check")) {
Long id = (Long) parameters.get("confirmationId"); Long id = (Long) parameters.get("confirmationId");
Confirmation confirmation = detailOrThrow(id);
switch (operation) { switch (operation) {
case APPLY: case APPLY:
confirmationRepository.updateStateById(id, Confirmation.State.NORMAL, userService.currentLoginUser()); confirmation.setState(Confirmation.State.NORMAL);
checkOrderService.over(order.getId()); order.setState(CheckOrder.State.OVER);
break; break;
case REJECT: case REJECT:
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser()); confirmation.setState(Confirmation.State.DRAFT);
checkOrderService.over(order.getId()); order.setState(CheckOrder.State.OVER);
break; break;
} }
save(confirmation);
checkOrderService.save(order);
} }
} }