WeQrCodeUpdateTask.java
4.31 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
package com.linkwechat.quartz.task;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Week;
import cn.hutool.core.util.ObjectUtil;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeExternalContactClient;
import com.linkwechat.wecom.domain.WeQrCode;
import com.linkwechat.wecom.domain.dto.WeContactWayDto;
import com.linkwechat.wecom.domain.dto.WeExternalContactDto;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopePartyVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeUserVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeVo;
import com.linkwechat.wecom.service.IWeQrCodeService;
import com.linkwechat.wecom.service.IWeQrScopeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author danmo
* @description 活码使用范围修改任务
* @date 2021/11/13 23:02
**/
@Slf4j
@Component()
public class WeQrCodeUpdateTask {
@Autowired
private IWeQrScopeService weQrScopeService;
@Autowired
private IWeQrCodeService weQrCodeService;
@Autowired
private WeExternalContactClient externalContactClient;
private void qrCodeUpdateTask() {
Date date = new Date();
Week week = DateUtil.dayOfWeekEnum(date);
String formatTime = DateUtil.formatTime(date);
List<WeQrScopeVo> weQrScopeList = weQrScopeService.getWeQrScopeByTime(week.getValue(), formatTime);
if (CollectionUtil.isNotEmpty(weQrScopeList)) {
List<WeQrScopeVo> weCustomizeQrScopeList = weQrScopeList.stream().filter(item -> ObjectUtil.equal(1, item.getType())).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(weCustomizeQrScopeList)) {
weCustomizeQrScopeList.forEach(this::extracted);
} else {
WeQrScopeVo weDefaultQrScope = weQrScopeList.stream().filter(item -> ObjectUtil.equal(0, item.getType())).findFirst().orElse(null);
if (weDefaultQrScope != null) {
extracted(weDefaultQrScope);
}
}
}
}
private void extracted(WeQrScopeVo weQrScope) {
WeQrCode weQrCode = weQrCodeService.getById(weQrScope.getQrId());
String configId = weQrCode.getConfigId();
WeContactWayDto contactWay = externalContactClient.getContactWay(configId);
if (contactWay != null && ObjectUtil.equal(0, contactWay.getErrcode())) {
String userIds = "";
String partys = "";
String qrUserIds = "";
String qrPartys = "";
if (CollectionUtil.isNotEmpty(contactWay.getContactWay().getUser())) {
userIds = String.join(",", contactWay.getContactWay().getUser());
}
if (CollectionUtil.isNotEmpty(contactWay.getContactWay().getParty())) {
partys = contactWay.getContactWay().getParty().stream().map(String::valueOf).collect(Collectors.joining(","));
}
if (CollectionUtil.isNotEmpty(weQrScope.getWeQrUserList())) {
qrUserIds = weQrScope.getWeQrUserList().stream().map(WeQrScopeUserVo::getUserId).collect(Collectors.joining(","));
}
if (CollectionUtil.isNotEmpty(weQrScope.getWeQrPartyList())) {
qrPartys = weQrScope.getWeQrPartyList().stream().map(WeQrScopePartyVo::getParty).collect(Collectors.joining(","));
}
if (!ObjectUtil.equal(qrUserIds, userIds) || !ObjectUtil.equal(qrPartys, partys)) {
WeExternalContactDto.WeContactWay weContactWay = new WeExternalContactDto.WeContactWay();
weContactWay.setConfig_id(configId);
if (StringUtils.isNotEmpty(qrUserIds)) {
weContactWay.setUser(qrUserIds.split(","));
}
if (StringUtils.isNotEmpty(qrPartys)) {
Long[] qrPartyList = Arrays.stream(qrPartys.split(","))
.map(s -> Long.parseLong(s.trim())).toArray(Long[]::new);
weContactWay.setParty(qrPartyList);
}
externalContactClient.updateContactWay(weContactWay);
}
}
}
}