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

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.service.ReceiptHeaderService;
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 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) {
        boolean flag = true;
        String  message = "成功";
        if(StringUtils.isNull(taskId)){
            callBack.back(false,"任务id不能为空");
            return;
        }
        TaskHeader header = taskHeaderService.getById(taskId);
        if(header == null){
            callBack.back(false,"找不到任务id为:"+taskId+"的任务");
            return;
        }
        List<TaskDetail> taskDetails = taskDetailService.findByTaskId(taskId);
        if(taskDetails==null || taskDetails.size()==0){
            callBack.back(false,"找不到任务id为:"+taskId+"的任务,没有任务明细");
            return;
        }
        switch (header.getInternalTaskType()){
            case 100 :
                String receiptHeaderId = "";
                ReceiptDetail receiptDetail = receiptDetailService.getById(taskDetails.get(0).getBillDetailId());
                receiptHeaderId += receiptDetail.getReceiptId();
                Map<Integer, BigDecimal> detailsQtyMap =new HashMap<>();
                for (TaskDetail taskDetail : taskDetails) {
                    detailsQtyMap.put(taskDetail.getBillDetailId(),taskDetail.getQty());
                }
                AjaxResult ajaxResult = receiptHeaderService.postBack(receiptHeaderId, detailsQtyMap);
                message = ajaxResult.getMsg();
                flag = !ajaxResult.hasErr();
                break;
            case 200 :
                String shipmentHeaderId = "";
                ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetails.get(0).getBillDetailId());
                shipmentHeaderId += shipmentDetail.getShipmentId();
                Map<Integer, BigDecimal> detailsQtyMap1 =new HashMap<>();
                for (TaskDetail taskDetail : taskDetails) {
                    detailsQtyMap1.put(taskDetail.getBillDetailId(),taskDetail.getQty());
                }
                AjaxResult ajaxResult1 = shipmentHeaderService.postBack(shipmentHeaderId,detailsQtyMap1);
                message = ajaxResult1.getMsg();
                flag = !ajaxResult1.hasErr();
                break;
        }
        callBack.back(flag,message);
    }
}