正在显示
7 个修改的文件
包含
189 行增加
和
74 行删除
1 | -package com.sunyo.energy.location.controller; | ||
2 | - | ||
3 | -import com.sunyo.energy.location.controller.response.ResultJson; | ||
4 | -import org.springframework.stereotype.Controller; | ||
5 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
6 | - | ||
7 | -@Controller | ||
8 | -@RequestMapping("/electricity") | ||
9 | -public class ElectricityMeterController { | ||
10 | - | ||
11 | -// | ||
12 | -// public ResultJson electricityPay(){ | ||
13 | -// | ||
14 | -// } | ||
15 | - | ||
16 | -} |
1 | package com.sunyo.energy.location.controller; | 1 | package com.sunyo.energy.location.controller; |
2 | 2 | ||
3 | import com.sunyo.energy.location.controller.response.ResultJson; | 3 | import com.sunyo.energy.location.controller.response.ResultJson; |
4 | +import com.sunyo.energy.location.model.ElectricityBalanceThree; | ||
4 | import com.sunyo.energy.location.model.WaterElectricityParameter; | 5 | import com.sunyo.energy.location.model.WaterElectricityParameter; |
6 | +import com.sunyo.energy.location.service.ElectricityMeterService; | ||
5 | import com.sunyo.energy.location.service.WaterElectricityParameterService; | 7 | import com.sunyo.energy.location.service.WaterElectricityParameterService; |
6 | import io.swagger.annotations.ApiOperation; | 8 | import io.swagger.annotations.ApiOperation; |
7 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -14,11 +16,16 @@ import java.util.Date; | @@ -14,11 +16,16 @@ import java.util.Date; | ||
14 | 16 | ||
15 | @RequestMapping("/electricity_meter") | 17 | @RequestMapping("/electricity_meter") |
16 | @Controller | 18 | @Controller |
17 | -public class WaterElectricityParameterController { | 19 | +public class ElectricityParameterController { |
18 | 20 | ||
19 | @Autowired | 21 | @Autowired |
20 | private WaterElectricityParameterService waterElectricityParameterService; | 22 | private WaterElectricityParameterService waterElectricityParameterService; |
21 | 23 | ||
24 | + /** | ||
25 | + * 电表处理远程访问 返回值信息 | ||
26 | + */ | ||
27 | + @Autowired | ||
28 | + ElectricityMeterService electricityMeterService; | ||
22 | 29 | ||
23 | 30 | ||
24 | @ApiOperation(value = "电表参数配置") | 31 | @ApiOperation(value = "电表参数配置") |
@@ -84,4 +91,22 @@ public class WaterElectricityParameterController { | @@ -84,4 +91,22 @@ public class WaterElectricityParameterController { | ||
84 | } | 91 | } |
85 | } | 92 | } |
86 | 93 | ||
94 | + /** | ||
95 | + * 获取电表实施数据 | ||
96 | + * @param eeId | ||
97 | + * @return | ||
98 | + */ | ||
99 | + @RequestMapping(value = "/getEnergyInfoForRealTime") | ||
100 | + @ResponseBody | ||
101 | + public ElectricityBalanceThree getEnergyInfoForRealTime(@RequestParam(value = "eeId", required = false) String eeId){ | ||
102 | + | ||
103 | + try { | ||
104 | + ElectricityBalanceThree energyInfoForRealTime = electricityMeterService.getEnergyInfoForRealTime(eeId); | ||
105 | + return energyInfoForRealTime; | ||
106 | + }catch (Exception e){ | ||
107 | + e.printStackTrace(); | ||
108 | + return null; | ||
109 | + } | ||
110 | + } | ||
111 | + | ||
87 | } | 112 | } |
1 | +package com.sunyo.energy.location.service; | ||
2 | + | ||
3 | +import com.sunyo.energy.location.controller.response.ResultJson; | ||
4 | +import com.sunyo.energy.location.model.ElectricityBalanceThree; | ||
5 | + | ||
6 | +import java.util.Map; | ||
7 | + | ||
8 | +/** | ||
9 | + * @author shenhailong | ||
10 | + * <p> | ||
11 | + * 2020/5/25/16:12 | ||
12 | + */ | ||
13 | +public interface ElectricityMeterService { | ||
14 | + /** | ||
15 | + * 获取电表实时数据 | ||
16 | + * | ||
17 | + * @param deviceId | ||
18 | + * @return | ||
19 | + */ | ||
20 | + ElectricityBalanceThree getEnergyInfoForRealTime(String deviceId) throws Exception; | ||
21 | + | ||
22 | +} |
@@ -16,7 +16,9 @@ public interface WaterMeterService { | @@ -16,7 +16,9 @@ public interface WaterMeterService { | ||
16 | 16 | ||
17 | ResultJson waterMeterAll(String wmId); | 17 | ResultJson waterMeterAll(String wmId); |
18 | 18 | ||
19 | - // 请求返回二维码 | 19 | + /** |
20 | + * 请求返回二维码 | ||
21 | + */ | ||
20 | ResultJson qrCode(String payFees, String wmId, String userId, String realName) throws UnsupportedEncodingException; | 22 | ResultJson qrCode(String payFees, String wmId, String userId, String realName) throws UnsupportedEncodingException; |
21 | 23 | ||
22 | 24 |
1 | package com.sunyo.energy.location.service.imp; | 1 | package com.sunyo.energy.location.service.imp; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | +import com.alibaba.fastjson.JSONArray; | ||
5 | +import com.sunyo.energy.location.controller.response.ResultJson; | ||
4 | import com.sunyo.energy.location.model.*; | 6 | import com.sunyo.energy.location.model.*; |
7 | +import com.sunyo.energy.location.service.ElectricityMeterService; | ||
5 | import com.sunyo.energy.location.utils.HttpsUtils; | 8 | import com.sunyo.energy.location.utils.HttpsUtils; |
9 | +import org.springframework.stereotype.Service; | ||
6 | 10 | ||
11 | +import java.awt.*; | ||
7 | import java.util.HashMap; | 12 | import java.util.HashMap; |
8 | import java.util.List; | 13 | import java.util.List; |
9 | import java.util.Map; | 14 | import java.util.Map; |
10 | 15 | ||
11 | -public class ElectricityMeterServiceImp { | 16 | +@Service |
17 | +public class ElectricityMeterServiceImp implements ElectricityMeterService { | ||
12 | 18 | ||
13 | - // 获取房间与设备信息 | 19 | + /** |
20 | + * 获取房间与设备信息 | ||
21 | + */ | ||
14 | private final static String electricityUrl = "/api/emcs/getRoomAndDevice"; | 22 | private final static String electricityUrl = "/api/emcs/getRoomAndDevice"; |
15 | - // 获取所有电表实时通断电状态 | 23 | + /** |
24 | + * 获取所有电表实时通断电状态 | ||
25 | + */ | ||
16 | private final static String electricityStatus = "/api/emcs/getAllDeviceControlStatus"; | 26 | private final static String electricityStatus = "/api/emcs/getAllDeviceControlStatus"; |
17 | - // 获取电表实时数据/余额 | ||
18 | - private final static String electricityBanlance = " /api/emcs/getEnergyInfoForRealTime"; | 27 | + /** |
28 | + * 获取电表实时数据/余额 | ||
29 | + */ | ||
30 | + private final static String electricityBanlance = "http://192.168.1.2:18080/api/emcs/getEnergyInfoForRealTime"; | ||
19 | 31 | ||
20 | /** | 32 | /** |
21 | * 电费查询 | 33 | * 电费查询 |
@@ -89,9 +101,12 @@ public class ElectricityMeterServiceImp { | @@ -89,9 +101,12 @@ public class ElectricityMeterServiceImp { | ||
89 | public Number balance(String deviceId){ | 101 | public Number balance(String deviceId){ |
90 | 102 | ||
91 | // 获取电表余额 | 103 | // 获取电表余额 |
92 | - String s1 = HttpsUtils.sendPostHttpRequest(electricityBanlance, ""); | 104 | + String s1 = HttpsUtils.sendPostHttpRequest(electricityBanlance, "1"); |
105 | + | ||
93 | ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(s1, ElectricityBalanceOne.class); | 106 | ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(s1, ElectricityBalanceOne.class); |
107 | + | ||
94 | ElectricityBalanceTwo data1 = electricityBalanceOne.getData(); | 108 | ElectricityBalanceTwo data1 = electricityBalanceOne.getData(); |
109 | + | ||
95 | List<ElectricityBalanceThree> electricityBalanceThreeList = data1.getDatas(); | 110 | List<ElectricityBalanceThree> electricityBalanceThreeList = data1.getDatas(); |
96 | for (ElectricityBalanceThree electricityBalanceThree: electricityBalanceThreeList){ | 111 | for (ElectricityBalanceThree electricityBalanceThree: electricityBalanceThreeList){ |
97 | if (deviceId.equals(electricityBalanceThree.getDeviceId())){ | 112 | if (deviceId.equals(electricityBalanceThree.getDeviceId())){ |
@@ -101,4 +116,26 @@ public class ElectricityMeterServiceImp { | @@ -101,4 +116,26 @@ public class ElectricityMeterServiceImp { | ||
101 | return 0; | 116 | return 0; |
102 | } | 117 | } |
103 | 118 | ||
119 | + | ||
120 | + @Override | ||
121 | + public ElectricityBalanceThree getEnergyInfoForRealTime(String deviceId){ | ||
122 | + | ||
123 | + Map<String, Object> datas = new HashMap<>(); | ||
124 | + datas.put("deviceId", "1"); | ||
125 | + try { | ||
126 | + | ||
127 | + String infoForRealTime = HttpsUtils.sendPost(electricityBanlance, datas); | ||
128 | + ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(infoForRealTime, ElectricityBalanceOne.class); | ||
129 | + List<ElectricityBalanceThree> infoForRealTimeList = electricityBalanceOne.getData().getDatas(); | ||
130 | + for (ElectricityBalanceThree electricityBalanceThree: infoForRealTimeList){ | ||
131 | + if (electricityBalanceThree != null){ | ||
132 | + return electricityBalanceThree; | ||
133 | + } | ||
134 | + } | ||
135 | + return null; | ||
136 | + }catch (Exception e){ | ||
137 | + e.printStackTrace(); | ||
138 | + return null; | ||
139 | + } | ||
140 | + } | ||
104 | } | 141 | } |
@@ -2,8 +2,6 @@ package com.sunyo.energy.location.service.imp; | @@ -2,8 +2,6 @@ package com.sunyo.energy.location.service.imp; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | import com.alibaba.fastjson.JSONArray; | 4 | import com.alibaba.fastjson.JSONArray; |
5 | -import com.alibaba.fastjson.JSONObject; | ||
6 | -import com.sun.xml.internal.ws.message.stream.PayloadStreamReaderMessage; | ||
7 | import com.sunyo.energy.location.controller.response.ResultJson; | 5 | import com.sunyo.energy.location.controller.response.ResultJson; |
8 | import com.sunyo.energy.location.dao.LocationMapper; | 6 | import com.sunyo.energy.location.dao.LocationMapper; |
9 | import com.sunyo.energy.location.dao.PayRecordsMapper; | 7 | import com.sunyo.energy.location.dao.PayRecordsMapper; |
@@ -14,13 +12,9 @@ import com.sunyo.energy.location.model.WaterMeter; | @@ -14,13 +12,9 @@ import com.sunyo.energy.location.model.WaterMeter; | ||
14 | import com.sunyo.energy.location.service.WaterMeterService; | 12 | import com.sunyo.energy.location.service.WaterMeterService; |
15 | import com.sunyo.energy.location.utils.AllUtils; | 13 | import com.sunyo.energy.location.utils.AllUtils; |
16 | import com.sunyo.energy.location.utils.HttpsUtils; | 14 | import com.sunyo.energy.location.utils.HttpsUtils; |
17 | -import com.sunyo.energy.location.utils.PropertiesLoader; | ||
18 | -import org.apache.catalina.loader.ParallelWebappClassLoader; | ||
19 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
20 | import org.springframework.scheduling.annotation.Scheduled; | 16 | import org.springframework.scheduling.annotation.Scheduled; |
21 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
22 | - | ||
23 | -import javax.servlet.http.HttpSession; | ||
24 | import java.io.UnsupportedEncodingException; | 18 | import java.io.UnsupportedEncodingException; |
25 | import java.math.BigDecimal; | 19 | import java.math.BigDecimal; |
26 | import java.util.Date; | 20 | import java.util.Date; |
@@ -40,7 +34,9 @@ public class WaterMeterServiceImp implements WaterMeterService { | @@ -40,7 +34,9 @@ public class WaterMeterServiceImp implements WaterMeterService { | ||
40 | 34 | ||
41 | @Autowired | 35 | @Autowired |
42 | private LocationMapper locationMapper; | 36 | private LocationMapper locationMapper; |
43 | - // 查询所有水表 | 37 | + /** |
38 | + * 查询所有水表 | ||
39 | + */ | ||
44 | private static final String selectUrl = "http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyMtId"; | 40 | private static final String selectUrl = "http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyMtId"; |
45 | 41 | ||
46 | private static final String payUrl = "http://123.56.159.203:8023/mtfmset/allWMadd"; | 42 | private static final String payUrl = "http://123.56.159.203:8023/mtfmset/allWMadd"; |
1 | package com.sunyo.energy.location.utils; | 1 | package com.sunyo.energy.location.utils; |
2 | 2 | ||
3 | +import lombok.extern.slf4j.Slf4j; | ||
4 | +import org.apache.http.HttpResponse; | ||
5 | +import org.apache.http.HttpStatus; | ||
6 | +import org.apache.http.client.HttpClient; | ||
7 | +import org.apache.http.client.methods.HttpPost; | ||
8 | +import org.apache.http.client.methods.HttpPut; | ||
9 | +import org.apache.http.client.utils.URLEncodedUtils; | ||
10 | +import org.apache.http.entity.StringEntity; | ||
11 | +import org.apache.http.impl.client.HttpClients; | ||
12 | +import org.apache.http.util.EncodingUtils; | ||
13 | +import org.apache.http.util.EntityUtils; | ||
14 | + | ||
3 | import java.io.*; | 15 | import java.io.*; |
4 | import java.net.HttpURLConnection; | 16 | import java.net.HttpURLConnection; |
5 | import java.net.URL; | 17 | import java.net.URL; |
6 | import java.net.URLConnection; | 18 | import java.net.URLConnection; |
7 | import java.net.URLEncoder; | 19 | import java.net.URLEncoder; |
20 | +import java.nio.charset.Charset; | ||
8 | import java.util.Map; | 21 | import java.util.Map; |
9 | 22 | ||
23 | +@Slf4j | ||
10 | public class HttpsUtils { | 24 | public class HttpsUtils { |
11 | 25 | ||
12 | /** | 26 | /** |
@@ -60,7 +74,7 @@ public class HttpsUtils { | @@ -60,7 +74,7 @@ public class HttpsUtils { | ||
60 | * @return | 74 | * @return |
61 | */ | 75 | */ |
62 | @SuppressWarnings("rawtypes") | 76 | @SuppressWarnings("rawtypes") |
63 | - public static String urlencode(Map<String, Object> data) { | 77 | + public static String urlencode(Map<String, Object> data) throws UnsupportedEncodingException { |
64 | // 将map里的参数变成像 showapi_appid=###&showapi_sign=###&的样子 | 78 | // 将map里的参数变成像 showapi_appid=###&showapi_sign=###&的样子 |
65 | StringBuilder sb = new StringBuilder(); | 79 | StringBuilder sb = new StringBuilder(); |
66 | for (Map.Entry i : data.entrySet()) { | 80 | for (Map.Entry i : data.entrySet()) { |
@@ -68,6 +82,7 @@ public class HttpsUtils { | @@ -68,6 +82,7 @@ public class HttpsUtils { | ||
68 | sb.append(i.getKey()).append("=") | 82 | sb.append(i.getKey()).append("=") |
69 | .append(URLEncoder.encode(i.getValue() + "", "UTF-8")) | 83 | .append(URLEncoder.encode(i.getValue() + "", "UTF-8")) |
70 | .append("&"); | 84 | .append("&"); |
85 | + | ||
71 | } catch (UnsupportedEncodingException e) { | 86 | } catch (UnsupportedEncodingException e) { |
72 | e.printStackTrace(); | 87 | e.printStackTrace(); |
73 | } | 88 | } |
@@ -133,46 +148,80 @@ public class HttpsUtils { | @@ -133,46 +148,80 @@ public class HttpsUtils { | ||
133 | return result; | 148 | return result; |
134 | } | 149 | } |
135 | 150 | ||
136 | - // 测试是否有效 | ||
137 | -// public static void main(String[] args) { | ||
138 | -// // 接口地址 | ||
139 | -// String requestUrl = "http://localhost:8080/manifest/f5f5669bbdecefd3dacfaba194647c35"; | ||
140 | -// try { | ||
141 | -// | ||
142 | -// Map<String, Object> datas = new HashMap<>(); | ||
143 | -// datas.put("de_size", "dcdf38d9a5d6411985e49155481882f5"); | ||
144 | -// datas.put("waybillnomaster", "66611111111"); | ||
145 | -// datas.put("de_type", "001"); | ||
146 | -// datas.put("delivery_station", "001"); | ||
147 | -// datas.put("flightno", "CA9999"); | ||
148 | -// datas.put("flightdate", "2019-9-21 00:00:00"); | ||
149 | -// datas.put("originatingstation", "CGO"); | ||
150 | -// datas.put("destinationstation", "CGO"); | ||
151 | -// datas.put("totalpiece", "19"); | ||
152 | -// datas.put("totalweight", "19"); | ||
153 | -// datas.put("paymode", "PP"); | ||
154 | -// datas.put("customsstatus", "001"); | ||
155 | -// datas.put("customscode", "4604"); | ||
156 | -// datas.put("productname", "SHOUJI"); | ||
157 | -// datas.put("co_company", "测试"); | ||
158 | -// datas.put("co_address", "测试"); | ||
159 | -// datas.put("co_telephone", "00000000"); | ||
160 | -// datas.put("co_country", "CN"); | ||
161 | -// datas.put("sh_company", "测试"); | ||
162 | -// datas.put("sh_address", "测试"); | ||
163 | -// datas.put("sh_country", "CN"); | ||
164 | -// datas.put("sh_telephone", "0000000"); | ||
165 | -// datas.put("sh_city", "测试"); | ||
166 | -// datas.put("USER_ID", "1"); | ||
167 | -// datas.put("reach_station", "CGO"); | ||
168 | -// datas.put("de_volume", "000100003_MMM"); | ||
169 | -// datas.put("de_trstation", "APL,111"); | ||
170 | -// | ||
171 | -// String param ="waybillnomaster=666-11111111&de_volume=66611111111_MMM&de_type=001&delivery_station=001&flightno=CV9765&flightdate=2019-12-20&originatingstation=CGO&destinationstation=ORD&totalpiece=1&totalweight=136.00&paymode=PP&customsstatus=001&customscode=4604&productname=CONSOL&co_company=DSV+AIR+%26+SEA+CO.%2c+LTD&co_address=8%269F%2c+RAFFLES+CITY+CHANGNING+OFFI.+TOWER+3%2c+NO.+1193+CHANGNING+RDSHANG&co_zipcode=200051&shpcusid=&shpaeo=&co_telephone=%2b86+21+33259800&co_country=CN&sh_company=ORD-DSV+AIR++SEA+INC&sh_address=1300+N+ARLINGTON+HEIGHTS+ROAD+SUITE+US&sh_zipcode=60143&cnecusid=&cneaeo=&sh_country=US&sh_telephone=8479568855&sh_fax=&sh_city=CHICAGO&USER_ID=1640&reach_station=ORD&de_trstation=BDX%2c111&de_packing=BDX%2c222&de_remarks=BDX%2c333&de_size=dcdf38d9a5d6411985e49155481882f5"; | ||
172 | -// String ss = HttpsUtils.sendPostHttpRequest(requestUrl, param); | ||
173 | -// JSONArray jsonArray = JSON.parseArray(ss); | ||
174 | -// } catch (Exception e) { | ||
175 | -// e.printStackTrace(); | ||
176 | -// } | ||
177 | -// } | 151 | + /** |
152 | + * 发送POST请求 | ||
153 | + * | ||
154 | + * @param url | ||
155 | + * 目的地址 | ||
156 | + * @param parameters | ||
157 | + * 请求参数,Map类型。 | ||
158 | + * @return 远程响应结果 | ||
159 | + */ | ||
160 | + public static String sendPost(String url, Map<String, Object> parameters) { | ||
161 | + String result = "";// 返回的结果 | ||
162 | + BufferedReader in = null;// 读取响应输入流 | ||
163 | + PrintWriter out = null; | ||
164 | + StringBuffer sb = new StringBuffer();// 处理请求参数 | ||
165 | + String params = "";// 编码之后的参数 | ||
166 | + try { | ||
167 | + // 编码请求参数 | ||
168 | + if (parameters.size() == 1) { | ||
169 | + for (String name : parameters.keySet()) { | ||
170 | + sb.append(name).append("=").append( | ||
171 | + java.net.URLEncoder.encode(parameters.get(name).toString(), | ||
172 | + "UTF-8")); | ||
173 | + } | ||
174 | + params = sb.toString(); | ||
175 | + } else { | ||
176 | + for (String name : parameters.keySet()) { | ||
177 | + sb.append(name).append("=").append( | ||
178 | + java.net.URLEncoder.encode(parameters.get(name).toString(), | ||
179 | + "UTF-8")).append("&"); | ||
180 | + } | ||
181 | + String temp_params = sb.toString(); | ||
182 | + params = temp_params.substring(0, temp_params.length() - 1); | ||
183 | + } | ||
184 | + // 创建URL对象 | ||
185 | + java.net.URL connURL = new java.net.URL(url); | ||
186 | + // 打开URL连接 | ||
187 | + java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL | ||
188 | + .openConnection(); | ||
189 | + // 设置通用属性 | ||
190 | + httpConn.setRequestProperty("Accept", "*/*"); | ||
191 | + httpConn.setRequestProperty("Connection", "Keep-Alive"); | ||
192 | + httpConn.setRequestProperty("User-Agent", | ||
193 | + "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); | ||
194 | + // 设置POST方式 | ||
195 | + httpConn.setDoInput(true); | ||
196 | + httpConn.setDoOutput(true); | ||
197 | + // 获取HttpURLConnection对象对应的输出流 | ||
198 | + out = new PrintWriter(httpConn.getOutputStream()); | ||
199 | + // 发送请求参数 | ||
200 | + out.write(params); | ||
201 | + // flush输出流的缓冲 | ||
202 | + out.flush(); | ||
203 | + // 定义BufferedReader输入流来读取URL的响应,设置编码方式 | ||
204 | + in = new BufferedReader(new InputStreamReader(httpConn | ||
205 | + .getInputStream(), "UTF-8")); | ||
206 | + String line; | ||
207 | + // 读取返回的内容 | ||
208 | + while ((line = in.readLine()) != null) { | ||
209 | + result += line; | ||
210 | + } | ||
211 | + } catch (Exception e) { | ||
212 | + e.printStackTrace(); | ||
213 | + } finally { | ||
214 | + try { | ||
215 | + if (out != null) { | ||
216 | + out.close(); | ||
217 | + } | ||
218 | + if (in != null) { | ||
219 | + in.close(); | ||
220 | + } | ||
221 | + } catch (IOException ex) { | ||
222 | + ex.printStackTrace(); | ||
223 | + } | ||
224 | + } | ||
225 | + return result; | ||
226 | + } | ||
178 | } | 227 | } |
-
请 注册 或 登录 后发表评论