获取处理电表数据、电表设备新增通讯地址字段

master
FCD 5 days ago
parent 2a20036a6c
commit 8c89048468

@ -183,6 +183,8 @@ public class BaseMonitorInfo extends BaseEntity {
private String businessName;
private String addressCode;
/**
*
*/
@ -461,6 +463,14 @@ public class BaseMonitorInfo extends BaseEntity {
this.publicShareType = publicShareType;
}
public String getAddressCode() {
return addressCode;
}
public void setAddressCode(String addressCode) {
this.addressCode = addressCode;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

@ -1,5 +1,6 @@
package com.op.energy.base.service.impl;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.op.common.core.exception.ServiceException;
import com.op.common.core.utils.DateUtils;
@ -93,6 +94,14 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service {
System.out.println("新增计量设备信息异常:" + e.getMessage());
}
//判断该通信地址是否已绑定设备
BaseMonitorInfo temp = new BaseMonitorInfo();
temp.setAddressCode(baseMonitorInfo.getAddressCode());
List<BaseMonitorInfo> list = baseMonitorInfoMapper.selectBaseMonitorInfoList(temp);
if (!CollectionUtils.isEmpty(list)){
throw new ServiceException("通信地址重复:" + baseMonitorInfo.getAddressCode());
}
baseMonitorInfo.setCreateTime(DateUtils.getNowDate());
baseMonitorInfo.setCreateBy(SecurityUtils.getUsername());
return baseMonitorInfoMapper.insertBaseMonitorInfo(baseMonitorInfo);

@ -188,4 +188,26 @@ public class RecordDnbInstantController extends BaseController {
return AjaxResult.success(recordDnbInstantService.voltageCurrentCurve(baseDnbInstant));
}
/**
*
* **/
@PostMapping("/getNhEnergyDetail")
@ResponseBody
public AjaxResult getNhEnergyDetail() {
recordDnbInstantService.getNhEnergyDetail();
return AjaxResult.success();
}
/**
*
* **/
@PostMapping("/getNhEnergy")
@ResponseBody
public AjaxResult getNhEnergy() {
recordDnbInstantService.getNhEnergy();
return AjaxResult.success();
}
}

@ -85,4 +85,8 @@ public interface IRecordDnbInstantService {
RecordDnbInstant tablewareDetailsInfo(RecordDnbInstant dnbInstant);
List<RecordDnbInstant> voltageCurrentCurve(RecordDnbInstant baseDnbInstant);
void getNhEnergyDetail();
void getNhEnergy();
}

@ -1,24 +1,30 @@
package com.op.energy.record.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.op.common.core.text.Convert;
import com.op.common.core.utils.DateUtils;
import com.op.common.core.utils.StringUtils;
import com.op.common.core.web.domain.AjaxResult;
import com.op.energy.base.domain.BaseMonitorInfo;
import com.op.energy.base.mapper.BaseMonitorInfo1Mapper;
import com.op.energy.base.service.IBaseMonitorInfoService;
import com.op.energy.record.domain.RecordDnbInstant;
import com.op.energy.record.mapper.RecordDnbInstantMapper;
import com.op.energy.record.service.IRecordDnbInstantService;
import com.op.energy.report.domain.ReportPointDnb;
import com.op.energy.report.mapper.ReportPointDnbMapper;
import com.op.system.api.RemoteOpenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -35,6 +41,15 @@ public class RecordDnbInstantServiceImpl implements IRecordDnbInstantService {
@Autowired
private IBaseMonitorInfoService baseMonitorInfoService;
@Autowired
private RemoteOpenService remoteOpenService;
@Autowired
private ReportPointDnbMapper reportPointDnbMapper;
@Autowired
private BaseMonitorInfo1Mapper baseMonitorInfoMapper;
/**
*
*
@ -232,5 +247,212 @@ public class RecordDnbInstantServiceImpl implements IRecordDnbInstantService {
return recordDnbInstantMapper.selectRecordDnbInstantList(dnbInstant);
}
@Override
public void getNhEnergyDetail() {
Map<String,String> params = new HashMap<>();
params.put("dateType","mi15");
//获取当前时间的前后5分钟
Date nowTime = DateUtils.getNowDate();
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.addMinutes(nowTime,-20));
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.addMinutes(nowTime,-10));
params.put("startTime",startTime);
params.put("endTime",endTime);
// params.put("startTime","2025-07-30 13:40:00");
// params.put("endTime","2025-07-30 13:50:00");
params.put("valueType","SJZ");
/**
* /
* **/
AjaxResult voltageRes = remoteOpenService.getVoltageCurrent(params);
List<RecordDnbInstant> list = new ArrayList<>();
if(voltageRes.isSuccess()){
JSONObject resData = JSONObject.parseObject(JSON.toJSONString(voltageRes.get(AjaxResult.DATA_TAG)));
JSONArray array = JSONArray.parseArray(resData.get("Data").toString());
for (int i = 0; i < array.size(); i++) {
RecordDnbInstant instant = new RecordDnbInstant();
instant.setVA(getSafeBigDecimal(array.getJSONObject(i), "ADY"));
instant.setVB(getSafeBigDecimal(array.getJSONObject(i), "BDY"));
instant.setVC(getSafeBigDecimal(array.getJSONObject(i), "CDY"));
instant.setIA(getSafeBigDecimal(array.getJSONObject(i), "ADL"));
instant.setIB(getSafeBigDecimal(array.getJSONObject(i), "BDL"));
instant.setIC(getSafeBigDecimal(array.getJSONObject(i), "CDL"));
instant.setMonitorId(array.getJSONObject(i).getString("Address"));
instant.setRecordTime(nowTime);
instant.setCollectTime(DateUtils.dateTime("yyyy-MM-dd HH:mm", array.getJSONObject(i).getString("ReadingDate")));
list.add(instant);
}
}
/**
*
* **/
AjaxResult electricPowerRes = remoteOpenService.getElectricPower(params);
if(electricPowerRes.isSuccess()){
JSONObject resData = JSONObject.parseObject(JSON.toJSONString(electricPowerRes.get(AjaxResult.DATA_TAG)));
JSONArray array = JSONArray.parseArray(resData.get("Data").toString());
for (int i = 0; i < array.size(); i++) {
for (RecordDnbInstant item : list) {
String address = array.getJSONObject(i).getString("Address");
if (address.equals(item.getMonitorId())) {
item.setGlys(getSafeBigDecimal(array.getJSONObject(i), "GLYS"));
item.setZxyg(getSafeBigDecimal(array.getJSONObject(i), "YGGL"));
item.setActivePower(getSafeBigDecimal(array.getJSONObject(i), "YGGL"));
item.setReactivePower(getSafeBigDecimal(array.getJSONObject(i), "WGGL"));
}
}
}
}
/**
*
* **/
AjaxResult electricQuantityRes= remoteOpenService.getElectricQuantity(params);
if(electricQuantityRes.isSuccess()){
JSONObject resData = JSONObject.parseObject(JSON.toJSONString(electricQuantityRes.get(AjaxResult.DATA_TAG)));
JSONArray array = JSONArray.parseArray(resData.get("Data").toString());
for (int i = 0; i < array.size(); i++) {
for (RecordDnbInstant item : list) {
String address = array.getJSONObject(i).getString("Address");
if (address.equals(item.getMonitorId())) {
item.setReactivePower(getSafeBigDecimal(array.getJSONObject(i), "ZYGDN"));
}
}
}
}
DynamicDataSourceContextHolder.push("ds_1000");
try {
for (RecordDnbInstant item : list) {
BaseMonitorInfo temp = new BaseMonitorInfo();
temp.setAddressCode(item.getMonitorId());
List<BaseMonitorInfo> BaseList = baseMonitorInfoMapper.selectBaseMonitorInfoList(temp);
for (BaseMonitorInfo base : BaseList) {
item.setMonitorId(base.getMonitorId());
recordDnbInstantMapper.insertRecordDnbInstant(item);
}
}
}finally {
DynamicDataSourceContextHolder.poll();
}
}
@Override
public void getNhEnergy() {
Map<String,String> params = new HashMap<>();
params.put("dateType","mi15");
//获取当前时间的前后5分钟
Date nowDate = DateUtils.getNowDate();
//取整点数据
String nowDateStr = DateUtils.parseDateToStr("yyyy-MM-dd HH",nowDate)+":00:00";
String startTime = DateUtils.parseDateToStr("yyyy-MM-dd HH",DateUtils.addHours(nowDate,-1))+":00:00";
params.put("startTime",startTime);
params.put("endTime",nowDateStr);
params.put("valueType","SJZ");
/**
*
* **/
List<ReportPointDnb> list = new ArrayList<>();
AjaxResult electricQuantityRes= remoteOpenService.getElectricQuantity(params);
if(electricQuantityRes.isSuccess()){
JSONObject resData = JSONObject.parseObject(JSON.toJSONString(electricQuantityRes.get(AjaxResult.DATA_TAG)));
JSONArray array = JSONArray.parseArray(resData.get("Data").toString());
//根据Address分类
List<String> addressList = new ArrayList<>();
for (int i = 0; i < array.size(); i++) {
addressList.add(array.getJSONObject(i).getString("Address"));
}
//addressList去重
addressList = addressList.stream().distinct().collect(Collectors.toList());
DynamicDataSourceContextHolder.push("ds_1000");
try {
for (String address : addressList) {
ReportPointDnb dnb = new ReportPointDnb();
BigDecimal electricQuantity = BigDecimal.ZERO;
for (int i = 0; i < array.size(); i++) {
if (address.equals(array.getJSONObject(i).getString("Address"))) {
electricQuantity = electricQuantity.add(getSafeBigDecimal(array.getJSONObject(i), "ZYGDN"));
}
}
dnb.setMeterValue(array.getJSONObject(0).getBigDecimal("ZYGDNSZ"));
dnb.setExpend(electricQuantity);
dnb.setMonitorId(address);
dnb.setBeginTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,startTime));
dnb.setEndTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,nowDateStr));
dnb.setRecordTime(new Date());
dnb.setPointTime(removeLeadingZeros(DateUtils.parseDateToStr("HH",DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,startTime))));
BaseMonitorInfo temp = new BaseMonitorInfo();
temp.setAddressCode(dnb.getMonitorId());
List<BaseMonitorInfo> BaseList = baseMonitorInfoMapper.selectBaseMonitorInfoList(temp);
for (BaseMonitorInfo base : BaseList) {
dnb.setMonitorId(base.getMonitorId());
reportPointDnbMapper.insertReportPointDnb(dnb);
}
}
}finally {
DynamicDataSourceContextHolder.poll();
}
}
}
/**
* 0
* **/
public static String removeLeadingZeros(String str) {
if (str.isEmpty()){
return "";
}
int index = 0;
while (index < str.length() && str.charAt(index) == '0') {
index++;
}
// 处理全零情况(如"0000"返回"0"
return index == str.length() ? "0" : str.substring(index);
}
private static BigDecimal getSafeBigDecimal(JSONObject jsonObject, String key) {
BigDecimal defaultValue = BigDecimal.ZERO;
// 处理字段不存在的情况
if (!jsonObject.containsKey(key)) {
return defaultValue;
}
Object value = jsonObject.get(key);
// 处理值为null的情况
if (value == null) {
return defaultValue;
}
// 处理各种可能的数值类型
try {
if (value instanceof BigDecimal) {
return (BigDecimal) value;
} else if (value instanceof Number) {
// 处理整数、浮点数等数字类型
return new BigDecimal(value.toString());
} else if (value instanceof String) {
// 处理字符串类型的数字
String strValue = (String) value;
if (strValue.trim().isEmpty()) {
return defaultValue;
}
return new BigDecimal(strValue);
} else {
// 不支持的类型
return defaultValue;
}
} catch (NumberFormatException e) {
// 转换失败时返回默认值
return defaultValue;
}
}
}

@ -37,13 +37,14 @@
<result property="roomCode" column="room_code"/>
<result property="roomName" column="room_name"/>
<result property="physicalCode" column="physical_code"/>
<result property="addressCode" column="address_code"/>
</resultMap>
<sql id="selectBaseMonitorInfoVo">
select objid, parent_id, monitor_id, monitor_name, monitor_addr, monitor_type, monitor_status,
collect_device_id, ancestors, grade, build_id, subentry_id, business_id, meter_type_id,
meter_id, correct_value, pt, ct, is_ammeter, is_key_monitor, is_circuit, dept_id, user_id,
create_by, create_time, update_by, update_time, public_share_type,monitor_hierarchy,room_code,room_name,physical_code from base_monitor_info
create_by, create_time, update_by, update_time, public_share_type,monitor_hierarchy,room_code,room_name,physical_code,address_code from base_monitor_info
</sql>
<select id="selectBaseMonitorInfoList" parameterType="BaseMonitorInfo" resultMap="BaseMonitorInfoResult">
@ -77,6 +78,7 @@
<if test="monitorHierarchy != null ">and monitor_hierarchy = #{monitorHierarchy}</if>
<if test="physicalCode != null ">and physical_code = #{physicalCode}</if>
<if test="roomCode != null ">and room_code = #{roomCode}</if>
<if test="addressCode != null ">and address_code = #{addressCode}</if>
</where>
</select>
@ -143,6 +145,7 @@
<if test="roomCode != null">room_code,</if>
<if test="roomName != null">room_name,</if>
<if test="physicalCode != null">physical_code,</if>
<if test="addressCode != null">address_code,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="parentId != null">#{parentId},</if>
@ -176,6 +179,7 @@
<if test="roomCode != null">#{roomCode},</if>
<if test="roomName != null">#{roomName},</if>
<if test="physicalCode != null">#{physicalCode},</if>
<if test="addressCode != null">#{addressCode},</if>
</trim>
</insert>
@ -213,6 +217,7 @@
<if test="roomCode != null">room_code = #{roomCode},</if>
<if test="roomName != null">room_name = #{roomName},</if>
<if test="physicalCode != null">physical_code = #{physicalCode},</if>
<if test="addressCode != null">address_code = #{addressCode},</if>
</trim>
where objid = #{objid}
</update>

Loading…
Cancel
Save