package com.mortals.xhx.modules.information.task;

import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.dao.ICRUDSubmeterDao;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.TableParam;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.base.system.table.service.TableIndexService;
import com.mortals.xhx.common.utils.DateByAffairUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author liaoxin
 * @Date: 2021-08-2021/8/4-16:19
 * @Description:
 */
@Component("createTableTaskImpl")
@Slf4j
public class CreateTableTaskImpl implements ITaskExcuteService {
    private static Object Double;
    @Autowired
    private TableIndexService tableIndexService;


    @Override
    public void excuteTask(ITask task) throws AppException {
            Map<String, ICRUDSubmeterDao> map = GlobalSysInfo.getBeansByType(ICRUDSubmeterDao.class);
            if (map == null || map.isEmpty()) {
                return;
            }
            Date currDate = new Date();
            Set<String> existsTables = tableIndexService.findLastMonthTables();
            TableParam param = new TableParam();
            param.unionTime = currDate;
            param.filterTables = existsTables;
            param.isCreateTable = true;
            for (Map.Entry<String, ICRUDSubmeterDao> entry : map.entrySet()) {
                tableIndexService.createTable(entry.getValue(), param);
            }
        log.info("表创建完成！");
    }

    @Override
    public void stopTask(ITask task) throws AppException {

    }

}
