From da20b84fb1dbb266939deff9fd52f9a16f4e32fa Mon Sep 17 00:00:00 2001 From: zjj <3272660260@qq.com> Date: 星期日, 27 四月 2025 14:59:24 +0800 Subject: [PATCH] #生成入库任务优化 --- rsf-server/src/main/java/com/vincent/rsf/server/api/utils/LocUtils.java | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 166 insertions(+), 0 deletions(-) diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/api/utils/LocUtils.java b/rsf-server/src/main/java/com/vincent/rsf/server/api/utils/LocUtils.java new file mode 100644 index 0000000..dc5064e --- /dev/null +++ b/rsf-server/src/main/java/com/vincent/rsf/server/api/utils/LocUtils.java @@ -0,0 +1,166 @@ +package com.vincent.rsf.server.api.utils; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.vincent.rsf.framework.common.Arith; +import com.vincent.rsf.framework.common.Cools; +import com.vincent.rsf.framework.common.SpringUtils; +import com.vincent.rsf.framework.exception.CoolException; +import com.vincent.rsf.server.api.entity.dto.LocTypeDto; +import com.vincent.rsf.server.manager.entity.DeviceBind; +import com.vincent.rsf.server.manager.entity.Loc; +import com.vincent.rsf.server.manager.service.DeviceBindService; + + +import java.util.List; + +public class LocUtils { + + /** + * 鑾峰彇 娴呭簱浣嶅搴旂殑娣卞簱浣嶅彿 + */ + public static String getDeepLoc(SlaveProperties slaveProperties, String shallowLoc) { + int row = getRow(shallowLoc); + int remainder = (int) Arith.remainder(row, slaveProperties.getGroupCount()); + int targetRow; + if (remainder == 2) { + targetRow = row - 1; + } else if (remainder == 3) { + targetRow = row + 1; + } else { + throw new CoolException(shallowLoc + "涓嶆槸娴呭簱浣嶏紝绯荤粺绻佸繖"); + } + return zerofill(String.valueOf(targetRow), 2) + shallowLoc.substring(2); + } + + /** + * 鑾峰彇 娣卞簱浣嶅搴旂殑娴呭簱浣嶅彿 + */ + public static String getShallowLoc(SlaveProperties slaveProperties, String deepLoc) { + int row = getRow(deepLoc); + int remainder = (int) Arith.remainder(row, slaveProperties.getGroupCount()); + int shallowRow = remainder == 1 ? (row + 1) : (row - 1); + return zerofill(String.valueOf(shallowRow), 2) + deepLoc.substring(2); + } + + /** + * 鍒ゆ柇鏄惁涓烘祬搴撲綅 + */ + public static boolean isShallowLoc(SlaveProperties slaveProperties, String locNo) { + if (slaveProperties.isDoubleDeep()) { + int row = getRow(locNo); + return !slaveProperties.getDoubleLocs().contains(row); + } else { + return false; + } + } + + //鑾峰彇绔欑偣瀵瑰簲鐨勫簱绫诲瀷 + public static Long getAreaType(Integer sourceStaNo) { + DeviceBindService rowLastnoService = SpringUtils.getBean(DeviceBindService.class); + List<DeviceBind> deviceBinds = rowLastnoService.list(new LambdaQueryWrapper<DeviceBind>()); + for (DeviceBind deviceBind : deviceBinds) { + String[] staNoList = deviceBind.getStaList().split(";"); + for (String staNo : staNoList) { + if (staNo.equals(sourceStaNo.toString())) { + return deviceBind.getId(); + } + } + } + return 0L; + } + + //搴撲綅鎺掑彿鍒嗛厤 + public static int[] LocNecessaryParameters(DeviceBind deviceBind, Integer curRow, Integer crnNumber) { + + return LocNecessaryParametersDoubleExtension(curRow, crnNumber); //宸插畬鍠� + + + } + + //缁忓吀鍙屼几搴撲綅 + public static int[] LocNecessaryParametersDoubleExtension( Integer curRow, Integer crnNumber) { + int[] necessaryParameters = new int[]{0, 0, 0, 0}; + + necessaryParameters[0] = crnNumber; // 杞娆℃暟 + //婊℃澘姝e父鍏ュ簱 + if (curRow.equals(crnNumber * 4)) { + necessaryParameters[1] = 1; //curRow 鏈�娣卞簱浣嶆帓 + necessaryParameters[2] = 1; //crnNo 鍫嗗灈鏈哄彿 + necessaryParameters[3] = 2; //nearRow 鏈�娴呭簱浣嶆帓 + } else if (curRow.equals(crnNumber * 4 - 3)) { + necessaryParameters[1] = 4; //curRow 鏈�娣卞簱浣嶆帓 + necessaryParameters[2] = 1; //crnNo 鍫嗗灈鏈哄彿 + necessaryParameters[3] = 3; //nearRow 鏈�娴呭簱浣嶆帓 + } else { + curRow = curRow + 4; + if (curRow < 1 || curRow > (crnNumber * 4)) { + throw new CoolException("搴撲綅鎺掑彿寮傚父锛氭帓鍙凤細" + curRow); + } + if ((curRow - 1) % 4 == 0) { + necessaryParameters[1] = curRow; //curRow 鏈�娣卞簱浣嶆帓 + necessaryParameters[2] = (curRow + 3) / 4; //crnNo 鍫嗗灈鏈哄彿 + necessaryParameters[3] = curRow + 1; //nearRow 鏈�娴呭簱浣嶆帓 + } else if (curRow % 4 == 0) { + necessaryParameters[1] = curRow; //curRow 鏈�娣卞簱浣嶆帓 + necessaryParameters[2] = curRow / 4; //crnNo 鍫嗗灈鏈哄彿 + necessaryParameters[3] = curRow - 1; //nearRow 鏈�娴呭簱浣嶆帓 + } else { + throw new CoolException("搴撲綅鎺掑彿寮傚父锛氭帓鍙凤細" + curRow); + } + } + + return necessaryParameters; + } + + /** + * 閫氳繃搴撲綅鍙疯幏鍙� 鎺� + */ + public static int getRow(String locNo) { + if (!Cools.isEmpty(locNo)) { + return Integer.parseInt(locNo.substring(0, 2)); + } + throw new RuntimeException("搴撲綅瑙f瀽寮傚父"); + } + + /** + * 閫氳繃搴撲綅鍙疯幏鍙� 鍒� + */ + public static int getBay(String locNo) { + if (!Cools.isEmpty(locNo)) { + return Integer.parseInt(locNo.substring(2, 5)); + } + throw new RuntimeException("搴撲綅瑙f瀽寮傚父"); + } + + /** + * 閫氳繃搴撲綅鍙疯幏鍙� 灞� + */ + public static int getLev(String locNo) { + if (!Cools.isEmpty(locNo)) { + return Integer.parseInt(locNo.substring(5, 7)); + } + throw new RuntimeException("搴撲綅瑙f瀽寮傚父"); + } + + /** + * 绫诲瀷妫�娴� + * 瀹屽叏妫�娴� + **/ + public static boolean locMoveCheckLocTypeComplete(Loc loc, LocTypeDto dto) { + // 濡傛灉婧愬簱浣嶆槸楂樺簱浣嶏紝鐩爣搴撲綅鏄綆搴撲綅 + return dto.getLocType1().equals(Integer.parseInt(loc.getType())); + } + public static String zerofill(String msg, Integer count) { + if (msg.length() == count) { + return msg; + } else if (msg.length() > count) { + return msg.substring(0, 16); + } else { + StringBuilder msgBuilder = new StringBuilder(msg); + for (int i = 0; i < count - msg.length(); i++) { + msgBuilder.insert(0, "0"); + } + return msgBuilder.toString(); + } + } +} -- Gitblit v1.9.1