| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.mes.common.S7object; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.common.config.ConstSysConfig; |
| | | import com.mes.damage.entity.Damage; |
| | | import com.mes.damage.service.DamageService; |
| | | import com.mes.device.PlcParameterObject; |
| | | import com.mes.sysconfig.service.SysConfigService; |
| | | import com.mes.sysdict.entity.SysDictData; |
| | | import com.mes.sysdict.service.SysDictDataService; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Comparator; |
| | |
| | | @Autowired |
| | | private SysDictDataService sysDictDataService; |
| | | |
| | | @Autowired |
| | | private SysConfigService sysConfigService; |
| | | |
| | | private static final String ALONE_STATE = "0"; |
| | | |
| | | @Value("${mes.width}") |
| | | private Integer temperingWidth; |
| | | @Value("${mes.height}") |
| | | private Integer temperingHeight; |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void temperingGlassBefore() { |
| | | Date startDate = new Date(); |
| | | log.info("本次任务开始执行时间:{}", startDate); |
| | |
| | | //将确认字置为0 |
| | | plcControl.writeWord(plcParameterObject.getPlcParameter("confirmationWord").getAddress(), 0); |
| | | //可能有几炉玻璃同时在钢,需要获取钢化小片表中的数据信息状态为2(旋转台玻璃已送出未钢化,正在钢化) |
| | | List<TemperingGlassInfo> temperingGlassInfoList = temporaryGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>() |
| | | .eq(TemperingGlassInfo::getState, Const.TEMPERING_START)); |
| | | List<TemperingGlassInfo> temperingGlassInfoList = temporaryGlassInfoService.list( |
| | | new LambdaQueryWrapper<TemperingGlassInfo>() |
| | | .inSql(TemperingGlassInfo::getTemperingLayoutId, "select distinct tempering_layout_id from tempering_glass_info where state=1") |
| | | .lt(TemperingGlassInfo::getState, Const.TEMPERING_START) |
| | | ); |
| | | if (CollectionUtils.isEmpty(temperingGlassInfoList)) { |
| | | log.info("当前系统没有需要钢化的玻璃信息"); |
| | | return; |
| | | } |
| | | TemperingGlassInfo maxGlassInfo = temperingGlassInfoList.stream().max(Comparator.comparingLong(TemperingGlassInfo::getId)).get(); |
| | | TemperingGlassInfo minGlassInfo = temperingGlassInfoList.stream().min(Comparator.comparingLong(TemperingGlassInfo::getState)).get(); |
| | | if (minGlassInfo.getState() < Const.TEMPERING_DROP) { |
| | | log.info("当前炉玻璃未到齐,稍后在执行"); |
| | | return; |
| | | } |
| | | //拿到工程id及炉号 |
| | | // List<EngineerTemperingDTO> engineerTemperingList = temperingGlassInfoList.stream().map(e -> { |
| | | // EngineerTemperingDTO engineerTemperingDTO = new EngineerTemperingDTO(); |
| | | // BeanUtils.copyProperties(e, engineerTemperingDTO); |
| | | // return engineerTemperingDTO; |
| | | // }).distinct().collect(Collectors.toList()); |
| | | //将正在钢化的炉号过滤掉,仅获取待钢化的玻璃 |
| | | // List<TemperingRecord> temperingRecords = temperingRecordService.list(new LambdaQueryWrapper<TemperingRecord>().and(i -> i.isNull(TemperingRecord::getCoolEnergy).or().eq(TemperingRecord::getCoolEnergy, ""))); |
| | | // List<EngineerTemperingDTO> temperingList = new ArrayList<>(); |
| | | // if (CollectionUtils.isNotEmpty(temperingRecords)) { |
| | | // temperingList = temperingRecords.stream().map(e -> { |
| | | // EngineerTemperingDTO engineerTemperingDTO = new EngineerTemperingDTO(); |
| | | // BeanUtils.copyProperties(e, engineerTemperingDTO); |
| | | // return engineerTemperingDTO; |
| | | // }).collect(Collectors.toList()); |
| | | // } |
| | | // engineerTemperingList.removeAll(temperingList); |
| | | // if (CollectionUtils.isEmpty(engineerTemperingList)) { |
| | | // log.info("没有待钢化的任务,结束"); |
| | | // return; |
| | | // } |
| | | // if (engineerTemperingList.size() > 1) { |
| | | // log.info("存在多炉待钢化的任务,请检查现场是否有异常数据未处理"); |
| | | // return; |
| | | // } |
| | | // EngineerTemperingDTO temperingDTO = engineerTemperingList.get(0); |
| | | TemperingGlassInfo maxGlassInfo = temperingGlassInfoList.stream().max(Comparator.comparingLong(TemperingGlassInfo::getId)).get(); |
| | | //将正在钢化的炉号过滤掉,仅获取待钢化的玻璃:判断待钢的玻璃是否已发送对接数据 |
| | | List<TemperingRecord> temperingRecordList = temperingRecordService.list(new LambdaQueryWrapper<TemperingRecord>().eq(TemperingRecord::getEngineerId, maxGlassInfo.getEngineerId()) |
| | | .eq(TemperingRecord::getTemperingLayoutId, maxGlassInfo.getTemperingLayoutId())); |
| | | if (CollectionUtils.isNotEmpty(temperingRecordList)) { |
| | | log.info("没有待钢化的任务,结束"); |
| | | return; |
| | | } |
| | | //获取待钢化的所有玻璃信息 |
| | | List<TemperingGlassInfo> temperingGlassList = temperingGlassInfoList.stream() |
| | | .filter(e -> e.getEngineerId().equals(maxGlassInfo.getEngineerId()) |
| | |
| | | .sorted(Comparator.comparing(TemperingGlassInfo::getTemperingFeedSequence)).collect(Collectors.toList()); |
| | | //按照膜系获取玻璃材质 |
| | | SysDictData glassTypeSysDictData = sysDictDataService.getOne(new QueryWrapper<SysDictData>() |
| | | .eq(StringUtils.isNotBlank(temperingGlassList.get(0).getFilmsid()), "dict_label", temperingGlassList.get(0).getFilmsid())); |
| | | .eq(StringUtils.isNotBlank(temperingGlassList.get(0).getFilmsId()), "dict_label", temperingGlassList.get(0).getFilmsId())); |
| | | |
| | | double sumArea = temperingGlassList.stream().mapToDouble(e -> e.getWidth() * e.getHeight()).sum(); |
| | | double maxArea = temperingGlassList.stream().mapToDouble(e -> e.getWidth() * e.getHeight()).max().orElse(0.0); |
| | | double minArea = temperingGlassList.stream().mapToDouble(e -> e.getWidth() * e.getHeight()).min().orElse(0.0); |
| | | double areaDifference = (10000 * (maxArea - minArea) / maxArea); |
| | | Integer temperingHeight = sysConfigService.queryConfigValue(ConstSysConfig.TEMPERING_HEIGHT); |
| | | Integer temperingWidth = sysConfigService.queryConfigValue(ConstSysConfig.TEMPERING_HEIGHT); |
| | | double loadingRate = (int) (10000 * sumArea / (temperingHeight * temperingWidth)); |
| | | TemperingRecord temperingRecord = new TemperingRecord(); |
| | | temperingRecord.setEngineerId(maxGlassInfo.getEngineerId()); |
| | |
| | | log.info("本次任务结束时间:{},共耗时:{}ms", endDate, endDate.getTime() - startDate.getTime()); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void temperingGlassAfter() { |
| | | //暂不处理 |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void dealDamageTask() { |
| | | Date startDate = new Date(); |
| | | log.info("钢化破损玻璃清除任务开始执行时间:{}", startDate); |
| | |
| | | damage.setLine(Const.TEMPERING_OUT_TARGET_POSITION); |
| | | damage.setWorkingProcedure("钢化"); |
| | | damage.setRemark("钢化"); |
| | | damage.setStatus(0); |
| | | damage.setStatus(1); |
| | | damage.setType(e.getState()); |
| | | return damage; |
| | | }).collect(Collectors.toList()); |