TaskBackService.java 3.05 KB
package com.huaheng.api.wcs.service.taskFinish;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.huaheng.api.acs.service.AgvTaskCSService;
import com.huaheng.api.wcs.domain.TaskFinishDomain;
import com.huaheng.api.wcs.service.emptyOutHandle.EmptyOutHandleService;
import com.huaheng.api.wcs.service.overrideHandle.OverrideHandleService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;

import java.math.BigDecimal;
import java.util.List;

@Service
public class TaskBackService  {

    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private InventoryDetailService inventoryDetailService;

    @Transactional(rollbackFor = Exception.class)
    public AjaxResult back(String taskNo) {
        TaskHeader taskHeader = taskHeaderService.getById(taskNo);
        if (taskHeader == null) {
            return AjaxResult.error("没有找到任务,不允许回库, 任务号:" + taskNo);
        }
        // 返回1 表示回库
        // 返回2 表示去叠盘
        int flag = 1;
        int taskType = taskHeader.getTaskType();
        if (taskType != QuantityConstant.TASK_TYPE_SORTINGSHIPMENT) {
            return AjaxResult.error("任务号" + taskNo + "不是分拣任务");
        }
        String containerCode = taskHeader.getContainerCode();
        if (StringUtils.isEmpty(containerCode)) {
            return AjaxResult.error("任务号" + taskNo + "没有托盘号");
        }
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode).eq(InventoryDetail::getWarehouseCode, taskHeader.getWarehouseCode());
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        for (InventoryDetail inventoryDetail : inventoryDetailList){
            BigDecimal qty=inventoryDetail.getQty();
            BigDecimal taskqty=inventoryDetail.getTaskQty();
            if(qty.compareTo(taskqty)>0){
                flag = 2;
                return AjaxResult.success("任务ID:" + taskHeader.getId() + " 允许去叠盘", flag);
            }
        }
        flag = 1; // 返回1 表示回库
        return AjaxResult.success("任务ID:" + taskHeader.getId() + " 允许回库", flag);
    }
}