1
0

feat(web): 实现数据产品上架审核功能

- 新增数据产品列表、详情、编辑等功能页面
- 实现数据产品提交审核、撤销审核、同意审核等操作
- 优化数据产品相关API接口,支持审核功能
- 重构部分代码以支持新功能
This commit is contained in:
2024-12-17 18:29:16 +08:00
parent 4934c6727e
commit 3138539bc5
12 changed files with 377 additions and 60 deletions

View File

@@ -0,0 +1,16 @@
package com.eshore.gringotts.web.configuration;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author lanyuanxiaoyao
* @date 2024-12-17
*/
@Data
@ConfigurationProperties(prefix = "gringotts.host")
@Configuration
public class HostConfiguration {
private String prefix = "http://127.0.0.1:20080";
}

View File

@@ -3,8 +3,7 @@ package com.eshore.gringotts.web.configuration;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -12,13 +11,12 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* web配置
*
* @author lanyuanxiaoyao
* @date 2024-11-14
* @author wn
* @since 2024-11-14
*/
@Slf4j
@Configuration
public class SaTokenConfiguration implements WebMvcConfigurer {
private static final Logger logger = LoggerFactory.getLogger(SaTokenConfiguration.class);
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry
@@ -31,6 +29,7 @@ public class SaTokenConfiguration implements WebMvcConfigurer {
.notMatch("/assets/**")
.notMatch("/pages/**")
.notMatch("/user/**")
.notMatch("/upload/download/**")
.check(r -> {
try {
StpUtil.checkLogin();

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.eshore.gringotts.web.configuration.HostConfiguration;
import com.eshore.gringotts.web.configuration.UploadConfiguration;
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
import com.eshore.gringotts.web.domain.entity.DataFile;
@@ -19,9 +20,8 @@ import javax.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -37,17 +37,18 @@ import org.springframework.web.multipart.MultipartFile;
* @author lanyuanxiaoyao
* @date 2024-11-21
*/
@Slf4j
@RestController
@RequestMapping("/upload")
public class DataFileController {
private static final Logger logger = LoggerFactory.getLogger(DataFileController.class);
private final HostConfiguration hostConfiguration;
private final DataFileService dataFileService;
private final String uploadFolderPath;
private final String cacheFolderPath;
private final String sliceFolderPath;
public DataFileController(UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
public DataFileController(HostConfiguration hostConfiguration, UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
this.hostConfiguration = hostConfiguration;
this.dataFileService = dataFileService;
this.uploadFolderPath = uploadConfiguration.getUploadPath();
@@ -59,7 +60,7 @@ public class DataFileController {
public AmisResponse<FinishResponse> upload(@RequestParam("file") MultipartFile file) throws IOException {
String filename = file.getOriginalFilename();
Long id = dataFileService.initialDataFile(filename);
String url = StrUtil.format("/upload/download/{}", id);
String url = StrUtil.format("{}/upload/download/{}", hostConfiguration.getPrefix(), id);
byte[] bytes = file.getBytes();
String originMd5 = SecureUtil.md5(new ByteArrayInputStream(bytes));
File targetFile = new File(StrUtil.format("{}/{}", uploadFolderPath, originMd5));
@@ -80,7 +81,7 @@ public class DataFileController {
@GetMapping("/download/{id}")
public void download(@PathVariable Long id, HttpServletResponse response) throws IOException {
DataFile dataFile = dataFileService.detailOrThrow(id);
DataFile dataFile = dataFileService.downloadFile(id);
File targetFile = new File(dataFile.getPath());
response.setHeader("Access-Control-Expose-Headers", "Content-Type");
response.setHeader("Content-Type", dataFile.getType());
@@ -91,7 +92,7 @@ public class DataFileController {
@PostMapping("/start")
public AmisResponse<StartResponse> start(@RequestBody StartRequest request) {
logger.info("Request: {}", request);
log.info("Request: {}", request);
Long id = dataFileService.initialDataFile(request.filename);
return AmisResponse.responseSuccess(new StartResponse(id.toString()));
}
@@ -158,7 +159,7 @@ public class DataFileController {
request.uploadId,
request.filename,
request.uploadId.toString(),
StrUtil.format("/upload/download/{}", request.uploadId)
StrUtil.format("{}/upload/download/{}", hostConfiguration.getPrefix(), request.uploadId)
));
} else {
throw new RuntimeException("合并文件失败");

View File

@@ -1,5 +1,8 @@
package com.eshore.gringotts.web.domain.controller;
import cn.hutool.core.util.StrUtil;
import com.eshore.gringotts.web.configuration.HostConfiguration;
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport;
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
@@ -7,33 +10,59 @@ import com.eshore.gringotts.web.domain.entity.Ware;
import com.eshore.gringotts.web.domain.service.DataFileService;
import com.eshore.gringotts.web.domain.service.DataResourceService;
import com.eshore.gringotts.web.domain.service.WareService;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.list.ImmutableList;
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;
/**
* @author lanyuanxiaoyao
* @date 2024-12-13
* @version 2024-12-13
*/
@Slf4j
@RestController
@RequestMapping("ware")
public class WareController extends SimpleControllerSupport<Ware, WareController.SaveItem, WareController.ListItem, WareController.DetailItem> {
private final HostConfiguration hostConfiguration;
private final WareService wareService;
private final DataResourceService dataResourceService;
private final DataFileService dataFileService;
public WareController(WareService service, DataResourceService dataResourceService, DataFileService dataFileService) {
public WareController(HostConfiguration hostConfiguration, WareService service, DataResourceService dataResourceService, DataFileService dataFileService) {
super(service);
this.hostConfiguration = hostConfiguration;
this.wareService = service;
this.dataResourceService = dataResourceService;
this.dataFileService = dataFileService;
}
@GetMapping(LIST + "_public")
public AmisResponse<ImmutableList<ListItem>> listPublic() throws Exception {
return AmisResponse.responseSuccess(wareService.listPublic().collect(this::toListItem));
}
@GetMapping("/submit/{id}")
public AmisResponse<Object> submit(@PathVariable Long id) throws JsonProcessingException {
wareService.submit(id);
return AmisResponse.responseSuccess();
}
@GetMapping("/retract/{id}")
public AmisResponse<Object> retract(@PathVariable Long id) {
wareService.retract(id);
return AmisResponse.responseSuccess();
}
@Override
protected Ware fromSaveItem(SaveItem saveItem) throws Exception {
protected Ware fromSaveItem(SaveItem saveItem) {
Ware ware = new Ware();
ware.setId(saveItem.getId());
ware.setResource(dataResourceService.detailOrThrow(saveItem.getResourceId()));
ware.setName(saveItem.getName());
ware.setDescription(saveItem.getDescription());
@@ -43,13 +72,33 @@ public class WareController extends SimpleControllerSupport<Ware, WareController
}
@Override
protected ListItem toListItem(Ware entity) throws Exception {
return new ListItem(entity);
protected ListItem toListItem(Ware entity) {
ListItem item = new ListItem();
item.setId(entity.getId());
item.setName(entity.getName());
item.setDescription(entity.getDescription());
item.setState(entity.getState().name());
item.setCreatedTime(entity.getCreatedTime());
item.setCreatedUsername(entity.getCreatedUser().getUsername());
return item;
}
@Override
protected DetailItem toDetailItem(Ware entity) throws Exception {
return new DetailItem(entity);
protected DetailItem toDetailItem(Ware entity) {
DetailItem item = new DetailItem();
item.setId(entity.getId());
item.setResourceId(entity.getResource().getId());
item.setResourceName(entity.getResource().getName());
item.setName(entity.getName());
item.setDescription(entity.getDescription());
item.setIconId(entity.getIcon().getId());
item.setContent(entity.getContent());
item.setIcon(StrUtil.format("{}/upload/download/{}", hostConfiguration.getPrefix(), entity.getIcon().getId()));
item.setCreatedTime(entity.getCreatedTime());
item.setCreatedUsername(entity.getCreatedUser().getUsername());
item.setModifiedTime(entity.getModifiedTime());
item.setModifiedUsername(entity.getModifiedUser().getUsername());
return item;
}
@Data
@@ -67,33 +116,17 @@ public class WareController extends SimpleControllerSupport<Ware, WareController
public static class ListItem extends SimpleListItem<Ware> {
private String name;
private String description;
public ListItem(Ware ware) {
this.setId(ware.getId());
this.setName(ware.getName());
this.setDescription(ware.getDescription());
this.setCreatedTime(ware.getCreatedTime());
this.setCreatedUsername(ware.getCreatedUser().getUsername());
}
private String state;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class DetailItem extends SaveItem {
private String icon;
private String resourceName;
private LocalDateTime createdTime;
private String createdUsername;
private LocalDateTime modifiedTime;
private String modifiedUsername;
public DetailItem(Ware ware) {
this.setId(ware.getId());
this.setResourceId(ware.getResource().getId());
this.setResourceName(ware.getResource().getName());
this.setName(ware.getName());
this.setDescription(ware.getDescription());
this.setIconId(ware.getIcon().getId());
this.setContent(ware.getContent());
}
}
}

View File

@@ -114,6 +114,7 @@ public class CheckOrder extends SimpleEntity {
public enum Type {
CONFIRMATION,
AUTHENTICATION,
MARKET,
}
public enum Target {

View File

@@ -1,6 +1,7 @@
package com.eshore.gringotts.web.domain.entity;
import com.eshore.gringotts.core.Constants;
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
@@ -48,7 +49,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
})
@SQLDelete(sql = "update " + Constants.TABLE_PREFIX + "ware" + " set deleted = true where id = ?")
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
public class Ware extends LogicDeleteEntity {
public class Ware extends CheckingNeededEntity {
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude
@@ -57,7 +58,7 @@ public class Ware extends LogicDeleteEntity {
private String name;
@Column(nullable = false)
private String description;
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude
private DataFile icon;

View File

@@ -68,6 +68,10 @@ public class DataFileService extends SimpleServiceSupport<DataFile> {
));
}
public DataFile downloadFile(Long id) {
return dataFileRepository.findOne((root, query, builder) -> builder.equal(root.get(DataFile_.id), id)).orElseThrow(DataFileNotFoundException::new);
}
public Long initialDataFile(String filename) {
DataFile dataFile = new DataFile();
dataFile.setFilename(filename);

View File

@@ -1,9 +1,21 @@
package com.eshore.gringotts.web.domain.service;
import cn.hutool.core.util.StrUtil;
import com.eshore.gringotts.web.domain.base.service.CheckingService;
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
import com.eshore.gringotts.web.domain.entity.CheckOrder;
import com.eshore.gringotts.web.domain.entity.User;
import com.eshore.gringotts.web.domain.entity.Ware;
import com.eshore.gringotts.web.domain.repository.WareRepository;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Service;
/**
@@ -11,9 +23,71 @@ import org.springframework.stereotype.Service;
* @date 2024-12-13
*/
@Slf4j
@Service
public class WareService extends SimpleServiceSupport<Ware> {
public WareService(WareRepository repository, UserService userService) {
@Service("com.eshore.gringotts.web.domain.service.WareService")
public class WareService extends SimpleServiceSupport<Ware> implements CheckingService {
private final WareRepository wareRepository;
private final CheckOrderService checkOrderService;
private final ObjectMapper mapper;
public WareService(WareRepository repository, UserService userService, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
super(repository, userService);
this.wareRepository = repository;
this.checkOrderService = checkOrderService;
this.mapper = builder.build();
}
public ImmutableList<Ware> listPublic() {
return Lists.immutable.ofAll(
wareRepository.findAll((root, query, builder) -> builder.equal(root.get("state"), Ware.State.NORMAL))
);
}
@Transactional(rollbackOn = Throwable.class)
@Override
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
if (StrUtil.equals(order.getKeyword(), "ware_check")) {
Long wareId = (Long) parameters.get("wareId");
Ware ware = detailOrThrow(wareId);
switch (operation) {
case APPLY:
ware.setState(Ware.State.NORMAL);
order.setState(CheckOrder.State.OVER);
break;
case REJECT:
ware.setState(Ware.State.DRAFT);
order.setState(CheckOrder.State.OVER);
break;
}
save(ware);
checkOrderService.save(order);
}
}
@Transactional(rollbackOn = Throwable.class)
public void submit(Long id) throws JsonProcessingException {
Ware ware = detailOrThrow(id);
ware.setState(Ware.State.CHECKING);
Long orderId = checkOrderService.save(new CheckOrder(
"ware_check",
StrUtil.format("数据资源「{}」的上架申请", ware.getName()),
CheckOrder.Type.MARKET,
mapper.writeValueAsString(Maps.immutable.of("wareId", ware.getId())),
"com.eshore.gringotts.web.domain.service.WareService",
User.Role.CHECKER
));
CheckOrder order = checkOrderService.detailOrThrow(orderId);
ware.setOrder(order);
save(ware);
}
@Transactional(rollbackOn = Throwable.class)
public void retract(Long id) {
Ware ware = detailOrThrow(id);
ware.setState(Ware.State.DRAFT);
save(ware);
CheckOrder order = ware.getOrder();
order.setState(CheckOrder.State.RETRACT);
checkOrderService.save(order);
}
}