zhoushihao
2025-10-13 83f738105416c9b11e3b7c5246a0980e41b6650e
hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/hollow/service/impl/HollowGlassOutRelationInfoServiceImpl.java
@@ -25,6 +25,9 @@
import com.mes.hollowqueue.entity.HollowGlassQueueInfo;
import com.mes.hollowqueue.service.HollowGlassQueueInfoService;
import com.mes.largenscreen.entity.PieChartVO;
import com.mes.order.entity.HollowOrderDTO;
import com.mes.order.entity.OrderDetailsDTO;
import com.mes.order.service.OrdersService;
import com.mes.sysconfig.service.SysConfigService;
import com.mes.tools.DateUtil;
import com.mes.utils.Blank;
@@ -35,7 +38,9 @@
import freemarker.template.Version;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.*;
@@ -65,6 +70,8 @@
    HollowGlassRelationInfoService hollowGlassRelationInfoService;
    @Resource
    SysConfigService sysConfigService;
    @Resource
    OrdersService ordersService;
    @Resource
    RedisUtil redisUtil;
@@ -78,11 +85,13 @@
    private static final int ID_RATIO = 10;
    @Override
    @Transactional
    public HollowGlassOutRelationInfo receiveTask(HollowTaskRequest request) {
        return childrenTask(request, 0);
    }
    @Override
    @Transactional
    public HollowGlassOutRelationInfo forceOutGlass(HollowTaskRequest request) {
        return childrenTask(request, 1);
    }
@@ -91,6 +100,12 @@
    public Boolean dispatchHollowSwitch(Boolean flag) {
        redisUtil.setCacheObject("dispatchHollowSwitch", flag);
        return redisUtil.getCacheObject("dispatchHollowSwitch");
    }
    @Override
    public Boolean priorityHollowSwitch(Boolean flag) {
        redisUtil.setCacheObject("priorityHollowSwitch", flag);
        return redisUtil.getCacheObject("priorityHollowSwitch");
    }
    @Override
@@ -106,44 +121,44 @@
    }
    @Override
    public List<HollowGlassQueueInfo> appointHollowTaskDetails(String flowCardId, int cell) {
    public Map<String, List<HollowGlassQueueInfo>> appointHollowTaskDetails(int cell) {
        //按照流程卡及路线,查找对应的任务信息
        HollowGlassOutRelationInfo hollowGlassOutRelationInfo = this.getOne(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
        List<HollowGlassOutRelationInfo> hollowGlassOutRelationInfos = this.list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
                .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE)
                .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId)
                .eq(HollowGlassOutRelationInfo::getCell, cell).last("limit 1"));
        if (null == hollowGlassOutRelationInfo) {
            return new ArrayList<HollowGlassQueueInfo>();
                .eq(HollowGlassOutRelationInfo::getCell, cell));
        if (CollectionUtil.isEmpty(hollowGlassOutRelationInfos)) {
            return null;
        }
        List<Long> ids = hollowGlassOutRelationInfos.stream()
                .map(HollowGlassOutRelationInfo::getId) // 提取每个元素的id
                .collect(Collectors.toList());
        //按照任务id查询对列表中的队列信息
        return hollowGlassQueueInfoService.list(new LambdaQueryWrapper<HollowGlassQueueInfo>()
                .eq(HollowGlassQueueInfo::getRelationId, hollowGlassOutRelationInfo.getId()));
        List<HollowGlassQueueInfo> hollowGlassQueueInfos = hollowGlassQueueInfoService.list(new LambdaQueryWrapper<HollowGlassQueueInfo>()
                .in(HollowGlassQueueInfo::getRelationId, ids)
                .orderByAsc(HollowGlassQueueInfo::getId));
        Map<String, List<HollowGlassQueueInfo>> groupedByFlowCardId = hollowGlassQueueInfos.stream()
                .collect(Collectors.groupingBy(
                        HollowGlassQueueInfo::getFlowCardId,
                        LinkedHashMap::new,
                        Collectors.toList()
                ));
        return groupedByFlowCardId;
    }
    @Override
    public Boolean startTask(String flowCardId, int cell) {
        log.info("查看该流程卡是否由正在执行的任务,流程卡:{}", flowCardId);
        int taskCount = this.count(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
                .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE)
                .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId));
        if (taskCount == 0 || taskCount > 1) {
            log.info("该流程卡不存在任务或者有正在执行中,无法再次执行");
            return Boolean.FALSE;
        }
    public Boolean startTask(int cell) {
        //更新任务状态为开始
        return this.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>()
                .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_START)
                .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId)
                .ne(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_SUCCESS)
                .eq(HollowGlassOutRelationInfo::getCell, cell));
    }
    @Override
    public Boolean pauseTask(String flowCardId, int cell) {
    public Boolean pauseTask(int cell) {
//        更新任务状态为暂停
        return this.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>()
                .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_PAUSE)
                .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId)
                .ne(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_SUCCESS)
                .eq(HollowGlassOutRelationInfo::getCell, cell));
    }
@@ -190,7 +205,7 @@
            return "任务总层数小于2,不生成李赛克文件";
        }
        //获取订单相关信息
        OrderDTO order = baseMapper.queryOrderByFlowCardId(flowCardId);
        HollowOrderDTO order = ordersService.queryOrderByFlowCardId(flowCardId);
        if (null == order) {
            return "生成失败,相关订单信息不存在";
        }
@@ -333,6 +348,12 @@
        return this.page(page, wrapper);
    }
    @Override
    @Cacheable(value = "orderDetails", key = "#flowCardId")
    public OrderDetailsDTO queryProductNameByFlowCardId(String flowCardId) {
        log.info("查询数据库一次:{}", flowCardId);
        return ordersService.queryProductNameByFlowCardId(flowCardId);
    }
    private HollowGlassOutRelationInfo childrenTask(HollowTaskRequest request, int isForce) {
        GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getFlowCardId, request.getFlowCardId()).last("limit 1"));
@@ -363,7 +384,8 @@
        int isPairCount = glassInfo.getTotalLayer() * request.getTotalPairQuantity();
        List<HollowGlassQueueInfo> hollowQueues = new ArrayList<>();
        Integer carWidth = sysConfigService.queryConfigValue(ConstSysConfig.HOLLOW_CAR_WIDTH);
        Integer glassGap = sysConfigService.queryConfigValue(ConstSysConfig.HOLLOW_GLASS_GAP);
//        Integer glassGap = sysConfigService.queryConfigValue(ConstSysConfig.HOLLOW_GLASS_GAP);
        Integer glassGap = hollowGlassRelationInfoService.getGlassGapByThickness(hollowBigStorageCageDetailsList.get(0).getThickness());
        if (930 == request.getCell()) {
            Map<Integer, List<HollowBigStorageCageDetails>> listMap = hollowBigStorageCageDetailsList.stream()
                    .collect(Collectors.groupingBy(HollowBigStorageCageDetails::getHollowSequence));
@@ -432,7 +454,7 @@
    }
    @Override
    public List<PieChartVO> queryPieChart(){
    public List<PieChartVO> queryPieChart() {
        return baseMapper.queryPieChart();
    }
}