SyncCustomerSubscribeState.java 2.85 KB
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());
        }
    }
}