| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.domain.AreaShapeDto; |
| | | import com.zy.acs.manager.common.domain.MapPointDto; |
| | | import com.zy.acs.manager.core.service.astart.CodeNodeType; |
| | |
| | | import com.zy.acs.manager.manager.entity.Area; |
| | | import com.zy.acs.manager.manager.enums.StatusType; |
| | | import com.zy.acs.manager.manager.service.AreaService; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| | | import org.springframework.context.event.EventListener; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class AreaBootService { |
| | | |
| | | // public static final Map<String, Set<Long>> CODE_AGV = new ConcurrentHashMap<>(); |
| | | |
| | | public static final Map<Long, List<String>> AREA_CODE = new ConcurrentHashMap<>(); |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | |
| | | private MapDataDispatcher mapDataDispatcher; |
| | | |
| | | // launcher ------------------------------------------------------- |
| | | |
| | | @EventListener(ApplicationReadyEvent.class) |
| | | public void init() { |
| | | List<Area> areaList = areaService.list(new LambdaQueryWrapper<Area>().eq(Area::getStatus, StatusType.ENABLE.val)); |
| | | log.info("areaList: {}", JSON.toJSONString(areaList)); |
| | | if (Cools.isEmpty(areaList)) { |
| | | return; |
| | | } |
| | | |
| | | List<AreaNode> areaNodeList = new ArrayList<>(); |
| | | for (Area area : areaList) { |
| | | AreaShapeDto shapeDto = JSON.parseObject(area.getShapeData(), AreaShapeDto.class); |
| | | MapPointDto start = shapeDto.getStart(); |
| | | MapPointDto end = shapeDto.getEnd(); |
| | | |
| | | List<String> codeList = this.findCodesInArea(start, end); |
| | | log.info("codeList: {}", JSON.toJSONString(codeList)); |
| | | double minX = Math.min(start.getX(), end.getX()); |
| | | double maxX = Math.max(start.getX(), end.getX()); |
| | | double minY = Math.min(start.getY(), end.getY()); |
| | | double maxY = Math.max(start.getY(), end.getY()); |
| | | |
| | | String redisKey = area.getName() + (area.getZoneId() != null ? "_" + area.getZoneId() : ""); |
| | | String areaDataStr = redis.getValue(RedisConstant.MAP_AREA_DATA_FLAG, redisKey); |
| | | |
| | | areaNodeList.add(new AreaNode(area.getId(), minX, maxX, minY, maxY)); |
| | | } |
| | | |
| | | String[][] codeMatrix = mapDataDispatcher.getCodeMatrix(MapDataDispatcher.MAP_DEFAULT_LEV); |
| | | Double[][][] cdaMatrix = mapDataDispatcher.getCdaMatrix(MapDataDispatcher.MAP_DEFAULT_LEV); |
| | | int rows = cdaMatrix.length; |
| | | int cols = cdaMatrix[0].length; |
| | | |
| | | for (int i = 0; i < rows; i++) { |
| | | for (int j = 0; j < cols; j++) { |
| | | String code = codeMatrix[i][j]; |
| | | if (CodeNodeType.NONE.val.equals(code)) { continue; } |
| | | |
| | | Double x = cdaMatrix[i][j][0]; |
| | | Double y = cdaMatrix[i][j][1]; |
| | | if (x == null || y == null) { continue; } |
| | | |
| | | for (AreaNode areaNode : areaNodeList) { |
| | | if (this.inRect(x, y, areaNode.minX, areaNode.maxX, areaNode.minY, areaNode.maxY)) { |
| | | |
| | | List<String> codeList = AREA_CODE.computeIfAbsent(areaNode.getId(), k -> new ArrayList<>()); |
| | | codeList.add(code); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // for (Map.Entry<Long, List<String>> entry : AREA_CODE.entrySet()) { |
| | | // Long areaId = entry.getKey(); |
| | | // List<String> codeList = entry.getValue(); |
| | | // |
| | | // for (String code : codeList) { |
| | | // Set<Long> agvList = CODE_AGV.computeIfAbsent(code, k -> new HashSet<>()); |
| | | // // todo AreaAGV( man_area_agv ) |
| | | // |
| | | // |
| | | // } |
| | | // } |
| | | |
| | | |
| | | // for (Area area : areaList) { |
| | | // AreaShapeDto shapeDto = JSON.parseObject(area.getShapeData(), AreaShapeDto.class); |
| | | // MapPointDto start = shapeDto.getStart(); |
| | | // MapPointDto end = shapeDto.getEnd(); |
| | | // |
| | | // List<String> codeList = this.findCodesInArea(start, end); |
| | | // log.info("codeList: {}", JSON.toJSONString(codeList)); |
| | | // |
| | | // String redisKey = area.getName() + (area.getZoneId() != null ? "_" + area.getZoneId() : ""); |
| | | // String areaDataStr = redis.getValue(RedisConstant.MAP_AREA_DATA_FLAG, redisKey); |
| | | // |
| | | // } |
| | | |
| | | System.out.println(1); |
| | | } |
| | | |
| | | // checkout list of area by code data |
| | | public List<Long> queryAreas(String code) { |
| | | List<Long> areaIds = new ArrayList<>(); |
| | | for (Map.Entry<Long, List<String>> entry : AREA_CODE.entrySet()) { |
| | | List<String> codeList = entry.getValue(); |
| | | if (!Cools.isEmpty(codeList) && codeList.contains(code)) { |
| | | areaIds.add(entry.getKey()); |
| | | } |
| | | } |
| | | return areaIds; |
| | | } |
| | | |
| | | // reset and set new area |
| | | public List<String> reSet(Area area) { |
| | | AreaShapeDto shapeDto = JSON.parseObject(area.getShapeData(), AreaShapeDto.class); |
| | | MapPointDto start = shapeDto.getStart(); |
| | | MapPointDto end = shapeDto.getEnd(); |
| | | |
| | | List<String> codeList = this.findCodesInArea(start, end); |
| | | AREA_CODE.remove(area.getId()); |
| | | AREA_CODE.put(area.getId(), codeList); |
| | | |
| | | return codeList; |
| | | } |
| | | |
| | | public List<String> findCodesInArea(MapPointDto start, MapPointDto end) { |
| | | double minX = Math.min(start.getX(), end.getX()); |
| | |
| | | return x >= minX && x <= maxX && y >= minY && y <= maxY; |
| | | } |
| | | |
| | | @Data |
| | | public static class AreaNode { |
| | | |
| | | public Long id; |
| | | public double minX; |
| | | public double maxX; |
| | | public double minY; |
| | | public double maxY; |
| | | |
| | | public AreaNode(Long id, double minX, double maxX, double minY, double maxY) { |
| | | this.id = id; |
| | | this.minX = minX; |
| | | this.maxX = maxX; |
| | | this.minY = minY; |
| | | this.maxY = maxY; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |