CommonBizService.java
51.7 KB
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
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
package cn.fw.dalaran.service.biz;
import cn.fw.dalaran.common.exception.BusinessException;
import cn.fw.dalaran.common.utils.DateUtil;
import cn.fw.dalaran.common.utils.ImageUtils;
import cn.fw.dalaran.common.utils.StringUtils;
import cn.fw.dalaran.domain.db.*;
import cn.fw.dalaran.domain.db.config.ValidConfig;
import cn.fw.dalaran.domain.db.config.ValidConfigNew;
import cn.fw.dalaran.domain.dto.LivePoolDto;
import cn.fw.dalaran.domain.dto.VideoPoolDto;
import cn.fw.dalaran.domain.enums.*;
import cn.fw.dalaran.domain.vo.ValidConfigNewVo;
import cn.fw.dalaran.service.Common;
import cn.fw.dalaran.service.data.*;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author kurisu
* @date 2021-12-04 14:29
* @description 通用服务
*/
@Slf4j
@Service
@RequiredArgsConstructor
@SuppressWarnings("Duplicates")
public class CommonBizService {
@Value("${spring.profiles.active}")
private String env;// 获取系统当前环境
private final Common common;
private final AccountService accountService;
private final VideoPoolService videoPoolService;
private final LivePoolService livePoolService;
private final ValidConfigService validConfigService;// 直播/视频有效性
private final ValidConfigNewService validConfigNewService;// 直播/视频有效性
private final ActivityThemeService activityThemeService;// 主题配置
private final GlobalConfigService globalConfigService;
private final ThemeFileService themeFileService;
private final DisqualificationRecordBizService disqualificationRecordBizService;
/**
* 储存短视频数据
*
* @param videoPoolDTO 自媒体服务器传过来的视频池
*/
public boolean saveVideoData(VideoPoolDto videoPoolDTO) {
String account = videoPoolDTO.getAccount();
Integer type = videoPoolDTO.getType();
List<Account> accountList = queryAccList(account, type);
if (CollectionUtils.isEmpty(accountList)) {
log.info(String.format("不存在[%s]平台, 账号为: %s的账号, 视频保存失败", PlatformEnum.getNameByVale(type), account));
return false;
}
List<VideoPoolDto.VideoDTO> videoList = videoPoolDTO.getVideoList();
if (CollectionUtils.isEmpty(videoList)) {
return true;
}
if (!this.acceptData()) {
log.info(String.format("%s 的视频数据提交时间已超当日期限, 数据将不保存到视频池", account));
return true;
}
for (Account db : accountList) {
saveVideoPoolList(db, videoList);
}
return true;
}
/**
* 储存直播数据
*
* @param livePoolDTO 自媒体服务器传过来的直播池
*/
public boolean saveLiveData(LivePoolDto livePoolDTO) {
String account = livePoolDTO.getAccount();
Integer type = livePoolDTO.getType();
List<Account> accountList = queryAccList(account, type);
if (CollectionUtils.isEmpty(accountList)) {
log.info(String.format("不存在[%s]平台, 账号为: %s的账号, 直播保存失败", PlatformEnum.getNameByVale(type), account));
return false;
}
List<LivePoolDto.LiveDTO> liveList = livePoolDTO.getLiveList();
if (CollectionUtils.isEmpty(liveList)) {
return true;
}
if (!this.acceptData()) {
log.info(String.format("%s 的直播数据提交时间已超当日期限, 数据将不保存到直播池", account));
return true;
}
for (Account db : accountList) {
saveLivePoolList(db, liveList);
}
return true;
}
/**
* 是否保存数据入池
*/
public boolean acceptData() {
/*if (env.contains("prd")) {
long acceptDataMaxTime = DateUtil.getBeginInTime(new Date()).getTime() + 27 * 1800 * 1000L;
return System.currentTimeMillis() - acceptDataMaxTime <= 0;
}
return true;*/
return true;
}
/**
* 查询指定类型的账号列表
*
* @param account 账户号
* @param type 账户类型
* @return
*/
private List<Account> queryAccList(String account, Integer type) {
PlatformEnum platformEnum = PlatformEnum.ofValue(type);
if (Objects.isNull(platformEnum)) {
return new ArrayList<>();
}
List<Account> accountList = accountService.list(Wrappers.<Account>lambdaQuery()
.eq(Account::getAccount, account)
.eq(Account::getType, platformEnum)
.eq(Account::getYn, Boolean.TRUE)
);
return CollectionUtils.isEmpty(accountList) ? new ArrayList<>() : accountList;
}
/**
* 保存视频池列表
*
* @param account 账户
* @param videoList 该账户的视频信息
*/
private void saveVideoPoolList(Account account, List<VideoPoolDto.VideoDTO> videoList) {
List<VideoPool> poolList = new ArrayList<>();
LocalDate today = LocalDate.now();
Long groupId = account.getGroupId();
Long shopId = account.getShopId();
String accountNo = account.getAccount();
PlatformEnum platformEnum = account.getType();
String platformName = platformEnum.getName();
List<ActivityTheme> thisMonthThemeList = this.getGroupActivityTheme(groupId, shopId, false);
List<ActivityTheme> themeList = thisMonthThemeList;
Date themeStartTime;// 主题活动开始时间
Date themeEndTime;// 主题活动结束时间
ValidConfigNew thisThemeFilterTopic = this.getIsFilterTagsConfig(themeList.get(0).getConfigGroupId());
ValidConfigNew config;
List<String> userDisqualificationWorkIds = disqualificationRecordBizService
.getUserDisqualificationRecords(accountNo, WorksTypeEnum.VIDEO, DateUtil.minusDays(new Date(), 1))
.stream()
.map(DisqualificationRecordEntity::getWorksId)
.collect(Collectors.toList());
for (VideoPoolDto.VideoDTO videoDTO : videoList) {
{// 让主题相关信息初始化到本月本天
themeList = thisMonthThemeList;
themeStartTime = themeList.get(0).getStartTime();// 获取最新的一个主题活动开始时间
themeEndTime = themeList.get(0).getEndTime();// 获取最新的一个主题活动结束时间
config = thisThemeFilterTopic;
}
String videoId = videoDTO.getVideoId();// 获取视频id
Date publishTime = videoDTO.getPublishTime();// 获取视频发布时间
String videoCover = videoDTO.getPreview();
String format = String.format("账户号为: %s, id为: %s, %s平台的视频", accountNo, videoId, platformName);
long timeSub = System.currentTimeMillis() - themeStartTime.getTime();
if (2 * 24 * 3600 * 1000L < timeSub && timeSub < 3 * 24 * 3600 * 1000L)// 新主题开始第二天了
if (themeList.size() > 1) {// 目前不止一个主题
Date lastThemeEndTime = themeList.get(1).getEndTime();
long timeSub1 = lastThemeEndTime.getTime() - publishTime.getTime();
if (0 < timeSub1 && timeSub1 < 12 * 3600 * 1000L) {// 说明是上一个主题结束时间的中午发布的
themeStartTime = themeList.get(1).getStartTime();// 获取上一个主题活动开始时间
themeEndTime = themeList.get(1).getEndTime();// 获取上一个主题活动结束时间
}
}
if (Objects.equals(today.getDayOfMonth(), 2)) {// 今天是这个月的第2天
LocalDateTime publishTime1 = DateUtil.date2LocalDateTime(publishTime);
LocalDateTime lastMonthLastDayAfternoon = today.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).atTime(12, 0, 0);
LocalDateTime lastMonthLastDayEndTime = today.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59);
if (publishTime1.compareTo(lastMonthLastDayAfternoon) >= 0 && publishTime1.compareTo(lastMonthLastDayEndTime) <= 0) {// 作品是上个主题中午12点后发布的
themeList = this.getGroupActivityTheme(groupId, shopId, true);
themeStartTime = themeList.get(0).getStartTime();// 获取最新的一个主题活动开始时间
themeEndTime = themeList.get(0).getEndTime();// 获取最新的一个主题活动结束时间
config = this.getIsFilterTagsConfig(themeList.get(0).getConfigGroupId());
}
}
List<ActivityTheme> collect = themeList.stream()
.filter(item -> publishTime.compareTo(item.getStartTime()) >= 0 && publishTime.compareTo(item.getEndTime()) <= 0)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)) {
log.info(String.format(" %s, 不是该月发布的视频, 视作无效视频", format));
continue;
}
VideoPool videoPool = new VideoPool();
if (publishTime.compareTo(themeStartTime) >= 0 && publishTime.compareTo(themeEndTime) <= 0) {
/* 话题验证 */
Set<String> tagsSet = this.processTags(videoDTO.getTitle());
ValidResult result = this.validTags(config, collect, tagsSet, groupId, shopId);
if (!result.getContainsTag()) {
if (!userDisqualificationWorkIds.contains(videoId)) {
log.info(String.format("%s, 不包含主题指定的话题, 未能成功进入视频池", format));
disqualificationRecordBizService.saveDisqualificationRecord(
disqualificationRecordBizService.createVideoDisqualificationRecord(account, result,
videoDTO, DisqualificationEnum.TAGS)
);
}
continue;
}
/* 封面图验证 */
boolean validCover = false;
ActivityTheme activityTheme = collect.get(0);
Long configGroupId = activityTheme.getConfigGroupId();
BigDecimal rate = this.getGlobalConfigValue(configGroupId, ConfigEnum.COVER_SIMILARITY);
List<ThemeFile> list = themeFileService.lambdaQuery()
.eq(ThemeFile::getThemeId, activityTheme.getId())
.eq(ThemeFile::getType, FileTypeEnum.THEME_COVER.getValue())
.list();
for (ThemeFile themeFile : list) {
try {
BigDecimal coverSimilarity = this.validCover(activityTheme.getTheme(), themeFile.getThemeId(),
themeFile.getFileId(), videoCover, accountNo, videoId, 1);
if (validCover = coverSimilarity.compareTo(rate) >= 0)
break;
} catch (Exception e) {
log.error(String.format("%s, 验证封面图出现异常", format), e);
}
}
if (!validCover) {
if (!userDisqualificationWorkIds.contains(videoId)) {
log.info(String.format("%s, 封面图不匹配, 视作无效视频", format));
disqualificationRecordBizService.saveDisqualificationRecord(
disqualificationRecordBizService.createVideoDisqualificationRecord(account, result,
videoDTO, DisqualificationEnum.COVER)
);
}
continue;
}
/* 指标验证 */
boolean validVideo = this.newValidVideo(account, configGroupId, videoDTO);
if (!validVideo) {
log.info(String.format("%s, 指标数据不满足集团标准, 视作无效视频", format));
}
if (validVideo) {
videoPool.setValidVideo(1);
} else {
videoPool.setValidVideo(0);
}
videoPool.setAccountId(account.getId());
videoPool.setPlatform(platformEnum);
videoPool.setVideoId(videoId);
videoPool.setPlayUrl(videoDTO.getPlayUrl());
videoPool.setTitle(videoDTO.getTitle());
videoPool.setPreview(videoCover);
videoPool.setUv(videoDTO.getUv());
videoPool.setFullUv(videoDTO.getFullUv());
videoPool.setLikeNum(videoDTO.getLikeNum());
videoPool.setShareNum(videoDTO.getShareNum());
videoPool.setCommentNum(videoDTO.getCommentNum());
videoPool.setNewFanNum(videoDTO.getNewFanNum());
videoPool.setDuration(videoDTO.getDuration());
videoPool.setThemeId(result.getThemeId());
videoPool.setTheme(result.getThemeName());
videoPool.setTags(this.collection2String(tagsSet));
videoPool.setPublishTime(publishTime);
} else {
log.info(String.format("%s, 不在目前最新活动时间内, 尝试查询历史记录", format));
VideoPool latestVideo = videoPoolService.getLatestVideo(videoId);
if (Objects.isNull(latestVideo)) {
log.info(String.format("%s, 不在目前最新活动时间内, 且无历史记录, 不进入视频池", format));
continue;
}
videoPool = latestVideo;
}
poolList.add(videoPool);
}
videoPoolService.removeAccountDataByDate(account.getId(), today);
videoPoolService.saveBatch(poolList);
}
/**
* 校验该视频是否符合集团配置的标准
*
* @param groupId 集团id
* @param video 视频信息
* @return 该条视频是否符合集团配置的标准
*/
@Deprecated
private boolean validVideo(Long groupId, VideoPoolDto.VideoDTO video) {
ValidConfig config = validConfigService.lambdaQuery()
.eq(ValidConfig::getGroupId, groupId)
.list().get(0);
if (config.getLikeCntEffectVideo() > 0) {
if (video.getLikeNum() < config.getLikeCntVideo()) {
return false;
}
}
if (config.getCommentCntEffectVideo() > 0) {
if (video.getCommentNum() < config.getCommentCntVideo()) {
return false;
}
}
if (config.getShareCntEffectVideo() > 0) {
if (video.getShareNum() < config.getShareCntVideo()) {
return false;
}
}
if (config.getNewFansCntEffectVideo() > 0) {
if (video.getNewFanNum() < config.getNewFansCntVideo()) {
return false;
}
}
if (config.getPlayCntEffect() > 0) {
if (video.getUv() < config.getPlayCnt()) {
return false;
}
}
if (config.getFullPlayCntEffect() > 0) {
if (video.getFullUv() < config.getFullPlayCnt()) {
return false;
}
}
return true;
}
/**
* 测试
*/
@Scheduled(fixedRate = 5000L)
public void test() {
}
@Data
public static class ValidVideoResult {
private Boolean valid;
}
/**
* new校验该视频是否符合集团配置的标准
*
* @param configGroupId 所属配置组id
* @param video 视频信息
* @return 该条视频是否符合集团配置的标准
*/
private boolean newValidVideo(Account account, Long configGroupId, VideoPoolDto.VideoDTO video) {
String accountNo = account.getAccount();
PlatformEnum platformEnum = account.getType();
String platformName = platformEnum.getName();
String videoId = video.getVideoId();
List<ValidConfigNew> configList = validConfigNewService
.queryList(configGroupId, WorksTypeEnum.VIDEO.getValue())
.getDetails()
.stream()
.map(ValidConfigNewVo::toDB)
.sorted(Comparator.comparing(ValidConfigNew::getIndexType))
.skip(1)
.collect(Collectors.toList());// 获取配置组的短视频检验最低标准指标
int indexCnt = ValidVideoEnum.values().length - 1;// 获取视频指标配置项数目
LocalDate now = LocalDate.now();
String format = String.format("%s 账户号为: %s, id为: %s, %s平台的视频", now, accountNo, videoId, platformName);
if (indexCnt > 0) {
ValidConfigNew playCntConfig = configList.get(0);// 播放数
if (playCntConfig.getValid() > 0) {
Integer playCnt = video.getUv();
if (Objects.isNull(playCnt)) {
log.error(String.format("%s[播放数]数据为空", format));
} else {
Integer minValue = playCntConfig.getMinValue();
if (playCnt < minValue) {
log.info(String.format("%s[播放数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
if (indexCnt > 1) {
ValidConfigNew fullPlayCntConfig = configList.get(1);// 完整播放数
if (fullPlayCntConfig.getValid() > 0) {
Integer fullPlayCnt = video.getFullUv();
if (Objects.isNull(fullPlayCnt)) {
log.error(String.format("%s[完整播放数]数据为空", format));
} else {
Integer minValue = fullPlayCntConfig.getMinValue();
if (fullPlayCnt < minValue) {
log.info(String.format("%s[完整播放数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
if (indexCnt > 2) {
ValidConfigNew likeCntConfig = configList.get(2);// 点赞数
if (likeCntConfig.getValid() > 0) {
Integer likeCnt = video.getLikeNum();
if (Objects.isNull(likeCnt)) {
log.error(String.format("%s[点赞数]数据为空", format));
} else {
Integer minValue = likeCntConfig.getMinValue();
if (likeCnt < minValue) {
log.info(String.format("%s[点赞数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
if (indexCnt > 3) {
ValidConfigNew commentCntConfig = configList.get(3);// 评论数
if (commentCntConfig.getValid() > 0) {
Integer commentCnt = video.getCommentNum();
if (Objects.isNull(commentCnt)) {
log.error(String.format("%s[评论数]数据为空", format));
} else {
Integer minValue = commentCntConfig.getMinValue();
if (commentCnt < minValue) {
log.info(String.format("%s[评论数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
if (indexCnt > 4) {
ValidConfigNew shareCntConfig = configList.get(4);// 分享数
if (shareCntConfig.getValid() > 0) {
Integer shareCnt = video.getShareNum();
if (Objects.isNull(shareCnt)) {
log.error(String.format("%s[分享数]数据为空", format));
} else {
Integer minValue = shareCntConfig.getMinValue();
if (shareCnt < minValue) {
log.info(String.format("%s[分享数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
if (indexCnt > 5) {
if (!Objects.equals(PlatformEnum.BILIBILI.getValue(), platformEnum.getValue())) {// bilibili视频[不过滤]增粉指标
ValidConfigNew newFansCntConfig = configList.get(5);// 增粉数
if (newFansCntConfig.getValid() > 0) {
Integer newFansCnt = video.getNewFanNum();
if (Objects.isNull(newFansCnt)) {
log.error(String.format("%s[增粉数]数据为空", format));
} else {
Integer minValue = newFansCntConfig.getMinValue();
if (newFansCnt < minValue) {
log.info(String.format("%s[增粉数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
}
return true;
}
/**
* 保存直播池列表
*
* @param account 账户
* @param liveList 该账户的直播信息
*/
private void saveLivePoolList(Account account, List<LivePoolDto.LiveDTO> liveList) {
List<LivePool> poolList = new ArrayList<>();
ValidConfigNew config = new ValidConfigNew();
LocalDate today = LocalDate.now();
Long groupId = account.getGroupId();
Long shopId = account.getShopId();
String accountNo = account.getAccount();
PlatformEnum platformEnum = account.getType();
String platformName = platformEnum.getName();
List<ActivityTheme> themeList = this.getGroupActivityTheme(groupId, shopId, false);
List<String> userDisqualificationWorkIds = disqualificationRecordBizService
.getUserDisqualificationRecords(accountNo, WorksTypeEnum.LIVE, DateUtil.minusDays(new Date(), 1))
.stream()
.map(DisqualificationRecordEntity::getWorksId)
.collect(Collectors.toList());
for (LivePoolDto.LiveDTO liveDTO : liveList) {
String roomNo = liveDTO.getRoomNo();
String liveCover = liveDTO.getCover();
String format = String.format("账户号为: %s, id为: %s, %s平台的直播", accountNo, roomNo, platformName);
Date liveStartTime = liveDTO.getLiveStartTime();
Set<String> tagsSet = this.processTags(liveDTO.getTitle());// 直播标题包含话题
List<ActivityTheme> collect = themeList.stream()
.filter(item -> liveStartTime.compareTo(item.getStartTime()) >= 0 && liveStartTime.compareTo(item.getEndTime()) <= 0)
.collect(Collectors.toList());// 作品发布时间和活动主题生效时间匹配的活动主题
ActivityTheme activityTheme = collect.get(0);
Long configGroupId = activityTheme.getConfigGroupId();// 获取主题所处配置组id
if (Objects.isNull(config.getMinValue()))
config = this.getIsFilterTagsConfig(configGroupId);
ValidResult result = this.validTags(config, collect, tagsSet, groupId, shopId);
/* 无回播的直播, 不进入直播池 */
String playbackUrl = liveDTO.getPlaybackUrl();
if (StringUtils.isEmpty(playbackUrl)) {
if (!userDisqualificationWorkIds.contains(roomNo)) {
log.info(String.format("%s, 无直播回放, 视作无效直播, 未能成功进入直播池", format));
disqualificationRecordBizService.saveDisqualificationRecord(
disqualificationRecordBizService.createLiveDisqualificationRecord(account, result,
liveDTO, DisqualificationEnum.LOSE_PLAYBACK)
);
}
continue;
}
/* 话题验证 */
if (!result.getContainsTag()) {
if (!userDisqualificationWorkIds.contains(roomNo)) {
log.info(String.format("%s, 不包含主题指定的话题, 未能成功进入直播池", format));
disqualificationRecordBizService.saveDisqualificationRecord(
disqualificationRecordBizService.createLiveDisqualificationRecord(account, result,
liveDTO, DisqualificationEnum.TAGS)
);
}
continue;
}
LivePool livePool = new LivePool();
/* 封面图验证 */
boolean validCover = false;
BigDecimal rate = this.getGlobalConfigValue(configGroupId, ConfigEnum.COVER_SIMILARITY);
List<ThemeFile> list = themeFileService.lambdaQuery()
.eq(ThemeFile::getThemeId, activityTheme.getId())
.eq(ThemeFile::getType, FileTypeEnum.THEME_COVER.getValue())
.list();
for (ThemeFile themeFile : list) {
try {
BigDecimal coverSimilarity = this.validCover(activityTheme.getTheme(), activityTheme.getId(),
themeFile.getFileId(), liveCover, accountNo, roomNo, 2);
if (validCover = coverSimilarity.compareTo(rate) >= 0)
break;
} catch (Exception e) {
log.error(String.format("%s, 验证封面图出现异常", format), e);
}
}
if (!validCover) {
if (!userDisqualificationWorkIds.contains(roomNo)) {
log.info(String.format("%s, 封面图不匹配, 视作无效直播", format));
disqualificationRecordBizService.saveDisqualificationRecord(
disqualificationRecordBizService.createLiveDisqualificationRecord(account, result,
liveDTO, DisqualificationEnum.COVER)
);
}
continue;
}
/* 指标验证, 付费判定 */
boolean validLive = this.newValidLive(account, configGroupId, liveDTO);// 是否满足指标
boolean pay = this.validPay(liveDTO, configGroupId);
if (!validLive) {
log.info(String.format("%s, 指标数据不满足集团标准, 视作无效直播", format));
livePool.setValidLive(0);
} else {
livePool.setValidLive(1);
if (pay) {
livePool.setValidLive(-1);
log.info(String.format("%s, 系统判定直播观看巅峰数据异常", format));
}
}
livePool.setAccountId(account.getId());
livePool.setPlatform(platformEnum);
livePool.setRoomNo(roomNo);
livePool.setPlaybackUrl(playbackUrl);
livePool.setUserNick(liveDTO.getUserNick());
livePool.setTitle(liveDTO.getTitle());
livePool.setCover(liveCover);
livePool.setUv(liveDTO.getUv());
livePool.setUvPeak(liveDTO.getUvPeak());
livePool.setLikeNum(liveDTO.getLikeNum());
livePool.setShareNum(liveDTO.getShareNum());
livePool.setCommentNum(liveDTO.getCommentNum());
livePool.setNewFanNum(liveDTO.getNewFanNum());
livePool.setReceiveNum(liveDTO.getReceiveNum());
livePool.setReceiveAmount(liveDTO.getReceiveAmount());
livePool.setLiveDuration(liveDTO.getLiveDuration());
livePool.setLiveStartTime(liveStartTime);
livePool.setLiveEndTime(liveDTO.getLiveEndTime());
livePool.setThemeId(result.getThemeId());
livePool.setTheme(result.getThemeName());
livePool.setTags(this.collection2String(tagsSet));
poolList.add(livePool);
}
livePoolService.removeAccountDataByDate(account.getId(), today);
livePoolService.saveBatch(poolList);
}
/**
* 观看巅峰数据异常判定
*
* @param live 直播数据
* @param configGroupId 配置组id
* @return 数据是否异常
*/
private boolean validPay(LivePoolDto.LiveDTO live, Long configGroupId) {
ValidConfigNew config = validConfigNewService.getOne(Wrappers.<ValidConfigNew>lambdaQuery()
.eq(ValidConfigNew::getConfigGroupId, configGroupId)
.eq(ValidConfigNew::getType, WorksTypeEnum.LIVE.getValue())
.eq(ValidConfigNew::getIndexType, ValidLiveEnum.PAY_LIVE_RATE.getValue()));
if (Objects.equals(config.getValid(), 0))
return false;
else
return live.getUvPeak() * config.getMinValue() >= live.getUv();
}
/**
* 校验该直播是否符合集团配置的标准
*
* @param groupId 集团id
* @param live 直播信息
* @return 该次直播是否符合集团配置的标准
*/
@Deprecated
private boolean validLive(Long groupId, LivePoolDto.LiveDTO live) {
ValidConfig config = validConfigService.lambdaQuery()
.eq(ValidConfig::getGroupId, groupId)
.list().get(0);
if (config.getLikeCntEffectLive() > 0) {
if (live.getLikeNum() < config.getLikeCntLive()) {
return false;
}
}
if (config.getCommentCntEffectLive() > 0) {
if (live.getCommentNum() < config.getCommentCntLive()) {
return false;
}
}
if (config.getShareCntEffectLive() > 0) {
if (live.getShareNum() < config.getShareCntLive()) {
return false;
}
}
if (config.getNewFansCntEffectLive() > 0) {
if (live.getNewFanNum() < config.getNewFansCntLive()) {
return false;
}
}
if (config.getWatchUserEffect() > 0) {
if (live.getUv() < config.getWatchUser()) {
return false;
}
}
if (config.getWatchUserPeakEffect() > 0) {
if (live.getUvPeak() < config.getWatchUserPeak()) {
return false;
}
}
if (config.getDurationEffect() > 0) {
if (live.getLiveDuration() < config.getDuration()) {
return false;
}
}
return true;
}
/**
* new校验该直播是否符合集团配置的标准
*
* @param account 账户信息
* @param configGroupId 所属配置组id
* @param live 直播信息
* @return 该次直播是否符合集团配置的标准
*/
private boolean newValidLive(Account account, Long configGroupId, LivePoolDto.LiveDTO live) {
String accountNo = account.getAccount();
PlatformEnum platformEnum = account.getType();
String platformName = platformEnum.getName();
String roomNo = live.getRoomNo();
List<ValidConfigNew> configList = validConfigNewService
.queryList(configGroupId, WorksTypeEnum.LIVE.getValue())
.getDetails()
.stream()
.map(ValidConfigNewVo::toDB)
.sorted(Comparator.comparing(ValidConfigNew::getIndexType))
.skip(2)
.collect(Collectors.toList());// 获取配置组的直播检验最低标准指标
int indexCnt = ValidLiveEnum.values().length - 2;// 获取直播指标配置项数目
String format = String.format("账户号为: %s, id为: %s, %s平台的直播", accountNo, roomNo, platformName);
if (indexCnt > 0) {
if (!Objects.equals(PlatformEnum.BILIBILI.getValue(), platformEnum.getValue())) {// bilibili直播[不过滤]观看人数
ValidConfigNew watchCntConfig = configList.get(0);// 观看人数
if (watchCntConfig.getValid() > 0) {
Long watchCnt = live.getUv();
if (Objects.isNull(watchCnt)) {
log.error(String.format("%s[观看人数]数据为空", format));
} else {
Integer minValue = watchCntConfig.getMinValue();
if (watchCnt < minValue) {
log.info(String.format("%s[观看人数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
}
if (indexCnt > 1) {
if (!Objects.equals(PlatformEnum.BILIBILI.getValue(), platformEnum.getValue())) {// bilibili直播[不过滤]观看人数巅峰
ValidConfigNew watchPeakCntConfig = configList.get(1);// 观看人数峰值
if (watchPeakCntConfig.getValid() > 0) {
Long watchCntPeak = live.getUvPeak();
if (Objects.isNull(watchCntPeak)) {
log.error(String.format("%s[观看人数巅峰]数据为空", format));
} else {
Integer minValue = watchPeakCntConfig.getMinValue();
if (watchCntPeak < minValue) {
log.info(String.format("%s[观看人数峰值]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
}
if (indexCnt > 2) {
if (Objects.equals(PlatformEnum.KS.getValue(), platformEnum.getValue())) {// 快手直播[才过滤]点赞指标
ValidConfigNew likeCntConfig = configList.get(2);// 点赞数
if (likeCntConfig.getValid() > 0) {
Long likeCnt = live.getLikeNum();
if (Objects.isNull(likeCnt)) {
log.error(String.format("%s[点赞数]数据为空", format));
} else {
Integer minValue = likeCntConfig.getMinValue();
if (likeCnt < minValue) {
log.info(String.format("%s[点赞数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
}
if (indexCnt > 3) {
ValidConfigNew commentCntConfig = configList.get(3);// 评论数
if (commentCntConfig.getValid() > 0) {
Long commentCnt = live.getCommentNum();
if (Objects.isNull(commentCnt)) {
log.error(String.format("%s[评论数]数据为空", format));
} else {
Integer minValue = commentCntConfig.getMinValue();
if (commentCnt < minValue) {
log.info(String.format("%s[评论数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
if (indexCnt > 4) {
if (Objects.equals(PlatformEnum.KS.getValue(), platformEnum.getValue())) {// 快手直播[才过滤]分享指标
ValidConfigNew shareCntConfig = configList.get(4);// 分享数
if (shareCntConfig.getValid() > 0) {
Long shareCnt = live.getShareNum();
if (Objects.isNull(shareCnt)) {
log.error(String.format("%s[分享数]数据为空", format));
} else {
Integer minValue = shareCntConfig.getMinValue();
if (shareCnt < minValue) {
log.info(String.format("%s[分享数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
}
if (indexCnt > 5) {
ValidConfigNew newFansCntConfig = configList.get(5);// 增粉数
if (newFansCntConfig.getValid() > 0) {
Long newFanCnt = live.getNewFanNum();
if (Objects.isNull(newFanCnt)) {
log.error(String.format("%s[增粉数]数据为空", format));
} else {
Integer minValue = newFansCntConfig.getMinValue();
if (newFanCnt < minValue) {
log.info(String.format("%s[增粉数]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
if (indexCnt > 6) {
ValidConfigNew durationCntConfig = configList.get(6);// 直播时长
if (durationCntConfig.getValid() > 0) {
Integer liveDuration = live.getLiveDuration();
if (Objects.isNull(liveDuration)) {
log.error(String.format("%s[直播时长]数据为空", format));
} else {
Integer minValue = durationCntConfig.getMinValue();
if (liveDuration < minValue) {
log.info(String.format("%s[直播时长]数据不满足集团配置标准(最低: %s)", format, minValue));
return false;
}
}
}
}
return true;
}
/**
* 将标题中的话题拿出来
*
* @param title 标题
* @return 话题集合
*/
private static Set<String> processTags(String title) {
title = title
.replace("#", "#")
.replace(" ", "")
.replace("\n", "")
.replace("—", "一");
String tagsStr = String.join("", StringUtils.matchs(title, StringUtils.tagsPattern));
return Arrays.stream(tagsStr.split("#"))
.map(item -> item.replace("#", ""))
.filter(item -> item.length() > 0)
.collect(Collectors.toSet());
}
public static void main(String[] args) {
System.out.println(System.getProperty("java.io.tmpdir"));
String workTitle = "#现车加\\\"免\\\"开新过新年";
String setTopic = "#温暖回家路提现车过新年,#现车加\\免\\开新过新年,#温暖回家路春节不打烊,#开年有礼大展宏兔,#智电超能体验,#开新年夜FUN,#温暖回家路一路有你,#展厅实车带货UNI-K iDD".replace(",", "");
Set<String> strings1 = processTags(workTitle);
Set<String> strings2 = processTags(setTopic);
System.out.println(CollectionUtils.containsAny(strings1, strings2));
}
/**
* 集合转换成字符串
*
* @param collection 输入集合
* @return 字符串类型的集合
*/
public static <Q> String collection2String(Collection<Q> collection) {
return JSON.toJSONString(collection)
.replace("[", "")
.replace("]", "")
.replace("\"", "");
}
/**
* 验证标题的话题
*
* @param config 集团是否过滤话题配置
* @param themeList 集团活动主题
* @param tags 话题集合
* @param groupId 集团id
* @param shopId 门店id
* @return 该视频/直播包含话题是否符合主题配置的话题
*/
private ValidResult validTags(ValidConfigNew config, List<ActivityTheme> themeList, Set<String> tags,
Long groupId, Long shopId) {
ValidResult result = new ValidResult();
if (config.getValid() <= 0) {// 配置不过滤话题
result.setContainsTag(true);
return result;
}
if (CollectionUtils.isEmpty(themeList)) {// 未配置活动主题
String format = String.format("集团id: %s, 门店id: %s未配置活动主题, 所有'直播'/'视频'数据都将无法保存", groupId, shopId);
log.error(String.format("%s, 请联系管理员配置活动主题或者禁用话题过滤", format));
throw new BusinessException(String.format("%s, 请联系管理员配置活动主题或者禁用话题过滤", format));
}
HashSet<Long> shopIds = new HashSet<>();
HashSet<String> configTags = new HashSet<>();// 主题包含话题
themeList.forEach(item -> {
configTags.addAll(Arrays.stream(item.getTopic().replace(",", "").split("#"))
.skip(1)
.collect(Collectors.toSet())
);
if (item.getAllShop() > 0) {
shopIds.add(-1L);
} else {
shopIds.addAll(Arrays.stream(item.getShopIds().split(","))
.map(Long::valueOf)
.collect(Collectors.toSet())
);
}
});// 找到所有活动主题的所有话题, 覆盖的所有门店
ActivityTheme activityTheme = themeList.get(0);
if (shopIds.contains(-1L) || shopIds.contains(shopId)) {
BigDecimal rate = this.getGlobalConfigValue(activityTheme.getConfigGroupId(), ConfigEnum.TOPIC_SIMILARITY);
boolean containsTag = false;
if (rate.compareTo(BigDecimal.valueOf(100)) == 0) {// 原方案
Set<String> resultSet = new HashSet<>(tags);
resultSet.retainAll(configTags);// 交集
//resultSet.removeAll(configTags);// 差集
//resultSet.addAll(configTags);// 并集
containsTag = !resultSet.isEmpty();
} else {// LCS计算话题匹配度
for (String configTag : configTags) {
for (String tag : tags) {
if (this.LCSCalcTopicSimilarity(rate, configTag, tag)) {
containsTag = true;
break;
}
}
if (containsTag)
break;
}
}
result.setContainsTag(containsTag);
} else {
result.setContainsTag(false);
}
result.setThemeId(activityTheme.getId());// 主题id
result.setThemeName(activityTheme.getTheme());// 主题名
result.setConfigTags(configTags);// 主题包含tags
result.setWorksTags(tags);// 作品包含tags
return result;
}
@Data
public static class ValidResult {
/**
* 是否包含指定话题
*/
private Boolean containsTag = false;
/**
* 主题id
*/
private Long themeId;
/**
* 主题名
*/
private String themeName;
/**
* 系统配置话题
*/
private Set<String> configTags = new HashSet<>();
/**
* 作品包含话题
*/
private Set<String> worksTags = new HashSet<>();
}
/**
* 获取集团是否过滤话题配置
*
* @param configGroupId 所属配置组id
* @return 集团是否过滤话题配置
*/
private ValidConfigNew getIsFilterTagsConfig(Long configGroupId) {
return validConfigNewService
.queryList(configGroupId, 3)
.getDetails()
.stream()
.map(ValidConfigNewVo::toDB)
.findFirst()
.orElse(null);
}
/**
* 获取集团活动主题
*
* @param groupId 集团id
* @param shopId 门店id
* @return 集团活动主题(全集团, 该门店)
*/
private List<ActivityTheme> getGroupActivityTheme(Long groupId, Long shopId, boolean queryLastMonth) {
Date yesterday, firstDayMin;
if (queryLastMonth) {
yesterday = DateUtil.localDateTime2Date(LocalDateTime.of(LocalDate.now().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()), LocalTime.of(12, 30, 0)));
firstDayMin = DateUtil.localDateTime2Date(LocalDateTime.of(LocalDate.now().minusMonths(1).with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN));
} else {
yesterday = new Date(System.currentTimeMillis() - 24 * 3600 * 1000L);
firstDayMin = DateUtil.localDateTime2Date(LocalDateTime.of(LocalDate.now().minusDays(1).withDayOfMonth(1), LocalTime.MIN));
}
List<ActivityTheme> list = activityThemeService.lambdaQuery()
.eq(ActivityTheme::getGroupId, groupId)
.and(wrapper -> wrapper
.le(ActivityTheme::getStartTime, firstDayMin)
.ge(ActivityTheme::getEndTime, firstDayMin)
.or()
.ge(ActivityTheme::getStartTime, firstDayMin)
.le(ActivityTheme::getEndTime, yesterday)
.or()
.le(ActivityTheme::getStartTime, yesterday)
.ge(ActivityTheme::getEndTime, yesterday)
.or()
.le(ActivityTheme::getStartTime, firstDayMin)
.ge(ActivityTheme::getEndTime, yesterday)
).list();
return list.stream()
.distinct()
.filter(item -> {
if (Objects.equals(item.getAllShop(), 1))
return true;
else
return Arrays.stream(item.getShopIds().split(","))
.map(Long::valueOf)
.collect(Collectors.toList())
.contains(shopId)
;
})
.sorted(Comparator.comparing(ActivityTheme::getStartTime).reversed())
.collect(Collectors.toList());
}
/**
* LCS计算话题匹配度
*
* @param setSimilarity 设置匹配度
* @param setTopic 主题设置话题
* @param userTopic 用户话题
* @return 话题匹配度是否合格
*/
private boolean LCSCalcTopicSimilarity(BigDecimal setSimilarity, String setTopic, String userTopic) {
int length = setTopic.length();
BigDecimal single = BigDecimal.valueOf(100).divide(BigDecimal.valueOf(length), 4, RoundingMode.HALF_UP);// 单个字占比
int m = setTopic.length();
int n = userTopic.length();
int[][] c = new int[m + 1][n + 1];
for (int i = 1; i < m + 1; i++) {
for (int j = 1; j < n + 1; j++) {
if (setTopic.charAt(i - 1) == userTopic.charAt(j - 1))
c[i][j] = c[i - 1][j - 1] + 1;
else
c[i][j] = Math.max(c[i - 1][j], c[i][j - 1]);
}
}
return c[setTopic.length()][userTopic.length()] >= setSimilarity.divideAndRemainder(single)[0].intValue();
}
/**
* 验证封面匹配度
*
* @param theme 主题名
* @param themeId 主题id
* @param fileId 文件id(主题配置指定封面图文件)
* @param coverUrl 用户作品封面图地址
* @param account 账户号
* @param itemId 作品id
* @param type 类型(1:视频, 2:直播)
* @return 封面图匹配度
* @throws Exception
*/
public BigDecimal validCover(String theme, Long themeId, String fileId, String coverUrl, String account, String itemId, Integer type) throws Exception {
int[][] imagePixArr1;// 图片1的像素数组
int[][] imagePixArr2;// 图片2的像素数组
File imageFile1 = this.findLocalCacheImageTheme(/*theme,*/ themeId, fileId);
imagePixArr1 = ImageUtils.readImagePixel(imageFile1);
File imageFile2;
File localCacheImage = this.findLocalCacheImageUser(/*theme,*/ themeId, account, itemId, type);
if (Objects.nonNull(localCacheImage)) {
imageFile2 = localCacheImage;
} else {
imageFile2 = ImageUtils.convertFileByUrl(coverUrl, itemId);
String tempDir = common.getActivityThemeCoverDir();
File file = new File(ImageUtils.modifyResolution1(imageFile2.getPath(),
tempDir + "activityTheme" + File.separator + themeId /*+ "#" + theme*/ + File.separator + account + File.separator + (Objects.equals(type, 1) ? "video" : "live"),
"fw_theme_cover_" + itemId,
512, 512));
if (imageFile2.delete()) {
imageFile2 = file;
}
}
imagePixArr2 = ImageUtils.readImagePixel(imageFile2);
String msg = String.format("\n 主题id: %s \n 主题名: %s\n 设置封面文件id: %s\n 账户号: %s\n %s%s\n", themeId, theme, fileId, account, Objects.equals(type, 1) ? "短视频id: " : "直播间号: ", itemId);
return BigDecimal.valueOf(ImageUtils.calcSimilarity(ImageUtils.getFingerprint(imagePixArr1), ImageUtils.getFingerprint(imagePixArr2), msg));
}
/**
* 获取本地已下载的封面图(用户作品封面图)
*
* @param theme 主题名
* @param themeId 主题id
* @param account 账号
* @param itemId 视频id/直播间id
* @param type 1:视频, 2:直播
*/
private File findLocalCacheImageUser(/*String theme,*/ Long themeId, String account, String itemId, Integer type) {
String tempDir = common.getActivityThemeCoverDir();
File file = new File(tempDir + File.separator + "activityTheme" + File.separator + themeId /*+ "#" + theme*/ + File.separator + account + File.separator + (Objects.equals(type, 1) ? "video" : "live"));
if (!file.exists()) {
boolean mkdirs = file.mkdirs();
if (mkdirs)
return null;
}
File imageFile = null;
for (File item : Objects.requireNonNull(file.listFiles())) {
if (item.getName().startsWith("fw_theme_cover_" + itemId)) {
imageFile = item;
break;
}
}
return imageFile;
}
/**
* 获取本地已下载的主题背景图(主题预设封面图)
*
* @param theme 主题名
* @param themeId 主题id
* @param fileId 文件id(主题配置指定封面图文件)
*/
private File findLocalCacheImageTheme(/*String theme,*/ Long themeId, String fileId) {
String tempDir = common.getActivityThemeCoverDir();
File file = new File(tempDir + "activityTheme" + File.separator + themeId /*+ "#" + theme*/ + File.separator + "settingCover");
if (!file.exists()) {
boolean mkdirs = file.mkdirs();
if (mkdirs)
return null;
}
File imageFile = null;
for (File item : Objects.requireNonNull(file.listFiles())) {
if (item.getName().startsWith("fw_theme_cover_" + fileId)) {
imageFile = item;
break;
}
}
return imageFile;
}
/**
* 获取配置值
*
* @param configGroupId 所属配置组id
* @param type 类型
* @return
*/
private BigDecimal getGlobalConfigValue(Long configGroupId, ConfigEnum type) {
Optional<GlobalConfig> first = Optional.ofNullable(globalConfigService.queryList(configGroupId))
.orElse(new ArrayList<>())
.stream()
.filter(item -> Objects.equals(item.getType(), type.getValue()))
.findFirst();
BigDecimal rate = BigDecimal.ZERO;
if (first.isPresent())
rate = first.get().getRate();
return rate;
}
}