SyncCustomerSubscribeState.java
2.85 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
package cn.com.glsx.entmicro.job;
import cn.com.glsx.entmicro.service.SyncDataService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @Description 同步客户关注公众号状态
* @author chizw
* @create 2022/7/10 14:48
* @version ver.1.0.0
*/
@Slf4j
@Component
@ElasticSimpleJob(jobName = "SyncCustomerSubscribeState", cron = "0 0 0 * * ?")
public class SyncCustomerSubscribeState implements SimpleJob {
@Resource
private SyncDataService syncDataService;
// 定时任务开启
@Value("${scrm_subscribe_job_enabled}")
private String jobEnabled;
@Autowired
private Environment environment;
@Override
public void execute(ShardingContext shardingContext) {
try {
if (!StringUtils.isEmpty(jobEnabled) && Boolean.parseBoolean(jobEnabled)){
// 同步公众号关注列表
syncDataService.syncWechatSubscriberMapping();
log.info("同步公众号关注列表完成");
String merchantIdScan = environment.getProperty("scrm_subscribe_merchantId_scan");
List<Integer> merchantIdList = new ArrayList<>();
if (!StringUtils.isEmpty(merchantIdScan)){
String[] split = StringUtils.split(merchantIdScan, ",");
for (String s : split) {
merchantIdList.add(Integer.valueOf(s));
}
}
log.info("同步关注公众号状态商户号 merchantIdList:{}",merchantIdList);
if (!CollectionUtils.isEmpty(merchantIdList)){
for (Integer merchantId : merchantIdList) {
// 同步是否关注公众号状态
log.info("开始同步客户关注公众号状态 merchantId:{}",merchantId);
syncDataService.syncCustomerSubscribe(merchantId);
}
}else {
log.info("开始同步客户关注公众号状态all");
syncDataService.syncCustomerSubscribe(null);
}
log.info("同步客户关注公众号状态成功");
}
} catch (Exception e) {
e.printStackTrace();
log.error("同步客户关注公众号状态异常,msg:"+e.getMessage());
}
}
}