rev:改切、报废出库自动分配变更为手动分配
This commit is contained in:
@@ -10,7 +10,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.SneakyThrows;
|
||||
import org.nl.b_lms.pdm_manage.enums.SUBEnum;
|
||||
import org.nl.b_lms.sch.tasks.TwoExcepionalMoveTask;
|
||||
import org.nl.b_lms.sch.tasks.TwoOutExceptionalTask;
|
||||
import org.nl.b_lms.sch.tasks.TwoOutTask;
|
||||
import org.nl.b_lms.storage_manage.database.service.IBstIvtBoxinfoService;
|
||||
@@ -42,12 +44,15 @@ import org.nl.wms.basedata.st.service.dto.StorattrDto;
|
||||
import org.nl.wms.pda.mps.eum.RegionTypeEnum;
|
||||
import org.nl.wms.sch.manage.TaskStatusEnum;
|
||||
import org.nl.wms.util.TranUtil;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collector;
|
||||
@@ -130,6 +135,9 @@ public class StIvtIostorinvOutServiceImpl extends ServiceImpl<StIvtIostorinvOutM
|
||||
@Autowired
|
||||
private TwoInBussManageService twoInBussManageService;
|
||||
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String insertMst(JSONObject whereJson) {
|
||||
@@ -211,6 +219,7 @@ public class StIvtIostorinvOutServiceImpl extends ServiceImpl<StIvtIostorinvOutM
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@SneakyThrows
|
||||
public void allDiv(JSONObject whereJson) {
|
||||
/*
|
||||
* 分配规则:
|
||||
@@ -267,39 +276,50 @@ public class StIvtIostorinvOutServiceImpl extends ServiceImpl<StIvtIostorinvOutM
|
||||
throw new BadRequestException("库存不足!");
|
||||
}
|
||||
|
||||
// 用于插入分配明细的集合
|
||||
List<StIvtIostorinvdis> disDaoList = new ArrayList<>();
|
||||
RLock lock = redissonClient.getLock("all_divTwo");
|
||||
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||
try {
|
||||
if (tryLock) {
|
||||
// 用于插入分配明细的集合
|
||||
List<StIvtIostorinvdis> disDaoList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < dtlDaoList.size(); i++) {
|
||||
StIvtIostorinvdtl dtlDao = dtlDaoList.get(i);
|
||||
for (int i = 0; i < dtlDaoList.size(); i++) {
|
||||
StIvtIostorinvdtl dtlDao = dtlDaoList.get(i);
|
||||
|
||||
// 调用分配库存公共方法
|
||||
List<StIvtIostorinvdis> disArr = outBussManageService.divIvt(dtlDao,ivtList);
|
||||
// 调用分配库存公共方法
|
||||
List<StIvtIostorinvdis> disArr = outBussManageService.divIvt(dtlDao,ivtList);
|
||||
|
||||
disDaoList.addAll(disArr);
|
||||
disDaoList.addAll(disArr);
|
||||
}
|
||||
|
||||
// 更新仓位
|
||||
List<String> paramLockList = disDaoList.stream()
|
||||
.map(StIvtIostorinvdis::getStruct_code)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
JSONObject jsonLockParam = new JSONObject();
|
||||
jsonLockParam.put("inv_type", mstDao.getBill_type());
|
||||
jsonLockParam.put("inv_id", mstDao.getIostorinv_id());
|
||||
jsonLockParam.put("inv_code", mstDao.getBill_code());
|
||||
jsonLockParam.put("lock_type", IOSEnum.LOCK_TYPE.code("出库锁"));
|
||||
jsonLockParam.put("operate", IOSEnum.IO_TYPE.code("出库"));
|
||||
|
||||
outBussManageService.lockStruct(paramLockList,jsonLockParam);
|
||||
|
||||
// 插入分配明细
|
||||
iStIvtIostorinvdisService.saveBatch(disDaoList);
|
||||
|
||||
// 更新主表状态
|
||||
updateMstStatus(mstDao.getIostorinv_id());
|
||||
} else {
|
||||
throw new BadRequestException("其他出库单当前正在分配货位,请等待几秒再进行操作!");
|
||||
}
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新仓位
|
||||
List<String> paramLockList = disDaoList.stream()
|
||||
.map(StIvtIostorinvdis::getStruct_code)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
JSONObject jsonLockParam = new JSONObject();
|
||||
jsonLockParam.put("inv_type", mstDao.getBill_type());
|
||||
jsonLockParam.put("inv_id", mstDao.getIostorinv_id());
|
||||
jsonLockParam.put("inv_code", mstDao.getBill_code());
|
||||
jsonLockParam.put("lock_type", IOSEnum.LOCK_TYPE.code("出库锁"));
|
||||
jsonLockParam.put("operate", IOSEnum.IO_TYPE.code("出库"));
|
||||
|
||||
outBussManageService.lockStruct(paramLockList,jsonLockParam);
|
||||
|
||||
// 插入分配明细
|
||||
iStIvtIostorinvdisService.saveBatch(disDaoList);
|
||||
|
||||
// 更新主表状态
|
||||
updateMstStatus(mstDao.getIostorinv_id());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -402,6 +422,7 @@ public class StIvtIostorinvOutServiceImpl extends ServiceImpl<StIvtIostorinvOutM
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@SneakyThrows
|
||||
public void cancelDiv(JSONObject whereJson) {
|
||||
// 任务表
|
||||
WQLObject taskService = WQLObject.getWQLObject("sch_base_task");
|
||||
@@ -415,156 +436,171 @@ public class StIvtIostorinvOutServiceImpl extends ServiceImpl<StIvtIostorinvOutM
|
||||
* 删除分配明细:查询此明细下的相同木箱的分配明细
|
||||
*/
|
||||
// 判断是什么类型 全部取消-0,自动取消-1,删除分配明细-3
|
||||
List<JSONObject> disList;
|
||||
RLock lock = redissonClient.getLock("all_cancelDivTwo");
|
||||
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||
|
||||
JSONObject jsonDisParam = new JSONObject();
|
||||
jsonDisParam.put("work_status", IOSEnum.WORK_STATUS.code("生成"));
|
||||
jsonDisParam.put("is_issued", IOSEnum.IS_NOTANDYES.code("否"));
|
||||
jsonDisParam.put("iostorinv_id", whereJson.getString("iostorinv_id"));
|
||||
try {
|
||||
if (tryLock) {
|
||||
List<JSONObject> disList;
|
||||
|
||||
// 自动取消
|
||||
if (whereJson.getString("cancel_type").equals(IOSEnum.OUT_CANCEL_TYPE.code("自动取消"))) {
|
||||
// 判断是否有箱号
|
||||
if (ObjectUtil.isEmpty(whereJson.getString("box_no"))) {
|
||||
jsonDisParam.put("iostorinvdtl_id", whereJson.getString("iostorinvdtl_id"));
|
||||
JSONObject jsonDisParam = new JSONObject();
|
||||
jsonDisParam.put("work_status", IOSEnum.WORK_STATUS.code("生成"));
|
||||
jsonDisParam.put("is_issued", IOSEnum.IS_NOTANDYES.code("否"));
|
||||
jsonDisParam.put("iostorinv_id", whereJson.getString("iostorinv_id"));
|
||||
|
||||
// 自动取消
|
||||
if (whereJson.getString("cancel_type").equals(IOSEnum.OUT_CANCEL_TYPE.code("自动取消"))) {
|
||||
// 判断是否有箱号
|
||||
if (ObjectUtil.isEmpty(whereJson.getString("box_no"))) {
|
||||
jsonDisParam.put("iostorinvdtl_id", whereJson.getString("iostorinvdtl_id"));
|
||||
} else {
|
||||
jsonDisParam.put("box_no", whereJson.getString("box_no"));
|
||||
}
|
||||
}
|
||||
|
||||
// 删除分配明细
|
||||
if (whereJson.getString("cancel_type").equals(IOSEnum.OUT_CANCEL_TYPE.code("删除一个"))) {
|
||||
jsonDisParam.put("box_no", whereJson.getString("box_no"));
|
||||
}
|
||||
|
||||
disList = stIvtIostorinvdisMapper.getDivIosDisAll(jsonDisParam);
|
||||
|
||||
if (ObjectUtil.isEmpty(disList)) {
|
||||
throw new BadRequestException("不存在可以取消的出库分配明细");
|
||||
}
|
||||
|
||||
//查询分配明细执行状态大于等于执行中,或任务状态大于等于下发时的记录
|
||||
List<String> dtl_id_in = disList.stream()
|
||||
.map(row -> row.getString("iostorinvdtl_id"))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<JSONObject> disNumList = stIvtIostorinvdisMapper.getDivTaskDis(dtl_id_in);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(disNumList)) {
|
||||
throw new BadRequestException("存在出库明细对应任务下发、执行中或完成,不可取消!");
|
||||
}
|
||||
|
||||
/*删除分配记录*/
|
||||
List<Long> dis_id_in = disList.stream()
|
||||
.map(row -> row.getLongValue("iostorinvdis_id"))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
iStIvtIostorinvdisService.remove(
|
||||
new QueryWrapper<StIvtIostorinvdis>().lambda()
|
||||
.in(StIvtIostorinvdis::getIostorinvdis_id, dis_id_in)
|
||||
);
|
||||
|
||||
/*更新库存*/
|
||||
outBussManageService.upateIvt(disList,mstDao,IOSEnum.IVT_CHANGE.code("减冻结"));
|
||||
|
||||
/*
|
||||
* 更新明细、主单据
|
||||
*/
|
||||
// 明细集合
|
||||
List<StIvtIostorinvdtl> dtlDaoList = iStIvtIostorinvdtlService.list(
|
||||
new QueryWrapper<StIvtIostorinvdtl>().lambda()
|
||||
.eq(StIvtIostorinvdtl::getIostorinv_id, mstDao.getIostorinv_id())
|
||||
);
|
||||
|
||||
// 需要更新的明细集合
|
||||
List<StIvtIostorinvdtl> needUpdateList = new ArrayList<>();
|
||||
|
||||
// 根据明细分组
|
||||
Map<String, List<JSONObject>> disListMap = disList.stream()
|
||||
.collect(Collectors.groupingBy(row -> row.getString("iostorinvdtl_id")));
|
||||
|
||||
for (String iostorinvdtl_id : disListMap.keySet()) {
|
||||
List<JSONObject> disDaoList = disListMap.get(iostorinvdtl_id);
|
||||
|
||||
// 过滤当前明细
|
||||
StIvtIostorinvdtl dtlDao = dtlDaoList.stream()
|
||||
.filter(row -> row.getIostorinvdtl_id().toString().equals(iostorinvdtl_id))
|
||||
.collect(Collectors.toList()).get(0);
|
||||
|
||||
// 需要减掉的数量
|
||||
double sub_qty = disDaoList.stream()
|
||||
.map(row -> row.getBigDecimal("plan_qty"))
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.doubleValue();
|
||||
|
||||
dtlDao.setAssign_qty(NumberUtil.sub(dtlDao.getAssign_qty(), sub_qty));
|
||||
dtlDao.setUnassign_qty(NumberUtil.add(dtlDao.getUnassign_qty(), sub_qty));
|
||||
|
||||
// 已分配数量 > 0 则 = 0
|
||||
if (dtlDao.getAssign_qty().doubleValue() < 0) {
|
||||
dtlDao.setAssign_qty(BigDecimal.valueOf(0));
|
||||
}
|
||||
|
||||
// 未分配数量 > 计划数量 则 = 计划数量
|
||||
if (dtlDao.getUnassign_qty().doubleValue() > dtlDao.getPlan_qty().doubleValue()) {
|
||||
dtlDao.setUnassign_qty(dtlDao.getPlan_qty());
|
||||
}
|
||||
|
||||
// 未分配重量 = 计划重量 则 明细状态为生成 否则 为分配中
|
||||
if (dtlDao.getUnassign_qty().doubleValue() == dtlDao.getPlan_qty().doubleValue()){
|
||||
dtlDao.setBill_status(IOSEnum.BILL_STATUS.code("生成"));
|
||||
} else {
|
||||
dtlDao.setBill_status(IOSEnum.BILL_STATUS.code("分配中"));
|
||||
}
|
||||
|
||||
needUpdateList.add(dtlDao);
|
||||
}
|
||||
|
||||
// 更新明细
|
||||
iStIvtIostorinvdtlService.updateBatchById(needUpdateList);
|
||||
|
||||
// 更新主表
|
||||
this.updateMstStatus(mstDao.getIostorinv_id());
|
||||
|
||||
/*删除出库任务*/
|
||||
String task_id_in = disList.stream()
|
||||
.map(row -> row.getString("task_id"))
|
||||
.distinct()
|
||||
.collect(Collectors.joining("','"));
|
||||
|
||||
|
||||
if (task_id_in.equals("null")) {
|
||||
task_id_in = "";
|
||||
}
|
||||
|
||||
JSONObject taskParam = new JSONObject();
|
||||
taskParam.put("is_delete", IOSEnum.IS_NOTANDYES.code("是"));
|
||||
|
||||
taskService.update(taskParam,"task_id IN ('"+task_id_in+"')");
|
||||
|
||||
/*
|
||||
* 删除移库单、移库任务
|
||||
*/
|
||||
// TODO 调用移库服务处理
|
||||
|
||||
/*
|
||||
* 更新仓位
|
||||
*/
|
||||
// 更新仓位
|
||||
List<String> paramLockList = disList.stream()
|
||||
.map(row -> row.getString("struct_code"))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
JSONObject jsonLockParam = new JSONObject();
|
||||
jsonLockParam.put("inv_type", mstDao.getBill_type());
|
||||
jsonLockParam.put("inv_id", mstDao.getIostorinv_id());
|
||||
jsonLockParam.put("inv_code", mstDao.getBill_code());
|
||||
jsonLockParam.put("lock_type", IOSEnum.LOCK_TYPE.code("未锁定"));
|
||||
jsonLockParam.put("operate", IOSEnum.IO_TYPE.code("出库"));
|
||||
|
||||
outBussManageService.lockStruct(paramLockList,jsonLockParam);
|
||||
} else {
|
||||
jsonDisParam.put("box_no", whereJson.getString("box_no"));
|
||||
throw new BadRequestException("其他出库单当前正在取消分配,请等待几秒再进行操作!");
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// 删除分配明细
|
||||
if (whereJson.getString("cancel_type").equals(IOSEnum.OUT_CANCEL_TYPE.code("删除一个"))) {
|
||||
jsonDisParam.put("box_no", whereJson.getString("box_no"));
|
||||
}
|
||||
|
||||
disList = stIvtIostorinvdisMapper.getDivIosDisAll(jsonDisParam);
|
||||
|
||||
if (ObjectUtil.isEmpty(disList)) {
|
||||
throw new BadRequestException("不存在可以取消的出库分配明细");
|
||||
}
|
||||
|
||||
//查询分配明细执行状态大于等于执行中,或任务状态大于等于下发时的记录
|
||||
List<String> dtl_id_in = disList.stream()
|
||||
.map(row -> row.getString("iostorinvdtl_id"))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<JSONObject> disNumList = stIvtIostorinvdisMapper.getDivTaskDis(dtl_id_in);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(disNumList)) {
|
||||
throw new BadRequestException("存在出库明细对应任务下发、执行中或完成,不可取消!");
|
||||
}
|
||||
|
||||
/*删除分配记录*/
|
||||
List<Long> dis_id_in = disList.stream()
|
||||
.map(row -> row.getLongValue("iostorinvdis_id"))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
iStIvtIostorinvdisService.remove(
|
||||
new QueryWrapper<StIvtIostorinvdis>().lambda()
|
||||
.in(StIvtIostorinvdis::getIostorinvdis_id, dis_id_in)
|
||||
);
|
||||
|
||||
/*更新库存*/
|
||||
outBussManageService.upateIvt(disList,mstDao,IOSEnum.IVT_CHANGE.code("减冻结"));
|
||||
|
||||
/*
|
||||
* 更新明细、主单据
|
||||
*/
|
||||
// 明细集合
|
||||
List<StIvtIostorinvdtl> dtlDaoList = iStIvtIostorinvdtlService.list(
|
||||
new QueryWrapper<StIvtIostorinvdtl>().lambda()
|
||||
.eq(StIvtIostorinvdtl::getIostorinv_id, mstDao.getIostorinv_id())
|
||||
);
|
||||
|
||||
// 需要更新的明细集合
|
||||
List<StIvtIostorinvdtl> needUpdateList = new ArrayList<>();
|
||||
|
||||
// 根据明细分组
|
||||
Map<String, List<JSONObject>> disListMap = disList.stream()
|
||||
.collect(Collectors.groupingBy(row -> row.getString("iostorinvdtl_id")));
|
||||
|
||||
for (String iostorinvdtl_id : disListMap.keySet()) {
|
||||
List<JSONObject> disDaoList = disListMap.get(iostorinvdtl_id);
|
||||
|
||||
// 过滤当前明细
|
||||
StIvtIostorinvdtl dtlDao = dtlDaoList.stream()
|
||||
.filter(row -> row.getIostorinvdtl_id().toString().equals(iostorinvdtl_id))
|
||||
.collect(Collectors.toList()).get(0);
|
||||
|
||||
// 需要减掉的数量
|
||||
double sub_qty = disDaoList.stream()
|
||||
.map(row -> row.getBigDecimal("plan_qty"))
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.doubleValue();
|
||||
|
||||
dtlDao.setAssign_qty(NumberUtil.sub(dtlDao.getAssign_qty(), sub_qty));
|
||||
dtlDao.setUnassign_qty(NumberUtil.add(dtlDao.getUnassign_qty(), sub_qty));
|
||||
|
||||
// 已分配数量 > 0 则 = 0
|
||||
if (dtlDao.getAssign_qty().doubleValue() < 0) {
|
||||
dtlDao.setAssign_qty(BigDecimal.valueOf(0));
|
||||
}
|
||||
|
||||
// 未分配数量 > 计划数量 则 = 计划数量
|
||||
if (dtlDao.getUnassign_qty().doubleValue() > dtlDao.getPlan_qty().doubleValue()) {
|
||||
dtlDao.setUnassign_qty(dtlDao.getPlan_qty());
|
||||
}
|
||||
|
||||
// 未分配重量 = 计划重量 则 明细状态为生成 否则 为分配中
|
||||
if (dtlDao.getUnassign_qty().doubleValue() == dtlDao.getPlan_qty().doubleValue()){
|
||||
dtlDao.setBill_status(IOSEnum.BILL_STATUS.code("生成"));
|
||||
} else {
|
||||
dtlDao.setBill_status(IOSEnum.BILL_STATUS.code("分配中"));
|
||||
}
|
||||
|
||||
needUpdateList.add(dtlDao);
|
||||
}
|
||||
|
||||
// 更新明细
|
||||
iStIvtIostorinvdtlService.updateBatchById(needUpdateList);
|
||||
|
||||
// 更新主表
|
||||
this.updateMstStatus(mstDao.getIostorinv_id());
|
||||
|
||||
/*删除出库任务*/
|
||||
String task_id_in = disList.stream()
|
||||
.map(row -> row.getString("task_id"))
|
||||
.distinct()
|
||||
.collect(Collectors.joining("','"));
|
||||
|
||||
|
||||
if (task_id_in.equals("null")) {
|
||||
task_id_in = "";
|
||||
}
|
||||
|
||||
JSONObject taskParam = new JSONObject();
|
||||
taskParam.put("is_delete", IOSEnum.IS_NOTANDYES.code("是"));
|
||||
|
||||
taskService.update(taskParam,"task_id IN ('"+task_id_in+"')");
|
||||
|
||||
/*
|
||||
* 删除移库单、移库任务
|
||||
*/
|
||||
// TODO 调用移库服务处理
|
||||
|
||||
/*
|
||||
* 更新仓位
|
||||
*/
|
||||
// 更新仓位
|
||||
List<String> paramLockList = disList.stream()
|
||||
.map(row -> row.getString("struct_code"))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
JSONObject jsonLockParam = new JSONObject();
|
||||
jsonLockParam.put("inv_type", mstDao.getBill_type());
|
||||
jsonLockParam.put("inv_id", mstDao.getIostorinv_id());
|
||||
jsonLockParam.put("inv_code", mstDao.getBill_code());
|
||||
jsonLockParam.put("lock_type", IOSEnum.LOCK_TYPE.code("未锁定"));
|
||||
jsonLockParam.put("operate", IOSEnum.IO_TYPE.code("出库"));
|
||||
|
||||
outBussManageService.lockStruct(paramLockList,jsonLockParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -197,6 +197,7 @@ public class ProductScrapServiceImpl implements ProductScrapService {
|
||||
jo_mst.put("update_optid", currentUserId + "");
|
||||
jo_mst.put("update_optname", nickName);
|
||||
jo_mst.put("update_time", now);
|
||||
|
||||
//更新主表
|
||||
wo_mst.update(jo_mst);
|
||||
}
|
||||
@@ -271,7 +272,8 @@ public class ProductScrapServiceImpl implements ProductScrapService {
|
||||
String iostorinv_id = checkOutBillService.insertDtl(jsonOutMst);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("iostorinv_id", iostorinv_id);
|
||||
checkOutBillService.allDiv(jsonObject);
|
||||
// 变更为手动分配
|
||||
// checkOutBillService.allDiv(jsonObject);
|
||||
|
||||
// 更新主表为完成
|
||||
JSONObject param = new JSONObject();
|
||||
|
||||
@@ -287,7 +287,8 @@ public class RecutPlanServiceImpl implements RecutPlanService {
|
||||
JSONObject out_jo = new JSONObject();
|
||||
out_jo.put("iostorinv_id", iostorinv_id);
|
||||
out_jo.put("div_type", "1");
|
||||
iStIvtIostorinvOutService.allDiv(out_jo);
|
||||
// 改为手动分配
|
||||
// iStIvtIostorinvOutService.allDiv(out_jo);
|
||||
} else {
|
||||
jsonMst.put("tableData", dtls);
|
||||
String iostorinv_id = checkOutBillService.insertDtl(jsonMst);
|
||||
@@ -295,7 +296,8 @@ public class RecutPlanServiceImpl implements RecutPlanService {
|
||||
//调用自动分配
|
||||
JSONObject out_jo = new JSONObject();
|
||||
out_jo.put("iostorinv_id", iostorinv_id);
|
||||
checkOutBillService.allDiv(out_jo);
|
||||
// 改为手动分配
|
||||
// checkOutBillService.allDiv(out_jo);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.utils.CodeUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
@@ -39,6 +40,8 @@ import org.nl.wms.st.outbill.util.ThreadManage;
|
||||
import org.nl.wms.st.returns.service.InAndOutReturnService;
|
||||
import org.nl.wms.st.returns.service.impl.InAndOutRetrunServiceImpl;
|
||||
import org.nl.wms.util.TranUtil;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -50,6 +53,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -67,6 +71,7 @@ public class CheckOutBillServiceImpl implements CheckOutBillService {
|
||||
private final OutTask outTask;
|
||||
private final HandMoveStorAcsTask moveStorAcsTask;
|
||||
private final InAndOutReturnService inAndOutReturnService;
|
||||
private final RedissonClient redissonClient;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pageQuery(Map whereJson, Pageable page, String[] stor_id, String[] bill_status, String[] bill_type) {
|
||||
@@ -402,7 +407,7 @@ public class CheckOutBillServiceImpl implements CheckOutBillService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String insertDtl(JSONObject map) {
|
||||
if(MapUtil.getStr(map,"bill_type").equals("1011")) {
|
||||
String iostorinv_id = inserdtlPic(map);
|
||||
String iostorinv_id = inserdtlPic(map);
|
||||
return iostorinv_id ;
|
||||
}
|
||||
|
||||
@@ -1521,6 +1526,7 @@ public class CheckOutBillServiceImpl implements CheckOutBillService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@SneakyThrows
|
||||
public void allDiv(JSONObject whereJson) {
|
||||
//出库分配表
|
||||
WQLObject wo_dis = WQLObject.getWQLObject("ST_IVT_IOStorInvDis");
|
||||
@@ -1531,8 +1537,6 @@ public class CheckOutBillServiceImpl implements CheckOutBillService {
|
||||
//库区表
|
||||
WQLObject wo_sect = WQLObject.getWQLObject("st_ivt_sectattr");
|
||||
|
||||
//定义需要更新的仓位集合
|
||||
HashMap<String, JSONObject> Struct_map = new HashMap<String, JSONObject>();
|
||||
String iostorinv_id = whereJson.getString("iostorinv_id");
|
||||
//查询主表信息
|
||||
JSONObject jo_mst = wo_mst.query("iostorinv_id = '" + iostorinv_id + "'").uniqueResult(0);
|
||||
@@ -1568,219 +1572,234 @@ public class CheckOutBillServiceImpl implements CheckOutBillService {
|
||||
throw new BadRequestException("当前订单无可分配出库明细");
|
||||
}
|
||||
|
||||
for (int i = 0; i < dtls.size(); i++) {
|
||||
JSONObject dtl = dtls.getJSONObject(i);
|
||||
double unassign_qty = dtl.getDoubleValue("unassign_qty");
|
||||
double plan_qty = dtl.getDoubleValue("plan_qty");
|
||||
/*
|
||||
* 分配规则:
|
||||
* top1.有销售订单号:用销售订单号、物料去找这批物料最早入库的所在的巷道
|
||||
* top2.没有销售订单号,有子卷号:固定出某个木箱
|
||||
* top3.没有销售订单号,没有子卷号:找此物料最早入库的所在巷道
|
||||
*/
|
||||
boolean is_top3 = false;
|
||||
if (ObjectUtil.isEmpty(dtl.getString("source_bill_code")) && ObjectUtil.isEmpty(dtl.getString("pcsn"))) {
|
||||
is_top3 = true;
|
||||
}
|
||||
JSONObject jsonMap = new JSONObject();
|
||||
// 已分配重量
|
||||
double assign_qty = dtl.getDoubleValue("assign_qty");
|
||||
RLock lock = redissonClient.getLock("all_divOne");
|
||||
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(dtl.getString("source_bill_code")) || is_top3) {
|
||||
while (unassign_qty > 0) {
|
||||
// 1.有销售订单号
|
||||
jsonMap.put("flag", "1");
|
||||
jsonMap.put("material_id", dtl.getString("material_id"));
|
||||
jsonMap.put("sale_order_name", dtl.getString("source_bill_code"));
|
||||
jsonMap.put("sect_id", whereJson.getString("sect_id"));
|
||||
jsonMap.put("stor_id", whereJson.getString("stor_id"));
|
||||
|
||||
JSONObject jsonOneIvt = WQL.getWO("ST_OUTIVT01").addParamMap(jsonMap).process().uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(jsonOneIvt)) {
|
||||
throw new BadRequestException("库存不足");
|
||||
try {
|
||||
if (tryLock) {
|
||||
//定义需要更新的仓位集合
|
||||
HashMap<String, JSONObject> Struct_map = new HashMap<String, JSONObject>();
|
||||
for (int i = 0; i < dtls.size(); i++) {
|
||||
JSONObject dtl = dtls.getJSONObject(i);
|
||||
double unassign_qty = dtl.getDoubleValue("unassign_qty");
|
||||
double plan_qty = dtl.getDoubleValue("plan_qty");
|
||||
/*
|
||||
* 分配规则:
|
||||
* top1.有销售订单号:用销售订单号、物料去找这批物料最早入库的所在的巷道
|
||||
* top2.没有销售订单号,有子卷号:固定出某个木箱
|
||||
* top3.没有销售订单号,没有子卷号:找此物料最早入库的所在巷道
|
||||
*/
|
||||
boolean is_top3 = false;
|
||||
if (ObjectUtil.isEmpty(dtl.getString("source_bill_code")) && ObjectUtil.isEmpty(dtl.getString("pcsn"))) {
|
||||
is_top3 = true;
|
||||
}
|
||||
JSONObject jsonMap = new JSONObject();
|
||||
// 已分配重量
|
||||
double assign_qty = dtl.getDoubleValue("assign_qty");
|
||||
|
||||
// 查询这一巷道所有此物料此库存此销售订单的库存
|
||||
jsonMap.put("flag", "2");
|
||||
jsonMap.put("row_num", jsonOneIvt.getString("row_num"));
|
||||
jsonMap.put("block_num", jsonOneIvt.getString("block_num"));
|
||||
JSONArray ivtAllArr = WQL.getWO("ST_OUTIVT01").addParamMap(jsonMap).process().getResultJSONArray(0);
|
||||
if (ObjectUtil.isNotEmpty(dtl.getString("source_bill_code")) || is_top3) {
|
||||
while (unassign_qty > 0) {
|
||||
// 1.有销售订单号
|
||||
jsonMap.put("flag", "1");
|
||||
jsonMap.put("material_id", dtl.getString("material_id"));
|
||||
jsonMap.put("sale_order_name", dtl.getString("source_bill_code"));
|
||||
jsonMap.put("sect_id", whereJson.getString("sect_id"));
|
||||
jsonMap.put("stor_id", whereJson.getString("stor_id"));
|
||||
|
||||
for (int j = 0; j < ivtAllArr.size(); j++) {
|
||||
JSONObject ivt = ivtAllArr.getJSONObject(j);
|
||||
double canuse_qty = ivt.getDoubleValue("canuse_qty");
|
||||
assign_qty = NumberUtil.add(assign_qty, canuse_qty);
|
||||
|
||||
if (unassign_qty >= canuse_qty) {
|
||||
unassign_qty = NumberUtil.sub(unassign_qty, canuse_qty);
|
||||
} else {
|
||||
unassign_qty = 0;
|
||||
}
|
||||
|
||||
// 查询此木箱下的所有子卷
|
||||
jsonMap.put("flag", "3");
|
||||
jsonMap.put("storagevehicle_code", ivt.getString("storagevehicle_code"));
|
||||
JSONArray ivtAllArr2 = WQL.getWO("ST_OUTIVT01").addParamMap(jsonMap).process().getResultJSONArray(0);
|
||||
|
||||
for (int k = 0; k < ivtAllArr2.size(); k++) {
|
||||
// 更新库存
|
||||
JSONObject ivt2 = ivtAllArr2.getJSONObject(k);
|
||||
ivt2.put("change_qty", ivt2.getDoubleValue("canuse_qty"));
|
||||
ivt2.put("bill_type_scode", jo_mst.getString("bill_type"));
|
||||
ivt2.put("inv_id", dtl.getString("iostorinv_id"));
|
||||
ivt2.put("bill_code", jo_mst.getString("bill_code"));
|
||||
ivt2.put("bill_table", "ST_IVT_IOStorInv");
|
||||
storPublicService.IOStor(ivt2, "11");
|
||||
|
||||
//生成分配明细
|
||||
dtl.put("iostorinvdis_id", IdUtil.getSnowflake(1, 1).nextId());
|
||||
dtl.put("sect_id", ivt2.getString("sect_id"));
|
||||
dtl.put("sect_code", ivt2.getString("sect_code"));
|
||||
dtl.put("sect_name", ivt2.getString("sect_name"));
|
||||
dtl.put("struct_id", ivt2.getString("struct_id"));
|
||||
dtl.put("struct_code", ivt2.getString("struct_code"));
|
||||
dtl.put("struct_name", ivt2.getString("struct_name"));
|
||||
dtl.put("pcsn", ivt2.getString("pcsn"));
|
||||
dtl.put("box_no", ivt2.getString("storagevehicle_code"));
|
||||
dtl.put("storagevehicle_id", ivt2.getString("storagevehicle_id"));
|
||||
dtl.put("storagevehicle_code", ivt2.getString("storagevehicle_code"));
|
||||
dtl.put("storagevehicle_type", ivt2.getString("storagevehicle_type"));
|
||||
dtl.put("is_issued", "0");
|
||||
dtl.put("plan_qty", ivt2.getDoubleValue("change_qty"));
|
||||
dtl.put("real_qty", ivt2.getDoubleValue("change_qty"));
|
||||
dtl.put("is_overdue", ivt2.getString("is_overdue"));
|
||||
dtl.put("instorage_time", ivt2.getString("instorage_time"));
|
||||
|
||||
// 如果所属仓位是虚拟区 则将分配明细状态变为生成
|
||||
JSONObject jsonSect = wo_sect.query("sect_id = '" + ivt2.getString("sect_id") + "'").uniqueResult(0);
|
||||
if (StrUtil.equals(jsonSect.getString("sect_type_attr"), "09")) {
|
||||
dtl.put("work_status", "01");
|
||||
} else {
|
||||
dtl.put("work_status", "00");
|
||||
JSONObject jsonOneIvt = WQL.getWO("ST_OUTIVT01").addParamMap(jsonMap).process().uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(jsonOneIvt)) {
|
||||
throw new BadRequestException("库存不足");
|
||||
}
|
||||
|
||||
if (jo_mst.getString("is_overdue").equals("1")) {
|
||||
// 判断是否超期
|
||||
if (ivt2.getString("is_overdue").equals("1")) {
|
||||
dtl.put("work_status", "01");
|
||||
// 查询这一巷道所有此物料此库存此销售订单的库存
|
||||
jsonMap.put("flag", "2");
|
||||
jsonMap.put("row_num", jsonOneIvt.getString("row_num"));
|
||||
jsonMap.put("block_num", jsonOneIvt.getString("block_num"));
|
||||
JSONArray ivtAllArr = WQL.getWO("ST_OUTIVT01").addParamMap(jsonMap).process().getResultJSONArray(0);
|
||||
|
||||
for (int j = 0; j < ivtAllArr.size(); j++) {
|
||||
JSONObject ivt = ivtAllArr.getJSONObject(j);
|
||||
double canuse_qty = ivt.getDoubleValue("canuse_qty");
|
||||
assign_qty = NumberUtil.add(assign_qty, canuse_qty);
|
||||
|
||||
if (unassign_qty >= canuse_qty) {
|
||||
unassign_qty = NumberUtil.sub(unassign_qty, canuse_qty);
|
||||
} else {
|
||||
unassign_qty = 0;
|
||||
}
|
||||
|
||||
// 查询此木箱下的所有子卷
|
||||
jsonMap.put("flag", "3");
|
||||
jsonMap.put("storagevehicle_code", ivt.getString("storagevehicle_code"));
|
||||
JSONArray ivtAllArr2 = WQL.getWO("ST_OUTIVT01").addParamMap(jsonMap).process().getResultJSONArray(0);
|
||||
|
||||
for (int k = 0; k < ivtAllArr2.size(); k++) {
|
||||
// 更新库存
|
||||
JSONObject ivt2 = ivtAllArr2.getJSONObject(k);
|
||||
ivt2.put("change_qty", ivt2.getDoubleValue("canuse_qty"));
|
||||
ivt2.put("bill_type_scode", jo_mst.getString("bill_type"));
|
||||
ivt2.put("inv_id", dtl.getString("iostorinv_id"));
|
||||
ivt2.put("bill_code", jo_mst.getString("bill_code"));
|
||||
ivt2.put("bill_table", "ST_IVT_IOStorInv");
|
||||
storPublicService.IOStor(ivt2, "11");
|
||||
|
||||
//生成分配明细
|
||||
dtl.put("iostorinvdis_id", IdUtil.getSnowflake(1, 1).nextId());
|
||||
dtl.put("sect_id", ivt2.getString("sect_id"));
|
||||
dtl.put("sect_code", ivt2.getString("sect_code"));
|
||||
dtl.put("sect_name", ivt2.getString("sect_name"));
|
||||
dtl.put("struct_id", ivt2.getString("struct_id"));
|
||||
dtl.put("struct_code", ivt2.getString("struct_code"));
|
||||
dtl.put("struct_name", ivt2.getString("struct_name"));
|
||||
dtl.put("pcsn", ivt2.getString("pcsn"));
|
||||
dtl.put("box_no", ivt2.getString("storagevehicle_code"));
|
||||
dtl.put("storagevehicle_id", ivt2.getString("storagevehicle_id"));
|
||||
dtl.put("storagevehicle_code", ivt2.getString("storagevehicle_code"));
|
||||
dtl.put("storagevehicle_type", ivt2.getString("storagevehicle_type"));
|
||||
dtl.put("is_issued", "0");
|
||||
dtl.put("plan_qty", ivt2.getDoubleValue("change_qty"));
|
||||
dtl.put("real_qty", ivt2.getDoubleValue("change_qty"));
|
||||
dtl.put("is_overdue", ivt2.getString("is_overdue"));
|
||||
dtl.put("instorage_time", ivt2.getString("instorage_time"));
|
||||
|
||||
// 如果所属仓位是虚拟区 则将分配明细状态变为生成
|
||||
JSONObject jsonSect = wo_sect.query("sect_id = '" + ivt2.getString("sect_id") + "'").uniqueResult(0);
|
||||
if (StrUtil.equals(jsonSect.getString("sect_type_attr"), "09")) {
|
||||
dtl.put("work_status", "01");
|
||||
} else {
|
||||
dtl.put("work_status", "00");
|
||||
}
|
||||
|
||||
if (jo_mst.getString("is_overdue").equals("1")) {
|
||||
// 判断是否超期
|
||||
if (ivt2.getString("is_overdue").equals("1")) {
|
||||
dtl.put("work_status", "01");
|
||||
}
|
||||
}
|
||||
wo_dis.insert(dtl);
|
||||
}
|
||||
//记录需锁定的仓位
|
||||
Struct_map.put(ivt.getString("struct_id"), ivt);
|
||||
// 为零结束
|
||||
if (unassign_qty == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
wo_dis.insert(dtl);
|
||||
}
|
||||
//记录需锁定的仓位
|
||||
Struct_map.put(ivt.getString("struct_id"), ivt);
|
||||
// 为零结束
|
||||
if (unassign_qty == 0) {
|
||||
break;
|
||||
|
||||
} else {
|
||||
// 确定子卷: 根据子卷找到库存出掉
|
||||
jsonMap.put("flag", "1");
|
||||
jsonMap.put("material_id", dtl.getString("material_id"));
|
||||
jsonMap.put("pcsn", dtl.getString("pcsn"));
|
||||
jsonMap.put("box_no", dtl.getString("box_no"));
|
||||
jsonMap.put("sect_id", whereJson.getString("sect_id"));
|
||||
jsonMap.put("stor_id", whereJson.getString("stor_id"));
|
||||
|
||||
JSONObject jsonIvt = WQL.getWO("ST_OUTIVT01").addParamMap(jsonMap).process().uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(jsonIvt)) {
|
||||
throw new BadRequestException("库存不足");
|
||||
}
|
||||
|
||||
double canuse_qty ;
|
||||
if (StrUtil.equals(bill_type, "1011")) {
|
||||
canuse_qty = dtl.getDoubleValue("plan_qty");
|
||||
} else {
|
||||
canuse_qty = jsonIvt.getDoubleValue("canuse_qty");
|
||||
}
|
||||
|
||||
jsonIvt.put("change_qty", canuse_qty + "");
|
||||
unassign_qty = 0;
|
||||
assign_qty = NumberUtil.add(assign_qty, canuse_qty);
|
||||
|
||||
//更新库存
|
||||
jsonIvt.put("bill_type_scode", jo_mst.getString("bill_type"));
|
||||
jsonIvt.put("inv_id", dtl.getString("iostorinv_id"));
|
||||
jsonIvt.put("bill_code", jo_mst.getString("bill_code"));
|
||||
jsonIvt.put("bill_table", "ST_IVT_IOStorInv");
|
||||
storPublicService.IOStor(jsonIvt, "11");
|
||||
//生成分配明细
|
||||
dtl.put("iostorinvdis_id", IdUtil.getSnowflake(1, 1).nextId());
|
||||
dtl.put("sect_id", jsonIvt.getString("sect_id"));
|
||||
dtl.put("sect_code", jsonIvt.getString("sect_code"));
|
||||
dtl.put("sect_name", jsonIvt.getString("sect_name"));
|
||||
dtl.put("struct_id", jsonIvt.getString("struct_id"));
|
||||
dtl.put("struct_code", jsonIvt.getString("struct_code"));
|
||||
dtl.put("struct_name", jsonIvt.getString("struct_name"));
|
||||
dtl.put("pcsn", jsonIvt.getString("pcsn"));
|
||||
dtl.put("box_no", jsonIvt.getString("storagevehicle_code"));
|
||||
dtl.put("storagevehicle_id", jsonIvt.getString("storagevehicle_id"));
|
||||
dtl.put("storagevehicle_code", jsonIvt.getString("storagevehicle_code"));
|
||||
dtl.put("storagevehicle_type", jsonIvt.getString("storagevehicle_type"));
|
||||
dtl.put("is_issued", "0");
|
||||
dtl.put("plan_qty", jsonIvt.getDoubleValue("change_qty"));
|
||||
dtl.put("real_qty", jsonIvt.getDoubleValue("change_qty"));
|
||||
dtl.put("is_overdue", jsonIvt.getString("is_overdue"));
|
||||
dtl.put("instorage_time", jsonIvt.getString("instorage_time"));
|
||||
// 如果所属仓位是虚拟区 则将分配明细状态变为生成
|
||||
JSONObject jsonSect = wo_sect.query("sect_id = '" + jsonIvt.getString("sect_id") + "'").uniqueResult(0);
|
||||
if (StrUtil.equals(jsonSect.getString("sect_type_attr"), "09")) {
|
||||
dtl.put("work_status", "01");
|
||||
} else {
|
||||
dtl.put("work_status", "00");
|
||||
}
|
||||
|
||||
// 判断是否超期
|
||||
if (jo_mst.getString("is_overdue").equals("1")) {
|
||||
if (jsonIvt.getString("is_overdue").equals("1")) {
|
||||
dtl.put("work_status", "01");
|
||||
}
|
||||
}
|
||||
|
||||
wo_dis.insert(dtl);
|
||||
|
||||
//记录需锁定的仓位 (如果此明细有相同物料的且子卷号不能为空的则在最后一个明细分配完成后锁定仓位)
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("flag", "5");
|
||||
map.put("material_id", dtl.getString("material_id"));
|
||||
map.put("box_no", dtl.getString("box_no"));
|
||||
map.put("iostorinv_id", iostorinv_id);
|
||||
map.put("iostorinvdtl_id", dtl.getString("iostorinvdtl_id"));
|
||||
JSONArray dtlArr = WQL.getWO("ST_OUTIVT01").addParamMap(map).process().getResultJSONArray(0);
|
||||
if (dtlArr.size() == 0) {
|
||||
Struct_map.put(jsonIvt.getString("struct_id"), jsonIvt);
|
||||
}
|
||||
|
||||
}
|
||||
HashMap<String, String> map_dtl = new HashMap<String, String>();
|
||||
//更新明细
|
||||
map_dtl.put("unassign_qty", unassign_qty + "");
|
||||
map_dtl.put("assign_qty", assign_qty + "");
|
||||
if (unassign_qty == 0) {
|
||||
map_dtl.put("bill_status", "40");
|
||||
} else {
|
||||
map_dtl.put("bill_status", "30");
|
||||
}
|
||||
wo_dtl.update(map_dtl, "iostorinvdtl_id='" + dtl.getString("iostorinvdtl_id") + "'");
|
||||
|
||||
//更新主表状态
|
||||
this.updateMststatus(iostorinv_id);
|
||||
|
||||
//锁定起点点位、仓位
|
||||
Collection<JSONObject> c = Struct_map.values();
|
||||
Iterator<JSONObject> it = c.iterator();
|
||||
JSONObject from_start = new JSONObject();
|
||||
from_start.put("lock_type", "3");
|
||||
for (; it.hasNext(); ) {
|
||||
JSONObject Struct = it.next();
|
||||
from_start.put("struct_id", Struct.getString("struct_id"));
|
||||
from_start.put("inv_type", jo_mst.getString("bill_type"));
|
||||
from_start.put("inv_id", jo_mst.getString("iostorinv_id"));
|
||||
from_start.put("inv_code", jo_mst.getString("bill_code"));
|
||||
storPublicService.updateStructAndPoint(from_start);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 确定子卷: 根据子卷找到库存出掉
|
||||
jsonMap.put("flag", "1");
|
||||
jsonMap.put("material_id", dtl.getString("material_id"));
|
||||
jsonMap.put("pcsn", dtl.getString("pcsn"));
|
||||
jsonMap.put("box_no", dtl.getString("box_no"));
|
||||
jsonMap.put("sect_id", whereJson.getString("sect_id"));
|
||||
jsonMap.put("stor_id", whereJson.getString("stor_id"));
|
||||
|
||||
JSONObject jsonIvt = WQL.getWO("ST_OUTIVT01").addParamMap(jsonMap).process().uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(jsonIvt)) {
|
||||
throw new BadRequestException("库存不足");
|
||||
}
|
||||
|
||||
double canuse_qty ;
|
||||
if (StrUtil.equals(bill_type, "1011")) {
|
||||
canuse_qty = dtl.getDoubleValue("plan_qty");
|
||||
} else {
|
||||
canuse_qty = jsonIvt.getDoubleValue("canuse_qty");
|
||||
}
|
||||
|
||||
jsonIvt.put("change_qty", canuse_qty + "");
|
||||
unassign_qty = 0;
|
||||
assign_qty = NumberUtil.add(assign_qty, canuse_qty);
|
||||
|
||||
//更新库存
|
||||
jsonIvt.put("bill_type_scode", jo_mst.getString("bill_type"));
|
||||
jsonIvt.put("inv_id", dtl.getString("iostorinv_id"));
|
||||
jsonIvt.put("bill_code", jo_mst.getString("bill_code"));
|
||||
jsonIvt.put("bill_table", "ST_IVT_IOStorInv");
|
||||
storPublicService.IOStor(jsonIvt, "11");
|
||||
//生成分配明细
|
||||
dtl.put("iostorinvdis_id", IdUtil.getSnowflake(1, 1).nextId());
|
||||
dtl.put("sect_id", jsonIvt.getString("sect_id"));
|
||||
dtl.put("sect_code", jsonIvt.getString("sect_code"));
|
||||
dtl.put("sect_name", jsonIvt.getString("sect_name"));
|
||||
dtl.put("struct_id", jsonIvt.getString("struct_id"));
|
||||
dtl.put("struct_code", jsonIvt.getString("struct_code"));
|
||||
dtl.put("struct_name", jsonIvt.getString("struct_name"));
|
||||
dtl.put("pcsn", jsonIvt.getString("pcsn"));
|
||||
dtl.put("box_no", jsonIvt.getString("storagevehicle_code"));
|
||||
dtl.put("storagevehicle_id", jsonIvt.getString("storagevehicle_id"));
|
||||
dtl.put("storagevehicle_code", jsonIvt.getString("storagevehicle_code"));
|
||||
dtl.put("storagevehicle_type", jsonIvt.getString("storagevehicle_type"));
|
||||
dtl.put("is_issued", "0");
|
||||
dtl.put("plan_qty", jsonIvt.getDoubleValue("change_qty"));
|
||||
dtl.put("real_qty", jsonIvt.getDoubleValue("change_qty"));
|
||||
dtl.put("is_overdue", jsonIvt.getString("is_overdue"));
|
||||
dtl.put("instorage_time", jsonIvt.getString("instorage_time"));
|
||||
// 如果所属仓位是虚拟区 则将分配明细状态变为生成
|
||||
JSONObject jsonSect = wo_sect.query("sect_id = '" + jsonIvt.getString("sect_id") + "'").uniqueResult(0);
|
||||
if (StrUtil.equals(jsonSect.getString("sect_type_attr"), "09")) {
|
||||
dtl.put("work_status", "01");
|
||||
} else {
|
||||
dtl.put("work_status", "00");
|
||||
}
|
||||
|
||||
// 判断是否超期
|
||||
if (jo_mst.getString("is_overdue").equals("1")) {
|
||||
if (jsonIvt.getString("is_overdue").equals("1")) {
|
||||
dtl.put("work_status", "01");
|
||||
}
|
||||
}
|
||||
|
||||
wo_dis.insert(dtl);
|
||||
|
||||
//记录需锁定的仓位 (如果此明细有相同物料的且子卷号不能为空的则在最后一个明细分配完成后锁定仓位)
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("flag", "5");
|
||||
map.put("material_id", dtl.getString("material_id"));
|
||||
map.put("box_no", dtl.getString("box_no"));
|
||||
map.put("iostorinv_id", iostorinv_id);
|
||||
map.put("iostorinvdtl_id", dtl.getString("iostorinvdtl_id"));
|
||||
JSONArray dtlArr = WQL.getWO("ST_OUTIVT01").addParamMap(map).process().getResultJSONArray(0);
|
||||
if (dtlArr.size() == 0) {
|
||||
Struct_map.put(jsonIvt.getString("struct_id"), jsonIvt);
|
||||
}
|
||||
|
||||
throw new BadRequestException("其他出库单当前正在分配货位,请等待几秒再进行操作!");
|
||||
}
|
||||
HashMap<String, String> map_dtl = new HashMap<String, String>();
|
||||
//更新明细
|
||||
map_dtl.put("unassign_qty", unassign_qty + "");
|
||||
map_dtl.put("assign_qty", assign_qty + "");
|
||||
if (unassign_qty == 0) {
|
||||
map_dtl.put("bill_status", "40");
|
||||
} else {
|
||||
map_dtl.put("bill_status", "30");
|
||||
}
|
||||
wo_dtl.update(map_dtl, "iostorinvdtl_id='" + dtl.getString("iostorinvdtl_id") + "'");
|
||||
|
||||
//更新主表状态
|
||||
this.updateMststatus(iostorinv_id);
|
||||
|
||||
//锁定起点点位、仓位
|
||||
Collection<JSONObject> c = Struct_map.values();
|
||||
Iterator<JSONObject> it = c.iterator();
|
||||
JSONObject from_start = new JSONObject();
|
||||
from_start.put("lock_type", "3");
|
||||
for (; it.hasNext(); ) {
|
||||
JSONObject Struct = it.next();
|
||||
from_start.put("struct_id", Struct.getString("struct_id"));
|
||||
from_start.put("inv_type", jo_mst.getString("bill_type"));
|
||||
from_start.put("inv_id", jo_mst.getString("iostorinv_id"));
|
||||
from_start.put("inv_code", jo_mst.getString("bill_code"));
|
||||
storPublicService.updateStructAndPoint(from_start);
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2384,6 +2403,7 @@ public class CheckOutBillServiceImpl implements CheckOutBillService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@SneakyThrows
|
||||
public void allCancel(JSONObject whereJson) {
|
||||
//出库分配表
|
||||
WQLObject wo_dis = WQLObject.getWQLObject("ST_IVT_IOStorInvDis");
|
||||
@@ -2415,112 +2435,127 @@ public class CheckOutBillServiceImpl implements CheckOutBillService {
|
||||
if (ObjectUtil.isEmpty(diss)) {
|
||||
throw new BadRequestException("不存在可以取消的出库分配明细");
|
||||
}
|
||||
for (int i = 0; i < diss.size(); i++) {
|
||||
JSONObject dis = diss.getJSONObject(i);
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
String iostorinvdtl_id = dis.getString("iostorinvdtl_id");
|
||||
//统计【出入库单分配表】执行状态大于等于执行中,或【任务指令表】任务状态大于等于下发时的记录和
|
||||
JSONArray dtl = WQL.getWO("QST_IVT_CHECKOUTBILL")
|
||||
.addParam("flag", "4")
|
||||
.addParam("iostorinvdtl_id", iostorinvdtl_id)
|
||||
.process()
|
||||
.getResultJSONArray(0);
|
||||
//若存在记录,则不可取消该出库明细对应的任何分配记录
|
||||
if (dtl.size() != 0) {
|
||||
throw new BadRequestException("存在出库明细对应任务下发、执行中或完成!");
|
||||
}
|
||||
double plan_qty = dis.getDoubleValue("plan_qty");
|
||||
//更新库存
|
||||
dis.put("change_qty", plan_qty + "");
|
||||
dis.put("bill_type_scode", jo_mst.getString("bill_type"));
|
||||
dis.put("inv_id", iostorinv_id);
|
||||
dis.put("bill_code", jo_mst.getString("bill_code"));
|
||||
dis.put("bill_table", "ST_IVT_IOStorInv");
|
||||
storPublicService.IOStor(dis, "12");
|
||||
//删除【出入库单分配表】中分配记录
|
||||
wo_dis.delete("iostorinvdis_id='" + dis.getString("iostorinvdis_id") + "'");
|
||||
//更新【出入库单明细表】中分配记录
|
||||
JSONObject jo_dtl = wo_dtl.query("iostorinvdtl_id = '" + iostorinvdtl_id + "'").uniqueResult(0);
|
||||
RLock lock = redissonClient.getLock("all_cancelDivOne");
|
||||
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||
|
||||
try {
|
||||
if (tryLock) {
|
||||
for (int i = 0; i < diss.size(); i++) {
|
||||
JSONObject dis = diss.getJSONObject(i);
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
String iostorinvdtl_id = dis.getString("iostorinvdtl_id");
|
||||
//统计【出入库单分配表】执行状态大于等于执行中,或【任务指令表】任务状态大于等于下发时的记录和
|
||||
JSONArray dtl = WQL.getWO("QST_IVT_CHECKOUTBILL")
|
||||
.addParam("flag", "4")
|
||||
.addParam("iostorinvdtl_id", iostorinvdtl_id)
|
||||
.process()
|
||||
.getResultJSONArray(0);
|
||||
//若存在记录,则不可取消该出库明细对应的任何分配记录
|
||||
if (dtl.size() != 0) {
|
||||
throw new BadRequestException("存在出库明细对应任务下发、执行中或完成!");
|
||||
}
|
||||
double plan_qty = dis.getDoubleValue("plan_qty");
|
||||
//更新库存
|
||||
dis.put("change_qty", plan_qty + "");
|
||||
dis.put("bill_type_scode", jo_mst.getString("bill_type"));
|
||||
dis.put("inv_id", iostorinv_id);
|
||||
dis.put("bill_code", jo_mst.getString("bill_code"));
|
||||
dis.put("bill_table", "ST_IVT_IOStorInv");
|
||||
storPublicService.IOStor(dis, "12");
|
||||
//删除【出入库单分配表】中分配记录
|
||||
wo_dis.delete("iostorinvdis_id='" + dis.getString("iostorinvdis_id") + "'");
|
||||
//更新【出入库单明细表】中分配记录
|
||||
JSONObject jo_dtl = wo_dtl.query("iostorinvdtl_id = '" + iostorinvdtl_id + "'").uniqueResult(0);
|
||||
|
||||
|
||||
jo_dtl.put("assign_qty", NumberUtil.sub(jo_dtl.getDoubleValue("assign_qty"), plan_qty));
|
||||
jo_dtl.put("unassign_qty", NumberUtil.sub(jo_dtl.getDoubleValue("plan_qty"), jo_dtl.getDoubleValue("assign_qty")));
|
||||
jo_dtl.put("assign_qty", NumberUtil.sub(jo_dtl.getDoubleValue("assign_qty"), plan_qty));
|
||||
jo_dtl.put("unassign_qty", NumberUtil.sub(jo_dtl.getDoubleValue("plan_qty"), jo_dtl.getDoubleValue("assign_qty")));
|
||||
|
||||
if (jo_dtl.getDoubleValue("assign_qty") < 0) {
|
||||
jo_dtl.put("assign_qty", 0);
|
||||
}
|
||||
if (jo_dtl.getDoubleValue("assign_qty") < 0) {
|
||||
jo_dtl.put("assign_qty", 0);
|
||||
}
|
||||
|
||||
if (jo_dtl.getDoubleValue("unassign_qty") > jo_dtl.getDoubleValue("plan_qty")) {
|
||||
jo_dtl.put("unassign_qty", jo_dtl.getDoubleValue("plan_qty"));
|
||||
}
|
||||
if (jo_dtl.getDoubleValue("unassign_qty") > jo_dtl.getDoubleValue("plan_qty")) {
|
||||
jo_dtl.put("unassign_qty", jo_dtl.getDoubleValue("plan_qty"));
|
||||
}
|
||||
|
||||
if (jo_dtl.getDoubleValue("unassign_qty") == jo_dtl.getDoubleValue("plan_qty")) {
|
||||
jo_dtl.put("bill_status", "10");
|
||||
} else {
|
||||
jo_dtl.put("bill_status", "30");
|
||||
}
|
||||
wo_dtl.update(jo_dtl);
|
||||
//更新主表状态
|
||||
this.updateMststatus(iostorinv_id);
|
||||
//判断是否存在同单据的同起点仓位的分配
|
||||
JSONArray flag = WQL.getWO("QST_IVT_CHECKOUTBILL")
|
||||
.addParam("flag", "5")
|
||||
.addParam("is_issued", "0")
|
||||
.addParam("struct_id", dis.getString("struct_id"))
|
||||
.addParam("iostorinv_id", iostorinv_id)
|
||||
.addParam("bill_status", "01")
|
||||
.process()
|
||||
.getResultJSONArray(0);
|
||||
if (flag.size() == 0) {//仓位载具冻结数为0
|
||||
//任务号不为空
|
||||
if (ObjectUtil.isNotEmpty(dis.getString("task_id"))) {
|
||||
// 判断是否有移库的任务:有就取消掉
|
||||
JSONObject jsonTask = wo_Task.query("task_id = '" + dis.getString("task_id") + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(jsonTask)) {
|
||||
JSONArray moveArrTask = wo_Task.query("task_group_id = '" + jsonTask.getString("task_group_id") + "' and task_type = '010505'").getResultJSONArray(0);
|
||||
if (jo_dtl.getDoubleValue("unassign_qty") == jo_dtl.getDoubleValue("plan_qty")) {
|
||||
jo_dtl.put("bill_status", "10");
|
||||
} else {
|
||||
jo_dtl.put("bill_status", "30");
|
||||
}
|
||||
wo_dtl.update(jo_dtl);
|
||||
//更新主表状态
|
||||
this.updateMststatus(iostorinv_id);
|
||||
//判断是否存在同单据的同起点仓位的分配
|
||||
JSONArray flag = WQL.getWO("QST_IVT_CHECKOUTBILL")
|
||||
.addParam("flag", "5")
|
||||
.addParam("is_issued", "0")
|
||||
.addParam("struct_id", dis.getString("struct_id"))
|
||||
.addParam("iostorinv_id", iostorinv_id)
|
||||
.addParam("bill_status", "01")
|
||||
.process()
|
||||
.getResultJSONArray(0);
|
||||
if (flag.size() == 0) {//仓位载具冻结数为0
|
||||
//任务号不为空
|
||||
if (ObjectUtil.isNotEmpty(dis.getString("task_id"))) {
|
||||
// 判断是否有移库的任务:有就取消掉
|
||||
JSONObject jsonTask = wo_Task.query("task_id = '" + dis.getString("task_id") + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(jsonTask)) {
|
||||
JSONArray moveArrTask = wo_Task.query("task_group_id = '" + jsonTask.getString("task_group_id") + "' and task_type = '010505'").getResultJSONArray(0);
|
||||
|
||||
for (int j = 0; j < moveArrTask.size(); j++) {
|
||||
JSONObject jsonMoveTask = moveArrTask.getJSONObject(j);
|
||||
// 调用删除移库单
|
||||
JSONObject jsonMoveDtl = move_dtl.query("task_id = '" + jsonMoveTask.getString("task_id") + "'").uniqueResult(0);
|
||||
for (int j = 0; j < moveArrTask.size(); j++) {
|
||||
JSONObject jsonMoveTask = moveArrTask.getJSONObject(j);
|
||||
// 调用删除移库单
|
||||
JSONObject jsonMoveDtl = move_dtl.query("task_id = '" + jsonMoveTask.getString("task_id") + "'").uniqueResult(0);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(jsonMoveDtl)) {
|
||||
JSONObject jsonMoveMst = move_mst.query("moveinv_id = '" + jsonMoveDtl.getString("moveinv_id") + "' and is_delete = '0'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(jsonMoveDtl)) {
|
||||
JSONObject jsonMoveMst = move_mst.query("moveinv_id = '" + jsonMoveDtl.getString("moveinv_id") + "' and is_delete = '0'").uniqueResult(0);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(jsonMoveMst)) {
|
||||
HandMoveStorServiceImpl bean = SpringContextHolder.getBean(HandMoveStorServiceImpl.class);
|
||||
bean.deleteById(jsonMoveMst.getString("moveinv_id"));
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(jsonMoveMst)) {
|
||||
HandMoveStorServiceImpl bean = SpringContextHolder.getBean(HandMoveStorServiceImpl.class);
|
||||
bean.deleteById(jsonMoveMst.getString("moveinv_id"));
|
||||
}
|
||||
}
|
||||
|
||||
//更新对应任务为删除
|
||||
map.put("is_delete", "1");
|
||||
wo_Task.update(map, "task_id='" + dis.getString("task_id") + "'");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//更新对应任务为删除
|
||||
map.put("is_delete", "1");
|
||||
wo_Task.update(map, "task_id='" + dis.getString("task_id") + "'");
|
||||
|
||||
}
|
||||
//解锁起点仓位点位
|
||||
JSONObject from_start = new JSONObject();
|
||||
from_start.put("struct_id", dis.getString("struct_id"));
|
||||
from_start.put("lock_type", "1");
|
||||
storPublicService.updateStructAndPoint2(from_start);
|
||||
//解锁终点仓位点位
|
||||
if (StrUtil.isNotEmpty(dis.getString("point_code"))) {
|
||||
JSONObject from_end = new JSONObject();
|
||||
from_end.put("point_code", dis.getString("point_code"));
|
||||
from_end.put("lock_type", "1");
|
||||
storPublicService.updateStructAndPoint2(from_end);
|
||||
}
|
||||
} else {//仓位载具扔有冻结数,需改任务类型为拣选出库
|
||||
//任务号不为空
|
||||
//解锁起点仓位点位
|
||||
JSONObject from_start = new JSONObject();
|
||||
from_start.put("struct_id", dis.getString("struct_id"));
|
||||
from_start.put("lock_type", "1");
|
||||
storPublicService.updateStructAndPoint2(from_start);
|
||||
//解锁终点仓位点位
|
||||
if (StrUtil.isNotEmpty(dis.getString("point_code"))) {
|
||||
JSONObject from_end = new JSONObject();
|
||||
from_end.put("point_code", dis.getString("point_code"));
|
||||
from_end.put("lock_type", "1");
|
||||
storPublicService.updateStructAndPoint2(from_end);
|
||||
}
|
||||
} else {//仓位载具扔有冻结数,需改任务类型为拣选出库
|
||||
//任务号不为空
|
||||
/* if (ObjectUtil.isNotEmpty(dis.getString("task_id"))) {
|
||||
//更新对应任务为拣选出库
|
||||
map.put("taskdtl_type", "05");
|
||||
wo_Task.update(map, "task_id='" + dis.getString("task_id") + "'");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestException("其他出库单当前正在取消分配,请等待几秒再进行操作!");
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5688,7 +5723,7 @@ public class CheckOutBillServiceImpl implements CheckOutBillService {
|
||||
if (jo_mst.getString("is_overdue").equals("1")) {
|
||||
dis_rows = WQLObject.getWQLObject("ST_IVT_IOStorInvDis").query("iostorinv_id = '" + iostorinv_id + "' and is_overdue = '0' and box_no = '"+jsonSub.getString("package_box_sn")+"'").getResultJSONArray(0);
|
||||
} else {
|
||||
|
||||
|
||||
dis_rows = WQLObject.getWQLObject("ST_IVT_IOStorInvDis").query("iostorinv_id = '" + iostorinv_id + "' and box_no = '"+jsonSub.getString("package_box_sn")+"'").getResultJSONArray(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user