| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.engineering.entity.Engineering; |
| | | import com.mes.engineering.mapper.EngineeringMapper; |
| | |
| | | import com.mes.opctask.entity.LoadGlassDeviceTaskHistory; |
| | | import com.mes.opctask.service.LoadGlassDeviceTaskHistoryService; |
| | | import com.mes.opctask.service.LoadGlassDeviceTaskService; |
| | | import com.mes.pp.entity.OptimizeProject; |
| | | import com.mes.pp.service.OptimizeProjectService; |
| | | import com.mes.rawglassdetails.entity.RawGlassStorageDetails; |
| | | import com.mes.rawglassdetails.service.RawGlassStorageDetailsService; |
| | | import com.mes.s7.entity.S7Data; |
| | | import com.mes.uppattenusage.entity.UpPattenUsage; |
| | | import com.mes.uppattenusage.entity.vo.UpPattenUsageVO; |
| | | import com.mes.uppattenusage.mapper.UpPattenUsageMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | private LoadGlassDeviceTaskHistoryService loadGlassDeviceTaskHistoryService; |
| | | @Resource |
| | | private UpPattenUsageMapper upPattenUsageMapper; |
| | | @Resource |
| | | private OptimizeProjectService optimizeProjectService; |
| | | |
| | | @Autowired(required = false) |
| | | S7Serializer s7Serializer; |
| | | |
| | | private static final List<Integer> LOAD_STATION_01 = Arrays.asList(101, 102); |
| | | private static final List<Integer> LOAD_STATION_02 = Arrays.asList(103, 104); |
| | |
| | | |
| | | private static final String LOAD_GLASS_DEVICE_TWO_TASK = "load_glass_device_two_task"; |
| | | |
| | | |
| | | //设备id 上片位信息 任务表不一致 历史任务表公用一张 新增任务/任务结束,后会在历史表中新增一条记录并在结束后更新任务 一个任务即可 |
| | | //定时任务扫描上片位有没有原片 |
| | | //1、是否有在执行的任务 |
| | | //2、1号上片位是否有原片,原片尺寸是否和上片待上片的尺寸一致 |
| | | //3、1号无原片,且没有架子,2号上片位尺寸是否和带上片尺寸一致 |
| | | //4、不一致可能出现玻璃破损导致的上一架原片数量不够 |
| | | @Scheduled(fixedDelay = 300) |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void opcLoadGlassOne() { |
| | | opcLoadGlassChild(LOAD_GLASS_DEVICE_ONE_TASK, LOAD_GLASS_ONE_DEVICE); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 300) |
| | | // @Scheduled(fixedDelay = 5000) |
| | | public void opcLoadGlassTwo() { |
| | | opcLoadGlassChild(LOAD_GLASS_DEVICE_TWO_TASK, LOAD_GLASS_TWO_DEVICE); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 300) |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void opcLoadGlassOneFinish() { |
| | | opcLoadGlassFinishChid(LOAD_GLASS_DEVICE_ONE_TASK, LOAD_GLASS_ONE_DEVICE); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 300) |
| | | // @Scheduled(fixedDelay = 5000) |
| | | public void opcLoadGlassTwoFinish() { |
| | | opcLoadGlassFinishChid(LOAD_GLASS_DEVICE_TWO_TASK, LOAD_GLASS_TWO_DEVICE); |
| | | } |
| | | |
| | | /** |
| | | * 定时任务扫码已完成上片的工程,将工程状态改为已完成,同步pp表的工程表,状态改为300 |
| | | */ |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void updateEngineerState() { |
| | | log.info("修改已完成工程状态任务开始执行"); |
| | | List<Engineering> engineerings = engineeringMapper.selectList(new LambdaQueryWrapper<Engineering>().eq(Engineering::getState, Const.ENGINEERING_RUNNING)); |
| | | for (Engineering engineering : engineerings) { |
| | | Integer count = upPattenUsageMapper.selectCount(new LambdaQueryWrapper<UpPattenUsage>() |
| | | .eq(UpPattenUsage::getEngineeringId, engineering.getEngineerId()).ne(UpPattenUsage::getState, Const.LOAD_RAW_GLASS_SUCCESS)); |
| | | if (count == 0) { |
| | | engineeringMapper.update(null, new LambdaUpdateWrapper<Engineering>().set(Engineering::getState, Const.ENGINEERING_SUCCESS) |
| | | .eq(Engineering::getEngineerId, engineering.getEngineerId())); |
| | | optimizeProjectService.update(null, new LambdaUpdateWrapper<OptimizeProject>().set(OptimizeProject::getState, 300) |
| | | .eq(OptimizeProject::getProjectNo, engineering.getEngineerId())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void opcLoadGlassChild(String tableName, Integer deviceId) { |
| | | S7Data S7DataSP1 = s7Serializer.read(S7Data.class); |
| | | Engineering engineering = engineeringMapper.selectOne(new LambdaQueryWrapper<Engineering>() |
| | | .eq(Engineering::getState, Const.ENGINEERING_RUNNING).eq(Engineering::getStationCell, deviceId)); |
| | | if (null == engineering) { |
| | |
| | | } |
| | | //任务暂停 |
| | | LoadGlassDeviceTask task = loadGlassDeviceTaskService.queryTaskMessage(tableName); |
| | | if (0 == task.getInkageState()) { |
| | | ; |
| | | if ("0".equals(S7DataSP1.getInkageState().toString())) { |
| | | // if (0 == task.getInkageState()) { |
| | | log.info("{}上片线,处于离线状态:{},结束本地上片请求", deviceId, task.getInkageState()); |
| | | return; |
| | | } |
| | | if (task.getTaskRunning().equals(Const.ENGINEERING_RUNNING)) { |
| | | if (S7DataSP1.getTaskRunning().toString().equals(Const.ENGINEERING_RUNNING)) { |
| | | // if (task.getTaskRunning().equals(Const.ENGINEERING_RUNNING)) { |
| | | log.info("{}上片线,有正在执行的任务,结束本地上片请求", deviceId); |
| | | return; |
| | | } |
| | |
| | | List<Integer> loadStation = LOAD_GLASS_DEVICE_ONE_TASK.equals(tableName) ? LOAD_STATION_01 : LOAD_STATION_02; |
| | | List<RawGlassStorageDetails> loadStationList = rawGlassStorageDetailsService.list(new LambdaQueryWrapper<RawGlassStorageDetails>() |
| | | .inSql(RawGlassStorageDetails::getSlot, "select slot from raw_glass_storage_station where enable_state = 1") |
| | | .eq(RawGlassStorageDetails::getState, Const.RAW_GLASS_STATE_IN) |
| | | .in(RawGlassStorageDetails::getState, Const.RAW_GLASS_STATE_IN_ALL) |
| | | .eq(RawGlassStorageDetails::getDeviceId, deviceId)); |
| | | if (CollectionUtils.isEmpty(loadStationList)) { |
| | | log.info("当前上片线路两个上片位都没有原片信息,结束本次上片任务,等待仓储调度任务"); |
| | |
| | | } |
| | | |
| | | private void opcLoadGlassFinishChid(String tableName, Integer deviceId) { |
| | | S7Data S7DataSP1 = s7Serializer.read(S7Data.class); |
| | | LoadGlassDeviceTask task = loadGlassDeviceTaskService.queryTaskMessage(tableName); |
| | | if (task.getTaskRunning().equals(Const.ENGINEERING_NEW)) { |
| | | if (S7DataSP1.getTaskRunning().toString().equals(Const.ENGINEERING_NEW)) { |
| | | // if (task.getTaskRunning().equals(Const.ENGINEERING_NEW)) { |
| | | log.info("无任务,结束"); |
| | | return; |
| | | } |
| | | if (task.getTaskState() <= 1) { |
| | | if (Integer.parseInt(S7DataSP1.getTaskState().toString()) <= 1) { |
| | | // if (task.getTaskState() <= 1) { |
| | | log.info("任务正在执行,结束"); |
| | | return; |
| | | } |
| | | //获取任务完成情况 |
| | | // 已完成数量 破损数量 |
| | | Integer finishCount = task.getFinishCount(); |
| | | Integer damageCount = task.getDamageCount(); |
| | | Integer finishCount = Integer.parseInt(S7DataSP1.getFinishCount().toString()); |
| | | Integer damageCount = Integer.parseInt(S7DataSP1.getDamageCount().toString()); |
| | | // Integer finishCount = task.getFinishCount(); |
| | | // Integer damageCount = task.getDamageCount(); |
| | | |
| | | //更新当前架子上的原片剩余情况 |
| | | rawGlassStorageDetailsService.update(new UpdateWrapper<RawGlassStorageDetails>() |
| | |
| | | .in(UpPattenUsage::getId, ids) |
| | | .set(UpPattenUsage::getState, Const.LOAD_RAW_GLASS_SUCCESS)); |
| | | } |
| | | //todo:任务表数据情况 |
| | | //任务表数据情况 |
| | | task.setTaskRunning(0); |
| | | task.setTotalCount(0); |
| | | task.setRawGlassWidth(0); |