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; // 轮询次数
|
//满板正常入库
|
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("库位解析异常");
|
}
|
|
/**
|
* 通过库位号获取 列
|
*/
|
public static int getBay(String locNo) {
|
if (!Cools.isEmpty(locNo)) {
|
return Integer.parseInt(locNo.substring(2, 5));
|
}
|
throw new RuntimeException("库位解析异常");
|
}
|
|
/**
|
* 通过库位号获取 层
|
*/
|
public static int getLev(String locNo) {
|
if (!Cools.isEmpty(locNo)) {
|
return Integer.parseInt(locNo.substring(5, 7));
|
}
|
throw new RuntimeException("库位解析异常");
|
}
|
|
/**
|
* 类型检测
|
* 完全检测
|
**/
|
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();
|
}
|
}
|
}
|