...
|
...
|
@@ -2,13 +2,25 @@ package com.sunyo.energy.location.service.imp; |
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sun.xml.internal.ws.message.stream.PayloadStreamReaderMessage;
|
|
|
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.model.PayRecords;
|
|
|
import com.sunyo.energy.location.model.WaterMeter;
|
|
|
import com.sunyo.energy.location.service.WaterMeterService;
|
|
|
import com.sunyo.energy.location.utils.AllUtils;
|
|
|
import com.sunyo.energy.location.utils.HttpsUtils;
|
|
|
import com.sunyo.energy.location.utils.PropertiesLoader;
|
|
|
import org.apache.catalina.loader.ParallelWebappClassLoader;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
...
|
...
|
@@ -20,17 +32,29 @@ public class WaterMeterServiceImp implements WaterMeterService { |
|
|
@Autowired
|
|
|
private WaterMeterMapper waterMeterMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private PayRecordsMapper payRecordsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private LocationMapper locationMapper;
|
|
|
// 查询所有水表
|
|
|
private static final String selectUrl = "http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyMtId";
|
|
|
|
|
|
private static final String payUrl = "http://123.56.159.203:8023/mtfmset/allWMadd";
|
|
|
|
|
|
private static final String addUrl = "http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyProjectID";
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@Scheduled(cron = "0 0 10 * * ?" )
|
|
|
@Scheduled(cron = "0 0 03 * * ?" )
|
|
|
public int realTime() {
|
|
|
|
|
|
try {
|
|
|
// 调用远程接口
|
|
|
String url = "http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyProjectID";
|
|
|
|
|
|
Map<String, Object> datas = new HashMap<>();
|
|
|
datas.put("ProjectID", "33-99-00-00-00-00-01");
|
|
|
String s = HttpsUtils.httpRequest(url, datas);
|
|
|
// 远程调用
|
|
|
String s = HttpsUtils.httpRequest(addUrl, datas);
|
|
|
JSONArray jsonArray = JSON.parseArray(s);
|
|
|
for (Object jsonObject:jsonArray){
|
|
|
WaterMeter waterMeter= new WaterMeter();
|
...
|
...
|
@@ -45,6 +69,7 @@ public class WaterMeterServiceImp implements WaterMeterService { |
|
|
waterMeter.setWmSignalpower(map.get("wm_signalpower").toString());
|
|
|
waterMeter.setWmVoltage(map.get("wm_voltage").toString());
|
|
|
waterMeter.setCreattime(new Date());
|
|
|
waterMeter.setReamke1(map.get("wm_sacc").toString());
|
|
|
waterMeterMapper.insertSelective(waterMeter);
|
|
|
}else {
|
|
|
if ("0".equals(map.get("state").toString())){
|
...
|
...
|
@@ -63,12 +88,10 @@ public class WaterMeterServiceImp implements WaterMeterService { |
|
|
@Override
|
|
|
public WaterMeter findRealTime(String wmId) {
|
|
|
try {
|
|
|
// 调用远程接口http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyMtId?MtId=68-74-40-34-05-29-55
|
|
|
String url = "http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyMtId";
|
|
|
Map<String, Object> datas = new HashMap<>();
|
|
|
datas.put("MtId", wmId);
|
|
|
|
|
|
String s = HttpsUtils.httpRequest(url, datas);
|
|
|
String s = HttpsUtils.httpRequest(selectUrl, datas);
|
|
|
JSONArray jsonArray = JSON.parseArray(s);
|
|
|
WaterMeter waterMeter= new WaterMeter();
|
|
|
for (Object jsonObject:jsonArray){
|
...
|
...
|
@@ -91,4 +114,94 @@ public class WaterMeterServiceImp implements WaterMeterService { |
|
|
return new WaterMeter();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 水费充值 换算总水量 生成订单
|
|
|
* @param payFees
|
|
|
* @param wmId
|
|
|
* @param userId
|
|
|
* @param realName
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public ResultJson payWater(String payFees, String wmId, String userId, String realName) {
|
|
|
|
|
|
ResultJson<Object> resultJson = new ResultJson<>();
|
|
|
try {
|
|
|
// 得到请求接口 返回值 和总水量
|
|
|
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());
|
|
|
// 成功生成水费订单
|
|
|
PayRecords payRecords = payRecords(payFees, wmId, userId, realName);
|
|
|
|
|
|
int i = payRecordsMapper.insertSelective(payRecords);
|
|
|
if (update > 0 && i >0){
|
|
|
resultJson.setCode("200");
|
|
|
}
|
|
|
}else {
|
|
|
resultJson.setCode("203");
|
|
|
}
|
|
|
return resultJson;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
resultJson.setCode("203");
|
|
|
return resultJson;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 总水量 换算
|
|
|
* @param payFees
|
|
|
* @param wmId
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Map<String, Object> allWater(String payFees, String wmId) throws Exception {
|
|
|
|
|
|
// 充值最后立方水数值
|
|
|
String s = AllUtils.nubmerDivision(payFees);
|
|
|
// 查询累计充值量
|
|
|
String oneWmSacc = waterMeterMapper.findOneWmSacc(wmId);
|
|
|
|
|
|
String allSacc = AllUtils.nubmerAdd(s, oneWmSacc);
|
|
|
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);
|
|
|
|
|
|
return datas;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单生成
|
|
|
* @param payFees
|
|
|
* @param wmId
|
|
|
* @param userId
|
|
|
* @param realName
|
|
|
* @return
|
|
|
*/
|
|
|
public PayRecords payRecords(String payFees, String wmId, String userId, String realName){
|
|
|
|
|
|
PayRecords payRecords = new PayRecords();
|
|
|
payRecords.setOrdernumber(AllUtils.getOrderIdByTime());
|
|
|
payRecords.setPayfees(Long.valueOf(payFees));
|
|
|
payRecords.setPaystatus(true);
|
|
|
payRecords.setPaytype(false);
|
|
|
payRecords.setReamke1("0");
|
|
|
payRecords.setPayuserid(Integer.valueOf(userId));
|
|
|
payRecords.setPaytime(new Date());
|
|
|
payRecords.setPayusername(realName);
|
|
|
payRecords.setPaytypeaddress(wmId);
|
|
|
String roomNumber = locationMapper.selectRoomNumber(wmId);
|
|
|
payRecords.setPaylocationname(roomNumber);
|
|
|
|
|
|
return payRecords;
|
|
|
}
|
|
|
} |
...
|
...
|
|