rev:入库单创建人优化

This commit is contained in:
2024-08-21 17:30:05 +08:00
parent b52aeb2b18
commit e1801ce001
3 changed files with 199 additions and 144 deletions

View File

@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nl.b_lms.pdm.bi.slittingproductionplan.service.IPdmBiSlittingproductionplanService;
@@ -52,6 +53,8 @@ import org.nl.wms.sch.service.dto.PointDto;
import org.nl.wms.sch.tasks.InTask;
import org.nl.wms.st.inbill.service.StorPublicService;
import org.nl.wms.st.returns.service.impl.InAndOutRetrunServiceImpl;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
@@ -61,6 +64,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -123,6 +127,8 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl<StIvtIostorinvMapper,
private IpdmBiSubpackagerelationService ipdmBiSubpackagerelationService;
@Autowired
private RedissonClient redissonClient;
@Override
public Object pageQuery(Map query, Pageable pageQuery) {
@@ -260,150 +266,163 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl<StIvtIostorinvMapper,
@Override
@Transactional
@SneakyThrows
public void divStruct(Map whereJson) {
// 仓位表
WQLObject attrTab = WQLObject.getWQLObject("st_ivt_structattr");
// 库区表
WQLObject sectTab = WQLObject.getWQLObject("st_ivt_sectattr");
// 参数类型转换 Map-> JSONObject
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(whereJson));
// 分配明细集合
ArrayList<HashMap> list = (ArrayList<HashMap>) whereJson.get("tableMater");
// 类型转换linkenHashMap -> JSONObject
JSONObject jsonDis = list.stream()
.map(row -> JSONObject.parseObject(JSON.toJSONString(row)))
.collect(Collectors.toList()).get(0);
// 判断当前木箱是否已经分配过货位
StIvtIostorinvdis disDao = iStIvtIostorinvdisService.getById(jsonDis.getString("iostorinvdis_id"));
if (ObjectUtil.isNotEmpty(disDao.getStruct_id())) {
throw new BadRequestException("该木箱已经分配过货位,无法继续分配!");
}
// 主表实体类
StIvtIostorinv mstDao = this.getById(disDao.getIostorinv_id());
// 用于锁定货位
JSONObject jsonLock = new JSONObject();
ArrayList<String> paramLockList = new ArrayList<>();
// 仓位对象
JSONObject jsonAttr;
// 是否自动分配货位
Boolean checked = jsonObject.getBoolean("checked");
String height = "";
if (ObjectUtil.isNotEmpty(checked) && checked) {
// 自动分配: 根据仓库、库区匹配一个合适的仓
JSONObject attrParam = new JSONObject();
attrParam.put("stor_id", jsonObject.getString("stor_id"));
attrParam.put("sect_id", jsonObject.getString("sect_id"));
attrParam.put("material_id", disDao.getMaterial_id());
attrParam.put("box_no", disDao.getBox_no());
BstIvtBoxinfo boxDao = getBstIvtBoxinfo(whereJson);
if (boxDao == null) {
throw new BadRequestException("未找到该木箱信息!");
}
jsonObject.put("box_no",boxDao.getBox_no());
jsonObject.put("vehicle_type",boxDao.getVehicle_type());
attrParam.put("vehicle_type", boxDao.getVehicle_type());
//根据木箱高度,判断入库仓位的高度
String heightLevel1 = iSysParamService.findByCode("height_level_1").getValue();
String heightLevel2 = iSysParamService.findByCode("height_level_2").getValue();
String box_high = boxDao.getBox_high();
if (Integer.parseInt(box_high) <= Integer.parseInt(heightLevel1)) {
height = "('1','2','3')";
} else if (Integer.parseInt(box_high) > Integer.parseInt(heightLevel1) && Integer.parseInt(box_high) <= Integer.parseInt(heightLevel2)) {
height = "('2','3')";
} else {
height = "('3')";
}
attrParam.put("height", height);
JSONObject jsonSect = sectTab.query("sect_id = '" + jsonObject.getString("sect_id") + "'").uniqueResult(0);
// 判断是否是虚拟区
if (jsonSect.getString("sect_type_attr").equals(IOSEnum.SECT_TYPE.code("虚拟区"))) {
jsonAttr = attrTab.query("sect_id = '" + jsonObject.getString("sect_id") + "' AND lock_type = '1' AND is_delete = '0' AND IFNULL( storagevehicle_code, '' ) = ''").uniqueResult(0);
} else {
jsonAttr = inBussManageService.getOneStruct(attrParam);
}
} else {
// 指定分配
jsonAttr = attrTab.query("struct_id = '" + jsonDis.getString("struct_id") + "'").uniqueResult(0);
}
if (ObjectUtil.isEmpty(jsonAttr)) {
throw new BadRequestException("没有可用仓位!");
}
// 调用业务处理类锁定货位
paramLockList.add(jsonAttr.getString("struct_code"));
jsonLock.put("inv_type", mstDao.getBill_type());
jsonLock.put("inv_id", mstDao.getIostorinv_id());
jsonLock.put("inv_code", mstDao.getBill_code());
jsonLock.put("lock_type", IOSEnum.LOCK_TYPE.code("入库锁"));
jsonLock.put("operate", IOSEnum.IO_TYPE.code("入库"));
inBussManageService.lockStruct(paramLockList, jsonLock);
// 判断是否虚拟区
String work_status;
Long task_id = null;
JSONObject jsonSect = sectTab.query("sect_id = '" + jsonAttr.getString("sect_id") + "'").uniqueResult(0);
if (jsonSect.getString("sect_type_attr").equals(IOSEnum.SECT_TYPE.code("虚拟区"))) {
// 虚拟区:执行状态为完成
work_status = IOSEnum.WORK_STATUS.code("完成");
task_id = IdUtil.getLongId();
} else {
work_status = IOSEnum.WORK_STATUS.code("未生成");
}
// 更新分配明细
iStIvtIostorinvdisService.update(
new UpdateWrapper<StIvtIostorinvdis>().lambda()
.set(StIvtIostorinvdis::getStruct_id, jsonAttr.getString("struct_id"))
.set(StIvtIostorinvdis::getStruct_code, jsonAttr.getString("struct_code"))
.set(StIvtIostorinvdis::getStruct_name, jsonAttr.getString("struct_name"))
.set(StIvtIostorinvdis::getSect_id, jsonAttr.getString("sect_id"))
.set(StIvtIostorinvdis::getSect_code, jsonAttr.getString("sect_code"))
.set(StIvtIostorinvdis::getSect_name, jsonAttr.getString("sect_name"))
.set(StIvtIostorinvdis::getWork_status, work_status)
.set(StIvtIostorinvdis::getTask_id, task_id)
.eq(StIvtIostorinvdis::getIostorinv_id, disDao.getIostorinv_id())
.eq(StIvtIostorinvdis::getBox_no, disDao.getBox_no())
);
// 更新库存
List<StIvtIostorinvdis> disDaoList = iStIvtIostorinvdisService.list(
new QueryWrapper<StIvtIostorinvdis>().lambda()
.eq(StIvtIostorinvdis::getIostorinv_id, disDao.getIostorinv_id())
.eq(StIvtIostorinvdis::getBox_no, disDao.getBox_no())
);
upateIvt(disDaoList, mstDao, IOSEnum.IVT_CHANGE.code("加待入"));
// 更新明细状态
iStIvtIostorinvdtlService.updateStatus(disDao.getIostorinvdtl_id());
// 更新主表状态
StIvtIostorinv mst = updateMstStatus(disDao.getIostorinv_id());
mst.setDis_optid(Long.parseLong(SecurityUtils.getCurrentUserId()));
mst.setDis_optname(SecurityUtils.getCurrentNickName());
mst.setDis_time(DateUtil.now());
this.updateById(mst);
// 判断是否自动下发任务
if (jsonObject.getString("is_send").equals(IOSEnum.IS_NOTANDYES.code("")) && ObjectUtil.isNotEmpty(jsonObject.getString("is_send"))) {
JSONObject jsonSend = new JSONObject();
StIvtIostorinvdtl dtlDao = iStIvtIostorinvdtlService.list(
new QueryWrapper<StIvtIostorinvdtl>().lambda()
.eq(StIvtIostorinvdtl::getIostorinv_id, mst.getIostorinv_id())
).get(0);
List<LinkedHashMap> disList = iStIvtIostorinvdisService.list(
RLock lock = redissonClient.getLock(StIvtIostorinvServiceImpl.class.getName());
boolean tryLock = lock.tryLock(5, TimeUnit.SECONDS);
try {
if (tryLock) {
// 仓位表
WQLObject attrTab = WQLObject.getWQLObject("st_ivt_structattr");
// 库区表
WQLObject sectTab = WQLObject.getWQLObject("st_ivt_sectattr");
// 参数类型转换 Map-> JSONObject
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(whereJson));
// 分配明细集合
ArrayList<HashMap> list = (ArrayList<HashMap>) whereJson.get("tableMater");
// 类型转换linkenHashMap -> JSONObject
JSONObject jsonDis = list.stream()
.map(row -> JSONObject.parseObject(JSON.toJSONString(row)))
.collect(Collectors.toList()).get(0);
// 判断当前木箱是否已经分配过货位
StIvtIostorinvdis disDao = iStIvtIostorinvdisService.getById(jsonDis.getString("iostorinvdis_id"));
if (ObjectUtil.isNotEmpty(disDao.getStruct_id())) {
throw new BadRequestException("该木箱已经分配过货位,无法继续分配!");
}
// 主表实体类
StIvtIostorinv mstDao = this.getById(disDao.getIostorinv_id());
// 用于锁定货位
JSONObject jsonLock = new JSONObject();
ArrayList<String> paramLockList = new ArrayList<>();
// 仓位对象
JSONObject jsonAttr;
// 是否自动分配
Boolean checked = jsonObject.getBoolean("checked");
String height = "";
if (ObjectUtil.isNotEmpty(checked) && checked) {
// 自动分配: 根据仓库、库区匹配一个合适的仓位
JSONObject attrParam = new JSONObject();
attrParam.put("stor_id", jsonObject.getString("stor_id"));
attrParam.put("sect_id", jsonObject.getString("sect_id"));
attrParam.put("material_id", disDao.getMaterial_id());
attrParam.put("box_no", disDao.getBox_no());
BstIvtBoxinfo boxDao = getBstIvtBoxinfo(whereJson);
if (boxDao == null) {
throw new BadRequestException("未找到该木箱信息!");
}
jsonObject.put("box_no",boxDao.getBox_no());
jsonObject.put("vehicle_type",boxDao.getVehicle_type());
attrParam.put("vehicle_type", boxDao.getVehicle_type());
//根据木箱高度,判断入库仓位的高度
String heightLevel1 = iSysParamService.findByCode("height_level_1").getValue();
String heightLevel2 = iSysParamService.findByCode("height_level_2").getValue();
String box_high = boxDao.getBox_high();
if (Integer.parseInt(box_high) <= Integer.parseInt(heightLevel1)) {
height = "('1','2','3')";
} else if (Integer.parseInt(box_high) > Integer.parseInt(heightLevel1) && Integer.parseInt(box_high) <= Integer.parseInt(heightLevel2)) {
height = "('2','3')";
} else {
height = "('3')";
}
attrParam.put("height", height);
JSONObject jsonSect = sectTab.query("sect_id = '" + jsonObject.getString("sect_id") + "'").uniqueResult(0);
// 判断是否是虚拟区
if (jsonSect.getString("sect_type_attr").equals(IOSEnum.SECT_TYPE.code("虚拟区"))) {
jsonAttr = attrTab.query("sect_id = '" + jsonObject.getString("sect_id") + "' AND lock_type = '1' AND is_delete = '0' AND IFNULL( storagevehicle_code, '' ) = ''").uniqueResult(0);
} else {
jsonAttr = inBussManageService.getOneStruct(attrParam);
}
} else {
// 指定分配
jsonAttr = attrTab.query("struct_id = '" + jsonDis.getString("struct_id") + "'").uniqueResult(0);
}
if (ObjectUtil.isEmpty(jsonAttr)) {
throw new BadRequestException("没有可用仓位!");
}
// 调用业务处理类锁定货位
paramLockList.add(jsonAttr.getString("struct_code"));
jsonLock.put("inv_type", mstDao.getBill_type());
jsonLock.put("inv_id", mstDao.getIostorinv_id());
jsonLock.put("inv_code", mstDao.getBill_code());
jsonLock.put("lock_type", IOSEnum.LOCK_TYPE.code("入库锁"));
jsonLock.put("operate", IOSEnum.IO_TYPE.code("入库"));
inBussManageService.lockStruct(paramLockList, jsonLock);
// 判断是否虚拟区
String work_status;
Long task_id = null;
JSONObject jsonSect = sectTab.query("sect_id = '" + jsonAttr.getString("sect_id") + "'").uniqueResult(0);
if (jsonSect.getString("sect_type_attr").equals(IOSEnum.SECT_TYPE.code("虚拟区"))) {
// 虚拟区:执行状态为完成
work_status = IOSEnum.WORK_STATUS.code("完成");
task_id = IdUtil.getLongId();
} else {
work_status = IOSEnum.WORK_STATUS.code("未生成");
}
// 更新分配明细
iStIvtIostorinvdisService.update(
new UpdateWrapper<StIvtIostorinvdis>().lambda()
.set(StIvtIostorinvdis::getStruct_id, jsonAttr.getString("struct_id"))
.set(StIvtIostorinvdis::getStruct_code, jsonAttr.getString("struct_code"))
.set(StIvtIostorinvdis::getStruct_name, jsonAttr.getString("struct_name"))
.set(StIvtIostorinvdis::getSect_id, jsonAttr.getString("sect_id"))
.set(StIvtIostorinvdis::getSect_code, jsonAttr.getString("sect_code"))
.set(StIvtIostorinvdis::getSect_name, jsonAttr.getString("sect_name"))
.set(StIvtIostorinvdis::getWork_status, work_status)
.set(StIvtIostorinvdis::getTask_id, task_id)
.eq(StIvtIostorinvdis::getIostorinv_id, disDao.getIostorinv_id())
.eq(StIvtIostorinvdis::getBox_no, disDao.getBox_no())
);
// 更新库存
List<StIvtIostorinvdis> disDaoList = iStIvtIostorinvdisService.list(
new QueryWrapper<StIvtIostorinvdis>().lambda()
.eq(StIvtIostorinvdis::getIostorinv_id, disDao.getIostorinv_id())
.eq(StIvtIostorinvdis::getBox_no, disDao.getBox_no())
);
upateIvt(disDaoList, mstDao, IOSEnum.IVT_CHANGE.code("加待入"));
// 更新明细状态
iStIvtIostorinvdtlService.updateStatus(disDao.getIostorinvdtl_id());
// 更新主表状态
StIvtIostorinv mst = updateMstStatus(disDao.getIostorinv_id());
mst.setDis_optid(Long.parseLong(SecurityUtils.getCurrentUserId()));
mst.setDis_optname(SecurityUtils.getCurrentNickName());
mst.setDis_time(DateUtil.now());
this.updateById(mst);
// 判断是否自动下发任务
if (jsonObject.getString("is_send").equals(IOSEnum.IS_NOTANDYES.code("")) && ObjectUtil.isNotEmpty(jsonObject.getString("is_send"))) {
JSONObject jsonSend = new JSONObject();
StIvtIostorinvdtl dtlDao = iStIvtIostorinvdtlService.list(
new QueryWrapper<StIvtIostorinvdtl>().lambda()
.eq(StIvtIostorinvdtl::getIostorinv_id, mst.getIostorinv_id())
).get(0);
List<LinkedHashMap> disList = iStIvtIostorinvdisService.list(
new QueryWrapper<StIvtIostorinvdis>().lambda()
.eq(StIvtIostorinvdis::getIostorinv_id, mst.getIostorinv_id())
).stream().map(row -> JSONObject.parseObject(JSON.toJSONString(row), LinkedHashMap.class))
.collect(Collectors.toList());
jsonSend.put("dtl_row", JSONObject.parseObject(JSON.toJSONString(dtlDao)));
jsonSend.put("tableMater", disList);
jsonSend.put("point_code", jsonObject.getString("point_code"));
jsonSend.put("stor_id", mst.getStor_id());
//成品入库托盘类型
jsonSend.put("vehicle_code", jsonObject.getString("box_no"));
jsonSend.put("vehicle_code2", jsonObject.getString("vehicle_code"));
JSONObject param = new JSONObject();
param.put("containerType", jsonObject.getString("vehicle_type"));
param.put("heightLevel", height);
jsonSend.put("request_param", param.toString());
String task_id1 = this.setPoint(jsonSend);
// 下发任务
JSONObject sendJson = new JSONObject();
sendJson.put("task_id", task_id1);
this.reIssueTask(sendJson);
.collect(Collectors.toList());
jsonSend.put("dtl_row", JSONObject.parseObject(JSON.toJSONString(dtlDao)));
jsonSend.put("tableMater", disList);
jsonSend.put("point_code", jsonObject.getString("point_code"));
jsonSend.put("stor_id", mst.getStor_id());
//成品入库托盘类型
jsonSend.put("vehicle_code", jsonObject.getString("box_no"));
jsonSend.put("vehicle_code2", jsonObject.getString("vehicle_code"));
JSONObject param = new JSONObject();
param.put("containerType", jsonObject.getString("vehicle_type"));
param.put("heightLevel", height);
jsonSend.put("request_param", param.toString());
String task_id1 = this.setPoint(jsonSend);
// 下发任务
JSONObject sendJson = new JSONObject();
sendJson.put("task_id", task_id1);
this.reIssueTask(sendJson);
}
} else {
throw new BadRequestException("有入库单据正在分配中,请稍后在试");
}
} finally {
if (tryLock) {
lock.unlock();
}
}
}
@@ -648,6 +667,20 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl<StIvtIostorinvMapper,
*/
private StIvtIostorinv updataMst(Map whereJson, StIvtIostorinv mstDao) {
// 明细-用于查找包装关系
ArrayList<HashMap> list = (ArrayList<HashMap>) whereJson.get("tableData");
List<JSONObject> rows = list.stream()
.map(row -> JSONObject.parseObject(JSON.toJSONString(row)))
.collect(Collectors.toList());
if (ObjectUtil.isEmpty(rows)) {
throw new BadRequestException("出入库明细不能为空!");
}
JSONObject jsonSub = WQLObject.getWQLObject("pdm_bi_subpackagerelation")
.query("package_box_sn = '" + rows.get(0).getString("package_box_sn") + "'")
.uniqueResult(0);
// 仓库信息
StorattrDto storattrDto = storattrService.findById(Long.parseLong((String) whereJson.get("stor_id")));
@@ -655,9 +688,14 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl<StIvtIostorinvMapper,
String currentUserId = SecurityUtils.getCurrentUserId();
String currentNickName = SecurityUtils.getCurrentNickName();
if (currentUserId.equals(IOSEnum.EXT_ACS.code("acs"))) {
// 如果是外部系统创建人全部写系统参数
currentUserId = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("IOS_CONFIRM_USER").getValue();
currentNickName = IOSEnum.EXT_ACS.code("kc");
// 如果是外部系统创建人全部写系统参数: 如果包装关系上有创建人就用包装关系上的,如果没有就用默认的
if (ObjectUtil.isEmpty(jsonSub) || ObjectUtil.isEmpty(jsonSub.getString("create_id"))) {
currentUserId = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("IOS_CONFIRM_USER").getValue();
currentNickName = IOSEnum.EXT_ACS.code("kc");
} else {
currentUserId = jsonSub.getString("create_id");
currentNickName = jsonSub.getString("create_name");
}
}
// 新增

View File

@@ -315,10 +315,21 @@ public class InBoxManageServiceImpl implements InBoxManageService {
public void returnIn(JSONObject whereJson) {
// 载具表
//api/twoPda/vehicle/returnIn
// 根据木箱号查询是否有托盘绑定关系,如果有则解绑
JSONObject jsonExt = WQLObject.getWQLObject("md_pb_storagevehicleext")
.query("pcsn = '" + whereJson.getString("box_no") + "'")
.uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonExt)) {
JSONObject param = new JSONObject();
param.put("pcsn", "");
WQLObject.getWQLObject("md_pb_storagevehicleext")
.update(param,"pcsn = '"+whereJson.getString("box_no")+"'");
}
/*
* 查询mes木箱信息插入木箱信息表
*/
JSONArray resultJSONArray = WQLObject.getWQLObject("pdm_bi_subpackagerelation").query("package_box_sn = '" + whereJson.getString("box_no") + "' AND status = '0'").getResultJSONArray(0);
if (ObjectUtil.isEmpty(resultJSONArray)) {
throw new BadRequestException("未查询到子卷包装信息!");

View File

@@ -2032,6 +2032,12 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
} else {
throw new BadRequestException("托盘号有误,无法找到对应的托盘类型!");
}
// 更新子卷包装关系为生成
JSONObject param = new JSONObject();
param.put("status", IOSEnum.IS_NOTANDYES.code(""));
WQLObject.getWQLObject("pdm_bi_subpackagerelation")
.update(param,"package_box_sn = '"+jsonObject.getString("box_no")+"'");
jsonTaskParam.put("request_param", request_param);
TwoExceptionInTask bean = SpringContextHolder.getBean(TwoExceptionInTask.class);
bean.createTask(jsonTaskParam);