package org.jeecg.modules.screen.service.impl; import org.jeecg.modules.mdc.entity.EquipmentAlarm; import org.jeecg.modules.mdc.entity.MdcEquipmentMonitor; import org.jeecg.modules.mdc.mapper.EquipmentAlarmMapper; import org.jeecg.modules.screen.dto.MdcProductDayscheduleDto; import org.jeecg.modules.screen.dto.ToolLifeDto; import org.jeecg.modules.screen.mapper.MdcSubLargeScreenMapper; import org.jeecg.modules.screen.service.MdcSubLargeScreenService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; /** * @author Lius * @date 2024/8/26 15:01 */ @Service public class MdcSubLargeScreenServiceImpl implements MdcSubLargeScreenService { @Resource private MdcSubLargeScreenMapper mdcSubLargeScreenMapper; @Resource private EquipmentAlarmMapper equipmentAlarmMapper; private final String today = LocalDate.now().toString(); /** * 当日生产计划 * * @param productionId * @return */ @Override public List todayProductionProgress(String productionId) { List mdcProductDayscheduleDtos = new ArrayList<>(); mdcProductDayscheduleDtos = mdcSubLargeScreenMapper.todayProductionProgress(productionId, today); if (mdcProductDayscheduleDtos != null && !mdcProductDayscheduleDtos.isEmpty()) { for (MdcProductDayscheduleDto mdcProductDayscheduleDto : mdcProductDayscheduleDtos) { if (mdcProductDayscheduleDto.getCompletionCount() != 0) { mdcProductDayscheduleDto.setPassRate(new BigDecimal(mdcProductDayscheduleDto.getQualifiedCount()).divide(new BigDecimal(mdcProductDayscheduleDto.getCompletionCount()), 0, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); } } } return mdcProductDayscheduleDtos; } /** * 设备实时状态 * * @param productionId * @return */ @Override public List equipmentStatus(String productionId) { List result = mdcSubLargeScreenMapper.checkStatusFromEquipmentIds(productionId); if (result != null && !result.isEmpty()) { for (MdcEquipmentMonitor mdcEquipmentMonitor : result) { if (mdcEquipmentMonitor.getOporation() != null) { switch (mdcEquipmentMonitor.getOporation()) { case 1: case 2: mdcEquipmentMonitor.setOporationDict("待机"); break; case 3: mdcEquipmentMonitor.setOporationDict("运行"); break; case 22: mdcEquipmentMonitor.setOporationDict("报警"); break; default: mdcEquipmentMonitor.setOporationDict("关机"); break; } } else { mdcEquipmentMonitor.setOporationDict("关机"); mdcEquipmentMonitor.setOporation(0); } } } return result; } /** * 设备报警 * * @param productionId * @return */ @Override public List equipmentAlarm(String productionId) { String startDate = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.of(LocalDate.now(), LocalTime.MIN)); String endDate = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.of(LocalDate.now(), LocalTime.MIN).plusDays(1)); return equipmentAlarmMapper.equipmentAlarm(productionId, startDate, endDate); } /** * 刀具寿命管理 * * @param productionId * @return */ @Override public List toolLifeList(String productionId) { // List toolLifeList = mdcSubLargeScreenMapper.toolLifeList(productionId); // if (toolLifeList != null && !toolLifeList.isEmpty()) { // for (ToolLifeDto toolLifeDto : toolLifeList) { // toolLifeDto.setTId("T" + toolLifeDto.getTId()); // } // } return mdcSubLargeScreenMapper.toolLifeList(productionId); } }