| | |
| | | package com.zy.asrs.wcs.core.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.wcs.core.entity.*; |
| | | import com.zy.asrs.wcs.core.kernel.AnalyzeService; |
| | | import com.zy.asrs.wcs.core.model.MapNode; |
| | | import com.zy.asrs.wcs.core.model.enums.DeviceCtgType; |
| | | import com.zy.asrs.wcs.core.model.enums.MotionStsType; |
| | | import com.zy.asrs.wcs.core.model.enums.TaskStsType; |
| | | import com.zy.asrs.wcs.core.service.*; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.core.utils.ShuttleDispatcher; |
| | | import com.zy.asrs.wcs.core.utils.Utils; |
| | | import com.zy.asrs.wcs.rcs.News; |
| | | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; |
| | | import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant; |
| | | import com.zy.asrs.wcs.rcs.entity.Device; |
| | | import com.zy.asrs.wcs.rcs.entity.DeviceType; |
| | | import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | |
| | | private DictService dictService; |
| | | @Autowired |
| | | private ShuttleDispatcher shuttleDispatcher; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | /** |
| | | * 组托 |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 初始化实时地图 |
| | | */ |
| | | public synchronized void initRealtimeBasMap() { |
| | | try { |
| | | List<Dict> dicts = dictService.list(new LambdaQueryWrapper<Dict>() |
| | | .like(Dict::getFlag, "map") |
| | | .eq(Dict::getStatus, 1)); |
| | | |
| | | TreeMap<Integer, ArrayList<ArrayList<MapNode>>> levData = new TreeMap<>(); |
| | | for (Dict dict : dicts) { |
| | | String[] split = dict.getFlag().split("-"); |
| | | int lev = Integer.parseInt(split[1]); |
| | | |
| | | TreeMap<Integer, List<JSONObject>> rows = new TreeMap<>(); |
| | | //排序Row |
| | | JSONArray value = JSON.parseArray(dict.getValue()); |
| | | for (Object o : value) { |
| | | JSONObject item = JSON.parseObject(o.toString()); |
| | | if (item.getString("type").equals("SHELF")) { |
| | | JSONObject property = JSON.parseObject(item.getString("property")); |
| | | Integer row1 = property.getInteger("row"); |
| | | ArrayList<JSONObject> bays = new ArrayList<>(); |
| | | if (rows.containsKey(row1)) { |
| | | bays.addAll(rows.get(row1)); |
| | | } |
| | | bays.add(property); |
| | | rows.put(row1, bays); |
| | | } |
| | | } |
| | | |
| | | ArrayList<ArrayList<MapNode>> list = new ArrayList<>(); |
| | | //排序Bay |
| | | for (Map.Entry<Integer, List<JSONObject>> entry : rows.entrySet()) { |
| | | ArrayList<MapNode> nodes = new ArrayList<>(); |
| | | for (JSONObject object : entry.getValue()) { |
| | | MapNode mapNode = new MapNode(); |
| | | mapNode.setValue(object.getInteger("value")); |
| | | mapNode.setTop(object.getInteger("top")); |
| | | mapNode.setBottom(object.getInteger("bottom")); |
| | | mapNode.setLeft(object.getInteger("left")); |
| | | mapNode.setRight(object.getInteger("right")); |
| | | mapNode.setRow(object.getInteger("row")); |
| | | mapNode.setBay(object.getInteger("bay")); |
| | | mapNode.setNo(object.getString("row") + "-" + object.getString("bay")); |
| | | nodes.add(mapNode); |
| | | } |
| | | |
| | | Collections.sort(nodes, new Comparator<MapNode>() { |
| | | @Override |
| | | public int compare(MapNode o1, MapNode o2) { |
| | | return Integer.compare(o1.getBay(), o2.getBay()); |
| | | } |
| | | }); |
| | | |
| | | list.add(nodes); |
| | | } |
| | | |
| | | levData.put(lev, list); |
| | | } |
| | | |
| | | for (Map.Entry<Integer, ArrayList<ArrayList<MapNode>>> entry : levData.entrySet()) { |
| | | ArrayList<ArrayList<MapNode>> lists = entry.getValue();//获取地图 |
| | | |
| | | Integer lev = entry.getKey(); |
| | | Date now = new Date(); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("data", JSON.toJSONString(lists)); |
| | | map.put("create_time", now); |
| | | map.put("update_time", now); |
| | | map.put("lev", lev); |
| | | |
| | | //将地图数据存入redis |
| | | redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(map)); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // 解析入库工作档 |
| | | public synchronized void analyzeInBoundTask() { |
| | | for (Task task : taskService.selectWaitAnalyzeInBoundTask()) { |