1.业务中台-电网拓扑图相关信息

This commit is contained in:
wr
2025-09-29 10:03:41 +08:00
parent 28daba40af
commit 722c4e11c3
16 changed files with 903 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
package com.njcn.jbsyncdata;
import com.github.jeffreyning.mybatisplus.conf.EnableMPP;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -10,6 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(scanBasePackages = "com.njcn")
@EnableScheduling
@EnableAsync
@EnableMPP
public class JbSyncdataApplication {
public static void main(String[] args) {

View File

@@ -0,0 +1,16 @@
package com.njcn.jbsyncdata.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.jbsyncdata.pojo.ywzt.BusBarResult;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wr
* @since 2024-08-07
*/
public interface BusBarMapper extends MppBaseMapper<BusBarResult.BusBar> {
}

View File

@@ -0,0 +1,16 @@
package com.njcn.jbsyncdata.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.jbsyncdata.pojo.ywzt.IncomeAndOutgoLinesResult;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wr
* @since 2024-08-07
*/
public interface IncomeAndOutgoMapper extends MppBaseMapper<IncomeAndOutgoLinesResult.PsrInfo> {
}

View File

@@ -0,0 +1,16 @@
package com.njcn.jbsyncdata.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.jbsyncdata.pojo.ywzt.LineDetail;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wr
* @since 2024-08-07
*/
public interface LineDetailMapper extends MppBaseMapper<LineDetail> {
}

View File

@@ -0,0 +1,70 @@
package com.njcn.jbsyncdata.pojo.ywzt;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author wr
* @description
* @date 2025/9/25 16:56
*/
@Data
public class BusBarResult {
private Result result;
@Data
public static class Result {
private List<BusBar> records;
}
@Data
@TableName("pq_ywzt_busbar")
public static class BusBar {
@MppMultiId
@TableField(value = "psr_id")
private String psrId;
@MppMultiId
@TableField(value = "psr_sub_id")
private String psrSubId;
private String psrType;
private String psrState;
private String cityName;
private String maintOrgName;
private String maintGroupName;
private String voltageLevelId;
private String voltageLevelName;
private String name;
private String psrStateName;
private String equipmentOwnerName;
/**
* 创建用户
*/
private String createBy;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新用户
*/
private String updateBy;
/**
* 更新时间
*/
private LocalDateTime updateTime;
}
}

View File

@@ -0,0 +1,76 @@
package com.njcn.jbsyncdata.pojo.ywzt;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class IncomeAndOutgoLinesResult {
/**
* 获取进出线
*/
private Result result;
@Data
public static class Result {
private int incomeTotal;
private int outgoTotal;
//进线
private List<PsrInfo> incomeList;
//出线
private List<PsrInfo> outgoList;
}
@Data
@TableName("pq_ywzt_xl")
public static class PsrInfo {
@MppMultiId
@TableField(value = "psr_id")
private String psrId;
@MppMultiId
@TableField(value = "psr_sub_id")
private String psrSubId;
private String psrName;
private String psrType;
private String psrTypeName;
private String voltageLevelId;
private String voltageLevelCode;
private String voltageLevelName;
private String maintOrg;
private String maintOrgName;
//进线或者出线
@MppMultiId
@TableField(value = "type")
private Integer type;
/**
* 创建用户
*/
private String createBy;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新用户
*/
private String updateBy;
/**
* 更新时间
*/
private LocalDateTime updateTime;
}
}

View File

@@ -0,0 +1,31 @@
package com.njcn.jbsyncdata.pojo.ywzt;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
/**
* @author wr
* @description
* @date 2025/9/28 10:32
*/
@Data
@TableName("pq_ywzt_xl_detail")
public class LineDetail {
@TableId(value = "psr_id")
private String psrId;
private String psrSubStartId;
private String psrSubStartName;
private String psrSubEndId;
private String psrSubEndName;
}

View File

@@ -0,0 +1,165 @@
package com.njcn.jbsyncdata.pojo.ywzt;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author wr
* @description
* @date 2025/9/28 10:18
*/
@NoArgsConstructor
@Data
public class LineDetailResult {
@JsonProperty("status")
private String status;
@JsonProperty("errors")
private Object errors;
@JsonProperty("result")
private ResultDTO result;
@NoArgsConstructor
@Data
public static class ResultDTO {
@JsonProperty("equipType")
private String equipType;
@JsonProperty("distribution")
private String distribution;
@JsonProperty("equipTypeName")
private String equipTypeName;
@JsonProperty("specialMode")
private Object specialMode;
@JsonProperty("equipArchivesGroupList")
private List<EquipArchivesGroupListDTO> equipArchivesGroupList;
@JsonProperty("equipStatisticList")
private Object equipStatisticList;
@NoArgsConstructor
@Data
public static class EquipArchivesGroupListDTO {
@JsonProperty("objId")
private String objId;
@JsonProperty("groupName")
private String groupName;
@JsonProperty("previousGroup")
private Object previousGroup;
@JsonProperty("parentGroup")
private Object parentGroup;
@JsonProperty("viewFlag")
private Boolean viewFlag;
@JsonProperty("subEquipArchivesGroupList")
private List<SubEquipArchivesGroupListDTO> subEquipArchivesGroupList;
@JsonProperty("equipArchivesFieldList")
private List<?> equipArchivesFieldList;
@JsonProperty("equipArchivesTabList")
private Object equipArchivesTabList;
@NoArgsConstructor
@Data
public static class SubEquipArchivesGroupListDTO {
@JsonProperty("objId")
private String objId;
@JsonProperty("groupName")
private String groupName;
@JsonProperty("previousGroup")
private Object previousGroup;
@JsonProperty("parentGroup")
private String parentGroup;
@JsonProperty("viewFlag")
private Boolean viewFlag;
@JsonProperty("subEquipArchivesGroupList")
private Object subEquipArchivesGroupList;
@JsonProperty("equipArchivesFieldList")
private List<EquipArchivesFieldListDTO> equipArchivesFieldList;
@JsonProperty("equipArchivesTabList")
private Object equipArchivesTabList;
@NoArgsConstructor
@Data
public static class EquipArchivesFieldListDTO {
@JsonProperty("objId")
private String objId;
@JsonProperty("modelType")
private String modelType;
@JsonProperty("fieldName")
private String fieldName;
@JsonProperty("lowerCamelFieldName")
private String lowerCamelFieldName;
@JsonProperty("fieldDescribe")
private String fieldDescribe;
@JsonProperty("fieldValue")
private String fieldValue;
@JsonProperty("fieldEscapeValue")
private String fieldEscapeValue;
@JsonProperty("fieldStorageType")
private String fieldStorageType;
@JsonProperty("fieldUnit")
private Object fieldUnit;
@JsonProperty("fieldGroup")
private String fieldGroup;
@JsonProperty("previousField")
private Object previousField;
@JsonProperty("detailedCardDisp")
private String detailedCardDisp;
@JsonProperty("dispRestrFieldName")
private Object dispRestrFieldName;
@JsonProperty("dispRestrFieldValue")
private Object dispRestrFieldValue;
@JsonProperty("dispMode")
private String dispMode;
@JsonProperty("linkMode")
private Object linkMode;
@JsonProperty("maintainEnable")
private String maintainEnable;
@JsonProperty("simpleMaintainEnable")
private String simpleMaintainEnable;
@JsonProperty("maintRestrFieldName")
private String maintRestrFieldName;
@JsonProperty("maintRestrFieldValue")
private String maintRestrFieldValue;
@JsonProperty("maintenanceMode")
private String maintenanceMode;
@JsonProperty("componentType")
private Object componentType;
@JsonProperty("textLength")
private Object textLength;
@JsonProperty("textRule")
private Object textRule;
@JsonProperty("minValue")
private Object minValue;
@JsonProperty("maxValue")
private Object maxValue;
@JsonProperty("accuracy")
private Object accuracy;
@JsonProperty("copyable")
private Object copyable;
@JsonProperty("required")
private String required;
@JsonProperty("reqRestrFieldName")
private Object reqRestrFieldName;
@JsonProperty("reqRestrFieldValue")
private Object reqRestrFieldValue;
@JsonProperty("refCons")
private Object refCons;
@JsonProperty("refConsFilterCond")
private Object refConsFilterCond;
@JsonProperty("foreignEquipType")
private Object foreignEquipType;
@JsonProperty("foreignDistribution")
private Object foreignDistribution;
@JsonProperty("commomCodeVoList")
private Object commomCodeVoList;
@JsonProperty("remark")
private Object remark;
@JsonProperty("equipType")
private String equipType;
}
}
}
}
}

View File

@@ -0,0 +1,19 @@
package com.njcn.jbsyncdata.service;
import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.jbsyncdata.pojo.ywzt.BusBarResult;
/**
* @author wr
* @description
* @date 2025/9/25 17:13
*/
public interface YwZtBusBarService extends IMppService<BusBarResult.BusBar> {
/**
* 获取业务中台变电站下所有母线
* @param cookie
* @param aMapToken
* @return
*/
Boolean addYwZtBusBar(String cookie, String aMapToken);
}

View File

@@ -0,0 +1,20 @@
package com.njcn.jbsyncdata.service;
import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.jbsyncdata.pojo.ywzt.IncomeAndOutgoLinesResult;
/**
* @author wr
* @description
* @date 2025/9/25 17:13
*/
public interface YwZtIncomeAndOutgoService extends IMppService<IncomeAndOutgoLinesResult.PsrInfo> {
/**
* 获得变电站中进线和出线
* @param cookie
* @param aMapToken
* @return
*/
Boolean addYwZtIncomeAndOutgo(String cookie, String aMapToken) throws InterruptedException;
}

View File

@@ -0,0 +1,20 @@
package com.njcn.jbsyncdata.service;
import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.jbsyncdata.pojo.ywzt.BusBarResult;
import com.njcn.jbsyncdata.pojo.ywzt.LineDetail;
/**
* @author wr
* @description
* @date 2025/9/25 17:13
*/
public interface YwZtLineDetailService extends IMppService<LineDetail> {
/**
* 获取业务中台变电站下所有母线
* @param aMapToken
* @return
*/
Boolean addYwZtLineDetail(String aMapToken);
}

View File

@@ -2,7 +2,7 @@ package com.njcn.jbsyncdata.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
@@ -69,21 +69,37 @@ public class PmsSubstationServiceImpl extends ServiceImpl<PmsSubstationMapper, P
params.put("fieldName", "");
params.put("compare", "");
params.put("fieldValue", "");
params.put("fields", "name,city,psrId");
paramList.add(filter);
params.put("filters", paramList);
//组装好json开始发送请求
Map<String, String> headers = new HashMap<>();
headers.put("x-token", tokenWithRestTemplate.getAccess_token());
ResponseEntity<String> post = restTemplateUtil.post(tokenComponent.getUrl().concat("/PSRCenter/queryServices/listPropertiesByFilters"), headers, param, String.class);
String body = post.getBody().replaceAll("#", "").replaceAll(psrType, "zf01");
String a="{\n" +
" \"distribution\": 1,\n" +
" \"psrType\": \"zf01\",\n" +
" \"params\": {\n" +
" \"current\": 1,\n" +
" \"size\": 20000,\n" +
" \"filters\": [\n" +
" {\n" +
" \"fieldName\": \"\",\n" +
" \"compare\": \"\",\n" +
" \"fieldValue\": \"\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
ResponseEntity<String> post = restTemplateUtil.post(tokenComponent.getUrl().concat("/PSRCenter/queryServices/listPropertiesByFilters"), headers, a, String.class);
String body = post.getBody().replaceAll("#", "");
YWZTSubstation ywztSubstation = JSONObject.parseObject(body, YWZTSubstation.class);
YWZTSubstation.ResultDTO.Zf01DTO zf01 = ywztSubstation.getResult().getZf01();
List<YWZTSubstation.ResultDTO.Zf01DTO.RecordsDTO> records = zf01.getRecords();
List<PmsSubstation> info = new ArrayList<>();
for (YWZTSubstation.ResultDTO.Zf01DTO.RecordsDTO record : records) {
YWZTSubstation.ResultDTO.Zf01DTO.RecordsDTO.ResourceDTO resource = record.getResource();
PmsSubstation byId = this.getById(record.getId());
if (ObjectUtil.isNull(byId)) {
PmsSubstation substation = new PmsSubstation();
substation.setId(record.getId());
substation.setOrgId(resource.getCity());
@@ -97,14 +113,19 @@ public class PmsSubstationServiceImpl extends ServiceImpl<PmsSubstationMapper, P
substation.setRunTime(LocalDateTimeUtil.parse(resource.getCtime(), "yyyy-MM-dd HH:mm:ss"));
//经纬度
String geoPositon = resource.getGeoPositon();
if(StrUtil.
isNotBlank(geoPositon)){
String[] split = geoPositon.split(",");
substation.setLng(new BigDecimal(split[0]));
substation.setLat(new BigDecimal(split[1]));
}
substation.setCreateTime(LocalDateTime.now());
substation.setUpdateTime(LocalDateTime.now());
info.add(substation);
}
}
System.out.println(info);
return this.saveOrUpdateBatch(info);
}

View File

@@ -0,0 +1,62 @@
package com.njcn.jbsyncdata.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.jbsyncdata.mapper.BusBarMapper;
import com.njcn.jbsyncdata.mapper.DictDataMapper;
import com.njcn.jbsyncdata.pojo.DictData;
import com.njcn.jbsyncdata.pojo.PmsSubstation;
import com.njcn.jbsyncdata.pojo.ywzt.BusBarResult;
import com.njcn.jbsyncdata.service.IPmsSubstationService;
import com.njcn.jbsyncdata.service.YwZtBusBarService;
import com.njcn.jbsyncdata.util.YwZtUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author wr
* @description
* @date 2025/9/25 17:13
*/
@Service
@RequiredArgsConstructor
public class YwZtBusBarServiceImpl extends MppServiceImpl<BusBarMapper, BusBarResult.BusBar> implements YwZtBusBarService {
private final IPmsSubstationService pmsSubstationService;
private final DictDataMapper dictDataMapper;
@Override
public Boolean addYwZtBusBar(String cookie, String aMapToken) {
List<DictData> devVoltage = dictDataMapper.selectList("Dev_Voltage_Stand");
List<PmsSubstation> list = pmsSubstationService.list().stream().filter(x->x.getType().equals("zf01")).collect(Collectors.toList());
for (int i = 0; i < list.size(); i++) {
System.out.println("-----------"+i);
List<BusBarResult.BusBar> busBars = YwZtUtil.busBar(list.get(i).getId(), list.get(i).getType(), "0311", cookie, aMapToken);
if (CollUtil.isNotEmpty(busBars)) {
for (BusBarResult.BusBar busBar : busBars) {
busBar.setVoltageLevelId(getAlgoDescribe(busBar.getVoltageLevelName(), devVoltage));
busBar.setCreateTime(LocalDateTime.now());
busBar.setUpdateTime(LocalDateTime.now());
}
this.saveOrUpdateBatchByMultiId(busBars);
}
}
return false;
}
public String getAlgoDescribe(String name, List<DictData> dictData) {
if (StrUtil.isNotBlank(name)) {
List<DictData> dictDataList = dictData.stream().filter(x -> name.contains(x.getName())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(dictDataList)) {
return dictDataList.get(0).getId();
}
}
return null;
}
}

View File

@@ -0,0 +1,72 @@
package com.njcn.jbsyncdata.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.jbsyncdata.mapper.DictDataMapper;
import com.njcn.jbsyncdata.mapper.IncomeAndOutgoMapper;
import com.njcn.jbsyncdata.pojo.DictData;
import com.njcn.jbsyncdata.pojo.PmsSubstation;
import com.njcn.jbsyncdata.pojo.ywzt.IncomeAndOutgoLinesResult;
import com.njcn.jbsyncdata.service.IPmsSubstationService;
import com.njcn.jbsyncdata.service.YwZtIncomeAndOutgoService;
import com.njcn.jbsyncdata.util.YwZtUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author wr
* @description
* @date 2025/9/25 17:13
*/
@Service
@RequiredArgsConstructor
public class YwZtIncomeAndOutgoServiceImpl extends MppServiceImpl<IncomeAndOutgoMapper, IncomeAndOutgoLinesResult.PsrInfo> implements YwZtIncomeAndOutgoService {
private final IPmsSubstationService pmsSubstationService;
private final DictDataMapper dictDataMapper;
@Override
public Boolean addYwZtIncomeAndOutgo(String cookie, String aMapToken) throws InterruptedException {
List<DictData> devVoltage = dictDataMapper.selectList("Dev_Voltage_Stand");
List<PmsSubstation> list = pmsSubstationService.list().stream().collect(Collectors.toList());
for (int i = 0; i < list.size(); i++) {
System.out.println("------------------"+i);
List<IncomeAndOutgoLinesResult.PsrInfo> list1 = this.list(new LambdaQueryWrapper<IncomeAndOutgoLinesResult.PsrInfo>()
.eq(IncomeAndOutgoLinesResult.PsrInfo::getPsrSubId, list.get(i).getId()));
if(CollUtil.isEmpty(list1)){
List<IncomeAndOutgoLinesResult.PsrInfo> psrInfos = YwZtUtil.inComeAndOutgo(list.get(i).getId(), cookie, aMapToken);
if (CollUtil.isNotEmpty(psrInfos)) {
for (IncomeAndOutgoLinesResult.PsrInfo psrInfo : psrInfos) {
psrInfo.setVoltageLevelId(getAlgoDescribe(psrInfo.getVoltageLevelCode(), devVoltage));
psrInfo.setCreateTime(LocalDateTime.now());
psrInfo.setUpdateTime(LocalDateTime.now());
}
this.saveOrUpdateBatchByMultiId(psrInfos);
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
return true;
}
public String getAlgoDescribe(String name, List<DictData> dictData) {
if (StrUtil.isNotBlank(name)) {
List<DictData> dictDataList = dictData.stream().filter(x -> x.getAlgoDescribe() == Integer.valueOf(name)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(dictDataList)) {
return dictDataList.get(0).getId();
}
}
return name;
}
}

View File

@@ -0,0 +1,59 @@
package com.njcn.jbsyncdata.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.jbsyncdata.mapper.BusBarMapper;
import com.njcn.jbsyncdata.mapper.DictDataMapper;
import com.njcn.jbsyncdata.mapper.LineDetailMapper;
import com.njcn.jbsyncdata.pojo.DictData;
import com.njcn.jbsyncdata.pojo.PmsSubstation;
import com.njcn.jbsyncdata.pojo.ywzt.BusBarResult;
import com.njcn.jbsyncdata.pojo.ywzt.IncomeAndOutgoLinesResult;
import com.njcn.jbsyncdata.pojo.ywzt.LineDetail;
import com.njcn.jbsyncdata.service.IPmsSubstationService;
import com.njcn.jbsyncdata.service.YwZtBusBarService;
import com.njcn.jbsyncdata.service.YwZtLineDetailService;
import com.njcn.jbsyncdata.util.YwZtUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author wr
* @description
* @date 2025/9/25 17:13
*/
@Service
@RequiredArgsConstructor
public class YwZtLineDetailServiceImpl extends MppServiceImpl<LineDetailMapper, LineDetail> implements YwZtLineDetailService {
private final YwZtIncomeAndOutgoServiceImpl incomeAndOutgoService;
@Override
public Boolean addYwZtLineDetail( String aMapToken) {
List<IncomeAndOutgoLinesResult.PsrInfo> list = incomeAndOutgoService.list(new LambdaQueryWrapper<IncomeAndOutgoLinesResult.PsrInfo>()
.eq(IncomeAndOutgoLinesResult.PsrInfo::getPsrType,"xl"));
List<String> collect = list.stream().map(IncomeAndOutgoLinesResult.PsrInfo::getPsrId).distinct().collect(Collectors.toList());
List<LineDetail> info=new ArrayList<>();
for (int i = 0; i < collect.size(); i++) {
System.out.println("-----------"+i);
LineDetail lineDetail = YwZtUtil.lineDetailSub(collect.get(i), aMapToken);
if (ObjUtil.isNotNull(lineDetail)) {
info.add(lineDetail);
}
}
if(CollUtil.isNotEmpty(info)){
this.saveOrUpdateBatch(info);
}
return false;
}
}

View File

@@ -0,0 +1,215 @@
package com.njcn.jbsyncdata.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.njcn.jbsyncdata.pojo.ywzt.BusBarResult;
import com.njcn.jbsyncdata.pojo.ywzt.IncomeAndOutgoLinesResult;
import com.njcn.jbsyncdata.pojo.ywzt.LineDetail;
import com.njcn.jbsyncdata.pojo.ywzt.LineDetailResult;
import okhttp3.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class YwZtUtil {
public static List<IncomeAndOutgoLinesResult.PsrInfo> inComeAndOutgo(String prsId, String cookie, String aMapToken) {
List<IncomeAndOutgoLinesResult.PsrInfo> info = new ArrayList<>();
String url = "http://dwyzt.jibei.sgcc.com.cn/amap-gateway-service/amap-app-service/graphicsExtension/station/intervals?psrId=" + prsId;
// 创建HTTP客户端
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(600, TimeUnit.SECONDS)
.readTimeout(600, TimeUnit.SECONDS)
.writeTimeout(600, TimeUnit.SECONDS)
.build();
// 创建请求
Request request = new Request.Builder().url(url).addHeader("Cookie", cookie).addHeader("amap-token", aMapToken).get().build();
try {
// 发送请求并获取响应
Response response = client.newCall(request).execute();
if (response.isSuccessful() && response.body() != null) {
String responseBody = response.body().string();
System.out.println(responseBody);
// 解析JSON响应
IncomeAndOutgoLinesResult incomeAndOutgoLinesResult = JSONObject.parseObject(responseBody, IncomeAndOutgoLinesResult.class);
if(ObjectUtil.isNotNull(incomeAndOutgoLinesResult.getResult())){
for (IncomeAndOutgoLinesResult.PsrInfo in : incomeAndOutgoLinesResult.getResult().getIncomeList()) {
in.setType(1);
in.setPsrSubId(prsId);
info.add(in);
}
for (IncomeAndOutgoLinesResult.PsrInfo out : incomeAndOutgoLinesResult.getResult().getOutgoList()) {
out.setType(0);
out.setPsrSubId(prsId);
info.add(out);
}
}
return info;
} else {
System.out.println("请求失败,响应码: " + response.code());
}
} catch (IOException e) {
e.printStackTrace();
}
return info;
}
/**
* 获取母线
*
* @param prsId
* @param containerType
* @param psrType
* @param cookie
* @param aMapToken
* @return
*/
public static List<BusBarResult.BusBar> busBar(String prsId, String containerType, String psrType, String cookie, String aMapToken) {
{
String url = "http://dwyzt.jibei.sgcc.com.cn/amap-gateway-service/amap-app-service/associateDevStat/associateDeviceDetail";
// 创建HTTP客户端
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(6000, TimeUnit.SECONDS)
.readTimeout(6000, TimeUnit.SECONDS)
.writeTimeout(6000, TimeUnit.SECONDS)
.build();
RequestBody body = RequestBody.create(MediaType.parse("application/json"), "{\n" +
" \"containerId\": \"" + prsId + "\",\n" +
" \"containerType\": \"" + containerType + "\",\n" +
" \"psrType\": \"" + psrType + "\",\n" +
" \"name\": \"\",\n" +
" \"pageNo\": 1,\n" +
" \"pageSize\": 10\n" +
"}");
// 创建请求
Request request = new Request.Builder()
.url(url)
.addHeader("Cookie", cookie)
.addHeader("amap-token", aMapToken)
.post(body)
.build();
try {
// 发送请求并获取响应
Response response = client.newCall(request).execute();
if (response.isSuccessful() && response.body() != null) {
String responseBody = response.body().string();
System.out.println(responseBody);
// 解析JSON响应
BusBarResult apiResponse = JSONObject.parseObject(responseBody, BusBarResult.class);
List<BusBarResult.BusBar> records = apiResponse.getResult().getRecords();
if(CollUtil.isNotEmpty(records)){
records.forEach(x -> x.setPsrSubId(prsId));
}
return apiResponse.getResult().getRecords();
} else {
System.out.println("请求失败,响应码: " + response.code());
}
} catch (IOException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
}
public static LineDetail lineDetailSub(String prsId, String aMapToken) {
{
String url = "http://25.42.182.119:32010/EquipArchivesCBB/pgpcom-cmpt-equip-archives-server/equipment/archives/queryEquipmentArchives";
// 创建HTTP客户端
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(6000, TimeUnit.SECONDS)
.readTimeout(6000, TimeUnit.SECONDS)
.writeTimeout(6000, TimeUnit.SECONDS)
.build();
RequestBody body = RequestBody.create(MediaType.parse("application/json"), "{\n" +
" \"astId\": \"\",\n" +
" \"psrId\": \""+prsId+"\",\n" +
" \"psrType\": \"xl\",\n" +
" \"distribution\": \"1\"\n" +
" \n" +
"}");
// 创建请求
Request request = new Request.Builder()
.url(url)
.addHeader("cmpt-token", aMapToken)
.post(body)
.build();
try {
// 发送请求并获取响应
Response response = client.newCall(request).execute();
if (response.isSuccessful() && response.body() != null) {
String responseBody = response.body().string();
System.out.println(responseBody);
// 解析JSON响应
LineDetailResult apiResponse = JSONObject.parseObject(responseBody, LineDetailResult.class);
LineDetail lineDetail=new LineDetail();
LineDetailResult.ResultDTO result = apiResponse.getResult();
if(ObjUtil.isNotNull(result)){
//运行管理参数
List<LineDetailResult.ResultDTO.EquipArchivesGroupListDTO> equipArchivesGroupListDTOList = result.getEquipArchivesGroupList().stream()
.filter(x -> "1744555113406.84960".equals(x.getObjId()))
.collect(Collectors.toList());
if(CollUtil.isNotEmpty(equipArchivesGroupListDTOList)){
LineDetailResult.ResultDTO.EquipArchivesGroupListDTO equipArchivesGroupListDTO = equipArchivesGroupListDTOList.get(0);
//起终点参数
List<LineDetailResult.ResultDTO.EquipArchivesGroupListDTO.SubEquipArchivesGroupListDTO> subEquipArchivesGroupList = equipArchivesGroupListDTO.getSubEquipArchivesGroupList().stream()
.filter(x -> "8a868de396228fbe019622a59ea20155".equals(x.getObjId()))
.collect(Collectors.toList());
if(CollUtil.isNotEmpty(subEquipArchivesGroupList)){
lineDetail.setPsrId(prsId);
List<LineDetailResult.ResultDTO.EquipArchivesGroupListDTO.SubEquipArchivesGroupListDTO.EquipArchivesFieldListDTO> startSub = subEquipArchivesGroupList.get(0).getEquipArchivesFieldList().stream()
.filter(x -> "4e7a254cdb664239ac8134e6f8321929".equals(x.getObjId()))
.collect(Collectors.toList());
if(CollUtil.isNotEmpty(startSub)){
if(StrUtil.isNotBlank(startSub.get(0).getFieldValue())){
lineDetail.setPsrSubStartId(startSub.get(0).getFieldValue());
lineDetail.setPsrSubStartName(startSub.get(0).getFieldEscapeValue());
}
}
List<LineDetailResult.ResultDTO.EquipArchivesGroupListDTO.SubEquipArchivesGroupListDTO.EquipArchivesFieldListDTO> endSub = subEquipArchivesGroupList.get(0).getEquipArchivesFieldList().stream()
.filter(x -> "e507be02993446389f7dff237362126c".equals(x.getObjId()))
.collect(Collectors.toList());
if(CollUtil.isNotEmpty(endSub)){
if(StrUtil.isNotBlank(endSub.get(0).getFieldValue())){
lineDetail.setPsrSubEndId(endSub.get(0).getFieldValue());
lineDetail.setPsrSubEndName(endSub.get(0).getFieldEscapeValue());
}
}
}
}
}
return lineDetail;
} else {
System.out.println("请求失败,响应码: " + response.code());
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
}