作者 shenhailong

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

@@ -175,13 +175,17 @@ eeid: @@ -175,13 +175,17 @@ eeid:
175 eeUrl: 175 eeUrl:
176 #电表充值路径 176 #电表充值路径
177 # rechargeDevicesUrl: "http://10.5.10.102:8000/api/emcs/rechargeDevices" 177 # rechargeDevicesUrl: "http://10.5.10.102:8000/api/emcs/rechargeDevices"
178 - rechargeDevicesUrl: "http://192.168.1.7:18080/api/emcs/rechargeDevices" 178 + rechargeDevicesUrl: "http://192.168.1.199:18080/api/emcs/rechargeDevices"
179 #获取电表实时数据/余额 179 #获取电表实时数据/余额
180 # electricityBanlanceUrl: "http://10.5.10.102:8000/api/emcs/getEnergyInfoForRealTime" 180 # electricityBanlanceUrl: "http://10.5.10.102:8000/api/emcs/getEnergyInfoForRealTime"
181 - electricityBanlanceUrl: "http://192.168.1.7:18080/api/emcs/getEnergyInfoForRealTime" 181 + electricityBanlanceUrl: "http://192.168.1.199:18080/api/emcs/getEnergyInfoForRealTime"
182 #获取设备跟公寓信息 182 #获取设备跟公寓信息
183 # getRoomAndDeviceUrl: "http://10.5.10.102:8000/api/emcs/getRoomAndDevice" 183 # getRoomAndDeviceUrl: "http://10.5.10.102:8000/api/emcs/getRoomAndDevice"
184 - getRoomAndDeviceUrl: "http://192.168.1.7:18080/api/emcs/getRoomAndDevice" 184 + getRoomAndDeviceUrl: "http://192.168.1.199:18080/api/emcs/getRoomAndDevice"
  185 + #电表送电 1送电 2断电
  186 + # remoteControlDevices: "http://10.5.10.102:8000/api/emcs/remoteControlDevices"
  187 + remoteControlDevices: "http://192.168.1.199:18080/api/emcs/remoteControlDevices"
  188 +
185 payInfo: 189 payInfo:
186 #商户代码 190 #商户代码
187 merchantid: "105001453995827" 191 merchantid: "105001453995827"
@@ -51,11 +51,9 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { @@ -51,11 +51,9 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
51 */ 51 */
52 @Value("${eeUrl.rechargeDevicesUrl}") 52 @Value("${eeUrl.rechargeDevicesUrl}")
53 private String rechargeDevicesUrl; 53 private String rechargeDevicesUrl;
54 - /**  
55 - * 获取设备跟公寓信息  
56 - */  
57 - @Value("${eeUrl.getRoomAndDeviceUrl}")  
58 - private String getRoomAndDeviceUrl; 54 +
  55 + @Value("${eeUrl.remoteControlDevices}")
  56 + private String remoteControlDevices;
59 57
60 /** 58 /**
61 * 实施获取电表数据 59 * 实施获取电表数据
@@ -111,6 +109,16 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { @@ -111,6 +109,16 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
111 } 109 }
112 if ("0".equals(rechargeDevicesResult.getErrcode()) && message == true) { 110 if ("0".equals(rechargeDevicesResult.getErrcode()) && message == true) {
113 log.info("电表充值成功,充值额度:{}", money); 111 log.info("电表充值成功,充值额度:{}", money);
  112 + ElectricityMeter energyInfoForRealTime = getEnergyInfoForRealTime(deviceId);
  113 + if (energyInfoForRealTime.getBalance() != null){
  114 + int i = energyInfoForRealTime.getBalance().compareTo(BigDecimal.ZERO);
  115 + if (i > 0){
  116 + Map<String, Object> map = new HashMap<>();
  117 + map.put("deviceId", deviceId);
  118 + map.put("action", "1");
  119 + HttpsUtils.sendPost(remoteControlDevices, map);
  120 + }
  121 + }
114 return 1; 122 return 1;
115 } else { 123 } else {
116 log.info("电表充值失败,充值额度:{}", money); 124 log.info("电表充值失败,充值额度:{}", money);
@@ -5,6 +5,7 @@ import com.sunyo.energy.location.model.ElectricityMeter; @@ -5,6 +5,7 @@ import com.sunyo.energy.location.model.ElectricityMeter;
5 import com.sunyo.energy.location.model.WaterMeter; 5 import com.sunyo.energy.location.model.WaterMeter;
6 import com.sunyo.energy.location.service.ElectricityMeterService; 6 import com.sunyo.energy.location.service.ElectricityMeterService;
7 import com.sunyo.energy.location.service.LocationService; 7 import com.sunyo.energy.location.service.LocationService;
  8 +import com.sunyo.energy.location.service.WaterMeterService;
8 import com.sunyo.energy.location.utils.AllUtils; 9 import com.sunyo.energy.location.utils.AllUtils;
9 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
@@ -25,6 +26,9 @@ public class LocationServiceImp implements LocationService { @@ -25,6 +26,9 @@ public class LocationServiceImp implements LocationService {
25 @Autowired 26 @Autowired
26 ElectricityMeterService electricityMeterService; 27 ElectricityMeterService electricityMeterService;
27 28
  29 + @Autowired
  30 + WaterMeterService waterMeterService;
  31 +
28 @Override 32 @Override
29 public List userPayList(String roomNumber) { 33 public List userPayList(String roomNumber) {
30 34
@@ -38,22 +42,11 @@ public class LocationServiceImp implements LocationService { @@ -38,22 +42,11 @@ public class LocationServiceImp implements LocationService {
38 // 查询房间号 水表本地查询list 42 // 查询房间号 水表本地查询list
39 Map<String, Object> thisLocalityWaterMap = locationMapper.userPayList(roomNumber); 43 Map<String, Object> thisLocalityWaterMap = locationMapper.userPayList(roomNumber);
40 Map<String, Object> distanceWaterMap = new HashMap<>(); 44 Map<String, Object> distanceWaterMap = new HashMap<>();
41 - // 是否为null 为null则去线上查询  
42 -// if (thisLocalityWaterMap != null) {  
43 -// if (!StringUtils.isEmpty(thisLocalityWaterMap.get("wmSacc").toString()) && !StringUtils.isEmpty(thisLocalityWaterMap.get("wmLacc").toString())) {  
44 -// // 计算剩余量 充值量 减去 消费量 参数1 减去 参数2  
45 -// String subtraction = AllUtils.nubmerSubtraction(thisLocalityWaterMap.get("wmSacc").toString(), thisLocalityWaterMap.get("wmLacc").toString());  
46 -// // 余量  
47 -// thisLocalityWaterMap.put("subtraction", subtraction);  
48 -// }  
49 -// list.add(thisLocalityWaterMap);  
50 -// } else {  
51 // 查询该房间号的水表编号 45 // 查询该房间号的水表编号
52 String wmId = locationMapper.findWmId(roomNumber); 46 String wmId = locationMapper.findWmId(roomNumber);
53 if (!"".equals(wmId)) { 47 if (!"".equals(wmId)) {
54 Map<String, Object> waterMaps = new HashMap<>(); 48 Map<String, Object> waterMaps = new HashMap<>();
55 - WaterMeterServiceImp waterMeterServiceImp = new WaterMeterServiceImp();  
56 - WaterMeter realTime = waterMeterServiceImp.findRealTime(wmId); 49 + WaterMeter realTime = waterMeterService.findRealTime(wmId);
57 String subtraction = AllUtils.nubmerSubtraction(realTime.getWmSacc(), realTime.getWmLacc()); 50 String subtraction = AllUtils.nubmerSubtraction(realTime.getWmSacc(), realTime.getWmLacc());
58 distanceWaterMap.put("subtraction", subtraction); 51 distanceWaterMap.put("subtraction", subtraction);
59 distanceWaterMap.put("wmSacc", realTime.getWmSacc()); 52 distanceWaterMap.put("wmSacc", realTime.getWmSacc());
@@ -62,7 +55,6 @@ public class LocationServiceImp implements LocationService { @@ -62,7 +55,6 @@ public class LocationServiceImp implements LocationService {
62 distanceWaterMap.put("wmId", wmId); 55 distanceWaterMap.put("wmId", wmId);
63 list.add(distanceWaterMap); 56 list.add(distanceWaterMap);
64 } 57 }
65 -// }  
66 /** 58 /**
67 * 电费查询 通过房间号查询设备id 59 * 电费查询 通过房间号查询设备id
68 */ 60 */
@@ -6,9 +6,11 @@ import com.sunyo.energy.location.controller.response.ResultJson; @@ -6,9 +6,11 @@ import com.sunyo.energy.location.controller.response.ResultJson;
6 import com.sunyo.energy.location.dao.LocationMapper; 6 import com.sunyo.energy.location.dao.LocationMapper;
7 import com.sunyo.energy.location.dao.PayRecordsMapper; 7 import com.sunyo.energy.location.dao.PayRecordsMapper;
8 import com.sunyo.energy.location.dao.WaterMeterMapper; 8 import com.sunyo.energy.location.dao.WaterMeterMapper;
  9 +import com.sunyo.energy.location.dao.WaterMeterSaccMapper;
9 import com.sunyo.energy.location.demopay.QrDemo; 10 import com.sunyo.energy.location.demopay.QrDemo;
10 import com.sunyo.energy.location.model.PayRecords; 11 import com.sunyo.energy.location.model.PayRecords;
11 import com.sunyo.energy.location.model.WaterMeter; 12 import com.sunyo.energy.location.model.WaterMeter;
  13 +import com.sunyo.energy.location.model.WaterMeterSacc;
12 import com.sunyo.energy.location.service.WaterMeterService; 14 import com.sunyo.energy.location.service.WaterMeterService;
13 import com.sunyo.energy.location.utils.AllUtils; 15 import com.sunyo.energy.location.utils.AllUtils;
14 import com.sunyo.energy.location.utils.HttpsUtils; 16 import com.sunyo.energy.location.utils.HttpsUtils;
@@ -37,6 +39,9 @@ public class WaterMeterServiceImp implements WaterMeterService { @@ -37,6 +39,9 @@ public class WaterMeterServiceImp implements WaterMeterService {
37 @Autowired 39 @Autowired
38 private LocationMapper locationMapper; 40 private LocationMapper locationMapper;
39 41
  42 + @Autowired
  43 + private WaterMeterSaccMapper waterMeterSaccMapper;
  44 +
40 @Value("${payInfo.merchantid}") 45 @Value("${payInfo.merchantid}")
41 private String MERCHANTIDS; 46 private String MERCHANTIDS;
42 47
@@ -124,6 +129,10 @@ public class WaterMeterServiceImp implements WaterMeterService { @@ -124,6 +129,10 @@ public class WaterMeterServiceImp implements WaterMeterService {
124 waterMeter.setWmVoltage(map.get("wm_voltage").toString()); 129 waterMeter.setWmVoltage(map.get("wm_voltage").toString());
125 } 130 }
126 } 131 }
  132 + //查询累计充值量
  133 + String wmIds = AllUtils.wmIdUtils(wmId);
  134 + WaterMeterSacc waterMeterSacc = waterMeterSaccMapper.selectByPrimaryKey(wmIds);
  135 + waterMeter.setWmSacc(String.valueOf(waterMeterSacc.getWmSacc()));
127 return waterMeter; 136 return waterMeter;
128 } catch (Exception e) { 137 } catch (Exception e) {
129 e.printStackTrace(); 138 e.printStackTrace();
@@ -146,9 +155,22 @@ public class WaterMeterServiceImp implements WaterMeterService { @@ -146,9 +155,22 @@ public class WaterMeterServiceImp implements WaterMeterService {
146 // 得到请求接口 返回值 和总水量 155 // 得到请求接口 返回值 和总水量
147 Map<String, Object> map = allWater(payFees, wmId); 156 Map<String, Object> map = allWater(payFees, wmId);
148 Map hashMap = JSON.parseObject(map.get("status").toString(), HashMap.class); 157 Map hashMap = JSON.parseObject(map.get("status").toString(), HashMap.class);
  158 + /**
  159 + * 外部充值水表成功
  160 + */
149 if ("0".equals(hashMap.get("state").toString())) { 161 if ("0".equals(hashMap.get("state").toString())) {
150 - int update = waterMeterMapper.update(wmId, map.get("allSacc").toString()); 162 + WaterMeterSacc waterMeterSacc = new WaterMeterSacc();
  163 + waterMeterSacc.setWmId(AllUtils.wmIdUtils(wmId));
  164 + waterMeterSacc.setWmSacc(new BigDecimal(String.valueOf(map.get("Add_sacc"))));
  165 + /**
  166 + * 修改本地累计充值量
  167 + */
  168 + int i = waterMeterSaccMapper.updateByPrimaryKeySelective(waterMeterSacc);
  169 + if (i > 0){
151 resultJson.setCode("200"); 170 resultJson.setCode("200");
  171 + }else {
  172 + resultJson.setCode("203");
  173 + }
152 } else { 174 } else {
153 resultJson.setCode("203"); 175 resultJson.setCode("203");
154 } 176 }
@@ -234,13 +256,14 @@ public class WaterMeterServiceImp implements WaterMeterService { @@ -234,13 +256,14 @@ public class WaterMeterServiceImp implements WaterMeterService {
234 // 充值最后立方水数值 256 // 充值最后立方水数值
235 String s = AllUtils.nubmerDivision(payFees); 257 String s = AllUtils.nubmerDivision(payFees);
236 // 查询累计充值量 258 // 查询累计充值量
237 - WaterMeter realTime = findRealTime(wmId);  
238 - String allSacc = AllUtils.nubmerAdd(s, realTime.getWmSacc()); 259 + WaterMeterSacc waterMeterSacc = waterMeterSaccMapper.selectByPrimaryKey(AllUtils.wmIdUtils(wmId));
  260 + String allSacc = AllUtils.nubmerAdd(s, waterMeterSacc.getWmSacc());
239 Map<String, Object> datas = new HashMap<>(); 261 Map<String, Object> datas = new HashMap<>();
240 datas.put("MtId", wmId); 262 datas.put("MtId", wmId);
241 datas.put("Add_sacc", allSacc); 263 datas.put("Add_sacc", allSacc);
242 datas.put("Add_addmode", "2"); 264 datas.put("Add_addmode", "2");
243 String status = HttpsUtils.httpRequest(payUrl, datas); 265 String status = HttpsUtils.httpRequest(payUrl, datas);
  266 +
244 datas.put("allSacc", allSacc); 267 datas.put("allSacc", allSacc);
245 datas.put("status", status); 268 datas.put("status", status);
246 269
@@ -35,11 +35,10 @@ public class AllUtils { @@ -35,11 +35,10 @@ public class AllUtils {
35 35
36 36
37 //数字相加 参数1加参数2 37 //数字相加 参数1加参数2
38 - public static String nubmerAdd(String oneWmSacc, String s) { 38 + public static String nubmerAdd(String oneWmSacc, BigDecimal s) {
39 39
40 BigDecimal bigDecimal = new BigDecimal(oneWmSacc); 40 BigDecimal bigDecimal = new BigDecimal(oneWmSacc);
41 - BigDecimal bigDecimal1 = new BigDecimal(s);  
42 - String s1 = bigDecimal.add(bigDecimal1).toString(); 41 + String s1 = bigDecimal.add(s).toString();
43 return s1; 42 return s1;
44 } 43 }
45 44
@@ -56,5 +55,22 @@ public class AllUtils { @@ -56,5 +55,22 @@ public class AllUtils {
56 return merchantId + result; 55 return merchantId + result;
57 } 56 }
58 57
  58 + /**
  59 + * 处理水表编号加 '-' 问题
  60 + * @param replace 水表编号
  61 + * @return
  62 + */
  63 + public static String wmIdUtils(String replace) {
  64 + if (!replace.contains("-")){
  65 + String regex = "(.{2})";
  66 + replace = replace.replaceAll(regex, "$1-");
  67 + String substring = replace.substring(0, replace.length() - 1);
  68 +
  69 + return substring;
  70 + }else {
  71 + return replace;
  72 + }
  73 +
  74 + }
59 75
60 } 76 }