离线数据上传第一版代码提交
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.njcn.csharmonic.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.csharmonic.service.OfflineDataUploadService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:离线数据上传解析控制类
|
||||
*
|
||||
* @author gfh
|
||||
* @version 1.0.0
|
||||
* @createTime 2024/7/22 13:56
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/offlineDataUpload")
|
||||
@Api(tags = "离线数据上传")
|
||||
@AllArgsConstructor
|
||||
public class OfflineDataUploadController extends BaseController {
|
||||
|
||||
private final OfflineDataUploadService offlineDataUploadService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping(value = "/uploadAnalysis",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@ApiOperation("解析上传的文件")
|
||||
public HttpResult<byte[]> uploadAnalysis(@RequestPart("files") List<MultipartFile> files,@RequestParam("type") String type) throws Exception{
|
||||
String methodDescribe = getMethodDescribe("uploadAnalysis");
|
||||
byte[] result = offlineDataUploadService.uploadAnalysis(files,type);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.csharmonic.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 类的介绍:离线数据上传解析服务类
|
||||
* </p>
|
||||
*
|
||||
* @author gfh
|
||||
* @since 2024/7/22 13:56
|
||||
*/
|
||||
public interface OfflineDataUploadService {
|
||||
|
||||
byte[] uploadAnalysis(List<MultipartFile> files,String type) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.njcn.csharmonic.service.impl;
|
||||
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csharmonic.offline.log.Log;
|
||||
import com.njcn.csharmonic.offline.log.vo.NewTaglogbuffer;
|
||||
import com.njcn.csharmonic.offline.mincfg.AnalyseComtradeCfg;
|
||||
import com.njcn.csharmonic.offline.mincfg.tagComtradeCfg;
|
||||
import com.njcn.csharmonic.offline.vo.Response;
|
||||
import com.njcn.csharmonic.service.OfflineDataUploadService;
|
||||
import com.njcn.influx.pojo.po.cs.PqdData;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:离线数据上传解析服务实现类
|
||||
*
|
||||
* @author gfh
|
||||
* @version 1.0.0
|
||||
* @createTime 2024/7/22 13:56
|
||||
*/
|
||||
@Service
|
||||
public class OfflineDataUploadServiceImpl implements OfflineDataUploadService {
|
||||
|
||||
@Override
|
||||
public byte[] uploadAnalysis(List<MultipartFile> files,String type) throws Exception{
|
||||
byte[] bytes = null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
|
||||
List<Response> responses = new ArrayList<>();
|
||||
//min解析较为特殊需要同时解析所有文件
|
||||
if(!files.isEmpty() && "min".equals(type)){
|
||||
Response response = new Response();
|
||||
response.setFilename("min");
|
||||
List<PqdData> pqdData = AnalyseComtradeCfg.processDirectory(files);
|
||||
response.setObj(pqdData);
|
||||
responses.add(response);
|
||||
}else{
|
||||
for(MultipartFile file : files){
|
||||
Response response = new Response();
|
||||
response.setFilename(file.getOriginalFilename());
|
||||
if("comtrade".equals(type) && file.getOriginalFilename().indexOf(".cfg") != -1) {
|
||||
tagComtradeCfg tagComtradeCfg = AnalyseComtradeCfg.analyseComtradeCfg(file);
|
||||
response.setObj(tagComtradeCfg);
|
||||
}else if("log".equals(type) && file.getOriginalFilename().indexOf(".bin") != -1){
|
||||
List<NewTaglogbuffer> newTaglogbuffers = Log.convertLog(file);
|
||||
response.setObj(newTaglogbuffers);
|
||||
}
|
||||
responses.add(response);
|
||||
}
|
||||
}
|
||||
try {
|
||||
oos.writeObject(responses);
|
||||
bytes = baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new BusinessException("数据集对象转字节数组失败");
|
||||
} finally {
|
||||
oos.close();
|
||||
baos.close();
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user