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; import com.sy.utils.FileTool; 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())) { //todo:这里后期判定可以复用场站白名单验证 // FileTool.readProperties("station").contains(info.getAreaid()); /** * 申请业务类型检查 * 调拨业务及分拨业务装载货物为单证的,必须有关锁号 * 就算申请信息里面没关锁号也要通知 */ LandBusinessTypeList landBusinessTypeList = landBusListService.getLandBusinessTypeListByGather(info); if (landBusinessTypeList!=null){ if ("调拨业务".equals(landBusinessTypeList.getBusinesstype()) || "分拨业务".equals(landBusinessTypeList.getBusinesstype())) { String sfAreaid = "4600541001"; String zbqAreaid = "4600329012"; String zbqN3Areaid = "4612199001"; 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"; String carEndstationList = redisService.get(info.getVename() + "_endstationList"); if (StringUtils.isNotEmpty(info.getVename()) && StringUtils.isNotEmpty(carEndstationList)){ //涉及综保区场站的申请不核验关锁业务. if (carEndstationList.contains(zbqAreaid)) { 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()); 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; /** * 单证验证-取消 */ // 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; // } // } } }else { return false; } } }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){ //首次离场,通知关锁接口 上锁 log.info("[UNLOCK-NOTICE]-非顺丰场站业务上锁通知"); /** * 涉及顺丰的场站业务涉及三个场站 * 顺丰的通道没有读解锁设备 * 需要在快邮卡口进行解读锁 */ //顺丰出通道,首次出不上锁 String sfExportChanel = "4600010001"; if (sfExportChanel.equals(info.getChnlno())) { log.warn("[UNLOCK-NOTICE]-顺丰货站,不进行上锁通知,{}",info.getBarcode()); return false; } return true; }else { /** * 顺丰上锁通知判定,是在第二个离场通道进行施封 * 当前场站是快邮货站出 * 有一个离场信息,那么就上锁通知 */ //快邮出通道,上锁通知,二次出上锁 String sfExportChanel = "4604110112"; if (sfExportChanel.equals(info.getChnlno()) && e==1){ log.warn("[UNLOCK-NOTICE]-快邮货站,进行上锁通知,{}",info.getBarcode()); return true; } } 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){ //顺丰进通道,解锁通知,末次进不解锁 String sfImportChanel = "4600011001"; if (sfImportChanel.equals(info.getChnlno())) { log.warn("[UNLOCK-NOTICE]-顺丰货站,不进行解锁通知,{}",info.getBarcode()); return false; } //场站信息 与 当前GatherInfo信息又对的上 if (stationList.get(0).equals(info.getAreaid())) { //通知解锁 log.info("[UNLOCK-NOTICE]-解锁通知"); return true; } } /** * 顺丰快邮特殊判定 */ //快邮进通道,解锁通知,二次进锁 String kyImportChanel = "4604111111"; if (kyImportChanel.equals(info.getChnlno()) && stationList.size() == 2 ){ log.info("[UNLOCK-NOTICE]-快邮货站,解锁通知,{}",info.getBarcode()); return true; } return false; } }