| | |
| | | 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 lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | /** |
| | | * Created by vincent on 12/9/2024 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class RouteGenerator { |
| | | |
| | |
| | | @Autowired |
| | | private CodeGapService codeGapService; |
| | | |
| | | public List<Route> generateRoutes(String[][] codeMatrix) { |
| | | List<Route> routes = new ArrayList<>(); |
| | | public static String generateRouteKey(String codeData0, String codeData1) { |
| | | if (Cools.isEmpty(codeData0, codeData1)) { |
| | | return null; |
| | | } |
| | | if (codeData0.compareTo(codeData1) < 0) { |
| | | return codeData0 + "-" + codeData1; |
| | | } else { |
| | | return codeData1 + "-" + codeData0; |
| | | } |
| | | } |
| | | |
| | | public static String generateRouteCdaKey(int[] code0Cda, int[] code1Cda) { |
| | | if (Cools.isEmpty(code0Cda, code1Cda)) { |
| | | return null; |
| | | } |
| | | if (code0Cda[0] < code1Cda[0] || (code0Cda[0] == code1Cda[0] && code0Cda[1] < code1Cda[1])) { |
| | | return code0Cda[0] + "," + code0Cda[1] + "-" + code1Cda[0] + "," + code1Cda[1]; |
| | | } else { |
| | | return code1Cda[0] + "," + code1Cda[1] + "-" + code0Cda[0] + "," + code0Cda[1]; |
| | | } |
| | | } |
| | | |
| | | public List<String> generateRoutes(String[][] codeMatrix) { |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | | int rows = codeMatrix.length; |
| | | int cols = codeMatrix[0].length; |
| | |
| | | if (currentCodeData == null || CodeNodeType.NONE.val.equals(currentCodeData)) { |
| | | continue; |
| | | } |
| | | Code currCode = codeService.selectByData(currentCodeData); |
| | | Code currCode = codeService.getCacheByData(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); |
| | | Code rightCode = codeService.getCacheByData(rightCodeData); |
| | | list.add(currCode.getData() + "-" + rightCode.getData()); |
| | | routeService.createRouteByCode(currCode, rightCode, 0, null); |
| | | codeGapService.createCodeGapByCode(currCode, rightCode, null); |
| | | |
| | | log.info(currCode.getData() + "-" + rightCode.getData() + " [finished]"); |
| | | } |
| | | } |
| | | |
| | |
| | | if (i + 1 < rows) { |
| | | String bottomCodeData = codeMatrix[i + 1][j]; |
| | | if (!Cools.isEmpty(bottomCodeData) && !CodeNodeType.NONE.val.equals(bottomCodeData)) { |
| | | Code bottomCode = codeService.selectByData(bottomCodeData); |
| | | Code bottomCode = codeService.getCacheByData(bottomCodeData); |
| | | list.add(currCode.getData() + "-" + bottomCode.getData()); |
| | | routeService.createRouteByCode(currCode, bottomCode, 0, null); |
| | | codeGapService.createCodeGapByCode(currCode, bottomCode, null); |
| | | |
| | | log.info(currCode.getData() + "-" + bottomCode.getData() + " [finished]"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return routes; |
| | | return list; |
| | | } |
| | | |
| | | |