From e73aeabf463a43e78a6cb4f5f915d3c786761b29 Mon Sep 17 00:00:00 2001 From: wr <1754607820@qq.com> Date: Tue, 21 Nov 2023 19:00:07 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=8F=B0=E5=8C=BA=E5=8F=B0=E8=B4=A6=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=AF=BC=E5=85=A5=EF=BC=88=E5=94=90=E5=B1=B1/?= =?UTF-8?q?=E5=BC=A0=E5=AE=B6=E5=8F=A3=EF=BC=89=202.=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=8F=B0=E5=8C=BA=E9=81=A5=E6=B5=8B=E6=95=B0=E6=8D=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DisPhotovoltaicController.java | 80 +++++- .../jbsyncdata/mapper/DictDataMapper.java | 4 +- .../PmsPowerDistributionareaMapper.java | 16 ++ .../mapper/mapping/DictDataMapper.xml | 41 ++- .../PmsPowerDistributionareaMapper.xml | 5 + .../pojo/DistributionAreaExcel.java | 58 ++++ .../njcn/jbsyncdata/pojo/InfluxAreaData.java | 25 ++ .../pojo/ZhangDistributionAreaExcel.java | 113 ++++++++ .../pojo/po/PmsPowerDistributionarea.java | 220 +++++++++++++++ .../service/DisPhotovoltaicService.java | 26 ++ .../jbsyncdata/service/IBusinessService.java | 4 + .../IPmsPowerDistributionareaService.java | 16 ++ .../service/impl/BusinessServiceImpl.java | 50 ++++ .../impl/DisPhotovoltaicServiceImpl.java | 245 ++++++++++++++-- .../PmsPowerDistributionareaServiceImpl.java | 20 ++ .../jbsyncdata/util/AreaDataProcessing.java | 264 ++++++++++++++++++ 16 files changed, 1162 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/njcn/jbsyncdata/mapper/PmsPowerDistributionareaMapper.java create mode 100644 src/main/java/com/njcn/jbsyncdata/mapper/mapping/PmsPowerDistributionareaMapper.xml create mode 100644 src/main/java/com/njcn/jbsyncdata/pojo/DistributionAreaExcel.java create mode 100644 src/main/java/com/njcn/jbsyncdata/pojo/InfluxAreaData.java create mode 100644 src/main/java/com/njcn/jbsyncdata/pojo/ZhangDistributionAreaExcel.java create mode 100644 src/main/java/com/njcn/jbsyncdata/pojo/po/PmsPowerDistributionarea.java create mode 100644 src/main/java/com/njcn/jbsyncdata/service/IPmsPowerDistributionareaService.java create mode 100644 src/main/java/com/njcn/jbsyncdata/service/impl/PmsPowerDistributionareaServiceImpl.java create mode 100644 src/main/java/com/njcn/jbsyncdata/util/AreaDataProcessing.java diff --git a/src/main/java/com/njcn/jbsyncdata/controller/DisPhotovoltaicController.java b/src/main/java/com/njcn/jbsyncdata/controller/DisPhotovoltaicController.java index a778694..8d4fd04 100644 --- a/src/main/java/com/njcn/jbsyncdata/controller/DisPhotovoltaicController.java +++ b/src/main/java/com/njcn/jbsyncdata/controller/DisPhotovoltaicController.java @@ -7,6 +7,8 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.excel.EasyExcel; import com.njcn.jbsyncdata.pojo.DisPhotovoltaic10Excel; import com.njcn.jbsyncdata.pojo.DisPhotovoltaic380Excel; +import com.njcn.jbsyncdata.pojo.DistributionAreaExcel; +import com.njcn.jbsyncdata.pojo.ZhangDistributionAreaExcel; import com.njcn.jbsyncdata.service.DisPhotovoltaicService; import com.njcn.jbsyncdata.service.IBusinessService; import com.njcn.jbsyncdata.util.StreamUtil; @@ -76,6 +78,42 @@ public class DisPhotovoltaicController { } } + /** + * @param date yyyy-MM-dd + */ + @ApiOperation(value = "查询指定日期所有台区用户的遥测数据") + @PostMapping("/queryTelemetryAreaData") + public void queryTelemetryAreaData(String date) { + try { + businessService.queryTelemetryAreaData(date); + } catch (Exception exception) { + exception.printStackTrace(); + } + } + + + /** + * @param startTime 起始时间 yyyy-MM-dd + * @param endTime 截止时间 yyyy-MM-dd + */ + @ApiOperation(value = "查询日期范围内所有台区用户的遥测数据") + @PostMapping("/queryTelemetryAreaDataTimeRange") + public void queryTelemetryAreaDataTimeRange(String startTime, String endTime) { + try { + DateTime startDate = DateUtil.parse(startTime, DatePattern.NORM_DATE_FORMAT); + DateTime endDate = DateUtil.parse(endTime, DatePattern.NORM_DATE_FORMAT); + long betweenDay = DateUtil.betweenDay(startDate, endDate, true); + //第一天 + businessService.queryTelemetryAreaData(DateUtil.format(startDate, DatePattern.NORM_DATE_PATTERN)); + //后续递增1 + for (int i = 0; i < betweenDay; i++) { + startDate = DateUtil.offsetDay(startDate, 1); + businessService.queryTelemetryAreaData(DateUtil.format(startDate, DatePattern.NORM_DATE_PATTERN)); + } + } catch (Exception exception) { + exception.printStackTrace(); + } + } @ApiOperation(value = "导入10kv分布式光伏接入情况", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) @PostMapping("/import10KV") @@ -110,16 +148,54 @@ public class DisPhotovoltaicController { } + @ApiOperation(value = "导入唐山供电公司台区数据") + @PostMapping("/importArea") + public void importArea(MultipartFile file, HttpServletResponse response) throws Exception { + List list = EasyExcel.read(file.getInputStream()) + .head(DistributionAreaExcel.class) + .sheet(0).doReadSync(); + list = list.stream() + .filter(t -> !"#N/A".equals(t.getPmsID())) + .collect(Collectors.toList()); + disPhotovoltaicService.SavaArea(list,response); + + } + + @ApiOperation(value = "导入张家口供电公司台区数据") + @PostMapping("/importZhangArea") + public void importZhangArea(MultipartFile file, HttpServletResponse response) throws Exception { + List list = EasyExcel.read(file.getInputStream()) + .head(ZhangDistributionAreaExcel.class) + .doReadAllSync(); + list = list.stream() + .filter(t -> StrUtil.isNotBlank(t.getId())) + .filter(StreamUtil.distinctByKey(ZhangDistributionAreaExcel::getId)) + .filter(t -> !"#N/A".equals(t.getPmsID())) + .collect(Collectors.toList()); + disPhotovoltaicService.SavaZhangArea(list,response); + System.out.println(); + + } @ApiOperation(value = "将用户数据导入到配网表中") @PostMapping("/insertDistributionMonitor") - public String import380KV() throws Exception { + public String import380KV() { Boolean aBoolean = disPhotovoltaicService.savePmsDistributionMonitor(); if (aBoolean) { return "数据导入成功"; } return "数据导入失败"; } + + @ApiOperation(value = "将台区数据导入到配网表中") + @PostMapping("/insertDistributionArea") + public String importArea() { + Boolean aBoolean = disPhotovoltaicService.savePmsDistributionArea(); + if (aBoolean) { + return "数据导入成功"; + } + return "数据导入失败"; + } @Scheduled(cron = "0 30 8 * * ?") public void insert() { log.error(Thread.currentThread().getName(),"1.定时器启动----!"); @@ -128,6 +204,8 @@ public class DisPhotovoltaicController { String ds = s.substring(0, s.indexOf(" ")); log.error(Thread.currentThread().getName() + "2.定时器执行数据日期 "+ds+"----!"); businessService.queryTelemetryData(ds); + log.error(Thread.currentThread().getName() + "台区定时器执行数据日期 "+ds+"----!"); + businessService.queryTelemetryAreaData(ds); log.error(Thread.currentThread().getName() + "2.定时器执行数据成功 "+ds+"----!"); } diff --git a/src/main/java/com/njcn/jbsyncdata/mapper/DictDataMapper.java b/src/main/java/com/njcn/jbsyncdata/mapper/DictDataMapper.java index 0a9a6f4..5ab042f 100644 --- a/src/main/java/com/njcn/jbsyncdata/mapper/DictDataMapper.java +++ b/src/main/java/com/njcn/jbsyncdata/mapper/DictDataMapper.java @@ -20,7 +20,7 @@ public interface DictDataMapper extends BaseMapper { List selectList(@Param("code") String code); DictData selectByCode(@Param("dataCode") String dataCode,@Param("typeCode") String typeCode); List selectUserList(); - Boolean deletePmsDistributionMonitor(@Param("date") String date); + Boolean deletePmsDistributionMonitor(@Param("dic") String dic,@Param("type") String type); Boolean insertPmsDistributionMonitor(); - + Boolean insertPmsDistributionArea(@Param("dic") String dic); } diff --git a/src/main/java/com/njcn/jbsyncdata/mapper/PmsPowerDistributionareaMapper.java b/src/main/java/com/njcn/jbsyncdata/mapper/PmsPowerDistributionareaMapper.java new file mode 100644 index 0000000..171d66d --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/mapper/PmsPowerDistributionareaMapper.java @@ -0,0 +1,16 @@ +package com.njcn.jbsyncdata.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.jbsyncdata.pojo.po.PmsPowerDistributionarea; + +/** + *

+ * 台区信息 Mapper 接口 + *

+ * + * @author wr + * @since 2023-11-20 + */ +public interface PmsPowerDistributionareaMapper extends BaseMapper { + +} diff --git a/src/main/java/com/njcn/jbsyncdata/mapper/mapping/DictDataMapper.xml b/src/main/java/com/njcn/jbsyncdata/mapper/mapping/DictDataMapper.xml index d94f124..c4f7e00 100644 --- a/src/main/java/com/njcn/jbsyncdata/mapper/mapping/DictDataMapper.xml +++ b/src/main/java/com/njcn/jbsyncdata/mapper/mapping/DictDataMapper.xml @@ -36,11 +36,48 @@ pms_power_generation_user where Status=1 + + INSERT INTO pms_distribution_monitor ( + Monitor_Sort, + Monitor_Id, + Org_Id, + Voltage_Level, + If_Power_User, + Monitor_State, + Created_Date, + Status, + Create_Time, + Update_Time, + Line_Id, + Statistical_Interval, + Power_Station_Id + ) + select + #{dic} as Monitor_Sort, + id as Monitor_Id, + Org_Id as Org_Id , + Voltage_Level as Voltage_Level, + 1 as If_Power_User, + (select sd.id from sys_dict_data sd INNER JOIN sys_dict_type st on st.id=sd.Type_Id where sd.`Code`="Run" and st.`Code`="Line_State") as Monitor_State, + now() as Created_Date, + 1 as Status, + now() as Create_Time, + now() as Update_Time, + Line_Id as Statistical_Interval, + 15 as Statistical_Interval, + Power_Station_Id as Power_Station_Id + from + pms_power_distributionarea + where Status=1 + delete FROM pms_distribution_monitor - - DATE_FORMAT(Create_Time, '%Y-%m-%d') = DATE_FORMAT(#{date}, '%Y-%m-%d') + + and If_Power_User = #{type} + + + and Monitor_Sort = #{dic} diff --git a/src/main/java/com/njcn/jbsyncdata/mapper/mapping/PmsPowerDistributionareaMapper.xml b/src/main/java/com/njcn/jbsyncdata/mapper/mapping/PmsPowerDistributionareaMapper.xml new file mode 100644 index 0000000..254392a --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/mapper/mapping/PmsPowerDistributionareaMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/com/njcn/jbsyncdata/pojo/DistributionAreaExcel.java b/src/main/java/com/njcn/jbsyncdata/pojo/DistributionAreaExcel.java new file mode 100644 index 0000000..0a12bad --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/pojo/DistributionAreaExcel.java @@ -0,0 +1,58 @@ +package com.njcn.jbsyncdata.pojo; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 台区信息 + *

+ * + * @author wr + * @since 2023-11-20 + */ +@Data +@ColumnWidth(30) +public class DistributionAreaExcel implements Serializable { + + private static final long serialVersionUID = 1L; + + @ExcelProperty(value = "错误信息") + private String errorMessage; + + /** + * 台区编号 + */ + @ExcelProperty(value = "台区编号") + private String id; + + /** + * 变压器名称 + */ + @ExcelProperty("变压器名称") + private String name; + + /** + * PMS资源id(同源) + */ + @ExcelProperty("PMS资源id(同源)") + private String pmsID; + + /** + * 监测线路名称 + */ + @ExcelProperty("所属线路") + private String lineName; + + @ExcelProperty(value = "公司名称") + private String orgName; + + @ExcelProperty(value = "供电所") + private String powerSupply; + + +} diff --git a/src/main/java/com/njcn/jbsyncdata/pojo/InfluxAreaData.java b/src/main/java/com/njcn/jbsyncdata/pojo/InfluxAreaData.java new file mode 100644 index 0000000..27445d5 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/pojo/InfluxAreaData.java @@ -0,0 +1,25 @@ +package com.njcn.jbsyncdata.pojo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * + */ +@Data +public class InfluxAreaData implements Serializable { + + + /** + * 台区id + */ + private String id; + + /** + * influxData数据 + */ + private String influxData; + + +} diff --git a/src/main/java/com/njcn/jbsyncdata/pojo/ZhangDistributionAreaExcel.java b/src/main/java/com/njcn/jbsyncdata/pojo/ZhangDistributionAreaExcel.java new file mode 100644 index 0000000..6f6a263 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/pojo/ZhangDistributionAreaExcel.java @@ -0,0 +1,113 @@ +package com.njcn.jbsyncdata.pojo; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 台区信息 + *

+ * + * @author wr + * @since 2023-11-20 + */ +@Data +@ColumnWidth(30) +public class ZhangDistributionAreaExcel implements Serializable { + + private static final long serialVersionUID = 1L; + + + @ExcelProperty("台区编号") + private String id; + + @ExcelProperty("台区(变压器)名称") + private String name; + + + @ExcelProperty("组织机构名称") + private String orgName; + + + @ExcelProperty("组织机构id") + private String orgId; + + + @ExcelProperty("运维单位名称") + private String operationName; + + + @ExcelProperty("运维单位id") + private String operationId; + + + @ExcelProperty("变电站名称") + private String powerrName; + + + @ExcelProperty("变电站id") + private String powerStationId; + + + @ExcelProperty("监测线路名称") + private String lineName; + + + @ExcelProperty("所属线路ID") + private String lineId; + + + @ExcelProperty("电压等级") + private String voltageLevel; + + + @ExcelProperty("PMS中资源ID") + private String pmsID; + + + @ExcelProperty("配变容量") + private String pCapacity; + + + @ExcelProperty("地区特征") + private String regionalism; + + @ExcelProperty("是否农网") + private String ifRuralPowerGrid; + + @ExcelProperty("使用性质") + private String natureOfUse; + + + @ExcelProperty("供电半径") + private Float powerSupplyRadius; + + + @ExcelProperty("供电线路总长度") + private Float lineLength; + + + @ExcelProperty("运行状态") + private String state; + + + @ExcelProperty("分布式光伏用户数") + private Integer distributedPhotovoltaicNum; + + + @ExcelProperty("装机容量") + private Float photovoltaicCapacity; + + + @ExcelProperty("是否有电动汽车接入") + private String ifBevAp; + + + @ExcelProperty("接入负荷类型") + private String apLoadType; + + +} diff --git a/src/main/java/com/njcn/jbsyncdata/pojo/po/PmsPowerDistributionarea.java b/src/main/java/com/njcn/jbsyncdata/pojo/po/PmsPowerDistributionarea.java new file mode 100644 index 0000000..4456e25 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/pojo/po/PmsPowerDistributionarea.java @@ -0,0 +1,220 @@ +package com.njcn.jbsyncdata.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.Setter; + +/** + *

+ * 台区信息 + *

+ * + * @author wr + * @since 2023-11-20 + */ +@Getter +@Setter +@TableName("pms_power_distributionarea") +public class PmsPowerDistributionarea { + + private static final long serialVersionUID = 1L; + + /** + * 台区编号 + */ + @TableId("Id") + private String id; + + /** + * 台区名称 + */ + @TableField("Name") + private String name; + + /** + * 组织机构名称 + */ + @TableField("Org_Name") + private String orgName; + + /** + * 组织机构ID(外键) + */ + @TableField("Org_Id") + private String orgId; + + /** + * 运维单位名称 + */ + @TableField("Operation_Name") + private String operationName; + + /** + * 运维单位ID(外键) + */ + @TableField("Operation_Id") + private String operationId; + + /** + * 变电站名称 + */ + @TableField("Powerr_Name") + private String powerrName; + + /** + * 电站ID(外键) + */ + @TableField("Power_Station_Id") + private String powerStationId; + + /** + * 监测线路名称 + */ + @TableField("Line_Name") + private String lineName; + + /** + * 所属线路ID(外键) + */ + @TableField("Line_Id") + private String lineId; + + /** + * 电压等级 + */ + @TableField("Voltage_Level") + private String voltageLevel; + + /** + * 配变容量 + */ + @TableField("P_Capacity") + private Float pCapacity; + + /** + * 地区特征(字典) + */ + @TableField("Regionalism") + private String regionalism; + + /** + * 设备地区特征 + */ + @TableField("Dev_Regionalism") + private String devRegionalism; + + /** + * 是否农网:0-否;1:是; + */ + @TableField("If_Rural_Power_Grid") + private Boolean ifRuralPowerGrid; + + /** + * 使用性质 + */ + @TableField("Nature_Of_Use") + private String natureOfUse; + + /** + * 供电半径 + */ + @TableField("Power_Supply_Radius") + private Float powerSupplyRadius; + + /** + * 供电线路总长度 + */ + @TableField("Line_Length") + private Float lineLength; + + /** + * 运行状态(字典) + */ + @TableField("State") + private String state; + + /** + * 分布式光伏用户数 + */ + @TableField("Distributed_Photovoltaic_Num") + private Integer distributedPhotovoltaicNum; + + /** + * 分布式光伏总装机容量 + */ + @TableField("Photovoltaic_Capacity") + private Float photovoltaicCapacity; + + /** + * 是否有电动汽车接入:0-否;1:是; + */ + @TableField("If_Bev_Ap") + private Boolean ifBevAp; + + /** + * 接入负荷类型(字典) + */ + @TableField("Ap_Load_Type") + private String apLoadType; + + /** + * 经度 + */ + @TableField("Longitude") + private Double longitude; + + /** + * 维度 + */ + @TableField("Latitude") + private Double latitude; + + /** + * 是否是上送国网监测点,0-否 1-是 + */ + @TableField("Is_Up_To_Grid") + private Boolean isUpToGrid; + + /** + * 数据状态:0-删除;1-正常; + */ + @TableField("Status") + private Boolean status; + + /** + * 数据状态:0-手动录入;1-gw台账录入 + */ + @TableField("input_Status") + private Integer inputStatus; + + /** + * 创建用户 + */ + @TableField("Create_By") + private String createBy; + + /** + * 创建时间 + */ + @TableField("Create_Time") + private LocalDateTime createTime; + + /** + * 更新用户 + */ + @TableField("Update_By") + private String updateBy; + + @TableField("Pms_Id") + private String pmsID; + /** + * 更新时间 + */ + @TableField("Update_Time") + private LocalDateTime updateTime; + + +} diff --git a/src/main/java/com/njcn/jbsyncdata/service/DisPhotovoltaicService.java b/src/main/java/com/njcn/jbsyncdata/service/DisPhotovoltaicService.java index 9965495..0420496 100644 --- a/src/main/java/com/njcn/jbsyncdata/service/DisPhotovoltaicService.java +++ b/src/main/java/com/njcn/jbsyncdata/service/DisPhotovoltaicService.java @@ -2,6 +2,8 @@ package com.njcn.jbsyncdata.service; import com.njcn.jbsyncdata.pojo.DisPhotovoltaic10Excel; import com.njcn.jbsyncdata.pojo.DisPhotovoltaic380Excel; +import com.njcn.jbsyncdata.pojo.DistributionAreaExcel; +import com.njcn.jbsyncdata.pojo.ZhangDistributionAreaExcel; import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -31,6 +33,21 @@ public interface DisPhotovoltaicService { */ void SavaPmsPowerGenerationUser380KV(List list, HttpServletResponse response); + /** + * 唐山模板导入 + * @param list + * @param response + */ + void SavaArea(List list, HttpServletResponse response); + + + /** + * 张家口模板导入 + * @param list + * @param response + */ + void SavaZhangArea(List list, HttpServletResponse response); + /** * @Description: 配网表数据新增 * @param @@ -39,4 +56,13 @@ public interface DisPhotovoltaicService { * @Date: 2023/10/11 14:31 */ Boolean savePmsDistributionMonitor(); + + /** + * @Description: 配网表数据新增 + * @param + * @return: java.lang.Boolean + * @Author: wr + * @Date: 2023/10/11 14:31 + */ + Boolean savePmsDistributionArea(); } diff --git a/src/main/java/com/njcn/jbsyncdata/service/IBusinessService.java b/src/main/java/com/njcn/jbsyncdata/service/IBusinessService.java index b8d6fd7..7454c75 100644 --- a/src/main/java/com/njcn/jbsyncdata/service/IBusinessService.java +++ b/src/main/java/com/njcn/jbsyncdata/service/IBusinessService.java @@ -5,4 +5,8 @@ public interface IBusinessService { void queryTelemetryData(String date); + + void queryTelemetryAreaData(String date); + + } diff --git a/src/main/java/com/njcn/jbsyncdata/service/IPmsPowerDistributionareaService.java b/src/main/java/com/njcn/jbsyncdata/service/IPmsPowerDistributionareaService.java new file mode 100644 index 0000000..dd51943 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/service/IPmsPowerDistributionareaService.java @@ -0,0 +1,16 @@ +package com.njcn.jbsyncdata.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.jbsyncdata.pojo.po.PmsPowerDistributionarea; + +/** + *

+ * 台区信息 服务类 + *

+ * + * @author wr + * @since 2023-11-20 + */ +public interface IPmsPowerDistributionareaService extends IService { + +} diff --git a/src/main/java/com/njcn/jbsyncdata/service/impl/BusinessServiceImpl.java b/src/main/java/com/njcn/jbsyncdata/service/impl/BusinessServiceImpl.java index 693930f..9e4ef74 100644 --- a/src/main/java/com/njcn/jbsyncdata/service/impl/BusinessServiceImpl.java +++ b/src/main/java/com/njcn/jbsyncdata/service/impl/BusinessServiceImpl.java @@ -5,11 +5,15 @@ import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.njcn.jbsyncdata.component.TokenComponent; import com.njcn.jbsyncdata.enums.MeasTypeEnum; +import com.njcn.jbsyncdata.pojo.po.PmsPowerDistributionarea; import com.njcn.jbsyncdata.pojo.result.*; import com.njcn.jbsyncdata.service.IBusinessService; +import com.njcn.jbsyncdata.service.IPmsPowerDistributionareaService; import com.njcn.jbsyncdata.service.IPmsPowerGenerationUserService; +import com.njcn.jbsyncdata.util.AreaDataProcessing; import com.njcn.jbsyncdata.util.DataProcessing; import com.njcn.jbsyncdata.util.RestTemplateUtil; import lombok.extern.slf4j.Slf4j; @@ -19,6 +23,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; +import java.util.stream.Collectors; @Slf4j @Service @@ -31,8 +36,13 @@ public class BusinessServiceImpl implements IBusinessService { @Resource private DataProcessing dataProcessing; + @Resource + private AreaDataProcessing areaDataProcessing; + @Resource private IPmsPowerGenerationUserService pmsPowerGenerationUserService; + @Resource + private IPmsPowerDistributionareaService powerDistributionareaService; /** * 此方法通过发电客户编号查询数据,该方法存在以下问题 @@ -86,5 +96,45 @@ public class BusinessServiceImpl implements IBusinessService { } } + @Override + public void queryTelemetryAreaData(String date) { + DateTime dateTemp = DateUtil.parse(date, DatePattern.NORM_DATE_FORMAT); + DateTime beginOfDay = DateUtil.beginOfDay(dateTemp); + DateTime endOfDay = DateUtil.endOfDay(dateTemp); + RestTemplateUtil restTemplateUtil = new RestTemplateUtil(); + TokenResult tokenWithRestTemplate = tokenComponent.getTokenWithRestTemplate(); + if (null == tokenWithRestTemplate) { + log.error("token信息获取失败"); + return; + } + List typeList = MeasTypeEnum.getMeasList(); + JSONObject jsonObject = JSONUtil.createObj(); + JSONObject jsonObjectSub = JSONUtil.createObj(); + jsonObject.set("page", 1); + jsonObject.set("perPage", 10000); + jsonObject.set("startTime", DateUtil.format(beginOfDay, DatePattern.NORM_DATETIME_FORMATTER)); + jsonObject.set("endTime", DateUtil.format(endOfDay, DatePattern.NORM_DATETIME_FORMATTER)); + //1公专变2低压用户3光伏 + jsonObjectSub.set("consNos", new ArrayList<>()); + jsonObjectSub.set("consType", ""); + jsonObjectSub.set("astIds", new ArrayList<>()); + jsonObjectSub.set("astType", ""); + jsonObjectSub.set("psrType", "0401004"); + jsonObjectSub.set("measPointIds", new ArrayList<>()); + jsonObjectSub.set("telemetryTypes", typeList); + //组装好json开始发送请求 + Map headers = new HashMap<>(); + headers.put("x-token", tokenWithRestTemplate.getAccess_token()); + //获取所有发电用户的id + List list = powerDistributionareaService.list(new LambdaQueryWrapper() + .select(PmsPowerDistributionarea::getId, PmsPowerDistributionarea::getPmsID) + .isNotNull(PmsPowerDistributionarea::getPmsID) + ); + List> singleQueryDataUserId = ListUtils.partition(list, 20000); + for (int k = 0; k < singleQueryDataUserId.size(); k++) { + areaDataProcessing.asyncInfluxDb(tokenComponent,date, restTemplateUtil, typeList, jsonObject, jsonObjectSub, headers, singleQueryDataUserId, k); + } + } + } diff --git a/src/main/java/com/njcn/jbsyncdata/service/impl/DisPhotovoltaicServiceImpl.java b/src/main/java/com/njcn/jbsyncdata/service/impl/DisPhotovoltaicServiceImpl.java index cb44d66..4729ba6 100644 --- a/src/main/java/com/njcn/jbsyncdata/service/impl/DisPhotovoltaicServiceImpl.java +++ b/src/main/java/com/njcn/jbsyncdata/service/impl/DisPhotovoltaicServiceImpl.java @@ -4,21 +4,19 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.njcn.jbsyncdata.mapper.DictDataMapper; import com.njcn.jbsyncdata.pojo.*; +import com.njcn.jbsyncdata.pojo.po.PmsPowerDistributionarea; import com.njcn.jbsyncdata.service.DisPhotovoltaicService; +import com.njcn.jbsyncdata.service.IPmsPowerDistributionareaService; import com.njcn.jbsyncdata.service.IPmsPowerGenerationUserService; import com.njcn.jbsyncdata.service.IPmsStatationStatService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; +import com.njcn.jbsyncdata.util.StreamUtil; import java.io.IOException; import java.net.URLEncoder; import java.time.LocalDateTime; @@ -26,6 +24,13 @@ import java.time.ZoneId; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + /** * @author wr @@ -40,6 +45,7 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { private final IPmsPowerGenerationUserService iPmsPowerGenerationUserService; private final DictDataMapper dictDataMapper; private final IPmsStatationStatService iPmsStatationStatService; + private final IPmsPowerDistributionareaService powerDistributionareaService; @Override public void SavaPmsPowerGenerationUser10KV(List list, HttpServletResponse response) { @@ -103,7 +109,7 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { user.setPowerGenerationMode(powerGenerationMode.getId()); //todo 电压等级(需要转换) - user.setVoltageLevel(getVoltage(excel.getVoltage_Level(), dev_voltage)); + user.setVoltageLevel(getVoltage(excel.getVoltage_Level().replace("交流",""), dev_voltage)); user.setSourceCapacity(excel.getContractCapacity()); @@ -129,10 +135,10 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { info.add(user); } if (CollUtil.isNotEmpty(info)) { -// LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); -// lambdaQueryWrapper.eq(PmsPowerGenerationUser::getInputStatus, 0); -// iPmsPowerGenerationUserService.remove(lambdaQueryWrapper); -// iPmsPowerGenerationUserService.saveOrUpdateBatch(info, 1000); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(PmsPowerGenerationUser::getInputStatus, 0); + iPmsPowerGenerationUserService.remove(lambdaQueryWrapper); + iPmsPowerGenerationUserService.saveOrUpdateBatch(info, 1000); } if (CollUtil.isNotEmpty(errorInfo)) { exportExcel(DateUtil.now() + "_10kV错误信息.xlsx", errorInfo,DisPhotovoltaic10Excel.class, response); @@ -229,10 +235,10 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { info.add(user); } if (CollUtil.isNotEmpty(info)) { -// LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); -// lambdaQueryWrapper.eq(PmsPowerGenerationUser::getInputStatus, 1); -// iPmsPowerGenerationUserService.remove(lambdaQueryWrapper); -// iPmsPowerGenerationUserService.saveBatch(info, 1000); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(PmsPowerGenerationUser::getInputStatus, 1); + iPmsPowerGenerationUserService.remove(lambdaQueryWrapper); + iPmsPowerGenerationUserService.saveBatch(info, 1000); } if (CollUtil.isNotEmpty(errorInfo)) { exportExcel(DateUtil.now() + "_380kV错误信息.xlsx", errorInfo,DisPhotovoltaic380Excel.class, response); @@ -240,14 +246,213 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { } @Override + @Transactional(rollbackFor = Exception.class) + public void SavaArea(List list, HttpServletResponse response) { + List info=new ArrayList<>(); + //电压等级 + DictData dictData = dictDataMapper.selectByCode("10kV", "Dev_Voltage"); + //运行状态 + DictData runData = dictDataMapper.selectByCode("Run", "Line_State"); + + List depts = dictDataMapper.selectUserList(); + //获取变电站信息 + List oldList = iPmsStatationStatService.list( + new LambdaQueryWrapper() + .eq(PmsStatationStat::getStatus, 1) + ); + Integer num=0; + PmsPowerDistributionarea area; + for (DistributionAreaExcel excel : list) { + area=new PmsPowerDistributionarea(); + if(StrUtil.isNotBlank(excel.getId())){ + area.setId(excel.getId().equals("新上")?excel.getId()+excel.getPmsID().substring(0,30):excel.getId()); + }else{ + area.setId(excel.getPmsID().substring(0,32)); + } + area.setName(excel.getName()); + List dept = depts.stream().filter(x -> x.getName().contains(excel.getOrgName())).collect(Collectors.toList()); + if(CollUtil.isNotEmpty(dept)){ + area.setOrgName(dept.get(0).getName()); + area.setOrgId(dept.get(0).getCode()); + area.setOperationName(dept.get(0).getName()); + area.setOperationId(dept.get(0).getCode()); + } + if(StrUtil.isNotEmpty(excel.getPowerSupply())){ + List station = oldList.stream() + .filter(x ->x.getPowerName().contains(excel.getPowerSupply())) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(station)){ + area.setPowerrName(station.get(0).getPowerName()); + area.setPowerStationId(station.get(0).getPowerId()); + area.setVoltageLevel(station.get(0).getVoltageLevel()); + }else { + area.setPowerrName(excel.getPowerSupply()); + area.setPowerStationId(IdUtil.simpleUUID()); + area.setVoltageLevel(dictData.getId()); + } + }else{ + area.setPowerrName(""); + area.setPowerStationId(""); + area.setVoltageLevel(dictData.getId()); + } + area.setLineName(StrUtil.isBlank(excel.getLineName())?"":excel.getLineName()); + area.setLineId(IdUtil.simpleUUID()); + area.setPCapacity(100.0F); + area.setRegionalism(""); + area.setDevRegionalism(""); + area.setIfRuralPowerGrid(false); + area.setNatureOfUse(""); + area.setPowerSupplyRadius(100.0F); + area.setLineLength(100.0F); + area.setState(runData.getId()); + area.setDistributedPhotovoltaicNum(10); + area.setPhotovoltaicCapacity(100.0F); + area.setIfBevAp(false); + area.setApLoadType("分布式光伏"); + area.setLongitude(0.0D); + area.setLatitude(0.0D); + area.setIsUpToGrid(false); + area.setStatus(true); + area.setInputStatus(1); + area.setCreateBy(""); + area.setCreateTime(LocalDateTime.now()); + area.setUpdateBy(""); + area.setUpdateTime(LocalDateTime.now()); + area.setPmsID(excel.getPmsID()); + info.add(area); + } + if (CollUtil.isNotEmpty(info)) { + info= info.stream() + .filter(StreamUtil.distinctByKey(PmsPowerDistributionarea::getId)) + .collect(Collectors.toList()); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(PmsPowerDistributionarea::getInputStatus, 1); + powerDistributionareaService.remove(lambdaQueryWrapper); + powerDistributionareaService.saveBatch(info, 1000); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void SavaZhangArea(List list, HttpServletResponse response) { + List info=new ArrayList<>(); + //电压等级 + List dictData = dictDataMapper.selectList("Dev_Voltage"); + DictData data10KV = dictDataMapper.selectByCode("10kV", "Dev_Voltage"); + //运行状态 + DictData runData = dictDataMapper.selectByCode("Run", "Line_State"); + //获取部门信息 + List depts = dictDataMapper.selectUserList(); + + Integer num=0; + PmsPowerDistributionarea area; + for (ZhangDistributionAreaExcel excel : list) { + area=new PmsPowerDistributionarea(); + if("#N/A".equals(excel.getId())){ + area.setId(excel.getPmsID().substring(0,30)); + }else{ + area.setId(excel.getId()); + } + area.setName(excel.getName()); + + + List deptList = depts.stream().filter(x -> x.getCode().contains(excel.getOrgId())).collect(Collectors.toList()); + if(CollUtil.isEmpty(deptList)){ + String org = subString(excel.getOrgName().replace("国网","")); + List deptName = depts.stream().filter(x -> x.getName().contains(org)).collect(Collectors.toList()); + if(CollUtil.isNotEmpty(deptName)){ + area.setOrgName(deptName.get(0).getName()); + area.setOrgId(deptName.get(0).getCode()); + } + }else{ + area.setOrgName(deptList.get(0).getName()); + area.setOrgId(deptList.get(0).getCode()); + } + if(StrUtil.isNotBlank(excel.getOperationId())){ + area.setOperationName(excel.getOperationName()); + area.setOperationId(excel.getOperationId()); + }else{ + area.setOperationName(""); + area.setOperationId(""); + } + area.setPowerrName(excel.getPowerrName()); + area.setPowerStationId(excel.getPowerStationId()); + if(StrUtil.isNotBlank(excel.getLineId())){ + area.setLineName(excel.getLineName()); + area.setLineId(excel.getLineId()); + }else{ + area.setLineName(""); + area.setLineId(""); + } + if(StrUtil.isNotBlank(excel.getVoltageLevel())){ + int i = excel.getVoltageLevel().indexOf("("); + if(i !=-1){ + area.setVoltageLevel(get380Voltage(excel.getVoltageLevel().substring(0,i), dictData)); + }else{ + area.setVoltageLevel(data10KV.getId()); + } + }else{ + area.setVoltageLevel(data10KV.getId()); + } + if(StrUtil.isNotBlank(excel.getPCapacity())&&!"#N/A".equals(excel.getPCapacity())){ + String substring = excel.getPCapacity().substring(excel.getPCapacity().lastIndexOf("-")+1, excel.getPCapacity().indexOf("/") ); + area.setPCapacity(Float.valueOf(substring)); + }else{ + area.setPCapacity(0.0f); + } + area.setRegionalism(""); + area.setDevRegionalism(""); + area.setIfRuralPowerGrid(false); + area.setNatureOfUse(""); + area.setPowerSupplyRadius(ObjectUtil.isNull(excel.getPowerSupplyRadius())?100.0f:excel.getPowerSupplyRadius()); + area.setLineLength(ObjectUtil.isNull(excel.getLineLength())?100.0f:excel.getLineLength()); + area.setState(runData.getId()); + area.setDistributedPhotovoltaicNum(ObjectUtil.isNull(excel.getDistributedPhotovoltaicNum())?10:excel.getDistributedPhotovoltaicNum()); + area.setPhotovoltaicCapacity(ObjectUtil.isNull(excel.getPhotovoltaicCapacity())?100.0f:excel.getPhotovoltaicCapacity()); + area.setIfBevAp(false); + area.setApLoadType("分布式光伏"); + area.setLongitude(0.0D); + area.setLatitude(0.0D); + area.setIsUpToGrid(false); + area.setStatus(true); + area.setInputStatus(2); + area.setCreateBy(""); + area.setCreateTime(LocalDateTime.now()); + area.setUpdateBy(""); + area.setPmsID(excel.getPmsID()); + area.setUpdateTime(LocalDateTime.now()); + info.add(area); + } + if (CollUtil.isNotEmpty(info)) { + info= info.stream() + .filter(StreamUtil.distinctByKey(PmsPowerDistributionarea::getId)) + .collect(Collectors.toList()); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(PmsPowerDistributionarea::getInputStatus, 2); + powerDistributionareaService.remove(lambdaQueryWrapper); + powerDistributionareaService.saveBatch(info, 1000); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) public Boolean savePmsDistributionMonitor() { - Boolean aBoolean = dictDataMapper.deletePmsDistributionMonitor(null); + DictData dictData = dictDataMapper.selectByCode("Three_Line", "Line_Sort"); + Boolean aBoolean = dictDataMapper.deletePmsDistributionMonitor(dictData.getId(),"1"); if(aBoolean){ return dictDataMapper.insertPmsDistributionMonitor(); } return false; } + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean savePmsDistributionArea() { + DictData dictData = dictDataMapper.selectByCode("Two_Line", "Line_Sort"); + dictDataMapper.deletePmsDistributionMonitor(dictData.getId(),null); + return dictDataMapper.insertPmsDistributionArea(dictData.getId()); + } + public String getAlgoDescribe(String name, List dictData) { List dictDataList = dictData.stream().filter(x -> x.getName().indexOf(name) != -1).collect(Collectors.toList()); if (CollUtil.isNotEmpty(dictDataList)) { @@ -317,7 +522,7 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { stat.setOrgId(dept.getCode()); stat.setOrgName(dept.getName()); stat.setShouldBeNum(100); - stat.setVoltageLevel(getVoltage(value.getVoltage_Level(), dev_voltage)); + stat.setVoltageLevel(getVoltage(value.getVoltage_Level().replace("交流",""), dev_voltage)); stat.setStatus(1); stat.setCreateTime(LocalDateTime.now()); stat.setUpdateTime(LocalDateTime.now()); @@ -326,7 +531,7 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { } }); if (CollUtil.isNotEmpty(info)) { - iPmsStatationStatService.saveBatch(info, 1000); + iPmsStatationStatService.saveOrUpdateBatch(info, 1000); } } @@ -361,7 +566,7 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { stat.setOrgId(dept.getCode()); stat.setOrgName(dept.getName()); stat.setShouldBeNum(100); - stat.setVoltageLevel(getVoltage(value.getVoltage_Level(), dev_voltage)); + stat.setVoltageLevel(get380Voltage(value.getVoltage_Level(), dev_voltage)); stat.setStatus(1); stat.setCreateTime(LocalDateTime.now()); stat.setUpdateTime(LocalDateTime.now()); @@ -370,7 +575,7 @@ public class DisPhotovoltaicServiceImpl implements DisPhotovoltaicService { } }); if (CollUtil.isNotEmpty(info)) { - iPmsStatationStatService.saveBatch(info, 1000); + iPmsStatationStatService.saveOrUpdateBatch(info, 1000); } } diff --git a/src/main/java/com/njcn/jbsyncdata/service/impl/PmsPowerDistributionareaServiceImpl.java b/src/main/java/com/njcn/jbsyncdata/service/impl/PmsPowerDistributionareaServiceImpl.java new file mode 100644 index 0000000..e8d3661 --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/service/impl/PmsPowerDistributionareaServiceImpl.java @@ -0,0 +1,20 @@ +package com.njcn.jbsyncdata.service.impl; + +import com.njcn.jbsyncdata.mapper.PmsPowerDistributionareaMapper; +import com.njcn.jbsyncdata.pojo.po.PmsPowerDistributionarea; +import com.njcn.jbsyncdata.service.IPmsPowerDistributionareaService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 台区信息 服务实现类 + *

+ * + * @author wr + * @since 2023-11-20 + */ +@Service +public class PmsPowerDistributionareaServiceImpl extends ServiceImpl implements IPmsPowerDistributionareaService { + +} diff --git a/src/main/java/com/njcn/jbsyncdata/util/AreaDataProcessing.java b/src/main/java/com/njcn/jbsyncdata/util/AreaDataProcessing.java new file mode 100644 index 0000000..eceee3f --- /dev/null +++ b/src/main/java/com/njcn/jbsyncdata/util/AreaDataProcessing.java @@ -0,0 +1,264 @@ +package com.njcn.jbsyncdata.util; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.file.FileReader; +import cn.hutool.core.io.file.FileWriter; +import cn.hutool.core.text.StrPool; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.njcn.influx.utils.InfluxDbUtils; +import com.njcn.jbsyncdata.component.TokenComponent; +import com.njcn.jbsyncdata.enums.MeasTypeEnum; +import com.njcn.jbsyncdata.pojo.InfluxAreaData; +import com.njcn.jbsyncdata.pojo.po.PmsPowerDistributionarea; +import com.njcn.jbsyncdata.pojo.result.TokenResult; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.StringUtils; +import org.influxdb.InfluxDB; +import org.influxdb.dto.BatchPoints; +import org.influxdb.dto.Point; +import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * @author wr + * @description + * @date 2023/10/20 14:14 + */ +@Component +@RequiredArgsConstructor +@Slf4j +public class AreaDataProcessing { + + private final InfluxDbUtils influxDbUtils; + + @Async("asyncExecutor") + public void asyncInfluxDb( + TokenComponent tokenComponent, + String date, + RestTemplateUtil restTemplateUtil, + List typeList, + JSONObject jsonObject, + JSONObject jsonObjectSub, + Map headers, + List> singleQueryDataUserId, int k + ) { + TokenResult tokenWithRestTemplate; + //将发电用户编号按100尺寸分片 + List> partitionList = ListUtils.partition(singleQueryDataUserId.get(k), 100); + log.error("总计分了{}片", partitionList.size()); + int count = 0; + tokenWithRestTemplate = tokenComponent.getTokenWithRestTemplate(); + headers.put("x-token", tokenWithRestTemplate.getAccess_token()); + //先获取数据 + List> responseEntities = new ArrayList<>(2000); + int kk = k + 1; + for (List generationAreaIDList : partitionList) { + count++; + log.error("查询第{}大片,{}小片数据", kk, count); + //按批次处理用户编号数据 + List psrIds = generationAreaIDList.stream().map(PmsPowerDistributionarea::getPmsID).collect(Collectors.toList()); + jsonObjectSub.set("psrIds", psrIds); + JSONArray jsonArray = JSONUtil.createArray(); + jsonArray.add(jsonObjectSub); + jsonObject.set("filters", jsonArray); + try { + responseEntities.add(restTemplateUtil.post(tokenComponent.getUrl().concat("/realMeasCenter/telemetry/commonQuery"), headers, jsonObject, String.class)); + } catch (Exception exception) { + log.error("远程调用接口异常,异常为:" + exception); + } + } + //开始解析数据 + Set userIdConcatMeasType = new HashSet<>(); + //将指标+客户编号组合起来匹配返回数据的第一条记录:userId@measType + for (String measType : typeList) { + userIdConcatMeasType.addAll(singleQueryDataUserId.get(k).stream().map(x->x.getPmsID().concat(StrPool.AT).concat(measType)).collect(Collectors.toSet())); + } + List influxData; + Map> typeData = new HashMap<>(); + StringBuilder tempInfluxData; + ResponseEntity response; + JSONArray statisticsDataList; + JSONObject result; + JSONObject statisticsData; + JSONObject body; + JSONArray records; + String dataIdentify; + JSONObject commonTelemetry; + MeasTypeEnum measTypeEnumByMeasType; + + //获取资源id和台区的对应关系 + Map> areaMap = singleQueryDataUserId.get(k).stream().collect(Collectors.groupingBy(PmsPowerDistributionarea::getPmsID, Collectors.mapping(PmsPowerDistributionarea::getId, Collectors.toList()))); + + for (int i = 0; i < partitionList.size(); i++) { + log.error("解析第{}片数据", i); + response = responseEntities.get(i); + body = JSONUtil.parseObj(response.getBody()); + +// String path = "C:\\Users\\web2023\\Desktop\\分布式光伏台区API调用结果\\2.txt"; +// FileReader fileReader = new FileReader(path); +// String jsonStr = fileReader.readString(); +// body = JSONUtil.parseObj(jsonStr); + if (response.getStatusCodeValue() == 200 && body.get("status", String.class).equalsIgnoreCase("000000")) { + result = JSONUtil.parseObj(body.get("result", String.class)); + records = JSONUtil.parseArray(result.get("records", String.class)); + log.error("查询遥测数据结束,返回数据量:{}", records.size()); + if (CollectionUtil.isEmpty(records)) { + //日志输出: + log.error("查询时间:{},无遥测数据;", date); + continue; + } + //处理各个record的数据,因用户下可能有多个测量点,按指标循环,默认采用第一个匹配上的做数据处理 + for (Object obj : records) { // 最多循环100*16次 + commonTelemetry = JSONUtil.parseObj(obj); + dataIdentify = commonTelemetry.get("psrId", String.class).concat(StrPool.AT).concat(commonTelemetry.get("measTypeCode", String.class)); + if (userIdConcatMeasType.contains(dataIdentify)) { + //首个包含该标识的数据进行处理 + measTypeEnumByMeasType = MeasTypeEnum.getMeasTypeEnumByMeasType(commonTelemetry.get("measTypeCode", String.class)); + //统计数据,经过测试,接口响应json可能不包含该属性 + statisticsDataList = commonTelemetry.get("telemetryValue", JSONArray.class); + if (CollectionUtil.isEmpty(statisticsDataList)) { + //添加进有指标但无遥测数据集合 + continue; + } + influxData = new ArrayList<>(); + InfluxAreaData influxAreaData; + for (Object subObj : statisticsDataList) { // 匹配上进入,循环96次 + statisticsData = JSONUtil.parseObj(subObj); + if(areaMap.containsKey(commonTelemetry.get("psrId", String.class))){ + List list = areaMap.get(commonTelemetry.get("psrId", String.class)); + for (String s : list) { + tempInfluxData = new StringBuilder(); + tempInfluxData.append(measTypeEnumByMeasType.getPhaseType()) + .append(StrPool.COMMA) + .append(s) + .append(StrPool.COMMA) + .append(statisticsData.get("dataTime", String.class)) + .append(StrPool.COMMA) + .append(measTypeEnumByMeasType.getFieldName()) + .append(StrPool.COMMA) + .append(StrUtil.isBlank(statisticsData.get("measValue", String.class)) ? "0" : statisticsData.get("measValue", String.class)); + influxAreaData=new InfluxAreaData(); + influxAreaData.setId(s); + influxAreaData.setInfluxData(tempInfluxData.toString()); + + influxData.add(influxAreaData); + } + } + } + //userId@measType@tableName:存在多个指标存储表名一致,避免数据覆盖; + Map> influxLineData = influxData.stream().collect(Collectors.groupingBy(InfluxAreaData::getId,Collectors.mapping(InfluxAreaData::getInfluxData, Collectors.toList()))); + for (String s : influxLineData.keySet()) { + typeData.put(s.concat(StrPool.AT).concat(measTypeEnumByMeasType.getMeasType()).concat(StrPool.AT).concat(measTypeEnumByMeasType.getTableName()),influxLineData.get(s) ); + } + + //处理完,删除该条记录,减少集合尺寸,提高效率 + userIdConcatMeasType.remove(dataIdentify); + } + } + //没有匹配上的就是该用户没有数据 + log.error("剩余有{}条标识", userIdConcatMeasType.size()); + } else { + log.error("查询遥测数据失败!第{}片,结果为:{}", count, response); + } + } + //最后输出没有数据的资源编号 + /** + * 输出到2个文件,lackData.txt、 excalationData.txt + * 注: + * 1、所有指标均没有有数据的资源编号 + * 2、部分指标没有数据的资源编号,并表明是哪些指标 + */ + if (CollectionUtil.isNotEmpty(userIdConcatMeasType)) { + Map> finalMap = userIdConcatMeasType.stream().collect(Collectors.groupingBy(str -> + str.substring(0, str.indexOf(StrPool.AT)) + )); + //全部缺失数据的用户 + List lackData = new ArrayList<>(); + //部分缺失的用户及指标 + List excalationData = new ArrayList<>(); + Set keyedSet = finalMap.keySet(); + for (String key : keyedSet) { + List data = finalMap.get(key); + if (data.size() == typeList.size()) { + lackData.add(key); + } else { + data = data.stream().map(t -> t.substring(t.indexOf(StrPool.AT) + 1)).collect(Collectors.toList()); + key = key.concat(StrPool.COMMA).concat(StringUtils.join(data, StrPool.AT)); + excalationData.add(key); + } + } + FileWriter lackDataWriter = FileWriter.create(new File("/usr/local/syncData/lackData" + date + k + ".txt")); + lackDataWriter.writeLines(lackData); + FileWriter excalationDataWriter = FileWriter.create(new File("/usr/local/syncData/excalationData" + date + k + ".txt")); + excalationDataWriter.writeLines(excalationData); + } + log.error("用户有指标没有数据的长度为:{}", userIdConcatMeasType.size()); + //最后批量入库 + batchInsertData(typeData); + } + + + /** + * 批量入库influxDB + * + * @param typeData 远程根据用户编号获取的数据 Map>> typeData = new HashMap<>(); + */ + private void batchInsertData(Map> typeData) { + log.error("总计有{}条记录入库,以20000作为基数分片插入influxdb", typeData.size()); + List sqlList = new ArrayList<>(); + Set tableNames = typeData.keySet(); + String[] datas; + Map tags; + Map fields; + Point point; + BatchPoints batchPoints; + for (String tableName : tableNames) { + List data = typeData.get(tableName); + tableName = tableName.substring(tableName.lastIndexOf(StrPool.AT) + 1); + for (String datum : data) { + datas = datum.split(StrPool.COMMA); + //tag数据 + tags = new HashMap<>(); + tags.put("phasic_type", datas[0]); + tags.put("line_id", datas[1]); + tags.put("quality_flag", "0"); + tags.put("value_type", "AVG"); + String time = datas[2]; + //tag数据删完后,剩余均是filed数据,因filed属性名不固定,无法指定获取,直接循环 + fields = new HashMap<>(); + fields.put(datas[3], datas[4]); + point = influxDbUtils.pointBuilder(tableName, DateUtil.parse(time, DatePattern.NORM_DATETIME_FORMATTER).getTime(), TimeUnit.MILLISECONDS, tags, fields); + batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build(); + batchPoints.point(point); + sqlList.add(batchPoints.lineProtocol()); + } + } + List> subSqlList = ListUtils.partition(sqlList, 20000); + int count = 1; + for (List sql : subSqlList) { + try { + influxDbUtils.batchInsert(influxDbUtils.getDbName(), "autogen", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, sql); + } catch (Exception exception) { + log.error("数据批量入库异常,异常为:{}",exception.toString()); + exception.printStackTrace(); + } + log.error("已经入库{}条记录!", count * 20000); + count++; + } + log.error("当前批次所有数据,{}条均已入库!", sqlList.size()); + + } +}