ResMessageServiceImpl.java 4.0 KB
package com.sy.service.impl;

import com.sy.mapper.RESMESSAGEMapper;
import com.sy.model.GatherInfo;
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO;
import com.sy.model.RESMESSAGE;
import com.sy.service.CommandLogService;
import com.sy.service.ResMessageService;
import com.sy.socket.CommandClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import java.util.stream.Collectors;

/**
 * @author
 * @time 2019-${MOUTH}-22 21:32
 */
@Service
@Slf4j
public class ResMessageServiceImpl implements ResMessageService {
    private static String FANGXING="-等运单未放行";
    private static String AWB_EMPTY="未申请装载运单";

    @Autowired
    private RESMESSAGEMapper mapper;

    @Autowired
    CommandLogService commandLogService;


    @Override
    public int saveEnter(RESMESSAGE resmessage){
        return mapper.insertSelective(resmessage);
    }

    @Override
    public RESMESSAGE selectByManifest(String manifest){
        return mapper.selectByManifest(manifest);
    }

    @Override
    public List<RESMESSAGE> selectByManifestList(String[] manifest) {
        return mapper.selectByManifestList(manifest);
    }

    @Override
    public boolean checkManifestRelease(GatherInfo info, List<LAND_BUSINEESTYPE_LIST_INFO> list_infos) {
        List<String> noRelease = new Vector<>();
        if (list_infos.size() < 1) {
            CommandClient.Client(info, AWB_EMPTY);
            return false;
        }

        //只拉板箱的话,这里list_infos会为null
        list_infos = list_infos.stream().filter(listInfo ->{
            if("B".equals(listInfo.getExt4())){
                return true;
            }else {
                return false;
            }
        }).collect(Collectors.toList());

        log.info("运单列表:" + toStrArry(list_infos));
        boolean flag = false;

        /**
         * 这里如果list_infos为NULL,会报错NULL Exception.什么指令都不给了.
         * 如果申请单据只有ULD板箱类型的时候.
         */
        if (!list_infos.isEmpty()){
            List<RESMESSAGE> list = selectByManifestList(toStrArry(list_infos));

            if (list.size() == toStrArry(list_infos).length) {
                flag = true;
            }else{
                //返回未放行的运单列表
                if (toStrArry(list_infos).length>0){
                    for (String awb : toStrArry(list_infos)) {
                        boolean anyMatch = list.stream().anyMatch(resmessage -> {
                            return resmessage.getManifest().equals(awb);
                        });
                        if (!anyMatch){
                            noRelease.add(awb);
                        }
                    }
                    if (!noRelease.isEmpty()) {
                        log.info(Arrays.toString(noRelease.toArray())+FANGXING);
                        commandLogService.commandlog(info,false,Arrays.toString(noRelease.toArray())+FANGXING,null,list_infos,
                                new Double("0.0"),new Double("0.0"),new Double("0.0"),new Double("0.0"));
                        CommandClient.Client(info, Arrays.toString(noRelease.toArray())+FANGXING);
                    }
                }
            }
        }
        //todo:如果只拉集装器的判定
        else{
            log.info("[放行判定]:{}","集装器与散杂货放行");
            return true;
        }


        return flag;
    }
    public static String[] toStrArry(List<LAND_BUSINEESTYPE_LIST_INFO> list_infos){
        List<String> manifestList=new ArrayList<String>();
        for(LAND_BUSINEESTYPE_LIST_INFO land:list_infos){
            manifestList.add(land.getAwba().replace("-",""));
        }
        //manifestList = manifestList.replace("-", "").replace(",", ",");
        String[] maifest = manifestList.toArray(new String[manifestList.size()]);
        return maifest;
    }
}