fix:空木箱移库加并发锁
This commit is contained in:
@@ -5,11 +5,13 @@ import cn.hutool.core.date.DateTime;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.http.HttpStatus;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.nl.b_lms.sch.point.dao.SchBasePoint;
|
import org.nl.b_lms.sch.point.dao.SchBasePoint;
|
||||||
@@ -37,12 +39,15 @@ import org.nl.wms.ext.mes.service.LmsToMesService;
|
|||||||
import org.nl.wms.pda.mps.eum.RegionTypeEnum;
|
import org.nl.wms.pda.mps.eum.RegionTypeEnum;
|
||||||
import org.nl.wms.pdm.bi.service.SubpackagerelationService;
|
import org.nl.wms.pdm.bi.service.SubpackagerelationService;
|
||||||
import org.nl.wms.sch.manage.TaskStatusEnum;
|
import org.nl.wms.sch.manage.TaskStatusEnum;
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,6 +96,9 @@ public class InBoxManageServiceImpl implements InBoxManageService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private InBussManageService inBussManageService;
|
private InBussManageService inBussManageService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedissonClient redissonClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void inBox(JSONObject whereJson) {
|
public void inBox(JSONObject whereJson) {
|
||||||
@@ -677,6 +685,7 @@ public class InBoxManageServiceImpl implements InBoxManageService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 找一个空仓位(木箱区)
|
* 找一个空仓位(木箱区)
|
||||||
*
|
*
|
||||||
@@ -689,6 +698,7 @@ public class InBoxManageServiceImpl implements InBoxManageService {
|
|||||||
* }
|
* }
|
||||||
* @return JSONObject : 仓位对象
|
* @return JSONObject : 仓位对象
|
||||||
*/
|
*/
|
||||||
|
@SneakyThrows
|
||||||
public JSONObject getStruct(JSONObject jsonParam) {
|
public JSONObject getStruct(JSONObject jsonParam) {
|
||||||
// 仓位表
|
// 仓位表
|
||||||
WQLObject attrTab = WQLObject.getWQLObject("st_ivt_structattr");
|
WQLObject attrTab = WQLObject.getWQLObject("st_ivt_structattr");
|
||||||
@@ -699,95 +709,110 @@ public class InBoxManageServiceImpl implements InBoxManageService {
|
|||||||
*/
|
*/
|
||||||
String block_num = jsonParam.getString("move_block_num");
|
String block_num = jsonParam.getString("move_block_num");
|
||||||
|
|
||||||
JSONArray structArray = new JSONArray();
|
JSONObject jsonAttr = new JSONObject();
|
||||||
|
|
||||||
String height = jsonParam.getString("height");
|
RLock lock = redissonClient.getLock("getEmptyBox-----"+block_num);
|
||||||
if (height.equals("1")) {
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
height = "('1','2','3')";
|
try {
|
||||||
} else if (height.equals("2")) {
|
if (tryLock) {
|
||||||
height = "('2','3')";
|
JSONArray structArray = new JSONArray();
|
||||||
} else {
|
|
||||||
height = "('3')";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ObjectUtil.isEmpty(block_num)) {
|
String height = jsonParam.getString("height");
|
||||||
structArray = attrTab.query("IFNULL(storagevehicle_code,'') = '' " +
|
if (height.equals("1")) {
|
||||||
"AND is_used = '" + IOSEnum.IS_NOTANDYES.code("是") + "' AND is_delete = '" + IOSEnum.IS_NOTANDYES.code("否") + "' " +
|
height = "('1','2','3')";
|
||||||
"AND storagevehicle_type = '" + jsonParam.getString("vehicle_type") + "'" +
|
} else if (height.equals("2")) {
|
||||||
"AND height IN " + height + " " +
|
height = "('2','3')";
|
||||||
"AND lock_type = '" + IOSEnum.LOCK_TYPE.code("未锁定") + "' AND stor_id = '" + jsonParam.getString("stor_id") + "' " +
|
|
||||||
"AND sect_id = '" + jsonParam.getString("sect_id") + "'").getResultJSONArray(0);
|
|
||||||
} else {
|
|
||||||
structArray = attrTab.query("IFNULL(storagevehicle_code,'') = '' " +
|
|
||||||
"AND is_used = '" + IOSEnum.IS_NOTANDYES.code("是") + "' AND is_delete = '" + IOSEnum.IS_NOTANDYES.code("否") + "' " +
|
|
||||||
"AND storagevehicle_type = '" + jsonParam.getString("vehicle_type") + "'" +
|
|
||||||
"AND height IN " + height + " " +
|
|
||||||
"AND lock_type = '" + IOSEnum.LOCK_TYPE.code("未锁定") + "' AND stor_id = '" + jsonParam.getString("stor_id") + "' " +
|
|
||||||
"AND sect_id = '" + jsonParam.getString("sect_id") + "' AND block_num = '" + block_num + "'").getResultJSONArray(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ObjectUtil.isEmpty(structArray)) {
|
|
||||||
notInRowList.clear();
|
|
||||||
notInBlockList.clear();
|
|
||||||
throw new BadRequestException("仓位不足!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确定巷道:查看每个巷道最小木箱数的巷道,获取最小木箱数的巷道
|
|
||||||
// 不是移库则需要找新巷道
|
|
||||||
jsonParam.put("height", height);
|
|
||||||
if (ObjectUtil.isEmpty(block_num)) {
|
|
||||||
block_num = getMinBlock(jsonParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确定排:查看每排的木箱数量,找到数量最小的那排
|
|
||||||
jsonParam.put("block_num", block_num);
|
|
||||||
String row_num = getMinRow(jsonParam);
|
|
||||||
|
|
||||||
// 确定仓位: 找到仓位
|
|
||||||
jsonParam.put("row_num", row_num);
|
|
||||||
JSONObject jsonAttr = queryStruct(jsonParam);
|
|
||||||
|
|
||||||
// 如果是移库空并且仓位为空则报错
|
|
||||||
if (ObjectUtil.isNotEmpty(block_num) && ObjectUtil.isEmpty(jsonAttr)) {
|
|
||||||
throw new BadRequestException("转库任务巷道"+block_num+"仓位不足!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 为空则新找巷道
|
|
||||||
if (ObjectUtil.isEmpty(jsonAttr)) {
|
|
||||||
|
|
||||||
jsonParam.put("flag", "1");
|
|
||||||
notInBlockList.add(jsonParam.getString("block_num"));
|
|
||||||
|
|
||||||
String join = "('" + String.join("','", notInBlockList) + "')";
|
|
||||||
jsonParam.put("not_block", join);
|
|
||||||
|
|
||||||
List<JSONObject> blockList = WQL.getWO("BST_INBOX").addParamMap(jsonParam)
|
|
||||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
|
|
||||||
|
|
||||||
for (int i = 0; i < blockList.size(); i++) {
|
|
||||||
JSONObject json = blockList.get(i);
|
|
||||||
json.put("stor_id", jsonParam.getString("stor_id"));
|
|
||||||
json.put("sect_id", jsonParam.getString("sect_id"));
|
|
||||||
json.put("box_length", jsonParam.getString("box_length"));
|
|
||||||
json.put("box_width", jsonParam.getString("box_width"));
|
|
||||||
json.put("box_high", jsonParam.getString("box_high"));
|
|
||||||
json.put("vehicle_type", jsonParam.getString("vehicle_type"));
|
|
||||||
json.put("height", jsonParam.getString("height"));
|
|
||||||
|
|
||||||
String row_num_2 = getMinRow(json);
|
|
||||||
json.put("row_num", row_num_2);
|
|
||||||
JSONObject jsonAttr_2 = queryStruct(json);
|
|
||||||
|
|
||||||
if (ObjectUtil.isNotEmpty(jsonAttr_2)) {
|
|
||||||
jsonAttr = jsonAttr_2;
|
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
height = "('3')";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(block_num)) {
|
||||||
|
structArray = attrTab.query("IFNULL(storagevehicle_code,'') = '' " +
|
||||||
|
"AND is_used = '" + IOSEnum.IS_NOTANDYES.code("是") + "' AND is_delete = '" + IOSEnum.IS_NOTANDYES.code("否") + "' " +
|
||||||
|
"AND storagevehicle_type = '" + jsonParam.getString("vehicle_type") + "'" +
|
||||||
|
"AND height IN " + height + " " +
|
||||||
|
"AND lock_type = '" + IOSEnum.LOCK_TYPE.code("未锁定") + "' AND stor_id = '" + jsonParam.getString("stor_id") + "' " +
|
||||||
|
"AND sect_id = '" + jsonParam.getString("sect_id") + "'").getResultJSONArray(0);
|
||||||
|
} else {
|
||||||
|
structArray = attrTab.query("IFNULL(storagevehicle_code,'') = '' " +
|
||||||
|
"AND is_used = '" + IOSEnum.IS_NOTANDYES.code("是") + "' AND is_delete = '" + IOSEnum.IS_NOTANDYES.code("否") + "' " +
|
||||||
|
"AND storagevehicle_type = '" + jsonParam.getString("vehicle_type") + "'" +
|
||||||
|
"AND height IN " + height + " " +
|
||||||
|
"AND lock_type = '" + IOSEnum.LOCK_TYPE.code("未锁定") + "' AND stor_id = '" + jsonParam.getString("stor_id") + "' " +
|
||||||
|
"AND sect_id = '" + jsonParam.getString("sect_id") + "' AND block_num = '" + block_num + "'").getResultJSONArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(structArray)) {
|
||||||
|
notInRowList.clear();
|
||||||
|
notInBlockList.clear();
|
||||||
|
throw new BadRequestException("仓位不足!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定巷道:查看每个巷道最小木箱数的巷道,获取最小木箱数的巷道
|
||||||
|
// 不是移库则需要找新巷道
|
||||||
|
jsonParam.put("height", height);
|
||||||
|
if (ObjectUtil.isEmpty(block_num)) {
|
||||||
|
block_num = getMinBlock(jsonParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定排:查看每排的木箱数量,找到数量最小的那排
|
||||||
|
jsonParam.put("block_num", block_num);
|
||||||
|
String row_num = getMinRow(jsonParam);
|
||||||
|
|
||||||
|
// 确定仓位: 找到仓位
|
||||||
|
jsonParam.put("row_num", row_num);
|
||||||
|
jsonAttr = queryStruct(jsonParam);
|
||||||
|
|
||||||
|
// 如果是移库空并且仓位为空则报错
|
||||||
|
if (ObjectUtil.isNotEmpty(block_num) && ObjectUtil.isEmpty(jsonAttr)) {
|
||||||
|
throw new BadRequestException("转库任务巷道"+block_num+"仓位不足!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 为空则新找巷道
|
||||||
|
if (ObjectUtil.isEmpty(jsonAttr)) {
|
||||||
|
|
||||||
|
jsonParam.put("flag", "1");
|
||||||
|
notInBlockList.add(jsonParam.getString("block_num"));
|
||||||
|
|
||||||
|
String join = "('" + String.join("','", notInBlockList) + "')";
|
||||||
|
jsonParam.put("not_block", join);
|
||||||
|
|
||||||
|
List<JSONObject> blockList = WQL.getWO("BST_INBOX").addParamMap(jsonParam)
|
||||||
|
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
|
||||||
|
|
||||||
|
for (int i = 0; i < blockList.size(); i++) {
|
||||||
|
JSONObject json = blockList.get(i);
|
||||||
|
json.put("stor_id", jsonParam.getString("stor_id"));
|
||||||
|
json.put("sect_id", jsonParam.getString("sect_id"));
|
||||||
|
json.put("box_length", jsonParam.getString("box_length"));
|
||||||
|
json.put("box_width", jsonParam.getString("box_width"));
|
||||||
|
json.put("box_high", jsonParam.getString("box_high"));
|
||||||
|
json.put("vehicle_type", jsonParam.getString("vehicle_type"));
|
||||||
|
json.put("height", jsonParam.getString("height"));
|
||||||
|
|
||||||
|
String row_num_2 = getMinRow(json);
|
||||||
|
json.put("row_num", row_num_2);
|
||||||
|
JSONObject jsonAttr_2 = queryStruct(json);
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotEmpty(jsonAttr_2)) {
|
||||||
|
jsonAttr = jsonAttr_2;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notInRowList.clear();
|
||||||
|
notInBlockList.clear();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("存在正在分配的空木箱任务,请稍后再试!");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notInRowList.clear();
|
|
||||||
notInBlockList.clear();
|
|
||||||
return jsonAttr;
|
return jsonAttr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user