| New file |
| | |
| | | package com.zy.acs.manager.core.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | 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.core.service.astart.MapDataDispatcher; |
| | | 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.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; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class AreaBootService { |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | @Autowired |
| | | private AreaService areaService; |
| | | @Autowired |
| | | 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)); |
| | | |
| | | 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)); |
| | | |
| | | } |
| | | |
| | | System.out.println(1); |
| | | } |
| | | |
| | | |
| | | public List<String> findCodesInArea(MapPointDto start, MapPointDto end) { |
| | | 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()); |
| | | |
| | | List<String> codeList = new ArrayList<>(); |
| | | |
| | | 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++) { |
| | | Double x = cdaMatrix[i][j][0]; |
| | | Double y = cdaMatrix[i][j][1]; |
| | | |
| | | if (x == null || y == null) { continue; } |
| | | |
| | | if (this.inRect(x, y, minX, maxX, minY, maxY)) { |
| | | String code = codeMatrix[i][j]; |
| | | if (!CodeNodeType.NONE.val.equals(code)) { |
| | | codeList.add(code); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | return codeList; |
| | | } |
| | | |
| | | private boolean inRect(double x, double y, |
| | | double minX, double maxX, |
| | | double minY, double maxY) { |
| | | return x >= minX && x <= maxX && y >= minY && y <= maxY; |
| | | } |
| | | |
| | | } |