|
|
package com.sunyo.energy.location.service.imp;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.sun.deploy.net.HttpUtils;
|
|
|
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIGlobalBinding;
|
|
|
import com.sunyo.energy.location.dao.*;
|
|
|
import com.sunyo.energy.location.model.*;
|
...
|
...
|
@@ -27,6 +28,9 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
@Autowired
|
|
|
PayRecordsMapper payRecordsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
ElectrifyInfoMapper electrifyInfoMapper;
|
|
|
|
|
|
/**
|
|
|
* 电表充值接口地址
|
|
|
*/
|
...
|
...
|
@@ -67,16 +71,11 @@ 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);
|
|
|
}
|
|
|
}
|
|
|
// 插入送电临时表
|
|
|
ElectrifyInfo electrifyInfo1 = new ElectrifyInfo();
|
|
|
electrifyInfo1.setDeviceid(electricityInfo.getDeviceId());
|
|
|
electrifyInfoMapper.insertSelective(electrifyInfo1);
|
|
|
// 修改订单状态
|
|
|
payRecordsMapper.updateStatus(electricityInfo.getOrderNumber());
|
|
|
// 成功 删除该订单
|
|
|
electricityInfoMapper.deleteByPrimaryKey(electricityInfo.getOrderNumber());
|
...
|
...
|
@@ -129,4 +128,50 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 定时读取电表临时表 送电
|
|
|
*/
|
|
|
@Scheduled(fixedDelay = 30000)
|
|
|
public void electrifyInfo() {
|
|
|
try {
|
|
|
List<ElectrifyInfo> electrifyInfoList = electrifyInfoMapper.selectAll();
|
|
|
for (ElectrifyInfo electrifyInfo: electrifyInfoList ){
|
|
|
ElectricityMeter energyInfoForRealTime = getEnergyInfoForRealTime(electrifyInfo.getDeviceid());
|
|
|
if (energyInfoForRealTime.getBalance() != null){
|
|
|
int i = energyInfoForRealTime.getBalance().compareTo(BigDecimal.ZERO);
|
|
|
log.info("查询该设备余额是否为正数{}", i);
|
|
|
if (i > 0){
|
|
|
log.info("进入送电接口----------");
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("deviceId", electrifyInfo.getDeviceid());
|
|
|
map.put("action", "1");
|
|
|
String postResult = HttpsUtils.sendPost(remoteControlDevices, map);
|
|
|
ProwerResult prowerResult = JSON.parseObject(postResult, ProwerResult.class);
|
|
|
List<ProwerResultDatas> datas = prowerResult.getData().getDatas();
|
|
|
if ("0".equals(prowerResult.getErrcode())){
|
|
|
log.info("送电成功-------------------");
|
|
|
log.info("success-info-RechargeDevicesResult");
|
|
|
System.out.println(datas);
|
|
|
// 成功 删除该订单
|
|
|
electrifyInfoMapper.deleteByPrimaryKey(electrifyInfo.getId());
|
|
|
}else {
|
|
|
// 失败插入临时表
|
|
|
ElectrifyInfo electrifyInfo1 = new ElectrifyInfo();
|
|
|
electrifyInfo1.setDeviceid(electrifyInfo.getDeviceid());
|
|
|
electrifyInfoMapper.insertSelective(electrifyInfo1);
|
|
|
log.info("送电失败插入临时表--------------------------------");
|
|
|
log.info("送电信息插入success---info");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
log.info("定时任务处理完成");
|
|
|
}
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|