审查视图

src/main/java/com/sy/service/lock/CustomsLockServiceImpl.java 11.5 KB
朱兆平 authored
1 2 3 4 5 6 7 8 9 10 11 12 13
package com.sy.service.lock;

import com.alibaba.fastjson.JSONObject;
import com.sy.mapper.LandBusinessTypeListMapper;
import com.sy.mapper.LandListDao;
import com.sy.model.GatherInfo;
import com.sy.model.LAND_BUSINEESTYPE_LIST_INFO;
import com.sy.model.LandBusinessTypeList;
import com.sy.model.LandList;
import com.sy.service.CustomsLockService;
import com.sy.service.LandBusListService;
import com.sy.service.RedisService;
import com.sy.service.impl.GatherInfoHandle;
14
import com.sy.utils.FileTool;
朱兆平 authored
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 关锁业务处理
 * @author mrz
 */
@Slf4j
@Service
public class CustomsLockServiceImpl implements CustomsLockService {

    @Resource
    private LandListDao landListDao;

    @Autowired
    private RedisService redisService;

    @Autowired
    private LandBusListService landBusListService;

    @Resource
    private LandBusinessTypeListMapper landBusinessTypeListMapper;

    /**
     * 缓存关锁相关前缀
     */
    private static String LOCK_PRE="LOCK-";

    @Override
    public void lockNotice() {

    }

    @Override
    public void unLockNotice() {

    }

    @Override
    public void cacheWrite(GatherInfo info) {
        redisService.set(LOCK_PRE+info.getBarcode(),
                JSONObject.toJSONString(info),
                60*60*6);
    }

    @Override
    public GatherInfo cacheRead(String barcode) {
        String jsonStr = redisService.get(LOCK_PRE+barcode);
        if (StringUtils.isNotEmpty(jsonStr)){
            GatherInfo gatherInfo = JSONObject.parseObject(jsonStr, GatherInfo.class);
            return gatherInfo;
        }
        return null;
    }

    @Override
    public void localGatherInfoHandle(GatherInfo gatherInfo) {
        GatherInfoHandle gatherInfoHandle = new GatherInfoHandle();
        gatherInfoHandle.handel(gatherInfo);
    }

    @Override
    public boolean lockNoticeCheck(GatherInfo info) {
        if (info!=null && StringUtils.isNotEmpty(info.getBarcode())) {
85 86
            //todo:这里后期判定可以复用场站白名单验证
//            FileTool.readProperties("station").contains(info.getAreaid());
朱兆平 authored
87 88 89 90 91 92 93 94
            /**
             * 申请业务类型检查
             * 调拨业务及分拨业务装载货物为单证的,必须有关锁号
             * 就算申请信息里面没关锁号也要通知
             */
            LandBusinessTypeList landBusinessTypeList = landBusListService.getLandBusinessTypeListByGather(info);
            if (landBusinessTypeList!=null){
                if ("调拨业务".equals(landBusinessTypeList.getBusinesstype()) || "分拨业务".equals(landBusinessTypeList.getBusinesstype())) {
95
96
                    String sfAreaid = "4600541001";
97 98
                    String zbqAreaid = "4600329012";
                    String zbqN3Areaid = "4612199001";
99 100 101 102 103 104 105 106 107 108 109 110 111
                    String xhAreaid = "4604000000";
                    String bhAreaid = "4604600000";

                    //北货三号卡口出通道
                    String bh_3_out = "4604600030";
                    //北货三号卡口进通道1
                    String bh_3_in1= "4604601030";
                    //北货三号卡口进通道2
                    String bh_3_in2= "4604601031";
                    // 西货站出通道1
                    String xh_1_out = "4604333312";
                    // 西货站出通道2
                    String xh_2_out = "4604333322";
112 113 114 115 116

                    String carEndstationList = redisService.get(info.getVename() + "_endstationList");
                    if (StringUtils.isNotEmpty(info.getVename()) && StringUtils.isNotEmpty(carEndstationList)){
                        //涉及综保区场站的申请不核验关锁业务.
                        if (carEndstationList.contains(zbqAreaid)) {
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
                            if ("分拨业务".equals(landBusinessTypeList.getBusinesstype())){
                                if (info.getChnlno().equals(bh_3_out)) {
                                    log.info("[LOCK-CHECK-TRUE]-分拨业务-综保区北货流转业务,北货区域关锁通知,当前场站北货站");
                                    return true;
                                }
                                if (info.getAreaid().equals(xhAreaid)) {
                                    log.info("[LOCK-CHECK-TRUE]-分拨业务-西货综保区流转业务,西货区域关锁通知,当前场站西货站");
                                    return true;
                                }
                            }
                            if ("调拨业务".equals(landBusinessTypeList.getBusinesstype())){
                                //申请设计综保区的流转场站,除了综保区不通知,其他场站正常通知
                                /**
                                 *  从综保区往北货或者西货调拨时,都不进行关锁通知,因为从综保区出来没有关锁施封记录无法到北货解封.没关锁秘钥,采用人工解封
                                 *  从西货或者北货往综保区调拨的话,进行施封通知,到综保区后不进行解封通知,采用人工解封
                                 */


                                if (info.getChnlno().equals(bh_3_out) ||  info.getChnlno().equals(xh_1_out) ||  info.getChnlno().equals(xh_2_out)){
                                    log.info("[LOCK-CHECK]-含综保区调拨业务-关锁施封通知,当前通道:{}",info.getChnlno());
                                    return true;
                                }
                            }
                            log.info("[LOCK-CHECK-NOTICE]-申报场站列表包含综保区,不处理关锁业务,当前场站:{}",landBusinessTypeList.getEndstation());
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
                            return false;
                        }

                        //综保区场站及内三不通知,顺丰场站不通知
                        if (zbqAreaid.equals(landBusinessTypeList.getEndstation())
                                || zbqN3Areaid.equals(landBusinessTypeList.getEndstation())
                                || sfAreaid.equals(landBusinessTypeList.getEndstation())
                        ) {
                            log.info("[LOCK-CHECK]-综保区及内三场站,顺丰场站,不处理关锁业务,当前场站:{}",landBusinessTypeList.getEndstation());
                            return false;
                        }else {
                            return true;
                            /**
                             * 单证验证-取消
                             */
朱兆平 authored
156 157 158 159 160 161 162 163 164 165 166 167
//                        List<LAND_BUSINEESTYPE_LIST_INFO> land_busineestype_list_infos = landBusinessTypeList.getLandBusineestypeListInfoList();
//                        if (!land_busineestype_list_infos.isEmpty()){
//                            LAND_BUSINEESTYPE_LIST_INFO list_info = land_busineestype_list_infos.stream().parallel()
//                                    .filter(item -> "B".equals(item.getExt4()))
//                                    .findAny().orElse(null);
//
//                            //包含单证
//                            if (list_info!=null){
//                                log.info("[LOCK-CHECK]-包含单证,开始关锁通知");
//                                return true;
//                            }
//                        }
168 169 170
                        }
                    }else {
                        return false;
朱兆平 authored
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
                    }
                }
            }else {
                log.info("[LOCK-CHECK]-无对应进出场申请");
                return false;
            }
        }
        return false;
    }

    @Override
    public boolean lockCheck(GatherInfo info) {
        int e = landBusListService.selectFirstLeave(info.getVename(), info.getBarcode(), "E");
        if (e==0){
            //首次离场,通知关锁接口 上锁
186 187 188 189 190 191 192 193 194 195 196 197 198 199
            log.info("[UNLOCK-NOTICE]-非顺丰场站业务上锁通知");

            /**
             * 涉及顺丰的场站业务涉及三个场站
             * 顺丰的通道没有读解锁设备
             * 需要在快邮卡口进行解读锁
             */
            //顺丰出通道,首次出不上锁
            String sfExportChanel = "4600010001";
            if (sfExportChanel.equals(info.getChnlno())) {
                log.warn("[UNLOCK-NOTICE]-顺丰货站,不进行上锁通知,{}",info.getBarcode());
                return false;
            }
朱兆平 authored
200
            return true;
201 202 203 204 205 206 207 208 209 210 211 212
        }else {
            /**
             * 顺丰上锁通知判定,是在第二个离场通道进行施封
             * 当前场站是快邮货站出
             * 有一个离场信息,那么就上锁通知
             */
            //快邮出通道,上锁通知,二次出上锁
            String sfExportChanel = "4604110112";
            if (sfExportChanel.equals(info.getChnlno()) && e==1){
                log.warn("[UNLOCK-NOTICE]-快邮货站,进行上锁通知,{}",info.getBarcode());
                return true;
            }
朱兆平 authored
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
        }

        return false;
    }

    @Override
    public boolean unLockCheck(GatherInfo info){

        //从缓存获取通道流转列表信息
        List<LandBusinessTypeList> landBusinessTypeListsByGather = landBusListService.getLandBusinessTypeListsByGather(info);
        List<LandBusinessTypeList> temp = landBusinessTypeListsByGather;
        //已经过场的记录
        List<LandBusinessTypeList> landBusinessTypeLists = landBusinessTypeListMapper.selectHistory(info.getVename(), info.getBarcode());

        for (LandBusinessTypeList formItem : landBusinessTypeLists) {
            List<LandBusinessTypeList> r = landBusinessTypeListsByGather.stream().filter(item -> {
                if (item.getEndstation().equals(formItem.getEndstation())) {
                    log.info("[Lock-Stream-loop]-缓存元素场站:[{}],已出入记录场站:[{}]-核销判定对碰成功", item.getEndstation(), formItem.getEndstation());
                    return true;
                } else {
                    return false;
                }
            }).collect(Collectors.toList());
            temp.removeAll(r);
        }


        //筛选出未入场的申请
        List<String> stationList = temp.stream().map(LandBusinessTypeList::getEndstation).distinct().collect(Collectors.toList());
        log.info("[unLockCheck]-未走的流转申请:{}",temp.size());

        //判定是否还剩最后一个场站未入场
        if (stationList.size() == 1){
246 247 248 249 250 251 252 253 254

            //顺丰进通道,解锁通知,末次进不解锁
            String sfImportChanel = "4600011001";
            if (sfImportChanel.equals(info.getChnlno())) {
                log.warn("[UNLOCK-NOTICE]-顺丰货站,不进行解锁通知,{}",info.getBarcode());
                return false;
            }

朱兆平 authored
255 256 257 258 259 260 261 262
            //场站信息 与 当前GatherInfo信息又对的上
            if (stationList.get(0).equals(info.getAreaid())) {
                //通知解锁
                log.info("[UNLOCK-NOTICE]-解锁通知");
                return true;
            }
        }
263 264 265 266 267 268 269 270 271 272
        /**
         * 顺丰快邮特殊判定
         */
        //快邮进通道,解锁通知,二次进锁
        String kyImportChanel = "4604111111";
        if (kyImportChanel.equals(info.getChnlno()) && stationList.size() == 2 ){
            log.info("[UNLOCK-NOTICE]-快邮货站,解锁通知,{}",info.getBarcode());
            return true;
        }
朱兆平 authored
273 274 275
        return false;
    }
}