package cn.com.ctop.job.bytedance.handler;

/**
 *  Created by JQ.bi on 2020.11.16
 */

import cn.com.ctop.common.module.entity.CtopOauthToken;
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
import cn.com.ctop.toutiao.modules.report.service.IRuleByteDanceAccountService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class RuleDataAccountCleanJob {
    @Autowired
    private ICtopOauthTokenService oauthTokenService;
    @Autowired
    private IRuleByteDanceAccountService ruleByteDanceAccountService;
    private ExecutorService executorService = Executors.newFixedThreadPool(10);
    @XxlJob("ruleDataAccountCleanJob")
    public void execute() throws Exception {
        XxlJobHelper.log("规则预警账户维度数据开始清洗");
        List<CtopOauthToken> tokens = oauthTokenService.selectToutiaoToken();
        tokens.forEach(token -> executorService.submit(()->{
            Map<String,Object> params = new HashMap<>();
            params.put("account_id",token.getAccountId());
            ruleByteDanceAccountService.removeByMap(params);
            ruleByteDanceAccountService.cleanRuleDataAccount(token.getAccountId());
        }));
    }
}
