puzhibing
2026-02-04 0bb2af72f1feb0de80dda046713045bc81949eab
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
package com.ruoyi.jianguan.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient;
import com.ruoyi.chargingPile.api.feignClient.ChargingPileClient;
import com.ruoyi.chargingPile.api.feignClient.SiteClient;
import com.ruoyi.chargingPile.api.model.Site;
import com.ruoyi.chargingPile.api.model.TChargingGun;
import com.ruoyi.chargingPile.api.model.TChargingPile;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.jianguan.dto.*;
import com.ruoyi.jianguan.service.ISiteService;
import com.ruoyi.jianguan.service.TChargingGunService;
import com.ruoyi.jianguan.service.TChargingPileService;
import com.ruoyi.jianguan.util.ChargePileHttpUtil;
import com.ruoyi.order.api.feignClient.ChargingOrderAccountingStrategyClient;
import com.ruoyi.order.api.feignClient.ChargingOrderClient;
import com.ruoyi.order.api.model.TChargingOrder;
import com.ruoyi.order.api.model.TChargingOrderAccountingStrategy;
import com.ruoyi.other.api.domain.Region;
import com.ruoyi.other.api.feignClient.OtherClient;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 站桩枪、订单 临时数据接口
 *
 * @author stylefeng
 * @Date 2018/7/20 23:39
 */
@RestController
@RequestMapping("/chargingPileInfo")
@Slf4j
public class ChargingPileInfoController {
    @Autowired
    private ChargePileHttpUtil chargePileHttpUtil;
 
    @Autowired
    private ChargingOrderAccountingStrategyClient chargingOrderAccountingStrategyClient;
    @Autowired
    private ChargingGunClient chargingGunClient;
    @Autowired
    private ChargingPileClient chargingPileClient;
    @Autowired
    private SiteClient siteClient;
    @Autowired
    private ChargingOrderClient chargingOrderClient;
    @Autowired
    private OtherClient otherClient;
    private static final double EARTH_RADIUS = 6371.0; // 地球半径,单位为千米
 
    /**
     * 计算两点之间的距离,单位为千米
     *
     * @param lat1 第一个点的纬度
     * @param lon1 第一个点的经度
     * @param lat2 第二个点的纬度
     * @param lon2 第二个点的经度
     * @return 两点之间的距离,单位为千米
     */
    public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
        double dLat = Math.toRadians(lat2 - lat1);
        double dLon = Math.toRadians(lon2 - lon1);
 
        lat1 = Math.toRadians(lat1);
        lat2 = Math.toRadians(lat2);
 
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
                Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
 
        return EARTH_RADIUS * c;
    }
 
    /**
     * 司机端-获取充电桩列表
     */
    @ResponseBody
    @PostMapping("/orderList")
    @ApiOperation(value = "获取充电订单", tags = {"司机端-获取充电订单"}, notes = "")
    public R<String> chargingPileList(Integer pageNo, Integer pageSize){
        List<TChargingGun> chargingGun = chargingGunClient.getAllGun().getData();
 
        chargingGun = chargingGun.stream().filter(e->StringUtils.hasLength(e.getConnectorID()))
                .collect(Collectors.toList());
        List<ChargeOrder> result = getOrderList(pageNo, pageSize);
        List<TChargingOrder> orders = new ArrayList<>();
 
        List<TChargingOrderAccountingStrategy> accountingStrategies = new ArrayList<>();
        // 封装订单数据
        for (ChargeOrder chargeOrder : result) {
            TChargingOrder chargingOrder = new TChargingOrder();
            chargingOrder.setOrderType(1);
            chargingOrder.setOrderClassification(1);
            chargingOrder.setAppUserId(1939601394823290882L);
            chargingOrder.setAppUserCarId(2017427572505907202L);
            chargingOrder.setRefundAmount(new BigDecimal(chargeOrder.getTotalMoney()));
            chargingOrder.setRechargeSerialNumber("4200002747202505247686188393");
            chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO);
            chargingOrder.setVipDiscount(BigDecimal.ZERO);
            chargingOrder.setVipDiscountAmount(BigDecimal.ZERO);
            chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO);
            chargingOrder.setCommissionAmount(BigDecimal.ZERO);
            chargingOrder.setSharingAmount(BigDecimal.ZERO);
            chargingOrder.setDelFlag(false);
            chargingOrder.setNeedElec(new BigDecimal(chargeOrder.getTotalPower()));
            chargingOrder.setStartSoc(BigDecimal.ZERO);
            chargingOrder.setEndSoc(new BigDecimal("100"));
            chargingOrder.setPower(new BigDecimal(chargeOrder.getTotalPower()));
            chargingOrder.setElectricity(new BigDecimal(chargeOrder.getTotalPower()));
            chargingOrder.setVoltage(new BigDecimal(chargeOrder.getTotalPower()));
            chargingOrder.setCurrent(new BigDecimal(chargeOrder.getTotalPower()));
            chargingOrder.setChargingPower(new BigDecimal(chargeOrder.getTotalPower()));
            chargingOrder.setChargingCapacity(new BigDecimal(chargeOrder.getTotalPower()));
            chargingOrder.setCode(chargeOrder.getStartChargeSeq());
            chargingOrder.setOrderSource(2);
            chargingOrder.setOperatorId(999);
            chargingOrder.setTripartitePlatformName("途来电");
            chargingOrder.setStartChargeSeq(chargeOrder.getStartChargeSeq());
            chargingOrder.setSourceName("途来电");
            chargingOrder.setStartTime(DateUtils.stringToLocalDateTime(chargeOrder.getStartTime()));
            chargingOrder.setEndTime(DateUtils.stringToLocalDateTime(chargeOrder.getEndTime()));
            chargingOrder.setStatus(5);
            chargingOrder.setEndMode(1);
            chargingOrder.setElectrovalence(new BigDecimal(chargeOrder.getSeviceMoney()).multiply(new BigDecimal("1.19")));
            chargingOrder.setServiceCharge(new BigDecimal(chargeOrder.getSeviceMoney()));
            chargingOrder.setTotalElectricity(new BigDecimal(chargeOrder.getElecMoney()));
            chargingOrder.setPaymentAmount(new BigDecimal(chargeOrder.getTotalMoney()));
            chargingOrder.setRechargePaymentType(1);
            chargingOrder.setRechargePaymentStatus(2);
            chargingOrder.setChargeAmount(new BigDecimal(chargeOrder.getTotalMoney()));
            chargingOrder.setOrderAmount(new BigDecimal(chargeOrder.getTotalMoney()));
            chargingOrder.setResidualAmount(BigDecimal.ZERO);
            chargingOrder.setPaymentAmount(new BigDecimal(chargeOrder.getTotalMoney()));
            chargingOrder.setPayTime(chargingOrder.getStartTime());
            chargingOrder.setCreateTime(chargingOrder.getStartTime());
            if (!StringUtils.hasLength(chargeOrder.getConnectorID())){
                continue;
            }
            // 通过枪编号查询枪
            TChargingGun tChargingGun = chargingGun.stream().filter(e ->chargeOrder.getConnectorID().equals(e.getConnectorID()))
                    .findFirst().orElse(null);
            if(Objects.nonNull(tChargingGun)){
                chargingOrder.setChargingGunId(tChargingGun.getId());
                chargingOrder.setChargingPileId(tChargingGun.getChargingPileId());
                chargingOrder.setSiteId(tChargingGun.getSiteId());
            }else{
                continue;
            }
            R<Long> orderIdR = chargingOrderClient.addChargingOrder(chargingOrder);
            if(orderIdR.getCode() == 200){
                // 充电明细
                List<com.ruoyi.jianguan.dto.ChargeDetail> chargeDetails = chargeOrder.getChargeDetails();
                if(!CollectionUtils.isEmpty(chargeDetails)){
                    List<TChargingOrderAccountingStrategy> accountingStrategyList = new ArrayList<>();
                    for (ChargeDetail chargeDetail : chargeDetails) {
                        TChargingOrderAccountingStrategy accountingStrategy = new TChargingOrderAccountingStrategy();
                        accountingStrategy.setChargingOrderId(orderIdR.getData());
                        accountingStrategy.setAccountingStrategyDetailId(232);
                        accountingStrategy.setType(1);
                        accountingStrategy.setStartTime(chargeDetail.getDetailStartTime());
                        accountingStrategy.setEndTime(chargeDetail.getDetailEndTime());
                        accountingStrategy.setElectrovalence(chargeDetail.getElecPrice());
                        accountingStrategy.setServiceCharge(chargeDetail.getSevicePrice());
                        accountingStrategy.setCostServiceCharge(chargeDetail.getDetailSeviceMoney());
                        accountingStrategy.setChargingCapacity(chargeDetail.getDetailPower());
                        accountingStrategy.setPeriodElectricPrice(chargeDetail.getDetailSeviceMoney().multiply(new BigDecimal("1.19")));
                        accountingStrategy.setCouponDiscountAmount(BigDecimal.ZERO);
                        accountingStrategy.setVipDiscountAmount(BigDecimal.ZERO);
                        accountingStrategy.setPeriodServicePrice(chargeDetail.getDetailSeviceMoney());
                        accountingStrategy.setPeriodOriginalServicePrice(chargeDetail.getDetailSeviceMoney());
                        accountingStrategy.setCreateTime(LocalDateTime.now());
                        accountingStrategyList.add(accountingStrategy);
                    }
                    chargingOrderAccountingStrategyClient.addChargingOrderAccountingStrategy(accountingStrategyList);
                }
            }
        }
 
        return R.ok();
    }
 
    @ResponseBody
    @PostMapping("/chargingPileList")
    @ApiOperation(value = "获取充电桩列表", tags = {"获取充电桩列表"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "电站类型 0=不限 1=公共 50=个人 100=公交 101=环卫(专用) 102=物流(专用) 103=出租车(专用) 255=其他", name = "type", required = false, dataType = "string"),
            @ApiImplicitParam(value = "电站距离 不限=0 1km内=1 2km内=2 3km内=3 5km内=4 10km内=5 50km内=6 100km内=7 ", name = "distance", required = false, dataType = "int"),
            @ApiImplicitParam(value = "设备状态 不限=0 1=只看空闲", name = "status", required = false, dataType = "int"),
            @ApiImplicitParam(value = "电站名称/目标地址", name = "name", required = false, dataType = "string"),
            @ApiImplicitParam(value = "pageNo", name = "pageNo", required = false, dataType = "string"),
            @ApiImplicitParam(value = "pageSize", name = "pageSize", required = false, dataType = "string"),
            @ApiImplicitParam(value = "lon", name = "经度", required = false, dataType = "string"),
            @ApiImplicitParam(value = "lat", name = "纬度", required = false, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public R<String> chargingPileList(String type, Integer distance,
                                      Integer status,
                                      String name,
                                      String lon,
                                      String lat,
                                      Integer pageNo, Integer pageSize){
        PageInfo pageInfo = new PageInfo();
        List<StationInfos> result = getStationInfos();
        // 电站类型
        if (StringUtils.hasLength(type) && (!type.equals("0"))){
            List<Integer> list = Arrays.stream(type.split(",")).map(Integer::parseInt).collect(Collectors.toList());
            result = result.stream().filter(item -> list.contains(item.getStationType())).collect(Collectors.toList());
        }
        // 电站名称/目标地址
        if(StringUtils.hasLength(name)){
            result = result.stream().filter(item -> item.getStationName().contains(name) ||
                    item.getAddress().contains(name)).collect(Collectors.toList());
        }
 
        for (StationInfos stationInfo : result) {
            if (StringUtils.hasLength(lon)){
                double v = calculateDistance(
                        stationInfo.getStationLat(),
                        stationInfo.getStationLng(),
                        Double.parseDouble(lat),
                        Double.parseDouble(lon)
                );
                stationInfo.setDistance(String.valueOf(Math.abs(v)));
            }else {
                stationInfo.setDistance("0");
            }
 
            List<EquipmentInfos> equipmentInfos = stationInfo.getEquipmentInfos();
            int a = 0;
            int b = 0;
            for (EquipmentInfos equipmentInfo : equipmentInfos) {
                if (equipmentInfo.getEquipmentType()==1){
                    a++;
                }
                if (equipmentInfo.getEquipmentType()==2){
                    b++;
                }
            }
            stationInfo.setFastTotal(a);
            stationInfo.setSnowTotal(b);
            stationInfo.setFast(a);
            stationInfo.setSnow(b);
        }
        if(Objects.nonNull(distance) && distance != 0){
            switch (distance){
                case 1:
                    result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 1).collect(Collectors.toList());
                    break;
                case 2:
                    result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 2).collect(Collectors.toList());
                    break;
                case 3:
                    result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 3).collect(Collectors.toList());
                    break;
                case 4:
                    result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 5).collect(Collectors.toList());
                    break;
                case 5:
                    result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 10).collect(Collectors.toList());
                    break;
                case 6:
                    result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 50).collect(Collectors.toList());
                    break;
                case 7:
                    result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 100).collect(Collectors.toList());
                    break;
            }
        }
        List<String> stationIDs = result.stream()
                .map(StationInfos::getStationID)
                .collect(Collectors.toList());
        String obj = chargePileHttpUtil.queryStationStatus(stationIDs);
        JSONObject jsonObject1 = JSONObject.parseObject(obj);
        JSONArray stationStatusInfos = jsonObject1.getJSONArray("StationStatusInfos");
        for (StationInfos stationInfo : result) {
            for (EquipmentInfos equipmentInfo : stationInfo.getEquipmentInfos()) {
                for (ConnectorInfo connectorInfo : equipmentInfo.getConnectorInfos()) {
                    for (Object stationStatusInfo : stationStatusInfos) {
                        JSONObject jsonObject2 = (JSONObject) stationStatusInfo;
                        String stationID = jsonObject2.getString("StationID");
                        JSONArray connectorStatusInfos = jsonObject2.getJSONArray("ConnectorStatusInfos");
                        if (connectorStatusInfos != null) {
                            for (Object connectorStatusInfo : connectorStatusInfos) {
                                JSONObject jsonObject3 = (JSONObject) connectorStatusInfo;
                                String status1 = jsonObject3.getString("ConnectorID");
                                if (connectorInfo.getConnectorID().equals(status1)){
                                    Integer status2 = jsonObject3.getInteger("Status");
                                    if (status2==1){
                                        connectorInfo.setStatus(1);
                                    }else {
                                        connectorInfo.setStatus(2);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        // 电站状态
        if (Objects.nonNull(status) && status == 1) {
            Iterator<StationInfos> iterator1 = result.iterator();
            while (iterator1.hasNext()) {
                StationInfos next = iterator1.next();
                for (Object stationStatusInfo : stationStatusInfos) {
                    JSONObject jsonObject2 = (JSONObject) stationStatusInfo;
                    String stationID = jsonObject2.getString("StationID");
                    if (stationID != null && stationID.equals(next.getStationID())) {
                        JSONArray connectorStatusInfos = jsonObject2.getJSONArray("ConnectorStatusInfos");
                        if (connectorStatusInfos != null) {
                            for (Object connectorStatusInfo : connectorStatusInfos) {
                                JSONObject jsonObject3 = (JSONObject) connectorStatusInfo;
                                Integer status1 = jsonObject3.getInteger("Status");
                                if (status1 != null && status1 == 1) {
                                    break;
                                }else {
                                    iterator1.remove();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        result.sort(Comparator.comparing(StationInfos::getDistance));
        pageInfo.setTotal(result.size());
 
//        List<StationInfos> testing = testing(result.size(), pageNo, pageSize, result);
        Map<String, Region> regionMap = otherClient.listAllRegion().getData()
                .stream().collect(Collectors.toMap(Region::getCode, e -> e));
        Map<Integer, Region> regionIdMap = otherClient.listAllRegion().getData()
                .stream().collect(Collectors.toMap(Region::getId, e -> e));
        List<Site> sites = new ArrayList<>();
        List<TChargingPile> piles = new ArrayList<>();
        List<TChargingGun> guns = new ArrayList<>();
        for (StationInfos stationInfos : result) {
            if (StringUtils.hasLength(stationInfos.getAreaCode())){
                if (stationInfos.getAreaCode().equals("0")){
                    continue;
                }
            }
            Site site = new Site();
            site.setStationID(stationInfos.getStationID());
            site.setPartnerId(26);
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            String dateTime = dateFormat.format(calendar.getTime());
            dateTime = dateTime.substring(2);
            String timestampPart = "" + (Math.random() * 10000) * (System.currentTimeMillis() / 10000);
            timestampPart = timestampPart.replace(".", "").replace("E", "");
            timestampPart = timestampPart.substring(0, 4);
            site.setCode(dateTime+timestampPart);
            site.setName(stationInfos.getStationName());
            site.setSiteType(stationInfos.getStationType());
            site.setBusinessCategory(2);
            site.setStatus(1);
            site.setConstructionSite(1);
            site.setImgUrl("");
            Region region = regionMap.get(stationInfos.getAreaCode());
            if (region!=null){
                site.setDistricts(region.getName());
                site.setDistrictsCode(region.getCode());
                Integer parentId = region.getParentId();
                Region parentRegion = regionIdMap.get(parentId);
                if (parentRegion != null) {
                    site.setCity(parentRegion.getName());
                    site.setCityCode(parentRegion.getCode());
                    Region region1 = regionIdMap.get(parentRegion.getParentId());
                    if (region1!=null){
                        site.setProvince(region1.getName());
                        site.setProvinceCode(region1.getCode());
                    }
                }
            }
            site.setLon(stationInfos.getStationLng()+"");
            site.setLat(stationInfos.getStationLat()+"");
            site.setAddress(stationInfos.getAddress());
//            site.setCountryCode();
            site.setPhone(stationInfos.getServiceTel());
            site.setServicePhone(stationInfos.getServiceTel());
            site.setGuide(stationInfos.getSiteGuide());
            site.setStartServiceTime("24小时");
//            site.setEndServiceTime();
//            site.setServiceDescription();
//            site.setVehicleDescription();
            site.setParkingSpace(stationInfos.getParkNums());
//            site.setRateDescription();
//            site.setSpaceChargeExplain();
            // todo 临时写死一个
            site.setAccountingStrategyId(232);
//            site.setEstablishmentTime();
            site.setSort(180);
//            site.setRemark();
//            site.setMark();
//            site.setAreaCodeCountryside();
            site.setStationClassification(1);
            site.setGeneralApplicationType(1);
            site.setSwapMatchCars(stationInfos.getMatchCars());
            site.setRoundTheClock(1);
            site.setParkType(4);
//            site.setParkFee();
//            site.setParkFeeFree();
            site.setBusinessExpandType(1);
            site.setElectricityType(1);
            site.setCapacity(new BigDecimal("1250"));
            site.setRatedPower(new BigDecimal("1200"));
            site.setPeriodFee(1);
            site.setOfficialRunTime("2025-06-22");
//            site.setStationOrientation();
//            site.setStationArea();
            site.setHavePerson(1);
            site.setVideoMonitor(1);
//            site.setSupportingFacilities();
            site.setPrinterFlag(1);
            site.setBarrierFlag(1);
            site.setParkingLockFlag(1);
//            site.setElectricityFee();
            site.setEquipmentOwnerName("途来电");
            site.setSupplyType(1);
            site.setResidentNo("0110043462");
            site.setWattHourMeterNo("MX01D05054000217");
            site.setForwardPower(new BigDecimal("0"));
            site.setServiceFee("0:00-23:59:\"0.20\"");
            Calendar calendar1 = Calendar.getInstance();
            SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyyMMdd");
            String dateTime1 = dateFormat1.format(calendar1.getTime());
            dateTime1 = dateTime1.substring(2);
            String timestampPart1 = "" + (Math.random() * 10000) * (System.currentTimeMillis() / 10000);
            timestampPart1 = timestampPart1.replace(".", "").replace("E", "");
            timestampPart1 = timestampPart1.substring(0, 4);
            site.setRecordUniqueNo(dateTime+timestampPart);
            site.setPayment(1);
            site.setSupportOrder(1);
//            site.setSerAreaCode();
            site.setIsOpenSynchronization(0);
            site.setIsEnergyStorage(0);
            if (site.getProvince()==null){
                continue;
            }
            Integer siteId = siteClient.addSiteTemp(site).getData();
            sites.add(site);
            int i = 1;
 
            for (EquipmentInfos equipmentInfo : stationInfos.getEquipmentInfos()) {
                TChargingPile chargingPile = new TChargingPile();
                Calendar calendar2 = Calendar.getInstance();
                SimpleDateFormat dateFormat3 = new SimpleDateFormat("yyyyMMddHHmmss");
                String dateTime4 = dateFormat3.format(calendar2.getTime());
                dateTime4 = dateTime4.substring(2);
                String timestampPart5 = "" + (Math.random() * 10000) * (System.currentTimeMillis() / 10000);
                timestampPart5 = timestampPart5.replace(".", "").replace("E", "");
                timestampPart5 = timestampPart5.substring(0, 4);
                chargingPile.setCode(dateTime4+timestampPart5);
                chargingPile.setName(equipmentInfo.getEquipmentName());
                chargingPile.setNumber(i);
                chargingPile.setType(equipmentInfo.getEquipmentType());
                chargingPile.setSiteId(siteId);
                chargingPile.setPartnerId(26);
                chargingPile.setManufacturerCode(equipmentInfo.getManufacturerID());
                chargingPile.setManufacturer(equipmentInfo.getManufacturerName());
                chargingPile.setEquipmentType(equipmentInfo.getEquipmentModel());
                String productionDate = equipmentInfo.getProductionDate();
                if (StringUtils.hasLength(productionDate)){
                    // 转化为LocalDate
                    chargingPile.setProductionDate(LocalDate.parse(productionDate));
                }
                chargingPile.setRatedPower(new BigDecimal(120));
//                chargingPile.setChargingStationNumber();
                chargingPile.setStatus(1);
//                chargingPile.setIotdDeviceId();
                chargingPile.setEquipmentClassification(1);
//                chargingPile.setEquipmentUniqueNumber(equipmentInfo.getEquipmentID());
                chargingPile.setEquipmentLng(equipmentInfo.getEquipmentLng()+"");
                chargingPile.setEquipmentLat(equipmentInfo.getEquipmentLat()+"");
//                chargingPile.setEquipmentProductCode();
                chargingPile.setEquipmentPurpose(1);
                chargingPile.setNewNationalStandard(1);
                chargingPile.setVinFlag(1);
                chargingPile.setName(site.getName()+chargingPile.getNumber()+"号桩");
                Integer pileId = chargingPileClient.addPileTemp(chargingPile).getData();
                piles.add(chargingPile);
                i++;
                int j = 1;
 
                for (ConnectorInfo connectorInfo : equipmentInfo.getConnectorInfos()) {
                    TChargingGun gun = new TChargingGun();
                    gun.setConnectorID(connectorInfo.getConnectorID());
                    gun.setCode(j+"");
                    gun.setSiteId(siteId);
                    gun.setPartnerId(26);
                    gun.setChargingPileId(pileId);
                    gun.setName(connectorInfo.getConnectorName());
                    gun.setType(connectorInfo.getConnectorType());
                    gun.setStatus(2);
                    gun.setChargeMode(connectorInfo.getGunType());
                    // todo 临时写死
                    gun.setAccountingStrategyId(232);
                    gun.setUpperRatedVoltage(new BigDecimal("240"));
                    gun.setLowerLimitOfRatedVoltage(new BigDecimal("200"));
                    gun.setRatedCurrent(new BigDecimal("32"));
                    gun.setRatedPower(new BigDecimal("7"));
                    gun.setChargingPower(new BigDecimal("200"));
                    gun.setParkingNumber("39");
                    gun.setParkingStatus(1);
                    gun.setParkingLockState(0);
                    gun.setNationalStandard("3");
//                    gun.setRemark();
//                    gun.setSoc();
                    gun.setFullNumber(chargingPile.getNumber()+j+"");
                    gun.setEquipmentClassification(1);
                    gun.setConstantVoltageUpperLimits(new BigDecimal("240"));
                    gun.setConstantVoltageLowerLimits(new BigDecimal("200"));
                    gun.setConstantCurrentUpperLimits(new BigDecimal("32"));
                    gun.setConstantCurrentLowerLimits(new BigDecimal("7"));
                    gun.setAuxPower(3);
                    gun.setOpreateStatus(50);
                    gun.setChargeMode(2);
//                    gun.setOpreateHours();
                    guns.add(gun);
                    chargingGunClient.addGunTemp(gun);
                    j++;
 
                }
            }
        }
        log.info("新增的站点数据:{}", sites);
        log.info("新增的桩数据:{}", piles);
        log.info("新增的枪数据:{}", guns);
 
        return R.ok();
    }
 
    private List<StationInfos> getStationInfos(){
        String s = chargePileHttpUtil.queryStationsInfo(1, 199);
        // 将s字符串转化为json 然后转化为实体类PageInfo
        JSONObject jsonObject = JSONObject.parseObject(s);
        com.ruoyi.jianguan.domain.PageInfo pageInfo = JSON.parseObject(jsonObject.toJSONString(), com.ruoyi.jianguan.domain.PageInfo.class);
        List<StationInfos> result = new ArrayList<>();
        int itemSize = pageInfo.getItemSize();
        if(itemSize>199){
            result.addAll(pageInfo.getStationInfos());
            int i = itemSize / 199;
//            int k =1;
            for (int j = 2; j < i + 2; j++) {
                s = chargePileHttpUtil.queryStationsInfo(j, 199);
                // 将s字符串转化为json 然后转化为实体类PageInfo
                jsonObject = JSONObject.parseObject(s);
                pageInfo = JSON.parseObject(jsonObject.toJSONString(), com.ruoyi.jianguan.domain.PageInfo.class);
                result.addAll(pageInfo.getStationInfos());
//                if (k==10){
//                    break;
//                }
//                k++;
            }
        }else {
            result.addAll(pageInfo.getStationInfos());
        }
        return result;
    }
    private List<ChargeOrder> getOrderList(Integer pageNo, Integer pageSize){
 
        String s = chargePileHttpUtil.getOrderList(pageNo, pageSize);
        // 将s字符串转化为json 然后转化为实体类PageInfo
        JSONObject jsonObject = JSONObject.parseObject(s);
        com.ruoyi.jianguan.domain.PageInfo pageInfo = JSON.parseObject(jsonObject.toJSONString(),  com.ruoyi.jianguan.domain.PageInfo.class);
        List<ChargeOrder> result = new ArrayList<>();
        int itemSize = pageInfo.getItemSize();
        int temp =  0;
//        if(itemSize>pageSize){
//            result.addAll(pageInfo.getChargeOrders());
//            int i = itemSize / pageNo;
//            for (int j = 2; j < i + 2; j++) {
//                s = chargePileHttpUtil.getOrderList(j, pageSize);
//                // 将s字符串转化为json 然后转化为实体类PageInfo
//                jsonObject = JSONObject.parseObject(s);
//                pageInfo = JSON.parseObject(jsonObject.toJSONString(),  com.ruoyi.jianguan.domain.PageInfo.class);
//                result.addAll(pageInfo.getChargeOrders());
//                if (temp ==20){
//                    break;
//                }
//                temp++;
//            }
//        }else {
            result.addAll(pageInfo.getChargeOrders());
//        }
        return result;
    }
 
}