严智鑫
2024-08-05 00c4dfc5ac687c93e0b7abafc33abb693b38edd6
hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/bigstorage/service/impl/BigStorageCageDetailsServiceImpl.java
@@ -30,6 +30,7 @@
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;
@@ -49,6 +50,7 @@
 * @author zhoush
 * @since 2024-03-27
 */
@Slf4j
@Service
public class BigStorageCageDetailsServiceImpl extends MPJBaseServiceImpl<BigStorageCageDetailsMapper, BigStorageCageDetails> implements BigStorageCageDetailsService {
@@ -266,6 +268,8 @@
                .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, Math.max(glassInfo.getWidth(), glassInfo.getHeight()))
                .last("limit 1");
@@ -276,6 +280,7 @@
        }
        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());
@@ -285,11 +290,12 @@
        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")
//                .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());
@@ -301,27 +307,33 @@
        bigStorageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>()
                .eq(BigStorageCage::getRemainWidth, slotWidth)
                .eq(BigStorageCage::getEnableState, Const.SLOT_ON)
                .notInSql(BigStorageCage::getSlot, "select distinct slot from big_storage_cage_details where state = 0")
                .notInSql(BigStorageCage::getDeviceId,
                        "select distinct device_id from big_storage_cage_details where state in (100,102,103)")
                .ge(BigStorageCage::getMaxThickness, glassInfo.getThickness())
                .orderByAsc(BigStorageCage::getDeviceId)
                .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)
                .notInSql(BigStorageCage::getSlot, "select distinct slot from big_storage_cage_details where state = 0")
                .eq(BigStorageCage::getEnableState, Const.SLOT_ON)
                .ge(BigStorageCage::getMaxThickness, glassInfo.getThickness())
                .orderByAsc(BigStorageCage::getDeviceId)
                .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());
@@ -376,7 +388,9 @@
        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");
                .groupBy("engineer_id,tempering_layout_id")
                .orderByAsc("engineer_id")
                .orderByAsc("tempering_layout_id");
        List<Map<String, Object>> TemperingGlass = baseMapper.selectMaps(wrapper);
        return TemperingGlass;
    }