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();
}
}
注解@Scheduled 启动服务时执行任务(定时器)
最新推荐文章于 2024-08-14 10:36:30 发布