longz
2026-07-29 607e4ab169b003991ed4788c9dbe0bd1fefc69f3
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
package com.ruoyi.chargingPile.service.impl;
 
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.feignClient.AppUserClient;
import com.ruoyi.account.api.feignClient.AppUserVipDetailClient;
import com.ruoyi.account.api.model.TAppUser;
import com.ruoyi.account.api.model.TAppUserVipDetail;
import com.ruoyi.account.api.vo.GetAppUserVipDetail;
import com.ruoyi.chargingPile.api.dto.GetSiteListDTO;
import com.ruoyi.chargingPile.api.model.*;
import com.ruoyi.chargingPile.api.query.GetSiteList;
import com.ruoyi.chargingPile.api.query.SiteDetailQuery;
import com.ruoyi.chargingPile.api.query.SiteQuery;
import com.ruoyi.chargingPile.api.vo.SiteDetailVO;
import com.ruoyi.chargingPile.api.vo.SiteVO;
import com.ruoyi.chargingPile.api.domain.SiteMenu;
import com.ruoyi.chargingPile.dto.SiteExcelDTO;
import com.ruoyi.chargingPile.dto.SiteImportErrorDTO;
import com.ruoyi.chargingPile.dto.SiteImportResultDTO;
import com.ruoyi.chargingPile.mapper.SiteMapper;
import com.ruoyi.chargingPile.service.*;
import com.ruoyi.chargingPile.util.UUIDUtil;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.integration.api.elutong.model.*;
import com.ruoyi.integration.api.feignClient.*;
import com.ruoyi.other.api.domain.TVip;
import com.ruoyi.other.api.domain.Region;
import com.ruoyi.other.api.feignClient.OtherClient;
import com.ruoyi.other.api.feignClient.RoleSiteClient;
import com.ruoyi.other.api.feignClient.UserSiteClient;
import com.ruoyi.other.api.feignClient.VipClient;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import com.ruoyi.system.api.feignClient.SysUserRoleClient;
import com.ruoyi.system.api.model.SysUserRoleVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.InputStream;
import java.math.BigDecimal;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @Date 2024/8/7 19:54
 */
@Slf4j
@Service
public class SiteServiceImpl extends ServiceImpl<SiteMapper, Site> implements ISiteService {
 
    static final int SITE_IMPORT_TITLE_ROWS = 1;
    
    @Resource
    private TChargingGunService chargingGunService;
    
    @Resource
    private TChargingPileService chargingPileService;
    
    @Resource
    private SysUserClient sysUserClient;
    
    @Resource
    private IPartnerService partnerService;
    
    @Resource
    private UserSiteClient userSiteClient;
    
    @Resource
    private RoleSiteClient roleSiteClient;
    @Resource
    private OtherClient otherClient;
    @Resource
    private TokenService tokenService;
    @Resource
    private AppUserClient appUserClient;
    @Resource
    private SysUserRoleClient sysUserRoleClient;
    @Resource
    private TParkingLotService parkingLotService;
    
    @Resource
    private IntegrationClient integrationClient;
    @Resource
    private AppUserVipDetailClient vipDetailClient;
    
    @Resource
    private TAccountingStrategyDetailService accountingStrategyDetailService;
    @Resource
    private TAccountingStrategyService accountingStrategyService;
    
    @Resource
    private TPartnerSiteService partnerSiteService;
    
    @Resource
    private TCECClient tcecClient;
 
    @Resource ELuTongClient eLuTongClient;
 
    @Resource
    private ChengDuJianGuanClient chengDuJianGuanClient;
    @Resource
    private DongFuStationClient dongFuStationClient;
 
    
    /**
     * 获取站点管理列表数据
     * @param siteList
     * @return
     */
 
    @Override
    public PageInfo<GetSiteListDTO> getSiteList(GetSiteList siteList) {
        Set<Integer> ids = null;
        //校验合作商权限
        SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData();
        Integer roleType = sysUser.getRoleType();
        Integer objectId = sysUser.getObjectId();
        R<Integer> admin = sysUserClient.isAdmin(tokenService.getLoginUser().getUserid());
        //合作商
        if(roleType == 2){
            ids = partnerService.authSite(objectId, SiteMenu.SITE_LIST);
        }else{
            //非管理员需要根据角色和用户配置查询允许的站点数据
            //改用roleId=1来判断
            if(admin.getData()!=1){
                ids = getAssignedSiteIds(sysUser.getUserId());
            }
        }
        PageInfo<GetSiteListDTO> pageInfo = new PageInfo<>(siteList.getPageCurr(), siteList.getPageSize());
        List<GetSiteListDTO> list = this.baseMapper.getSiteList(pageInfo, siteList, ids);
        for (GetSiteListDTO getSiteListDTO : list) {
            Integer siteId = getSiteListDTO.getId();
            getSiteListDTO.setAuthAccountingStrategy(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.SITE_ACCOUNTING_STRATEGY));
            //平台账号才有此权限
            getSiteListDTO.setAuthPartner(roleType == 1 ? true : false);
            getSiteListDTO.setAuthUpdate(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.SITE_UPDATE));
            getSiteListDTO.setAuthDelete(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.SITE_DELETE));
        }
        return pageInfo.setRecords(list);
    }
 
    @Override
    public List<Site> listSitesForExport(GetSiteList siteList) {
        siteList.setPageCurr(1);
        siteList.setPageSize(100000);
        List<Integer> ids = getSiteList(siteList).getRecords().stream()
                .map(GetSiteListDTO::getId)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        return ids.isEmpty() ? Collections.emptyList() : listByIds(ids);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public SiteImportResultDTO importSites(MultipartFile file, Boolean cover) throws Exception {
        if (file == null || file.isEmpty()) {
            throw new ServiceException("请选择要导入的Excel文件");
        }
        ExcelUtil<SiteExcelDTO> util = new ExcelUtil<>(SiteExcelDTO.class);
        List<SiteExcelDTO> rows;
        try (InputStream inputStream = file.getInputStream()) {
            rows = util.importExcel(inputStream, SITE_IMPORT_TITLE_ROWS);
        } catch (Exception e) {
            log.error("站点Excel解析失败,fileName={},size={}", file.getOriginalFilename(), file.getSize(), e);
            ServiceException exception = new ServiceException("Excel文件已损坏或格式不正确,请重新下载站点导入模板后填写")
                    .setDetailMessage(e.getMessage());
            exception.initCause(e);
            throw exception;
        }
        if (rows == null || rows.isEmpty()) {
            throw new ServiceException("导入文件没有数据");
        }
 
        SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData();
        Integer roleType = sysUser.getRoleType();
        Integer objectId = sysUser.getObjectId();
        Map<String, Partner> partnerMap = partnerService.list(new LambdaQueryWrapper<Partner>().eq(Partner::getDelFlag, 0)).stream()
                .filter(item -> StringUtils.isNotEmpty(item.getName()))
                .collect(Collectors.toMap(item -> normalizeImportValue(item.getName()), item -> item, (a, b) -> a));
        List<TAccountingStrategy> strategies = accountingStrategyService.list(
                new LambdaQueryWrapper<TAccountingStrategy>().eq(TAccountingStrategy::getDelFlag, 0));
        Map<String, TAccountingStrategy> strategyMap = strategies.stream().filter(item -> StringUtils.isNotEmpty(item.getName()))
                .collect(Collectors.toMap(item -> normalizeImportValue(item.getName()), item -> item, (a, b) -> a));
        List<Region> regions = otherClient.listAllRegion().getData();
        if (regions == null) {
            regions = Collections.emptyList();
        }
        Map<String, Region> regionByCode = regions.stream().filter(item -> StringUtils.isNotEmpty(item.getCode()))
                .collect(Collectors.toMap(Region::getCode, item -> item, (a, b) -> a));
        Map<Integer, Region> regionById = regions.stream().filter(item -> item.getId() != null)
                .collect(Collectors.toMap(Region::getId, item -> item, (a, b) -> a));
 
        SiteImportResultDTO result = new SiteImportResultDTO();
        List<Site> validRows = new ArrayList<>();
        Set<String> fileCodes = new HashSet<>();
        Set<String> duplicateCodes = new LinkedHashSet<>();
        for (int i = 0; i < rows.size(); i++) {
            SiteExcelDTO row = rows.get(i);
            int rowNum = i + SITE_IMPORT_TITLE_ROWS + 2;
            List<String> errors = validateSiteImportRow(row, partnerMap, strategyMap, regionByCode, regionById,
                    roleType, objectId, fileCodes);
            String code = row == null ? null : normalizeImportValue(row.getCode());
            if (!errors.isEmpty()) {
                result.getErrorMessage().add(new SiteImportErrorDTO(rowNum, code, String.join(";", errors)));
                continue;
            }
            Site site = buildImportedSite(row, partnerMap, strategyMap, regionByCode, regionById);
            Site exists = getOne(new LambdaQueryWrapper<Site>().eq(Site::getCode, site.getCode()).eq(Site::getDelFlag, 0));
            if (exists != null) {
                duplicateCodes.add(site.getCode());
                site.setId(exists.getId());
                site.setMark(exists.getMark());
            }
            validRows.add(site);
        }
        result.setErrorCount(result.getErrorMessage().size());
        if (result.getErrorCount() > 0) {
            return result;
        }
        if (!duplicateCodes.isEmpty() && !Boolean.TRUE.equals(cover)) {
            result.setNeedConfirm(true);
            result.setDuplicateCodes(new ArrayList<>(duplicateCodes));
            return result;
        }
        for (Site site : validRows) {
            site.setDelFlag(false);
            if (site.getId() == null) {
                site.setMark(0);
                save(site);
                result.setSuccessCount(result.getSuccessCount() + 1);
            } else {
                updateById(site);
                result.setUpdateCount(result.getUpdateCount() + 1);
            }
        }
        return result;
    }
 
    private List<String> validateSiteImportRow(SiteExcelDTO row, Map<String, Partner> partnerMap,
            Map<String, TAccountingStrategy> strategyMap, Map<String, Region> regionByCode, Map<Integer, Region> regionById,
            Integer roleType, Integer objectId, Set<String> fileCodes) {
        List<String> errors = new ArrayList<>();
        if (row == null) {
            errors.add("空行");
            return errors;
        }
        String code = normalizeImportValue(row.getCode());
        String partnerName = normalizeImportValue(row.getPartnerName());
        Partner partner = partnerMap.get(partnerName);
        if (StringUtils.isEmpty(partnerName)) errors.add("归属合作商/服务商不能为空");
        else if (partner == null || !Arrays.asList(1, 3).contains(partner.getPartnerType())) errors.add("归属合作商/服务商不存在");
        else if (Integer.valueOf(2).equals(roleType) && !Objects.equals(objectId, partner.getId())) errors.add("无权导入其他合作商/服务商站点");
        if (StringUtils.isNotEmpty(row.getVenuePartnerName())) {
            Partner venue = partnerMap.get(normalizeImportValue(row.getVenuePartnerName()));
            if (venue == null || !Integer.valueOf(2).equals(venue.getPartnerType())) errors.add("场地方不存在");
        }
        if (StringUtils.isEmpty(code)) errors.add("站点编号不能为空");
        else if (!fileCodes.add(code)) errors.add("导入文件内站点编号重复");
        if (StringUtils.isEmpty(row.getName())) errors.add("站点名称不能为空");
        if (row.getSiteType() == null) errors.add("站点类型不能为空");
        if (row.getBusinessCategory() == null) errors.add("经营类别不能为空");
        if (row.getStatus() == null) errors.add("站点状态不能为空");
        if (row.getConstructionSite() == null) errors.add("建设场所不能为空");
        if (row.getTransformerPower() == null) errors.add("变压器功率不能为空");
        if (row.getMemberDiscountFlag() == null) errors.add("是否参与会员折扣不能为空");
        if (StringUtils.isEmpty(row.getAreaCode()) || !regionByCode.containsKey(row.getAreaCode().trim())) {
            errors.add("所在区域行政区划代码不存在");
        } else {
            Region district = regionByCode.get(row.getAreaCode().trim());
            Region city = regionById.get(district.getParentId());
            Region province = city == null ? null : regionById.get(city.getParentId());
            if (city == null || province == null) errors.add("所在区域必须填写区县级行政区划代码");
        }
        if (StringUtils.isEmpty(row.getAddress())) errors.add("详细地址不能为空");
        if (StringUtils.isEmpty(row.getLon())) errors.add("经度不能为空");
        if (StringUtils.isEmpty(row.getLat())) errors.add("纬度不能为空");
        if (StringUtils.isEmpty(row.getCountryCode())) errors.add("充电站国家代码不能为空");
        if (StringUtils.isEmpty(row.getPhone())) errors.add("站点电话不能为空");
        if (StringUtils.isEmpty(row.getServicePhone())) errors.add("服务电话不能为空");
        if (row.getParkingSpace() == null) errors.add("车位数量不能为空");
        if (StringUtils.isEmpty(row.getRateDescription())) errors.add("充电电费描述不能为空");
        if (row.getSort() == null) errors.add("排序不能为空");
        if (row.getStationClassification() == null) errors.add("电站分类不能为空");
        if (row.getRoundTheClock() == null) errors.add("7*24小时营业不能为空");
        if (row.getParkType() == null) errors.add("停车费类型不能为空");
        if (row.getElectricityType() == null) errors.add("电费类型不能为空");
        if (row.getBusinessExpandType() == null) errors.add("报装类型不能为空或填写不正确,请填写独立报装或非独立报装");
        if (row.getCapacity() == null) errors.add("报装电源容量不能为空");
        if (row.getRatedPower() == null) errors.add("站点额定总功率不能为空");
        if (row.getPeriodFee() == null) errors.add("是否峰谷分时不能为空");
        if (StringUtils.isEmpty(row.getOfficialRunTime())) errors.add("正式投运时间不能为空");
        if (row.getVideoMonitor() == null) errors.add("视频监控配套情况不能为空");
        if (StringUtils.isEmpty(row.getEquipmentOwnerName())) errors.add("设备所属方名称不能为空");
        if (StringUtils.isEmpty(row.getResidentNo())) errors.add("供电局用户编号不能为空");
        if (row.getSupplyType() == null) errors.add("供电类型不能为空");
        if (StringUtils.isEmpty(row.getWattHourMeterNo())) errors.add("表号不能为空");
        if (row.getForwardPower() == null) errors.add("外电功率不能为空");
        if (StringUtils.isEmpty(row.getServiceFee())) errors.add("服务费描述不能为空");
        if (StringUtils.isEmpty(row.getRecordUniqueNo())) errors.add("充电站全省唯一备案号不能为空");
        if (StringUtils.isNotEmpty(row.getAccountingStrategyName()) && !strategyMap.containsKey(normalizeImportValue(row.getAccountingStrategyName()))) errors.add("计费模板不存在");
        if (StringUtils.isNotEmpty(row.getEstablishmentTime())) {
            try { java.time.LocalDateTime.parse(row.getEstablishmentTime().trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); }
            catch (Exception e) { errors.add("建站时间格式应为yyyy-MM-dd HH:mm:ss"); }
        }
        return errors;
    }
 
    private Site buildImportedSite(SiteExcelDTO row, Map<String, Partner> partnerMap,
            Map<String, TAccountingStrategy> strategyMap, Map<String, Region> regionByCode,
            Map<Integer, Region> regionById) {
        Site site = new Site();
        BeanUtils.copyProperties(row, site);
        site.setCode(normalizeImportValue(row.getCode()));
        site.setName(normalizeImportValue(row.getName()));
        site.setPartnerId(partnerMap.get(normalizeImportValue(row.getPartnerName())).getId());
        if (StringUtils.isNotEmpty(row.getVenuePartnerName())) {
            site.setVenuePartnerId(partnerMap.get(normalizeImportValue(row.getVenuePartnerName())).getId());
        }
        if (StringUtils.isNotEmpty(row.getAccountingStrategyName())) {
            site.setAccountingStrategyId(strategyMap.get(normalizeImportValue(row.getAccountingStrategyName())).getId());
        }
        Region district = regionByCode.get(row.getAreaCode().trim());
        Region city = regionById.get(district.getParentId());
        Region province = city == null ? null : regionById.get(city.getParentId());
        site.setDistricts(district.getName());
        site.setDistrictsCode(district.getCode());
        if (city != null) {
            site.setCity(city.getName());
            site.setCityCode(city.getCode());
        }
        if (province != null) {
            site.setProvince(province.getName());
            site.setProvinceCode(province.getCode());
        }
        if (StringUtils.isNotEmpty(row.getEstablishmentTime())) {
            site.setEstablishmentTime(java.time.LocalDateTime.parse(row.getEstablishmentTime().trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }
        site.setImgUrl("");
        return site;
    }
 
    private String normalizeImportValue(String value) {
        return value == null ? null : value.trim();
    }
 
 
 
 
    @Override
    public PageInfo<GetSiteListDTO> getSiteList1(Long userId) {
        Set<Integer> ids = null;
        SysUser sysUser = sysUserClient.getSysUser(userId).getData();
        Integer roleType = sysUser.getRoleType();
        Integer partnerId = null;
 
        if(roleType == 2){
            partnerId = sysUser.getObjectId();
        }else{
            R<Integer> admin = sysUserClient.isAdmin(userId);
            if(admin.getData()!=1){
                ids = getAssignedSiteIds(sysUser.getUserId());
                if (ids.isEmpty()) {
                    ids.add(-1);
                }
            }
        }
        PageInfo<GetSiteListDTO> pageInfo = new PageInfo<>(1, 9999);
        return pageInfo.setRecords(this.baseMapper.getSiteOptions(ids, partnerId));
    }
 
    private Set<Integer> getAssignedSiteIds(Long userId) {
        Set<Integer> siteIds = new HashSet<>();
        if (userId == null) {
            return siteIds;
        }
        R<List<Integer>> userSiteResult = userSiteClient.getSiteIds(userId);
        if (userSiteResult != null && userSiteResult.getData() != null) {
            siteIds.addAll(userSiteResult.getData());
        }
        R<List<SysUserRoleVo>> roleResult = sysUserRoleClient.getRoleByUserId(userId);
        if (roleResult != null && roleResult.getData() != null) {
            for (SysUserRoleVo role : roleResult.getData()) {
                if (role == null || role.getRoleId() == null) {
                    continue;
                }
                R<List<Integer>> roleSiteResult = roleSiteClient.getSiteIds(role.getRoleId());
                if (roleSiteResult != null && roleSiteResult.getData() != null) {
                    siteIds.addAll(roleSiteResult.getData());
                }
            }
        }
        return siteIds;
    }
 
 
 
 
    /**
     * 添加站点信息
     * @param site
     * @return
     */
    @Override
    public AjaxResult addSite(Site site) {
        AjaxResult ajaxResult = addSiteVerify(site);
        if(ajaxResult.isError()){
            return ajaxResult;
        }
        Site one = this.getOne(new LambdaQueryWrapper<Site>().eq(Site::getCode, site.getCode()).eq(Site::getDelFlag, 0));
        if(null != one){
            return AjaxResult.error("站点编号重复");
        }
        site.setMark(0);
        this.save(site);
        //推送成都监管
        chengDuJianGuanClient.notificationStationInfo(site.getId());
        if(StringUtils.isNotEmpty(site.getSerAreaCode())){
            ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingDeque<>());
            threadPoolExecutor.execute(()->{
                StationInfoReq stationInfoReq = new StationInfoReq();
                stationInfoReq.setOperatorId("91510903906171535D");
                stationInfoReq.setStationId(site.getCode());
                OperatorInfo operatorInfo = new OperatorInfo();
                operatorInfo.setOperatorId("91510903906171535D");
                operatorInfo.setOperatorName("四川明星新能源科技有限公司");
                operatorInfo.setOperatorTel1("18683346252");
                operatorInfo.setOperatorTel2("13982508784");
                operatorInfo.setOperatorRegAddress("遂宁市船山区渠河南路18号");
                operatorInfo.setOperatorNote("");
                stationInfoReq.setOperatorInfo(operatorInfo);
                List<StationInfo> stationInfos = new ArrayList<>();
                stationInfos.add(buildStationInfo(site));
                stationInfoReq.setItemSize(stationInfos.size());
                stationInfoReq.setStationInfos(stationInfos);
                R r = eLuTongClient.pushStationInfo(stationInfoReq);
                if(200 != r.getCode()){
                    System.out.println(r.getMsg());
                }
                // TODO 东涪推送
                dongFuStationClient.pushChargingStation();
            });
        }
        return AjaxResult.success();
    }
 
 
    private StationInfo buildStationInfo(Site site){
        StationInfo stationInfo = new StationInfo();
        stationInfo.setSerAreaCode(site.getSerAreaCode());
        stationInfo.setOperatorId("91510903906171535D");
        stationInfo.setStationId(site.getCode());
        stationInfo.setStationName(site.getName());
        stationInfo.setStationMode("CD");
        stationInfo.setAreaCode(site.getDistrictsCode());
        stationInfo.setServiceTel(site.getServicePhone());
        switch (site.getSiteType()){
            case 0:
                stationInfo.setStationType(255);
                break;
            case 1:
                stationInfo.setStationType(1);
                break;
            case 2:
                stationInfo.setStationType(50);
                break;
            case 3:
                stationInfo.setStationType(100);
                break;
            case 4:
                stationInfo.setStationType(101);
                break;
            case 5:
                stationInfo.setStationType(102);
                break;
            case 6:
                stationInfo.setStationType(103);
                break;
        }
        switch (site.getStatus()){
            case 3:
                stationInfo.setStationStatus(5);
                break;
            case 2:
                stationInfo.setStationStatus(6);
                break;
            case 1:
                stationInfo.setStationStatus(50);
                break;
        }
        stationInfo.setParkNums(site.getParkingSpace());
        stationInfo.setStationLng(Double.parseDouble(site.getLon()));
        stationInfo.setStationLat(Double.parseDouble(site.getLat()));
        stationInfo.setSiteGuide(site.getGuide());
        switch (site.getConstructionSite()){
            case 1:
                stationInfo.setConstruction(1);
                break;
            case 2:
                stationInfo.setConstruction(2);
                break;
            case 3:
                stationInfo.setConstruction(3);
                break;
            case 4:
                stationInfo.setConstruction(4);
                break;
            case 5:
                stationInfo.setConstruction(5);
                break;
            case 6:
                stationInfo.setConstruction(6);
                break;
            case 7:
                stationInfo.setConstruction(7);
                break;
            case 8:
                stationInfo.setConstruction(8);
                break;
            case 9:
                stationInfo.setConstruction(9);
                break;
            case 10:
                stationInfo.setConstruction(10);
                break;
            case 11:
                stationInfo.setConstruction(11);
                break;
            case 0:
                stationInfo.setConstruction(255);
                break;
        }
        if(StringUtils.isNotEmpty(site.getImgUrl())){
            stationInfo.setPictures(Arrays.asList(site.getImgUrl().split(",")));
        }
        stationInfo.setMatchCars(site.getVehicleDescription());
        stationInfo.setBusinessHours(site.getStartServiceTime() + " - " + site.getEndServiceTime());
        stationInfo.setSiteGuide("");
        stationInfo.setPictures(new ArrayList<>());
        stationInfo.setMatchCars("");
        stationInfo.setElectricityFee(BigDecimal.ZERO);
        stationInfo.setServiceFee(BigDecimal.ZERO);
        stationInfo.setParkFee(BigDecimal.ZERO);
        stationInfo.setPayment("2");
        stationInfo.setSupportOrder(0);
        stationInfo.setEquipmentInfos(buildEquipmentInfo(site));
        return stationInfo;
    }
 
    private List<EquipmentInfo> buildEquipmentInfo(Site site){
        List<TChargingPile> list = chargingPileService.list(new LambdaQueryWrapper<TChargingPile>()
                .eq(TChargingPile::getSiteId, site.getId()).eq(TChargingPile::getDelFlag, 0));
        return new ArrayList<EquipmentInfo>(){{
            for (TChargingPile chargingPile : list) {
                EquipmentInfo equipmentInfo = new EquipmentInfo();
                equipmentInfo.setEquipmentId(chargingPile.getCode());
                equipmentInfo.setEquipmentName(chargingPile.getName());
                equipmentInfo.setManufacturerId(StringUtils.isNotEmpty(chargingPile.getManufacturerCode()) ? chargingPile.getManufacturerCode() : "91510900MACPB4NJ4E");
                equipmentInfo.setManufacturerName(StringUtils.isNotEmpty(chargingPile.getManufacturer()) ? chargingPile.getManufacturer() : "");
                equipmentInfo.setEquipmentModel(StringUtils.isNotEmpty(chargingPile.getEquipmentType()) ? chargingPile.getEquipmentType() : "");
                if(null != chargingPile.getProductionDate()){
                    equipmentInfo.setProductionDate(chargingPile.getProductionDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                }else{
                    equipmentInfo.setProductionDate("");
                }
                equipmentInfo.setEquipmentType(0 == chargingPile.getType() ? 5 : chargingPile.getType());
                if(StringUtils.isNotEmpty(chargingPile.getEquipmentLng())){
                    equipmentInfo.setEquipmentLng(Double.parseDouble(chargingPile.getEquipmentLng()));
                }
                if(StringUtils.isNotEmpty(chargingPile.getEquipmentLat())){
                    equipmentInfo.setEquipmentLat(Double.parseDouble(chargingPile.getEquipmentLat()));
                }
                equipmentInfo.setPower(chargingPile.getRatedPower().doubleValue());
                equipmentInfo.setConnectorInfos(buildConnectorInfo(chargingPile));
                add(equipmentInfo);
            }
        }};
    }
 
 
    private List<ConnectorInfo> buildConnectorInfo(TChargingPile chargingPile){
        List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>()
                .eq(TChargingGun::getChargingPileId, chargingPile.getId()).eq(TChargingGun::getDelFlag, 0));
        return new ArrayList<ConnectorInfo>(){{
            for (TChargingGun chargingGun : list) {
                ConnectorInfo connectorInfo = new ConnectorInfo();
                connectorInfo.setConnectorId(chargingGun.getFullNumber());
                connectorInfo.setConnectorName(chargingGun.getName());
                connectorInfo.setConnectorType(0 == chargingGun.getType() ? 6 : chargingGun.getType());
                connectorInfo.setVoltageUpperLimits(chargingGun.getUpperRatedVoltage().intValue());
                connectorInfo.setVoltageLowerLimits(chargingGun.getLowerLimitOfRatedVoltage().intValue());
                connectorInfo.setCurrent(chargingGun.getRatedCurrent().intValue());
                connectorInfo.setPower(chargingGun.getRatedPower().doubleValue());
                connectorInfo.setParkNo(chargingGun.getParkingNumber());
                connectorInfo.setNationalStandard(Integer.parseInt(chargingGun.getNationalStandard()));
                connectorInfo.setParkNo("");
                add(connectorInfo);
            }
        }};
    }
    
    /**
     * 编辑站点
     * @param site
     * @return
     */
    @Override
    public AjaxResult editSite(Site site) {
        AjaxResult ajaxResult = addSiteVerify(site);
        if(ajaxResult.isError()){
            return ajaxResult;
        }
        Site one = this.getOne(new LambdaQueryWrapper<Site>().eq(Site::getCode, site.getCode()).eq(Site::getDelFlag, 0));
        if(null != one && !one.getCode().equals(site.getCode())){
            return AjaxResult.error("站点编号重复");
        }
        
        Site site1 = this.getById(site.getId());
        if(!site1.getPartnerId().equals(site.getPartnerId())){
            List<TPartnerSite> list = partnerSiteService.list(new LambdaQueryWrapper<TPartnerSite>().eq(TPartnerSite::getPartnerId, site1.getPartnerId()).eq(TPartnerSite::getSiteId, site.getId()));
            for (TPartnerSite partnerSite : list) {
                partnerSite.setPartnerId(site.getPartnerId());
                partnerSiteService.updateById(partnerSite);
            }
        }
        
        this.updateById(site);
        tcecClient.superviseNotificationStationInfo(site.getId());
        //推送成都监管
        chengDuJianGuanClient.notificationStationInfo(site.getId());
        if(StringUtils.isNotEmpty(site.getSerAreaCode())){
            ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingDeque<>());
            threadPoolExecutor.execute(()->{
                StationInfoReq stationInfoReq = new StationInfoReq();
                stationInfoReq.setOperatorId("91510903906171535D");
                stationInfoReq.setStationId(site.getCode());
                OperatorInfo operatorInfo = new OperatorInfo();
                operatorInfo.setOperatorId("91510903906171535D");
                operatorInfo.setOperatorName("四川明星新能源科技有限公司");
                operatorInfo.setOperatorTel1("18683346252");
                operatorInfo.setOperatorTel2("13982508784");
                operatorInfo.setOperatorRegAddress("遂宁市船山区渠河南路18号");
                operatorInfo.setOperatorNote("");
                stationInfoReq.setOperatorInfo(operatorInfo);
                List<StationInfo> stationInfos = new ArrayList<>();
                stationInfos.add(buildStationInfo(site));
                stationInfoReq.setItemSize(stationInfos.size());
                stationInfoReq.setStationInfos(stationInfos);
                R r = eLuTongClient.pushStationInfo(stationInfoReq);
                if(200 != r.getCode()){
                    System.out.println(r.getMsg());
                }
                // TODO 东涪推送
                dongFuStationClient.pushChargingStation();
            });
        }
        return AjaxResult.success();
    }
    
    /**
     * 校验必填项
     * @param site
     * @return
     */
    AjaxResult addSiteVerify(Site site){
        if(null == site.getPartnerId()){
            return AjaxResult.error("合作商不能为空");
        }
        if(StringUtils.isEmpty(site.getCode())){
            return AjaxResult.error("站点编号不能为空");
        }
        if(StringUtils.isEmpty(site.getName())){
            return AjaxResult.error("站点名称不能为空");
        }
        if(null == site.getSiteType()){
            return AjaxResult.error("站点类型不能为空");
        }
        if(null == site.getBusinessCategory()){
            return AjaxResult.error("经营类别不能为空");
        }
        if(null == site.getStatus()){
            return AjaxResult.error("站点状态不能为空");
        }
        if(null == site.getConstructionSite()){
            return AjaxResult.error("建设场所不能为空");
        }
        if(null == site.getTransformerPower()){
            return AjaxResult.error("变压器功率不能为空");
        }
        if(null == site.getMemberDiscountFlag()){
            return AjaxResult.error("请选择是否参与会员折扣");
        }
        if(StringUtils.isEmpty(site.getProvince()) || StringUtils.isEmpty(site.getProvinceCode()) ||
                StringUtils.isEmpty(site.getCity()) || StringUtils.isEmpty(site.getCityCode()) ||
                StringUtils.isEmpty(site.getDistricts()) || StringUtils.isEmpty(site.getDistrictsCode())){
            return AjaxResult.error("所在区域不能为空");
        }
        if(StringUtils.isEmpty(site.getAddress())){
            return AjaxResult.error("详细地址不能为空");
        }
//        if(StringUtils.isEmpty(site.getLon()) || StringUtils.isEmpty(site.getLat())){
//            return AjaxResult.error("地图位置不能为空");
//        }
//        if(StringUtils.isEmpty(site.getPhone())){
//            return AjaxResult.error("站点电话不能为空");
//        }
        if(StringUtils.isEmpty(site.getServicePhone())){
            return AjaxResult.error("服务电话不能为空");
        }
        if(null == site.getParkingSpace()){
            return AjaxResult.error("车位数量不能为空");
        }
        if(null == site.getSort()){
            return AjaxResult.error("排序不能为空");
        }
//        if(StringUtils.isEmpty(site.getAreaCodeCountryside())){
//            return AjaxResult.error("充换电站所在县以下行政区划代码不能为空");
//        }
//        if(null == site.getStationClassification()){
//            return AjaxResult.error("请选择站点分类");
//        }
//        if(null == site.getGeneralApplicationType()){
//            return AjaxResult.error("请选择通用类型");
//        }
//        if(null == site.getParkType()){
//            return AjaxResult.error("请选择停车费类型");
//        }
//        if(null == site.getRoundTheClock()){
//            return AjaxResult.error("请选择是否7*24h营业");
//        }
//        if (site.getStationClassification()!=1&& (!org.springframework.util.StringUtils.hasLength(site.getSwapMatchCars()))){
//            return AjaxResult.error("服务车型描述不能为空");
//        }
//        if(null == site.getElectricityType()){
//            return AjaxResult.error("请选择电费类型");
//        }
//        if(null == site.getBusinessExpandType()){
//            return AjaxResult.error("请选择报装类型");
//        }
//        if(null == site.getCapacity()){
//            return AjaxResult.error("报装电源容量不能为空");
//        }
//        if(null == site.getRatedPower()){
//            return AjaxResult.error("站点额定总功率不能为空");
//        }
//        if(StringUtils.isEmpty(site.getOfficialRunTime())){
//            return AjaxResult.error("请选择正式投运时间");
//        }
//        if(null == site.getPeriodFee()){
//            return AjaxResult.error("请选择峰谷时分");
//        }
//        if(null == site.getVideoMonitor()){
//            return AjaxResult.error("请选择视频监控配套情况");
//        }
//        if(StringUtils.isEmpty(site.getEquipmentOwnerName())){
//            return AjaxResult.error("设备所属方名称不能为空");
//        }
//        if(null == site.getSupplyType()){
//            return AjaxResult.error("请选择供电类型");
//        }
//        if(site.getSupplyType()==1){
//            if (StringUtils.isEmpty(site.getResidentNo())){
//                return AjaxResult.error("供电局用户编号不能为空");
//            }
//        }
        return AjaxResult.success();
    }
    
    /**
     * 删除站点
     * @param ids 站点id
     * @return
     */
    @Override
    public AjaxResult delSite(Integer[] ids) {
        //查询是否有关联数据
        //充电桩
        long count1 = chargingPileService.count(new LambdaQueryWrapper<TChargingPile>().in(TChargingPile::getSiteId, Arrays.asList(ids))
                .eq(TChargingPile::getDelFlag, 0));
        if(count1 > 0){
            return AjaxResult.error("该站点已添加充电桩,不可删除。");
        }
        for (Integer id : ids) {
            Site site = this.getById(id);
            this.removeById(site);
        }
        return AjaxResult.success();
    }
 
    @Override
    public PageInfo<SiteVO> pageList(SiteQuery query,Integer isLogin) {
        TAppUser appUser = null;
        // 获取当前登录用户id
        TAppUserVipDetail data1 = null;
        if(isLogin == 1){
            Long userId = tokenService.getLoginUserApplet().getUserId();
            // 根据id查询用户信息
            appUser = appUserClient.getUserById(userId).getData();
            GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
            getAppUserVipDetail.setAppUserId(userId);
            getAppUserVipDetail.setVipId(appUser.getVipId());
            R<TAppUserVipDetail> appUserVipDetail = vipDetailClient.getAppUserVipDetail(getAppUserVipDetail);
            data1 = appUserVipDetail.getData();
        }
        PageInfo<SiteVO> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize());
        List<SiteVO> list = this.baseMapper.pageList(query,pageInfo);
        if(Objects.nonNull(appUser) && Objects.nonNull(appUser.getVipId())){
            // 查询会员信息
//            TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
            if(Objects.nonNull(data1)){
                String vipJson = data1.getVipJson();
                TVip vip = JSON.parseObject(vipJson, TVip.class);
                if(Objects.nonNull(vip) && vip.getType() == 2){
                    list.forEach(item -> {
                        if(Integer.valueOf(1).equals(item.getMemberDiscountFlag()) && Objects.nonNull(vip.getDiscount())){
                            item.setVipElectrovalence(vip.getDiscount().divide(new BigDecimal(10)).multiply(item.getServiceCharge()).add(item.getElectrovalenceOriginal()));
                        }
                    });
                }
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
 
    @Override
    public SiteDetailVO getDetailById(SiteDetailQuery query) {
        return this.baseMapper.getDetailById(query);
    }
 
    @Override
    public List<Site> getSiteListParkLot() {
        Set<Integer> ids = null;
        //校验合作商权限
        SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData();
        Integer roleType = sysUser.getRoleType();
        Integer objectId = sysUser.getObjectId();
        //合作商
        if(roleType == 2){
            ids = partnerService.authSite(objectId, SiteMenu.SITE_LIST);
        }else{
            //非管理员需要根据角色和用户配置查询允许的站点数据
            if(!SecurityUtils.isAdmin(tokenService.getLoginUser().getUserid())){
                List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData();
                List<SysUserRoleVo> data2 = sysUserRoleClient.getRoleByUserId(sysUser.getUserId()).getData();
                List<Integer> data1 = roleSiteClient.getSiteIds(data2.get(0).getRoleId()).getData();
                data.addAll(data1);
                ids = new HashSet<>(data);
            }
        }
        // 查询所有的停车场的站点id
        List<TParkingLot> list = parkingLotService.list();
        List<Integer> siteIds = list.stream().map(TParkingLot::getSiteId).distinct().collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(ids) && !CollectionUtils.isEmpty(siteIds)){
            Iterator<Integer> iterator = ids.iterator();
            while (iterator.hasNext()){
                Integer next = iterator.next();
                if(siteIds.contains(next)){
                    iterator.remove();
                }
            }
        }
        return this.baseMapper.getSiteListParkLot(ids);
    }
 
    @Override
    public List<Site> getSiteListGun() {
        Set<Integer> ids = null;
        //校验合作商权限
        SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData();
        Integer roleType = sysUser.getRoleType();
        Integer objectId = sysUser.getObjectId();
        //合作商
        if(roleType == 2){
            ids = partnerService.authSite(objectId, SiteMenu.SITE_LIST);
        }else{
            //非管理员需要根据角色和用户配置查询允许的站点数据
            if(!SecurityUtils.isAdmin(tokenService.getLoginUser().getUserid())){
                List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData();
                List<SysUserRoleVo> data2 = sysUserRoleClient.getRoleByUserId(sysUser.getUserId()).getData();
                List<Integer> data1 = roleSiteClient.getSiteIds(data2.get(0).getRoleId()).getData();
                data.addAll(data1);
                ids = new HashSet<>(data);
            }
        }
        return this.baseMapper.getSiteListGun(ids);
    }
 
    @Override
    public List<SiteVO> getMapSiteList(SiteQuery query,Integer isLogin) {
 
        if(StringUtils.isEmpty(query.getLon()) || StringUtils.isEmpty(query.getLat())){
            return new ArrayList<>();
        }
        TAppUser appUser = null;
        // 获取当前登录用户id
        TAppUserVipDetail data1 = null;
        if(isLogin == 1){
            Long userId = tokenService.getLoginUserApplet().getUserId();
            // 根据id查询用户信息
            appUser = appUserClient.getUserById(userId).getData();
            GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
            getAppUserVipDetail.setAppUserId(userId);
            getAppUserVipDetail.setVipId(appUser.getVipId());
            R<TAppUserVipDetail> appUserVipDetail = vipDetailClient.getAppUserVipDetail(getAppUserVipDetail);
            data1 = appUserVipDetail.getData();
        }
        List<SiteVO> list = this.baseMapper.getMapSiteList(query);
        if(Objects.nonNull(appUser) && Objects.nonNull(appUser.getVipId())){
            // 查询会员信息
//            TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
            if(Objects.nonNull(data1)){
                String vipJson = data1.getVipJson();
                TVip vip = JSON.parseObject(vipJson, TVip.class);
                if(Objects.nonNull(vip) && vip.getType() == 2){
                    list.forEach(item -> {
                        if (Integer.valueOf(1).equals(item.getMemberDiscountFlag())) {
                            item.setVipElectrovalence(vip.getDiscount().divide(new BigDecimal(10)).multiply(item.getServiceCharge()).add(item.getElectrovalenceOriginal()));
                        }
                    });
                }
            }
        }
        return list;
    }
 
 
    /**
     * 设置站点计费策略
     * @param id 站点id
     * @param accountingStrategyId 计费策略id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void setAccountingStrategy(Integer id, Integer accountingStrategyId) {
        Site site = this.getById(id);
        site.setAccountingStrategyId(accountingStrategyId);
        this.updateById(site);
        List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().in(TChargingGun::getSiteId, id).eq(TChargingGun::getDelFlag, 0));
        for (TChargingGun tChargingGun : list) {
            TChargingGun tChargingGun1 = new TChargingGun();
            tChargingGun1.setId(tChargingGun.getId());
            tChargingGun1.setAccountingStrategyId(accountingStrategyId);
            chargingGunService.updateById(tChargingGun1);
        }
        
        //下发硬件数据
        List<TAccountingStrategyDetail> accountingStrategyDetails = accountingStrategyDetailService.list(new LambdaQueryWrapper<TAccountingStrategyDetail>().eq(TAccountingStrategyDetail::getAccountingStrategyId, accountingStrategyId));
        List<TChargingPile> list1 = chargingPileService.lambdaQuery().eq(TChargingPile::getSiteId, id).eq(TChargingPile::getDelFlag, 0).list();
        for (TChargingPile tChargingPile : list1) {
            integrationClient.setupBillingModel1(tChargingPile.getCode(), JSON.toJSONString(accountingStrategyDetails));
            chengDuJianGuanClient.notificationStationFee(tChargingPile.getId());
        }
        
        if(1 == site.getIsOpenSynchronization()){
            //推送三方平台
            tcecClient.notificationStationChange(Arrays.asList(id));
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void batchSetAccountingStrategy(List<Integer> ids, Integer accountingStrategyId) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        this.lambdaUpdate()
                .in(Site::getId, ids)
                .set(Site::getAccountingStrategyId, accountingStrategyId)
                .update();
        chargingGunService.lambdaUpdate()
                .in(TChargingGun::getSiteId, ids)
                .eq(TChargingGun::getDelFlag, 0)
                .set(TChargingGun::getAccountingStrategyId, accountingStrategyId)
                .update();
        List<TAccountingStrategyDetail> accountingStrategyDetails = accountingStrategyDetailService.list(new LambdaQueryWrapper<TAccountingStrategyDetail>().eq(TAccountingStrategyDetail::getAccountingStrategyId, accountingStrategyId));
        List<TChargingPile> chargingPiles = chargingPileService.lambdaQuery().in(TChargingPile::getSiteId, ids).eq(TChargingPile::getDelFlag, 0).list();
        List<Integer> syncSiteIds = this.lambdaQuery()
                .select(Site::getId, Site::getIsOpenSynchronization)
                .in(Site::getId, ids)
                .eq(Site::getIsOpenSynchronization, 1)
                .list()
                .stream()
                .map(Site::getId)
                .collect(Collectors.toList());
        new Thread(() -> {
            for (TChargingPile chargingPile : chargingPiles) {
                try {
                    integrationClient.setupBillingModel1(chargingPile.getCode(), JSON.toJSONString(accountingStrategyDetails));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    chengDuJianGuanClient.notificationStationFee(chargingPile.getId());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (!CollectionUtils.isEmpty(syncSiteIds)) {
                try {
                    tcecClient.notificationStationChange(syncSiteIds);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}