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.controller.params.TaskInParam;
|
import com.vincent.rsf.server.api.entity.dto.InTaskMsgDto;
|
import com.vincent.rsf.server.api.entity.dto.LocTypeDto;
|
import com.vincent.rsf.server.manager.entity.*;
|
import com.vincent.rsf.server.manager.enums.LocStsType;
|
import com.vincent.rsf.server.manager.enums.TaskType;
|
import com.vincent.rsf.server.manager.service.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
|
import javax.annotation.RegEx;
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
public class LocUtils {
|
|
/**
|
* 获取 浅库位对应的深库位号
|
*/
|
public static String getDeepLoc(SlaveProperties slaveProperties, String shallowLoc) {
|
LocService locService = SpringUtils.getBean(LocService.class);
|
Loc shaLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
|
int row = shaLoc.getRow()-1;
|
boolean contains = slaveProperties.getDoubleLocs().contains(row);
|
Loc deepLoc = null;
|
if (contains) {
|
deepLoc = locService.getOne(new LambdaQueryWrapper<Loc>()
|
.eq(Loc::getAreaId, shaLoc.getAreaId())
|
.eq(Loc::getRow, row)
|
.eq(Loc::getCol, shaLoc.getCol())
|
.eq(Loc::getLev, shaLoc.getLev())
|
);
|
}else {
|
deepLoc = locService.getOne(new LambdaQueryWrapper<Loc>()
|
.eq(Loc::getAreaId, shaLoc.getAreaId())
|
.eq(Loc::getRow, shaLoc.getRow()+1)
|
.eq(Loc::getCol, shaLoc.getCol())
|
.eq(Loc::getLev, shaLoc.getLev())
|
);
|
}
|
return deepLoc.getCode();
|
}
|
|
/**
|
* 获取 深库位对应的浅库位号
|
*/
|
public static String getShallowLoc(SlaveProperties slaveProperties, String deepLoc) {
|
LocService locService = SpringUtils.getBean(LocService.class);
|
Loc depLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, deepLoc));
|
int row = depLoc.getRow()-1;
|
boolean contains = slaveProperties.getDoubleLocs().contains(row);
|
Loc shallowLoc = null;
|
if (!contains) {
|
shallowLoc = locService.getOne(new LambdaQueryWrapper<Loc>()
|
.eq(Loc::getAreaId, depLoc.getAreaId())
|
.eq(Loc::getRow, row)
|
.eq(Loc::getCol, depLoc.getCol())
|
.eq(Loc::getLev, depLoc.getLev())
|
);
|
}else {
|
shallowLoc = locService.getOne(new LambdaQueryWrapper<Loc>()
|
.eq(Loc::getAreaId, depLoc.getAreaId())
|
.eq(Loc::getRow, depLoc.getRow()+1)
|
.eq(Loc::getCol, depLoc.getCol())
|
.eq(Loc::getLev, depLoc.getLev())
|
);
|
}
|
return shallowLoc.getCode();
|
}
|
|
/**
|
* 判断是否为浅库位
|
*/
|
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)) {
|
LocService locService = SpringUtils.getBean(LocService.class);
|
Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, locNo));
|
if (null == loc) {
|
throw new RuntimeException("库位解析异常");
|
}
|
return loc.getRow();
|
}
|
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();
|
}
|
}
|
}
|