package com.zy.common.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.SpringUtils; import com.zy.asrs.utils.Utils; import com.zy.common.model.NavigateNode; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.SlaveType; import com.zy.core.model.ForkLiftSlave; import com.zy.core.model.protocol.ForkLiftStaProtocol; import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.ForkLiftThread; import com.zy.system.entity.Config; import com.zy.system.service.ConfigService; import java.util.ArrayList; import java.util.HashMap; import java.util.List; /** * 货叉提升机工具类 */ public class ForkLiftUtils { //获取提升机所有站点 public static List getLiftAllStaNo(Integer liftNo) { List list = new ArrayList<>(); ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo); if (forkLiftThread == null) { return list; } for (ForkLiftStaProtocol forkLiftStaProtocol : forkLiftThread.getForkLiftStaProtocols()) { list.add(forkLiftStaProtocol.getStaNo()); } return list; } //获取提升机所绑定的输送线所有站点 public static List getConveyorBindLiftAllStaNo(Integer liftNo) { List list = new ArrayList<>(); ConfigService configService = SpringUtils.getBean(ConfigService.class); if (configService == null) { return list; } Config conveyorLiftBindConfig = configService.selectOne(new EntityWrapper().eq("code", "conveyorLiftBind")); if(conveyorLiftBindConfig == null) { return list; } List val = JSON.parseArray(conveyorLiftBindConfig.getValue(), JSONObject.class); if (val.isEmpty()) { return list; } for (JSONObject data : val) { if(data.getInteger("liftNo").equals(liftNo)) { list.add(data.getInteger("staNo")); } } return list; } //获取提升机站点 public static ForkLiftStaProtocol getLiftStaByStaNo(Integer staNo) { SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class); for (ForkLiftSlave liftSlave : slaveProperties.getForkLift()) { ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftSlave.getId()); if (forkLiftThread == null) { return null; } for (ForkLiftStaProtocol forkLiftStaProtocol : forkLiftThread.getForkLiftStaProtocols()) { if (forkLiftStaProtocol.getStaNo().equals(staNo)) { return forkLiftStaProtocol; } } } return null; } //获取提升机站点 public static ForkLiftStaProtocol getLiftStaByLev(Integer liftNo, Integer lev) { ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo); if (forkLiftThread == null) { return null; } for (ForkLiftStaProtocol forkLiftStaProtocol : forkLiftThread.getForkLiftStaProtocols()) { if (forkLiftStaProtocol.getLev().equals(lev)) { return forkLiftStaProtocol; } } return null; } //获取提升机输送站及其前一站节点 public static List getLiftStaNodes(Integer staNo) { List targetNodes = new ArrayList<>(); //获取目标站 ForkLiftStaProtocol targetLiftSta = ForkLiftUtils.getLiftStaByStaNo(staNo); if (targetLiftSta == null) { return null;//找不到站点 } NavigateNode targetNode = NavigatePositionConvert.locNoToNode(targetLiftSta.getLocNo());//目标节点 String targetLastLocNo = Utils.getLocNo(Utils.getRow(targetLiftSta.getLocNo()) - 1, Utils.getBay(targetLiftSta.getLocNo()), Utils.getLev(targetLiftSta.getLocNo()));//目标节点前一站 NavigateNode targetLastNode = NavigatePositionConvert.locNoToNode(targetLastLocNo);//目标节点前一站 targetNodes.add(targetNode); targetNodes.add(targetLastNode); return targetNodes; } //通过输送线站号获取对应提升机号 public static Integer getConveyorBindLiftNo(Integer staNo) { ConfigService configService = SpringUtils.getBean(ConfigService.class); if (configService == null) { return null; } Config conveyorLiftBindConfig = configService.selectOne(new EntityWrapper().eq("code", "conveyorLiftBind")); if(conveyorLiftBindConfig == null) { return null; } List list = JSON.parseArray(conveyorLiftBindConfig.getValue(), JSONObject.class); if (list.isEmpty()) { return null; } for (JSONObject data : list) { if(data.getInteger("staNo").equals(staNo)) { return data.getInteger("liftNo"); } } return null; } //请求上级系统,是否允许出库 //查询是否有出库权限 public static boolean queryOutMission(Integer staNo) { ConfigService configService = SpringUtils.getBean(ConfigService.class); if (configService == null) { return false; } Config queryOutMissionPathEnableConfig = configService.selectOne(new EntityWrapper().eq("code", "queryOutMissionPathEnable")); if (queryOutMissionPathEnableConfig != null) { String queryOutMissionPathEnable = queryOutMissionPathEnableConfig.getValue(); if (!queryOutMissionPathEnable.equals("Y")) { return true;//关闭查询出库权限功能 } } Config superSystemUriConfig = configService.selectOne(new EntityWrapper().eq("code", "superSystemUri")); if (superSystemUriConfig == null) { return false; } String superSystemUri = superSystemUriConfig.getValue(); Config queryOutMissionPathConfig = configService.selectOne(new EntityWrapper().eq("code", "queryOutMissionPath")); if (queryOutMissionPathConfig == null) { return false; } String missionPath = queryOutMissionPathConfig.getValue(); try { HashMap data = new HashMap<>(); data.put("staNo", staNo); String response = new HttpHandler.Builder() .setUri(superSystemUri) .setPath(missionPath) .setJson(JSON.toJSONString(data)) .build() .doPost(); if (response.equals("ok")) { return true;//有出库权限 } }catch (Exception e){ e.printStackTrace(); } return false; } //请求上级系统,是否允许入库 //查询是否有入库权限 public static boolean queryInMission(Integer sourceStaNo, Integer liftNo, String superTaskNo) { ConfigService configService = SpringUtils.getBean(ConfigService.class); if (configService == null) { return false; } Config queryInMissionPathEnableConfig = configService.selectOne(new EntityWrapper().eq("code", "queryInMissionPathEnable")); if (queryInMissionPathEnableConfig != null) { String queryInMissionPathEnable = queryInMissionPathEnableConfig.getValue(); if (!queryInMissionPathEnable.equals("Y")) { return true;//关闭查询入库权限功能 } } Config superSystemUriConfig = configService.selectOne(new EntityWrapper().eq("code", "superSystemUri")); if (superSystemUriConfig == null) { return false; } String superSystemUri = superSystemUriConfig.getValue(); Config queryInMissionPathConfig = configService.selectOne(new EntityWrapper().eq("code", "queryInMissionPath")); if (queryInMissionPathConfig == null) { return false; } String missionPath = queryInMissionPathConfig.getValue(); try { HashMap data = new HashMap<>(); data.put("staNo", sourceStaNo); data.put("liftNo", liftNo); data.put("superTaskNo", superTaskNo); String response = new HttpHandler.Builder() .setUri(superSystemUri) .setPath(missionPath) .setJson(JSON.toJSONString(data)) .build() .doPost(); if (response.equals("ok")) { return true;//有入库权限 } } catch (Exception e) { e.printStackTrace(); } return false; } }