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

import com.sy.mapper.RESMESSAGEMapper;
import com.sy.model.GatherInfo;
import com.sy.model.RESMESSAGE;
import com.sy.service.ResMessageService;
import com.sy.socket.CommandClient;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Vector;

/**
 * @author
 * @time 2019-${MOUTH}-22 21:32
 */
@Service
public class ResMessageServiceImpl implements ResMessageService {
    private static final Logger logger = Logger.getLogger(ResMessageServiceImpl.class);
    private static String FANGXING="-等运单未放行";
    private static String AWB_EMPTY="未申请装载运单";
    @Autowired
    private RESMESSAGEMapper mapper;


    @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,String manifestList) {
        List<String> noRelease = new Vector<>();
        if (manifestList.length() < 1) {
            CommandClient.Client(info, AWB_EMPTY);
            return false;
        }
        manifestList = manifestList.replace("-", "").replace(",", ",");
        String[] maifest = manifestList.split(",");
        logger.info("运单列表:" + manifestList);
        boolean flag = false;

        List<RESMESSAGE> list = selectByManifestList(maifest);

        if (list.size() == maifest.length) {
            flag = true;
        }else{
            //返回未放行的运单列表
            if (maifest.length>0){
                for (String awb : maifest) {
                    boolean anyMatch = list.stream().anyMatch(resmessage -> {
                        return resmessage.getManifest().equals(awb);
                    });
                    if (!anyMatch){
                        noRelease.add(awb);
                    }
                }
                if (!noRelease.isEmpty()) {
                    logger.info(Arrays.toString(noRelease.toArray())+FANGXING);
                    CommandClient.Client(info, Arrays.toString(noRelease.toArray())+FANGXING);
                }
            }
        }
        return flag;
    }
}