ShareServiceImp.java 11.2 KB
package com.tianbo.analysis.service.imp;

import com.tianbo.analysis.dao.*;
import com.tianbo.analysis.model.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: shenhl
 * @Date: 2019/8/26 17:15
 */
@Service
@Slf4j
/**
 *
 *  共享
 */
public class ShareServiceImp {

    @Autowired
    ARRIVEDMASTERMapper arrivedmasterMapper;

    @Autowired
    ARRIVEDSECONDARYMapper arrivedsecondaryMapper;

    @Autowired
    DEPARTURESLOADINGMapper departuresloadingMapper;

    @Autowired
    PREPAREMASTERMapper preparemasterMapper;

    @Autowired
    PREPARESECONDARYMapper preparesecondaryMapper;

    @Autowired
    TALLYMASTERMapper tallymasterMapper;

    @Autowired
    TALLYSECONDARYMapper tallysecondaryMapper;

    @Autowired
    ORIGINMANIFESTMASTERMapper originmanifestmasterMapper;

    @Autowired
    OriginmanifestsecondaryMapper originmanifestsecondaryMapper;

    @Autowired
    CUSTOMSMESSAGEMapper customsmessageMapper;

    public int share(String type, CustomReception customReception){
        // 发送日志 插入
        CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();

        CUSTOMSMESSAGEWithBLOBs cus = customsmessageMapper.selectMessage(customReception.getMessageID());

        switch (type){
            case "MT9999":
               return MT1201MT9999(customReception, cus, type);
            case "MT3201":
                // 判断 主单id  主单号是否为空
                if (cus.getMasterautoid() != null && cus.getWaybillnomaster() != null){
                    String waybill = waybill(cus.getWaybillnomaster());

                    ARRIVEDMASTER arrivedmaster = new ARRIVEDMASTER();
                    arrivedmaster.setFlightno(cus.getFlightno());
                    arrivedmaster.setFlightdate(cus.getFlightdate());
                    arrivedmaster.setReceiptinformation(customReception.getResponseText());
                    arrivedmaster.setAutoid(cus.getMasterautoid());
                    arrivedmaster.setWaybillnomaster(waybill);

                    int i = arrivedmasterMapper.updateRECEIPTION(arrivedmaster);

                    //插入sendlog记录表
                    log.info("即将插入日志运单号为:"+waybill+"->autoid="+cus.getMasterautoid());
                    int ii = coustomAnalysisServiceImp.insertSendlog(type,customReception.getResponseText(),cus.getMasterautoid());
                    if (i > 0 && ii > 0){

                        return 1;
                    }

                    return 0;
                }else {
                    // 分单
                    ARRIVEDSECONDARY arrivedsecondary = new ARRIVEDSECONDARY();

                    arrivedsecondary.setReceiption(customReception.getResponseText());
                    arrivedsecondary.setAutoid(cus.getSecondaryautoid());
                    arrivedsecondary.setWaybillnomaster(cus.getWaybillnomaster());
                    arrivedsecondary.setWaybillnosecondary(cus.getWaybillnosecondary());
                    int i = arrivedsecondaryMapper.updateRECEIPTION(arrivedsecondary);
                    //插入sendlog记录表
                    log.info("即将插入日志运单号为:"+cus.getWaybillnosecondary()+"->autoid="+cus.getSecondaryautoid());
                    int ii = coustomAnalysisServiceImp.insertSendlog(type,customReception.getResponseText(),cus.getSecondaryautoid());
                    if (i > 0 && ii > 0){

                        return 1;
                    }
                }
            case "MT5202":

                return tallAWB_H(customReception, cus, type);
            case "MT5201":

                return tallAWB_H(customReception, cus, type);
            case "MT4201":
                String waybill = waybill(cus.getWaybillnomaster());

                DEPARTURESLOADING departuresloading = new DEPARTURESLOADING();
                departuresloading.setFlightno(cus.getFlightno());
                departuresloading.setFlightdate(cus.getFlightdate());
                departuresloading.setReceiption(customReception.getResponseText());
                departuresloading.setId(cus.getMasterautoid());
                departuresloading.setWaybillno(waybill);
                int i = departuresloadingMapper.updateRECEIPTION(departuresloading);

                //插入sendlog记录表
                log.info("即将插入日志运单号为:"+waybill+"->autoid="+cus.getMasterautoid());
                int ii = coustomAnalysisServiceImp.insertSendlog(type,customReception.getResponseText(),cus.getMasterautoid());
                if (i > 0 && ii > 0){

                    return 1;
                }
            case "MT1201":

                return MT1201MT9999(customReception, cus, type);
            case "MT2201":
                // 判断 主单id  主单号是否为空
                if (cus.getMasterautoid() != null && cus.getWaybillnomaster() != null){
                    String waybill1 = waybill(cus.getWaybillnomaster());

                    PREPAREMASTER preparemaster = new PREPAREMASTER();
                    preparemaster.setFlightno(cus.getFlightno());
                    preparemaster.setFlightdate(cus.getFlightdate());
                    preparemaster.setReceiptinformation(customReception.getResponseText());
                    preparemaster.setAutoid(cus.getMasterautoid());
                    preparemaster.setWaybillnomaster(waybill1);

                    int i1 = preparemasterMapper.updateRECEIPTION(preparemaster);

                    //插入sendlog记录表
                    log.info("即将插入日志运单号为:"+waybill1+"->autoid="+cus.getMasterautoid());
                    int ii1 = coustomAnalysisServiceImp.insertSendlog(type,customReception.getResponseText(),cus.getMasterautoid());
                    if (i1 > 0 && ii1 > 0){

                        return 1;
                    }

                    return 0;
                }else {
                    // 分单
                    PREPARESECONDARY preparesecondary = new PREPARESECONDARY();

                    preparesecondary.setReceiptinformation(customReception.getResponseText());
                    preparesecondary.setAutoid(cus.getSecondaryautoid());
                    preparesecondary.setWaybillnomaster(cus.getWaybillnomaster());
                    preparesecondary.setWaybillnosecondary(cus.getWaybillnosecondary());
                    int i1 = preparesecondaryMapper.updateRECEIPTION(preparesecondary);
                    //插入sendlog记录表
                    log.info("即将插入日志运单号为:"+cus.getWaybillnosecondary()+"->autoid="+cus.getSecondaryautoid());
                    int ii1 = coustomAnalysisServiceImp.insertSendlog(type,customReception.getResponseText(),cus.getSecondaryautoid());
                    if (i1 > 0 && ii1 > 0){

                        return 1;
                    }
                }
        }


        return 0;
    }

    public String waybill (String waybill){

        StringBuffer stringBuffer = new StringBuffer(waybill);
        StringBuffer insert = stringBuffer.insert(3, "-");

        return insert.toString();
    }

    // 主分单
    public int tallAWB_H(CustomReception customReception, CUSTOMSMESSAGEWithBLOBs cus, String type){
        // 发送日志 插入
        CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();

        // 判断 主单id  主单号是否为空
        if (cus.getMasterautoid() != null && cus.getWaybillnomaster() != null){
            String waybill = waybill(cus.getWaybillnomaster());

            TALLYMASTER tallymaster = new TALLYMASTER();
            tallymaster.setFlightno(cus.getFlightno());
            tallymaster.setFlightdate(cus.getFlightdate());
            tallymaster.setReceiptinformation(customReception.getResponseText());
            tallymaster.setAutoid(cus.getMasterautoid());
            tallymaster.setWaybillnomaster(waybill);

            int i = tallymasterMapper.updateRECEIPTION(tallymaster);

            //插入sendlog记录表
            log.info("即将插入日志运单号为:"+waybill+"->autoid="+cus.getMasterautoid());
            int ii = coustomAnalysisServiceImp.insertSendlog(type,customReception.getResponseText(),cus.getMasterautoid());
            if (i > 0 && ii > 0){

                return 1;
            }

            return 0;
        }else {
            // 分单
            TALLYSECONDARY tallysecondary = new TALLYSECONDARY();

            tallysecondary.setReceiptinformation(customReception.getResponseText());
            tallysecondary.setAutoid(cus.getSecondaryautoid());
            tallysecondary.setWaybillnomaster(cus.getWaybillnomaster());
            tallysecondary.setWaybillnosecondary(cus.getWaybillnosecondary());
            int i = tallysecondaryMapper.updateRECEIPTION(tallysecondary);
            //插入sendlog记录表
            log.info("即将插入日志运单号为:"+cus.getWaybillnosecondary()+"->autoid="+cus.getSecondaryautoid());
            int ii = coustomAnalysisServiceImp.insertSendlog(type,customReception.getResponseText(),cus.getSecondaryautoid());
            if (i > 0 && ii > 0){

                return 1;
            }

            return 0;
        }
    }


    // MT9999 MT1201
    public int MT1201MT9999(CustomReception customReception, CUSTOMSMESSAGEWithBLOBs cus, String type) {
        // 发送日志 插入
        CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();
        // 判断 主单id  主单号是否为空
        if (cus.getMasterautoid() != null && cus.getWaybillnomaster() != null) {
            String waybill = waybill(cus.getWaybillnomaster());

            ORIGINMANIFESTMASTER or = new ORIGINMANIFESTMASTER();
            or.setFlightno(cus.getFlightno());
            or.setFlightDate(cus.getFlightdate());
            or.setReceiptinformation(customReception.getResponseText());
            or.setAutoid(cus.getMasterautoid());
            or.setWaybillnomaster(waybill);
            int i = originmanifestmasterMapper.updateRECEIPTION(or);

            //插入sendlog记录表
            log.info("即将插入日志运单号为:" + waybill + "->autoid=" + cus.getMasterautoid());
            int ii = coustomAnalysisServiceImp.insertSendlog(type, customReception.getResponseText(), cus.getMasterautoid());
            if (i > 0 && ii > 0) {

                return 1;
            }

            return 0;
        } else {
            // 分单
            Originmanifestsecondary or = new Originmanifestsecondary();

            or.setReceiption(customReception.getResponseText());
            or.setAutoid(cus.getSecondaryautoid());
            or.setWaybillnomaster(cus.getWaybillnomaster());
            or.setWaybillnosecondary(cus.getWaybillnosecondary());
            int i = originmanifestsecondaryMapper.updateRECEIPTION(or);
            //插入sendlog记录表
            log.info("即将插入日志运单号为:" + cus.getWaybillnosecondary() + "->autoid=" + cus.getSecondaryautoid());
            int ii = coustomAnalysisServiceImp.insertSendlog(type, customReception.getResponseText(), cus.getSecondaryautoid());
            if (i > 0 && ii > 0) {

                return 1;
            }
            return 0;
        }
    }
}