You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
9.5 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.example.duplicate.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.duplicate.controller.param.UploadBatchFileParam;
import com.example.duplicate.controller.param.updateTaskDto;
import com.example.duplicate.controller.param.FileUpload;
import com.example.duplicate.service.TaskService;
import com.example.utils.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @ClassName TaskController
* @Description 任务接口
* @Author linjj
* @Date 2024/8/5 14:21
* @Version 1.0
*/
@RestController
@RequestMapping("/task")
@Api(value = "任务接口", tags = "任务对外接口")
@Slf4j
public class TaskController {
@Autowired
private TaskService taskService;
/**
* @description: 获取任务接口
* @params: collectid
* @return: data
* @author linjj
* @date: 2024/8/5 14:46
*/
@PostMapping("/getTask")
@ApiOperation("获取任务接口")
@ResponseBody
public CommonResult<?> GetTask(@RequestParam @ApiParam(required = false, name = "collectId", value = "采集器id") String collectId) {
return taskService.GetTask(collectId);
}
/**
* @description: 补偿患者所有采集任务接口
* @params: masterId
* @return: data
* @author linjj
* @date: 2024/8/5 15:31
*/
//补偿接口
@PostMapping(value = "repairTask")
@ApiOperation("补偿患者所有采集任务接口")
@ResponseBody
public CommonResult<?> repairTask(@RequestParam @ApiParam(required = false, name = "masterId", value = "患者masterId") String masterId) {
if (StringUtils.isBlank(masterId)) {
return CommonResult.failed("masterId不能为空");
}
return taskService.repairTask(masterId);
}
/**
* @description: 补偿患者单个采集任务接口
* @params: masterId
* @params: collectId
* @return: CommonResult
* @author linjj
* @date: 2024/8/6 9:15
*/
@PostMapping(value = "repairTaskByCollectId")
@ApiOperation("补偿患者单个采集任务接口")
@ResponseBody
public CommonResult<?> repairTask(@RequestParam @ApiParam(required = false, name = "masterId", value = "患者masterId") String masterId,
@RequestParam @ApiParam(required = false, name = "collectId", value = "采集器id") String collectId) {
if (StringUtils.isBlank(masterId)) {
return CommonResult.failed("masterId不能为空");
}
if (StringUtils.isBlank(collectId)) {
return CommonResult.failed("collectId不能为空");
}
return taskService.repairTaskByCollectId(masterId, collectId);
}
/**
* @description: 根据采集器id患者id删除单据
* @params: masterId
* @params: collectId
* @author linjj
* @date: 2024/12/26 14:30
*/
@PostMapping(value = "delFileBySource")
@ApiOperation("根据采集器id患者id删除单据")
@ResponseBody
public CommonResult<?> delFileBySource(@RequestParam @ApiParam(required = false, name = "masterId", value = "患者masterId") String masterId,
@RequestParam @ApiParam(required = false, name = "collectId", value = "采集器id") String collectId) {
if (StringUtils.isBlank(masterId)) {
return CommonResult.failed("masterId不能为空");
}
if (StringUtils.isBlank(collectId)) {
return CommonResult.failed("collectId不能为空");
}
return taskService.delFileBySource(masterId,collectId);
}
/**
* @description: 维护任务表接口
* @params: updateTaskDto
* @return: CommonResult
* @author linjj
* @date: 2024/8/6 9:17
*/
@PostMapping(value = "updateTask")
@ApiOperation("维护任务表接口")
@ResponseBody
public CommonResult<?> updateTask(updateTaskDto dto) {
return taskService.updateTask(dto);
}
/**
* @description: 文件上传接口
* @params: files
* @params: uploadBatchFileParam
* @return: CommonResult
* @author linjj
* @date: 2024/8/6 14:13
*/
@PostMapping(value = "fileUpload")
@ApiOperation("文件上传接口")
@ResponseBody
public CommonResult<?> fileUpload(@RequestPart("files") MultipartFile[] files, UploadBatchFileParam uploadBatchFileParam) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = dateFormat.format(new Date());
//成功流水号id
List<String> serialNumberIds = new ArrayList<>();
//失败流水号id
List<String> failIds = new ArrayList<>();
if (Objects.isNull(uploadBatchFileParam) || Objects.isNull(uploadBatchFileParam.getUploadFileParams())) {
log.info(format + "文件上传参数为空!");
return CommonResult.failed("文件上传参数为空!");
}
log.info(format + "本次文件上传传输参数为:" + JSONObject.toJSONString(uploadBatchFileParam));
List<FileUpload> fileUpload = JSONArray.parseArray(uploadBatchFileParam.getUploadFileParams(), FileUpload.class);
for (FileUpload dto : fileUpload) {
if (StringUtils.isBlank(dto.getMasterid())) {
log.info(format + "病案主键不能为空!");
return CommonResult.failed("病案主键不能为空");
}
if (StringUtils.isBlank(dto.getAssortid())) {
log.info(format + "文件分段id不能为空");
return CommonResult.failed("文件分段id不能为空");
}
if (StringUtils.isBlank(dto.getSource())) {
log.info(format + "文件来源不能为空!");
return CommonResult.failed("文件来源不能为空");
}
if (StringUtils.isBlank(dto.getSubassort())) {
log.info(format + "文件MD5码不能为空不能为空");
return CommonResult.failed("文件MD5码不能为空不能为空");
}
if (StringUtils.isBlank(dto.getTitle())) {
log.info(format + "保存数据库文件名不能为空!");
return CommonResult.failed("保存数据库文件名不能为空");
}
if (StringUtils.isBlank(dto.getFileName())) {
log.info(format + "真实文件名不能为空!");
return CommonResult.failed("真实文件名不能为空");
}
if (StringUtils.isBlank(dto.getSerialNumber())) {
log.info(format + "文件MD5码不能为空不能为空");
return CommonResult.failed("文件MD5码不能为空不能为空");
}
if (StringUtils.isBlank(dto.getSoleKey())) {
log.info(format + "SoleKey值不能为空");
return CommonResult.failed("文件MD5码不能为空不能为空");
}
}
if (fileUpload.size() != files.length) {
log.info(format + "文件上传参数为空!");
return CommonResult.failed("文件上传数量与参数不一致");
}
// 参数不含上传的,不匹配
List<String> originalFileNames = fileUpload.stream().map(item -> String.valueOf(item.getFileName())).collect(Collectors.toList());
for (MultipartFile file : files) {
if (!originalFileNames.contains(file.getOriginalFilename())) {
log.info(format + "文件上传参数为空!");
return CommonResult.failed("原文件名不匹配!");
}
}
for (MultipartFile file : files) {
for (FileUpload uploadFileParam : fileUpload) {
if (uploadFileParam.getFileName().equals(file.getOriginalFilename())) {
if (taskService.fileUpload(file, uploadFileParam)) {
serialNumberIds.add(uploadFileParam.getSubassort());
} else {
failIds.add(uploadFileParam.getSubassort());
}
}
}
}
log.info("本次文件上传传输完成,成功流水号:" + JSONObject.toJSONString(serialNumberIds));
log.info("本次文件上传传输完成,失败流水号:" + JSONObject.toJSONString(failIds));
return CommonResult.success("本次文件上传传输完成");
}
/**
* @description: 根据时间补偿采集器接口
* @author linjj
* @date: 2024/8/19 4:32
*/
@PostMapping(value = "compensate")
@ApiOperation("根据时间补偿采集器接口")
@ResponseBody
public CommonResult<?> compensate(@RequestParam @ApiParam(required = true, name = "startTime", value = "补偿开始时间") String startTime,
@RequestParam @ApiParam(required = true, name = "entTime", value = "补偿开始时间") String entTime,
@RequestParam @ApiParam(required = true, name = "collectId", value = "采集器id") String collectId) {
return taskService.compensate(startTime,entTime,collectId);
}
}