package com.jjt.utils;

import com.jjt.biz.service.IApiService;
import com.jjt.calc.service.ITwinCalcHourEnergyService;
import com.jjt.calc.service.ITwinCalcHourService;
import com.jjt.calc.service.ITwinCalcHourYhjService;
import com.jjt.rz.service.ITwinCalcHourRzService;
import com.jjt.vms.service.IWmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 初始化启动处理
 *
 * @author wukai
 * @date 2024/5/4 20:35
 */
@Service
@Slf4j
public class InitService {
    @Resource
    private IApiService apiService;
    @Resource
    private ITwinCalcHourService twinCalcHourService;
    @Resource
    private Environment env;
    @Resource
    private IotService iotService;
    @Resource
    private IWmsService wmsService;
    @Resource
    private ITwinCalcHourYhjService twinCalcHourYhjService;
    @Resource
    private ITwinCalcHourEnergyService twinCalcHourEnergyService;
    @Resource
    private ITwinCalcHourRzService rzService;

    @PostConstruct
    public void init() {
        String[] activeProfiles = env.getActiveProfiles();
        boolean prod = false;
        for (String profile : activeProfiles) {
            if (profile.equals("prod")) {
                prod = true;
                System.err.println("Active Profile: " + profile);
            }
        }
        if (prod) {
            //设置iotToken
            iotService.setToken();
            //补录印花线数据
            twinCalcHourYhjService.calc2Curr();
            //补录染整参数数据
            rzService.calc2Curr();
            //补录能耗数据至当前时间
            twinCalcHourEnergyService.calc2Curr();
            //补录经编车间数据至当前时间
            twinCalcHourService.calc2Curr();
            //当前数据
            apiService.curr();
            //当天统计
            apiService.today();
            //当前库存
            wmsService.currStock();
        }
    }
}
