perf:过程日志改造

This commit is contained in:
曾文豪
2024-08-26 13:20:45 +08:00
parent 1db8ef9d85
commit ecb5aa1b29
19 changed files with 404 additions and 216 deletions

View File

@@ -4,19 +4,33 @@ package com.tiesheng.web.controller.comm;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.tiesheng.annotation.operation.OperationIgnore;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.util.service.TsCacheService;
import com.tiesheng.web.config.template.ToolTemplateHandler;
import com.tiesheng.web.pojos.dto.*;
import com.tiesheng.web.pojos.vo.TemplateInfoVO;
import com.tiesheng.web.pojos.vo.PicVerifyVo;
import com.tiesheng.web.service.FileUploadService;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.pojos.ApiResp;
import com.tiesheng.util.pojos.TokenBean;
import com.tiesheng.util.service.TsCacheService;
import com.tiesheng.web.pojos.dao.CoreLogProcess;
import com.tiesheng.web.pojos.dto.ChunkCheckDTO;
import com.tiesheng.web.pojos.dto.ChunkMergeDTO;
import com.tiesheng.web.pojos.dto.ChunkStartDTO;
import com.tiesheng.web.pojos.dto.ImageCodeDTO;
import com.tiesheng.web.pojos.imex.ExportDealDTO;
import com.tiesheng.web.pojos.imex.ImportDealDTO;
import com.tiesheng.web.pojos.imex.ImportInfoDTO;
import com.tiesheng.web.pojos.imex.ImportInfoVO;
import com.tiesheng.web.pojos.vo.PicVerifyVo;
import com.tiesheng.web.service.CoreLogService;
import com.tiesheng.web.service.FileUploadService;
import com.tiesheng.web.service.imex.TsExportHandler;
import com.tiesheng.web.service.imex.TsImportHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -35,7 +49,11 @@ public class ToolController {
@Autowired
FileUploadService fileUploadService;
@Autowired
List<ToolTemplateHandler> templateHandlerList;
List<TsImportHandler> importHandlers;
@Autowired
List<TsExportHandler> exportHandlers;
@Autowired
CoreLogService coreLogService;
/**
@@ -124,40 +142,102 @@ public class ToolController {
}
@TokenIgnore
@GetMapping("/template/info")
public ApiResp<TemplateInfoVO> templateInfo(TemplateInfoDTO dto) {
///////////////////////////////////////////////////////////////////////////
// import
///////////////////////////////////////////////////////////////////////////
List<ToolTemplateHandler> collect = templateHandlerList.stream()
.filter(it -> Objects.equals(it.getAction(), dto.getAction()))
.sorted((it, it2) -> it2.getSort() - it.getSort())
.collect(Collectors.toList());
if (CollUtil.isEmpty(collect)) {
throw new ApiException("没有找到对应的模版");
@TokenIgnore
@GetMapping("/imex/info")
public ApiResp<ImportInfoVO> importInfo(@Valid ImportInfoDTO dto) {
ImportInfoVO template = new ImportInfoVO();
if (Objects.equals(dto.getType(), "import")) {
List<TsImportHandler> collect = importHandlers.stream()
.filter(it -> Objects.equals(it.getAction(), dto.getAction()))
.sorted((it, it2) -> it2.getSort() - it.getSort())
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(collect)) {
TsImportHandler toolTemplateHandler = collect.get(0);
template.setTemplateUrl(toolTemplateHandler.getTemplateUrl());
template.setImexId(toolTemplateHandler.getImexId());
}
} else if (Objects.equals(dto.getType(), "export")) {
List<TsExportHandler> collect = exportHandlers.stream()
.filter(it -> Objects.equals(it.getAction(), dto.getAction()))
.sorted((it, it2) -> it2.getSort() - it.getSort())
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(collect)) {
TsExportHandler toolTemplateHandler = collect.get(0);
template.setImexId(toolTemplateHandler.getImexId());
}
}
ToolTemplateHandler toolTemplateHandler = collect.get(0);
TemplateInfoVO template = new TemplateInfoVO();
template.setTemplateUrl(toolTemplateHandler.getTemplateUrl());
template.setParams(toolTemplateHandler.getParms(dto.getParams()));
template.setTemplateId(toolTemplateHandler.getTeamplateId());
if (StrUtil.isEmpty(template.getImexId())) {
throw new ApiException("没有找到对应的模版");
}
return ApiResp.respOK(template);
}
@TokenIgnore
@PostMapping("/template/deal")
public ApiResp<String> templateDeal(@RequestBody TemplateDealDTO dto) {
List<ToolTemplateHandler> collect = templateHandlerList.stream().
filter(it -> Objects.equals(it.getTeamplateId(), dto.getTemplateId()))
@TokenIgnore
@OperationIgnore
@PostMapping("/import/deal")
public ApiResp<String> importDeal(@RequestBody @Valid ImportDealDTO dto, TokenBean token) {
List<TsImportHandler> collect = importHandlers.stream().
filter(it -> Objects.equals(it.getImexId(), dto.getImexId()))
.collect(Collectors.toList());
if (CollUtil.isEmpty(collect)) {
throw new ApiException("模版ID不存在");
throw new ApiException("导入ID不存在");
}
return ApiResp.respOK(collect.get(0).handler(dto));
TsImportHandler tsImportHandler = collect.get(0);
tsImportHandler.validToken(token);
List read = tsImportHandler.ready(dto, token);
if (CollUtil.isEmpty(read)) {
throw new ApiException("没有数据可以导入");
}
CoreLogProcess coreLogProcess = coreLogService.addProcess(tsImportHandler.getImexId(), read, tsImportHandler);
coreLogProcess.setParams(JSON.toJSONString(dto));
coreLogService.getCoreLogProcessMapper().updateById(coreLogProcess);
return ApiResp.respOK(coreLogProcess.getId());
}
///////////////////////////////////////////////////////////////////////////
// export
///////////////////////////////////////////////////////////////////////////
@TokenIgnore
@OperationIgnore
@PostMapping("/export/deal")
public ApiResp<String> exportDeal(@RequestBody @Valid ExportDealDTO dto, TokenBean token) {
List<TsExportHandler> collect = exportHandlers.stream().
filter(it -> Objects.equals(it.getImexId(), dto.getImexId()))
.collect(Collectors.toList());
if (CollUtil.isEmpty(collect)) {
throw new ApiException("导出ID不存在");
}
TsExportHandler tsExportHandler = collect.get(0);
tsExportHandler.validToken(token);
List read = tsExportHandler.ready(dto, token);
if (CollUtil.isEmpty(read)) {
throw new ApiException("没有数据可以导出");
}
CoreLogProcess coreLogProcess = coreLogService.addProcess(tsExportHandler.getImexId(), read, tsExportHandler);
coreLogProcess.setType("export");
coreLogProcess.setParams(JSON.toJSONString(dto));
coreLogService.getCoreLogProcessMapper().updateById(coreLogProcess);
return ApiResp.respOK(coreLogProcess.getId());
}
}