rev:成品报废审核增加接口报错信息

This commit is contained in:
2024-06-06 09:35:53 +08:00
parent 6f1d80737e
commit 9aba17fd13

View File

@@ -212,82 +212,81 @@ public class ProductScrapServiceImpl implements ProductScrapService {
WQLObject mst = WQLObject.getWQLObject("ST_IVT_ProductScrapMst");
WQLObject dtl = WQLObject.getWQLObject("ST_IVT_ProductScrapDtl");
WQLObject ivt = WQLObject.getWQLObject("st_ivt_structivt");
try {
// 查询所有明细
JSONArray dtlArr = dtl.query("scrap_id = '" + whereJson.getString("scrap_id") + "'").getResultJSONArray(0);
// 查询所有明细
JSONArray dtlArr = dtl.query("scrap_id = '" + whereJson.getString("scrap_id") + "'").getResultJSONArray(0);
// 查询库存中这些子卷是否存在
String pcsnJoining = dtlArr.stream()
.map(row -> JSON.parseObject(row.toString()))
.map(row -> row.getString("pcsn"))
.collect(Collectors.joining("','"));
// 查询库存中这些子卷是否存在
String pcsnJoining = dtlArr.stream()
.map(row -> JSON.parseObject(row.toString()))
.map(row -> row.getString("pcsn"))
.collect(Collectors.joining("','"));
List<JSONObject> ivtList = ivt.query("pcsn in ('" + pcsnJoining + "') and canuse_qty > 0")
.getResultJSONArray(0).toJavaList(JSONObject.class);
List<JSONObject> ivtList = ivt.query("pcsn in ('" + pcsnJoining + "') and canuse_qty > 0")
.getResultJSONArray(0).toJavaList(JSONObject.class);
if (dtlArr.size() != ivtList.size()) {
throw new BadRequestException("库存异常请检查!");
}
if (dtlArr.size() != ivtList.size()) {
throw new BadRequestException("库存异常请检查!");
// 校验库存
boolean is_pass = ivtList.stream()
.allMatch(row -> pcsnJoining.contains(row.getString("pcsn")));
if (!is_pass) {
throw new BadRequestException("库存异常请检查!");
}
// 生成出库单
JSONObject jsonOutMst = new JSONObject();
jsonOutMst.put("stor_id", whereJson.getString("stor_id"));
jsonOutMst.put("stor_code", whereJson.getString("stor_code"));
jsonOutMst.put("stor_name", whereJson.getString("stor_name"));
jsonOutMst.put("detail_count", ivtList.size());
jsonOutMst.put("bill_status", "10");
jsonOutMst.put("create_mode", "03");
jsonOutMst.put("biz_date", DateUtil.now());
jsonOutMst.put("io_type", "1");
jsonOutMst.put("buss_type", "1002");
jsonOutMst.put("bill_type", "1002");
jsonOutMst.put("source_name", "成品报废审核单");
JSONArray tableData = new JSONArray();
for (int i = 0; i < dtlArr.size(); i++) {
JSONObject json = dtlArr.getJSONObject(i);
JSONObject jsonDtl = new JSONObject();
jsonDtl.put("pcsn", json.getString("pcsn"));
jsonDtl.put("box_no", json.getString("package_box_sn"));
jsonDtl.put("material_id", json.getString("material_id"));
jsonDtl.put("qty_unit_id", json.getLongValue("qty_unit_id"));
jsonDtl.put("qty_unit_name", json.getString("qty_unit_name"));
jsonDtl.put("plan_qty", json.getDoubleValue("qty"));
tableData.add(jsonDtl);
}
// 调用出库新增并分配
jsonOutMst.put("tableData", tableData);
String iostorinv_id = checkOutBillService.insertDtl(jsonOutMst);
JSONObject jsonObject = new JSONObject();
jsonObject.put("iostorinv_id", iostorinv_id);
checkOutBillService.allDiv(jsonObject);
// 更新主表为完成
JSONObject param = new JSONObject();
param.put("bill_status", "99");
param.put("confirm_optid", SecurityUtils.getCurrentUserId());
param.put("confirm_optname", SecurityUtils.getCurrentNickName());
param.put("confirm_time", DateUtil.now());
mst.update(param, "scrap_id = '" + whereJson.getString("scrap_id") + "'");
} catch (Exception e) {
JSONObject msg = new JSONObject();
msg.put("remark", "单据异常:"+e.getMessage());
mst.update(msg,"scrap_id = '" + whereJson.getString("scrap_id") + "'");
}
// 校验库存
boolean is_pass = ivtList.stream()
.allMatch(row -> pcsnJoining.contains(row.getString("pcsn")));
if (!is_pass) {
throw new BadRequestException("库存异常请检查!");
}
/* List<String> collect = ivtList.stream()
.filter(row -> !pcsnJoining.contains(row.getString("pcsn")))
.map(row -> row.getString("pcsn"))
.collect(Collectors.toList());
if (ObjectUtil.isNotEmpty(collect)) {
throw new BadRequestException("子卷:"+collect.toString()+"异常请检查!");
}*/
// 生成出库单
JSONObject jsonOutMst = new JSONObject();
jsonOutMst.put("stor_id", whereJson.getString("stor_id"));
jsonOutMst.put("stor_code", whereJson.getString("stor_code"));
jsonOutMst.put("stor_name", whereJson.getString("stor_name"));
jsonOutMst.put("detail_count", ivtList.size());
jsonOutMst.put("bill_status", "10");
jsonOutMst.put("create_mode", "03");
jsonOutMst.put("biz_date", DateUtil.now());
jsonOutMst.put("io_type", "1");
jsonOutMst.put("buss_type", "1002");
jsonOutMst.put("bill_type", "1002");
jsonOutMst.put("source_name", "成品报废审核单");
JSONArray tableData = new JSONArray();
for (int i = 0; i < dtlArr.size(); i++) {
JSONObject json = dtlArr.getJSONObject(i);
JSONObject jsonDtl = new JSONObject();
jsonDtl.put("pcsn", json.getString("pcsn"));
jsonDtl.put("box_no", json.getString("package_box_sn"));
jsonDtl.put("material_id", json.getString("material_id"));
jsonDtl.put("qty_unit_id", json.getLongValue("qty_unit_id"));
jsonDtl.put("qty_unit_name", json.getString("qty_unit_name"));
jsonDtl.put("plan_qty", json.getDoubleValue("qty"));
tableData.add(jsonDtl);
}
// 调用出库新增并分配
jsonOutMst.put("tableData", tableData);
String iostorinv_id = checkOutBillService.insertDtl(jsonOutMst);
JSONObject jsonObject = new JSONObject();
jsonObject.put("iostorinv_id", iostorinv_id);
checkOutBillService.allDiv(jsonObject);
// 更新主表为完成
JSONObject param = new JSONObject();
param.put("bill_status", "99");
param.put("confirm_optid", SecurityUtils.getCurrentUserId());
param.put("confirm_optname", SecurityUtils.getCurrentNickName());
param.put("confirm_time", DateUtil.now());
mst.update(param, "scrap_id = '" + whereJson.getString("scrap_id") + "'");
}
@Override