TaskBackQueue.java 5.06 KB
package com.huaheng.pc.task.taskHeader.service;

import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
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.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.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import org.springframework.stereotype.Service;

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

@Service
public class TaskBackQueue implements BackQueue{

    @Resource
    private  ReceiptHeaderService receiptHeaderService;
    @Resource
    private ReceiptDetailService receiptDetailService;
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
    @Resource
    private ShipmentDetailService shipmentDetailService;
    @Resource
    private  TaskHeaderService taskHeaderService;
    @Resource
    private TaskDetailService taskDetailService;

    @Override
    public void receiveBack(int taskId, CallBack callBack) {
        Integer receiptOrShipment = null;
        AjaxResult ajaxResult = AjaxResult.success();
        boolean flag = true;
        String  message = "成功";
        Integer result = 0;
        if(StringUtils.isNull(taskId)){
            callBack.back(false,"任务id不能为空", QuantityConstant.ISRETURN_FAIL,receiptOrShipment);
            return;
        }
        TaskHeader header = taskHeaderService.getById(taskId);
        if(header == null){
            callBack.back(false,"找不到任务id为:"+taskId+"的任务",QuantityConstant.ISRETURN_FAIL,receiptOrShipment);
            return;
        }
        switch (header.getTaskType()){
            case 500 :
            case 600 :
            case 800 :
            case 900 :
            case 1000 :
            case 1100 :
            case 1200 :
                callBack.back(true,"无需回传",QuantityConstant.NOT_RETURN,receiptOrShipment);
                return;
        }
        List<TaskDetail> taskDetails = taskDetailService.findByTaskId(taskId);
        if(taskDetails==null || taskDetails.size()==0){
            callBack.back(false,"找不到任务id为:"+taskId+"的任务,没有任务明细",QuantityConstant.ISRETURN_FAIL,receiptOrShipment);
            return;
        }
        switch (header.getInternalTaskType()){
            case 100 :
                String receiptHeaderId = "";
                ReceiptDetail receiptDetail = receiptDetailService.getById(taskDetails.get(0).getBillDetailId());
                ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptDetail.getReceiptId());
                if(StringUtils.isEmpty(receiptHeader.getReferCode())){
                    callBack.back(true,"无需回传",QuantityConstant.NOT_RETURN,receiptOrShipment);
                    return;
                }
                receiptHeaderId += receiptDetail.getReceiptId();
                Map<Integer, BigDecimal> detailsQtyMap =new HashMap<>();
                for (TaskDetail taskDetail : taskDetails) {
                    detailsQtyMap.put(taskDetail.getBillDetailId(),taskDetail.getQty());
                }
                ajaxResult = receiptHeaderService.postBack(receiptHeaderId, detailsQtyMap);
                receiptOrShipment = 1;
                break;
            case 200 :
                String shipmentHeaderId = "";
                ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetails.get(0).getBillDetailId());
                ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentDetail.getShipmentId());
                if(StringUtils.isEmpty(shipmentHeader.getReferCode())){
                    callBack.back(true,"无需回传",QuantityConstant.NOT_RETURN,receiptOrShipment);
                    return;
                }
                shipmentHeaderId += shipmentDetail.getShipmentId();
                Map<Integer, BigDecimal> detailsQtyMap1 =new HashMap<>();
                for (TaskDetail taskDetail : taskDetails) {
                    detailsQtyMap1.put(taskDetail.getBillDetailId(),taskDetail.getQty());
                }
                ajaxResult = shipmentHeaderService.postBack(shipmentHeaderId,detailsQtyMap1);
                receiptOrShipment = 2;
                break;
        }
        flag = !ajaxResult.hasErr();
        message = ajaxResult.getMsg();
        result = flag ?  QuantityConstant.ISRETURN_SUCC : QuantityConstant.ISRETURN_FAIL;
        callBack.back(flag,message,result,receiptOrShipment);
    }
}