puzhibing
2022-08-22 1421f8e9c308c4741cb396309035009393b5b036
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
package com.stylefeng.guns.modular.system.util;
 
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.common.constant.state.Order;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.dao.CarMapper;
import com.stylefeng.guns.modular.system.dao.ServerCarModelMapper;
import com.stylefeng.guns.modular.system.dao.SystemPriceMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.taxi.model.TransactionDetails;
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
 
/**
 * 上传交通部
 */
@Component
public class PushMinistryOfTransportUtil {
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Autowired
    private HttpClientUtil httpClientUtil;
 
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
 
    @Resource
    private SystemPriceMapper systemPriceMapper;
 
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
 
    @Autowired
    private IOrderCancelService orderCancelService;
 
    @Autowired
    private IDriverService driverService;
 
    @Resource
    private CarMapper carMapper;
 
    @Resource
    private ServerCarModelMapper serverCarModelMapper;
 
    @Autowired
    private ITransactionDetailsService transactionDetailsService;
 
    @Autowired
    private IOrderPositionService orderPositionService;
 
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
    @Autowired
    private IOrderEvaluateService orderEvaluateService;
 
    private String path = "http://120.77.11.218:8868/";
 
 
    /**
     * 乘客基本信息
     * @param uid
     */
    public void baseInfoPassenger(Integer uid){
        UserInfo userInfo = userInfoService.selectById(uid);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("RegisterDate", userInfo.getInsertTime());//注册日期YYYYMMDD
        jsonObject.put("PassengerPhone", userInfo.getPhone());//乘客手机号
        jsonObject.put("PassengerName", userInfo.getNickName());//乘客称谓
        jsonObject.put("PassengerGender", userInfo.getSex() == 1 ? "男" : "女");//乘客性别
        jsonObject.put("State", 0);//状态(0:有效,1:失效)
        jsonObject.put("Flag", 1);//操作标识(1:新增,2:更新,3:删除)
        jsonObject.put("UpdateTime", new Date());
        Map<String, Object> map = new HashMap<>();
        map.put("baseInfoPassenger", jsonObject.toJSONString());
        String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/baseInfoPassenger", map,null,"form");
        System.out.println("乘客基本信息:" + result);
    }
 
 
    /**
     * 订单撤销接口
     * @param orderId
     */
    public void orderCancel(Integer orderId){
        OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
        Driver driver = driverService.selectById(orderPrivateCar.getDriverId());
        OrderCancel query = null;
        try {
            query = orderCancelService.query(orderId, 1, null, null, 2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, String> geocode = null;
        try {
            geocode = gdMapGeocodingUtil.geocode(orderPrivateCar.getBoardingLon().toString(),
                    orderPrivateCar.getBoardingLat().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("Address", Integer.valueOf(geocode.get("districtCode")));//上车地点行政区划代码
        jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单编号
        jsonObject.put("OrderTime", orderPrivateCar.getOrderNum());//订单时间YYYYMMDDhhmmss
        jsonObject.put("CancelTime", query.getInsertTime());//订单撤销时间YYYYMMDDhhmmss
        jsonObject.put("Operator", "1");//撤销发起方(1:乘客,2:驾驶员,3:平台公司)
        jsonObject.put("CancelTypeCode", driver.getDriveCard());//机动车驾驶证编号
        jsonObject.put("CancelReason", query.getReason());//撤销或违约原因
        Map<String, Object> map = new HashMap<>();
        map.put("orderCancel", jsonObject.toJSONString());
        String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/orderCancel", map,null,"form");
        System.out.println("订单撤销接口:" + result);
    }
 
 
    /**
     * 经营支付接口
     * @param orderId
     */
    public void operatePay(Integer orderId){
        OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
        Driver driver = driverService.selectById(orderPrivateCar.getDriverId());
        Map<String, Object> query = systemPriceMapper.query(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId());
        Car car = carMapper.selectById(orderPrivateCar.getCarId());
        ServerCarModel serverCarModel = serverCarModelMapper.selectById(orderPrivateCar.getServerCarModelId());
        TransactionDetails transactionDetails = transactionDetailsService.selectById(new EntityWrapper<TransactionDetails>().eq("orderType", 1).eq("orderId", orderId));
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单号
        jsonObject.put("OnArea", 450204);//上车位置行政区划代码
        jsonObject.put("DriverName", driver.getName());//机动车驾驶员
        jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证号
        jsonObject.put("FareType", query.get("id").toString());//运价类型编码(由网约车公司定义,与运价信息接口保持一街)
        jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌
        jsonObject.put("BookDepTime", orderPrivateCar.getTravelTime());//预计上车时间YYYYMMDDhhmmss
        jsonObject.put("WaitTime", orderPrivateCar.getWait() * 60);//等待时间(秒)
        jsonObject.put("DepLongitude", orderPrivateCar.getBoardingLon());//车辆出发经度
        jsonObject.put("DepLatitude", orderPrivateCar.getBoardingLat());//车辆出发纬度
        jsonObject.put("DepArea", orderPrivateCar.getBoardingAddress());//上车点
        jsonObject.put("DepTime", orderPrivateCar.getBoardingTime());//上车时间YYYYMMDDhhmmss
        jsonObject.put("DestLongitude", orderPrivateCar.getGetoffLon());//车辆到达经度
        jsonObject.put("DestLatitude", orderPrivateCar.getGetoffLat());//车辆到达纬度
        jsonObject.put("DestArea", orderPrivateCar.getGetoffAddress());//下车地点
        jsonObject.put("DestTime", orderPrivateCar.getGetoffTime());//下车时间YYYYMMDDhhmmss
        jsonObject.put("BookModel", serverCarModel.getName());//预定车型
        jsonObject.put("Model", serverCarModel.getName());//实际使用车型
        jsonObject.put("DriveMile", Double.valueOf(orderPrivateCar.getMileage() / 1000).intValue());//载客里程(km)
        jsonObject.put("DriveTime", Double.valueOf((orderPrivateCar.getGetoffTime().getTime() - orderPrivateCar.getBoardingTime().getTime()) / 1000).intValue());//载客时间(秒)
        List<OrderPosition> orderPositions = null;
        try {
            orderPositions = orderPositionService.queryPosition(orderId, 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        int distance = 0;
        if(orderPositions.size() > 0){
            OrderPosition orderPosition = orderPositions.get(0);
            Map<String, String> distance1 = gdMapElectricFenceUtil.getDistance(orderPosition.getLon() + "," + orderPosition.getLat(), orderPrivateCar.getBoardingLon() + "," + orderPrivateCar.getBoardingLat(), 1);
            distance = Integer.valueOf(distance1.get("distance")) / 1000;
        }
        jsonObject.put("WaitMile", distance);//空驶里程(km)
        jsonObject.put("FactPrice", orderPrivateCar.getPayMoney());//实收金额(元)
        jsonObject.put("Price", orderPrivateCar.getOrderMoney());//应收金额(元)
        jsonObject.put("CashPrice", orderPrivateCar.getPayType() == 3 ? orderPrivateCar.getPayMoney() : 0);//现金支付金额(元)
        jsonObject.put("LineName", orderPrivateCar.getPayType() != 3 ? "" : "");//电子支付机构
        jsonObject.put("LinePrice", orderPrivateCar.getPayType() != 3 ? orderPrivateCar.getPayMoney() : 0);//电子支付金额(元)
        jsonObject.put("PosName", "");//POS机支付机构
        jsonObject.put("PosPrice", 0);//POS机支付金额(元)
        jsonObject.put("BenfitPrice", (orderPrivateCar.getRedPacketMoney() == null ? 0 : orderPrivateCar.getRedPacketMoney())
                + (orderPrivateCar.getCouponMoney() == null ? 0 : orderPrivateCar.getCouponMoney())
                + (orderPrivateCar.getDurationMoney() == null ? 0 : orderPrivateCar.getDurationMoney()));//优惠金额(元)
        jsonObject.put("BookTip", 0);//预约服务费(元)
        jsonObject.put("PassengerTip", (orderPrivateCar.getParkMoney() == null ? 0 : orderPrivateCar.getParkMoney())
                + (orderPrivateCar.getRoadTollMoney() == null ? 0 : orderPrivateCar.getRoadTollMoney()));//附加费(元)
        Map<String, Double> map1 = this.setMoney(orderPrivateCar);
        Double amount3 = map1.get("amount3");//其他时间段
        Double amount2 = map1.get("amount2");//高峰时段
        Double amount1 = map1.get("amount1");//夜间时段
        jsonObject.put("PeakUpPrice", null != amount2 ? (amount2 - amount3) : 0);//高峰时段时间加价金额(元)
        jsonObject.put("NightUpPrice", null != amount1 ? (amount1 - amount3) : 0);//夜间时段里程加价金额(元)
        jsonObject.put("FarUpPrice", orderPrivateCar.getLongDistanceMoney() == null ? 0 : orderPrivateCar.getLongDistanceMoney());//远途加价金额(元)
        jsonObject.put("OtherUpPrice", (orderPrivateCar.getDurationMoney() == null ? 0 : orderPrivateCar.getDurationMoney())
                + (orderPrivateCar.getWaitMoney() == null ? 0 : orderPrivateCar.getWaitMoney()));//其他加价金额(元)
        jsonObject.put("PayState", 1);//结算状态(0:未结算,1:已结算,2:未知)
        jsonObject.put("PayTime", null != transactionDetails ? transactionDetails.getInsertTime() : new Date());//乘客结算时间YYYYMMDDhhmmss
        jsonObject.put("OrderMatchTime", null != transactionDetails ? transactionDetails.getInsertTime() : new Date());//订单完成时间YYYYMMDDhhmmss
        jsonObject.put("InvoiceStatus", "0");//发票状态(0:未开票,1:已开票,2:未知)
        Map<String, Object> map = new HashMap<>();
        map.put("operatePay", jsonObject.toJSONString());
        String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/operatePay", map,null,"form");
        System.out.println("经营支付接口:" + result);
    }
 
 
    /**
     * 乘客评价信息
     * @param id
     */
    public void ratedPassenger(Integer id){
        OrderEvaluate orderEvaluate = orderEvaluateService.selectById(id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("OrderId", orderEvaluate.getOrderId());//订单号
        jsonObject.put("EvaluateTime", new Date());//评价时间YYYYMMDDhhmms
        jsonObject.put("ServiceScore", orderEvaluate.getFraction());//服务满意度(五分制)
        jsonObject.put("DriverScore", orderEvaluate.getFraction());//驾驶员满意度(五分制)
        jsonObject.put("VehicleScore", orderEvaluate.getFraction());//车辆满意度(五分制)
        jsonObject.put("Detail", orderEvaluate.getContent());//评价内容
        Map<String, Object> map = new HashMap<>();
        map.put("ratedPassenger", jsonObject.toJSONString());
        String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/ratedPassenger", map,null,"form");
        System.out.println("乘客评价信息:" + result);
    }
 
 
 
    /**
     * 驾驶员信誉信息
     * @param driverId
     */
    public void ratedDriver(Integer driverId){
        Driver driver = driverService.selectById(driverId);
        List<OrderEvaluate> driverId1 = orderEvaluateService.selectList(new EntityWrapper<OrderEvaluate>().eq("driverId", driverId));
        Integer level = 0;
        for(OrderEvaluate orderEvaluate : driverId1){
            level += orderEvaluate.getFraction().intValue();
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证编号
        jsonObject.put("Level", driverId1.size() == 0 ? 0 : level / driverId1.size());//服务质量信誉等级(五分制)
        jsonObject.put("TestDate", new Date());//服务质量信誉考核日期YYYYMMDD
        jsonObject.put("TestDepartment", "广西云森科技有限公司");//服务质量信誉考核机构
        Map<String, Object> map = new HashMap<>();
        map.put("ratedDriver", jsonObject.toJSONString());
        String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/ratedDriver", map,null,"form");
        System.out.println("驾驶员信誉信息:" + result);
    }
 
 
 
 
    /**
     * 计算价格
     * @param orderPrivateCar
     * @return
     * @throws Exception
     */
    private Map<String, Double> setMoney(OrderPrivateCar orderPrivateCar) {
        Map<String, Object> query1 = systemPriceMapper.query(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId());
        Map<String, Double> map = new HashMap<>();
        //开始根据不同的方式计算金额
        double amount1 = 0;
        double amount2 = 0;
        double amount3 = 0;
        JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());
        Double num1 = jsonObject.getDouble("num1");//起步价(元)
        Double num2 = jsonObject.getDouble("num2");//起步公里(公里)
        Double num3 = jsonObject.getDouble("num3");//起步时间(分钟)
        Double num4 = jsonObject.getDouble("num4");//里程费(元)
        Double num5 = jsonObject.getDouble("num5");//时长费(分钟)
        Double num6 = jsonObject.getDouble("num6");//等待费(分钟)
        Double num7 = jsonObject.getDouble("num7");//等待费(元)
        Double num8 = jsonObject.getDouble("num8");//远途费(公里)
        Double num9 = jsonObject.getDouble("num9");//远途费(公里)
        Double num10 = jsonObject.getDouble("num10");//远途费(元)
        Double num11 = jsonObject.getDouble("num11");//远途费(公里)
        Double num12 = jsonObject.getDouble("num12");//远途费(公里)
        Double num13 = jsonObject.getDouble("num13");//远途费(元)
        Double num14 = jsonObject.getDouble("num14");//远途费(公里)
        Double num15 = jsonObject.getDouble("num15");//远途费(元)
        String num16 = jsonObject.getString("num16");//夜间费(开始时间)
        Double num17 = jsonObject.getDouble("num17");//夜间费(元)
        Double num18 = jsonObject.getDouble("num18");//夜间费(元)
        Double num19 = jsonObject.getDouble("num19");//夜间费(元)
        Double num20 = jsonObject.getDouble("num20");//夜间费(元)
        Double num21 = jsonObject.getDouble("num21");//夜间费(元)
        Double num22 = jsonObject.getDouble("num22");//夜间费(元)
        String num23 = jsonObject.getString("num23");//高峰费(开始时间)
        String num24 = jsonObject.getString("num24");//高峰费(开始时间)
        Double num25 = jsonObject.getDouble("num25");//高峰费(元)
        Double num26 = jsonObject.getDouble("num26");//高峰费(元)
        Double num27 = jsonObject.getDouble("num27");//高峰费(元)
        Double num28 = jsonObject.getDouble("num28");//高峰费(元)
        Double num29 = jsonObject.getDouble("num29");//高峰费(元)
        Double num30 = jsonObject.getDouble("num30");//高峰费(元)
 
        Date date = new Date();
        double d = (null == orderPrivateCar.getMileage() ? 0D : orderPrivateCar.getMileage()) / 1000;//实际公里
        double t = ((orderPrivateCar.getEndServiceTime().getTime() - orderPrivateCar.getStartServiceTime().getTime()) / 60000) + 1;//实际时间(不满一分钟按一分钟算)
        double w = ((orderPrivateCar.getStartServiceTime().getTime() - orderPrivateCar.getArriveTime().getTime()) / 60000) + 1;//等待分钟(不满一分钟按一分钟算)
        double d1 = (d - num2) < 0 ? 0 : d - num2;//超出起步里程的公里
        double t1 = (t - num3) < 0 ? 0 : new BigDecimal(t - num3).setScale(0, BigDecimal.ROUND_UP).doubleValue();//超过起步分钟数的时间
        double w1 = (w - num6) < 0 ? 0 : new BigDecimal(w - num6).setScale(0, BigDecimal.ROUND_UP).doubleValue();//超出等待时间的时间
        double yt1 = 0;//远途1段
        double yt2 = 0;//远途2段
        double yt3 = 0;//远途3段
 
 
        //夜间服务处理逻辑
        Calendar s = Calendar.getInstance();
        s.setTime(date);
        s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num16.split(" - ")[0].split(":")[0]));
        s.set(Calendar.MINUTE, Integer.valueOf(num16.split(" - ")[0].split(":")[1]));
 
        Calendar e = Calendar.getInstance();
        e.setTime(date);
        e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num16.split(" - ")[1].split(":")[0]));
        e.set(Calendar.MINUTE, Integer.valueOf(num16.split(" - ")[1].split(":")[1]));
 
        if(date.getTime() > s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){
            if(d > num8.doubleValue() && d <= num9.doubleValue()){
                yt1 = num20 * (d - num8);
            }
            if(d > num9.doubleValue()){
                yt1 = num20 * (num9 - num8);
            }
            if(d > num11.doubleValue() || d <= num12.doubleValue()){
                yt2 = num21 * (d - num11);
            }
            if(d > num12.doubleValue()){
                yt2 = num21 * (num12 - num11);
            }
            if(d > num14.doubleValue()){
                yt3 = num22 * (d - num14);
            }
            amount1 = num17 + (d1 * num18) + (t1 * num19) + (w1 * num7) + yt1 + yt2 + yt3;
            map.put("amount1", amount1);
        }
 
 
        //高峰时段处理逻辑
        Calendar s1 = Calendar.getInstance();
        s1.setTime(date);
        s1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num23.split(" - ")[0].split(":")[0]));
        s1.set(Calendar.MINUTE, Integer.valueOf(num23.split(" - ")[0].split(":")[1]));
 
        Calendar e1 = Calendar.getInstance();
        e1.setTime(date);
        e1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num23.split(" - ")[1].split(":")[0]));
        e1.set(Calendar.MINUTE, Integer.valueOf(num23.split(" - ")[1].split(":")[1]));
 
        Calendar s2 = Calendar.getInstance();
        s2.setTime(date);
        s2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num24.split(" - ")[0].split(":")[0]));
        s2.set(Calendar.MINUTE, Integer.valueOf(num24.split(" - ")[0].split(":")[1]));
 
        Calendar e2 = Calendar.getInstance();
        e2.setTime(date);
        e2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num24.split(" - ")[1].split(":")[0]));
        e2.set(Calendar.MINUTE, Integer.valueOf(num24.split(" - ")[1].split(":")[1]));
 
        if((date.getTime() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())){
            if(d > num8.doubleValue() && d <= num9.doubleValue()){
                yt1 = num28 * (d - num8);
            }
            if(d > num9.doubleValue()){
                yt1 = num28 * (num9 - num8);
            }
            if(d > num11.doubleValue() && d <= num12.doubleValue()){
                yt2 = num29 * (d - num11);
            }
            if(d > num12.doubleValue()){
                yt2 = num29 * (num12 - num11);
            }
            if(d > num14.doubleValue()){
                yt3 = num30 * (d - num14);
            }
            amount2 = num25 + (d1 * num26) + (t1 * num27) + (w1 * num7) + yt1 + yt2 + yt3;
            map.put("amount2", amount2);
        }
 
        //其他时间段的计算
        if(d > num8.doubleValue() && d <= num9.doubleValue()){
            yt1 = num10 * (d - num8);
        }
        if(d > num9.doubleValue()){
            yt1 = num10 * (num9 - num8);
        }
        if(d > num11.doubleValue() && d <= num12.doubleValue()){
            yt2 = num13 * (d - num11);
        }
        if(d > num12.doubleValue()){
            yt2 = num13 * (num12 - num11);
        }
        if(d > num14.doubleValue()){
            yt3 = num15 * (d - num14);
        }
        amount3 = num1 + (d1 * num4) + (t1 * num5) + (w1 * num7) + yt1 + yt2 + yt3;
        map.put("amount3", amount3);
        return map;
    }
}