| 
 | 
 | 
 package com.sunyo.energy.location.service.imp;
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 import com.alibaba.fastjson.JSON;
 | 
| 
 | 
 | 
 import com.alibaba.fastjson.JSONArray;
 | 
| 
 | 
 | 
 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;
 | 
| 
 | 
 | 
 import org.springframework.beans.factory.annotation.Autowired;
 | 
| 
 | 
 | 
 import org.springframework.scheduling.annotation.Scheduled;
 | 
| 
 | 
 | 
 import org.springframework.stereotype.Service;
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 import java.io.UnsupportedEncodingException;
 | 
| 
 | 
 | 
 import java.math.BigDecimal;
 | 
| 
 | 
 | 
 import java.util.Date;
 | 
| 
 | 
 | 
 import java.util.HashMap;
 | 
| 
 | 
 | 
 import java.util.List;
 | 
| 
 | 
 | 
 import java.util.Map;
 | 
| 
 | 
 | 
 import java.util.*;
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 @Service
 | 
| 
...
 | 
...
 | 
@@ -51,76 +41,6 @@ public class WaterMeterServiceImp implements WaterMeterService { | 
| 
 | 
 | 
     private static final String addUrl = "http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyProjectID";
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     @Override
 | 
| 
 | 
 | 
     @Scheduled(cron = "0 0 03 * * ?")
 | 
| 
 | 
 | 
     public int realTime() {
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         try {
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             Map<String, Object> datas = new HashMap<>();
 | 
| 
 | 
 | 
             datas.put("ProjectID", "33-99-00-00-00-00-01");
 | 
| 
 | 
 | 
             // 远程调用
 | 
| 
 | 
 | 
             String s = HttpsUtils.httpRequest(addUrl, datas);
 | 
| 
 | 
 | 
             JSONArray jsonArray = JSON.parseArray(s);
 | 
| 
 | 
 | 
             for (Object jsonObject : jsonArray) {
 | 
| 
 | 
 | 
                 WaterMeter waterMeter = new WaterMeter();
 | 
| 
 | 
 | 
                 Map<String, Object> map = (Map) jsonObject;
 | 
| 
 | 
 | 
                 if (!map.containsKey("state")) {
 | 
| 
 | 
 | 
                     waterMeter.setWmId(map.get("wm_id").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmErrmessage(map.get("wm_errmessage").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmFmstate(map.get("wm_fmstate").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmSacc(map.get("wm_sacc").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmLacc(map.get("wm_lacc").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmRdtime(map.get("wm_rdtime").toString());
 | 
| 
 | 
 | 
                     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())) {
 | 
| 
 | 
 | 
                         return 1;
 | 
| 
 | 
 | 
                     }
 | 
| 
 | 
 | 
                     return 0;
 | 
| 
 | 
 | 
                 }
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
             return 1;
 | 
| 
 | 
 | 
         } catch (Exception e) {
 | 
| 
 | 
 | 
             e.printStackTrace();
 | 
| 
 | 
 | 
             return 0;
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     @Override
 | 
| 
 | 
 | 
     public WaterMeter findRealTime(String wmId) {
 | 
| 
 | 
 | 
         try {
 | 
| 
 | 
 | 
             Map<String, Object> datas = new HashMap<>();
 | 
| 
 | 
 | 
             datas.put("MtId", wmId);
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             String s = HttpsUtils.httpRequest(selectUrl, datas);
 | 
| 
 | 
 | 
             JSONArray jsonArray = JSON.parseArray(s);
 | 
| 
 | 
 | 
             WaterMeter waterMeter = new WaterMeter();
 | 
| 
 | 
 | 
             for (Object jsonObject : jsonArray) {
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
                 Map<String, Object> map = (Map) jsonObject;
 | 
| 
 | 
 | 
                 if (!map.containsKey("state")) {
 | 
| 
 | 
 | 
                     waterMeter.setWmId(map.get("wm_id").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmErrmessage(map.get("wm_errmessage").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmFmstate(map.get("wm_fmstate").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmSacc(map.get("wm_sacc").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmLacc(map.get("wm_lacc").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmRdtime(map.get("wm_rdtime").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmSignalpower(map.get("wm_signalpower").toString());
 | 
| 
 | 
 | 
                     waterMeter.setWmVoltage(map.get("wm_voltage").toString());
 | 
| 
 | 
 | 
                 }
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
             return waterMeter;
 | 
| 
 | 
 | 
         } catch (Exception e) {
 | 
| 
 | 
 | 
             e.printStackTrace();
 | 
| 
 | 
 | 
             return new WaterMeter();
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 水费充值 换算总水量 生成订单
 | 
| 
 | 
 | 
      *
 | 
| 
...
 | 
...
 | 
@@ -163,66 +83,6 @@ public class WaterMeterServiceImp implements WaterMeterService { | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     @Override
 | 
| 
 | 
 | 
     public ResultJson waterMeterAll(String wmId) {
 | 
| 
 | 
 | 
         ResultJson<Object> resultJson = new ResultJson<>();
 | 
| 
 | 
 | 
         try {
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             List<WaterMeter> waterMeterList = waterMeterMapper.waterMeterAll(wmId);
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             return new ResultJson("200", "success", waterMeterList);
 | 
| 
 | 
 | 
         } catch (Exception e) {
 | 
| 
 | 
 | 
             e.printStackTrace();
 | 
| 
 | 
 | 
             resultJson.setCode("203");
 | 
| 
 | 
 | 
             return resultJson;
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     // 请求返回二维码
 | 
| 
 | 
 | 
     @Override
 | 
| 
 | 
 | 
     public ResultJson qrCode(String payFees, String wmId, String userId, String realName, String eeId) throws UnsupportedEncodingException {
 | 
| 
 | 
 | 
         ResultJson<Object> resultJson = new ResultJson<>();
 | 
| 
 | 
 | 
         // 成功生成水费订单
 | 
| 
 | 
 | 
         if (!"".equals(wmId)) {
 | 
| 
 | 
 | 
             PayRecords payRecords = payRecords(payFees, wmId, userId, realName, "");
 | 
| 
 | 
 | 
             // 请求返回二维码lujing
 | 
| 
 | 
 | 
             String url = QrDemo.orUrl(payRecords.getOrdernumber(), payFees);
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             if (!"".equals(url)) {
 | 
| 
 | 
 | 
                 payRecords.setReamke2(url);
 | 
| 
 | 
 | 
                 // 返回map 包含订单号  二维码url
 | 
| 
 | 
 | 
                 Map<String, Object> map = new HashMap<>();
 | 
| 
 | 
 | 
                 map.put("url", url);
 | 
| 
 | 
 | 
                 map.put("orderNumber", payRecords.getOrdernumber());
 | 
| 
 | 
 | 
                 resultJson.setData(map);
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
             int i = payRecordsMapper.insertSelective(payRecords);
 | 
| 
 | 
 | 
             if (i > 0) {
 | 
| 
 | 
 | 
                 resultJson.setCode("200");
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
         } else {
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             PayRecords payRecords = payRecords(payFees, "", userId, realName, eeId);
 | 
| 
 | 
 | 
             // 请求返回二维码lujing
 | 
| 
 | 
 | 
             String url = QrDemo.orUrl(payRecords.getOrdernumber(), payFees);
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             if (!"".equals(url)) {
 | 
| 
 | 
 | 
                 payRecords.setReamke2(url);
 | 
| 
 | 
 | 
                 // 返回map 包含订单号  二维码url
 | 
| 
 | 
 | 
                 Map<String, Object> map = new HashMap<>();
 | 
| 
 | 
 | 
                 map.put("url", url);
 | 
| 
 | 
 | 
                 map.put("orderNumber", payRecords.getOrdernumber());
 | 
| 
 | 
 | 
                 resultJson.setData(map);
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
             int i = payRecordsMapper.insertSelective(payRecords);
 | 
| 
 | 
 | 
             if (i > 0) {
 | 
| 
 | 
 | 
                 resultJson.setCode("200");
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         return resultJson;
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 总水量 换算
 | 
| 
 | 
 | 
      *
 | 
| 
...
 | 
...
 | 
@@ -250,40 +110,4 @@ public class WaterMeterServiceImp implements WaterMeterService { | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         return datas;
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 订单生成
 | 
| 
 | 
 | 
      *
 | 
| 
 | 
 | 
      * @param payFees
 | 
| 
 | 
 | 
      * @param wmId
 | 
| 
 | 
 | 
      * @param userId
 | 
| 
 | 
 | 
      * @param realName
 | 
| 
 | 
 | 
      * @return
 | 
| 
 | 
 | 
      */
 | 
| 
 | 
 | 
     public PayRecords payRecords(String payFees, String wmId, String userId, String realName, String eeId) {
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         PayRecords payRecords = new PayRecords();
 | 
| 
 | 
 | 
         payRecords.setOrdernumber(AllUtils.getOrderIdByTime());
 | 
| 
 | 
 | 
         payRecords.setPayfees(new BigDecimal(payFees));
 | 
| 
 | 
 | 
         payRecords.setPaystatus(false);
 | 
| 
 | 
 | 
         if (!"".equals(wmId)) {
 | 
| 
 | 
 | 
             payRecords.setPaytype(false);
 | 
| 
 | 
 | 
             payRecords.setPaytypeaddress(wmId);
 | 
| 
 | 
 | 
             String roomNumber = locationMapper.selectRoomNumber(wmId);
 | 
| 
 | 
 | 
             payRecords.setPaylocationname(roomNumber);
 | 
| 
 | 
 | 
         } else {
 | 
| 
 | 
 | 
             payRecords.setPaytype(true);
 | 
| 
 | 
 | 
             payRecords.setPaytypeaddress(eeId);
 | 
| 
 | 
 | 
             String roomNumber = locationMapper.selectRoomNumberElectricity(eeId);
 | 
| 
 | 
 | 
             payRecords.setPaylocationname(roomNumber);
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
         payRecords.setReamke1("0");
 | 
| 
 | 
 | 
         payRecords.setPayuserid(Integer.valueOf(userId));
 | 
| 
 | 
 | 
         payRecords.setPaytime(new Date());
 | 
| 
 | 
 | 
         payRecords.setPayusername(realName);
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         return payRecords;
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 } | 
...
 | 
...
 | 
 |