|
|
package com.sunyo.energy.location.service.imp;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIGlobalBinding;
|
|
|
import com.sunyo.energy.location.dao.*;
|
|
|
import com.sunyo.energy.location.model.*;
|
|
|
import com.sunyo.energy.location.service.ElectricityMeterService;
|
...
|
...
|
@@ -10,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
...
|
...
|
@@ -30,6 +33,15 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
@Value("${eeUrl.rechargeDevicesUrl}")
|
|
|
private String rechargeDevicesUrl;
|
|
|
|
|
|
@Value("${eeUrl.remoteControlDevices}")
|
|
|
private String remoteControlDevices;
|
|
|
|
|
|
/**
|
|
|
* 获取电表实时数据/余额
|
|
|
*/
|
|
|
@Value("${eeUrl.electricityBanlanceUrl}")
|
|
|
private String electricityBanlanceUrl;
|
|
|
|
|
|
/**
|
|
|
* 定时读取电表临时表 发起充值
|
|
|
*/
|
...
|
...
|
@@ -55,6 +67,17 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
message = rechargeDevicesResultData.getSuccess();
|
|
|
}
|
|
|
if ("0".equals(rechargeDevicesResult.getErrcode()) && message == true) {
|
|
|
ElectricityMeter energyInfoForRealTime = getEnergyInfoForRealTime(electricityInfo.getDeviceId());
|
|
|
if (energyInfoForRealTime.getBalance() != null){
|
|
|
int i = energyInfoForRealTime.getBalance().compareTo(BigDecimal.ZERO);
|
|
|
if (i > 0){
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("deviceId", electricityInfo.getDeviceId());
|
|
|
map.put("action", "1");
|
|
|
HttpsUtils.sendPost(remoteControlDevices, map);
|
|
|
}
|
|
|
}
|
|
|
payRecordsMapper.updateStatus(electricityInfo.getOrderNumber());
|
|
|
// 成功 删除该订单
|
|
|
electricityInfoMapper.deleteByPrimaryKey(electricityInfo.getOrderNumber());
|
|
|
}
|
...
|
...
|
@@ -76,4 +99,34 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
return map;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 实施获取电表数据
|
|
|
*/
|
|
|
public ElectricityMeter getEnergyInfoForRealTime(String deviceId) {
|
|
|
try {
|
|
|
if (!"".equals(deviceId)) {
|
|
|
Map<String, Object> stringObjectMap = eeInfo(deviceId);
|
|
|
String infoForRealTime = HttpsUtils.sendPost(electricityBanlanceUrl, stringObjectMap);
|
|
|
ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(infoForRealTime, ElectricityBalanceOne.class);
|
|
|
List<ElectricityMeter> infoForRealTimeList = electricityBalanceOne.getData().getDatas();
|
|
|
for (ElectricityMeter electricityBalanceThree : infoForRealTimeList) {
|
|
|
if (electricityBalanceThree != null) {
|
|
|
return electricityBalanceThree;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> eeInfo(String deviceId) {
|
|
|
Map<String, Object> datas = new HashMap<>();
|
|
|
datas.put("deviceId", deviceId);
|
|
|
return datas;
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|