国网上送接口,提交

This commit is contained in:
wr
2023-06-30 15:36:28 +08:00
parent 9b0404a207
commit c05b67435f
4 changed files with 165 additions and 19 deletions

View File

@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.List;
/**
@@ -78,7 +79,7 @@ public class SupvPushGwController extends BaseController {
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("推送附件接口")
@ApiImplicitParam(name = "busIds",value = "请求体",required = true)
public HttpResult<Object> pushFile(@RequestBody List<String> busIds){
public HttpResult<Object> pushFile(@RequestBody List<String> busIds) throws IOException {
String methodDescribe = getMethodDescribe("pushFile");
supvPushGwService.pushFile(busIds);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);

View File

@@ -1,5 +1,6 @@
package com.njcn.process.service;
import java.io.IOException;
import java.util.List;
/**
@@ -30,7 +31,7 @@ public interface SupvPushGwService {
* @author cdf
* @date 2023/6/28
*/
boolean pushFile(List<String> busIds);
boolean pushFile(List<String> busIds) throws IOException;
/**

View File

@@ -1,16 +1,15 @@
package com.njcn.process.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.process.mapper.SupvFileMapper;
import com.njcn.process.mapper.SupvPlanMapper;
import com.njcn.process.mapper.SupvProblemMapper;
import com.njcn.process.mapper.SupvReportMMapper;
import com.njcn.process.pojo.dto.supv.PlanProblemData;
import com.njcn.process.pojo.dto.supv.WorkPlanData;
import com.njcn.process.pojo.po.SupvFile;
import com.njcn.process.pojo.po.SupvPlan;
import com.njcn.process.pojo.po.SupvProblem;
@@ -18,19 +17,26 @@ import com.njcn.process.pojo.po.SupvReportM;
import com.njcn.process.service.SupvPushGwService;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.Dic;
import com.njcn.system.pojo.po.DictData;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.po.Dept;
import com.njcn.user.pojo.vo.PvTerminalTreeVO;
import liquibase.pro.packaged.W;
import com.njcn.web.utils.RestTemplateUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.IOUtils;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -41,6 +47,7 @@ import java.util.stream.Collectors;
* @date 2023/6/28
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class SupvPushGwServiceImpl implements SupvPushGwService {
@@ -56,6 +63,7 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
private final DeptFeignClient deptFeignClient;
private final FileStorageUtil fileStorageUtil;
@Override
public boolean pushPlan(List<String> planIds) {
LambdaQueryWrapper<SupvPlan> lambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -167,7 +175,7 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
//TODO 调用国网接口
// Map map = postStatsUrl(getUrl(1), null, supvPlanList);
for(SupvPlan supvPlan: supvPlanList){
SupvPlan supvPlanPO = new SupvPlan();
@@ -220,6 +228,8 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
//TODO
// 目前一个问题对应一个措施,上送一个问题需要调用问题接口和整改措施接口
// Map map = postStatsUrl(getUrl(2), null, supvProblemList);
// Map map = postStatsUrl(getUrl(3), null, supvProblemList);
for(SupvProblem supvProblem:supvProblemList){
SupvProblem supvProblemPO = new SupvProblem();
@@ -231,7 +241,7 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
}
@Override
public boolean pushFile(List<String> busIds) {
public boolean pushFile(List<String> busIds) throws IOException {
LambdaQueryWrapper<SupvFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SupvFile::getBusiId,busIds);
List<SupvFile> supvFiles = supvFileMapper.selectList(lambdaQueryWrapper);
@@ -239,6 +249,7 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
throw new BusinessException("一次最多上送100条数据");
}
//TODO 调用上送接口
// Map map = postFileUrl(getUrl(4), null, supvFiles.get(0));
return true;
}
@@ -252,7 +263,7 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
throw new BusinessException("一次最多上送100条数据");
}
//TODO 调用上送接口
// Map map = postStatsUrl(getUrl(5), null, supvReportMList);
for(SupvReportM supvReportM : supvReportMList){
SupvReportM supvReportMPO = new SupvReportM();
@@ -275,7 +286,7 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
}
//TODO
// Map map = postStatsUrl(getUrl(6), null, supvPlanList);
for(SupvPlan supvPlan : supvPlanList) {
supvPlan.setIsUploadHead(2);
@@ -283,4 +294,139 @@ public class SupvPushGwServiceImpl implements SupvPushGwService {
}
return true;
}
/**
* 通用上送提交
* @param url
* @param token
* @param list
* @return
*/
public Map postStatsUrl(String url,String token,List<?> list){
Map body = new HashMap();
Map<String, String> mapHeader = new HashMap<>();
mapHeader.put("Content-Type", "application/json; charset=utf-8");
mapHeader.put("x-token", token);
mapHeader.put("x-date", System.currentTimeMillis() + "");
mapHeader.put("x-signature", "123");
//设置入参
Map<String, Object> mapBody = new HashMap<>();
mapBody.put("stats", list);
ResponseEntity<Map> userEntity = RestTemplateUtil.post(url, mapHeader, mapBody, Map.class, new ArrayList<>());
if (userEntity.getStatusCodeValue() == 200) {
//获取返回体
body = userEntity.getBody();
log.info(Thread.currentThread().getName() + "获取返回体 getResourceData" + body + "结束----");
}
return body;
}
/**
* 文件上送提交
* @param url
* @param token
* @return
*/
public Map postFileUrl(String url,String token,SupvFile supvFile) throws IOException {
Map body = new HashMap();
Map<String, String> mapHeader = new HashMap<>();
mapHeader.put("Content-Type", "multipart/form-data");
String path=supvFile.getFileUrl();
if(StrUtil.isBlank(path)){
throw new BusinessException("获取文件上传路径为空!请检查原始路径是否存在");
}
String suffix = path.substring(path.lastIndexOf("."));
String attachmentName = supvFile.getAttachmentName();
if(StrUtil.isNotBlank(attachmentName)){
int i = attachmentName.lastIndexOf(".");
if(i!=-1){
attachmentName = attachmentName.substring(0,i);
}
}else{
throw new BusinessException("不存在文件,文件名称");
}
InputStream fileStream = fileStorageUtil.getFileStream(path);
if(ObjectUtil.isNull(fileStream)){
throw new BusinessException("文件服务器,文件不存在");
}
byte[] fileBytes = IOUtils.toByteArray(fileStream);
File files = File.createTempFile(attachmentName, suffix);
FileOutputStream stream = new FileOutputStream(files);
stream.write(fileBytes);
stream.close();
FileSystemResource resource = new FileSystemResource(files);
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("uuid", supvFile.getUuid());
param.add("file", resource);
param.add("attachmentName", supvFile.getAttachmentName());
param.add("attachmentType", supvFile.getAttachmentType());
param.add("busiId", supvFile.getBusiId());
param.add("uploaderName", supvFile.getUploaderName());
String uploadTime = supvFile.getUploadTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
param.add("uploadTime", uploadTime);
param.add("uploaderId", supvFile.getUploaderId());
ResponseEntity<Map> userEntity = RestTemplateUtil.post(url, mapHeader, param, Map.class, new ArrayList<>());
files.deleteOnExit();
if (userEntity.getStatusCodeValue() == 200) {
//获取返回体
body = userEntity.getBody();
log.info(Thread.currentThread().getName() + "获取返回体 getResourceData" + body + "结束----");
}
return body;
}
/**
* 根据type获取上送地址
* @param type
* @return
*/
public static String getUrl(Integer type){
String url="http://ip:port";
switch (type){
case 1:
/**
* 接收电能质量技术监督工作计划数据接口
*/
url+="/WMCenter/powerQuality/plan/create";
break;
case 2:
/**
* 接收电能质量技术监督实施问题数据接口
*/
url+="/WMCenter/powerQuality/problem/create";
break;
case 3:
/**
* 接收电能质量技术监督实施问题整改数据接口
*/
url+="/WMCenter/powerQuality/problem/update";
break;
case 4:
/**
* 总部提供附件接收接口,省公司调用此接口,完成附件上报
*/
url+="/WMCenter/powerQuality/file/create";
break;
case 5:
/**
* 接收电能质量技术监督月报统计数据接口
*/
url+="/WMCenter/powerQuality/monthReport/create";
break;
case 6:
/**
* 删除电能质量技术监督工作计划接口
*/
url+="/WMCenter/powerQuality/plan/delete";
break;
}
return url;
}
}