| | |
| | | if (param == null) { |
| | | return R.error("åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | boolean result = commonService.createInTask(param); |
| | | if (result) { |
| | | WrkMast wrkMast = commonService.createInTask(param); |
| | | if (wrkMast != null) { |
| | | return R.ok(); |
| | | } |
| | | return R.error("çæå
¥åºä»»å¡å¤±è´¥"); |
| | |
| | | } |
| | | |
| | | //å
¥åºä»»å¡ |
| | | public boolean createInTask(CreateInTaskParam param) { |
| | | public WrkMast createInTask(CreateInTaskParam param) { |
| | | Date now = new Date(); |
| | | LocMast locMast = locMastService.queryByLoc(param.getLocNo()); |
| | | if (null == locMast) { |
| | |
| | | |
| | | //ç¼åè®°å½å½åå½ä»¤å åæºç¼å· |
| | | redisUtil.set(RedisKeyType.CURRENT_CIRCLE_TASK_CRN_NO.key, crnNo, 60 * 60 * 24); |
| | | return true; |
| | | return wrkMast; |
| | | } |
| | | |
| | | //åºåºä»»å¡ |
| | |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.core.enums.MapNodeType; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.function.BiFunction; |
| | | |
| | | /** |
| | | * A*ç®æ³å®ç°ç±» |
| | |
| | | return null; |
| | | } |
| | | |
| | | public List<List<NavigateNode>> allSimplePaths( |
| | | List<List<NavigateNode>> map, |
| | | NavigateNode start, |
| | | NavigateNode end, |
| | | int maxDepth, // æå¤§æ¥æ°(è¾¹æ°). 建议ï¼50/100/200ï¼<=0 表示ä¸éå¶ï¼ä¸å»ºè®®ï¼ |
| | | int maxPaths, // æå¤§è¿åæ¡æ°. 建议ï¼100/500/2000ï¼<=0 表示ä¸éå¶ï¼ä¸å»ºè®®ï¼ |
| | | int maxCost // æå¤§æ»ä»£ä»·(å«æç¹æ©ç½). <=0 表示ä¸éå¶ |
| | | ) { |
| | | List<List<NavigateNode>> results = new ArrayList<>(); |
| | | if (map == null || map.isEmpty() || map.get(0).isEmpty()) return results; |
| | | if (start == null || end == null) return results; |
| | | if (start.getValue() == MapNodeType.DISABLE.id || end.getValue() == MapNodeType.DISABLE.id) return results; |
| | | |
| | | // visited ç¨åæ keyï¼é¿å
NavigateNode equals/hashCode ä¸å¯é 导è´éå¤å¤æå¤±æ |
| | | Set<String> visited = new HashSet<>(map.size() * map.get(0).size() * 2); |
| | | LinkedList<NavigateNode> path = new LinkedList<>(); |
| | | |
| | | String startKey = keyOf(start); |
| | | visited.add(startKey); |
| | | path.add(start); |
| | | |
| | | AtomicInteger pathCount = new AtomicInteger(0); |
| | | |
| | | dfsAllSimplePaths(map, start, end, |
| | | visited, path, results, |
| | | 0, // depth |
| | | 0, // cost |
| | | maxDepth, maxPaths, maxCost, |
| | | pathCount |
| | | ); |
| | | |
| | | return results; |
| | | } |
| | | |
| | | /** |
| | | * DFS + åæº¯ï¼æä¸¾ææç®åè·¯å¾ï¼è·¯å¾ä¸ä¸å
许éå¤èç¹ï¼ |
| | | */ |
| | | private void dfsAllSimplePaths( |
| | | List<List<NavigateNode>> map, |
| | | NavigateNode current, |
| | | NavigateNode end, |
| | | Set<String> visited, |
| | | LinkedList<NavigateNode> path, |
| | | List<List<NavigateNode>> results, |
| | | int depth, // å½åæ¥æ°ï¼è¾¹æ°ï¼ |
| | | int cost, // å½åæ»ä»£ä»·ï¼ä½ å¯ä»¥è®¤ä¸ºæ¯ gï¼ |
| | | int maxDepth, |
| | | int maxPaths, |
| | | int maxCost, |
| | | AtomicInteger pathCount |
| | | ) { |
| | | // é²çï¼æ¡æ°éå¶ |
| | | if (maxPaths > 0 && pathCount.get() >= maxPaths) return; |
| | | |
| | | // å°è¾¾ç»ç¹ï¼æ¶éè·¯å¾ |
| | | if (current.getX() == end.getX() && current.getY() == end.getY()) { |
| | | results.add(new ArrayList<>(path)); |
| | | pathCount.incrementAndGet(); |
| | | return; |
| | | } |
| | | |
| | | // é²çï¼æ·±åº¦éå¶ï¼depth 表示已走çè¾¹æ°ï¼ |
| | | if (maxDepth > 0 && depth >= maxDepth) return; |
| | | |
| | | // æ©å±é»å±
ï¼ä¸¥æ ¼å¤ç¨ä½ èªå·±çå¯è¡èµ°æ¹åè§åï¼ |
| | | ArrayList<NavigateNode> neighbors = extend_current_node(map, current); |
| | | if (neighbors == null || neighbors.isEmpty()) return; |
| | | |
| | | for (NavigateNode next : neighbors) { |
| | | // é²çï¼æ¡æ°éå¶ |
| | | if (maxPaths > 0 && pathCount.get() >= maxPaths) return; |
| | | |
| | | if (next == null) continue; |
| | | if (next.getValue() == MapNodeType.DISABLE.id) continue; |
| | | |
| | | String nk = keyOf(next); |
| | | |
| | | // ç®åè·¯å¾ï¼ä¸å
许éå¤èç¹ |
| | | if (visited.contains(nk)) continue; |
| | | |
| | | // ä½ ç代价è§åï¼æ¯æ¥ 1 + æç¹æ©ç½ |
| | | int stepCost = 1 + calcNodeExtraCost(current, next, end); |
| | | int newCost = cost + stepCost; |
| | | |
| | | // é²çï¼æ»ä»£ä»·éå¶ |
| | | if (maxCost > 0 && newCost > maxCost) continue; |
| | | |
| | | // è¿å
¥ |
| | | visited.add(nk); |
| | | path.addLast(next); |
| | | |
| | | dfsAllSimplePaths(map, next, end, |
| | | visited, path, results, |
| | | depth + 1, |
| | | newCost, |
| | | maxDepth, maxPaths, maxCost, |
| | | pathCount |
| | | ); |
| | | |
| | | // åæº¯ |
| | | path.removeLast(); |
| | | visited.remove(nk); |
| | | } |
| | | } |
| | | |
| | | private String keyOf(NavigateNode n) { |
| | | return n.getX() + "_" + n.getY(); |
| | | } |
| | | |
| | | public ArrayList<NavigateNode> extend_current_node(List<List<NavigateNode>> map, NavigateNode current_node) { |
| | | //è·åå½åç»ç¹çx, y |
| | | int x = current_node.getX(); |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.zy.core.News; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.service.DeviceConfigService; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | |
| | | @Component |
| | | public class NavigateUtils { |
| | |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | News.info("[WCS Debug] ç«ç¹è·¯å¾å¼å§è®¡ç®,startStationId={},endStationId={}", startStationId, endStationId); |
| | | NavigateNode res_node = navigateSolution.astarSearchJava(stationMap, startNode, endNode); |
| | | if (res_node == null) { |
| | | List<List<NavigateNode>> allList = navigateSolution.allSimplePaths(stationMap, startNode, endNode, 120, 500, 300); |
| | | if (allList.isEmpty()) { |
| | | throw new CoolException("æªæ¾å°è¯¥è·¯å¾"); |
| | | } |
| | | News.info("[WCS Debug] ç«ç¹è·¯å¾è®¡ç®å®æï¼èæ¶ï¼{}ms", System.currentTimeMillis() - startTime); |
| | | |
| | | ArrayList<NavigateNode> list = new ArrayList<>(); |
| | | // ä½¿ç¨ visited éå鲿¢ç¶é¾åºç°ç¯å¯¼è´æ»å¾ªç¯ï¼åæ¶è®¾ç½®å®å
¨æ¥æ°ä¸é |
| | | HashSet<NavigateNode> visited = new HashSet<>(); |
| | | int maxSteps = stationMap.size() * stationMap.get(0).size() + 5; // å®å
¨ä¸é |
| | | int steps = 0; |
| | | while (res_node != null && visited.add(res_node) && steps++ < maxSteps) { |
| | | list.add(res_node); |
| | | res_node = res_node.getFather();//è¿ä»£æä½ |
| | | } |
| | | if (steps >= maxSteps) { |
| | | throw new CoolException("è·¯å¾å溯è¶
åºå®å
¨ä¸éï¼çä¼¼åå¨ç¶é¾å¾ªç¯"); |
| | | } |
| | | Collections.reverse(list); |
| | | //å°æ¯ä¸ªèç¹éé¢çfatherNodeè³ä¸ºnull(æ¹ä¾¿åç»è®¡ç®æ¶ç¶èç¹è¿å¤å¯¼è´æ¾ç¤ºçèç¹å¤ªå¤) |
| | | for (NavigateNode navigateNode : list) { |
| | | //ç¶èç¹è®¾ç½®ä¸ºnullï¼ä¸å½±å计ç®ç»æï¼ä¸å½±ååç»æä½ã |
| | | //æ¤æä½ä»
为åç»ææ¥å¤çæä¾è§è§æ¹ä¾¿ã |
| | | navigateNode.setFather(null); |
| | | } |
| | | startTime = System.currentTimeMillis(); |
| | | News.info("[WCS Debug] ç«ç¹è·¯å¾æéå¼å§åæ,startStationId={},endStationId={}", startStationId, endStationId); |
| | | List<NavigateNode> list = findStationBestPath(allList); |
| | | News.info("[WCS Debug] ç«ç¹è·¯å¾æéåæå®æï¼èæ¶ï¼{}ms", System.currentTimeMillis() - startTime); |
| | | |
| | | //å»é |
| | | HashSet<Integer> set = new HashSet<>(); |
| | |
| | | |
| | | return liftStationList; |
| | | } |
| | | |
| | | public synchronized List<NavigateNode> findStationBestPath(List<List<NavigateNode>> allList) { |
| | | if (allList == null || allList.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> statusMap = new HashMap<>(); |
| | | try { |
| | | DeviceConfigService deviceConfigService = SpringUtils.getBean(DeviceConfigService.class); |
| | | if (deviceConfigService != null) { |
| | | List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Devp))); |
| | | for (DeviceConfig deviceConfig : devpList) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, deviceConfig.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | Map<Integer, StationProtocol> m = stationThread.getStatusMap(); |
| | | if (m != null && !m.isEmpty()) { |
| | | statusMap.putAll(m); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception ignore) {} |
| | | |
| | | List<List<NavigateNode>> candidates = new ArrayList<>(); |
| | | List<Integer> lens = new ArrayList<>(); |
| | | List<Integer> tasksList = new ArrayList<>(); |
| | | List<Double> congs = new ArrayList<>(); |
| | | |
| | | for (List<NavigateNode> path : allList) { |
| | | if (path == null || path.isEmpty()) { |
| | | continue; |
| | | } |
| | | int len = path.size(); |
| | | int tasks = 0; |
| | | HashSet<Integer> stationIdSet = new HashSet<>(); |
| | | for (NavigateNode node : path) { |
| | | JSONObject value = null; |
| | | try { |
| | | value = JSON.parseObject(node.getNodeValue()); |
| | | } catch (Exception ignore) {} |
| | | if (value == null) { |
| | | continue; |
| | | } |
| | | Integer stationId = value.getInteger("stationId"); |
| | | if (stationId == null) { |
| | | continue; |
| | | } |
| | | if (!stationIdSet.add(stationId)) { |
| | | continue; |
| | | } |
| | | StationProtocol protocol = statusMap.get(stationId); |
| | | if (protocol != null && protocol.getTaskNo() != null && protocol.getTaskNo() > 0) { |
| | | tasks++; |
| | | } |
| | | } |
| | | double cong = len <= 0 ? 0.0 : (double) tasks / (double) len; |
| | | candidates.add(path); |
| | | lens.add(len); |
| | | tasksList.add(tasks); |
| | | congs.add(cong); |
| | | } |
| | | |
| | | if (candidates.isEmpty()) { |
| | | return allList.get(0); |
| | | } |
| | | |
| | | int minLen = Integer.MAX_VALUE; |
| | | int maxLen = Integer.MIN_VALUE; |
| | | double minCong = Double.MAX_VALUE; |
| | | double maxCong = -Double.MAX_VALUE; |
| | | for (int i = 0; i < candidates.size(); i++) { |
| | | int l = lens.get(i); |
| | | double c = congs.get(i); |
| | | if (l < minLen) minLen = l; |
| | | if (l > maxLen) maxLen = l; |
| | | if (c < minCong) minCong = c; |
| | | if (c > maxCong) maxCong = c; |
| | | } |
| | | |
| | | //é¿åº¦æéç¾åæ¯ |
| | | double lenWeightPercent = 50.0; |
| | | //æ¥å µæéç¾åæ¯ |
| | | double congWeightPercent = 50.0; |
| | | try { |
| | | ConfigService configService = SpringUtils.getBean(ConfigService.class); |
| | | if (configService != null) { |
| | | Config cfgLen = configService.selectOne(new EntityWrapper<Config>().eq("code", "stationPathLenWeightPercent")); |
| | | if (cfgLen != null && cfgLen.getValue() != null) { |
| | | String v = cfgLen.getValue().trim(); |
| | | if (v.endsWith("%")) v = v.substring(0, v.length() - 1); |
| | | try { lenWeightPercent = Double.parseDouble(v); } catch (Exception ignore) {} |
| | | } |
| | | Config cfgCong = configService.selectOne(new EntityWrapper<Config>().eq("code", "stationPathCongWeightPercent")); |
| | | if (cfgCong != null && cfgCong.getValue() != null) { |
| | | String v = cfgCong.getValue().trim(); |
| | | if (v.endsWith("%")) v = v.substring(0, v.length() - 1); |
| | | try { congWeightPercent = Double.parseDouble(v); } catch (Exception ignore) {} |
| | | } |
| | | } |
| | | } catch (Exception ignore) {} |
| | | |
| | | double weightSum = lenWeightPercent + congWeightPercent; |
| | | double lenW = weightSum <= 0 ? 0.5 : lenWeightPercent / weightSum; |
| | | double congW = weightSum <= 0 ? 0.5 : congWeightPercent / weightSum; |
| | | |
| | | List<NavigateNode> best = null; |
| | | double bestCost = Double.MAX_VALUE; |
| | | int bestTasks = Integer.MAX_VALUE; |
| | | int bestLen = Integer.MAX_VALUE; |
| | | for (int i = 0; i < candidates.size(); i++) { |
| | | int l = lens.get(i); |
| | | int t = tasksList.get(i); |
| | | double c = congs.get(i); |
| | | //å½ä¸å |
| | | double lenNorm = (maxLen - minLen) <= 0 ? 0.0 : (l - minLen) / (double) (maxLen - minLen); |
| | | double congNorm = (maxCong - minCong) <= 0 ? 0.0 : (c - minCong) / (double) (maxCong - minCong); |
| | | //è·åæé |
| | | double cost = lenNorm * lenW + congNorm * congW; |
| | | if (cost < bestCost |
| | | || (cost == bestCost && t < bestTasks) |
| | | || (cost == bestCost && t == bestTasks && l < bestLen)) { |
| | | best = candidates.get(i); |
| | | bestCost = cost; |
| | | bestTasks = t; |
| | | bestLen = l; |
| | | } |
| | | } |
| | | |
| | | if (best == null) { |
| | | return allList.get(0); |
| | | } |
| | | return best; |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }); |
| | | thread.setName("MainProcess"); |
| | | thread.setDaemon(true); |
| | | thread.start(); |
| | | } |
| | | |
| | |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PreDestroy; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | throw new CoolException("æªç¥ç线ç¨å®ç°"); |
| | | } |
| | | |
| | | new Thread(thread).start(); |
| | | Thread t = new Thread(thread); |
| | | t.setName("CrnThread-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | t.start(); |
| | | SlaveConnection.put(SlaveType.Crn, deviceConfig.getDeviceNo(), thread); |
| | | } |
| | | |
| | |
| | | throw new CoolException("æªç¥ç线ç¨å®ç°"); |
| | | } |
| | | |
| | | new Thread(thread).start(); |
| | | Thread t = new Thread(thread); |
| | | t.setName("DevpThread-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | t.start(); |
| | | SlaveConnection.put(SlaveType.Devp, deviceConfig.getDeviceNo(), thread); |
| | | } |
| | | |
| | |
| | | throw new CoolException("æªç¥ç线ç¨å®ç°"); |
| | | } |
| | | |
| | | new Thread(thread).start(); |
| | | Thread t = new Thread(thread); |
| | | t.setName("RgvThread-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | t.start(); |
| | | SlaveConnection.put(SlaveType.Rgv, deviceConfig.getDeviceNo(), thread); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @PreDestroy |
| | | public void destroy() { |
| | | try { |
| | | List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Crn))); |
| | | for (DeviceConfig deviceConfig : crnList) { |
| | | SlaveConnection.remove(SlaveType.Crn, deviceConfig.getDeviceNo()); |
| | | } |
| | | } catch (Exception ignore) {} |
| | | try { |
| | | List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Devp))); |
| | | for (DeviceConfig deviceConfig : devpList) { |
| | | SlaveConnection.remove(SlaveType.Devp, deviceConfig.getDeviceNo()); |
| | | } |
| | | } catch (Exception ignore) {} |
| | | try { |
| | | List<DeviceConfig> rgvList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Rgv))); |
| | | for (DeviceConfig deviceConfig : rgvList) { |
| | | SlaveConnection.remove(SlaveType.Rgv, deviceConfig.getDeviceNo()); |
| | | } |
| | | } catch (Exception ignore) {} |
| | | try { |
| | | mainProcess.shutDown(); |
| | | } catch (Exception ignore) {} |
| | | } |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.zy.core.config; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.WrkLastno; |
| | | import com.zy.asrs.service.WrkLastnoService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.WrkIoType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.HashMap; |
| | | |
| | | @Component |
| | | public class FakeTaskNoAreaInitializer { |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private WrkLastnoService wrkLastnoService; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | WrkLastno wrkLastno = wrkLastnoService.selectById(WrkIoType.FAKE_TASK_NO.id); |
| | | if (Cools.isEmpty(wrkLastno)) { |
| | | throw new CoolException("æ°æ®å¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("start", wrkLastno.getSNo()); |
| | | map.put("end", wrkLastno.getENo()); |
| | | redisUtil.set(RedisKeyType.FAKE_TASK_NO_AREA.key, JSON.toJSONString(map)); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | LOG_LIMIT("log_limit_"), |
| | | SYSTEM_CONFIG_MAP("system_config_map"), |
| | | FAKE_TASK_NO_AREA("fake_task_no_area"), |
| | | |
| | | LOC_MAP_BASE("loc_map_base"), |
| | | LOC_MAST_MAP_LIST("loc_mast_map_list"), |
| | |
| | | CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT("check_out_station_stay_time_out_limit_"), |
| | | CHECK_IN_STATION_STAY_TIME_OUT_LIMIT("check_in_station_stay_time_out_limit_"), |
| | | CRN_IO_EXECUTE_FINISH_LIMIT("crn_io_execute_finish_limit_"), |
| | | STATION_IN_EXECUTE_LIMIT("station_in_execute_limit_"), |
| | | STATION_OUT_EXECUTE_LIMIT("station_out_execute_limit_"), |
| | | |
| | | CURRENT_CIRCLE_TASK_CRN_NO("current_circle_task_crn_no_"), |
| | | AI_CHAT_HISTORY("ai_chat_history_"), |
| | |
| | | LOC_MOVE(201, "ç§»åºä»»å¡"), |
| | | PREVIEW_LIFT_MOVE(98, "æåæºé¢è°åº¦ç§»å¨ä»»å¡"), |
| | | MANUAL(99, "æå¨ä»»å¡"), |
| | | FAKE_TASK_NO(9999, "仿çéæºå·¥ä½å·"), |
| | | ; |
| | | |
| | | WrkIoType(int id, String desc) { |
| | |
| | | |
| | | private Integer deviceLev; |
| | | |
| | | private StationObjModel barcodeStation; |
| | | |
| | | } |
| | |
| | | import com.zy.core.network.fake.ZyCrnFakeConnect; |
| | | import com.zy.core.network.real.ZyCrnRealConnect; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.ThreadFactory; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * è¿æ¥é©±å¨ |
| | |
| | | private DeviceConfig deviceConfig; |
| | | private ZyCrnConnectApi zyCrnConnectApi; |
| | | private volatile boolean closed = false; |
| | | private Thread selfThread; |
| | | private ScheduledExecutorService executor; |
| | | |
| | | public ZyCrnConnectDriver(DeviceConfig deviceConfig) { |
| | | this.deviceConfig = deviceConfig; |
| | | } |
| | | |
| | | @Override |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | selfThread = Thread.currentThread(); |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | if (!connected) { |
| | | connect(); |
| | | } |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public void close() { |
| | | closed = true; |
| | | Thread t = selfThread; |
| | | if (t != null) { |
| | | try { t.interrupt(); } catch (Exception ignore) {} |
| | | ScheduledExecutorService ex = executor; |
| | | if (ex != null) { |
| | | try { ex.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | if (zyCrnConnectApi != null) { |
| | | zyCrnConnectApi.disconnect(); |
| | |
| | | } |
| | | |
| | | public void start() { |
| | | Thread t = new Thread(this); |
| | | t.start(); |
| | | executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("CrnConnect-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | executor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | if (!connected) { |
| | | connect(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }, 0, 1000, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | public ZyCrnStatusEntity getStatus() { |
| | |
| | | import com.zy.core.network.fake.ZyRgvFakeConnect; |
| | | import com.zy.core.network.real.ZyRgvRealConnect; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.ThreadFactory; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Slf4j |
| | | public class ZyRgvConnectDriver implements ThreadHandler { |
| | |
| | | private DeviceConfig deviceConfig; |
| | | private ZyRgvConnectApi zyRgvConnectApi; |
| | | private volatile boolean closed = false; |
| | | private Thread selfThread; |
| | | private ScheduledExecutorService executor; |
| | | |
| | | public ZyRgvConnectDriver(DeviceConfig deviceConfig) { |
| | | this.deviceConfig = deviceConfig; |
| | | } |
| | | |
| | | @Override |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | selfThread = Thread.currentThread(); |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | if (!connected) { |
| | | connect(); |
| | | } |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public void close() { |
| | | closed = true; |
| | | Thread t = selfThread; |
| | | if (t != null) { |
| | | try { t.interrupt(); } catch (Exception ignore) {} |
| | | ScheduledExecutorService ex = executor; |
| | | if (ex != null) { |
| | | try { ex.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | if (zyRgvConnectApi != null) { |
| | | zyRgvConnectApi.disconnect(); |
| | |
| | | } |
| | | |
| | | public void start() { |
| | | Thread t = new Thread(this); |
| | | t.start(); |
| | | executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("RgvConnect-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | executor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | if (!connected) { |
| | | connect(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }, 0, 1000, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | public ZyRgvStatusEntity getStatus() { |
| | |
| | | package com.zy.core.network; |
| | | |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.StationCommand; |
| | |
| | | import com.zy.core.network.fake.ZyStationFakeConnect; |
| | | import com.zy.core.network.real.ZyStationRealConnect; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.ThreadFactory; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * è¾éç«è¿æ¥é©±å¨ |
| | |
| | | |
| | | private boolean connected = false; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | private ZyStationConnectApi zyStationConnectApi; |
| | | private volatile boolean closed = false; |
| | | private Thread selfThread; |
| | | private ScheduledExecutorService executor; |
| | | |
| | | public ZyStationConnectDriver(DeviceConfig deviceConfig) { |
| | | public ZyStationConnectDriver(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | } |
| | | |
| | | @Override |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | selfThread = Thread.currentThread(); |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | if (!connected) { |
| | | connect(); |
| | | } |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | if (deviceConfig.getFake() == 0) { |
| | | zyStationConnectApi = new ZyStationRealConnect(deviceConfig); |
| | | zyStationConnectApi = new ZyStationRealConnect(deviceConfig, redisUtil); |
| | | } else { |
| | | zyStationConnectApi = new ZyStationFakeConnect(deviceConfig); |
| | | zyStationConnectApi = new ZyStationFakeConnect(deviceConfig, redisUtil); |
| | | } |
| | | |
| | | boolean connect = zyStationConnectApi.connect(); |
| | |
| | | @Override |
| | | public void close() { |
| | | closed = true; |
| | | Thread t = selfThread; |
| | | if (t != null) { |
| | | try { t.interrupt(); } catch (Exception ignore) {} |
| | | ScheduledExecutorService ex = executor; |
| | | if (ex != null) { |
| | | try { ex.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | if (zyStationConnectApi != null) { |
| | | zyStationConnectApi.disconnect(); |
| | |
| | | } |
| | | |
| | | public void start() { |
| | | Thread t = new Thread(this); |
| | | t.start(); |
| | | executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("DevpConnect-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | |
| | | executor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | if (!connected) { |
| | | connect(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }, 0, 1000, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | public List<ZyStationStatusEntity> getStatus() { |
| | |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.utils.NavigateUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.network.api.ZyStationConnectApi; |
| | | import com.zy.core.network.entity.ZyStationStatusEntity; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.function.Supplier; |
| | | |
| | | /** |
| | | * è¾éç«åè¿æ¥ï¼æ¨¡æï¼ |
| | | */ |
| | | public class ZyStationFakeConnect implements ZyStationConnectApi { |
| | | |
| | | private List<ZyStationStatusEntity> statusList = new ArrayList<>(); |
| | | private final List<ZyStationStatusEntity> statusList = new CopyOnWriteArrayList<>(); |
| | | private static int LOCK_STATION = 0; |
| | | private final DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | // å
è®¸å¹¶è¡æ§è¡å¤ä¸ªå½ä»¤ä»»å¡ï¼åºå®çº¿ç¨æ± ï¼ãå¦éæ´é«å¹¶åå¯è°æ´å¤§å°ã |
| | | private final ExecutorService executor = Executors |
| | | .newFixedThreadPool(9999); |
| | | |
| | | public ZyStationFakeConnect(DeviceConfig deviceConfig) { |
| | | public ZyStationFakeConnect(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public List<ZyStationStatusEntity> getStatus() { |
| | | if (this.statusList.isEmpty()) { |
| | | this.statusList = JSON.parseArray(deviceConfig.getFakeInitStatus(), ZyStationStatusEntity.class); |
| | | |
| | | for (ZyStationStatusEntity status : this.statusList) { |
| | | status.setAutoing(true);// 模æèªå¨è¿è¡ |
| | | status.setLoading(false);// 模ææç© |
| | | status.setInEnable(true);// 模æå¯å
¥ |
| | | status.setOutEnable(true);// 模æå¯åº |
| | | status.setEmptyMk(false);// 模æç©ºæ¿ä¿¡å· |
| | | status.setFullPlt(false);// æ¨¡ææ»¡æç |
| | | status.setPalletHeight(0);// 模ææçé«åº¦ä¸º0 |
| | | status.setError(0);// æ¨¡ææ æ¥è¦ |
| | | status.setBarcode("");// æ¨¡ææ æ¡ç |
| | | List<ZyStationStatusEntity> init = JSON.parseArray(deviceConfig.getFakeInitStatus(), ZyStationStatusEntity.class); |
| | | if (init != null) { |
| | | statusList.addAll(init); |
| | | for (ZyStationStatusEntity status : this.statusList) { |
| | | status.setAutoing(true);// 模æèªå¨è¿è¡ |
| | | status.setLoading(false);// 模ææç© |
| | | status.setInEnable(true);// 模æå¯å
¥ |
| | | status.setOutEnable(true);// 模æå¯åº |
| | | status.setEmptyMk(false);// 模æç©ºæ¿ä¿¡å· |
| | | status.setFullPlt(false);// æ¨¡ææ»¡æç |
| | | status.setPalletHeight(0);// 模ææçé«åº¦ä¸º0 |
| | | status.setError(0);// æ¨¡ææ æ¥è¦ |
| | | status.setBarcode("");// æ¨¡ææ æ¡ç |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | Integer taskNo = command.getTaskNo(); |
| | | Integer stationId = command.getStationId(); |
| | | Integer targetStationId = command.getTargetStaNo(); |
| | | boolean generateBarcode = false; |
| | | |
| | | if(taskNo == 0 && targetStationId == 0){ |
| | | //æ¸
空ç«ç¹ |
| | |
| | | return; |
| | | } |
| | | |
| | | if (taskNo == 9999 && targetStationId == 0) { |
| | | //ä»»å¡å·å±äºä»¿çå
¥åºä»»å¡å· |
| | | if (checkTaskNoInArea(taskNo)) { |
| | | //çæä»¿çæ°æ® |
| | | generateFakeData(stationId, taskNo); |
| | | return; |
| | | generateBarcode = true; |
| | | } |
| | | |
| | | if (taskNo == 9998 && targetStationId == 0) { |
| | |
| | | return; |
| | | } |
| | | |
| | | if (taskNo > 0 && taskNo != 9999 && taskNo != 9998 && stationId == targetStationId) { |
| | | //ä¸å任塿°æ®-ä¸å
è®¸åªæ¯ä¸åæ°æ® |
| | | generateStationData(taskNo, stationId, targetStationId); |
| | | } |
| | | |
| | | String startLev = String.valueOf(stationId).substring(0, 1); |
| | | String endLev = String.valueOf(targetStationId).substring(0, 1); |
| | | |
| | | if (startLev.equals(endLev)) { |
| | | currentLevCommand(command); |
| | | currentLevCommand(command, generateBarcode); |
| | | }else { |
| | | diffLevCommand(command); |
| | | diffLevCommand(command, generateBarcode); |
| | | } |
| | | } |
| | | |
| | | private void generateFakeData(Integer stationId, Integer taskNo) { |
| | | ZyStationStatusEntity status = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null); |
| | | if (status == null) { |
| | | return; |
| | | } |
| | | |
| | | String barcodeTime = String.valueOf(System.currentTimeMillis()); |
| | | String barcode = barcodeTime.substring(5); |
| | | |
| | | status.setTaskNo(taskNo); |
| | | status.setLoading(true); |
| | | status.setBarcode(barcode); |
| | | } |
| | | |
| | | private void generateFakeOutStationData(Integer stationId) { |
| | |
| | | return; |
| | | } |
| | | |
| | | status.setLoading(true); |
| | | synchronized (status) { |
| | | status.setLoading(true); |
| | | } |
| | | } |
| | | |
| | | private void generateStationData(Integer taskNo, Integer stationId, Integer targetStationId) { |
| | | ZyStationStatusEntity status = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null); |
| | | if (status == null) { |
| | | return; |
| | | } |
| | | |
| | | synchronized (status) { |
| | | status.setTaskNo(taskNo); |
| | | status.setTargetStaNo(targetStationId); |
| | | } |
| | | } |
| | | |
| | | private void resetStation(Integer stationId) { |
| | |
| | | return; |
| | | } |
| | | |
| | | status.setTaskNo(0); |
| | | status.setLoading(false); |
| | | status.setBarcode(""); |
| | | synchronized (status) { |
| | | status.setTaskNo(0); |
| | | status.setLoading(false); |
| | | status.setBarcode(""); |
| | | } |
| | | } |
| | | |
| | | private void currentLevCommand(StationCommand command) { |
| | | private void currentLevCommand(StationCommand command, boolean generateBarcode) { |
| | | NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class); |
| | | if (navigateUtils == null) { |
| | | return; |
| | |
| | | return; |
| | | } |
| | | |
| | | stationMove(navigateNodes, taskNo, targetStationId, false); |
| | | stationMove(navigateNodes, taskNo, targetStationId, false, generateBarcode); |
| | | } |
| | | |
| | | private void diffLevCommand(StationCommand command) { |
| | | private void diffLevCommand(StationCommand command, boolean generateBarcode) { |
| | | NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class); |
| | | if (navigateUtils == null) { |
| | | return; |
| | |
| | | return; |
| | | } |
| | | |
| | | stationMove(navigateNodes, taskNo, stationId, true); |
| | | stationMove(targetNavigateNodes, taskNo, targetStationId, false); |
| | | stationMove(navigateNodes, taskNo, stationId, true, generateBarcode); |
| | | stationMove(targetNavigateNodes, taskNo, targetStationId, false, generateBarcode); |
| | | } |
| | | |
| | | private void stationMove(List<NavigateNode> navigateNodes, Integer taskNo, Integer targetStationId, boolean clearData) { |
| | | private void stationMove(List<NavigateNode> navigateNodes, Integer taskNo, Integer targetStationId, boolean clearData, boolean generateBarcode) { |
| | | Integer lastStationId = null; |
| | | for (int i = 0; i < navigateNodes.size(); i++) { |
| | | |
| | | int i = 0; |
| | | while (i < navigateNodes.size()) { |
| | | NavigateNode navigateNode = navigateNodes.get(i); |
| | | JSONObject valueObject = JSON.parseObject(navigateNode.getNodeValue()); |
| | | Integer currentStationId = valueObject.getInteger("stationId"); |
| | | ZyStationStatusEntity status = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null); |
| | | if (status == null) { |
| | | continue; |
| | | |
| | | Integer nextStationId = null; |
| | | try { |
| | | NavigateNode nextNode = navigateNodes.get(i + 1); |
| | | JSONObject nextValueObject = JSON.parseObject(nextNode.getNodeValue()); |
| | | nextStationId = nextValueObject.getInteger("stationId"); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | |
| | | try { |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | | ZyStationStatusEntity nextStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null); |
| | | if (nextStatus == null) { |
| | | if (nextStationId != null) { |
| | | |
| | | } |
| | | |
| | | if (i == 0) { |
| | | boolean result = initStationMove(taskNo, currentStationId, taskNo, targetStationId, true, null); |
| | | if (!result) { |
| | | continue; |
| | | } |
| | | sleep(1000); |
| | | } |
| | | |
| | | if(nextStationId != null) { |
| | | boolean result = stationMoveToNext(taskNo, currentStationId, nextStationId, taskNo, targetStationId); |
| | | if (!result) { |
| | | continue; |
| | | } |
| | | lastStationId = currentStationId; |
| | | } |
| | | |
| | | i++; |
| | | sleep(1000); |
| | | } |
| | | |
| | | if (generateBarcode) { |
| | | if (lastStationId != null) { |
| | | while (true) { |
| | | boolean result = generateStationBarcode(taskNo, targetStationId); |
| | | sleep(1000); |
| | | if (!result) { |
| | | continue; |
| | | } |
| | | |
| | | if (nextStatus.getTaskNo() == 0 || nextStatus.getTaskNo() == 9999) { |
| | | break; |
| | | } |
| | | |
| | | sleep(100); |
| | | } |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | |
| | | if (lastStationId != null) { |
| | | Integer finalLastStationId = lastStationId; |
| | | ZyStationStatusEntity lastStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(finalLastStationId)).findFirst().orElse(null); |
| | | if (lastStatus != null) { |
| | | synchronized (lastStatus) { |
| | | lastStatus.setTaskNo(0); |
| | | lastStatus.setTargetStaNo(0); |
| | | lastStatus.setLoading(false); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | |
| | | synchronized (status) { |
| | | status.setTaskNo(taskNo); |
| | | status.setTargetStaNo(targetStationId); |
| | | status.setLoading(true); |
| | | } |
| | | |
| | | lastStationId = currentStationId; |
| | | sleep(1000); |
| | | } |
| | | |
| | | if (clearData) { |
| | | sleep(10000); |
| | | if (lastStationId != null) { |
| | | Integer finalLastStationId = lastStationId; |
| | | ZyStationStatusEntity lastStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(finalLastStationId)).findFirst().orElse(null); |
| | | if (lastStatus != null) { |
| | | synchronized (lastStatus) { |
| | | lastStatus.setTaskNo(0); |
| | | lastStatus.setTargetStaNo(0); |
| | | lastStatus.setLoading(false); |
| | | while (true) { |
| | | boolean result = clearStation(taskNo, targetStationId); |
| | | sleep(1000); |
| | | if (!result) { |
| | | continue; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public synchronized boolean setLockStation(Integer uuid) { |
| | | if (LOCK_STATION == 0) { |
| | | LOCK_STATION = uuid; |
| | | return true; |
| | | }else { |
| | | if(LOCK_STATION == uuid) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public synchronized boolean releaseLockStation(Integer uuid) { |
| | | if (LOCK_STATION != uuid) { |
| | | return false; |
| | | } |
| | | |
| | | LOCK_STATION = 0; |
| | | return true; |
| | | } |
| | | |
| | | public synchronized boolean updateStationData(Integer lockTaskNo, Integer stationId, Integer taskNo, Integer targetStaNo, Boolean isLoading, String barcode) { |
| | | if (LOCK_STATION != lockTaskNo) { |
| | | return false; |
| | | } |
| | | |
| | | ZyStationStatusEntity currentStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null); |
| | | |
| | | if (currentStatus == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (taskNo != null) { |
| | | currentStatus.setTaskNo(taskNo); |
| | | } |
| | | |
| | | if (targetStaNo != null) { |
| | | currentStatus.setTargetStaNo(targetStaNo); |
| | | } |
| | | |
| | | if (isLoading != null) { |
| | | currentStatus.setLoading(isLoading); |
| | | } |
| | | |
| | | if (barcode != null) { |
| | | currentStatus.setBarcode(barcode); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | public synchronized boolean initStationMove(Integer lockTaskNo, Integer currentStationId, Integer taskNo, Integer targetStationId, Boolean isLoading, String barcode) { |
| | | boolean executeResult = lockExecute(lockTaskNo, () -> { |
| | | ZyStationStatusEntity currentStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null); |
| | | |
| | | if (currentStatus == null) { |
| | | return false; |
| | | } |
| | | |
| | | if(currentStatus.getTaskNo().equals(taskNo)) { |
| | | return true; |
| | | } |
| | | |
| | | if (currentStatus.getTaskNo() > 0 || currentStatus.isLoading()) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result = updateStationData(taskNo, currentStationId, taskNo, targetStationId, isLoading, barcode); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | | return true; |
| | | }); |
| | | |
| | | return executeResult; |
| | | } |
| | | |
| | | public synchronized boolean stationMoveToNext(Integer lockTaskNo, Integer currentStationId, Integer nextStationId, Integer taskNo, Integer targetStaNo) { |
| | | boolean executeResult = lockExecute(lockTaskNo, () -> { |
| | | ZyStationStatusEntity currentStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null); |
| | | |
| | | ZyStationStatusEntity nextStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(nextStationId)).findFirst().orElse(null); |
| | | |
| | | if (currentStatus == null || nextStatus == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (nextStatus.getTaskNo() > 0 || nextStatus.isLoading()) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result = updateStationData(lockTaskNo, nextStationId, taskNo, targetStaNo, true, null); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result2 = updateStationData(lockTaskNo, currentStationId, 0, 0, false, null); |
| | | if (!result2) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | }); |
| | | return executeResult; |
| | | } |
| | | |
| | | public synchronized boolean generateStationBarcode(Integer lockTaskNo, Integer currentStationId) { |
| | | boolean executeResult = lockExecute(lockTaskNo, () -> { |
| | | ZyStationStatusEntity currentStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null); |
| | | |
| | | if (currentStatus == null) { |
| | | return false; |
| | | } |
| | | |
| | | String barcodeTime = String.valueOf(System.currentTimeMillis()); |
| | | String barcode = barcodeTime.substring(5); |
| | | |
| | | boolean result = updateStationData(lockTaskNo, currentStationId, null, null, null, barcode); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | | return true; |
| | | }); |
| | | |
| | | return executeResult; |
| | | } |
| | | |
| | | public synchronized boolean clearStation(Integer lockTaskNo, Integer currentStationId) { |
| | | boolean executeResult = lockExecute(lockTaskNo, () -> { |
| | | ZyStationStatusEntity currentStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null); |
| | | |
| | | if (currentStatus == null) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result = updateStationData(lockTaskNo, currentStationId, 0, 0, false, ""); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | | return true; |
| | | }); |
| | | |
| | | return executeResult; |
| | | } |
| | | |
| | | public synchronized boolean lockExecute(Integer taskNo, Supplier<Boolean> function) { |
| | | if (!setLockStation(taskNo)) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result = function.get(); |
| | | releaseLockStation(taskNo); |
| | | return result; |
| | | } |
| | | |
| | | private synchronized boolean checkTaskNoInArea(Integer taskNo) { |
| | | Object fakeTaskNoAreaObj = redisUtil.get(RedisKeyType.FAKE_TASK_NO_AREA.key); |
| | | if (fakeTaskNoAreaObj == null) { |
| | | return false; |
| | | } |
| | | |
| | | JSONObject data = JSON.parseObject(String.valueOf(fakeTaskNoAreaObj)); |
| | | Integer start = data.getInteger("start"); |
| | | Integer end = data.getInteger("end"); |
| | | |
| | | if(taskNo >= start && taskNo <= end) { |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | } |
| | |
| | | import HslCommunication.Core.Types.OperateResultExOne; |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | |
| | | private List<ZyStationStatusEntity> barcodeStatusList; |
| | | private SiemensS7Net siemensNet; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | |
| | | public ZyStationRealConnect(DeviceConfig deviceConfig) { |
| | | public ZyStationRealConnect(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | } |
| | | |
| | | @Override |
| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.zy.asrs.domain.param.CreateInTaskParam; |
| | | import com.zy.asrs.domain.param.CreateOutTaskParam; |
| | | import com.zy.asrs.entity.*; |
| | |
| | | continue; |
| | | } |
| | | |
| | | Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId); |
| | | if (object != null) { |
| | | Object lock = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId); |
| | | if(lock != null){ |
| | | continue; |
| | | } |
| | | |
| | |
| | | && !stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 0 |
| | | ) { |
| | | StationCommand command = stationThread.getMoveCommand(9999, stationId, 0, 0); |
| | | StationCommand command = stationThread.getMoveCommand(commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, entity.getBarcodeStation().getStationId(), 0); |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 10); |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 5); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> list = basDevp.getInStationList$(); |
| | | List<StationObjModel> list = basDevp.getBarcodeStationList$(); |
| | | for (StationObjModel model : list) { |
| | | Integer stationId = model.getStationId(); |
| | | if(!stationMap.containsKey(stationId)){ |
| | |
| | | return; |
| | | } |
| | | |
| | | //满足èªå¨ãæç©ãå·¥ä½å·9999ï¼çæå
¥åºæ°æ® |
| | | //满足èªå¨ãæç©ãæå·¥ä½å·ï¼çæå
¥åºæ°æ® |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 9999 |
| | | && stationProtocol.getTaskNo() > 0 |
| | | ) { |
| | | if (Cools.isEmpty(stationProtocol.getBarcode())) { |
| | | continue; |
| | | } |
| | | |
| | | //æ£æµä»»å¡æ¯å¦çæ |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | | if (!wrkMasts.isEmpty()) { |
| | |
| | | taskParam.setStaNo(targetStationId); |
| | | taskParam.setLocNo(locMast.getLocNo()); |
| | | taskParam.setBarcode(stationProtocol.getBarcode()); |
| | | boolean result = commonService.createInTask(taskParam); |
| | | WrkMast wrkMast = commonService.createInTask(taskParam); |
| | | |
| | | StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationId, stationId, 0); |
| | | if(command == null){ |
| | | News.taskInfo(wrkMast.getWrkNo(), "è·åè¾é线å½ä»¤å¤±è´¥"); |
| | | continue; |
| | | } |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_TASK_LIMIT.key + stationId, "lock", 5); |
| | | } |
| | | } |
| | |
| | | taskParam.setStaNo(stationId); |
| | | taskParam.setLocNo(locMast.getLocNo()); |
| | | boolean result = commonService.createOutTask(taskParam); |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_OUT_TASK_LIMIT.key + stationId, "lock", 15); |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_OUT_TASK_LIMIT.key + stationId, "lock", 10); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> list = basDevp.getInStationList$(); |
| | | List<StationObjModel> list = basDevp.getBarcodeStationList$(); |
| | | for (StationObjModel entity : list) { |
| | | Integer stationId = entity.getStationId(); |
| | | if(!stationMap.containsKey(stationId)){ |
| | |
| | | continue; |
| | | } |
| | | |
| | | //满足èªå¨ãæç©ãå·¥ä½å·9999ï¼çæå
¥åºæ°æ® |
| | | //满足èªå¨ãæç©ãæå·¥ä½å·ï¼çæå
¥åºæ°æ® |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 9999 |
| | | && stationProtocol.getTaskNo() > 0 |
| | | ) { |
| | | if (Cools.isEmpty(stationProtocol.getBarcode())) { |
| | | continue; |
| | | } |
| | | |
| | | //æ£æµä»»å¡æ¯å¦çæ |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | | if (!wrkMasts.isEmpty()) { |
| | |
| | | continue; |
| | | } |
| | | |
| | | redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 15); |
| | | redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 5); |
| | | |
| | | HashMap<String, Object> requestParam = new HashMap<>(); |
| | | String response = null; |
| | |
| | | taskParam.setLocNo(dto.getLocNo()); |
| | | taskParam.setTaskPri(dto.getTaskPri()); |
| | | taskParam.setBarcode(stationProtocol.getBarcode()); |
| | | boolean result = commonService.createInTask(taskParam); |
| | | WrkMast wrkMast = commonService.createInTask(taskParam); |
| | | |
| | | StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationId, stationId, 0); |
| | | if(command == null){ |
| | | News.taskInfo(wrkMast.getWrkNo(), "è·åè¾é线å½ä»¤å¤±è´¥"); |
| | | continue; |
| | | } |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | News.info("请æ±WMSæ¥å£æåï¼ï¼ï¼urlï¼{}ï¼requestï¼{}ï¼responseï¼{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response); |
| | | } else { |
| | | News.error("请æ±WMSæ¥å£å¤±è´¥ï¼ï¼ï¼urlï¼{}ï¼requestï¼{}ï¼responseï¼{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response); |
| | |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.ThreadFactory; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Data |
| | | @Slf4j |
| | |
| | | private RgvProtocol rgvProtocol; |
| | | private int deviceLogCollectTime = 200; |
| | | private volatile boolean closed = false; |
| | | private Thread mainThread; |
| | | private ScheduledExecutorService readExecutor; |
| | | private ScheduledExecutorService processExecutor; |
| | | |
| | | public ZyRgvThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | public void run() { |
| | | connect(); |
| | | initRgv(); |
| | | mainThread = Thread.currentThread(); |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | readExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("RgvReader-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | readExecutor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | readStatus(); |
| | | } catch (Exception e) { |
| | | log.error("RgvThread Fail", e); |
| | | } |
| | | }, 0, 200, TimeUnit.MILLISECONDS); |
| | | |
| | | processExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("RgvWriter-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | processExecutor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | int step = 1; |
| | | Task task = MessageQueue.poll(SlaveType.Rgv, deviceConfig.getDeviceNo()); |
| | | if (task != null) { |
| | | step = task.getStep(); |
| | | } |
| | | switch (step) { |
| | | case 1: |
| | | readStatus(); |
| | | break; |
| | | case 2: |
| | | sendCommand((RgvCommand) task.getData()); |
| | | break; |
| | | default: |
| | | break; |
| | | if (step == 2 && task != null) { |
| | | sendCommand((RgvCommand) task.getData()); |
| | | } |
| | | Thread.sleep(200); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }, 0, 200, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | private void initRgv() { |
| | |
| | | @Override |
| | | public void close() { |
| | | closed = true; |
| | | Thread t = mainThread; |
| | | if (t != null) { |
| | | try { t.interrupt(); } catch (Exception ignore) {} |
| | | } |
| | | if (zyRgvConnectDriver != null) { |
| | | zyRgvConnectDriver.close(); |
| | | } |
| | | ScheduledExecutorService ex = readExecutor; |
| | | if (ex != null) { |
| | | try { ex.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | ScheduledExecutorService px = processExecutor; |
| | | if (px != null) { |
| | | try { px.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | import com.zy.asrs.service.BasCrnpOptService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.CrnTaskModeType; |
| | |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.ThreadFactory; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * å åæºçº¿ç¨ |
| | |
| | | private int deviceLogCollectTime = 200; |
| | | private boolean resetFlag = false; |
| | | private volatile boolean closed = false; |
| | | private Thread mainThread; |
| | | private ScheduledExecutorService readExecutor; |
| | | private ScheduledExecutorService processExecutor; |
| | | |
| | | public ZySiemensCrnThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | public void run() { |
| | | this.connect(); |
| | | this.initCrn(); |
| | | mainThread = Thread.currentThread(); |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | readExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("CrnReader-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | readExecutor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | readStatus(); |
| | | } catch (Exception e) { |
| | | log.error("CrnThread Fail", e); |
| | | } |
| | | }, 0, 200, TimeUnit.MILLISECONDS); |
| | | |
| | | processExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("CrnWriter-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | processExecutor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | int step = 1; |
| | | Task task = MessageQueue.poll(SlaveType.Crn, deviceConfig.getDeviceNo()); |
| | | if (task != null) { |
| | | step = task.getStep(); |
| | | } |
| | | switch (step) { |
| | | case 1: |
| | | readStatus(); |
| | | break; |
| | | case 2: |
| | | sendCommand((CrnCommand) task.getData()); |
| | | break; |
| | | default: |
| | | break; |
| | | if (step == 2 && task != null) { |
| | | sendCommand((CrnCommand) task.getData()); |
| | | } |
| | | Thread.sleep(200); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }, 0, 200, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public void close() { |
| | | closed = true; |
| | | Thread t = mainThread; |
| | | if (t != null) { |
| | | try { t.interrupt(); } catch (Exception ignore) {} |
| | | ScheduledExecutorService ex = readExecutor; |
| | | if (ex != null) { |
| | | try { ex.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | ScheduledExecutorService px = processExecutor; |
| | | if (px != null) { |
| | | try { px.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | if (zyCrnConnectDriver != null) { |
| | | zyCrnConnectDriver.close(); |
| | |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | import java.util.concurrent.ThreadFactory; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | private int deviceLogCollectTime = 200; |
| | | private long deviceDataLogTime = System.currentTimeMillis(); |
| | | private volatile boolean closed = false; |
| | | private Thread mainThread; |
| | | private Thread readThread; |
| | | private ScheduledExecutorService readExecutor; |
| | | private ScheduledExecutorService processExecutor; |
| | | |
| | | public ZyStationThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | public void run() { |
| | | this.connect(); |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | mainThread = Thread.currentThread(); |
| | | |
| | | readThread = new Thread(() -> { |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | readStatus(); |
| | | Thread.sleep(200); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | log.error("StationThread Fail", e); |
| | | } |
| | | readExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("DevpReader-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | readThread.start(); |
| | | readExecutor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | readStatus(); |
| | | } catch (Exception e) { |
| | | log.error("StationThread Fail", e); |
| | | } |
| | | }, 0, 200, TimeUnit.MILLISECONDS); |
| | | |
| | | while (!closed && !Thread.currentThread().isInterrupted()) { |
| | | processExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | Thread t = new Thread(r); |
| | | t.setName("DevpWriter-" + deviceConfig.getDeviceNo()); |
| | | t.setDaemon(true); |
| | | return t; |
| | | } |
| | | }); |
| | | processExecutor.scheduleAtFixedRate(() -> { |
| | | if (closed || Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | try { |
| | | int step = 1; |
| | | Task task = MessageQueue.poll(SlaveType.Devp, deviceConfig.getDeviceNo()); |
| | | if (task != null) { |
| | | step = task.getStep(); |
| | | } |
| | | switch (step) { |
| | | case 2: |
| | | sendCommand((StationCommand) task.getData()); |
| | | break; |
| | | default: |
| | | break; |
| | | if (step == 2 && task != null) { |
| | | sendCommand((StationCommand) task.getData()); |
| | | } |
| | | Thread.sleep(200); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }, 0, 200, TimeUnit.MILLISECONDS); |
| | | } |
| | | |
| | | private void readStatus() { |
| | |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig); |
| | | zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig, redisUtil); |
| | | zyStationConnectDriver.start(); |
| | | DeviceConnectPool.put(SlaveType.Devp, deviceConfig.getDeviceNo(), zyStationConnectDriver); |
| | | return true; |
| | |
| | | @Override |
| | | public void close() { |
| | | closed = true; |
| | | Thread t = mainThread; |
| | | if (t != null) { |
| | | try { t.interrupt(); } catch (Exception ignore) {} |
| | | ScheduledExecutorService ex = readExecutor; |
| | | if (ex != null) { |
| | | try { ex.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | Thread rt = readThread; |
| | | if (rt != null) { |
| | | try { rt.interrupt(); } catch (Exception ignore) {} |
| | | ScheduledExecutorService px = processExecutor; |
| | | if (px != null) { |
| | | try { px.shutdownNow(); } catch (Exception ignore) {} |
| | | } |
| | | if (zyStationConnectDriver != null) { |
| | | zyStationConnectDriver.close(); |
| | |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.model.StationObjModel; |
| | |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | //æ§è¡è¾éç«ç¹å
¥åºä»»å¡ |
| | | public synchronized void stationInExecute() { |
| | |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> list = basDevp.getInStationList$(); |
| | | List<StationObjModel> list = basDevp.getBarcodeStationList$(); |
| | | for (StationObjModel entity : list) { |
| | | Integer stationId = entity.getStationId(); |
| | | if(!stationMap.containsKey(stationId)){ |
| | |
| | | continue; |
| | | } |
| | | |
| | | //满足èªå¨ãæç©ãå·¥ä½å·9999 |
| | | Object lock = redisUtil.get(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId); |
| | | if(lock != null){ |
| | | continue; |
| | | } |
| | | |
| | | //满足èªå¨ãæç©ãæå·¥ä½å· |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 9999 |
| | | && stationProtocol.getTaskNo() > 0 |
| | | ) { |
| | | //æ£æµä»»å¡æ¯å¦çæ |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) { |
| | | continue; |
| | | } |
| | | |
| | | if (!wrkMast.getWrkNo().equals(stationProtocol.getTaskNo())) { |
| | | News.taskInfo(stationProtocol.getStationId(), "è¾éç«ç¹å·¥ä½å·:{}䏿¡ç æç´¢å°çä»»å¡å·¥ä½å·:{}ä¸ä¸è´", stationProtocol.getTaskNo(), wrkMast.getWrkNo()); |
| | | continue; |
| | | } |
| | | |
| | |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | News.info("è¾éç«ç¹å
¥åºå½ä»¤ä¸åæåï¼ç«ç¹å·={}ï¼å·¥ä½å·={}ï¼å½ä»¤æ°æ®={}", stationId, wrkMast.getWrkNo(), JSON.toJSONString(command)); |
| | | redisUtil.set(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId, "lock", 5); |
| | | } |
| | | } |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId()); |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | |
| | | //满足èªå¨ãæç©ãå·¥ä½å·0 |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | News.info("è¾éç«ç¹åºåºå½ä»¤ä¸åæåï¼ç«ç¹å·={}ï¼å·¥ä½å·={}ï¼å½ä»¤æ°æ®={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command)); |
| | | redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId(), "lock", 5); |
| | | } |
| | | } |
| | | } |
| | |
| | | port: 9090 |
| | | servlet: |
| | | context-path: /@pom.build.finalName@ |
| | | shutdown: graceful |
| | | |
| | | spring: |
| | | application: |
| | |
| | | scheduling: |
| | | pool: |
| | | size: 3 |
| | | shutdown: |
| | | await-termination: true |
| | | await-termination-period: 30s |
| | | execution: |
| | | shutdown: |
| | | await-termination: true |
| | | await-termination-period: 30s |
| | | lifecycle: |
| | | timeout-per-shutdown-phase: 20s |
| | | |
| | | mybatis-plus: |
| | | mapper-locations: classpath:mapper/*.xml |
| | |
| | | model: deepseek-ai/DeepSeek-V3.2 |
| | | # base-url: http://34.2.134.223:3000/v1 |
| | | # api-key: sk-WabrmtOezCFwVo7XvVOrO3QkmfcKG7T7jy0BaVnmQTWm5GXh |
| | | # model: gemini-3-pro-preview |
| | | # model: gemini-3-pro-preview |