fix:状态变更添加等待锁

This commit is contained in:
zhangzhiqiang
2023-04-20 11:18:52 +08:00
parent 9fd1a1e6dd
commit 0112e723c7
2 changed files with 296 additions and 239 deletions

View File

@@ -0,0 +1,46 @@
package org.nl.wms.common.util;
import lombok.SneakyThrows;
import org.nl.exception.BadRequestException;
import org.nl.utils.SpringContextHolder;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
/*
* @author ZZQ
* @Date 2023/3/27 10:30
*/
public class RedissonUtils {
/**
*
* @param process 业务代码
* @param key
* @param seconds 尝试获取锁的等待时间,允许为空
*/
@SneakyThrows
public static void lock(Consumer process, String key, Integer seconds){
RedissonClient redissonClient = SpringContextHolder.getBean(RedissonClient.class);
RLock lock = redissonClient.getLock(key);
boolean isLock;
if (seconds == null){
isLock = lock.tryLock();
}else {
isLock = lock.tryLock(seconds, TimeUnit.SECONDS);
}
try {
if (isLock){
process.accept(null);
} else {
throw new BadRequestException("The current business is being processed key:"+key);
}
}finally {
if (isLock){
lock.unlock();
}
}
}
}

View File

@@ -23,6 +23,7 @@ import org.nl.utils.SecurityUtils;
import org.nl.utils.SpringContextHolder;
import org.nl.wms.basedata.master.constant.MaterOptTypeEnum;
import org.nl.wms.basedata.master.service.MaterialbaseService;
import org.nl.wms.common.util.RedissonUtils;
import org.nl.wms.pcs.Enum.ProcStatusEnum;
import org.nl.wms.pcs.Enum.ReceiveStatusEnum;
import org.nl.wms.ql.Enum.QlBillStatusEnum;
@@ -783,249 +784,259 @@ public class InspectionsheetmstServiceImpl implements InspectionsheetmstService
* 并按照原单据标识查到到货单并进行汇总实际数量 明细表原单据标识 = 到货单明细标识
*/
String inspection_id = jsonWhere.getString("inspection_id");
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
WQLObject mstTab = WQLObject.getWQLObject("QL_TEST_InspectionSheetMst"); //质检单主表
WQLObject dtlTab = WQLObject.getWQLObject("QL_TEST_InspectionSheetDtl"); //质检单明细表
WQLObject ivtTab = WQLObject.getWQLObject("ST_IVT_StructIvt"); //库存表
WQLObject flowTab = WQLObject.getWQLObject("ST_IVT_StructIvtFlow"); //仓位库存变动表
WQLObject redTab = WQLObject.getWQLObject("MD_PB_BucketRecord"); //桶记录表
WQLObject redFlowTab = WQLObject.getWQLObject("MD_PB_BucketChangeFlow"); //桶物料变动记录表
WQLObject reMstTab = WQLObject.getWQLObject("PCS_RC_ReceiveMst"); //到货通知单主表
WQLObject reDtlTab = WQLObject.getWQLObject("PCS_RC_ReceiveDtl"); //到货通知单明细表
WQLObject procTab = WQLObject.getWQLObject("PCS_IF_PurchaseOrderProc"); //采购订单接口处理表
WQLObject daTab = WQLObject.getWQLObject("ST_IVT_IOStorDaily"); //仓库物料日表
/*
* 更新到货通知单明细表
*/
JSONObject jsonDtl = dtlTab.query("inspection_id = '" + inspection_id + "'").uniqueResult(0);
JSONObject jsonMst = mstTab.query("inspection_id = '" + inspection_id + "'").uniqueResult(0);
String material_id = jsonDtl.getString("material_id");
//判断单据类型是否为原辅料单据 、并单据状态为完成
boolean is_yfl = materialBaseService.isAlongMaterType(MaterOptTypeEnum.YL_AND_FL.getCode(), material_id, null);
if (!is_yfl) {
throw new BadRequestException("此单据【" + jsonWhere.getString("inspection_code") + "】不为原辅料单据");
} else if (!StrUtil.equals(jsonWhere.getString("bill_status"), QlBillStatusEnum.FINISH.getCode())) {
throw new BadRequestException("只能对完成的单据进行状态变更");
}
JSONArray ivtDtlArr = WQL.getWO("QL_TEST_INSPECTIONSHEET002")
.addParam("flag", "2")
.addParam("material_id", jsonDtl.getString("material_id"))
.addParam("pcsn", jsonDtl.getString("pcsn")).process().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(ivtDtlArr)) {
for (int j = 0; j < ivtDtlArr.size(); j++) {
JSONObject json = ivtDtlArr.getJSONObject(j);
JSONObject jsonReDtl = reDtlTab.query("receivedtl_id = '" + json.getString("source_billdtl_id") + "'").uniqueResult(0);
// 如果是合格或者是放行就存入 入库数
if (StrUtil.equals(jsonDtl.getString("result"), "02")) {
jsonReDtl.put("instor_qty", 0);
// 如果是不合格就将入库数清0
} else {
jsonReDtl.put("instor_qty", json.getDoubleValue("real_qty"));
}
//判断到货明细表中的数量与到货入库数是否相等,相同就完成,不相等就到货中
if (jsonReDtl.getDoubleValue("receive_qty") <= jsonReDtl.getDoubleValue("instor_qty")) {
jsonReDtl.put("status", ReceiveStatusEnum.AFFIRM.getCode());
} else {
jsonReDtl.put("status", ReceiveStatusEnum.ARRIVAL_NOTICE.getCode());
}
reDtlTab.update(jsonReDtl);
/*
* 判断到货明细单中的状态是否完成,全部完成则更新到货通知单主表完成
*/
JSONArray reDtlArr = reDtlTab.query("receive_id = '" + jsonReDtl.getString("receive_id") + "'").getResultJSONArray(0);
int flag = 0;
for (int i = 0; i < reDtlArr.size(); i++) {
JSONObject json1 = reDtlArr.getJSONObject(i);
if (StrUtil.equals(json1.getString("status"), ReceiveStatusEnum.AFFIRM.getCode())) {
flag = flag + 1;
RedissonUtils.lock(
a->{
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
JSONObject jsonReMst = reMstTab.query("receive_id = '" + jsonReDtl.getString("receive_id") + "'").uniqueResult(0);
if (reDtlArr.size() == flag) {
jsonReMst.put("status", ReceiveStatusEnum.AFFIRM.getCode());
jsonReMst.put("confirm_optid", currentUserId);
jsonReMst.put("confirm_optname", nickName);
jsonReMst.put("confirm_time", now);
reMstTab.update(jsonReMst);
}
/*
* 如果到货单主表状态为确认,则需要更新采购订单接口处理表
*/
if (StrUtil.equals(jsonReMst.getString("status"), ReceiveStatusEnum.AFFIRM.getCode())) {
JSONObject jsonProc = procTab.query("id = '" + jsonReDtl.getString("source_billdtl_id") + "'").uniqueResult(0);
// 到货数量 = 订单数量,为完成,否则为采购中
if ((jsonReDtl.getDoubleValue("instor_qty") >= jsonProc.getDoubleValue("qty")) && (StrUtil.equals(jsonReDtl.getString("status"), "99"))) {
jsonProc.put("proc_status", ProcStatusEnum.FULFILL.getCode());
} else {
jsonProc.put("proc_status", ProcStatusEnum.BUYING_CENTER.getCode());
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
WQLObject mstTab = WQLObject.getWQLObject("QL_TEST_InspectionSheetMst"); //质检单主表
WQLObject dtlTab = WQLObject.getWQLObject("QL_TEST_InspectionSheetDtl"); //质检单明细表
WQLObject ivtTab = WQLObject.getWQLObject("ST_IVT_StructIvt"); //库存表
WQLObject flowTab = WQLObject.getWQLObject("ST_IVT_StructIvtFlow"); //仓位库存变动表
WQLObject redTab = WQLObject.getWQLObject("MD_PB_BucketRecord"); //桶记录表
WQLObject redFlowTab = WQLObject.getWQLObject("MD_PB_BucketChangeFlow"); //桶物料变动记录表
WQLObject reMstTab = WQLObject.getWQLObject("PCS_RC_ReceiveMst"); //到货通知单主表
WQLObject reDtlTab = WQLObject.getWQLObject("PCS_RC_ReceiveDtl"); //到货通知单明细表
WQLObject procTab = WQLObject.getWQLObject("PCS_IF_PurchaseOrderProc"); //采购订单接口处理表
WQLObject daTab = WQLObject.getWQLObject("ST_IVT_IOStorDaily"); //仓库物料日表
/*
* 更新到货通知单明细表
*/
JSONObject jsonDtl = dtlTab.query("inspection_id = '" + inspection_id + "'").uniqueResult(0);
JSONObject jsonMst = mstTab.query("inspection_id = '" + inspection_id + "'").uniqueResult(0);
String material_id = jsonDtl.getString("material_id");
//判断单据类型是否为原辅料单据 、并单据状态为完成
boolean is_yfl = materialBaseService.isAlongMaterType(MaterOptTypeEnum.YL_AND_FL.getCode(), material_id, null);
if (!is_yfl) {
throw new BadRequestException("此单据【" + jsonWhere.getString("inspection_code") + "】不为原辅料单据");
} else if (!StrUtil.equals(jsonWhere.getString("bill_status"), QlBillStatusEnum.FINISH.getCode())) {
throw new BadRequestException("只能对完成的单据进行状态变更");
}
procTab.update(jsonProc);
}
}
}
/*
* 更新仓位库存表
*/
JSONArray IvtArr = new JSONArray();
if (StrUtil.equals(jsonDtl.getString("result"), "01") || StrUtil.equals(jsonDtl.getString("result"), "03")) {
IvtArr = ivtTab.query("material_id = '" + jsonDtl.getString("material_id") + "' and pcsn = '" + jsonDtl.getString("pcsn") + "'").getResultJSONArray(0);
} else if (StrUtil.equals(jsonDtl.getString("result"), "02")) {
IvtArr = ivtTab.query("material_id = '" + jsonDtl.getString("material_id") + "' and pcsn = '" + jsonDtl.getString("pcsn") + "'").getResultJSONArray(0);
}
if (ObjectUtil.isNotEmpty(IvtArr)) {
//判断当前库存是否有冻结数或者待入数
JSONObject ivt_now = WQL.getWO("QL_TEST_INSPECTIONSHEET002")
.addParam("flag", "5")
.addParam("material_id", jsonDtl.getString("material_id"))
.addParam("pcsn", jsonDtl.getString("pcsn"))
.process().uniqueResult(0);
if(ivt_now != null){
double frozen_qty = ivt_now.getDouble("frozen_qty");
double warehousing_qty = ivt_now.getDouble("warehousing_qty");
if(frozen_qty!=0 || warehousing_qty != 0){
throw new BadRequestException("此批次物料库存冻结数或待入数不为0,有未完成的单据,请稍后再试!");
}
}
/*
* 更新仓位库存表
*/
for (int i = 0; i < IvtArr.size(); i++) {
JSONObject jsonIvt = IvtArr.getJSONObject(i);
// 判断库存的可用数和库存数是否一致,不可以确认
if (jsonIvt.getDoubleValue("canuse_qty") != jsonIvt.getDoubleValue("ivt_qty")) {
throw new BadRequestException("此批次物料有未完成的单据");
}
JSONObject prarm = new JSONObject();
String change_type_scode = "";
prarm.put("struct_id", jsonIvt.getString("struct_id"));
prarm.put("material_id", jsonIvt.getString("material_id"));
prarm.put("quality_scode", jsonIvt.getString("quality_scode"));
prarm.put("pcsn", jsonIvt.getString("pcsn"));
prarm.put("ivt_level", jsonIvt.getString("ivt_level"));
prarm.put("is_active", jsonIvt.getString("is_active"));
prarm.put("change_qty", jsonIvt.getString("ivt_qty"));
prarm.put("bill_type_scode", jsonMst.getString("inspection_type"));
prarm.put("inv_id", jsonMst.getString("inspection_id"));
prarm.put("bill_code", jsonMst.getString("inspection_code"));
prarm.put("qty_unit_id", jsonIvt.getString("qty_unit_id"));
prarm.put("qty_unit_name", jsonIvt.getString("qty_unit_name"));
change_type_scode = "24";
storPublicService.IOStor(prarm, change_type_scode);
prarm.put("quality_scode", jsonDtl.getString("result"));
prarm.put("ivt_level", jsonDtl.getString("grade"));
change_type_scode = "23";
storPublicService.IOStor(prarm, change_type_scode);
}
/*
* 更新桶记录表
*/
JSONArray redArr = redTab.query("material_id = '" + jsonDtl.getString("material_id") + "' and pcsn = '" + jsonDtl.getString("pcsn") + "' and status = '03'").getResultJSONArray(0);
if (ObjectUtil.isEmpty(redArr)) {
throw new BadRequestException("此物料【" + jsonMst.getString("material_code") + "】没有桶记录表");
}
for (int k = 0; k < redArr.size(); k++) {
JSONObject json = redArr.getJSONObject(k);
String quality_scode = json.getString("quality_scode"); // 原品质类型
String ivt_level = json.getString("ivt_level"); //原库存
String result_qty = json.getString("storage_qty"); // 原结存数量
json.put("quality_scode", jsonDtl.getString("result"));
json.put("ivt_level", jsonDtl.getString("grade"));
redTab.update(json);
if (StrUtil.equals(jsonDtl.getString("result"), "02")) {
//不合格 插入桶物料变动表
JSONObject jsonRedFow = new JSONObject();
jsonRedFow.put("change_id", IdUtil.getSnowflake(1, 1).nextId());
jsonRedFow.put("bucket_code", json.get("bucketunique"));
jsonRedFow.put("material_id", json.get("material_id"));
jsonRedFow.put("pcsn", json.getString("pcsn"));
jsonRedFow.put("ivt_level", ivt_level);
jsonRedFow.put("is_active", json.getString("is_active"));
jsonRedFow.put("quality_scode", quality_scode);
jsonRedFow.put("change_type_scode", "02");
jsonRedFow.put("change_time", now);
jsonRedFow.put("rec_person", currentUserId);
jsonRedFow.put("change_qty", result_qty);
jsonRedFow.put("qty_unit_id", json.getString("qty_unit_id"));
jsonRedFow.put("qty_unit_name", json.getString("qty_unit_name"));
redFlowTab.insert(jsonRedFow);
} else if (StrUtil.equals(jsonDtl.getString("result"), "01") || StrUtil.equals(jsonDtl.getString("result"), "03")) {
// 合格 插入桶物料变动表
JSONObject jsonRedFow = new JSONObject();
jsonRedFow.put("change_id", IdUtil.getSnowflake(1, 1).nextId());
jsonRedFow.put("bucket_code", json.get("bucketunique"));
jsonRedFow.put("material_id", json.get("material_id"));
jsonRedFow.put("pcsn", json.getString("pcsn"));
jsonRedFow.put("ivt_level", jsonDtl.getString("grade"));
jsonRedFow.put("is_active", json.getString("is_active"));
jsonRedFow.put("quality_scode", jsonDtl.getString("result"));
jsonRedFow.put("change_type_scode", "01");
jsonRedFow.put("change_time", now);
jsonRedFow.put("rec_person", currentUserId);
jsonRedFow.put("change_qty", result_qty);
jsonRedFow.put("result_qty", result_qty);
jsonRedFow.put("qty_unit_id", json.getString("qty_unit_id"));
jsonRedFow.put("qty_unit_name", json.getString("qty_unit_name"));
redFlowTab.insert(jsonRedFow);
}
}
}
//判断质检单是否合格;不合格就走退货流程
if (StrUtil.equals(jsonDtl.getString("result"), "02") && ObjectUtil.isNotEmpty(ivtDtlArr)) {
/*
* 插入退货单
* 主表参数bill_code=, stor_id=1473161852946092032, stor_code=01,
* stor_name=原材料库, bill_status=10, total_qty=2, detail_count=1,
* bill_type=010201, remark=, biz_date=2022-01-08, create_mode=
*
* 明细参数bill_status=10,
* pcsn=, quality_scode=02, ivt_level=01,
* is_active=1, plan_qty=2, qty_unit_name=千克\公斤, qty_unit_id=1, remark=, edit=true
*/
// 根据物料、批次找出所有库存
JSONArray ivtArrAll = WQL.getWO("QL_TEST_INSPECTIONSHEET002").addParam("flag", "4").addParam("material_id", jsonDtl.getString("material_id")).addParam("pcsn", jsonDtl.getString("pcsn")).process().getResultJSONArray(0);
if (ObjectUtil.isEmpty(ivtArrAll)) {
throw new BadRequestException("此批次【" + jsonDtl.getString("pcsn") + "】没有物料为【" + jsonMst.getString("material_code") + "】的库存");
}
double total_qty = 0;
for (int i = 0; i < ivtArrAll.size(); i++) {
JSONObject json = ivtArrAll.getJSONObject(i);
json.put("bill_status", "10");
json.put("pcsn", jsonDtl.getString("pcsn"));
json.put("quality_scode", jsonDtl.getString("result"));
json.put("ivt_level", jsonDtl.getString("grade"));
json.put("is_active", jsonDtl.getString("is_active"));
json.put("plan_qty", json.getString("ivt_qty"));
json.put("qty_unit_name", json.getString("qty_unit_name"));
json.put("qty_unit_id", json.getString("qty_unit_id"));
json.put("remark", "");
json.put("edit", true);
total_qty += json.getDoubleValue("ivt_qty");
}
JSONObject param = new JSONObject();
param.put("stor_id", "1473161852946092032");
param.put("stor_code", "01");
param.put("stor_name", "原材料库");
param.put("bill_status", "10");
param.put("total_qty", total_qty);
param.put("detail_count", ivtArrAll.size());
if (StrUtil.equals(jsonMst.getString("inspection_type"), "10")) param.put("bill_type", "010201");
if (StrUtil.equals(jsonMst.getString("inspection_type"), "20")) param.put("bill_type", "010202");
param.put("remark", "");
param.put("biz_date", DateUtil.today());
param.put("create_mode", "01");
param.put("tableData", ivtArrAll);
checkOutBillService.insertDtlByJson(param);
}
JSONArray ivtDtlArr = WQL.getWO("QL_TEST_INSPECTIONSHEET002")
.addParam("flag", "2")
.addParam("material_id", jsonDtl.getString("material_id"))
.addParam("pcsn", jsonDtl.getString("pcsn")).process().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(ivtDtlArr)) {
for (int j = 0; j < ivtDtlArr.size(); j++) {
JSONObject json = ivtDtlArr.getJSONObject(j);
JSONObject jsonReDtl = reDtlTab.query("receivedtl_id = '" + json.getString("source_billdtl_id") + "'").uniqueResult(0);
// 如果是合格或者是放行就存入 入库数
if (StrUtil.equals(jsonDtl.getString("result"), "02")) {
jsonReDtl.put("instor_qty", 0);
// 如果是不合格就将入库数清0
} else {
jsonReDtl.put("instor_qty", json.getDoubleValue("real_qty"));
}
//判断到货明细表中的数量与到货入库数是否相等,相同就完成,不相等就到货中
if (jsonReDtl.getDoubleValue("receive_qty") <= jsonReDtl.getDoubleValue("instor_qty")) {
jsonReDtl.put("status", ReceiveStatusEnum.AFFIRM.getCode());
} else {
jsonReDtl.put("status", ReceiveStatusEnum.ARRIVAL_NOTICE.getCode());
}
reDtlTab.update(jsonReDtl);
/*
* 判断到货明细单中的状态是否完成,全部完成则更新到货通知单主表完成
*/
JSONArray reDtlArr = reDtlTab.query("receive_id = '" + jsonReDtl.getString("receive_id") + "'").getResultJSONArray(0);
int flag = 0;
for (int i = 0; i < reDtlArr.size(); i++) {
JSONObject json1 = reDtlArr.getJSONObject(i);
if (StrUtil.equals(json1.getString("status"), ReceiveStatusEnum.AFFIRM.getCode())) {
flag = flag + 1;
}
}
JSONObject jsonReMst = reMstTab.query("receive_id = '" + jsonReDtl.getString("receive_id") + "'").uniqueResult(0);
if (reDtlArr.size() == flag) {
jsonReMst.put("status", ReceiveStatusEnum.AFFIRM.getCode());
jsonReMst.put("confirm_optid", currentUserId);
jsonReMst.put("confirm_optname", nickName);
jsonReMst.put("confirm_time", now);
reMstTab.update(jsonReMst);
}
/*
* 如果到货单主表状态为确认,则需要更新采购订单接口处理表
*/
if (StrUtil.equals(jsonReMst.getString("status"), ReceiveStatusEnum.AFFIRM.getCode())) {
JSONObject jsonProc = procTab.query("id = '" + jsonReDtl.getString("source_billdtl_id") + "'").uniqueResult(0);
// 到货数量 = 订单数量,为完成,否则为采购中
if ((jsonReDtl.getDoubleValue("instor_qty") >= jsonProc.getDoubleValue("qty")) && (StrUtil.equals(jsonReDtl.getString("status"), "99"))) {
jsonProc.put("proc_status", ProcStatusEnum.FULFILL.getCode());
} else {
jsonProc.put("proc_status", ProcStatusEnum.BUYING_CENTER.getCode());
}
procTab.update(jsonProc);
}
}
}
/*
* 更新仓位库存表
*/
JSONArray IvtArr = new JSONArray();
if (StrUtil.equals(jsonDtl.getString("result"), "01") || StrUtil.equals(jsonDtl.getString("result"), "03")) {
IvtArr = ivtTab.query("material_id = '" + jsonDtl.getString("material_id") + "' and pcsn = '" + jsonDtl.getString("pcsn") + "'").getResultJSONArray(0);
} else if (StrUtil.equals(jsonDtl.getString("result"), "02")) {
IvtArr = ivtTab.query("material_id = '" + jsonDtl.getString("material_id") + "' and pcsn = '" + jsonDtl.getString("pcsn") + "'").getResultJSONArray(0);
}
if (ObjectUtil.isNotEmpty(IvtArr)) {
//判断当前库存是否有冻结数或者待入数
JSONObject ivt_now = WQL.getWO("QL_TEST_INSPECTIONSHEET002")
.addParam("flag", "5")
.addParam("material_id", jsonDtl.getString("material_id"))
.addParam("pcsn", jsonDtl.getString("pcsn"))
.process().uniqueResult(0);
if (ivt_now != null) {
double frozen_qty = ivt_now.getDouble("frozen_qty");
double warehousing_qty = ivt_now.getDouble("warehousing_qty");
if (frozen_qty != 0 || warehousing_qty != 0) {
throw new BadRequestException("此批次物料库存冻结数或待入数不为0,有未完成的单据,请稍后再试!");
}
}
/*
* 更新仓位库存表
*/
for (int i = 0; i < IvtArr.size(); i++) {
JSONObject jsonIvt = IvtArr.getJSONObject(i);
// 判断库存的可用数和库存数是否一致,不可以确认
if (jsonIvt.getDoubleValue("canuse_qty") != jsonIvt.getDoubleValue("ivt_qty")) {
throw new BadRequestException("此批次物料有未完成的单据");
}
JSONObject prarm = new JSONObject();
String change_type_scode = "";
prarm.put("struct_id", jsonIvt.getString("struct_id"));
prarm.put("material_id", jsonIvt.getString("material_id"));
prarm.put("quality_scode", jsonIvt.getString("quality_scode"));
prarm.put("pcsn", jsonIvt.getString("pcsn"));
prarm.put("ivt_level", jsonIvt.getString("ivt_level"));
prarm.put("is_active", jsonIvt.getString("is_active"));
prarm.put("change_qty", jsonIvt.getString("ivt_qty"));
prarm.put("bill_type_scode", jsonMst.getString("inspection_type"));
prarm.put("inv_id", jsonMst.getString("inspection_id"));
prarm.put("bill_code", jsonMst.getString("inspection_code"));
prarm.put("qty_unit_id", jsonIvt.getString("qty_unit_id"));
prarm.put("qty_unit_name", jsonIvt.getString("qty_unit_name"));
change_type_scode = "24";
storPublicService.IOStor(prarm, change_type_scode);
prarm.put("quality_scode", jsonDtl.getString("result"));
prarm.put("ivt_level", jsonDtl.getString("grade"));
change_type_scode = "23";
storPublicService.IOStor(prarm, change_type_scode);
}
/*
* 更新桶记录表
*/
JSONArray redArr = redTab.query("material_id = '" + jsonDtl.getString("material_id") + "' and pcsn = '" + jsonDtl.getString("pcsn") + "' and status = '03'").getResultJSONArray(0);
if (ObjectUtil.isEmpty(redArr)) {
throw new BadRequestException("此物料【" + jsonMst.getString("material_code") + "】没有桶记录表");
}
for (int k = 0; k < redArr.size(); k++) {
JSONObject json = redArr.getJSONObject(k);
String quality_scode = json.getString("quality_scode"); // 原品质类型
String ivt_level = json.getString("ivt_level"); //原库存
String result_qty = json.getString("storage_qty"); // 原结存数量
json.put("quality_scode", jsonDtl.getString("result"));
json.put("ivt_level", jsonDtl.getString("grade"));
redTab.update(json);
if (StrUtil.equals(jsonDtl.getString("result"), "02")) {
//不合格 插入桶物料变动表
JSONObject jsonRedFow = new JSONObject();
jsonRedFow.put("change_id", IdUtil.getSnowflake(1, 1).nextId());
jsonRedFow.put("bucket_code", json.get("bucketunique"));
jsonRedFow.put("material_id", json.get("material_id"));
jsonRedFow.put("pcsn", json.getString("pcsn"));
jsonRedFow.put("ivt_level", ivt_level);
jsonRedFow.put("is_active", json.getString("is_active"));
jsonRedFow.put("quality_scode", quality_scode);
jsonRedFow.put("change_type_scode", "02");
jsonRedFow.put("change_time", now);
jsonRedFow.put("rec_person", currentUserId);
jsonRedFow.put("change_qty", result_qty);
jsonRedFow.put("qty_unit_id", json.getString("qty_unit_id"));
jsonRedFow.put("qty_unit_name", json.getString("qty_unit_name"));
redFlowTab.insert(jsonRedFow);
} else if (StrUtil.equals(jsonDtl.getString("result"), "01") || StrUtil.equals(jsonDtl.getString("result"), "03")) {
// 合格 插入桶物料变动表
JSONObject jsonRedFow = new JSONObject();
jsonRedFow.put("change_id", IdUtil.getSnowflake(1, 1).nextId());
jsonRedFow.put("bucket_code", json.get("bucketunique"));
jsonRedFow.put("material_id", json.get("material_id"));
jsonRedFow.put("pcsn", json.getString("pcsn"));
jsonRedFow.put("ivt_level", jsonDtl.getString("grade"));
jsonRedFow.put("is_active", json.getString("is_active"));
jsonRedFow.put("quality_scode", jsonDtl.getString("result"));
jsonRedFow.put("change_type_scode", "01");
jsonRedFow.put("change_time", now);
jsonRedFow.put("rec_person", currentUserId);
jsonRedFow.put("change_qty", result_qty);
jsonRedFow.put("result_qty", result_qty);
jsonRedFow.put("qty_unit_id", json.getString("qty_unit_id"));
jsonRedFow.put("qty_unit_name", json.getString("qty_unit_name"));
redFlowTab.insert(jsonRedFow);
}
}
}
//判断质检单是否合格;不合格就走退货流程
if (StrUtil.equals(jsonDtl.getString("result"), "02") && ObjectUtil.isNotEmpty(ivtDtlArr)) {
/*
* 插入退货单
* 主表参数bill_code=, stor_id=1473161852946092032, stor_code=01,
* stor_name=原材料库, bill_status=10, total_qty=2, detail_count=1,
* bill_type=010201, remark=, biz_date=2022-01-08, create_mode=
*
* 明细参数bill_status=10,
* pcsn=, quality_scode=02, ivt_level=01,
* is_active=1, plan_qty=2, qty_unit_name=千克\公斤, qty_unit_id=1, remark=, edit=true
*/
// 根据物料、批次找出所有库存
JSONArray ivtArrAll = WQL.getWO("QL_TEST_INSPECTIONSHEET002").addParam("flag", "4").addParam("material_id", jsonDtl.getString("material_id")).addParam("pcsn", jsonDtl.getString("pcsn")).process().getResultJSONArray(0);
if (ObjectUtil.isEmpty(ivtArrAll)) {
throw new BadRequestException("此批次【" + jsonDtl.getString("pcsn") + "】没有物料为【" + jsonMst.getString("material_code") + "】的库存");
}
double total_qty = 0;
for (int i = 0; i < ivtArrAll.size(); i++) {
JSONObject json = ivtArrAll.getJSONObject(i);
json.put("bill_status", "10");
json.put("pcsn", jsonDtl.getString("pcsn"));
json.put("quality_scode", jsonDtl.getString("result"));
json.put("ivt_level", jsonDtl.getString("grade"));
json.put("is_active", jsonDtl.getString("is_active"));
json.put("plan_qty", json.getString("ivt_qty"));
json.put("qty_unit_name", json.getString("qty_unit_name"));
json.put("qty_unit_id", json.getString("qty_unit_id"));
json.put("remark", "");
json.put("edit", true);
total_qty += json.getDoubleValue("ivt_qty");
}
JSONObject param = new JSONObject();
param.put("stor_id", "1473161852946092032");
param.put("stor_code", "01");
param.put("stor_name", "原材料库");
param.put("bill_status", "10");
param.put("total_qty", total_qty);
param.put("detail_count", ivtArrAll.size());
if (StrUtil.equals(jsonMst.getString("inspection_type"), "10")) param.put("bill_type", "010201");
if (StrUtil.equals(jsonMst.getString("inspection_type"), "20")) param.put("bill_type", "010202");
param.put("remark", "");
param.put("biz_date", DateUtil.today());
param.put("create_mode", "01");
param.put("tableData", ivtArrAll);
checkOutBillService.insertDtlByJson(param);
}
},inspection_id,2
);
}
@Override