| | |
| | | package com.mes.downstorage.service.impl; |
| | | |
| | | import com.mes.downstorage.entity.DownStorageCage; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.yulichang.toolkit.JoinWrappers; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.downglassinfo.entity.DownGlassTask; |
| | | import com.mes.downglassinfo.service.DownGlassTaskService; |
| | | import com.mes.downstorage.entity.DownStorageCage; |
| | | import com.mes.downstorage.entity.DownStorageCageDetails; |
| | | import com.mes.downstorage.mapper.DownStorageCageDetailsMapper; |
| | | import com.mes.downstorage.mapper.DownStorageCageMapper; |
| | | import com.mes.downstorage.service.DownStorageCageDetailsService; |
| | | import com.mes.downstorage.service.DownStorageCageService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | /** |
| | | * <p> |
| | | * 服务实现类 |
| | | * 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author zhoush |
| | | * @since 2024-03-27 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class DownStorageCageServiceImpl extends ServiceImpl<DownStorageCageMapper, DownStorageCage> implements DownStorageCageService { |
| | | @Autowired |
| | | @Autowired(required = false) |
| | | private DownStorageCageMapper downStorageCageMapper; |
| | | |
| | | @Autowired |
| | | private GlassInfoService glassInfoService; |
| | | |
| | | @Autowired |
| | | private DownGlassTaskService downGlassTaskService; |
| | | @Autowired |
| | | private DownStorageCageDetailsService downStorageCageDetailsService; |
| | | @Autowired |
| | | private DownStorageCageDetailsMapper downStorageCageDetailsMapper; |
| | | |
| | | @Override |
| | | public List<Map> gettask(){ |
| | | downStorageCageMapper.selectList(null); |
| | | // downStorageCageMapper.selectJoin(); |
| | | return null; |
| | | }; |
| | | public DownGlassTask createDownGlassTask(GlassInfo glassInfo, Integer startCell, Integer endCell, Integer taskType) { |
| | | DownGlassTask downGlassTask = new DownGlassTask(); |
| | | |
| | | BeanUtils.copyProperties(glassInfo, downGlassTask); |
| | | |
| | | downGlassTask.setStartCell(startCell); |
| | | downGlassTask.setTaskType(taskType); |
| | | downGlassTask.setEndCell(endCell); |
| | | return downGlassTask; |
| | | } |
| | | |
| | | @Override |
| | | public DownGlassTask createDownGlassTask(DownStorageCageDetails glassInfo, Integer startCell, Integer endCell, Integer taskType) { |
| | | DownGlassTask downGlassTask = new DownGlassTask(); |
| | | |
| | | BeanUtils.copyProperties(glassInfo, downGlassTask); |
| | | downGlassTask.setStartCell(startCell); |
| | | downGlassTask.setTaskType(taskType); |
| | | downGlassTask.setEndCell(endCell); |
| | | return downGlassTask; |
| | | } |
| | | |
| | | |
| | | //找到空格子 |
| | | @Override |
| | | public List<DownStorageCageDetails> selectCacheEmpty() { |
| | | return this.selectJoinList(DownStorageCageDetails.class, |
| | | JoinWrappers.lambda(DownStorageCage.class) |
| | | .selectAll(DownStorageCage.class) |
| | | .leftJoin(DownStorageCageDetails.class, on -> on |
| | | .eq(DownStorageCageDetails::getDeviceId, DownStorageCage::getDeviceId) |
| | | .eq(DownStorageCageDetails::getSlot, DownStorageCage::getSlot) |
| | | .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN)) |
| | | .isNull(DownStorageCageDetails::getSlot) |
| | | ); |
| | | } |
| | | |
| | | //找到空格子 |
| | | @Override |
| | | public DownStorageCage selectCacheEmpty(int currentSlot, boolean flag) { |
| | | List<DownStorageCage> emptyList = this.selectJoinList(DownStorageCage.class, |
| | | JoinWrappers.lambda(DownStorageCage.class) |
| | | .selectAll(DownStorageCage.class) |
| | | .leftJoin(DownStorageCageDetails.class, on -> on |
| | | .eq(DownStorageCageDetails::getSlot, DownStorageCage::getSlot) |
| | | .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN)) |
| | | .isNull(DownStorageCageDetails::getSlot) |
| | | .last("order by abs(t.slot - " + currentSlot + ") asc limit 2") |
| | | ); |
| | | if (flag && CollectionUtil.isNotEmpty(emptyList)) { |
| | | return emptyList.get(0); |
| | | } |
| | | if (CollectionUtil.isEmpty(emptyList) || emptyList.size() == 1) { |
| | | return null; |
| | | } |
| | | return emptyList.get(0); |
| | | } |
| | | |
| | | @Override |
| | | public List<DownStorageCageDetails> selectCacheMax() { |
| | | return baseMapper.selectJoinList(DownStorageCageDetails.class, |
| | | JoinWrappers.lambda(DownStorageCage.class) |
| | | // 添加 DownStorageCage 的 enableState 为 1 的条件 |
| | | .select(DownStorageCageDetails::getFlowCardId) |
| | | .leftJoin(DownStorageCageDetails.class, on -> on |
| | | .eq(DownStorageCageDetails::getDeviceId, DownStorageCage::getDeviceId) |
| | | .eq(DownStorageCageDetails::getSlot, DownStorageCage::getSlot) |
| | | .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN)) |
| | | .isNull(DownStorageCageDetails::getSlot) |
| | | .eq(DownStorageCage::getEnableState, 1) |
| | | .groupBy(DownStorageCageDetails::getFlowCardId) // 根据 flowCardId 分组 |
| | | // 使用子查询和排序来获取相同 FlowCardId 中的最多记录 |
| | | .having("count(*) = (select max(cnt) from (select count(*) as cnt from down_storage_cage_details group by flow_card_id) as temp)") |
| | | |
| | | ); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> selectDownStorageCages() { |
| | | return baseMapper.selectJoinMaps(JoinWrappers.lambda(DownStorageCage.class) |
| | | .selectAll(DownStorageCage.class) |
| | | .selectAs(DownStorageCageDetails::getId, "esdId") |
| | | .select(DownStorageCageDetails::getGlassId, DownStorageCageDetails::getWidth, DownStorageCageDetails::getHeight, DownStorageCageDetails::getId) |
| | | .leftJoin(DownStorageCageDetails.class, on -> on |
| | | .eq(DownStorageCageDetails::getDeviceId, DownStorageCage::getDeviceId) |
| | | .eq(DownStorageCageDetails::getSlot, DownStorageCage::getSlot) |
| | | .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN)) |
| | | ); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 修改理片笼信息 功能:对笼内栅格玻璃 【启用/禁用】 |
| | | * |
| | | * @param downStorageCage |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean updateDownStorageCage(DownStorageCage downStorageCage) { |
| | | DownStorageCage downItem = baseMapper.selectById(downStorageCage.getId()); |
| | | downItem.setEnableState(downStorageCage.getEnableState()); |
| | | baseMapper.updateById(downItem); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 修改理片笼信息 功能:对笼内栅格玻璃 【添加/删除/更换】 |
| | | * |
| | | * @param downStorageCageId |
| | | * @param downStorageCageDetails |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean updateDownStorageCageDetails(int downStorageCageId, DownStorageCageDetails downStorageCageDetails) { |
| | | DownStorageCage downItem = baseMapper.selectById(downStorageCageId); |
| | | log.info("正常" + downItem); |
| | | if (downStorageCageDetails != null) { |
| | | DownStorageCageDetails edgDItem = downStorageCageDetailsMapper.selectById(downStorageCageDetails.getId()); |
| | | //添加 |
| | | if (edgDItem != null) { |
| | | //只传格子 :移除玻璃 |
| | | DownStorageCageDetails newresult = downStorageCageDetailsMapper.selectById(downStorageCageDetails.getId()); |
| | | newresult.setSlot(downItem.getSlot()); |
| | | downStorageCageDetailsMapper.updateById(newresult); |
| | | } |
| | | } |
| | | |
| | | if (downItem != null) { |
| | | //移除 |
| | | DownStorageCageDetails result = downStorageCageDetailsMapper.selectOne(new MPJLambdaWrapper<DownStorageCageDetails>().eq(DownStorageCageDetails::getSlot, downStorageCageId)); |
| | | if (result != null) { |
| | | result.setSlot(0); |
| | | downStorageCageDetailsMapper.updateById(result); |
| | | } |
| | | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | } |