Blame view

src/main/java/com/rnt/service/IRainQueryService.java 8.36 KB
e80df919   atao   init
1
2
3
4
5
6
7
  package com.rnt.service;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.beetl.sql.core.kit.StringKit;
  
44ea6641   王富生   提交
8
  import com.alibaba.fastjson.JSON;
e80df919   atao   init
9
10
11
12
13
14
15
  import com.alibaba.fastjson.JSONObject;
  import com.jfinal.kit.Prop;
  import com.jfinal.kit.PropKit;
  import com.jfinal.log.Log;
  import com.rnt.model.park.IrainPknoRelation;
  import com.rnt.utils.HttpClientTutorial;
  import com.rnt.utils.MD5Utils;
44ea6641   王富生   提交
16
  import com.zteits.clouds.api.dto.park.param.RoadsideRequest;
e80df919   atao   init
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
  
  /**
   * 艾润费用查询service.<br/>
   * 
   * Copyright: Copyright (c) 2017  zteits
   * 
   * @ClassName: IRainQueryService.java
   * @Description: 
   * @version: v1.0.0
   * @author: wangfs
   * @date: 2017613   上午9:25:31 
   * Modification History:
   * Date             Author          Version            Description
   *---------------------------------------------------------*
   * 2017613      wangfs           v1.0.0               创建
   */
  public class IRainQueryService {
  	 private static final Log logger = Log.getLog(IRainQueryService.class);
  
  	 /**
  	  * 调用艾润查询费用接口.<br/>
  	  * @param carNum
  	  * @param parkCode
  	  * @return
  	  */
44ea6641   王富生   提交
42
43
  	public Map<String, String> billQuery(String carNum,String parkCode) {
  		logger.info("---begin调用艾润查询费用接口,入参={carNum,parkCode}="+"{"+carNum+","+parkCode+"}");
e80df919   atao   init
44
45
46
47
48
  		//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  = "";
44ea6641   王富生   提交
49
  		Map<String, String> map = new HashMap<String, String>();
e80df919   atao   init
50
  		IrainPknoRelation irainPknoRelation = new IrainPknoRelation().findFirst(sql.toString(), parkCode);
44ea6641   王富生   提交
51
  		logger.info("获取查询费用编码数据结果="+JSONObject.toJSON(irainPknoRelation));
e80df919   atao   init
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  		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));
44ea6641   王富生   提交
68
69
70
71
72
73
  				 if (StringKit.isNotBlank(rs) && !"NO_PARK_RECORD".equals(JSONObject.parseObject(rs).get("code"))) {
  			         map = this.jsonToMapForIrunResult(rs);
  				 }else{
  					 logger.info("调用艾润费用查询接口:无停车记录");
  				 }
  				
e80df919   atao   init
74
75
76
77
78
79
80
  			} catch (Exception e) {
  				logger.info("irain 查询停车费用出错:" + e);
  			}
  		}else{
  			logger.info("没有查询到艾润查询费用编码");
  		}
  		 
44ea6641   王富生   提交
81
  		logger.info("---end调用艾润查询费用接口,结果="+JSONObject.toJSON(map));
e80df919   atao   init
82
83
  		
  	
44ea6641   王富生   提交
84
  		return map;
e80df919   atao   init
85
  	}
e5b4babd   王富生   提交
86
  	
44ea6641   王富生   提交
87
88
89
90
91
92
93
  	/**
  	 * 青岛路侧费用查询接口.<br/>
  	 * @param recordId
  	 * @return
  	 */
  	public static Map<String, String> queryBillRoadside(String recordId){
  		logger.info("---begin调用青岛路侧费用查询接口,入参={recordId}="+"{"+recordId+"}");
e5b4babd   王富生   提交
94
  		Prop prop = PropKit.use("a_little_config.txt");
44ea6641   王富生   提交
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
  		Map<String, Object> params = new HashMap<>();
  		 Long time = System.currentTimeMillis();
  		params.put("orderCode", recordId);
  		params.put("timestamp",time);
  		Map<String, String> rsMap = new HashMap<String, String>();
  		try{
  			String qingdaors = HttpClientTutorial.httpPostRequest(prop.get("qindao.url")+"", JSONObject.toJSONString(params));
  			logger.info("青岛路侧查询停车费用返回:" + JSONObject.toJSONString(qingdaors));
  			RoadsideRequest roadsideRequest = JSONObject.parseObject(qingdaors,RoadsideRequest.class);
  			logger.info("青岛路侧返回JSON转换对象结果"+JSONObject.toJSON(roadsideRequest));
  			if(roadsideRequest != null){
  				rsMap.put("record_id", roadsideRequest.getOrderCode());
  				// 出场时间
  				rsMap.put("park_out_time", roadsideRequest.getOuttime());
  				//入场时间
  				rsMap.put("park_in_time", roadsideRequest.getIntime());
  				//总费用
  				rsMap.put("order_total_fee", roadsideRequest.getOrderPay() != null ? roadsideRequest.getOrderPay().toString() :"1");
                  //已付费用
  				rsMap.put("order_payed_fee", "0");
                  //未支付费用(本次应付金额)
  				rsMap.put("order_not_pay_fee", roadsideRequest.getOrderPay() != null ? roadsideRequest.getOrderPay().toString() :"1");
  				//停车时长  单位:秒
  				rsMap.put("parking_duration",roadsideRequest.getStaytime() != null ? String.valueOf(roadsideRequest.getStaytime()) :"1");
  				//停车场名车
  				rsMap.put("park_name", roadsideRequest.getParkName());
  			}
  			
  		}catch (Exception e) {
  			e.printStackTrace();
  		}
  		logger.info("---end调用青岛路侧费用查询接口,结果="+JSONObject.toJSON(rsMap));
  		return rsMap;
  	}
  	
  	
  	/**
       * 获取查询费用返回结果.<br/>
       *
       * @param json
       * @return
       */
      private static Map<String, String> jsonToMapForIrunResult(String json) {
  
          JSONObject jsobj = JSONObject.parseObject(json);
          Map<String, String> map = new HashMap<String, String>();
          if (jsobj != null) {
              if (!jsobj.get("status").toString().equals("0")) {
                  JSONObject data = (JSONObject)jsobj.get("data");
                  // 出场时间对象
                  JSONObject parkOutObject = (JSONObject)data.get("out");
                  //停车记录id
                  map.put("record_id", data.getString("id"));
                  // 出场时间
                  map.put("park_out_time", parkOutObject.getString("time"));
                  if (data.get("park") != null) {
                      map.put("park_name", JSONObject.parseObject(data.get("park").toString()).get("name") + "");
                      map.put("park_address", JSONObject.parseObject(data.get("park").toString()).get("address") + "");
                  }
  
                  //入场时间
                  if (data.get("in") != null) {
                      map.put("park_in_time", JSONObject.parseObject(data.get("in").toString()).getString("time"));
                  }
                  //总费用
                  map.put("order_total_fee", JSONObject.parseObject(data.get("charge").toString()).getString("due"));
                  //已付费用
                  map.put("order_payed_fee", JSONObject.parseObject(data.get("charge").toString()).getString("paid"));
                  //未支付费用(本次应付金额)
                  map.put("order_not_pay_fee", JSONObject.parseObject(data.get("charge").toString()).getString("unpaid"));
                  //停车时长  单位:秒
                  map.put("parking_duration",
                      JSONObject.parseObject(data.get("charge").toString()).getString("duration"));
              }
          }
          return map;
      }
      
      public static void main(String[] args) {
      	/**Map<String, String> map = new HashMap<String, String>();
      	Prop prop = PropKit.use("a_little_config.txt");
e5b4babd   王富生   提交
176
177
178
179
180
181
  	    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);
44ea6641   王富生   提交
182
  		params.put("vpl_number", "苏BV291U");
e5b4babd   王富生   提交
183
  		params.put("park_code", "734861a1e8656ffa51bdd90829941ca9");
44ea6641   王富生   提交
184
  		String rs = "";
e5b4babd   王富生   提交
185
186
187
188
  		try {
  			logger.info("irain 查询停车费用入参:" + JSONObject.toJSONString(params));
  			 rs = HttpClientTutorial.httpPostRequest(prop.get("irain.url")+"/bill/Query", params);
  			logger.info("irain 查询停车费用返回:" + JSONObject.toJSONString(rs));
44ea6641   王富生   提交
189
190
191
192
193
194
195
196
  			 if (StringKit.isNotBlank(rs) && !"NO_PARK_RECORD".equals(JSONObject.parseObject(rs).get("code"))) {
  		        System.out.println(rs);
  		        map = jsonToMapForIrunResult(rs);
  		        System.out.println("------"+JSONObject.toJSON(map));
  			 }else{
  				 logger.info("调用艾润费用查询接口:无停车记录");
  			 }
  			
e5b4babd   王富生   提交
197
198
  		} catch (Exception e) {
  			logger.info("irain 查询停车费用出错:" + e);
44ea6641   王富生   提交
199
200
  		}*/
  	    queryBillRoadside("101332467802357239808");
e5b4babd   王富生   提交
201
  	}
e80df919   atao   init
202
  }