From 3e43d437e6694a579cf09a142531f32bb64b6902 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Mon, 9 Dec 2024 10:38:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor(web):=20=E9=87=8D=E6=9E=84=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 AuthenticationRepository 和 ConfirmationRepository 中的 updateStateById 方法 - 更新 AuthenticationService 和 ConfirmationService 中的状态更新逻辑 - 修改 CheckOrder 实体,使用 State 枚举替代布尔型 over 字段 - 更新相关前端组件,适应新的审核状态 --- gringotts-frontend/components/constants.js | 5 +-- .../permission/dialog-permission.js | 2 +- gringotts-frontend/pages/index/tab-check.js | 10 +++--- .../pages/index/tab-permissions.js | 2 +- .../repository/AuthenticationRepository.java | 13 -------- .../service/AuthenticationService.java | 31 +++++++++++++------ .../base/entity/CheckingNeededEntity.java | 8 +++++ .../controller/CheckOrderController.java | 4 +-- .../web/domain/check/entity/CheckOrder.java | 9 +++++- .../repository/CheckOrderRepository.java | 4 +-- .../check/service/CheckOrderService.java | 6 +++- .../repository/ConfirmationRepository.java | 13 -------- .../service/ConfirmationService.java | 28 ++++++++++++----- 13 files changed, 76 insertions(+), 59 deletions(-) diff --git a/gringotts-frontend/components/constants.js b/gringotts-frontend/components/constants.js index 61816a2..7ad9687 100644 --- a/gringotts-frontend/components/constants.js +++ b/gringotts-frontend/components/constants.js @@ -264,8 +264,9 @@ export const checkTypeMapping = [ ] export const checkOverMapping = [ - mappingItem('完结', 'true', 'bg-success'), - mappingItem('进行中', 'false', 'bg-primary'), + mappingItem('进行中', 'CHECKING', 'bg-warning'), + mappingItem('已撤销', 'RETRACT', 'bg-primary'), + mappingItem('已办结', 'OVER', 'bg-success'), ] function api(method, url) { diff --git a/gringotts-frontend/components/permission/dialog-permission.js b/gringotts-frontend/components/permission/dialog-permission.js index cbcc34c..5a2b29c 100644 --- a/gringotts-frontend/components/permission/dialog-permission.js +++ b/gringotts-frontend/components/permission/dialog-permission.js @@ -165,7 +165,7 @@ export function confirmationEditeDialog(field = 'id') { } export function authenticationEditeDialog(field = 'id') { - return permissionEditeDialog(CONFIRMATION_TYPE, field) + return permissionEditeDialog(AUTHENTICATION_TYPE, field) } function permissionEditeDialog(type, field = 'id') { diff --git a/gringotts-frontend/pages/index/tab-check.js b/gringotts-frontend/pages/index/tab-check.js index 72912cf..36f895d 100644 --- a/gringotts-frontend/pages/index/tab-check.js +++ b/gringotts-frontend/pages/index/tab-check.js @@ -29,14 +29,14 @@ export function tabCheck() { columns: [ stringField('description', '描述'), mappingField('type', '类型', checkTypeMapping), - mappingField('over', '状态', checkOverMapping), + mappingField('state', '状态', checkOverMapping), timeField('createdTime', '创建时间'), stringField('createdUsername', '创建人', 100), timeField('modifiedTime', '最后修改时间'), stringField('modifiedUsername', '最后操作人', 100), operationField('操作', undefined, [ { - visibleOn: `\${type == 'CONFIRMATION' && !over}`, + visibleOn: `\${type === 'CONFIRMATION' && state === 'CHECKING'}`, type: 'action', label: '处理', level: 'link', @@ -63,14 +63,14 @@ export function tabCheck() { ), }, { - visibleOn: `\${type == 'CONFIRMATION' && over}`, + visibleOn: `\${type === 'CONFIRMATION' && state !== NORMAL}`, type: 'action', label: '查看', level: 'link', ...confirmationDetailDialog('parameters.confirmationId'), }, { - visibleOn: `\${type == 'AUTHENTICATION' && !over}`, + visibleOn: `\${type === 'AUTHENTICATION' && state === 'CHECKING'}`, type: 'action', label: '处理', level: 'link', @@ -97,7 +97,7 @@ export function tabCheck() { ), }, { - visibleOn: `\${type == 'AUTHENTICATION' && over}`, + visibleOn: `\${type === 'AUTHENTICATION' && state !== NORMAL}`, type: 'action', label: '查看', level: 'link', diff --git a/gringotts-frontend/pages/index/tab-permissions.js b/gringotts-frontend/pages/index/tab-permissions.js index 6b83938..7c2017f 100644 --- a/gringotts-frontend/pages/index/tab-permissions.js +++ b/gringotts-frontend/pages/index/tab-permissions.js @@ -63,7 +63,7 @@ export function tabPermissions() { ...authenticationDetailDialog(), }, { - visibleOn: arrayInCheck([checkState.ownerChecking, checkState.checking], checkState), + visibleOn: arrayInCheck([checkState.ownerChecking, checkState.checking], 'state'), type: 'action', label: '撤销', level: 'link', diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/repository/AuthenticationRepository.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/repository/AuthenticationRepository.java index f964b50..8feea13 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/repository/AuthenticationRepository.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/repository/AuthenticationRepository.java @@ -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 findOne(Specification 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); } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/service/AuthenticationService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/service/AuthenticationService.java index 70f1f40..462fc40 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/service/AuthenticationService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/service/AuthenticationService.java @@ -62,7 +62,7 @@ public class AuthenticationService extends LogicDeleteService 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 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 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 { diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/CheckingNeededEntity.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/CheckingNeededEntity.java index 71e2e72..9206a31 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/CheckingNeededEntity.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/CheckingNeededEntity.java @@ -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 { /** * 无确权 diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckOrderController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckOrderController.java index a3b6454..f1ff745 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckOrderController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckOrderController.java @@ -59,7 +59,7 @@ public class CheckOrderController implements ListController() {})); - 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 parameters; - private Boolean over; + private CheckOrder.State state; private LocalDateTime createdTime; private String createdUsername; private LocalDateTime modifiedTime; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/entity/CheckOrder.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/entity/CheckOrder.java index dcb9d74..d57eba1 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/entity/CheckOrder.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/entity/CheckOrder.java @@ -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, + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/repository/CheckOrderRepository.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/repository/CheckOrderRepository.java index e78d4d9..3b4ec35 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/repository/CheckOrderRepository.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/repository/CheckOrderRepository.java @@ -34,6 +34,6 @@ public interface CheckOrderRepository extends SimpleRepository @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); } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/service/CheckOrderService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/service/CheckOrderService.java index b18d7cb..e7e4001 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/service/CheckOrderService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/service/CheckOrderService.java @@ -71,7 +71,11 @@ public class CheckOrderService extends SimpleServiceSupport { 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()); } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/repository/ConfirmationRepository.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/repository/ConfirmationRepository.java index 5d1e533..270c573 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/repository/ConfirmationRepository.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/repository/ConfirmationRepository.java @@ -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 findOne(Specification 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); } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/service/ConfirmationService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/service/ConfirmationService.java index b78add1..b6aefef 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/service/ConfirmationService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/service/ConfirmationService.java @@ -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 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 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 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 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); } }