...
|
...
|
@@ -6,9 +6,14 @@ import com.sunyo.energy.location.controller.response.ResultJson; |
|
|
import com.sunyo.energy.location.model.*;
|
|
|
import com.sunyo.energy.location.service.ElectricityMeterService;
|
|
|
import com.sunyo.energy.location.utils.HttpsUtils;
|
|
|
import com.sunyo.energy.location.utils.Md5Utils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import sun.security.provider.MD5;
|
|
|
|
|
|
import java.awt.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
...
|
...
|
@@ -27,7 +32,17 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
/**
|
|
|
* 获取电表实时数据/余额
|
|
|
*/
|
|
|
private final static String electricityBanlance = "http://192.168.1.2:18080/api/emcs/getEnergyInfoForRealTime";
|
|
|
private final static String electricityBanlanceUrl = "http://192.168.1.2:18080/api/emcs/getEnergyInfoForRealTime";
|
|
|
|
|
|
/**
|
|
|
* 电表充值接口读取配置文件ip地址
|
|
|
*/
|
|
|
@Value("${eeid.ipAddress}")
|
|
|
private String ipAddress;
|
|
|
/**
|
|
|
* 电表充值接口地址
|
|
|
*/
|
|
|
private final static String rechargeDevicesUrl = "http://192.168.1.2:18080/api/emcs/rechargeDevices";
|
|
|
|
|
|
/**
|
|
|
* 电费查询
|
...
|
...
|
@@ -101,7 +116,7 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
public Number balance(String deviceId){
|
|
|
|
|
|
// 获取电表余额
|
|
|
String s1 = HttpsUtils.sendPostHttpRequest(electricityBanlance, "1");
|
|
|
String s1 = HttpsUtils.sendPostHttpRequest(electricityBanlanceUrl, "1");
|
|
|
|
|
|
ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(s1, ElectricityBalanceOne.class);
|
|
|
|
...
|
...
|
@@ -124,7 +139,7 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
datas.put("deviceId", "1");
|
|
|
try {
|
|
|
|
|
|
String infoForRealTime = HttpsUtils.sendPost(electricityBanlance, datas);
|
|
|
String infoForRealTime = HttpsUtils.sendPost(electricityBanlanceUrl, datas);
|
|
|
ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(infoForRealTime, ElectricityBalanceOne.class);
|
|
|
List<ElectricityBalanceThree> infoForRealTimeList = electricityBalanceOne.getData().getDatas();
|
|
|
for (ElectricityBalanceThree electricityBalanceThree: infoForRealTimeList){
|
...
|
...
|
@@ -138,4 +153,33 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { |
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int rechargeDevices(String deviceId, String money, String actionType) {
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("actionType", actionType);
|
|
|
map.put("deviceId", deviceId);
|
|
|
map.put("money", money);
|
|
|
map.put("ipAddress", ipAddress);
|
|
|
// 设置secret值 设备id 跟金额 盐 需要进行加密
|
|
|
BigDecimal bigDecimal = new BigDecimal(money).setScale(2, RoundingMode.HALF_UP);
|
|
|
String moneyString = String.valueOf(bigDecimal);
|
|
|
String secret = Md5Utils.getMD5(deviceId + moneyString + "tiansu", true, 32);
|
|
|
map.put("secret", secret);
|
|
|
try {
|
|
|
|
|
|
String result = HttpsUtils.sendPost(rechargeDevicesUrl, map);
|
|
|
RechargeDevicesResult rechargeDevicesResult = JSON.parseObject(result, RechargeDevicesResult.class);
|
|
|
|
|
|
if ("0".equals(rechargeDevicesResult.getErrcode())){
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return 0;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
} |
...
|
...
|
|