| | |
| | | |
| | | import cn.hutool.core.lang.Assert; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.github.yulichang.base.MPJBaseServiceImpl; |
| | | import com.github.yulichang.toolkit.JoinWrappers; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.mes.bigstorage.entity.BigStorageCage; |
| | | import com.mes.bigstorage.entity.BigStorageCageDetails; |
| | |
| | | import com.mes.bigstorage.service.BigStorageCageDetailsService; |
| | | import com.mes.bigstorage.service.BigStorageCageService; |
| | | import com.mes.bigstoragetask.entity.BigStorageCageFeedTask; |
| | | import com.mes.bigstoragetask.entity.BigStorageCageOutTask; |
| | | import com.mes.bigstoragetask.entity.UpdateBigStorageCageDTO; |
| | | import com.mes.bigstoragetask.mapper.BigStorageCageFeedTaskMapper; |
| | | import com.mes.bigstoragetask.mapper.BigStorageCageOutTaskMapper; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.common.utils.RedisUtil; |
| | | import com.mes.damage.entity.Damage; |
| | | import com.mes.damage.service.DamageService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.mapper.GlassInfoMapper; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | | import com.mes.temperingglass.mapper.TemperingGlassInfoMapper; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | * @author zhoush |
| | | * @since 2024-03-27 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class BigStorageCageDetailsServiceImpl extends MPJBaseServiceImpl<BigStorageCageDetailsMapper, BigStorageCageDetails> implements BigStorageCageDetailsService { |
| | | |
| | |
| | | @Resource |
| | | private GlassInfoMapper glassInfoMapper; |
| | | |
| | | @Resource |
| | | private GlassInfoService glassInfoService; |
| | | |
| | | @Resource |
| | | private TemperingGlassInfoService temperingGlassInfoService; |
| | | |
| | | @Resource |
| | | private DamageService damageService; |
| | | @Resource |
| | | private RedisUtil redisUtil; |
| | | |
| | | @Value("${mes.minCount}") |
| | | private int minCount; |
| | | |
| | |
| | | @Value("${mes.glassGap}") |
| | | private Integer glassGap; |
| | | |
| | | /** |
| | | * 查询进/出片任务 |
| | | */ |
| | | @Value("${mes.sequence.order}") |
| | | private boolean sequenceOrder; |
| | | |
| | | |
| | | @Override |
| | | public List<BigStorageCageDetails> selectTask(int taskType) { |
| | | if (taskType == 1) { |
| | | //进片任务数据 |
| | | LambdaQueryWrapper<BigStorageCageDetails> feedWrapper = new LambdaQueryWrapper<>(); |
| | | feedWrapper.eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN); |
| | | List<BigStorageCageDetails> bigStorageCageDetailsList = baseMapper.selectList(feedWrapper); |
| | | public List<BigStorageCageDetails> selectFeedTask() { |
| | | //进片任务数据 |
| | | LambdaQueryWrapper<BigStorageCageDetails> feedWrapper = new LambdaQueryWrapper<>(); |
| | | feedWrapper.eq(BigStorageCageDetails::getState, Const.GLASS_STATE_NEW); |
| | | List<BigStorageCageDetails> bigStorageCageDetailsList = baseMapper.selectList(feedWrapper); |
| | | |
| | | LambdaQueryWrapper<BigStorageCageFeedTask> feedTaskWrapper = new LambdaQueryWrapper<>(); |
| | | feedTaskWrapper.lt(BigStorageCageFeedTask::getTaskState, Const.BIG_STORAGE_IN_SLOT); |
| | | List<BigStorageCageFeedTask> bigStorageCageFeedTaskList = bigStorageCageFeedTaskMapper.selectList(feedTaskWrapper); |
| | | |
| | | Map<String, BigStorageCageFeedTask> listMap = bigStorageCageFeedTaskList.stream() |
| | | .collect(Collectors.toMap(BigStorageCageFeedTask::getGlassId, task -> task)); |
| | | Iterator<BigStorageCageDetails> iterator = bigStorageCageDetailsList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | BigStorageCageDetails bigStorageCageDetails = iterator.next(); |
| | | BigStorageCageFeedTask bigStorageCageFeedTask = listMap.get(bigStorageCageDetails.getGlassId()); |
| | | bigStorageCageDetails.setBigStorageCageFeedTask(bigStorageCageFeedTask); |
| | | if (bigStorageCageDetails.getBigStorageCageFeedTask() == null) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | return bigStorageCageDetailsList; |
| | | } else { |
| | | //出片任务数据 |
| | | LambdaQueryWrapper<BigStorageCageDetails> outWrapper = new LambdaQueryWrapper<>(); |
| | | outWrapper.eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN); |
| | | List<BigStorageCageDetails> bigStorageCageDetailsList = baseMapper.selectList(outWrapper); |
| | | |
| | | LambdaQueryWrapper<BigStorageCageOutTask> outTaskWrapper = new LambdaQueryWrapper<>(); |
| | | outTaskWrapper.lt(BigStorageCageOutTask::getTaskState, Const.BIG_STORAGE_OUT_SUCCESS); |
| | | List<BigStorageCageOutTask> bigStorageCageOutTaskList = bigStorageCageOutTaskMapper.selectList(outTaskWrapper); |
| | | |
| | | Map<String, BigStorageCageOutTask> listMap = bigStorageCageOutTaskList.stream() |
| | | .collect(Collectors.toMap(BigStorageCageOutTask::getGlassId, task -> task)); |
| | | for (BigStorageCageDetails bigStorageCageDetails : bigStorageCageDetailsList) { |
| | | BigStorageCageOutTask bigStorageCageOutTask = listMap.get(bigStorageCageDetails.getGlassId()); |
| | | bigStorageCageDetails.setBigStorageCageOutTask(bigStorageCageOutTask); |
| | | } |
| | | Iterator<BigStorageCageDetails> iterator = bigStorageCageDetailsList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | BigStorageCageDetails bigStorageCageDetails = iterator.next(); |
| | | BigStorageCageOutTask bigStorageCageOutTask = listMap.get(bigStorageCageDetails.getGlassId()); |
| | | bigStorageCageDetails.setBigStorageCageOutTask(bigStorageCageOutTask); |
| | | if (bigStorageCageDetails.getBigStorageCageOutTask() == null) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | return bigStorageCageDetailsList; |
| | | LambdaQueryWrapper<BigStorageCageFeedTask> feedTaskWrapper = new LambdaQueryWrapper<>(); |
| | | feedTaskWrapper |
| | | .lt(BigStorageCageFeedTask::getTaskState, Const.BIG_STORAGE_IN_SLOT) |
| | | .isNotNull(BigStorageCageFeedTask::getTargetSlot); |
| | | List<BigStorageCageFeedTask> bigStorageCageFeedTaskList = bigStorageCageFeedTaskMapper.selectList(feedTaskWrapper); |
| | | Map<String, BigStorageCageFeedTask> listMap = bigStorageCageFeedTaskList.stream() |
| | | .collect(Collectors.toMap(BigStorageCageFeedTask::getGlassId, task -> task)); |
| | | Iterator<BigStorageCageDetails> iterator = bigStorageCageDetailsList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | BigStorageCageDetails bigStorageCageDetails = iterator.next(); |
| | | BigStorageCageFeedTask bigStorageCageFeedTask = listMap.get(bigStorageCageDetails.getGlassId()); |
| | | bigStorageCageDetails.setBigStorageCageFeedTask(bigStorageCageFeedTask); |
| | | } |
| | | return bigStorageCageDetailsList; |
| | | } |
| | | |
| | | @Override |
| | | public List<BigStorageCageDetails> selectOutTask() { |
| | | LambdaQueryWrapper<BigStorageCageDetails> outWrapper = new LambdaQueryWrapper<>(); |
| | | outWrapper.in(BigStorageCageDetails::getState, Const.GLASS_STATE_OUT_ING, Const.GLASS_STATE_SCHEDULE_ING); |
| | | List<BigStorageCageDetails> bigStorageCageDetailsList = baseMapper.selectList(outWrapper); |
| | | LambdaQueryWrapper<BigStorageCageOutTask> outTaskWrapper = new LambdaQueryWrapper<>(); |
| | | outTaskWrapper.lt(BigStorageCageOutTask::getTaskState, Const.BIG_STORAGE_OUT_SUCCESS); |
| | | List<BigStorageCageOutTask> bigStorageCageOutTaskList = bigStorageCageOutTaskMapper.selectList(outTaskWrapper); |
| | | |
| | | Map<String, BigStorageCageOutTask> listMap = bigStorageCageOutTaskList.stream() |
| | | .collect(Collectors.toMap(BigStorageCageOutTask::getGlassId, task -> task)); |
| | | for (BigStorageCageDetails bigStorageCageDetails : bigStorageCageDetailsList) { |
| | | BigStorageCageOutTask bigStorageCageOutTask = listMap.get(bigStorageCageDetails.getGlassId()); |
| | | bigStorageCageDetails.setBigStorageCageOutTask(bigStorageCageOutTask); |
| | | } |
| | | Iterator<BigStorageCageDetails> iterator = bigStorageCageDetailsList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | BigStorageCageDetails bigStorageCageDetails = iterator.next(); |
| | | BigStorageCageOutTask bigStorageCageOutTask = listMap.get(bigStorageCageDetails.getGlassId()); |
| | | bigStorageCageDetails.setBigStorageCageOutTask(bigStorageCageOutTask); |
| | | } |
| | | return bigStorageCageDetailsList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 判断当前玻璃是否能上车 |
| | |
| | | temperingGlassInfoMapper.updateById(temperingGlassInfo); |
| | | } |
| | | if (status == 0) { |
| | | bigStorageCageDetails.setState(Const.GLASS_STATE_TAKE); |
| | | } else { |
| | | bigStorageCageDetails.setState(Const.GLASS_STATE_DAMAGE); |
| | | } else { |
| | | bigStorageCageDetails.setState(Const.GLASS_STATE_TAKE); |
| | | } |
| | | baseMapper.updateById(bigStorageCageDetails); |
| | | bigStorageCageService.updateRemainWidth(bigStorageCageDetails.getSlot()); |
| | | //todo:插入破损数据 |
| | | |
| | | Damage damage = new Damage(); |
| | | damage.setGlassId(bigStorageCageDetails.getGlassId()); |
| | | damage.setWorkingProcedure("冷加工"); |
| | | damage.setRemark("大理片笼破损"); |
| | | damage.setStatus(2); |
| | | damageService.insertDamage(damage); |
| | | } |
| | | |
| | | //查询玻璃信息 |
| | |
| | | BeanUtils.copyProperties(glassInfo, bigStorageCageDetails); |
| | | bigStorageCageDetails.setState(1); |
| | | bigStorageCageDetails.setGap(glassGap); |
| | | List<BigStorageCageDetails> bigStorageCageDetailsList = new ArrayList<>(); |
| | | bigStorageCageDetailsList.add(bigStorageCageDetails); |
| | | return bigStorageCageDetailsList; |
| | | } else { |
| | | return null; |
| | | } |
| | | List<BigStorageCageDetails> bigStorageCageDetailsList = new ArrayList<>(); |
| | | bigStorageCageDetailsList.add(bigStorageCageDetails); |
| | | return bigStorageCageDetailsList; |
| | | |
| | | } |
| | | |
| | | //理片笼详情添加 |
| | |
| | | .selectAll(BigStorageCage.class) |
| | | .leftJoin(BigStorageCageDetails.class, BigStorageCageDetails::getSlot, BigStorageCage::getSlot) |
| | | .eq(BigStorageCage::getEnableState, Const.SLOT_ON) |
| | | .in(BigStorageCageDetails::getState, Const.GLASS_STATE_NEW, Const.GLASS_STATE_IN_ALL) |
| | | .eq(BigStorageCageDetails::getEngineerId, glassInfo.getEngineerId()) |
| | | .eq(BigStorageCageDetails::getTemperingLayoutId, glassInfo.getTemperingLayoutId()) |
| | | .gt(BigStorageCage::getRemainWidth, glassInfo.getWidth()) |
| | | .gt(BigStorageCage::getRemainWidth, Math.max(glassInfo.getWidth(), glassInfo.getHeight())) |
| | | .last("limit 1"); |
| | | if (glassInfo.getTemperingLayoutId() == 0) { |
| | | wrapper.eq(BigStorageCageDetails::getWidth, glassInfo.getWidth()).eq(BigStorageCageDetails::getHeight, glassInfo.getHeight()); |
| | |
| | | } |
| | | BigStorageCage bigStorageCage = bigStorageCageService.selectJoinOne(BigStorageCage.class, wrapper); |
| | | if (null != bigStorageCage) { |
| | | log.info("无钢化版图id或根据当前玻璃片序+1找到目标格子:{},玻璃id:{}", bigStorageCage.getSlot(), glassInfo.getGlassId()); |
| | | bigStorageDTO = new BigStorageDTO(); |
| | | bigStorageDTO.setWidth(bigStorageCage.getRemainWidth()); |
| | | bigStorageDTO.setSlot(bigStorageCage.getSlot()); |
| | | bigStorageDTO.setDeviceId(bigStorageCage.getDeviceId()); |
| | | return bigStorageDTO; |
| | | } |
| | | bigStorageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>() |
| | | .eq(BigStorageCage::getEnableState, Const.SLOT_ON) |
| | | .eq(BigStorageCage::getRemainWidth, slotWidth) |
| | | // .notInSql(BigStorageCage::getSlot, "select distinct slot from big_storage_cage_details where state = 0") |
| | | .inSql(BigStorageCage::getDeviceId, |
| | | "select distinct device_id from big_storage_cage_details where tempering_layout_id = " + glassInfo.getTemperingLayoutId()) |
| | | "select distinct device_id from big_storage_cage_details where engineer_id = '" + glassInfo.getEngineerId() + "' and tempering_layout_id = " + glassInfo.getTemperingLayoutId()) |
| | | .last("limit 1")); |
| | | if (null != bigStorageCage) { |
| | | log.info("根据版图id找到笼子内的目标格子:{},玻璃id:{}", bigStorageCage.getSlot(), glassInfo.getGlassId()); |
| | | bigStorageDTO = new BigStorageDTO(); |
| | | bigStorageDTO.setWidth(bigStorageCage.getRemainWidth()); |
| | | bigStorageDTO.setSlot(bigStorageCage.getSlot()); |
| | | bigStorageDTO.setDeviceId(bigStorageCage.getDeviceId()); |
| | | return bigStorageDTO; |
| | | } |
| | | |
| | | //获取玻璃的厚度:重新选笼子需要按照笼子可放玻璃厚度进行选择 |
| | | bigStorageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>() |
| | | .eq(BigStorageCage::getRemainWidth, slotWidth) |
| | | .eq(BigStorageCage::getEnableState, Const.SLOT_ON) |
| | | .inSql(BigStorageCage::getDeviceId, |
| | | "select t.device_id from big_storage_cage t left join big_storage_cage_details t1 on t.slot = t1.slot " + |
| | | " where state in (0,100,102,103,104) and t.max_thickness >= " + glassInfo.getThickness() + " and t.enable_state = 1 " + |
| | | " group by t.device_id " + |
| | | " order by count(DISTINCT t1.tempering_layout_id), count(distinct t1.slot)") |
| | | .last("limit 1")); |
| | | if (null != bigStorageCage) { |
| | | log.info("按照存笼玻璃格子数占用最少方式获取信息格子为:{},玻璃id:{}", bigStorageCage.getSlot(), glassInfo.getGlassId()); |
| | | bigStorageDTO = new BigStorageDTO(); |
| | | bigStorageDTO.setWidth(bigStorageCage.getRemainWidth()); |
| | | bigStorageDTO.setSlot(bigStorageCage.getSlot()); |
| | | bigStorageDTO.setDeviceId(bigStorageCage.getDeviceId()); |
| | | return bigStorageDTO; |
| | | } |
| | | |
| | | //获取玻璃的厚度:重新选笼子需要按照笼子可放玻璃厚度进行选择 |
| | | bigStorageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>() |
| | | .eq(BigStorageCage::getRemainWidth, slotWidth) |
| | | .eq(BigStorageCage::getEnableState, Const.SLOT_ON) |
| | | .inSql(BigStorageCage::getDeviceId, |
| | | "select t.device_id from big_storage_cage t left join big_storage_cage_details t1 on t.slot = t1.slot " + |
| | | " where state in (0,100,102,103,104) and t.max_thickness >= " + glassInfo.getThickness() + " and t.enable_state = 1 " + |
| | | " group by t.device_id " + |
| | | " order by count(DISTINCT t1.tempering_layout_id), count(distinct t.slot) - count(distinct t1.slot) desc") |
| | | .last("limit 1")); |
| | | Assert.isTrue(null != bigStorageCage, "没有空余的笼子存放玻璃"); |
| | | log.info("按照存笼玻璃格子数剩余最多得方式获取信息版图id:{},格子:{},玻璃id:{}", glassInfo.getTemperingLayoutId(), bigStorageCage.getSlot(), glassInfo.getGlassId()); |
| | | bigStorageDTO = new BigStorageDTO(); |
| | | bigStorageDTO.setWidth(bigStorageCage.getRemainWidth()); |
| | | bigStorageDTO.setSlot(bigStorageCage.getSlot()); |
| | | bigStorageDTO.setDeviceId(bigStorageCage.getDeviceId()); |
| | | return bigStorageDTO; |
| | | } |
| | | |
| | | @Override |
| | | public TemperingLayoutDTO temperingIsAll() { |
| | | public List<TemperingLayoutDTO> temperingIsAll() { |
| | | return baseMapper.temperingIsAll(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public TemperingLayoutDTO queryTemperingOccupySlot() { |
| | | public List<TemperingLayoutDTO> queryTemperingOccupySlot() { |
| | | return baseMapper.queryTemperingOccupySlot(minCount); |
| | | } |
| | | |
| | |
| | | public List<SlotSequenceDTO> queryGlassMaxAndMin(String engineerId, Integer temperingLayoutId) { |
| | | return baseMapper.queryGlassMaxAndMin(engineerId, temperingLayoutId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean temperingGlass(String temperingLayoutId, String engineerId) { |
| | | LambdaQueryWrapper<TemperingGlassInfo> temperingGlassInfoLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | temperingGlassInfoLambdaQueryWrapper |
| | | .eq(TemperingGlassInfo::getState, Const.TEMPERING_NEW); |
| | | List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoMapper.selectList(temperingGlassInfoLambdaQueryWrapper); |
| | | |
| | | if (temperingGlassInfoList.size() == 0) { |
| | | List<TemperingGlassInfo> temperingGlassInfos = glassInfoService.selectJoinList(TemperingGlassInfo.class, JoinWrappers.lambda(GlassInfo.class) |
| | | .selectAll(GlassInfo.class) |
| | | .select("-1 as state") |
| | | .selectAs(BigStorageCageDetails::getSlot, TemperingGlassInfo::getSlot) |
| | | .innerJoin(BigStorageCageDetails.class, BigStorageCageDetails::getGlassId, GlassInfo::getGlassId) |
| | | .eq(GlassInfo::getTemperingLayoutId, temperingLayoutId) |
| | | .eq(GlassInfo::getEngineerId, engineerId) |
| | | .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN) |
| | | .orderBy(Boolean.TRUE, sequenceOrder, GlassInfo::getTemperingFeedSequence)); |
| | | if (CollectionUtils.isNotEmpty(temperingGlassInfos)) { |
| | | temperingGlassInfoService.saveBatch(temperingGlassInfos); |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> selectTemperingGlass() { |
| | | QueryWrapper<BigStorageCageDetails> wrapper = new QueryWrapper<>(); |
| | | wrapper.select("engineer_id,tempering_layout_id,count(*) as count") |
| | | .in("state", Const.GLASS_STATE_IN, Const.GLASS_STATE_ARTIFICIAL) |
| | | .groupBy("engineer_id,tempering_layout_id") |
| | | .orderByAsc("engineer_id") |
| | | .orderByAsc("tempering_layout_id"); |
| | | List<Map<String, Object>> TemperingGlass = baseMapper.selectMaps(wrapper); |
| | | return TemperingGlass; |
| | | } |
| | | |
| | | @Override |
| | | public void updateBySlot(List<UpdateBigStorageCageDTO> glassList, int state) { |
| | | baseMapper.updateBySlot(glassList, state); |
| | | } |
| | | |
| | | @Override |
| | | public String temperingSwitch(Boolean flag) { |
| | | redisUtil.setCacheObject("temperingSwitch", flag); |
| | | return "success"; |
| | | } |
| | | } |