作者 shenhailong

修改充值水费逻辑 电费充值成功送电逻辑

... ... @@ -175,13 +175,17 @@ eeid:
eeUrl:
#电表充值路径
# rechargeDevicesUrl: "http://10.5.10.102:8000/api/emcs/rechargeDevices"
rechargeDevicesUrl: "http://192.168.1.7:18080/api/emcs/rechargeDevices"
rechargeDevicesUrl: "http://192.168.1.199:18080/api/emcs/rechargeDevices"
#获取电表实时数据/余额
# electricityBanlanceUrl: "http://10.5.10.102:8000/api/emcs/getEnergyInfoForRealTime"
electricityBanlanceUrl: "http://192.168.1.7:18080/api/emcs/getEnergyInfoForRealTime"
electricityBanlanceUrl: "http://192.168.1.199:18080/api/emcs/getEnergyInfoForRealTime"
#获取设备跟公寓信息
# getRoomAndDeviceUrl: "http://10.5.10.102:8000/api/emcs/getRoomAndDevice"
getRoomAndDeviceUrl: "http://192.168.1.7:18080/api/emcs/getRoomAndDevice"
getRoomAndDeviceUrl: "http://192.168.1.199:18080/api/emcs/getRoomAndDevice"
#电表送电 1送电 2断电
# remoteControlDevices: "http://10.5.10.102:8000/api/emcs/remoteControlDevices"
remoteControlDevices: "http://192.168.1.199:18080/api/emcs/remoteControlDevices"
payInfo:
#商户代码
merchantid: "105001453995827"
... ...
... ... @@ -51,11 +51,9 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
*/
@Value("${eeUrl.rechargeDevicesUrl}")
private String rechargeDevicesUrl;
/**
* 获取设备跟公寓信息
*/
@Value("${eeUrl.getRoomAndDeviceUrl}")
private String getRoomAndDeviceUrl;
@Value("${eeUrl.remoteControlDevices}")
private String remoteControlDevices;
/**
* 实施获取电表数据
... ... @@ -111,6 +109,16 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
}
if ("0".equals(rechargeDevicesResult.getErrcode()) && message == true) {
log.info("电表充值成功,充值额度:{}", money);
ElectricityMeter energyInfoForRealTime = getEnergyInfoForRealTime(deviceId);
if (energyInfoForRealTime.getBalance() != null){
int i = energyInfoForRealTime.getBalance().compareTo(BigDecimal.ZERO);
if (i > 0){
Map<String, Object> map = new HashMap<>();
map.put("deviceId", deviceId);
map.put("action", "1");
HttpsUtils.sendPost(remoteControlDevices, map);
}
}
return 1;
} else {
log.info("电表充值失败,充值额度:{}", money);
... ...
... ... @@ -5,6 +5,7 @@ import com.sunyo.energy.location.model.ElectricityMeter;
import com.sunyo.energy.location.model.WaterMeter;
import com.sunyo.energy.location.service.ElectricityMeterService;
import com.sunyo.energy.location.service.LocationService;
import com.sunyo.energy.location.service.WaterMeterService;
import com.sunyo.energy.location.utils.AllUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -25,6 +26,9 @@ public class LocationServiceImp implements LocationService {
@Autowired
ElectricityMeterService electricityMeterService;
@Autowired
WaterMeterService waterMeterService;
@Override
public List userPayList(String roomNumber) {
... ... @@ -38,22 +42,11 @@ public class LocationServiceImp implements LocationService {
// 查询房间号 水表本地查询list
Map<String, Object> thisLocalityWaterMap = locationMapper.userPayList(roomNumber);
Map<String, Object> distanceWaterMap = new HashMap<>();
// 是否为null 为null则去线上查询
// if (thisLocalityWaterMap != null) {
// if (!StringUtils.isEmpty(thisLocalityWaterMap.get("wmSacc").toString()) && !StringUtils.isEmpty(thisLocalityWaterMap.get("wmLacc").toString())) {
// // 计算剩余量 充值量 减去 消费量 参数1 减去 参数2
// String subtraction = AllUtils.nubmerSubtraction(thisLocalityWaterMap.get("wmSacc").toString(), thisLocalityWaterMap.get("wmLacc").toString());
// // 余量
// thisLocalityWaterMap.put("subtraction", subtraction);
// }
// list.add(thisLocalityWaterMap);
// } else {
// 查询该房间号的水表编号
String wmId = locationMapper.findWmId(roomNumber);
if (!"".equals(wmId)) {
Map<String, Object> waterMaps = new HashMap<>();
WaterMeterServiceImp waterMeterServiceImp = new WaterMeterServiceImp();
WaterMeter realTime = waterMeterServiceImp.findRealTime(wmId);
WaterMeter realTime = waterMeterService.findRealTime(wmId);
String subtraction = AllUtils.nubmerSubtraction(realTime.getWmSacc(), realTime.getWmLacc());
distanceWaterMap.put("subtraction", subtraction);
distanceWaterMap.put("wmSacc", realTime.getWmSacc());
... ... @@ -62,7 +55,6 @@ public class LocationServiceImp implements LocationService {
distanceWaterMap.put("wmId", wmId);
list.add(distanceWaterMap);
}
// }
/**
* 电费查询 通过房间号查询设备id
*/
... ...
... ... @@ -6,9 +6,11 @@ import com.sunyo.energy.location.controller.response.ResultJson;
import com.sunyo.energy.location.dao.LocationMapper;
import com.sunyo.energy.location.dao.PayRecordsMapper;
import com.sunyo.energy.location.dao.WaterMeterMapper;
import com.sunyo.energy.location.dao.WaterMeterSaccMapper;
import com.sunyo.energy.location.demopay.QrDemo;
import com.sunyo.energy.location.model.PayRecords;
import com.sunyo.energy.location.model.WaterMeter;
import com.sunyo.energy.location.model.WaterMeterSacc;
import com.sunyo.energy.location.service.WaterMeterService;
import com.sunyo.energy.location.utils.AllUtils;
import com.sunyo.energy.location.utils.HttpsUtils;
... ... @@ -37,6 +39,9 @@ public class WaterMeterServiceImp implements WaterMeterService {
@Autowired
private LocationMapper locationMapper;
@Autowired
private WaterMeterSaccMapper waterMeterSaccMapper;
@Value("${payInfo.merchantid}")
private String MERCHANTIDS;
... ... @@ -124,6 +129,10 @@ public class WaterMeterServiceImp implements WaterMeterService {
waterMeter.setWmVoltage(map.get("wm_voltage").toString());
}
}
//查询累计充值量
String wmIds = AllUtils.wmIdUtils(wmId);
WaterMeterSacc waterMeterSacc = waterMeterSaccMapper.selectByPrimaryKey(wmIds);
waterMeter.setWmSacc(String.valueOf(waterMeterSacc.getWmSacc()));
return waterMeter;
} catch (Exception e) {
e.printStackTrace();
... ... @@ -146,9 +155,22 @@ public class WaterMeterServiceImp implements WaterMeterService {
// 得到请求接口 返回值 和总水量
Map<String, Object> map = allWater(payFees, wmId);
Map hashMap = JSON.parseObject(map.get("status").toString(), HashMap.class);
/**
* 外部充值水表成功
*/
if ("0".equals(hashMap.get("state").toString())) {
int update = waterMeterMapper.update(wmId, map.get("allSacc").toString());
WaterMeterSacc waterMeterSacc = new WaterMeterSacc();
waterMeterSacc.setWmId(AllUtils.wmIdUtils(wmId));
waterMeterSacc.setWmSacc(new BigDecimal(String.valueOf(map.get("Add_sacc"))));
/**
* 修改本地累计充值量
*/
int i = waterMeterSaccMapper.updateByPrimaryKeySelective(waterMeterSacc);
if (i > 0){
resultJson.setCode("200");
}else {
resultJson.setCode("203");
}
} else {
resultJson.setCode("203");
}
... ... @@ -234,13 +256,14 @@ public class WaterMeterServiceImp implements WaterMeterService {
// 充值最后立方水数值
String s = AllUtils.nubmerDivision(payFees);
// 查询累计充值量
WaterMeter realTime = findRealTime(wmId);
String allSacc = AllUtils.nubmerAdd(s, realTime.getWmSacc());
WaterMeterSacc waterMeterSacc = waterMeterSaccMapper.selectByPrimaryKey(AllUtils.wmIdUtils(wmId));
String allSacc = AllUtils.nubmerAdd(s, waterMeterSacc.getWmSacc());
Map<String, Object> datas = new HashMap<>();
datas.put("MtId", wmId);
datas.put("Add_sacc", allSacc);
datas.put("Add_addmode", "2");
String status = HttpsUtils.httpRequest(payUrl, datas);
datas.put("allSacc", allSacc);
datas.put("status", status);
... ...
... ... @@ -35,11 +35,10 @@ public class AllUtils {
//数字相加 参数1加参数2
public static String nubmerAdd(String oneWmSacc, String s) {
public static String nubmerAdd(String oneWmSacc, BigDecimal s) {
BigDecimal bigDecimal = new BigDecimal(oneWmSacc);
BigDecimal bigDecimal1 = new BigDecimal(s);
String s1 = bigDecimal.add(bigDecimal1).toString();
String s1 = bigDecimal.add(s).toString();
return s1;
}
... ... @@ -56,5 +55,22 @@ public class AllUtils {
return merchantId + result;
}
/**
* 处理水表编号加 '-' 问题
* @param replace 水表编号
* @return
*/
public static String wmIdUtils(String replace) {
if (!replace.contains("-")){
String regex = "(.{2})";
replace = replace.replaceAll(regex, "$1-");
String substring = replace.substring(0, replace.length() - 1);
return substring;
}else {
return replace;
}
}
}
... ...