|
|
|
@ -1,16 +1,27 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.base.IMesDowntimeRecordService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesDowntimeRecord;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesEquipment;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesDowntimeRecordRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesProductionRecordRepository;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description: 设备生产停机记录
|
|
|
|
@ -22,6 +33,12 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class MesDowntimeRecordServiceImpl extends BaseMesService<MesDowntimeRecord> implements IMesDowntimeRecordService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesProductionRecordRepository mesProductionRecordRDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesDowntimeRecordRepository mesDowntimeRecordRDao;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void setPackQueryBean(MesDowntimeRecord bean, DdlPackBean packBean) {
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(bean.getWorkCenterCode(), "workCenterCode", packBean);
|
|
|
|
@ -54,4 +71,50 @@ public class MesDowntimeRecordServiceImpl extends BaseMesService<MesDowntimeReco
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void doMesDowntimeRecordJob(String organizeCode, List<MesEquipment> mesEquipmentList) {
|
|
|
|
|
for (MesEquipment mesEquipment : mesEquipmentList) {
|
|
|
|
|
Integer monitorDownTime = Integer.parseInt(mesEquipment.getMonitorDownTime());//todo
|
|
|
|
|
String previousDay = getPreviousDay(new Date(), monitorDownTime);
|
|
|
|
|
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(mesEquipment.getEquipmentCode(), "equipmentCode", ddlPackBean);
|
|
|
|
|
DdlPreparedPack.getNumberBiggerEqualPack(previousDay, "createDatetime", ddlPackBean);
|
|
|
|
|
// DdlPreparedPack.getNumberSmallerEqualPack(mesEquipment.getCreateDateTimeEnd(), "createDatetime", ddlPackBean);
|
|
|
|
|
int byHqlWhereCount = mesProductionRecordRDao.findByHqlWhereCount(ddlPackBean);
|
|
|
|
|
if (byHqlWhereCount < 1) {
|
|
|
|
|
//新增设备停机记录
|
|
|
|
|
MesDowntimeRecord mesDowntimeRecord=new MesDowntimeRecord();
|
|
|
|
|
mesDowntimeRecord.setOrganizeCode(organizeCode);
|
|
|
|
|
mesDowntimeRecord.setEquipId(mesEquipment.getEquipId());
|
|
|
|
|
mesDowntimeRecord.setEquipmentCode(mesEquipment.getEquipmentCode());
|
|
|
|
|
mesDowntimeRecord.setAreaCode(mesEquipment.getAreaCode());
|
|
|
|
|
mesDowntimeRecord.setWorkCenterCode(mesEquipment.getWorkCenterCode());
|
|
|
|
|
mesDowntimeRecord.setWorkCellCode(mesEquipment.getWorkCellCode());
|
|
|
|
|
mesDowntimeRecord.setReasonCode("未选择停机原因");
|
|
|
|
|
mesDowntimeRecord.setReasonTypeCode("未选择停机类型原因");//todo
|
|
|
|
|
ConvertBean.serviceModelInitialize(mesDowntimeRecord, "MesDowntimeRecordJob");
|
|
|
|
|
|
|
|
|
|
mesDowntimeRecordRDao.insert(mesDowntimeRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取某个时间的前几分钟
|
|
|
|
|
*
|
|
|
|
|
* @return yyyy-MM-dd HH:mm:ss
|
|
|
|
|
*/
|
|
|
|
|
public static String getPreviousDay(Date dateTime, int amount) {
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
|
if (dateTime != null) {
|
|
|
|
|
c.setTime(dateTime);
|
|
|
|
|
}
|
|
|
|
|
c.add(Calendar.MINUTE, -amount);
|
|
|
|
|
Date start = c.getTime();
|
|
|
|
|
String date = format.format(start);//前几分钟
|
|
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|