From 6ec672ebfadb642b52f81d5b0f0de33b3e59f638 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Fri, 6 Dec 2024 20:01:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20=E5=AE=9E=E7=8E=B0=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E7=94=B3=E8=AF=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增授权申请提交和撤销功能 - 实现授权申请的审核流程 - 优化授权申请的列表和详情展示- 添加时间格式配置 --- .../configuration/JacksonConfiguration.java | 14 ++- gringotts-frontend/components/constants.js | 5 +- gringotts-frontend/pages/index/tab-check.js | 40 ++++++++- gringotts-frontend/pages/index/tab-data.js | 6 +- .../pages/index/tab-permissions.js | 15 ++-- .../controller/AuthenticationController.java | 67 +++++++++++--- .../repository/AuthenticationRepository.java | 30 +++++++ .../service/AuthenticationService.java | 90 ++++++++++++++++++- .../controller/SimpleControllerSupport.java | 2 +- .../base/entity/CheckingNeededEntity.java | 2 +- .../check/service/CheckOrderService.java | 25 ++++++ .../controller/ConfirmationController.java | 20 +++-- .../service/ConfirmationService.java | 1 - .../resource/service/DataResourceService.java | 20 +++-- 14 files changed, 288 insertions(+), 49 deletions(-) diff --git a/gringotts-configuration/src/main/java/com/eshore/gringotts/configuration/JacksonConfiguration.java b/gringotts-configuration/src/main/java/com/eshore/gringotts/configuration/JacksonConfiguration.java index 8dc5ca6..e21a588 100644 --- a/gringotts-configuration/src/main/java/com/eshore/gringotts/configuration/JacksonConfiguration.java +++ b/gringotts-configuration/src/main/java/com/eshore/gringotts/configuration/JacksonConfiguration.java @@ -2,6 +2,10 @@ package com.eshore.gringotts.configuration; import com.fasterxml.jackson.datatype.eclipsecollections.EclipseCollectionsModule; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; @@ -21,9 +25,17 @@ public class JacksonConfiguration { @Bean public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { return builder -> { + /* + * 配置时间格式 + */ + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + JavaTimeModule javaTimeModule = new JavaTimeModule(); + javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter)); + javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter)); + builder.modules( new EclipseCollectionsModule(), - new JavaTimeModule() + javaTimeModule ); }; } diff --git a/gringotts-frontend/components/constants.js b/gringotts-frontend/components/constants.js index 9f0f015..61816a2 100644 --- a/gringotts-frontend/components/constants.js +++ b/gringotts-frontend/components/constants.js @@ -253,7 +253,7 @@ export const permissionStateMapping = [ mappingItem('未确权', 'NONE'), mappingItem('草稿', 'DRAFT', 'bg-primary'), mappingItem('审查中', 'CHECKING', 'bg-warning'), - mappingItem('用户审查中', 'USER_CHECKING', 'bg-warning'), + mappingItem('用户审查中', 'OWNER_CHECKING', 'bg-warning'), mappingItem('通过', 'NORMAL', 'bg-success'), mappingItem('驳回', 'REJECT', 'bg-danger'), ] @@ -294,10 +294,11 @@ export function arrayOutCheck(array, field) { return `\${!ARRAYINCLUDES(['${array.join("','")}'], ${field})}` } -export const confirmationState = { +export const checkState = { none: 'NONE', draft: 'DRAFT', checking: 'CHECKING', + ownerChecking: 'OWNER_CHECKING', normal: 'NORMAL', } diff --git a/gringotts-frontend/pages/index/tab-check.js b/gringotts-frontend/pages/index/tab-check.js index d44549e..72912cf 100644 --- a/gringotts-frontend/pages/index/tab-check.js +++ b/gringotts-frontend/pages/index/tab-check.js @@ -9,7 +9,7 @@ import { stringField, timeField, } from "../../components/constants.js"; -import {confirmationDetailDialog} from "../../components/permission/dialog-permission.js"; +import {authenticationDetailDialog, confirmationDetailDialog} from "../../components/permission/dialog-permission.js"; export function tabCheck() { return { @@ -36,7 +36,7 @@ export function tabCheck() { stringField('modifiedUsername', '最后操作人', 100), operationField('操作', undefined, [ { - visibleOn: '${!over}', + visibleOn: `\${type == 'CONFIRMATION' && !over}`, type: 'action', label: '处理', level: 'link', @@ -63,12 +63,46 @@ export function tabCheck() { ), }, { - visibleOn: '${over}', + visibleOn: `\${type == 'CONFIRMATION' && over}`, type: 'action', label: '查看', level: 'link', ...confirmationDetailDialog('parameters.confirmationId'), }, + { + visibleOn: `\${type == 'AUTHENTICATION' && !over}`, + type: 'action', + label: '处理', + level: 'link', + ...authenticationDetailDialog( + 'parameters.authenticationId', + [ + { + type: 'action', + label: '同意', + actionType: 'ajax', + close: true, + api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'), + reload: 'check_order_list', + }, + { + type: 'action', + label: '拒绝', + actionType: 'ajax', + close: true, + api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'), + reload: 'check_order_list', + }, + ], + ), + }, + { + visibleOn: `\${type == 'AUTHENTICATION' && over}`, + type: 'action', + label: '查看', + level: 'link', + ...authenticationDetailDialog('parameters.authenticationId'), + }, ]), ], }, diff --git a/gringotts-frontend/pages/index/tab-data.js b/gringotts-frontend/pages/index/tab-data.js index 8cea4f1..abc0ebe 100644 --- a/gringotts-frontend/pages/index/tab-data.js +++ b/gringotts-frontend/pages/index/tab-data.js @@ -7,7 +7,7 @@ import { apiGet, arrayInCheck, arrayOutCheck, - confirmationState, + checkState, crudCommonOptions, mappingField, operationField, @@ -57,7 +57,7 @@ export function resourceList() { trigger: 'hover', buttons: [ { - disabledOn: arrayOutCheck([confirmationState.none, confirmationState.draft], 'confirmationState'), + disabledOn: arrayOutCheck([checkState.none, checkState.draft], 'confirmationState'), disabledTip: '审查或确权成功后无法编辑', tooltipPlacement: 'top', type: 'action', @@ -66,7 +66,7 @@ export function resourceList() { ...resourceEditeDialog(), }, { - disabledOn: arrayInCheck([confirmationState.checking], 'confirmationState'), + disabledOn: arrayInCheck([checkState.checking], 'confirmationState'), disabledTip: '审查中无法删除', tooltipPlacement: 'bottom', type: 'action', diff --git a/gringotts-frontend/pages/index/tab-permissions.js b/gringotts-frontend/pages/index/tab-permissions.js index 0c3cdd5..6b83938 100644 --- a/gringotts-frontend/pages/index/tab-permissions.js +++ b/gringotts-frontend/pages/index/tab-permissions.js @@ -1,5 +1,8 @@ import { apiGet, + arrayInCheck, + arrayOutCheck, + checkState, crudCommonOptions, customerOnly, mappingField, @@ -60,22 +63,22 @@ export function tabPermissions() { ...authenticationDetailDialog(), }, { - visibleOn: "${state === 'CHECKING'}", + visibleOn: arrayInCheck([checkState.ownerChecking, checkState.checking], checkState), type: 'action', label: '撤销', level: 'link', confirmTitle: '确认撤销', - confirmText: '确认撤销名称为「${name}」的确权申请吗?', + confirmText: '确认撤销名称为「${name}」的授权申请吗?', actionType: 'ajax', api: apiGet('${base}/authentication/retract/${id}'), }, { - visibleOn: "${state === 'DRAFT' || state === 'REJECT'}", + visibleOn: arrayInCheck([checkState.draft], 'state'), type: 'action', label: '提交', level: 'link', confirmTitle: '确认提交', - confirmText: '确认提交名称为「${name}」的确权申请吗?', + confirmText: '确认提交名称为「${name}」的授权申请吗?', actionType: 'ajax', api: apiGet('${base}/authentication/submit/${id}'), }, @@ -87,14 +90,14 @@ export function tabPermissions() { trigger: 'hover', buttons: [ { - disabledOn: "${state !== 'DRAFT'}", + disabledOn: arrayOutCheck([checkState.draft], 'state'), type: 'action', label: '编辑', level: 'link', ...authenticationEditeDialog(), }, { - disabledOn: "${state === 'CHECKING'}", + disabledOn: arrayInCheck([checkState.ownerChecking, checkState.checking], 'state'), type: 'action', label: "删除", confirmTitle: '确认删除', diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/controller/AuthenticationController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/controller/AuthenticationController.java index f0d55bc..300204a 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/controller/AuthenticationController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/authentication/controller/AuthenticationController.java @@ -1,5 +1,6 @@ package com.eshore.gringotts.web.domain.authentication.controller; +import com.eshore.gringotts.web.configuration.amis.AmisResponse; import com.eshore.gringotts.web.domain.authentication.entity.Authentication; import com.eshore.gringotts.web.domain.authentication.service.AuthenticationService; import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport; @@ -8,11 +9,16 @@ import com.eshore.gringotts.web.domain.base.entity.SimpleListItem; import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem; import com.eshore.gringotts.web.domain.resource.service.DataResourceService; import com.eshore.gringotts.web.domain.upload.service.DataFileService; +import com.fasterxml.jackson.core.JsonProcessingException; import java.time.LocalDateTime; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.set.ImmutableSet; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -35,6 +41,18 @@ public class AuthenticationController extends SimpleControllerSupport submit(@PathVariable Long id) throws JsonProcessingException { + authenticationService.submit(id); + return AmisResponse.responseSuccess(); + } + + @GetMapping("/retract/{id}") + public AmisResponse retract(@PathVariable Long id) { + authenticationService.retract(id); + return AmisResponse.responseSuccess(); + } + @Override protected Authentication fromSaveItem(SaveItem item) throws Exception { Authentication authentication = new Authentication(); @@ -44,29 +62,22 @@ public class AuthenticationController extends SimpleControllerSupport { + public static class SaveItem extends SimpleSaveItem { private Long targetId; private String description; private ImmutableSet evidenceFiles; @@ -75,13 +86,45 @@ public class AuthenticationController extends SimpleControllerSupport { private String name; private String description; private String state; + + public ListItem(Authentication authentication) { + this.setId(authentication.getId()); + this.setName(authentication.getTarget().getName()); + this.setDescription(authentication.getDescription()); + this.setState(authentication.getState().name()); + this.setCreatedUsername(authentication.getCreatedUser().getUsername()); + this.setCreatedTime(authentication.getCreatedTime()); + } } @Data - public static final class DetailItem {} + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public static final class DetailItem extends SaveItem { + private String targetName; + private LocalDateTime createdTime; + private String createdUsername; + private LocalDateTime modifiedTime; + private String modifiedUsername; + + public DetailItem(Authentication authentication) { + this.setId(authentication.getId()); + this.setTargetId(authentication.getTarget().getId()); + this.setTargetName(authentication.getTarget().getName()); + this.setDescription(authentication.getDescription()); + this.setEvidenceFiles(Sets.immutable.ofAll(authentication.getEvidences()).collect(FileInfo::new)); + this.setActiveTime(authentication.getActiveTime()); + this.setExpiredTime(authentication.getExpiredTime()); + this.setCreatedTime(authentication.getCreatedTime()); + this.setCreatedUsername(authentication.getCreatedUser().getUsername()); + this.setModifiedTime(authentication.getModifiedTime()); + this.setModifiedUsername(authentication.getModifiedUser().getUsername()); + } + } } 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 96f685d..f964b50 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,12 +2,42 @@ 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; /** * @author lanyuanxiaoyao * @date 2024-12-02 */ +@SuppressWarnings("NullableProblems") @Repository public interface AuthenticationRepository extends SimpleRepository { + @Override + @EntityGraph(value = "authentication.list", type = EntityGraph.EntityGraphType.FETCH) + List findAll(Specification specification); + + @Override + @EntityGraph(value = "authentication.list", type = EntityGraph.EntityGraphType.FETCH) + List findAll(Specification specification, Sort sort); + + @Override + @EntityGraph(value = "authentication.detail", type = EntityGraph.EntityGraphType.FETCH) + Optional 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 746d562..70f1f40 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 @@ -1,14 +1,24 @@ package com.eshore.gringotts.web.domain.authentication.service; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.eshore.gringotts.web.domain.authentication.entity.Authentication; import com.eshore.gringotts.web.domain.authentication.repository.AuthenticationRepository; +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.LogicDeleteService; import com.eshore.gringotts.web.domain.check.entity.CheckOrder; +import com.eshore.gringotts.web.domain.check.service.CheckOrderService; +import com.eshore.gringotts.web.domain.user.entity.User; import com.eshore.gringotts.web.domain.user.service.UserService; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import javax.persistence.EntityManager; +import javax.transaction.Transactional; import lombok.extern.slf4j.Slf4j; +import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.map.ImmutableMap; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.stereotype.Service; /** @@ -16,16 +26,92 @@ import org.springframework.stereotype.Service; * @date 2024-12-02 */ @Slf4j -@Service +@Service("com.eshore.gringotts.web.domain.authentication.service.AuthenticationService") public class AuthenticationService extends LogicDeleteService implements CheckingService { private final AuthenticationRepository authenticationRepository; + private final UserService userService; + private final CheckOrderService checkOrderService; + private final ObjectMapper mapper; - public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager) { + public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { super(repository, userService, manager); this.authenticationRepository = repository; + this.userService = userService; + this.checkOrderService = checkOrderService; + this.mapper = builder.build(); + } + + @Override + public Long save(Authentication entity) { + if (ObjectUtil.isNull(entity.getId()) && authenticationRepository.findOne( + (root, query, criteriaBuilder) -> { + // TODO 同一个资源的授权时间是否重合 + // 查询是否存在createdUser为当前登陆用户并且绑定的数据资源是同一个的授权申请 + return criteriaBuilder.and( + criteriaBuilder.equal(root.get("createdUser"), userService.currentLoginUser()), + criteriaBuilder.equal(root.get("target"), entity.getTarget()) + ); + } + ).isPresent()) { + throw new AuthenticationDuplicatedException(); + } + return super.save(entity); + } + + @Transactional(rollbackOn = Throwable.class) + public void submit(Long id) throws JsonProcessingException { + Authentication authentication = detailOrThrow(id); + authentication.setState(CheckingNeededEntity.State.OWNER_CHECKING); + checkOrderService.save(new CheckOrder( + "authentication_owner_check", + StrUtil.format("数据资源「{}」的授权申请", authentication.getTarget().getName()), + CheckOrder.Type.AUTHENTICATION, + mapper.writeValueAsString(Maps.immutable.of("authenticationId", authentication.getId())), + "com.eshore.gringotts.web.domain.authentication.service.AuthenticationService", + authentication.getCreatedUser() + )); + save(authentication); + } + + @Transactional(rollbackOn = Throwable.class) + public void retract(Long id) { + authenticationRepository.updateStateById(id, Authentication.State.DRAFT, userService.currentLoginUser()); } @Override public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap parameters) { + Long id = (Long) parameters.get("authenticationId"); + User user = userService.currentLoginUser(); + if (StrUtil.equals(order.getKeyword(), "authentication_owner_check")) { + switch (operation) { + case APPLY: + authenticationRepository.updateStateById(id, Authentication.State.CHECKING, user); + 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); + 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()); + break; + case REJECT: + authenticationRepository.updateStateById(id, Authentication.State.DRAFT, user); + checkOrderService.over(order.getId()); + break; + } + } + } + + public static final class AuthenticationDuplicatedException extends RuntimeException { + public AuthenticationDuplicatedException() { + super("数据资源已绑定该账号的授权申请,无法再次申请"); + } } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/SimpleControllerSupport.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/SimpleControllerSupport.java index 12abd94..740c5b3 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/SimpleControllerSupport.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/SimpleControllerSupport.java @@ -66,7 +66,7 @@ public abstract class SimpleControllerSupport detail(@PathVariable Long id) throws Exception { - return AmisResponse.responseSuccess(toDetailItem(service.detail(id))); + return AmisResponse.responseSuccess(toDetailItem(service.detailOrThrow(id))); } @GetMapping(REMOVE) 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 98b1c7c..71e2e72 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 @@ -38,7 +38,7 @@ public class CheckingNeededEntity extends LogicDeleteEntity { /** * 用户审核 */ - USER_CHECKING, + OWNER_CHECKING, /** * 正常 */ 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 909421b..b18d7cb 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 @@ -6,11 +6,18 @@ 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.entity.User; 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 javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; import lombok.extern.slf4j.Slf4j; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.map.ImmutableMap; import org.springframework.context.ApplicationContext; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; @@ -36,6 +43,24 @@ public class CheckOrderService extends SimpleServiceSupport { this.userService = userService; } + @Override + protected ImmutableList listPredicates(Root root, CriteriaQuery query, CriteriaBuilder builder) { + User user = userService.currentLoginUser(); + return Lists.immutable.of( + builder.or( + builder.equal(root.get("createdUser"), user), + builder.and( + builder.equal(root.get("target"), CheckOrder.Target.USER), + builder.equal(root.get("targetUser"), user) + ), + builder.and( + builder.equal(root.get("target"), CheckOrder.Target.ROLE), + builder.equal(root.get("targetRole"), user.getRole()) + ) + ) + ); + } + public void operation(Long id, CheckOrder.Operation operation) throws JsonProcessingException { CheckOrder order = detailOrThrow(id); CheckingService service = applicationContext.getBean(order.getTargetClass(), CheckingService.class); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/controller/ConfirmationController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/controller/ConfirmationController.java index 46804d7..36f13ad 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/controller/ConfirmationController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/controller/ConfirmationController.java @@ -64,14 +64,7 @@ public class ConfirmationController extends SimpleControllerSupport { + public static final class ListItem extends SimpleListItem { private String name; private String description; private String state; + + public ListItem(Confirmation confirmation) { + this.setId(confirmation.getId()); + this.setName(confirmation.getTarget().getName()); + this.setDescription(confirmation.getDescription()); + this.setState(confirmation.getState().name()); + this.setCreatedUsername(confirmation.getCreatedUser().getUsername()); + this.setCreatedTime(confirmation.getCreatedTime()); + } } @Data 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 d4ce51d..b78add1 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 @@ -50,7 +50,6 @@ public class ConfirmationService extends SimpleServiceSupport impl @Transactional(rollbackOn = Throwable.class) 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", diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/service/DataResourceService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/service/DataResourceService.java index 550f355..98d341f 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/service/DataResourceService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/service/DataResourceService.java @@ -10,11 +10,10 @@ import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType; import com.eshore.gringotts.web.domain.resource.repository.DataResourceRepository; import com.eshore.gringotts.web.domain.resource.repository.ResourceFormatRepository; import com.eshore.gringotts.web.domain.resource.repository.ResourceTypeRepository; -import com.eshore.gringotts.web.domain.user.entity.User; import com.eshore.gringotts.web.domain.user.service.UserService; import javax.persistence.criteria.Join; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.SetJoin; +import javax.persistence.criteria.Root; +import javax.persistence.criteria.Subquery; import lombok.extern.slf4j.Slf4j; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; @@ -46,14 +45,19 @@ public class DataResourceService extends SimpleServiceSupport { } public ImmutableList listNoAuthentication() { - User user = userService.currentLoginUser(); return Lists.immutable.ofAll(dataResourceRepository.findAll( (root, query, builder) -> { - SetJoin authenticationJoin = root.joinSet("authentications", JoinType.LEFT); - authenticationJoin.on(builder.notEqual(authenticationJoin.get("createdUser"), user)); - Join confirmationJoin = root.join("confirmation", JoinType.LEFT); + Join confirmationJoin = root.join("confirmation"); confirmationJoin.on(builder.equal(confirmationJoin.get("state"), CheckingNeededEntity.State.NORMAL)); - return null; + + Subquery authenticationSubquery = query.subquery(Authentication.class); + Root authenticationRoot = authenticationSubquery.from(Authentication.class); + authenticationSubquery.select(authenticationRoot) + .where( + builder.equal(authenticationRoot.get("target"), root), + builder.equal(authenticationRoot.get("createdUser"), userService.currentLoginUser()) + ); + return builder.exists(authenticationSubquery).not(); } )); }