package cn.ezhizao.framework.enbust;


import cn.ezhizao.project.fegin.IFeignClient;
import cn.ezhizao.project.tenant.domain.Tenant;
import cn.ezhizao.project.tenant.service.ITenantService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.sql.Array;
import java.util.Arrays;
import java.util.Date;
import java.util.List;


@Component("entrust")
public class EntrustTask {

    private static final Logger log = LoggerFactory.getLogger(EntrustTask.class);
    @Resource
    private IFeignClient entrustFeignClient;
    @Resource
    private ITenantService tenantService;

    public void start() {
        System.out.println(111);
    }

    public void next() {
        try {
            log.info("定时任务开始执行" + new Date());
            //非工厂 -- 门店  !4
            List<Tenant> storeList = tenantService.list(new LambdaQueryWrapper<Tenant>().in(Tenant::getVersionId, Arrays.asList(1, 2)));
            if (storeList != null) {
                entrustFeignClient.transNext(storeList);
            }
//            log.info("非工厂执行完毕" + new Date());
            //工厂   4
//                List<Tenant> factoryList = tenantService.list(new LambdaQueryWrapper<Tenant>().eq(Tenant::getVersionId, 4));
//                if (factoryList != null) {
//                    for (Tenant tenant : factoryList) {
//                        entrustFeignClient.transNextFactory(tenant.getId());
//                    }
//                }
//                log.info("工厂执行完毕" + new Date());
            log.info("定时任务成功" + new Date());
        } catch (Exception e) {
            log.info("定时任务出错" + e.getMessage());
        }
    }


}