注解@Scheduled 启动服务时执行任务(定时器)

package com.amc.qcmtt.oee.util;

import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.amc.qcmtt.oee.model.OeeInModel;
import com.amc.qcmtt.oee.model.OeeOutModel;
import com.amc.qcmtt.oee.model.OeeParaSetModel;
import com.amc.qcmtt.oee.service.OeeInService;
import com.amc.qcmtt.oee.service.OeeOutService;
import com.amc.qcmtt.oee.service.OeeParaSetService;

/**
 * 定时器  随着项目启动而执行 
 * OeeMonitorlogin名字自定义的(需要注意的是别被拦截器拦截即可)
 * @Scheduled(cron="*/60 * * * * ?") 1分钟执行一次
 */
@Component("OeeMonitorlogin")
public class OeeMonitor implements InitializingBean{

    @Autowired
    private OeeInService oeeInService;

    @Autowired
    private OeeOutService oeeOutService;

    @Autowired
    private OeeParaSetService oeeParaSetService;

    @Scheduled(cron="*/60 * * * * ?")
    @Transactional
    public void OeeMonitor() {
        List<OeeParaSetModel> listOeeParaSetModel = oeeParaSetService.findAll(OeeParaSetModel.class);
        for (int i = 0; i < listOeeParaSetModel.size(); i++) {
            OeeParaSetModel oeeParaSetModel = listOeeParaSetModel.get(i);
            Float lowSpeRunTime = Float.valueOf(oeeInService.lowSpeRunTime(listOeeParaSetModel.get(i).getServerkey(),
                    listOeeParaSetModel.get(i).getOpTime(), listOeeParaSetModel.get(i).getEnTime(),
                    listOeeParaSetModel.get(i).getPowRat()));
            OeeInModel oeeIn = new OeeInModel();
            oeeIn.setPlannedDowntime(Float.parseFloat(oeeParaSetModel.getpDD()));
            oeeIn.setLowSpeRunTime(lowSpeRunTime);
            oeeIn.setNonProLossTime(oeeParaSetModel.getUnqualNum() / Float.valueOf(oeeParaSetModel.getEquipCap()));
            OeeInterface oeeUtil = new OeeUtil();
            OeeOutModel oeeOut = new OeeOutModel();
            oeeOut.setpPT(oeeUtil.pPT(oeeIn, Float.valueOf(oeeParaSetModel.getsWST())));
            oeeOut.setoT(oeeUtil.oT(oeeIn));
            oeeOut.setnOTime(oeeUtil.nOTime(oeeIn));
            oeeOut.setnPLT(oeeUtil.nPLT(oeeIn));
            oeeOut.setvOT(oeeUtil.vOT());
            oeeOut.seteU(oeeUtil.eU());
            oeeOut.seteA(oeeUtil.eA());
            oeeOut.setpE(oeeUtil.pE());
            oeeOut.setrQ(oeeUtil.rQ());
            oeeOut.setoEE(oeeUtil.oEE());
            oeeOut.settEEP(oeeUtil.tEEP());
            oeeOut.setServerkey(listOeeParaSetModel.get(i).getServerkey());
            OeeOutModel oeeOutModel = new OeeOutModel();
            oeeOutService.saveOeeOut(oeeOut, oeeOutModel);
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        // TODO Auto-generated method stub
        this.OeeMonitor();
    }

}

参考:https://blog.csdn.net/jack_bob/article/details/78786740

           https://www.cnblogs.com/dyppp/p/7498457.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值