PmsSchedule4Count.java
package com.mycim.valueobject.ems;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.time.DateUtils;
import com.mycim.valueobject.SystemConstant;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
/**
* @Author: yibing.liu
* @Date: 2021/12/10 17:44
*/
public class PmsSchedule4Count extends PmsSchedule{
@Override
public PmsSchedule4Count newInstance() {
return new PmsSchedule4Count();
}
@Override
public void setToleranceStatusBase(int runCount) {
if (StringUtils.equalsIgnoreCase(this.getItemStatus(), SystemConstant.Str.ON)) {
int totalCount = this.getTotalCount();
int alarmCount = this.getAlarmCount();
double toleranceMax = totalCount + alarmCount - runCount;//设定的值 + 允许的差值 - 实际读取值
double specMax = totalCount - runCount;//设定的值 - 实际读取的值
double toleranceMin = totalCount - alarmCount - runCount;//设定的值 - 允许的差值 - 实际读取值
this.setToleranceStatus(PmControlTypeEnum.countStatus(toleranceMax, specMax, toleranceMin, true));
if (runCount > 0) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtils.DATE_FORMAT);
Date startDate = this.getCreateDate();
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
LocalDateTime startDateTime = LocalDateTime
.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
LocalDateTime now = LocalDateTime.now();
Duration duration = Duration.between(startDateTime, now);
long minutes = duration.toMinutes();//相差的分钟数
//每lot/wafer平均需要多少分钟
double avgRunQuantity = (double) minutes / runCount;
long prePMMinutes = (long) avgRunQuantity * (this.getTotalCount() - this.getAlarmCount());
long nextPmMinutes = (long) avgRunQuantity * this.getTotalCount();
long deadLineMinutes = (long) avgRunQuantity * (this.getTotalCount() + this.getAlarmCount());
LocalDateTime prePMDateTime = startDateTime.plusMinutes(prePMMinutes);//
LocalDateTime nextPmDateTime = startDateTime.plusMinutes(nextPmMinutes);
LocalDateTime deadLineDateTime = startDateTime.plusMinutes(deadLineMinutes);
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = nextPmDateTime.atZone(zoneId);
this.setPrePMTimee(dtf.format(prePMDateTime)); // 这些时间只在PM_TIME里有用。
this.setNextPmTime(Date.from(zdt.toInstant()));
this.setNextPmTimeStr(dtf.format(nextPmDateTime));
this.setDeadLine(dtf.format(deadLineDateTime));
this.setRunLotCount(String.valueOf(runCount));
} else {
this.setPrePMTimee("");
this.setNextPmTime(null);
this.setNextPmTimeStr("");
this.setDeadLine("");
}
}
}
}