TaskHeaderAgvService.java 5.69 KB
package com.huaheng.pc.task.taskHeader.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.DataUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderAGVService;
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.service.ReceiptHeaderService;
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.service.ShipmentHeaderService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

    @Resource
    private ReceiptHeaderService receiptHeaderService;
    @Resource
    private TaskDetailService taskDetailService;

    @Resource
    private ReceiptContainerHeaderService receiptContainerHeaderService;
    @Resource
    private ShipmentContainerHeaderService shipmentContainerHeaderService;
    @Resource
    private CycleCountDetailService cycleCountDetailService;
    @Resource
    private ReceiptContainerHeaderAGVService receiptContainerHeaderAGVService;
    /**
     * 下发任务
     * @param taskIds
     * @return
     */
    @Transactional
    public AjaxResult sendTaskToAGV(Integer[] taskIds,String station) {
        for(Integer taskId:taskIds){
            TaskHeader task = this.getById(taskId);

            //修改任务主表状态
            task.setStatus(10);
            task.setCreated(new Date());   //生成时间
            task.setLastUpdated(new Date());
            task.setLastUpdatedBy(ShiroUtils.getLoginName());
            task.setPort(station);

            if(task.getTaskType() == 100 || task.getTaskType() == 200){
                ReceiptContainerHeader receiptContainerHeader =
                        receiptContainerHeaderService.getById(task.getAllocationHeadId());
                if(receiptContainerHeader!=null){
                    receiptContainerHeader.setStatus(20);
                    receiptContainerHeaderService.updateById(receiptContainerHeader);
                }
            }
            if(task.getTaskType() == 300 || task.getTaskType() ==400){
                ShipmentContainerHeader shipmentContainerHeader =
                        shipmentContainerHeaderService.getById(task.getAllocationHeadId());
                if(shipmentContainerHeader!= null){
                    shipmentContainerHeader.setStatus(20);
                    shipmentContainerHeaderService.updateById(shipmentContainerHeader);
                }
            }

            this.updateById(task);
            //修改任务明细状态
            TaskDetail record = new TaskDetail();
            record.setStatus(10);
            record.setLastUpdated(new Date());
            record.setLastUpdatedBy(ShiroUtils.getLoginName());
            LambdaQueryWrapper<TaskDetail> detailLambdaQueryWrapper = Wrappers.lambdaQuery();
            detailLambdaQueryWrapper.eq(TaskDetail::getTaskId,taskId);
            taskDetailService.update(record, detailLambdaQueryWrapper);

//            if(task.getFirstStatus() > 9){
//                return AjaxResult.error("任务" + taskId + "已经下发,请不要重复下发,操作中止");
//            }

            if (task.getTaskType() == 100 || task.getTaskType() == 200)
            {
                List<TaskDetail> list=taskDetailService.list(detailLambdaQueryWrapper);
                for (TaskDetail taskDetail : list){
//                    taskDetail.setStatus(300);
                    taskDetail.setStatus(10);
                    if(taskDetail.getStatus()>=200){
                        taskDetailService.updateById(taskDetail);
                    }
                }
                list.stream().map(X -> X.getBillId()).distinct().forEach(billid ->
                        receiptContainerHeaderAGVService.receiptStatusUpdate(DataUtils.getInteger(billid),300));
            }
            //盘点单执行
            if(task.getTaskType() == 700){
                CycleCountDetail cyclecountDetai = cycleCountDetailService.getById(task.getAllocationHeadId());
                cyclecountDetai.setProcessStamp("10");
                cycleCountDetailService.updateById(cyclecountDetai);
            }
        }
        return AjaxResult.success("下发任务成功");
    }

}