BackInvokeService.java 4.49 KB
package com.huaheng.pc.task.taskHeader.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
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.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BackInvokeService {

    @Resource
    private BackQueue backQueue;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private ReceiptContainerDetailService receiptContainerDetailService;
    @Resource
    private ReceiptHeaderService receiptHeaderService;
    @Resource
    private ShipmentContainerDetailService shipmentContainerDetailService;
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
    public void invokeBack(int taskId){
        new Thread(()->{
            backQueue.receiveBack(taskId, new CallBack() {
                @Override
                public void back(Boolean flag, String message,Integer isReturn,Integer receiptOrShipment) {
                    if(flag){
                        //回传失败
                        TaskHeader taskHeader = taskHeaderService.getById(taskId);
                        taskHeader.setBackQty(taskHeader.getBackQty()+1);
                        taskHeader.setBackInfo(message);
                        taskHeader.setIsReturn(isReturn);
                        taskHeaderService.updateById(taskHeader);

                        Integer allocationHeadId = taskHeader.getAllocationHeadId();
                        if(StringUtils.isNotNull(receiptOrShipment)){
                            if(receiptOrShipment==1){

                                List<ReceiptContainerDetail> receiptContainerDetails = receiptContainerDetailService.getReceiptContainerDetailByHeaderId(allocationHeadId);
                                ReceiptContainerDetail receiptContainerDetail = receiptContainerDetails.get(0);
                                ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptContainerDetail.getReceiptId());
                                receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
                                receiptHeaderService.updateById(receiptHeader);
                            }else if(receiptOrShipment==2){
                                LambdaQueryWrapper<ShipmentContainerDetail> queryWrapper = Wrappers.lambdaQuery();
                                queryWrapper.eq(ShipmentContainerDetail::getId,allocationHeadId);
                                List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.list(queryWrapper);

                                ShipmentContainerDetail shipmentContainerDetail = shipmentContainerDetails.get(0);
                                ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentContainerDetail.getShipmentId());
                                shipmentHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
                                shipmentHeaderService.updateById(shipmentHeader);
                            }
                        }
                    }else{
                        //回传成功
                        TaskHeader taskHeader = taskHeaderService.getById(taskId);
                        taskHeader.setBackQty(taskHeader.getBackQty()+1);
                        taskHeader.setBackInfo(message);
                        taskHeader.setIsReturn(isReturn);
                        taskHeaderService.updateById(taskHeader);
                    }
                }
            });
        },"async-thread").start();
    }
}