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

import com.tianbo.analysis.bean.SpringBeanUtitl;
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 ShareServiceImp(){
        customsmessageMapper = SpringBeanUtitl.getBean(CUSTOMSMESSAGEMapper.class);
    }

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

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


        switch (type){
            case "MT9999":
               return MT1201MT9999(customReception, cus, type);
            case "MT3201":
                // 判断 分单id  分单号是否为空
                if (cus.getSecondaryautoid() != null && cus.getWaybillnosecondary() != null) {
                    // 分单
                    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());
                    // 更新海关表  内容回执
                    int iii = updateMessage(cus);

                    if (i > 0 && ii > 0 && iii > 0) {

                        return 1;
                    }
                }else {

                    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());
                    // 更新海关表  内容回执
                    int iii = updateMessage(cus);

                    if (i > 0 && ii > 0 && iii > 0) {

                        return 1;
                    }

                    return 0;
                }
            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());
                // 更新海关表  内容回执
                int iii1 = updateMessage(cus);

                if (i > 0 && ii > 0 && iii1 > 0) {

                    return 1;
                }
            case "MT1201":

                return MT1201MT9999(customReception, cus, type);
            case "MT2201":
                // 判断 分单id  分单号是否为空
                if (cus.getSecondaryautoid() != null && cus.getWaybillnosecondary() != null) {
                    // 分单
                    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());
                    // 更新海关表  内容回执
                    int iii = updateMessage(cus);

                    if (i1 > 0 && ii1 > 0 && iii > 0) {

                        return 1;
                    }
                }else {

                    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());
                    // 更新海关表  内容回执
                    int iii = updateMessage(cus);

                    if (i1 > 0 && ii1 > 0 && iii > 0) {

                        return 1;
                    }

                    return 0;
                }
        }
        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.getSecondaryautoid() != null && cus.getWaybillnosecondary() != null) {
            // 分单
            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());
            // 更新海关表  内容回执
            int iii = updateMessage(cus);

            if (i > 0 && ii > 0 && iii > 0) {

                return 1;
            }

            return 0;
        }else {

            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());
            // 更新海关表  内容回执
            int iii = updateMessage(cus);

            if (i > 0 && ii > 0 && iii > 0) {

                return 1;
            }

            return 0;
        }
    }


    // MT9999 MT1201
    public int MT1201MT9999(CustomReception customReception, CUSTOMSMESSAGEWithBLOBs cus, String type) {
        // 发送日志 插入
        CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();
        // 判断 分单id  分单号是否为空
        if (cus.getSecondaryautoid() != null && cus.getWaybillnosecondary() != null) {
            // 分单
            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());

            // 更新海关表  内容回执
            int iii = updateMessage(cus);

            if (i > 0 && ii > 0 && iii > 0) {

                return 1;
            }
            return 0;
        } else {
            // 主单
            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());


            // 更新海关表  内容回执
            int iii = updateMessage(cus);

            if (i > 0 && ii > 0 && iii > 0) {

                return 1;
            }

            return 0;
        }
    }


    // messageId 更新
    public int updateMessage(CUSTOMSMESSAGEWithBLOBs cus){
        return 0;
//        return customsmessageMapper.updateMessage(cus);
    }


    public int updateMessages(CustomReception cr){

        CUSTOMSMESSAGEWithBLOBs cus = new CUSTOMSMESSAGEWithBLOBs();

        cus.setMessageid(cr.getMessageID());
        cus.setResponsetext(cr.getResponseText());

//        return customsmessageMapper.updateMessage(cus);
        return 0;
    }

}