PREPAREMASTERServiceImp.java 5.2 KB
package com.tianbo.analysis.service.imp;

import com.tianbo.analysis.dao.PREPAREMASTERMapper;
import com.tianbo.analysis.dao.PREPARESECONDARYMapper;
import com.tianbo.analysis.model.CustomReception;
import com.tianbo.analysis.model.PREPAREMASTER;
import com.tianbo.analysis.model.PREPARESECONDARY;
import com.tianbo.analysis.service.PREPAREMASTERService;
import com.tianbo.util.Date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Auther: shenhl
 * @Date: 2019/8/26 15:29
 */
@Service
@Slf4j
public class PREPAREMASTERServiceImp implements PREPAREMASTERService {

    @Autowired
    PREPAREMASTERMapper preparemasterMapper;

    @Autowired
    PREPARESECONDARYMapper preparesecondaryMapper;

    @Override
    // 货物接收运抵主分单
    public int insertRecept(CustomReception customReception) {


        ShareServiceImp shareServiceImp = new ShareServiceImp();
        // 发送日志 插入
        CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();

        // 主单号
        String awbA = customReception.getWayBillMaster();
        String awbH = customReception.getWayBillSecond();
        //回执内容
        String reception = customReception.getResponseText();
        String flightDateStr = customReception.getFlightDate();
        if (!StringUtils.isEmpty(flightDateStr)) {
            Date flightDate = DateUtil.formatByyyyyMMdd(flightDateStr);

            // 设置 接收运抵分单  回执
            PREPARESECONDARY preparesecondary = new PREPARESECONDARY();
            preparesecondary.setReceiptinformation(reception);

            //设置主单回执、航班号、航班日期
            PREPAREMASTER preparemaster = new PREPAREMASTER();
            preparemaster.setReceiptinformation(reception);
            preparemaster.setFlightno(customReception.getFlightNo());
            preparemaster.setFlightdate(flightDate);

            if (awbA!=null && awbA.length()>0){
                StringBuffer stringBuffer = new StringBuffer(awbA);
                stringBuffer.insert(3,"-");
                awbA = stringBuffer.toString();

                //设置主分单的 主单号
                preparesecondary.setWaybillnomaster(awbA);
                preparemaster.setWaybillnomaster(awbA);
            }


            // 判断航班号 航班日期  是否为空
            if (flightDate != null && customReception.getFlightNo() != null){
                //有分单号 更新分单
                if(awbA!=null && awbA.length()>0 && awbH!=null && awbH.length()> 0){
                    //取分单号
                    String[] awbhArr = awbH.split("_");
                    String awbh = awbhArr[1];
                    preparesecondary.setWaybillnosecondary(awbh);
                    //更新分单回执
                    int i = preparesecondaryMapper.updateRECEIPTION(preparesecondary);
                    //获取分单autoid
                    List<PREPARESECONDARY> arrivedsecondaryList = preparesecondaryMapper.selectAutoIdByawbAawbH(preparesecondary);
                    if(!arrivedsecondaryList.isEmpty()){
                        PREPARESECONDARY preparesecondary1 = arrivedsecondaryList.get(0);
                        String autoId = preparesecondary1.getAutoid();
                        //插入sendlog记录表
                        log.info("即将插入日志运单号为:"+awbH+"->autoid="+autoId);
                        int ii = coustomAnalysisServiceImp.insertSendlog("MT3201",reception,autoId);

                        int iii = shareServiceImp.updateMessages(customReception);
                        if (i>0 && ii>0 && iii > 0){
                            return 1;
                        }
                    }
                    return 0;
                }

                //处理主单格式,将海关回执的主单号58019316861,变为580-19316861
                if (awbA!=null && awbA.length()>0){
                    //更新主单回执
                    int i = preparemasterMapper.updateRECEIPTION(preparemaster);
                    //获取分单autoid
                    List<PREPAREMASTER> arrivedmasterList = preparemasterMapper.selectAutoIdByAwb(preparemaster);
                    if(!arrivedmasterList.isEmpty()){
                        PREPAREMASTER originMaster = arrivedmasterList.get(0);
                        String autoId = originMaster.getAutoid();

                        //插入sendlog记录表
                        log.info("即将插入日志运单号为:"+awbA+"->autoid="+autoId);
                        int ii =coustomAnalysisServiceImp.insertSendlog("MT3201",reception,autoId);

                        int iii = shareServiceImp.updateMessages(customReception);
                        if (i>0 && ii>0 && iii > 0){
                            return 1;
                        }
                    }
                    return 0;
                }
            }else {


                return shareServiceImp.share("MT2201", customReception);
            }

        }

        //未进入主分单解析 返回0 失败
        return 0;
    }
}