1
0

feat(web): 增加授权相关界面

This commit is contained in:
2024-12-02 19:07:22 +08:00
parent e7918f9039
commit 1ec345e18d
11 changed files with 308 additions and 36 deletions

View File

@@ -0,0 +1,87 @@
package com.eshore.gringotts.web.domain.authentication.controller;
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;
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
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 java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.set.ImmutableSet;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lanyuanxiaoyao
* @date 2024-12-02
*/
@Slf4j
@RestController
@RequestMapping("authentication")
public class AuthenticationController extends SimpleControllerSupport<Authentication, AuthenticationController.SaveItem, AuthenticationController.ListItem, AuthenticationController.DetailItem> {
private final AuthenticationService authenticationService;
private final DataResourceService dataResourceService;
private final DataFileService dataFileService;
public AuthenticationController(AuthenticationService service, DataResourceService dataResourceService, DataFileService dataFileService) {
super(service);
this.authenticationService = service;
this.dataResourceService = dataResourceService;
this.dataFileService = dataFileService;
}
@Override
protected Authentication fromSaveItem(SaveItem item) {
Authentication authentication = new Authentication();
authentication.setId(item.getId());
authentication.setDescription(item.getDescription());
authentication.setTarget(dataResourceService.detailOrThrow(item.getTargetId()));
authentication.setEvidences(dataFileService.list(item.getEvidenceFiles().collect(FileInfo::getValue)).toSet());
authentication.setActiveTime(item.getActiveTime());
authentication.setExpiredTime(item.getExpiredTime());
return null;
}
@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;
}
@Override
protected DetailItem toDetailItem(Authentication entity) {
return null;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static final class SaveItem extends SimpleSaveItem<Authentication> {
private Long targetId;
private String description;
private ImmutableSet<FileInfo> evidenceFiles;
private LocalDateTime activeTime;
private LocalDateTime expiredTime;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static final class ListItem extends SimpleListItem<Authentication> {
private String name;
private String description;
private String state;
}
@Data
public static final class DetailItem {}
}

View File

@@ -5,8 +5,10 @@ import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
import java.time.LocalDateTime;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
@@ -59,4 +61,14 @@ public class Authentication extends CheckingNeededEntity {
@ToString.Exclude
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private Set<DataFile> evidences;
/**
* 生效时间
*/
@Column(nullable = false)
private LocalDateTime activeTime = LocalDateTime.now();
/**
* 过期时间
*/
@Column(nullable = false)
private LocalDateTime expiredTime = LocalDateTime.now().plusDays(1);
}

View File

@@ -0,0 +1,13 @@
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 org.springframework.stereotype.Repository;
/**
* @author lanyuanxiaoyao
* @date 2024-12-02
*/
@Repository
public interface AuthenticationRepository extends SimpleRepository<Authentication, Long> {
}

View File

@@ -0,0 +1,31 @@
package com.eshore.gringotts.web.domain.authentication.service;
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.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.user.service.UserService;
import javax.persistence.EntityManager;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.map.ImmutableMap;
import org.springframework.stereotype.Service;
/**
* @author lanyuanxiaoyao
* @date 2024-12-02
*/
@Slf4j
@Service
public class AuthenticationService extends LogicDeleteService<Authentication> implements CheckingService {
private final AuthenticationRepository authenticationRepository;
public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager) {
super(repository, userService, manager);
this.authenticationRepository = repository;
}
@Override
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
}
}

View File

@@ -35,6 +35,10 @@ public class CheckingNeededEntity extends LogicDeleteEntity {
* 审查中
*/
CHECKING,
/**
* 用户审核
*/
USER_CHECKING,
/**
* 正常
*/