IRainQueryService.java
9.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package com.rnt.service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.log.Log;
import com.rnt.commo.enums.ErrorType;
import com.rnt.commo.enums.OrderTypeEnum;
import com.rnt.model.park.IrainPknoRelation;
import com.rnt.model.zf.Order;
import com.rnt.model.zf.OrderDetailPark;
import com.rnt.utils.HttpClientTutorial;
import com.rnt.utils.MD5Utils;
import com.rnt.vo.BizResult;
import org.beetl.sql.core.kit.StringKit;
/**
* 艾润费用查询service.<br/>
*
* Copyright: Copyright (c) 2017 zteits
*
* @ClassName: IRainQueryService.java
* @Description:
* @version: v1.0.0
* @author: wangfs
* @date: 2017年6月13日 上午9:25:31
* Modification History:
* Date Author Version Description
* ---------------------------------------------------------*
* 2017年6月13日 wangfs v1.0.0 创建
*/
public class IRainQueryService {
private static final Log logger = Log.getLog(IRainQueryService.class);
/**
* 调用艾润查询费用接口.<br/>
*
* @param carNum
* @param parkCode
* @return
*/
public String billQuery(String carNum, String parkCode) {
logger.info("开始调用查询费用接口,入参={carNum,parkCode}=" + "{" + carNum + "," + parkCode + "}");
//1.查询停车场关系映射表-获取艾润停车场查询费用编码 ztetis-park.irain_pkno_relation
StringBuffer sql = new StringBuffer("select a.irain_pkno1");
sql.append(" from irain_pkno_relation a");
sql.append(" where a.park_lotpkno = ?");
String rs = "";
IrainPknoRelation irainPknoRelation = new IrainPknoRelation().findFirst(sql.toString(), parkCode);
if (irainPknoRelation != null && StringKit.isNotBlank(irainPknoRelation.getIrainPkno1())) {
/**** 以下为模拟入参 实际入参 由app提供-------------------------------------*/
Prop prop = PropKit.use("a_little_config.txt");
Long time = System.currentTimeMillis();
String md5 = MD5Utils.enMD5(prop.get("irain.appid") + prop.get("irain.appsecret") + time);
Map<String, Object> params = new HashMap<>();
params.put("appid", prop.get("irain.appid"));
params.put("sign", md5);
params.put("timestamp", time);
params.put("vpl_number", carNum);
params.put("park_code", irainPknoRelation.getIrainPkno1());
try {
logger.info("irain 查询停车费用入参:" + JSONObject.toJSONString(params));
rs = HttpClientTutorial.httpPostRequest(prop.get("irain.url") + "/bill/Query", params);
logger.info("irain 查询停车费用返回:" + JSONObject.toJSONString(rs));
} catch (Exception e) {
logger.info("irain 查询停车费用出错:" + e);
}
} else {
logger.info("没有查询到艾润查询费用编码");
}
logger.info("结束调用查询费用接口,结果=" + JSONObject.toJSONString(rs));
return JSONObject.toJSON(rs) + "";
}
/***
* 支付完成,停车通过栏杆
*/
public BizResult<String> passHandrail(String orderId) throws Exception {
BizResult<String> bizResult = new BizResult<>();
logger.info(" 支付完成,通知抬杆 ----start--- req=" + orderId);
Order order = Order.dao.findFirst("SELECT * FROM td_b_order t where t.order_id = ?", orderId);
if (null == order) {
logger.info(" 支付完成,通知抬杆 订单不存在 orderId=" + orderId);
bizResult.setErrorMessage(ErrorType.ORDER_NO_EXISTS, "订单不存在");
return bizResult;
}
if (order.getSourceType().equals(OrderTypeEnum.ORDER_SOURCE_TYPE_IN)) {
/**
* 艾润通知
*/
bizResult = passIRail(order.getCarNumber(), order.getParkId(), order.getOrderTotalFee());
logger.info("艾润抬杆通知 返回为: bizResult=" + JSONObject.toJSONString(bizResult));
} else if (order.getSourceType().equals(OrderTypeEnum.ORDER_SOURCE_TYPE_OUT)) {
/**
* 青岛
*/
bizResult = passQD(order);
} else {
logger.info("支付完成,通知抬杆 未知的订单来源类型: orderSourceType=" + order.getSourceType());
bizResult.setErrorMessage(ErrorType.BIZ_ERROR, "未知的订单来源类型");
}
return bizResult;
}
/**
* 艾润抬杆设置
*/
private BizResult<String> passIRail(String vpl_number, String park_code, BigDecimal amount) throws Exception {
BizResult<String> bizResult = new BizResult<>();
//1.查询停车场关系映射表-获取艾润停车场查询费用编码 ztetis-park.irain_pkno_relation
StringBuffer sql = new StringBuffer("select a.irain_pkno1");
sql.append(" from irain_pkno_relation a");
sql.append(" where a.park_lotpkno = ?");
String rs = "";
IrainPknoRelation irainPknoRelation = new IrainPknoRelation().findFirst(sql.toString(), park_code);
if (irainPknoRelation != null && StringKit.isNotBlank(irainPknoRelation.getIrainPkno2())) {
/**** 以下为模拟入参 实际入参 由app提供-------------------------------------*/
Prop prop = PropKit.use("a_little_config.txt");
Long time = System.currentTimeMillis();
String md5 = MD5Utils.enMD5(prop.get("irain.appid") + prop.get("irain.appsecret") + time);
Map<String, Object> params = new HashMap<>();
params.put("appid", prop.get("irain.appid"));
params.put("sign", md5);
params.put("timestamp", time);
params.put("vpl_number", vpl_number);
//要用进出场上报的那个编码
params.put("park_code", irainPknoRelation.getIrainPkno2());
params.put("amount", amount.intValue());
logger.info("开始通知irain 支付已经完成:" + JSONObject.toJSONString(params));
rs = HttpClientTutorial.httpPostRequest(prop.get("irain.url") + "/pay/Issued", params);
logger.info("结束通知irain 支付已经完成::" + rs);
JSONObject result = JSONObject.parseObject(rs);
if ("OK".equals(result.getString("message"))) {
bizResult.setData("通知成功!");
} else {
bizResult.setErrorMessage(ErrorType.BIZ_ERROR, "通知irain 支付已经完成失败!");
}
return bizResult;
} else {
logger.info("没有查询到艾润进出场上报编码");
bizResult.setErrorMessage(ErrorType.BIZ_ERROR, "未查询到艾润进出场上报编码");
return bizResult;
}
}
/**
* 青岛抬杆设置
*/
private BizResult<String> passQD(Order order) throws Exception {
BizResult<String> bizResult = new BizResult<>();
String url = PropKit.get("qd.retrun_fee_url");
OrderDetailPark orderDetailPark = OrderDetailPark.dao.findFirst(
"SELECT * FROM td_b_order_detail_park t where t.order_id = ?", order.getOrderId());
Map<String, Object> params = new HashMap<>();
params.put("orderCode", orderDetailPark.getRecordId());
params.put("amount", order.getOrderTotalFee().intValue());
params.put("orderPay", order.getOrderPayedFee().intValue());
params.put("payType", 1);
logger.info("开始通知irain 支付已经完成:" + JSONObject.toJSONString(params));
String rs = HttpClientTutorial.httpPostRequest(url, JSONObject.toJSONString(params));
logger.info("结束通知irain 支付已经完成:" + rs);
JSONObject result = JSONObject.parseObject(rs);
if ("1".equals(result.getString("status"))) {
bizResult.setData("通知成功!");
} else {
bizResult.setErrorMessage(ErrorType.BIZ_ERROR, "通知青岛 支付已经完成失败!");
}
return bizResult;
}
public static void main(String[] args) {
Prop prop = PropKit.use("a_little_config.txt");
String rs = "";
Long time = System.currentTimeMillis();
String md5 = MD5Utils.enMD5(prop.get("irain.appid") + prop.get("irain.appsecret") + time);
Map<String, Object> params = new HashMap<>();
params.put("appid", prop.get("irain.appid"));
params.put("sign", md5);
params.put("timestamp", time);
params.put("vpl_number", "苏B1B566");
params.put("park_code", "734861a1e8656ffa51bdd90829941ca9");
try {
logger.info("irain 查询停车费用入参:" + JSONObject.toJSONString(params));
rs = HttpClientTutorial.httpPostRequest(prop.get("irain.url") + "/bill/Query", params);
logger.info("irain 查询停车费用返回:" + JSONObject.toJSONString(rs));
} catch (Exception e) {
logger.info("irain 查询停车费用出错:" + e);
}
}
}