package org.jeecg.modules.ctop.job;

import cn.com.ctop.common.module.entity.BindAccountLogin;
import cn.com.ctop.common.module.service.IBindAccountLoginService;
import cn.com.ctop.common.module.utils.CtopAdConstant;
import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.List;

@Slf4j
public class KuaishouCommentAutoLoginJob implements Job {
    @Value("${chrome.script.clean}")
    private String cleanUrl;
    @Autowired
    private IBindAccountLoginService bindAccountLoginService;
    @Autowired
    private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY,1);
        if(list!=null&&!list.isEmpty()){
            for (BindAccountLogin login:list) {
                if(null==login.getCookie()||"".equals(login.getCookie().trim())){
                    kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
                    Runtime runtime = Runtime.getRuntime();
                    try {
                        Process pro = runtime.exec(cleanUrl);
                        int status = pro.waitFor();
                        if (status == 0) {
                            log.info("success，删除评论调用shell脚本执行成功");
                        } else {
                            log.info("error，删除评论调用shell脚本执行失败");
                        }
                    } catch (Exception e) {
                        log.error(e.getMessage(),e);
                    }
                }
            }
        }
    }
}
