diff --git a/src/main/java/com/njcn/jbsyncdata/JbSyncdataApplication.java b/src/main/java/com/njcn/jbsyncdata/JbSyncdataApplication.java index cedeac3..a477d1d 100644 --- a/src/main/java/com/njcn/jbsyncdata/JbSyncdataApplication.java +++ b/src/main/java/com/njcn/jbsyncdata/JbSyncdataApplication.java @@ -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) { diff --git a/src/main/java/com/njcn/jbsyncdata/mapper/BusBarMapper.java b/src/main/java/com/njcn/jbsyncdata/mapper/BusBarMapper.java new file mode 100644 index 0000000..52d34f9 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/mapper/BusBarMapper.java @@ -0,0 +1,16 @@ +package com.njcn.jbsyncdata.mapper; + +import com.github.jeffreyning.mybatisplus.base.MppBaseMapper; +import com.njcn.jbsyncdata.pojo.ywzt.BusBarResult; + +/** + *

+ * Mapper 接口 + *

+ * + * @author wr + * @since 2024-08-07 + */ +public interface BusBarMapper extends MppBaseMapper { + +} diff --git a/src/main/java/com/njcn/jbsyncdata/mapper/IncomeAndOutgoMapper.java b/src/main/java/com/njcn/jbsyncdata/mapper/IncomeAndOutgoMapper.java new file mode 100644 index 0000000..3722077 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/mapper/IncomeAndOutgoMapper.java @@ -0,0 +1,16 @@ +package com.njcn.jbsyncdata.mapper; + +import com.github.jeffreyning.mybatisplus.base.MppBaseMapper; +import com.njcn.jbsyncdata.pojo.ywzt.IncomeAndOutgoLinesResult; + +/** + *

+ * Mapper 接口 + *

+ * + * @author wr + * @since 2024-08-07 + */ +public interface IncomeAndOutgoMapper extends MppBaseMapper { + +} diff --git a/src/main/java/com/njcn/jbsyncdata/mapper/LineDetailMapper.java b/src/main/java/com/njcn/jbsyncdata/mapper/LineDetailMapper.java new file mode 100644 index 0000000..6c7c5a9 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/mapper/LineDetailMapper.java @@ -0,0 +1,16 @@ +package com.njcn.jbsyncdata.mapper; + +import com.github.jeffreyning.mybatisplus.base.MppBaseMapper; +import com.njcn.jbsyncdata.pojo.ywzt.LineDetail; + +/** + *

+ * Mapper 接口 + *

+ * + * @author wr + * @since 2024-08-07 + */ +public interface LineDetailMapper extends MppBaseMapper { + +} diff --git a/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/BusBarResult.java b/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/BusBarResult.java new file mode 100644 index 0000000..8a8842a --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/BusBarResult.java @@ -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 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; + } + + +} diff --git a/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/IncomeAndOutgoLinesResult.java b/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/IncomeAndOutgoLinesResult.java new file mode 100644 index 0000000..472b38f --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/IncomeAndOutgoLinesResult.java @@ -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 incomeList; + //出线 + private List 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; + + } + +} diff --git a/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/LineDetail.java b/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/LineDetail.java new file mode 100644 index 0000000..e651193 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/LineDetail.java @@ -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; + + + +} diff --git a/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/LineDetailResult.java b/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/LineDetailResult.java new file mode 100644 index 0000000..e461c53 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/pojo/ywzt/LineDetailResult.java @@ -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 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 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 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; + } + } + } + } +} diff --git a/src/main/java/com/njcn/jbsyncdata/service/YwZtBusBarService.java b/src/main/java/com/njcn/jbsyncdata/service/YwZtBusBarService.java new file mode 100644 index 0000000..4155d89 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/service/YwZtBusBarService.java @@ -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 { + + /** + * 获取业务中台变电站下所有母线 + * @param cookie + * @param aMapToken + * @return + */ + Boolean addYwZtBusBar(String cookie, String aMapToken); +} diff --git a/src/main/java/com/njcn/jbsyncdata/service/YwZtIncomeAndOutgoService.java b/src/main/java/com/njcn/jbsyncdata/service/YwZtIncomeAndOutgoService.java new file mode 100644 index 0000000..569a46c --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/service/YwZtIncomeAndOutgoService.java @@ -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 { + + /** + * 获得变电站中进线和出线 + * @param cookie + * @param aMapToken + * @return + */ + Boolean addYwZtIncomeAndOutgo(String cookie, String aMapToken) throws InterruptedException; +} diff --git a/src/main/java/com/njcn/jbsyncdata/service/YwZtLineDetailService.java b/src/main/java/com/njcn/jbsyncdata/service/YwZtLineDetailService.java new file mode 100644 index 0000000..3d18345 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/service/YwZtLineDetailService.java @@ -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 { + + /** + * 获取业务中台变电站下所有母线 + * @param aMapToken + * @return + */ + Boolean addYwZtLineDetail(String aMapToken); +} diff --git a/src/main/java/com/njcn/jbsyncdata/service/impl/PmsSubstationServiceImpl.java b/src/main/java/com/njcn/jbsyncdata/service/impl/PmsSubstationServiceImpl.java index 102838b..003fa4d 100644 --- a/src/main/java/com/njcn/jbsyncdata/service/impl/PmsSubstationServiceImpl.java +++ b/src/main/java/com/njcn/jbsyncdata/service/impl/PmsSubstationServiceImpl.java @@ -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,40 +69,61 @@ public class PmsSubstationServiceImpl extends ServiceImpl headers = new HashMap<>(); headers.put("x-token", tokenWithRestTemplate.getAccess_token()); - - ResponseEntity 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 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 records = zf01.getRecords(); List 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()); + substation.setOperationName(resource.getCityName()); + substation.setType(psrType); + substation.setName(resource.getName()); + substation.setScale(getAlgoDescribe(resource.getVoltageLevel(), devVoltage)); + substation.setScaleName(resource.getVoltageLevelName()); + substation.setMaintenanceName(resource.getMaintGroupName()); + substation.setRunStatus(resource.getPsrStateName()); + 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); + } - PmsSubstation substation = new PmsSubstation(); - substation.setId(record.getId()); - substation.setOrgId(resource.getCity()); - substation.setOperationName(resource.getCityName()); - substation.setType(psrType); - substation.setName(resource.getName()); - substation.setScale(getAlgoDescribe(resource.getVoltageLevel(), devVoltage)); - substation.setScaleName(resource.getVoltageLevelName()); - substation.setMaintenanceName(resource.getMaintGroupName()); - substation.setRunStatus(resource.getPsrStateName()); - substation.setRunTime(LocalDateTimeUtil.parse(resource.getCtime(), "yyyy-MM-dd HH:mm:ss")); - //经纬度 - String geoPositon = resource.getGeoPositon(); - 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); diff --git a/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtBusBarServiceImpl.java b/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtBusBarServiceImpl.java new file mode 100644 index 0000000..9514ff6 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtBusBarServiceImpl.java @@ -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 implements YwZtBusBarService { + + private final IPmsSubstationService pmsSubstationService; + private final DictDataMapper dictDataMapper; + + @Override + public Boolean addYwZtBusBar(String cookie, String aMapToken) { + List devVoltage = dictDataMapper.selectList("Dev_Voltage_Stand"); + List 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 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) { + if (StrUtil.isNotBlank(name)) { + List dictDataList = dictData.stream().filter(x -> name.contains(x.getName())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(dictDataList)) { + return dictDataList.get(0).getId(); + } + } + return null; + } +} diff --git a/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtIncomeAndOutgoServiceImpl.java b/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtIncomeAndOutgoServiceImpl.java new file mode 100644 index 0000000..e8e76e0 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtIncomeAndOutgoServiceImpl.java @@ -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 implements YwZtIncomeAndOutgoService { + + private final IPmsSubstationService pmsSubstationService; + private final DictDataMapper dictDataMapper; + @Override + public Boolean addYwZtIncomeAndOutgo(String cookie, String aMapToken) throws InterruptedException { + List devVoltage = dictDataMapper.selectList("Dev_Voltage_Stand"); + List list = pmsSubstationService.list().stream().collect(Collectors.toList()); + for (int i = 0; i < list.size(); i++) { + System.out.println("------------------"+i); + List list1 = this.list(new LambdaQueryWrapper() + .eq(IncomeAndOutgoLinesResult.PsrInfo::getPsrSubId, list.get(i).getId())); + if(CollUtil.isEmpty(list1)){ + List 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) { + if (StrUtil.isNotBlank(name)) { + List dictDataList = dictData.stream().filter(x -> x.getAlgoDescribe() == Integer.valueOf(name)).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(dictDataList)) { + return dictDataList.get(0).getId(); + } + } + return name; + } +} diff --git a/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtLineDetailServiceImpl.java b/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtLineDetailServiceImpl.java new file mode 100644 index 0000000..cfbc1e4 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/service/impl/YwZtLineDetailServiceImpl.java @@ -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 implements YwZtLineDetailService { + + private final YwZtIncomeAndOutgoServiceImpl incomeAndOutgoService; + + @Override + public Boolean addYwZtLineDetail( String aMapToken) { + List list = incomeAndOutgoService.list(new LambdaQueryWrapper() + .eq(IncomeAndOutgoLinesResult.PsrInfo::getPsrType,"xl")); + List collect = list.stream().map(IncomeAndOutgoLinesResult.PsrInfo::getPsrId).distinct().collect(Collectors.toList()); + List 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; + } + +} diff --git a/src/main/java/com/njcn/jbsyncdata/util/YwZtUtil.java b/src/main/java/com/njcn/jbsyncdata/util/YwZtUtil.java new file mode 100644 index 0000000..e4939bb --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/util/YwZtUtil.java @@ -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 inComeAndOutgo(String prsId, String cookie, String aMapToken) { + List 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 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 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 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 subEquipArchivesGroupList = equipArchivesGroupListDTO.getSubEquipArchivesGroupList().stream() + .filter(x -> "8a868de396228fbe019622a59ea20155".equals(x.getObjId())) + .collect(Collectors.toList()); + if(CollUtil.isNotEmpty(subEquipArchivesGroupList)){ + lineDetail.setPsrId(prsId); + List 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 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; + } + } +}