feat(web): 实现授权申请功能
- 新增授权申请提交和撤销功能 - 实现授权申请的审核流程 - 优化授权申请的列表和详情展示- 添加时间格式配置
This commit is contained in:
@@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
}
|
||||
|
||||
|
||||
@@ -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'),
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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: '确认删除',
|
||||
|
||||
@@ -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<Authentica
|
||||
this.dataFileService = dataFileService;
|
||||
}
|
||||
|
||||
@GetMapping("/submit/{id}")
|
||||
public AmisResponse<Object> submit(@PathVariable Long id) throws JsonProcessingException {
|
||||
authenticationService.submit(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@GetMapping("/retract/{id}")
|
||||
public AmisResponse<Object> 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<Authentica
|
||||
authentication.setEvidences(dataFileService.list(item.getEvidenceFiles().collect(FileInfo::getValue)).toSet());
|
||||
authentication.setActiveTime(item.getActiveTime());
|
||||
authentication.setExpiredTime(item.getExpiredTime());
|
||||
return null;
|
||||
return authentication;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListItem toListItem(Authentication entity) {
|
||||
ListItem item = new ListItem();
|
||||
item.setId(entity.getId());
|
||||
item.setName(entity.getTarget().getName());
|
||||
item.setDescription(entity.getDescription());
|
||||
item.setState(entity.getState().name());
|
||||
item.setCreatedUsername(entity.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(entity.getCreatedTime());
|
||||
return item;
|
||||
return new ListItem(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItem toDetailItem(Authentication entity) {
|
||||
return null;
|
||||
return new DetailItem(entity);
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class SaveItem extends SimpleSaveItem<Authentication> {
|
||||
public static class SaveItem extends SimpleSaveItem<Authentication> {
|
||||
private Long targetId;
|
||||
private String description;
|
||||
private ImmutableSet<FileInfo> evidenceFiles;
|
||||
@@ -75,13 +86,45 @@ public class AuthenticationController extends SimpleControllerSupport<Authentica
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class ListItem extends SimpleListItem<Authentication> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Authentication, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "authentication.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<Authentication> findAll(Specification<Authentication> specification);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "authentication.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<Authentication> findAll(Specification<Authentication> specification, Sort sort);
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@@ -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<Authentication> 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<String, Object> 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("数据资源已绑定该账号的授权申请,无法再次申请");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
||||
@GetMapping(DETAIL)
|
||||
@Override
|
||||
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {
|
||||
return AmisResponse.responseSuccess(toDetailItem(service.detail(id)));
|
||||
return AmisResponse.responseSuccess(toDetailItem(service.detailOrThrow(id)));
|
||||
}
|
||||
|
||||
@GetMapping(REMOVE)
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CheckingNeededEntity extends LogicDeleteEntity {
|
||||
/**
|
||||
* 用户审核
|
||||
*/
|
||||
USER_CHECKING,
|
||||
OWNER_CHECKING,
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
|
||||
@@ -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<CheckOrder> {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImmutableList<Predicate> listPredicates(Root<CheckOrder> 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);
|
||||
|
||||
@@ -64,14 +64,7 @@ public class ConfirmationController extends SimpleControllerSupport<Confirmation
|
||||
|
||||
@Override
|
||||
protected ListItem toListItem(Confirmation entity) {
|
||||
ListItem item = new ListItem();
|
||||
item.setId(entity.getId());
|
||||
item.setName(entity.getTarget().getName());
|
||||
item.setDescription(entity.getDescription());
|
||||
item.setState(entity.getState().name());
|
||||
item.setCreatedUsername(entity.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(entity.getCreatedTime());
|
||||
return item;
|
||||
return new ListItem(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,10 +82,19 @@ public class ConfirmationController extends SimpleControllerSupport<Confirmation
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ListItem extends SimpleListItem<Confirmation> {
|
||||
public static final class ListItem extends SimpleListItem<Confirmation> {
|
||||
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
|
||||
|
||||
@@ -50,7 +50,6 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> 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",
|
||||
|
||||
@@ -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<DataResource> {
|
||||
}
|
||||
|
||||
public ImmutableList<DataResource> listNoAuthentication() {
|
||||
User user = userService.currentLoginUser();
|
||||
return Lists.immutable.ofAll(dataResourceRepository.findAll(
|
||||
(root, query, builder) -> {
|
||||
SetJoin<DataResource, Authentication> authenticationJoin = root.joinSet("authentications", JoinType.LEFT);
|
||||
authenticationJoin.on(builder.notEqual(authenticationJoin.get("createdUser"), user));
|
||||
Join<DataResource, Confirmation> confirmationJoin = root.join("confirmation", JoinType.LEFT);
|
||||
Join<DataResource, Confirmation> confirmationJoin = root.join("confirmation");
|
||||
confirmationJoin.on(builder.equal(confirmationJoin.get("state"), CheckingNeededEntity.State.NORMAL));
|
||||
return null;
|
||||
|
||||
Subquery<Authentication> authenticationSubquery = query.subquery(Authentication.class);
|
||||
Root<Authentication> 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();
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user