New file |
| | |
| | | package com.zy.acs.manager.core.utils; |
| | | |
| | | import com.zy.acs.framework.common.Cools; |
| | | 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.Code; |
| | | import com.zy.acs.manager.manager.entity.Route; |
| | | import com.zy.acs.manager.manager.service.CodeGapService; |
| | | import com.zy.acs.manager.manager.service.CodeService; |
| | | import com.zy.acs.manager.manager.service.RouteService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Created by vincent on 12/9/2024 |
| | | */ |
| | | @Component |
| | | public class RouteGenerator { |
| | | |
| | | @Autowired |
| | | private MapDataDispatcher mapDataDispatcher; |
| | | @Autowired |
| | | private CodeService codeService; |
| | | @Autowired |
| | | private RouteService routeService; |
| | | @Autowired |
| | | private CodeGapService codeGapService; |
| | | |
| | | public List<Route> generateRoutes(String[][] codeMatrix) { |
| | | List<Route> routes = new ArrayList<>(); |
| | | |
| | | int rows = codeMatrix.length; |
| | | int cols = codeMatrix[0].length; |
| | | |
| | | // 遍历二维数组,生成相邻条码之间的 Route |
| | | for (int i = 0; i < rows; i++) { |
| | | for (int j = 0; j < cols; j++) { |
| | | String currentCodeData = codeMatrix[i][j]; |
| | | |
| | | // 跳过 NONE 条码 |
| | | if (currentCodeData == null || CodeNodeType.NONE.val.equals(currentCodeData)) { |
| | | continue; |
| | | } |
| | | Code currCode = codeService.selectByData(currentCodeData); |
| | | |
| | | // 检查右边相邻条码 |
| | | if (j + 1 < cols) { |
| | | String rightCodeData = codeMatrix[i][j + 1]; |
| | | if (!Cools.isEmpty(rightCodeData) && !CodeNodeType.NONE.val.equals(rightCodeData)) { |
| | | Code rightCode = codeService.selectByData(rightCodeData); |
| | | routeService.createRouteByCode(currCode, rightCode, 0, null); |
| | | } |
| | | } |
| | | |
| | | // 检查下边相邻条码 |
| | | if (i + 1 < rows) { |
| | | String bottomCodeData = codeMatrix[i + 1][j]; |
| | | if (!Cools.isEmpty(bottomCodeData) && !CodeNodeType.NONE.val.equals(bottomCodeData)) { |
| | | Code bottomCode = codeService.selectByData(bottomCodeData); |
| | | routeService.createRouteByCode(currCode, bottomCode, 0, null); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return routes; |
| | | } |
| | | |
| | | |
| | | } |