TaskHeaderSiXiangCheService.java 12.6 KB
package com.huaheng.pc.task.taskHeader.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.api.SSP.service.OrderAssignApiService;
import com.huaheng.api.acs.domain.AgvTaskCS;
import com.huaheng.api.acs.service.AcsService;
import com.huaheng.api.acs.service.AgvTaskCSCreateService;
import com.huaheng.api.acs.service.AgvTaskCSService;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
import com.huaheng.api.wcs.service.taskCancel.TaskCancelService;
import com.huaheng.common.constant.HttpConstant;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.Assert;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.restful.RestUtil;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.cycleCountPreference.domain.CycleCountPreference;
import com.huaheng.pc.config.cycleCountPreference.service.CycleCountPreferenceService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryTransferService;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentContainerAdvice.service.ShipmentContainerAdviceService;
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.system.dict.service.IDictDataService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.MobileTask;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
import javafx.concurrent.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class TaskHeaderSiXiangCheService extends ServiceImpl<TaskHeaderMapper, TaskHeader> {

    private static final Logger logger = LoggerFactory.getLogger(TaskHeaderSiXiangCheService.class);

    @Resource
    private StationService stationService;
    @Resource
    private TaskHeaderService taskHeaderService;
    /**
     * 第一段任务
     * @param taskHeader
     * @return
     */
    public TaskHeader siXiangCheTask(TaskHeader taskHeader) {
        //lkPort是立库站台,taskHeader.setPort是四向车站台
        String lkPort=taskHeader.getPort();
        TaskHeader task=new TaskHeader();
        TaskHeader task2=new TaskHeader();
        switch (taskHeader.getTaskType()){
            case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
            case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
                taskHeader.setPort(QuantityConstant.FOUR_WHEEL_RECEIPT_PORT);
                taskHeader.setToPort(lkPort);
                //生成换站任务;
                task=saveTaskSiXiangCheOne(taskHeader);
                if(task!=null){
                    //入库任务的前置任务时换站任务
                    taskHeader.setPreTaskNo(task.getId());
                    task2 = new TaskHeader();
                    task2.setPreTaskNo(task.getId());
                    task2.setId(taskHeader.getId());
                    if(!taskHeaderService.updateById(task2)){
                        throw new ServiceException("任务下发,设置前置任务失败");
                    }
                }

                break;
            case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
            case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
                taskHeader.setPort(QuantityConstant.FOUR_WHEEL_SHIPMENT_PORT);
                taskHeader.setToPort(lkPort);
                //生成换站任务;
                task= saveTaskSiXiangCheOne(taskHeader);
                if(task!=null){
                    //出库任务,换站任务的前置任务是出库任务
                    task2 = new TaskHeader();
                    task2.setId(task.getId());
                    task2.setPreTaskNo(taskHeader.getId());
                    if(!taskHeaderService.updateById(task2)){
                        throw new ServiceException("任务下发,设置前置任务失败");
                    }
                }
                break;
            case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
            case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
            case QuantityConstant.TASK_TYPE_VIEW:
                taskHeader.setPort(QuantityConstant.FOUR_WHEEL_SHIPMENT_PORT);
                taskHeader.setToPort(lkPort);
                //生成出库的换站任务;
                task= saveTaskSiXiangCheOne(taskHeader);
                if(task!=null){
                    //设置前置任务,第一个taskheader,第2个task,第3个Task2
                    TaskHeader task3 = new TaskHeader();
                    task3.setId(task.getId());
                    task3.setPreTaskNo(taskHeader.getId());
                    if(!taskHeaderService.updateById(task3)){
                        throw new ServiceException("任务下发,设置前置任务失败");
                    }
                    //生成回库的换站任务;
                    task2 = saveTaskSiXiangCheTwo(taskHeader);
                    TaskHeader task4 = new TaskHeader();
                    task4.setId(task2.getId());
                    task4.setPreTaskNo(task.getId());
                    if(!taskHeaderService.updateById(task4)){
                        throw new ServiceException("任务下发,设置前置任务失败");
                    }
                }
                break;
            default:
                break;
        }

        return taskHeader;
    }
    /**
     *  四向车库第1段换站任务
     * @param taskHeader
     * @return
     */
    public TaskHeader saveTaskSiXiangCheOne(TaskHeader taskHeader) {
        String lkport=taskHeader.getToPort();
        TaskHeader task = new TaskHeader();
        task.setWarehouseCode(taskHeader.getWarehouseCode());
        task.setZoneCode(QuantityConstant.ZONE_CODE_TYPE_LK);
        task.setCompanyCode(taskHeader.getCompanyCode());
        task.setContainerCode(taskHeader.getContainerCode());
        task.setTaskType(QuantityConstant.TASK_TYPE_OVER_STATION);
        switch (taskHeader.getTaskType()) {
            case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
            case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
                task.setFromLocation(lkport);
                task.setToLocation(taskHeader.getPort());
                break;
            case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
            case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
            case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
            case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
            case QuantityConstant.TASK_TYPE_VIEW:
                task.setFromLocation(taskHeader.getPort());
                task.setToLocation(lkport);
                break;
        }
        if(task.getFromLocation().equals(task.getToLocation())){
            return null;
        }
        //有任务则不重复生成
        TaskHeader taskNew=this.checkTranskTask(task);
        if(taskNew != null){
            return null;
        }
        if(!taskHeaderService.save( task)){
            throw new ServiceException("生成换站任务失败");
        }
        return task;
    }

    /**
     *
     * 四向车库第2段换站任务
     * @param taskHeader
     * @return
     */
    public TaskHeader saveTaskSiXiangCheTwo(TaskHeader taskHeader) {
        String lkport=taskHeader.getToPort();
        TaskHeader task = new TaskHeader();
        task.setWarehouseCode(taskHeader.getWarehouseCode());
        task.setZoneCode(QuantityConstant.ZONE_CODE_TYPE_LK);
        task.setCompanyCode(taskHeader.getCompanyCode());
        task.setContainerCode(taskHeader.getContainerCode());
        task.setTaskType(QuantityConstant.TASK_TYPE_OVER_STATION);
        switch (taskHeader.getTaskType()) {
            case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
            case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
            case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
            case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
                break;
            case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
            case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
            case QuantityConstant.TASK_TYPE_VIEW:
                //回库的换站任务
                task.setFromLocation(lkport);
                task.setToLocation(taskHeader.getPort());
                break;
        }
        TaskHeader taskNew=this.checkTranskTask(task);
        if(taskNew != null){
            return taskNew;
        }
        if(!taskHeaderService.save( task)){
            throw new ServiceException("生成换站任务失败");
        }
        return task;
    }

    public TaskHeader checkTranskTask(TaskHeader task){
        //有任务则不重复生成
        LambdaQueryWrapper<TaskHeader> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskHeader::getContainerCode,task.getContainerCode())
                .eq(TaskHeader::getTaskType,task.getTaskType())
                .eq(TaskHeader::getFromLocation,task.getFromLocation())
                .eq(TaskHeader::getToLocation,task.getToLocation());
        queryWrapper.eq(TaskHeader::getWarehouseCode,task.getWarehouseCode());
        queryWrapper.eq(TaskHeader::getZoneCode,task.getZoneCode());
        queryWrapper.lt(TaskHeader::getStatus,QuantityConstant.TASK_STATUS_COMPLETED);
        List<TaskHeader> list=taskHeaderService.list(queryWrapper);
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }

}