郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
package com.gkhy.safePlatform.safeCheck.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
import com.gkhy.safePlatform.account.rpc.apimodel.AccountUserService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserInfoRPCRespDTO;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserRPCRespDTO;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.AusinessException;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.commons.utils.idService.SnowFlow;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.safeCheck.entity.*;
import com.gkhy.safePlatform.safeCheck.enums.DelectStatusEnum;
import com.gkhy.safePlatform.safeCheck.enums.UserTypeEnum;
import com.gkhy.safePlatform.safeCheck.model.dto.req.*;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.*;
import com.gkhy.safePlatform.safeCheck.model.query.ListPointByPageDBQuery;
import com.gkhy.safePlatform.safeCheck.service.SafeCheckBaseManagerService;
import com.gkhy.safePlatform.safeCheck.service.SafeCheckMinioAccessService;
import com.gkhy.safePlatform.safeCheck.service.baseService.*;
import com.gkhy.safePlatform.safeCheck.util.UserInfoUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboReference;
 
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
 
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
 
 
@Service
public class SafeCheckBaseManagerServiceImpl implements SafeCheckBaseManagerService {
 
    @DubboReference(check = false)
    private AccountAuthService accountAuthService;
 
    @DubboReference(check = false)
    private AccountUserService accountUserService;
 
    @DubboReference(check = false)
    private AccountDepartmentService accountDepartmentService;
 
    @Autowired
    private RedissonClient redissonClient;
 
    @Autowired
    private SafeCheckQuotaTypeService safeCheckQuotaTypeService;
 
    @Autowired
    private SafeCheckRegionTypeService safeCheckRegionTypeService;
 
    @Autowired
    private SafeCheckPointService safeCheckPointService;
 
    @Autowired
    private SafeCheckRegionService safeCheckRegionService;
 
    @Autowired
    private SafeCheckMinioAccessService safeCheckMinioAccessService;
 
    @Autowired
    private SafeCheckQuotaService safeCheckQuotaService;
 
    @Autowired
    private SafeCheckUnitAndQuotaService safeCheckUnitAndQuotaService;
 
    @Autowired
    private SafeCheckRfidService safeCheckRfidService;
 
    /**
     * @description *****************************************   通用的     **********************************************
     */
 
    /**
     * @description 获取巡检指标的单元及类型(有效状态)
     */
    @Override
    public List<SafeCheckQuotaTypeRespDTO> listQuotaType() {
        List<SafeCheckQuotaTypeRespDTO> safeCheckQuotaTypeRespDTOS = new ArrayList<>();
        List<SafeCheckQuotaType> quotaTypes = safeCheckQuotaTypeService.listQuotaType(DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        if (quotaTypes == null || quotaTypes.size() == 0 ){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"数据库不存在单元及类型,请添加");
        }
        safeCheckQuotaTypeRespDTOS = quotaTypes.stream().map((quotatype) -> {
            SafeCheckQuotaTypeRespDTO safeCheckQuotaTypeRespDTO = new SafeCheckQuotaTypeRespDTO();
            BeanUtils.copyProperties(quotatype, safeCheckQuotaTypeRespDTO);
            return safeCheckQuotaTypeRespDTO;
        }).collect(Collectors.toList());
        return safeCheckQuotaTypeRespDTOS;
    }
 
    /**
     * @description 获取巡检区域类型(有效状态)
     */
    @Override
    public List<SafeCheckRegionTypeRespDTO> listRegionType() {
        List<SafeCheckRegionTypeRespDTO> safeCheckRegionTypeRespDTOS = new ArrayList<>();
        List<SafeCheckRegionType> regionTypes  = safeCheckRegionTypeService.listRegionType(DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        if (regionTypes == null || regionTypes.size() == 0 ){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"数据库不存在相关类型,请添加");
        }
        safeCheckRegionTypeRespDTOS = regionTypes.stream().map((regiontype) -> {
            SafeCheckRegionTypeRespDTO safeCheckRegionTypeRespDTO = new SafeCheckRegionTypeRespDTO();
            BeanUtils.copyProperties(regiontype, safeCheckRegionTypeRespDTO);
            return safeCheckRegionTypeRespDTO;
        }).collect(Collectors.toList());
        return safeCheckRegionTypeRespDTOS;
    }
 
    /**
     * @description 获取所有巡检区域名称(有效状态)
     */
    @Override
    public List<SafeCheckRegionNameRespDTO> listRegionName() {
        List<SafeCheckRegionNameRespDTO> regionNameRespDTOS = new ArrayList<>();
        List<SafeCheckRegion> regions = safeCheckRegionService.listRegionName(DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (regions == null || regions.size() == 0){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"请新增巡检区域");
        }
        regionNameRespDTOS = regions.stream().map((region) ->{
            SafeCheckRegionNameRespDTO regionNameRespDTO = new SafeCheckRegionNameRespDTO();
            BeanUtils.copyProperties(region,regionNameRespDTO);
            return regionNameRespDTO;
        }).collect(Collectors.toList());
        return regionNameRespDTOS;
    }
 
    /**
     * @description 获取所有有效的RFID名称(有效状态)
     */
    @Override
    public List<SafeCheckRfidNameRespDTO> listRfidName() {
        List<SafeCheckRfidNameRespDTO> rfidNameRespDTOS = new ArrayList<>();
        List<SafeCheckRfid> rfids = safeCheckRfidService.listRfidName(DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (rfids == null || rfids.size() == 0){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"请新增RFID");
        }
        rfidNameRespDTOS = rfids.stream().map((rfid) ->{
            SafeCheckRfidNameRespDTO rfidNameRespDTO = new SafeCheckRfidNameRespDTO();
            BeanUtils.copyProperties(rfid,rfidNameRespDTO);
            return rfidNameRespDTO;
        }).collect(Collectors.toList());
        return rfidNameRespDTOS;
    }
 
 
    /**
     * @description *****************************************   巡检区域    **********************************************
     */
 
 
    /**
     * @description 新增巡检区域
     */
    @Transactional
    @Override
    public int  saveRegion(ContextCacheUser currentUser, SafeCheckRegionReqDTO safeCheckRegionReqDTO) {
        SafeCheckRegion safeCheckRegion = new SafeCheckRegion();
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
        if (safeCheckRegionReqDTO == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"关键参数不能为空");
        }
        String regionName = safeCheckRegionReqDTO.getRegion();
        int regionTypeId = safeCheckRegionReqDTO.getRegionTypeId();
 
        if (regionName == null || regionName.length() == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"设备区域名称不能为空");
        }
        if (regionTypeId == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"设备区域类型不能为空");
        }
        if (safeCheckRegionReqDTO.getRegionDepartmentId() == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"设备区域所属部门不能为空");
        }
        //部门是否存在
        ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(safeCheckRegionReqDTO.getRegionDepartmentId());
        if (depInfoByDepId.getData() == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"设备区域所属部门不存在");
        }
        //0、加分布式锁
        String lockName = "SAFECHECK_REGION_CREATE_"+regionName;
        RLock createRegionLock = redissonClient.getLock(lockName);
        createRegionLock.lock(3, TimeUnit.SECONDS);
 
        SafeCheckRegion regionByName = safeCheckRegionService.getRegionByName(regionName, DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (regionByName != null){
            throw new AusinessException(E.DATA_DATABASE_EXIST,"设备区域名称已经存在");
        }
        String regionTypeName = safeCheckRegionTypeService.getRegionTypeNameById(regionTypeId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        //雪花算法生成id和uuid
        SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
        String uuid = UUID.randomUUID().toString();
        Date date = new Date();
        long regionid = snowFlow.nextId();
 
        safeCheckRegion.setId(regionid);
        safeCheckRegion.setUuid(uuid);
        safeCheckRegion.setDeleteStatus(DelectStatusEnum.DELECT_NO.getStatus());
        safeCheckRegion.setRegionDepartmentId(safeCheckRegionReqDTO.getRegionDepartmentId());
        safeCheckRegion.setRegion(regionName);
        safeCheckRegion.setRegionType(regionTypeName);
        safeCheckRegion.setGmtCreate(date);
        safeCheckRegion.setGmtModitify(date);
        safeCheckRegion.setDepId(userInfo.getDepartment().getDepId());
        safeCheckRegion.setDepUuid(null);
        safeCheckRegion.setEnterpriseId(userInfo.getEnterprise().getId());
        safeCheckRegion.setEnterpriseUuid(userInfo.getEnterprise().getUuid());
        safeCheckRegion.setCreateByUserName(userInfo.getRealName());
        safeCheckRegion.setLastEditUserName(userInfo.getRealName());
 
        int saveResult = safeCheckRegionService.saveRegion(safeCheckRegion);
 
        //释放分布式锁
        createRegionLock.unlock();
        return saveResult;
    }
 
    /**
     * @description 根据id删除巡检区域
     */
    @Transactional
    @Override
    public int deleteRegionById(ContextCacheUser currentUser, Long id) {
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
 
        SafeCheckRegion region = this.paramIsValidAndRegionIsExit(id);
        region.setDeleteStatus(DelectStatusEnum.DELECT_YES.getStatus());
        region.setGmtModitify(new Date());
        region.setLastEditUserName(userInfo.getRealName());
        int deleteResult = safeCheckRegionService.deleteRegionById(region,DelectStatusEnum.DELECT_NO.getStatus().intValue());
        return deleteResult;
 
    }
 
    /**
     * @description 根据id更新巡检区域
     */
    @Transactional
    @Override
    public void updateRegionById(ContextCacheUser currentUser, SafeCheckRegionReqDTO safeCheckRegionReqDTO) {
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
        if (safeCheckRegionReqDTO == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"关键参数不能为空");
        }
        String newRegionName = safeCheckRegionReqDTO.getRegion();
        int newRegionTypeId = safeCheckRegionReqDTO.getRegionTypeId();
 
        if (newRegionName == null || newRegionName.length() == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"设备区域名称不能为空");
        }
        if (newRegionTypeId == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"设备区域类型不能为空");
        }
        if (safeCheckRegionReqDTO.getRegionDepartmentId() == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"设备区域所属部门不能为空");
        }
        //部门是否存在
        ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(safeCheckRegionReqDTO.getRegionDepartmentId());
        if (depInfoByDepId.getData() == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"设备区域所属部门不存在");
        }
        SafeCheckRegion oldRegion = this.paramIsValidAndRegionIsExit(safeCheckRegionReqDTO.getId());
 
        //0、加分布式锁
        String lockName = "SAFECHECK_REGION_UPDATE_"+newRegionName;
        RLock updateRegionLock = redissonClient.getLock(lockName);
        updateRegionLock.lock(3, TimeUnit.SECONDS);
 
        SafeCheckRegion regionByName = safeCheckRegionService.getRegionByName(newRegionName, DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        if (regionByName != null){
            if (!newRegionName.equals(oldRegion.getRegion())) {
                throw new AusinessException(E.DATA_DATABASE_EXIST, "设备区域名称已存在");
            }
        }
        String regionTypeName = safeCheckRegionTypeService.getRegionTypeNameById(safeCheckRegionReqDTO.getRegionTypeId()
                ,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        BeanUtils.copyProperties(safeCheckRegionReqDTO,oldRegion);
 
 
        oldRegion.setRegionType(regionTypeName);
        oldRegion.setGmtModitify(new Date());
        oldRegion.setLastEditUserName(userInfo.getRealName());
        safeCheckRegionService.updateRegionById(oldRegion,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        //1、释放分布式锁
        updateRegionLock.unlock();
    }
 
 
    /**
     * @description 根据巡检区域id、未删除标志查询巡检数据
     */
    @Override
    public SafeCheckRegionRespDTO getRegionById(Long id) {
        SafeCheckRegionRespDTO safeCheckRegionRespDTO = new SafeCheckRegionRespDTO();
        SafeCheckRegion safeCheckRegion = this.paramIsValidAndRegionIsExit(id);
        String regionType = safeCheckRegion.getRegionType();
        int regionTypeId = safeCheckRegionTypeService.getRegionTypeIdByName(regionType, DelectStatusEnum.DELECT_NO.getStatus().intValue());
        BeanUtils.copyProperties(safeCheckRegion,safeCheckRegionRespDTO);
        safeCheckRegionRespDTO.setRegionTypeId(regionTypeId);
        return safeCheckRegionRespDTO;
    }
 
 
    /**
     * @description 对区域id进行参数校验,以及数据库是否存在 存在即返回
     */
    private SafeCheckRegion paramIsValidAndRegionIsExit(Long id){
        //todo: 存在 应为 exist
        if (id == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"巡检区域id不能为空");
        }
        SafeCheckRegion region = new SafeCheckRegion();
        region = safeCheckRegionService.getOneRegion(id,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        if (region == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"该巡检区域数据库中不存在");
        }
        return region;
    }
 
 
 
 
 
    /**
     * @description 条件分页查询所有的区域  没有条件就是全部查询
     */
    @Override
    public Page listRegionByPage(Page pageInfo, HashMap<String, Object> selectCondition,ContextCacheUser currentUser) {
        int regionTypeId = (int) selectCondition.get("regionTypeId");
        String regionTypeName = null;
        if (regionTypeId != 1) {
            regionTypeName = safeCheckRegionTypeService.getRegionTypeNameById(regionTypeId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
            if (regionTypeName == null) {
                throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "巡检区域类型不存在");
            }
        }
        selectCondition.put("regionTypeName",regionTypeName);
        List<Long> depIds = null;
        if (UserTypeEnum.STAFF.getCode() == currentUser.getType()){
            ResultVO<List<Long>> resultVO = accountDepartmentService.listDepAndSubDepIds(currentUser.getDepId());
            depIds = (List<Long>) resultVO.getData();
        }
        selectCondition.put("depIds",depIds);
 
        Page pageInfoResult = safeCheckRegionService.listRegionByPage(pageInfo,selectCondition);
        List<SafeCheckRegion> regions = pageInfoResult.getRecords();
        if (regions == null && regions.size() == 0){
            return null;
        }
        List<SafeCheckRegionPageRespDTO> regionPageRespDTOS = regions.stream().map((region)->{
            SafeCheckRegionPageRespDTO regionPageRespDTO = new SafeCheckRegionPageRespDTO();
            BeanUtils.copyProperties(region,regionPageRespDTO);
            ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(region.getDepId());
            DepInfoRPCRespDTO depData = (DepInfoRPCRespDTO) depInfoByDepId.getData();
            if (depData != null){
                regionPageRespDTO.setRegionDepartment(depData.getDepName());
            }
            return regionPageRespDTO;
        }).collect(Collectors.toList());
 
        pageInfoResult.setRecords(regionPageRespDTOS);
 
        return pageInfoResult;
    }
 
    /**
     * @description *****************************************    巡检指标    ********************************************
     */
 
    /**
     * @description 新增巡检指标
     */
    @Transactional
    @Override
    public int saveQuota(ContextCacheUser currentUser, SafeCheckQuotaReqDTO safeCheckQuotaReqDTO) {
        SafeCheckQuota safeCheckQuota = new SafeCheckQuota();
 
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
 
        String quotaName = safeCheckQuotaReqDTO.getQuota();
 
        if (quotaName == null){
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
 
        //0、加分布式锁
        String lockName = "SAFECHECK_QUOTA_CREATE_"+quotaName;
        RLock createQuotaLock = redissonClient.getLock(lockName);
        createQuotaLock.lock(3, TimeUnit.SECONDS);
 
        if (safeCheckQuotaService.getQuotaByName(quotaName,DelectStatusEnum.DELECT_NO.getStatus()) != null){
            throw new AusinessException(E.DATA_DATABASE_EXIST,"数据库已存在同名指标");
        }
 
        BeanUtils.copyProperties(safeCheckQuotaReqDTO,safeCheckQuota);
 
        int quotaTypeId = safeCheckQuotaReqDTO.getQuotaTypeId();
        String quotaType = safeCheckQuotaTypeService.getNameByTypeId(quotaTypeId);
        if (quotaType == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"无此巡检指标类型");
        }
 
        safeCheckQuota.setQuotaType(quotaType);
        safeCheckQuota.setDeleteStatus(DelectStatusEnum.DELECT_NO.getStatus());
        safeCheckQuota.setGmtCreate(new Date());
        safeCheckQuota.setGmtModitify(new Date());
        safeCheckQuota.setCreateUserName(userInfo.getRealName());
        safeCheckQuota.setLastEditUserName(userInfo.getRealName());
 
        int saveResult = safeCheckQuotaService.saveQuota(safeCheckQuota);
 
        //释放分布式锁
        createQuotaLock.unlock();
        return saveResult;
 
    }
 
 
    /**
     * @description 根据巡检指标id删除巡检指标
     */
    @Transactional
    @Override
    public void deleteQuotaById(ContextCacheUser currentUser, Long quotaId) {
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
 
        SafeCheckQuota quota = this.quotaIsExit(quotaId);
 
        //判断巡检指标是否关联到其他任务单元
        safeCheckUnitAndQuotaService.unitIsExitTheQuota(quotaId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        quota.setDeleteStatus(DelectStatusEnum.DELECT_YES.getStatus());
        quota.setGmtModitify(new Date());
        quota.setLastEditUserName(userInfo.getRealName());
 
        safeCheckQuotaService.deleteQuotaById(quota,DelectStatusEnum.DELECT_NO.getStatus().intValue());
    }
 
    /**
     * @description 根据巡检指标id修改巡检指标
     *
     */
    @Transactional
    @Override
    public void updateQuotaById(ContextCacheUser currentUser, SafeCheckQuotaReqDTO safeCheckQuotaReqDTO) {
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
 
        String quotaName = safeCheckQuotaReqDTO.getQuota();
 
        if (quotaName.isEmpty()){
            throw new AusinessException(E.DATA_PARAM_NULL,"巡检指标名不能为空");
        }
 
 
        //0、加分布式锁
        String lockName = "SAFECHECK_QUOTA_UPDATE_"+quotaName;
        RLock updateQuotaLock = redissonClient.getLock(lockName);
        updateQuotaLock.lock(3, TimeUnit.SECONDS);
 
        //判断修改后的指标名称是否存在
        SafeCheckQuota quota = safeCheckQuotaService.getQuotaByName(quotaName, DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        if (quota != null ) {
            if (quota.getId() != safeCheckQuotaReqDTO.getId()) {
                throw new AusinessException(E.DATA_DATABASE_EXIST, "数据库已存在同名指标");
            }
        }
        int quotaTypeId = safeCheckQuotaReqDTO.getQuotaTypeId();
        String quotaType = safeCheckQuotaTypeService.getNameByTypeId(quotaTypeId);
        if (quotaType == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"无此巡检指标类型");
        }
 
        SafeCheckQuota safeCheckQuota = this.quotaIsExit(safeCheckQuotaReqDTO.getId());
        BeanUtils.copyProperties(safeCheckQuotaReqDTO,safeCheckQuota);
        safeCheckQuota.setQuotaType(quotaType);
        safeCheckQuota.setGmtModitify(new Date());
        safeCheckQuota.setLastEditUserName(userInfo.getRealName());
 
        safeCheckQuotaService.updateQuotaById(safeCheckQuota,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
 
        //1、释放分布式锁
        updateQuotaLock.unlock();
    }
 
 
    /**
     * @description 根据巡检指标id获取巡检指标
     */
    @Override
    public SafeCheckQuotaUpdateRespDTO getQuataById(Long id) {
        SafeCheckQuotaUpdateRespDTO safeCheckQuotaUpdateRespDTO = new SafeCheckQuotaUpdateRespDTO();
        SafeCheckQuota safeCheckQuota = this.quotaIsExit(id);
        BeanUtils.copyProperties(safeCheckQuota,safeCheckQuotaUpdateRespDTO);
        int  quotaTypeId = safeCheckQuotaTypeService.getTyIdByName(safeCheckQuota.getQuotaType());
        safeCheckQuotaUpdateRespDTO.setQuotaTypeId(quotaTypeId);
        return safeCheckQuotaUpdateRespDTO;
    }
 
    /**
     * @description 根据巡检指标name获取巡检指标
     */
    @Override
    public SafeCheckQuotaRespDTO getQuotaByName(String quotaName) {
        SafeCheckQuotaRespDTO safeCheckQuotaRespDTO = new SafeCheckQuotaRespDTO();
        SafeCheckQuota safeCheckQuota = safeCheckQuotaService.getQuotaByName(quotaName, DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (safeCheckQuota == null){
            return null;
        };
        BeanUtils.copyProperties(safeCheckQuota,safeCheckQuotaRespDTO);
        return safeCheckQuotaRespDTO;
    }
 
    /**
     * @description 分页获取当前页中的巡检指标信息
     */
    @Override
    public Page listQuotaByPage(Page pageInfo,String quotaName) {
        List<SafeCheckQuotaRespDTO> safeCheckQuotaRespDTOS = new ArrayList<>();
        Page pageInfoResult = safeCheckQuotaService.listQuotaByPage(pageInfo,quotaName);
        List<SafeCheckQuota> quotas = pageInfoResult.getRecords();
        if (quotas == null && quotas.size() == 0){
            return null;
        }
        safeCheckQuotaRespDTOS = quotas.stream().map((quota)->{
            SafeCheckQuotaRespDTO safeCheckQuotaRespDTO = new SafeCheckQuotaRespDTO();
            BeanUtils.copyProperties(quota,safeCheckQuotaRespDTO);
            return safeCheckQuotaRespDTO;
        }).collect(Collectors.toList());
 
        pageInfoResult.setRecords(safeCheckQuotaRespDTOS);
 
        return pageInfoResult;
    }
 
    /**
     * @description 判断巡检指标是否存在,存在则返回该指标
     */
    private SafeCheckQuota quotaIsExit(Long quotaId){
        SafeCheckQuota quota = safeCheckQuotaService.getQuotaById(quotaId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (quota == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"巡检指标不存在");
        }
        return quota;
    }
 
    /**
     * @description ******************************************** rfid  *************************************************
     */
 
    /**
     * @description 新增rfid
     *
     */
    @Transactional
    @Override
    public void saveRfid(ContextCacheUser currentUser, SafeCheckRfidReqDTO safeCheckRfidReqDTO) {
 
        SafeCheckRfid safeCheckRfid = new SafeCheckRfid();
        if (safeCheckRfid == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"关键参数不能为空");
        }
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
 
        //rfid编码
        String rfid = safeCheckRfidReqDTO.getRfid();
        String rfidName = safeCheckRfidReqDTO.getRfidName();
 
        this.rfidParamIsValid(safeCheckRfidReqDTO);
 
        BeanUtils.copyProperties(safeCheckRfidReqDTO,safeCheckRfid);
 
        //0、加分布式锁
        String lockName = "SAFECHECK_RFID_CREATE_"+rfidName;
        RLock createRfidLock = redissonClient.getLock(lockName);
        createRfidLock.lock(3, TimeUnit.SECONDS);
 
        SafeCheckRfid rfidByRfidName = safeCheckRfidService.getRfidByRfidName(rfidName, DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (rfidByRfidName != null){
            throw new AusinessException(E.DATA_DATABASE_EXIST,"rfid名称已存在");
        }
 
        SafeCheckRfid safeCheckRfidByRfidName = safeCheckRfidService.getRfid(rfid,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        if (safeCheckRfidByRfidName != null){
            throw new AusinessException(E.DATA_DATABASE_EXIST,"rfid编码已存在");
        }
 
        //初次新增默认有效状态
        safeCheckRfid.setDeleteStatus(DelectStatusEnum.DELECT_NO.getStatus());
        safeCheckRfid.setGmtCreate(new Date());
        safeCheckRfid.setCreateUserName(userInfo.getRealName());
        safeCheckRfid.setGmtModitify(new Date());
        safeCheckRfid.setLastEditUserName(userInfo.getRealName());
 
        safeCheckRfidService.savaRfid(safeCheckRfid);
        //释放分布式锁
        createRfidLock.unlock();
    }
 
    /**
     * @description 根据RFID的id值删除rfid
     */
    @Transactional
    @Override
    public void deleteRfidById(ContextCacheUser currentUser, int rfidId) {
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
        //先判断这个RFID是否存在
        SafeCheckRfid safeCheckRfid = this.rfidIsExit(rfidId);
        safeCheckRfid.setDeleteStatus(DelectStatusEnum.DELECT_YES.getStatus());
        safeCheckRfid.setGmtModitify(new Date());
        safeCheckRfid.setLastEditUserName(userInfo.getRealName());
        safeCheckRfidService.deleteRfidById(safeCheckRfid,DelectStatusEnum.DELECT_NO.getStatus().intValue());
    }
 
    /**
     * @description 根据RFID的id更新RFID
     */
    @Transactional
    @Override
    public void updateRfidById(ContextCacheUser currentUser, SafeCheckRfidReqDTO safeCheckRfidReqDTO) {
        if (safeCheckRfidReqDTO == null){
            throw new AusinessException(E.DATA_PARAM_NULL, "关键参数为空");
        }
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
 
        this.rfidParamIsValid(safeCheckRfidReqDTO);
        //根据id获取到的数据库中的rfid
        SafeCheckRfid rfidByRfidId = this.rfidIsExit(safeCheckRfidReqDTO.getId());
 
        String rfidName = safeCheckRfidReqDTO.getRfidName();
 
        //0、加分布式锁
        String lockName = "SAFECHECK_RFID_UPDATE_"+rfidName;
        RLock updateRfidLock = redissonClient.getLock(lockName);
        updateRfidLock.lock(3, TimeUnit.SECONDS);
 
        SafeCheckRfid rfidByRfidName = safeCheckRfidService.getRfidByRfidName(rfidName, DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (rfidByRfidName != null){
            if (!rfidName.equals(rfidByRfidId.getRfidName())) {
                throw new AusinessException(E.DATA_DATABASE_EXIST, "rfid名称已存在");
            }
        }
 
        //这是新改的rfid编码
        String rfid = safeCheckRfidReqDTO.getRfid();
        SafeCheckRfid safeCheckRfid = safeCheckRfidService.getRfid(rfid,DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (safeCheckRfid != null){
            if (!rfid.equals(rfidByRfidId.getRfid())) {
                throw new AusinessException(E.DATA_DATABASE_EXIST, "rfid已关联其他设施区域");
            }
        }
        if (safeCheckRfidReqDTO.getRfidImage() == null){
            String rfidImage = rfidByRfidId.getRfidImage();
            if (rfidImage != null){
                safeCheckMinioAccessService.deleteFile(rfidImage);
            }
            BeanUtils.copyProperties(safeCheckRfidReqDTO, rfidByRfidId);
        }else if (safeCheckRfidReqDTO.getRfidImage().startsWith("http")){
            BeanUtils.copyProperties(safeCheckRfidReqDTO,rfidByRfidId,"rfidImage");
        }else {
            String rfidImage = rfidByRfidId.getRfidImage();
            if (rfidImage != null){
                safeCheckMinioAccessService.deleteFile(rfidImage);
            }
            BeanUtils.copyProperties(safeCheckRfidReqDTO, rfidByRfidId);
        }
        //初次新增默认有效状态
        rfidByRfidId.setGmtModitify(new Date());
        rfidByRfidId.setLastEditUserName(userInfo.getRealName());
        safeCheckRfidService.updateRfidById(rfidByRfidId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
 
        //1、释放分布式锁
        updateRfidLock.unlock();
    }
 
 
 
    /**
     * @description 校验更新和新增传来的参数是否有效
     */
    private void rfidParamIsValid(SafeCheckRfidReqDTO safeCheckRfidReqDTO){
        String rfidName = safeCheckRfidReqDTO.getRfidName();
 
        String rfid = safeCheckRfidReqDTO.getRfid();
 
        if (rfidName == null || rfidName.length() == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"rfid名称不能为空");
        }
 
        if (rfid == null || rfid.length() == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"rfid码不能为空");
        }
        if (safeCheckRfidReqDTO.getExceptionHandlerId() == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"rfid异常处理人不能为空");
        }
        if (safeCheckRfidReqDTO.getExceptionHandlerDepId() == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"rfid异常处理人所属部门不能为空");
        }
        if (safeCheckRfidReqDTO.getRfidDepartmentId() == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"rfid所属部门不能为空");
        }
        //获取异常处理人id 看是否存在
        ResultVO<UserInfoRPCRespDTO> userInfoByUid = accountUserService.getUserInfoByUid(safeCheckRfidReqDTO.getExceptionHandlerId());
        if (userInfoByUid.getData() == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"异常处置人不存在");
        }
        //部门是否存在
        ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(safeCheckRfidReqDTO.getRfidDepartmentId());
        if (depInfoByDepId.getData() == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"rfid所属部门不存在");
        }
    }
 
 
    /**
     * @description 根据RFID的id值获取RFID
     */
    @Override
    public SafeCheckRfidRespDTO getRfidById(int rfidId) {
        SafeCheckRfidRespDTO safeCheckRfidRespDTO = new SafeCheckRfidRespDTO();
        SafeCheckRfid safeCheckRfid = this.rfidIsExit(rfidId);
        BeanUtils.copyProperties(safeCheckRfid, safeCheckRfidRespDTO);
        if (safeCheckRfid.getRfidImage() != null){
            safeCheckRfidRespDTO.setRfidImage(safeCheckMinioAccessService.viewFile(safeCheckRfid.getRfidImage()));
        };
        return safeCheckRfidRespDTO;
    }
 
 
    /**
     * @description 判断巡检RFID是否存在,存在则返回该RFID
     */
    private SafeCheckRfid rfidIsExit(int rfidId){
        SafeCheckRfid safeCheckRfid = safeCheckRfidService.getRfidById(rfidId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (safeCheckRfid == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"RFID不存在");
        }
        return safeCheckRfid;
    }
 
    /**
     * @description 条件分页查询rfid  没有条件就是全部查询
     */
    @Override
    public Page listRfidByPage(Page pageInfo, SafeCheckRfidPageReqDTO safeCheckRfidPageReqDTO,ContextCacheUser currentUser) {
        Byte type = currentUser.getType();
        String rfidName = safeCheckRfidPageReqDTO.getRfidName();
        String rfid = safeCheckRfidPageReqDTO.getRfid();
 
        List<Long> depIds = null;
        if (UserTypeEnum.STAFF.getCode() == type){
            ResultVO<List<Long>> resultVO = accountDepartmentService.listDepAndSubDepIds(currentUser.getDepId());
            depIds = (List<Long>) resultVO.getData();
        }
        Page pageInfoResult = safeCheckRfidService.listRfidByPage(pageInfo,rfidName,rfid,depIds);
 
        List<SafeCheckRfid> safeCheckRfids = pageInfoResult.getRecords();
        if (safeCheckRfids == null && safeCheckRfids.size() == 0){
            return pageInfoResult;
        }
        List<SafeCheckRfidPageRepsDTO> safeCheckRfidPageRepsDTOS = safeCheckRfids.stream().map((safeCheckRfid)->{
            SafeCheckRfidPageRepsDTO safeCheckRfidPageRepsDTO = new SafeCheckRfidPageRepsDTO();
            BeanUtils.copyProperties(safeCheckRfid, safeCheckRfidPageRepsDTO);
 
            ResultVO<UserInfoRPCRespDTO> userInfoByUid = accountUserService.getUserInfoByUid(safeCheckRfid.getExceptionHandlerId());
            UserInfoRPCRespDTO userData = (UserInfoRPCRespDTO) userInfoByUid.getData();
            if (userData != null){
                safeCheckRfidPageRepsDTO.setExceptionHandler(userData.getRealName());
                safeCheckRfidPageRepsDTO.setExceptionHandlerPhone(userData.getPhone());
            }
            //部门是否存在
            ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(safeCheckRfid.getRfidDepartmentId());
            DepInfoRPCRespDTO depData = (DepInfoRPCRespDTO) depInfoByDepId.getData();
            if (depData != null){
                safeCheckRfidPageRepsDTO.setRfidDepartment(depData.getDepName());
            }
            if (safeCheckRfid.getRfidImage() != null){
                safeCheckRfidPageRepsDTO.setRfidImage(safeCheckMinioAccessService.viewFile(safeCheckRfid.getRfidImage()));
            }
            return safeCheckRfidPageRepsDTO;
        }).collect(Collectors.toList());
 
        pageInfoResult.setRecords(safeCheckRfidPageRepsDTOS);
 
        return pageInfoResult;
    }
 
    /**
     * @description ******************************************** 巡检点  ************************************************
     */
 
 
    /**
     * @description 新增巡检点
     */
    @Transactional
    @Override
    public void savePoint(ContextCacheUser currentUser, SafeCheckPointReqDTO safeCheckPointReqDTO) {
 
        SafeCheckPoint safeCheckPoint = new SafeCheckPoint();
 
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
 
        //rfid编码
        String pointName = safeCheckPointReqDTO.getCode();
 
        if (pointName == null || pointName.length() == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"巡检点名称不能为空");
        }
 
        //0、加分布式锁
        String lockName = "SAFECHECK_POINT_CREATE_"+pointName;
        RLock createPointLock = redissonClient.getLock(lockName);
        createPointLock.lock(3, TimeUnit.SECONDS);
 
        SafeCheckPoint safeCheckPointByName = safeCheckPointService.getPointByPointName(pointName,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        if (safeCheckPointByName != null){
            throw new AusinessException(E.DATA_DATABASE_EXIST,"巡检点名称已存在");
        }
        BeanUtils.copyProperties(safeCheckPointReqDTO,safeCheckPoint);
 
        //雪花算法生成id和uuid
        SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
        String uuid = UUID.randomUUID().toString();
        long pointId = snowFlow.nextId();
 
        //初次新增默认有效状态
        safeCheckPoint.setId(pointId);
        safeCheckPoint.setUuid(uuid);
        safeCheckPoint.setDeleteStatus(DelectStatusEnum.DELECT_NO.getStatus());
        safeCheckPoint.setGmtCreate(new Date());
        safeCheckPoint.setCreateUserName(userInfo.getRealName());
        safeCheckPoint.setGmtModitify(new Date());
        safeCheckPoint.setLastEditUserName(userInfo.getRealName());
        safeCheckPoint.setEnterpriseId(userInfo.getEnterprise().getId());
        safeCheckPoint.setEnterpriseUuid(userInfo.getEnterprise().getUuid());
 
        safeCheckPointService.savePoint(safeCheckPoint);
 
        //释放分布式锁
        createPointLock.unlock();
    }
 
    /**
     * @description 根据巡检点id删除巡检点
     */
    @Transactional
    @Override
    public void deletePointById(ContextCacheUser currentUser, Long id) {
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
        //先判断这个point是否存在
        SafeCheckPoint safeCheckPoint = this.paramIsValidAndPointIsExit(id);
 
        safeCheckPoint.setDeleteStatus(DelectStatusEnum.DELECT_YES.getStatus());
        safeCheckPoint.setGmtModitify(new Date());
        safeCheckPoint.setLastEditUserName(userInfo.getRealName());
        safeCheckPointService.deletePointById(safeCheckPoint,DelectStatusEnum.DELECT_NO.getStatus().intValue());
    }
 
    /**
     * @description 根据巡检点id查询数据
     */
    @Override
    public SafeCheckPointRespDTO getPointById(Long id) {
        SafeCheckPointRespDTO safeCheckPointRespDTO = new SafeCheckPointRespDTO();
        SafeCheckPoint safeCheckPoint = this.paramIsValidAndPointIsExit(id);
        BeanUtils.copyProperties(safeCheckPoint,safeCheckPointRespDTO);
        return safeCheckPointRespDTO;
    }
 
    /**
     * @description 根据id更新巡检点
     */
    @Transactional
    @Override
    public void updatePointById(ContextCacheUser currentUser, SafeCheckPointReqDTO safeCheckPointReqDTO) {
        //获取用户信息
        ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
        UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
 
        String newPointName =  safeCheckPointReqDTO.getCode();
 
        if (newPointName == null || newPointName.length() == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"巡检点名称不能为空");
        }
 
        SafeCheckPoint oldPoint = this.paramIsValidAndPointIsExit(safeCheckPointReqDTO.getId());
 
        //0、加分布式锁
        String lockName = "SAFECHECK_POINT_UPDATE_"+newPointName;
        RLock updatePointLock = redissonClient.getLock(lockName);
        updatePointLock.lock(3, TimeUnit.SECONDS);
 
        SafeCheckPoint pointByName = safeCheckPointService.getPointByPointName(newPointName, DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        if (pointByName != null){
            if (!newPointName.equals(oldPoint.getCode())) {
                throw new AusinessException(E.DATA_DATABASE_EXIST, "巡检点名称已存在");
            }
        }
        BeanUtils.copyProperties(safeCheckPointReqDTO,oldPoint);
 
        oldPoint.setGmtModitify(new Date());
        oldPoint.setLastEditUserName(userInfo.getRealName());
        safeCheckPointService.updatePointById(oldPoint,DelectStatusEnum.DELECT_NO.getStatus().intValue());
 
        //1、释放分布式锁
        updatePointLock.unlock();
    }
 
 
    /**
     * @description 对巡检点id进行参数校验,以及数据库是否存在 存在即返回
     */
    private SafeCheckPoint paramIsValidAndPointIsExit(Long id){
 
        if (id == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"巡检点id不能为空");
        }
        SafeCheckPoint point = new SafeCheckPoint();
        point = safeCheckPointService.getOnePoint(id,DelectStatusEnum.DELECT_NO.getStatus().intValue());
        if (point == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"该巡检点数据库中不存在");
        }
        return point;
    }
 
    /**
     * @description 查询所有巡检点数据并进行分页展示
     */
    @Override
    public Page listPointByPage(Page pageInfo, SafeCheckPointPageReqDTO safeCheckPointPageReqDTO,ContextCacheUser currentUser) {
        List<SafeCheckPointPageRespDTO> safeCheckPointPageRespDTOS;
        String pointName = safeCheckPointPageReqDTO.getCode();
        Long regionId = safeCheckPointPageReqDTO.getRegionId();
 
        if (regionId == 1){
            regionId = null;
        }
        ListPointByPageDBQuery pageDBQuery = new ListPointByPageDBQuery();
        pageDBQuery.setPointName(pointName);
        pageDBQuery.setRegionId(regionId);
        List<Long> depIds = null;
        if (UserTypeEnum.STAFF.getCode() == currentUser.getType()){
            ResultVO<List<Long>> resultVO = accountDepartmentService.listDepAndSubDepIds(currentUser.getDepId());
            depIds = (List<Long>) resultVO.getData();
        }
        pageDBQuery.setDepIds(depIds);
 
        Page pageInfoResult = safeCheckPointService.listPointByPage(pageInfo,pageDBQuery);
 
 
        List<SafeCheckPoint> points = pageInfoResult.getRecords();
        if (CollectionUtils.isEmpty(points)){
            return null;
        }
        safeCheckPointPageRespDTOS = points.stream().map((point)->{
            SafeCheckPointPageRespDTO safeCheckPointPageRespDTO = new SafeCheckPointPageRespDTO();
            BeanUtils.copyProperties(point,safeCheckPointPageRespDTO);
            Long id = point.getRegionId();
            int rfidId = point.getRfidId();
 
            if (id != null) {
                SafeCheckRegion region = safeCheckRegionService.getOneRegion(id,DelectStatusEnum.DELECT_NO.getStatus().intValue());
                if (region != null){
                    safeCheckPointPageRespDTO.setRegionName(region.getRegion());
                }
            }
 
            if (rfidId != 0){
                SafeCheckRfid rfid = safeCheckRfidService.getRfidById(rfidId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
                if (rfid != null) {
                    safeCheckPointPageRespDTO.setRfidName(rfid.getRfidName());
                }
            }
            return safeCheckPointPageRespDTO;
        }).collect(Collectors.toList());
 
        pageInfoResult.setRecords(safeCheckPointPageRespDTOS);
 
        return pageInfoResult;
    }
 
    /**
     * @description 获取所有巡检点、巡检区域、巡检rfid的id值
     */
    @Override
    public List<SafeCheckPointRespDTO> getPointRegionRfidId() {
        List<SafeCheckPoint> points = safeCheckPointService.getPointRegionRfidId();
        if (points == null){
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"数据库无任何巡检点,请先新增巡检点");
        }
        List<SafeCheckPointRespDTO> pointRespDTOS = new ArrayList<>();
        pointRespDTOS = points.stream().map((point)->{
            SafeCheckPointRespDTO pointRespDTO = new SafeCheckPointRespDTO();
            BeanUtils.copyProperties(point,pointRespDTO);
            return pointRespDTO;
        }).collect(Collectors.toList());
        return pointRespDTOS;
    }
 
    /**
     * 获取所有的巡检指标
     */
    @Override
    public List<ListQuotasRespDTO> listQuotas(ContextCacheUser currentUser) {
        LambdaQueryWrapper<SafeCheckQuota> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SafeCheckQuota::getDeleteStatus,DelectStatusEnum.DELECT_NO.getStatus());
        List<SafeCheckQuota> quotas = safeCheckQuotaService.list(wrapper);
        if (CollectionUtils.isEmpty(quotas)){
            return null;
        }
        List<ListQuotasRespDTO> dtos = quotas.stream().map((quota) -> {
            ListQuotasRespDTO dto = new ListQuotasRespDTO();
            BeanUtils.copyProperties(quota, dto);
            return dto;
        }).collect(Collectors.toList());
        return dtos;
    }
}