opt:自动叫料接口优化
This commit is contained in:
@@ -18,6 +18,7 @@ import org.nl.exception.BadRequestException;
|
||||
import org.nl.ext.acs.enu.WeighEnum;
|
||||
import org.nl.ext.acs.service.WmsToAcsService;
|
||||
import org.nl.modules.system.service.impl.ParamServiceImpl;
|
||||
import org.nl.modules.system.util.MapOf;
|
||||
import org.nl.pda.st.out.service.HandPFOutIvtService;
|
||||
import org.nl.utils.FileUtil;
|
||||
import org.nl.utils.SecurityUtils;
|
||||
@@ -39,11 +40,18 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.ToDoubleFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -56,12 +64,9 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class FlourworkServiceImpl implements FlourworkService {
|
||||
private final HandMoveStorService handMoveStorService;
|
||||
private final WorkTaskService workTaskService;
|
||||
private final HandPFOutIvtService handPFOutIvtService;
|
||||
private final MaterialbaseService materialbaseService;
|
||||
private final WmsToAcsService wmsToAcsService;
|
||||
private final ClassstandardService classstandardService;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private FlourworkService flourworkService;
|
||||
@@ -183,225 +188,185 @@ public class FlourworkServiceImpl implements FlourworkService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JSONObject autoCalledMater(JSONObject whereJson) {
|
||||
String device_id = whereJson.getString("device_id");
|
||||
String formula_id = whereJson.getString("formula_id");
|
||||
public JSONObject autoCalledMater(JSONObject form) {
|
||||
JSONObject jsonFormMst = WQLObject.getWQLObject("PDM_BI_Formula").query("formula_id = '" + form.getString("formula_id") + "' and status <> '99'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(jsonFormMst)) { throw new BadRequestException("配方已完成"); }
|
||||
JSONArray dtlArr = WQLObject.getWQLObject("PDM_BI_FormulaDtl").query("formula_id = '" + form.getString("formula_id") + "' and status <> '99' and is_need_move = '1' order by seq_no ASC").getResultJSONArray(0);
|
||||
if (ObjectUtil.isEmpty(dtlArr)) { throw new BadRequestException("没有需要叫料的物料"); }
|
||||
|
||||
WQLObject formTabMst = WQLObject.getWQLObject("PDM_BI_Formula"); // 配方主表
|
||||
WQLObject formTabDtl = WQLObject.getWQLObject("PDM_BI_FormulaDtl"); // 配方明细表
|
||||
WQLObject devicePointTab = WQLObject.getWQLObject("SCH_BASE_DevicePointPara"); // 设备点位参数表
|
||||
WQLObject strucTab = WQLObject.getWQLObject("st_ivt_structattr"); // 仓位表
|
||||
|
||||
JSONObject jsonFormMst = formTabMst.query("formula_id = '" + formula_id + "' and status <> '99'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(jsonFormMst)) throw new BadRequestException("配方已完成");
|
||||
/*
|
||||
* 查询需要移库的物料(配方明细表)条件:
|
||||
* 1.状态等于10生成、20生产中
|
||||
* 2.是否需要移库 = 1
|
||||
* 3.按照配粉序号排序 ASC
|
||||
*/
|
||||
ArrayList<String> arr = new ArrayList<>();
|
||||
ArrayList<String> arr2 = new ArrayList<>();
|
||||
JSONObject result = new JSONObject();
|
||||
String taskNum = "0";
|
||||
JSONArray dtlArr = formTabDtl.query("formula_id = '" + formula_id + "' and status <> '99' and is_need_move = '1' order by seq_no ASC").getResultJSONArray(0);
|
||||
if (ObjectUtil.isEmpty(dtlArr)) throw new BadRequestException("没有需要叫料的物料");
|
||||
JSONArray jsonDeviceArr = devicePointTab.query("device_uuid = '" + device_id + "' and point_type = '03'").getResultJSONArray(0);
|
||||
Set<String> set = classstandardService.getAllChildIdSet(MaterOptTypeEnum.GF.getClass_idStr());
|
||||
String materials = "";
|
||||
for (int i = 0; i < dtlArr.size(); i++) {
|
||||
JSONObject jsonFormDtl = dtlArr.getJSONObject(i);
|
||||
String material_id = jsonFormDtl.getString("material_id");
|
||||
materials = materials+"'"+material_id+"',";
|
||||
Set<String> materilsCollect = dtlArr.stream().map(o-> ((JSONObject)o).getString("material_id")).collect(Collectors.toSet());
|
||||
//可用点位校验:估粉位跟非估粉位都有
|
||||
List<JSONObject> g_points = new ArrayList<>();
|
||||
List<JSONObject> notG_points = new ArrayList<>();
|
||||
配分位置数量校验:{
|
||||
JSONArray move_ins = WQL.getWO("QMD_FORMING01")
|
||||
.addParamMap(MapOf.of("flag", "6"
|
||||
, "device_uuid", form.getString("device_id")
|
||||
)).process()
|
||||
.getResultJSONArray(0);
|
||||
if (move_ins.size()==0){
|
||||
throw new BadRequestException("叫料失败,配粉间没有空位");
|
||||
}
|
||||
for (Object item : move_ins) {
|
||||
JSONObject item1 = (JSONObject) item;
|
||||
int has = item1.getIntValue("has");
|
||||
if (has == 0) { notG_points.add(item1); }
|
||||
else { g_points.add(item1); }
|
||||
}
|
||||
}
|
||||
JSONArray md_me_materialbase = WQLObject.getWQLObject("md_me_materialbase").query("material_id in (" + materials.substring(0, materials.length() - 1) + ")").getResultJSONArray(0);
|
||||
List<String> GFSet = md_me_materialbase.stream().filter(o -> {
|
||||
//钴粉class_id = 1503644362192588800
|
||||
JSONArray materialInfos = WQLObject.getWQLObject("md_me_materialbase").query("material_type_id = '1503644362192588800' and material_id in ('" + materilsCollect.stream().collect(Collectors.joining("','")) + "')").getResultJSONArray(0);
|
||||
List<String> g_material = materialInfos.stream().map(o-> ((JSONObject)o).getString("material_id")).collect(Collectors.toList());
|
||||
log.info("配粉位情况 g粉位" + g_points.size() + "非g位" + notG_points.size()+"g粉物料数量"+g_material.size());
|
||||
//物料校验 1.查询所有点位上物料信息:批次没确认2.查询工令所有正在移库的物料2.扣减之后如果还有需要叫料3.查询仓位物料信息:进行叫料操作
|
||||
//1
|
||||
JSONArray total_materilas = WQL.getWO("QMD_FORMING01")
|
||||
.addParamMap(MapOf.of("flag","3"
|
||||
,"device_uuid",form.getString("device_id")
|
||||
,"materials","('"+materilsCollect.stream().collect(Collectors.joining("','"))+"')"))
|
||||
.process()
|
||||
.getResultJSONArray(0);
|
||||
//2
|
||||
JSONArray total_move = WQL.getWO("QMD_FORMING01")
|
||||
.addParamMap(MapOf.of("flag","4"
|
||||
,"workorder_id",jsonFormMst.getString("workorder_id")
|
||||
,"materials","('"+materilsCollect.stream().collect(Collectors.joining("','"))+"')"))
|
||||
.process()
|
||||
.getResultJSONArray(0);
|
||||
log.info("配粉位已有物料:{},移库物料:{}",total_materilas,total_move);
|
||||
//map的key:qk定义为material_id+pcsn
|
||||
Map<String, Double> hasQty = total_materilas.stream().collect(HashMap::new, (map, qty) -> {
|
||||
JSONObject jo = (JSONObject) qty;
|
||||
map.put(jo.getString("qk"), jo.getDouble("canuse_qty"));
|
||||
}, HashMap::putAll);
|
||||
Map<String, Double> moveQty = total_move.stream().collect(HashMap::new, (map, qty) -> {
|
||||
JSONObject jo = (JSONObject) qty;
|
||||
map.put(jo.getString("qk"), jo.getDouble("canuse_qty"));
|
||||
}, HashMap::putAll);
|
||||
//需要移库的库存
|
||||
List<JSONObject> need_move = new ArrayList<>();
|
||||
for (Object o : dtlArr) {
|
||||
JSONObject item = (JSONObject) o;
|
||||
return set.contains(item.getString("material_type_id"));
|
||||
}).map(a -> ((JSONObject) a).getString("material_id")).collect(Collectors.toList());
|
||||
List<String> movList = new ArrayList<>();
|
||||
for (int i = 0; i < dtlArr.size(); i++) {
|
||||
JSONObject jsonFormDtl = dtlArr.getJSONObject(i);
|
||||
String material_id = jsonFormDtl.getString("material_id");
|
||||
String formuladtl_id = jsonFormDtl.getString("formuladtl_id");
|
||||
String pcsn = jsonFormDtl.getString("pcsn");
|
||||
/*
|
||||
* 计算未领重量:未领重量=剩余需投料 - 当前可用数 - 正在移库数
|
||||
*/
|
||||
// 1.计算剩余需投料: 剩余需投料=此配方明细的重量-已投料重量
|
||||
double subQty = NumberUtil.sub(jsonFormDtl.getDoubleValue("formula_qty"), jsonFormDtl.getDoubleValue("put_qty"));
|
||||
// 2.查询当前配粉工位的所有上料位
|
||||
// 3.查询当前可用数:当前可用数=sum(此配粉工位点位仓位此物料可用数)
|
||||
double canuse_qty = 0.0; // 总当前可用数
|
||||
if (ObjectUtil.isNotEmpty(jsonDeviceArr)) {
|
||||
for (int j = 0; j < jsonDeviceArr.size(); j++) {
|
||||
JSONObject json = jsonDeviceArr.getJSONObject(j);
|
||||
JSONObject jsonObject = WQLObject.getWQLObject("sch_base_point").query("point_id ='" + json.getString("point_uuid") + "'").uniqueResult(0);
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("flag", "1");
|
||||
map.put("point_uuid", jsonObject.getString("source_id"));
|
||||
map.put("pcsn", pcsn);
|
||||
map.put("material_id", material_id);
|
||||
JSONObject jsonIvt = WQL.getWO("QPDM_BI_FORMULA02").addParamMap(map).process().uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(jsonIvt))
|
||||
canuse_qty = NumberUtil.add(canuse_qty, jsonIvt.getDoubleValue("canuse_qty"));
|
||||
}
|
||||
String material_id = item.getString("material_id");
|
||||
String pcsn = item.getString("pcsn");
|
||||
//校验配粉位有没有位置没有跳过
|
||||
if (g_material.contains(material_id)?g_points.size()==0:notG_points.size()==0){
|
||||
continue;
|
||||
}
|
||||
// 4.查询正在移库数:正在移库数=sum(未完成移库单、此工令、此物料移库数量)
|
||||
String workorder_id = jsonFormMst.getString("workorder_id"); // 工令标识
|
||||
JSONObject jsonMoveDtl = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "2").addParam("workorder_id", workorder_id).addParam("material_id", material_id).addParam("pcsn", pcsn).process().uniqueResult(0);
|
||||
double move_qty = 0.0; // 正在移库数
|
||||
if (ObjectUtil.isNotEmpty(jsonMoveDtl)) {
|
||||
move_qty = jsonMoveDtl.getDoubleValue("qty");
|
||||
//3
|
||||
double subQty = NumberUtil.sub(item.getDoubleValue("formula_qty"), item.getDoubleValue("put_qty"));
|
||||
Double 配粉位_hasQty = hasQty.get(item.getString("material_id") + item.getString("pcsn"));
|
||||
Double 移库种_hasQty = moveQty.get(item.getString("material_id") + item.getString("pcsn"));
|
||||
double uncla_qty = Double.parseDouble(String.valueOf(NumberUtil.sub(subQty, 配粉位_hasQty, 移库种_hasQty)));
|
||||
if (uncla_qty<=0){
|
||||
continue;
|
||||
}
|
||||
// 5.计算未领重量:未领重量=剩余需投料 - 当前可用数 - 正在移库数
|
||||
double uncla_qty = Double.parseDouble(String.valueOf(NumberUtil.sub(subQty, canuse_qty, move_qty)));
|
||||
// 6.判断物料是否为钴粉
|
||||
boolean is_GF = GFSet.contains(material_id);
|
||||
|
||||
/*
|
||||
* 对获取的物料未领重量生成配粉移库单
|
||||
*/
|
||||
// 1.查询移出货位:此物料批次、未锁定、可用数量>=未领重量,按可用数量排序的第一个货位物料; 取不到:此物料批次、未锁定
|
||||
JSONObject moveOutIvt = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "3").addParam("uncla_qty", String.valueOf(uncla_qty)).addParam("material_id", material_id).addParam("pcsn", pcsn).process().uniqueResult(0);
|
||||
// 2.如果为空:说明需要进行多次生成移库任务
|
||||
if (ObjectUtil.isEmpty(moveOutIvt)) {
|
||||
JSONArray moveOutIvtArr = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "4").addParam("material_id", material_id).addParam("pcsn", pcsn).process().getResultJSONArray(0);
|
||||
if (ObjectUtil.isNotEmpty(moveOutIvtArr)) {
|
||||
for (int k = 0; k < moveOutIvtArr.size(); k++) {
|
||||
JSONObject jsonMoveOutIvt = moveOutIvtArr.getJSONObject(k); // 移出货位
|
||||
double canuse_qty1 = jsonMoveOutIvt.getDoubleValue("canuse_qty");
|
||||
// 3.判断未领重量是否 <= 0 ,如果是则跳出循环
|
||||
if (uncla_qty <= 0) break;
|
||||
// 4.查找移入货位,判断物料是否是钴粉
|
||||
JSONObject moveInIvt = new JSONObject();
|
||||
if (is_GF) {
|
||||
moveInIvt = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "5").addParam("device_id", whereJson.getString("device_id")).process().uniqueResult(0);
|
||||
} else {
|
||||
moveInIvt = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "9").addParam("device_id", whereJson.getString("device_id")).process().uniqueResult(0);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(moveInIvt)) break;
|
||||
// 5.生成移库单
|
||||
//校验点位是否有执行中任务:
|
||||
;
|
||||
JSONArray runingtask = WQLObject.getWQLObject("SCH_BASE_Task").query("next_point_code = '" + moveInIvt.getString("point_code") + "' and task_status <> '99' and is_delete = '0'").getResultJSONArray(0);
|
||||
if (runingtask.size()>0){
|
||||
throw new BadRequestException("分配点位存在未完成任务:"+moveInIvt.getString("point_code"));
|
||||
}
|
||||
JSONObject map = new JSONObject();
|
||||
JSONArray tableData = new JSONArray();
|
||||
map.put("bill_status", "10");
|
||||
map.put("bill_type", "21");
|
||||
map.put("biz_date", DateUtil.today());
|
||||
map.put("stor_code", "01");
|
||||
map.put("stor_id", "1473161852946092032");
|
||||
map.put("stor_name", "原材料库");
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("edit", true);
|
||||
param.put("is_active", jsonMoveOutIvt.getString("is_active"));
|
||||
param.put("ivt_level", jsonMoveOutIvt.getString("ivt_level"));
|
||||
param.put("material_id", jsonMoveOutIvt.getString("material_id"));
|
||||
param.put("pcsn", jsonMoveOutIvt.getString("pcsn"));
|
||||
param.put("qty", jsonMoveOutIvt.getString("canuse_qty"));
|
||||
param.put("qty_unit_id", jsonMoveOutIvt.getString("qty_unit_id"));
|
||||
param.put("quality_scode", jsonMoveOutIvt.getString("quality_scode"));
|
||||
JSONObject trunIn = strucTab.query("struct_code = '" + moveInIvt.getString("point_code") + "'").uniqueResult(0);
|
||||
JSONObject trunOut = strucTab.query("struct_code = '" + jsonMoveOutIvt.getString("struct_code") + "'").uniqueResult(0);
|
||||
param.put("turnin_sect_id", trunIn.getString("sect_id"));
|
||||
param.put("turnin_sect_code", trunIn.getString("sect_code"));
|
||||
param.put("turnin_sect_name", trunIn.getString("sect_name"));
|
||||
param.put("turnin_struct_id", trunIn.getString("struct_id"));
|
||||
param.put("turnin_struct_code", trunIn.getString("struct_code"));
|
||||
param.put("turnin_struct_name", trunIn.getString("struct_name"));
|
||||
param.put("turnout_sect_id", trunOut.getString("sect_id"));
|
||||
param.put("turnout_sect_code", trunOut.getString("sect_code"));
|
||||
param.put("turnout_sect_name", trunOut.getString("sect_name"));
|
||||
param.put("turnout_struct_id", trunOut.getString("struct_id"));
|
||||
param.put("turnout_struct_code", trunOut.getString("struct_code"));
|
||||
param.put("turnout_struct_name", trunOut.getString("struct_name"));
|
||||
param.put("storagevehicle_code", trunOut.getString("storagevehicle_code"));
|
||||
param.put("work_status", "10");
|
||||
param.put("source_billdtl_id", formuladtl_id);
|
||||
tableData.add(param);
|
||||
map.put("tableData", tableData);
|
||||
String moveinv_id = handMoveStorService.insertDtl2(map);
|
||||
// 6.下发移库单
|
||||
movList.add(moveinv_id);
|
||||
// 7.下发移库单后减去未领重量
|
||||
uncla_qty = NumberUtil.sub(uncla_qty, canuse_qty1);
|
||||
// 回馈任务数
|
||||
taskNum = String.valueOf(NumberUtil.add(taskNum, "1"));
|
||||
}
|
||||
} else {
|
||||
// 没有找到移出货位 ,说明没有物料
|
||||
arr.add(jsonFormDtl.getString("material_id"));
|
||||
}
|
||||
} else {
|
||||
// 8.到这一步说明没有进入步骤 2
|
||||
// 8.1 查找移入货位,判断物料是否是钴粉
|
||||
if (uncla_qty > 0) {
|
||||
JSONObject moveInIvt2 = new JSONObject();
|
||||
if (is_GF) {
|
||||
moveInIvt2 = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "5").addParam("device_id", whereJson.getString("device_id")).process().uniqueResult(0);
|
||||
} else {
|
||||
moveInIvt2 = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "9").addParam("device_id", whereJson.getString("device_id")).process().uniqueResult(0);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(moveInIvt2)) {
|
||||
// 8.2 生成移库单
|
||||
JSONObject map = new JSONObject();
|
||||
JSONArray tableData = new JSONArray();
|
||||
map.put("bill_status", "10");
|
||||
map.put("bill_type", "21");
|
||||
map.put("biz_date", DateUtil.today());
|
||||
map.put("stor_code", "01");
|
||||
map.put("stor_id", "1473161852946092032");
|
||||
map.put("stor_name", "原材料库");
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("edit", true);
|
||||
param.put("is_active", moveOutIvt.getString("is_active"));
|
||||
param.put("ivt_level", moveOutIvt.getString("ivt_level"));
|
||||
param.put("material_id", moveOutIvt.getString("material_id"));
|
||||
param.put("pcsn", moveOutIvt.getString("pcsn"));
|
||||
param.put("qty", moveOutIvt.getString("canuse_qty"));
|
||||
param.put("qty_unit_id", moveOutIvt.getString("qty_unit_id"));
|
||||
param.put("quality_scode", moveOutIvt.getString("quality_scode"));
|
||||
JSONObject trunIn = strucTab.query("struct_code = '" + moveInIvt2.getString("point_code") + "'").uniqueResult(0);
|
||||
JSONObject trunOut = strucTab.query("struct_code = '" + moveOutIvt.getString("struct_code") + "'").uniqueResult(0);
|
||||
param.put("turnin_sect_id", trunIn.getString("sect_id"));
|
||||
param.put("turnin_sect_code", trunIn.getString("sect_code"));
|
||||
param.put("turnin_sect_name", trunIn.getString("sect_name"));
|
||||
param.put("turnin_struct_id", trunIn.getString("struct_id"));
|
||||
param.put("turnin_struct_code", trunIn.getString("struct_code"));
|
||||
param.put("turnin_struct_name", trunIn.getString("struct_name"));
|
||||
param.put("turnout_sect_id", trunOut.getString("sect_id"));
|
||||
param.put("turnout_sect_code", trunOut.getString("sect_code"));
|
||||
param.put("turnout_sect_name", trunOut.getString("sect_name"));
|
||||
param.put("turnout_struct_id", trunOut.getString("struct_id"));
|
||||
param.put("turnout_struct_code", trunOut.getString("struct_code"));
|
||||
param.put("turnout_struct_name", trunOut.getString("struct_name"));
|
||||
param.put("storagevehicle_code", trunOut.getString("storagevehicle_code"));
|
||||
param.put("work_status", "10");
|
||||
param.put("source_billdtl_id", formuladtl_id);
|
||||
tableData.add(param);
|
||||
map.put("tableData", tableData);
|
||||
String moveinv_id = handMoveStorService.insertDtl2(map);
|
||||
// 6.下发移库单
|
||||
movList.add(moveinv_id);
|
||||
// 回馈任务数
|
||||
taskNum = String.valueOf(NumberUtil.add(taskNum, "1"));
|
||||
} else {
|
||||
arr2.add(String.valueOf(i));
|
||||
//4 库存:从小到大
|
||||
JSONArray 库存_qty = WQL.getWO("QMD_FORMING01")
|
||||
.addParam("flag", "5")
|
||||
.addParam("material_id", material_id)
|
||||
.addParam("pcsn", pcsn).process()
|
||||
.getResultJSONArray(0);
|
||||
if (库存_qty.size()==0){
|
||||
log.info("叫料失败,此配方明细批次:"+pcsn+"/物料:"+material_id+"没有库存");
|
||||
continue;
|
||||
}
|
||||
// double total = 库存_qty.stream().mapToDouble(item1 -> ((JSONObject) item1).getDoubleValue("canuse_qty")).sum();
|
||||
//不够也叫过来 if (total<uncla_qty){ throw new BadRequestException("叫料失败,库存总数:"+total+"小于需要数量"+uncla_qty+"批次"+pcsn+"/"+material_id); }
|
||||
JSONObject max_qty = 库存_qty.getJSONObject(库存_qty.size()-1);
|
||||
//如果存在偏差>0的则直接叫一次料
|
||||
if (max_qty.getDoubleValue("canuse_qty")>=uncla_qty){
|
||||
double finalUncla_qty = uncla_qty;
|
||||
JSONObject deviation = (JSONObject) 库存_qty.stream().filter(o1 -> ((JSONObject) o1).getDoubleValue("canuse_qty") >= finalUncla_qty).findFirst().get();
|
||||
deviation.put("source_billdtl_id",item.getString("formuladtl_id"));
|
||||
need_move.add(deviation);
|
||||
}else {
|
||||
//循环叫料
|
||||
for (int i = 库存_qty.size()-1; i >=0; i--) {
|
||||
if (uncla_qty<=0){
|
||||
break;
|
||||
}
|
||||
JSONObject ivt = 库存_qty.getJSONObject(i);
|
||||
ivt.put("source_billdtl_id",item.getString("formuladtl_id"));
|
||||
need_move.add(ivt);
|
||||
//扣减剩余数
|
||||
uncla_qty = NumberUtil.sub(uncla_qty, ivt.getDoubleValue("canuse_qty"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dtlArr.size() == arr.size()) throw new BadRequestException("叫料失败,此配方明细没有符合的库存");
|
||||
if (dtlArr.size() == arr2.size()) throw new BadRequestException("叫料失败,配粉间没有空位");
|
||||
result.put("task", taskNum);
|
||||
flourworkService.asyncdown(movList,SecurityUtils.getCurrentUserId(),SecurityUtils.getNickName());
|
||||
|
||||
log.info("待移库信息:{}",need_move);
|
||||
List<JSONObject> moveForm = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(need_move)){
|
||||
for (JSONObject move_ivt : need_move) {
|
||||
String material_id = move_ivt.getString("material_id");
|
||||
JSONObject in_point = null;
|
||||
if (g_material.contains(material_id )){
|
||||
if (g_points.size()>0){
|
||||
in_point= g_points.remove(0);
|
||||
}
|
||||
}else if (notG_points.size()>0){
|
||||
if (notG_points.size()>0){
|
||||
in_point= notG_points.remove(0);
|
||||
}
|
||||
}
|
||||
if (in_point==null){
|
||||
continue;
|
||||
};
|
||||
// 8.2 生成移库单
|
||||
JSONObject map = packageMoveForm(move_ivt, in_point);
|
||||
moveForm.add(map);
|
||||
}
|
||||
List<String> moveList = new ArrayList<>();
|
||||
for (JSONObject map : moveForm) {
|
||||
String move_id = handMoveStorService.insertDtl2(map);
|
||||
moveList.add(move_id);
|
||||
}
|
||||
flourworkService.asyncdown(moveList,SecurityUtils.getCurrentUserId(),SecurityUtils.getNickName());
|
||||
}
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("task", moveForm.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
private JSONObject packageMoveForm(JSONObject move_ivt, JSONObject in_point) {
|
||||
JSONObject map = new JSONObject();
|
||||
JSONArray tableData = new JSONArray();
|
||||
map.put("bill_status", "10");
|
||||
map.put("bill_type", "21");
|
||||
map.put("biz_date", DateUtil.today());
|
||||
map.put("stor_code", "01");
|
||||
map.put("stor_id", "1473161852946092032");
|
||||
map.put("stor_name", "原材料库");
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("edit", true);
|
||||
param.put("is_active", move_ivt.getString("is_active"));
|
||||
param.put("ivt_level", move_ivt.getString("ivt_level"));
|
||||
param.put("material_id", move_ivt.getString("material_id"));
|
||||
param.put("pcsn", move_ivt.getString("pcsn"));
|
||||
param.put("qty", move_ivt.getString("canuse_qty"));
|
||||
param.put("qty_unit_id", move_ivt.getString("qty_unit_id"));
|
||||
param.put("quality_scode", move_ivt.getString("quality_scode"));
|
||||
param.put("turnin_sect_id", in_point.getString("sect_id"));
|
||||
param.put("turnin_sect_code", in_point.getString("sect_code"));
|
||||
param.put("turnin_sect_name", in_point.getString("sect_name"));
|
||||
param.put("turnin_struct_id", in_point.getString("struct_id"));
|
||||
param.put("turnin_struct_code", in_point.getString("struct_code"));
|
||||
param.put("turnin_struct_name", in_point.getString("struct_name"));
|
||||
param.put("turnout_sect_id", move_ivt.getString("sect_id"));
|
||||
param.put("turnout_sect_code", move_ivt.getString("sect_code"));
|
||||
param.put("turnout_sect_name", move_ivt.getString("sect_name"));
|
||||
param.put("turnout_struct_id", move_ivt.getString("struct_id"));
|
||||
param.put("turnout_struct_code", move_ivt.getString("struct_code"));
|
||||
param.put("turnout_struct_name", move_ivt.getString("struct_name"));
|
||||
param.put("storagevehicle_code", move_ivt.getString("storagevehicle_code"));
|
||||
param.put("work_status", "10");
|
||||
param.put("source_billdtl_id", move_ivt.getString("source_billdtl_id"));
|
||||
tableData.add(param);
|
||||
map.put("tableData", tableData);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject autoCalledMater2(JSONObject whereJson) {
|
||||
ArrayList<String> striings = new ArrayList<String>();
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
输入.flag TYPEAS s_string
|
||||
输入.classIds TYPEAS f_string
|
||||
输入.class_id TYPEAS s_string
|
||||
输入.device_uuid TYPEAS s_string
|
||||
输入.workorder_id TYPEAS s_string
|
||||
输入.material_id TYPEAS s_string
|
||||
输入.pcsn TYPEAS s_string
|
||||
输入.materials TYPEAS f_string
|
||||
输入.uncla_qty TYPEAS s_string
|
||||
[临时表]
|
||||
--这边列出来的临时表就会在运行期动态创建
|
||||
|
||||
@@ -89,5 +95,120 @@
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
|
||||
IF 输入.flag = "3"
|
||||
QUERY
|
||||
SELECT
|
||||
SCH_BASE_DevicePointPara.device_uuid,
|
||||
sum(ST_IVT_StructIvt.canuse_qty) canuse_qty,
|
||||
CONCAT(ST_IVT_StructIvt.material_id,ST_IVT_StructIvt.pcsn) qk,
|
||||
GROUP_CONCAT(SCH_BASE_DevicePointPara.point_code) point_code
|
||||
FROM sch_base_point
|
||||
left join SCH_BASE_DevicePointPara on SCH_BASE_DevicePointPara.point_code=sch_base_point.point_code
|
||||
left join ST_IVT_StructIvt on ST_IVT_StructIvt.struct_id = sch_base_point.source_id
|
||||
WHERE
|
||||
1=1
|
||||
OPTION 输入.device_uuid <> ""
|
||||
SCH_BASE_DevicePointPara.device_uuid = 输入.device_uuid
|
||||
ENDOPTION
|
||||
and canuse_qty > 0
|
||||
OPTION 输入.materials <> ""
|
||||
ST_IVT_StructIvt.material_id in 输入.materials
|
||||
ENDOPTION
|
||||
group by ST_IVT_StructIvt.material_id,ST_IVT_StructIvt.pcsn
|
||||
ENDSELECT
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
|
||||
IF 输入.flag = "4"
|
||||
QUERY
|
||||
SELECT
|
||||
SUM(invdtl.qty) AS qty,
|
||||
CONCAT(invdtl.material_id,invdtl.pcsn) qk,
|
||||
invdtl.material_id,
|
||||
moveinvdtl_id
|
||||
FROM
|
||||
ST_IVT_MoveInvDtl invdtl
|
||||
LEFT JOIN PDM_BI_FormulaDtl formdtl ON formdtl.formuladtl_id = invdtl.source_billdtl_id
|
||||
LEFT JOIN PDM_BI_Formula formmst ON formmst.formula_id = formdtl.formula_id
|
||||
WHERE
|
||||
invdtl.work_status = '02'
|
||||
OPTION 输入.workorder_id <> ""
|
||||
formmst.workorder_id = 输入.workorder_id
|
||||
ENDOPTION
|
||||
OPTION 输入.materials <> ""
|
||||
invdtl.material_id in 输入.materials
|
||||
ENDOPTION
|
||||
group by invdtl.material_id,invdtl.pcsn
|
||||
|
||||
ENDSELECT
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
IF 输入.flag = "5"
|
||||
QUERY
|
||||
SELECT
|
||||
ivt.canuse_qty,
|
||||
ivt.qty_unit_id,
|
||||
ivt.quality_scode,
|
||||
ivt.ivt_level,
|
||||
att.storagevehicle_code,
|
||||
ivt.material_id,
|
||||
ivt.pcsn,
|
||||
ivt.is_active,
|
||||
ivt.struct_code,ivt.struct_name,ivt.struct_id,
|
||||
att.sect_id,att.sect_code,att.sect_name
|
||||
FROM
|
||||
ST_IVT_StructIvt ivt
|
||||
LEFT JOIN sch_base_point point ON point.point_code = ivt.struct_code
|
||||
LEFT JOIN st_ivt_structattr att on ivt.struct_code = att.struct_code
|
||||
WHERE
|
||||
point.lock_type = '00'
|
||||
AND ivt.canuse_qty > 0
|
||||
AND point.area_type not in('22','23','24')
|
||||
|
||||
OPTION 输入.material_id <> ""
|
||||
ivt.material_id = 输入.material_id
|
||||
ENDOPTION
|
||||
OPTION 输入.pcsn <> ""
|
||||
ivt.pcsn = 输入.pcsn
|
||||
ENDOPTION
|
||||
order by ivt.canuse_qty ASC
|
||||
ENDSELECT
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
IF 输入.flag = "6"
|
||||
QUERY
|
||||
SELECT
|
||||
device.point_code,
|
||||
LOCATE('钴',device.point_name) as has,
|
||||
att.sect_code,att.sect_name,sect_id,att.struct_id,att.struct_code,att.struct_name
|
||||
FROM
|
||||
SCH_BASE_DevicePointPara device
|
||||
LEFT JOIN sch_base_point point ON point.point_id = device.point_uuid
|
||||
LEFT JOIN st_ivt_structattr att ON att.struct_code = device.point_code
|
||||
WHERE
|
||||
point.lock_type = '00'
|
||||
AND point.vehicle_code = ''
|
||||
AND point.point_status = '00'
|
||||
AND device.point_type = '03'
|
||||
OPTION 输入.device_uuid <> ""
|
||||
device.device_uuid = 输入.device_uuid
|
||||
ENDOPTION
|
||||
AND point.point_code NOT IN (
|
||||
SELECT
|
||||
sch_base_point.point_code
|
||||
FROM
|
||||
sch_base_point
|
||||
LEFT JOIN sch_base_task ON sch_base_task.next_point_code = sch_base_point.point_code
|
||||
LEFT JOIN SCH_BASE_DevicePointPara device on sch_base_point.point_id = device.point_uuid
|
||||
WHERE
|
||||
1=1
|
||||
OPTION 输入.device_uuid <> ""
|
||||
device.device_uuid = 输入.device_uuid
|
||||
ENDOPTION
|
||||
AND task_status <> '99'
|
||||
AND sch_base_task.is_delete = '0'
|
||||
);
|
||||
ENDSELECT
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
|
||||
|
||||
@@ -428,13 +428,17 @@ public class HandMoveStorServiceImpl implements HandMoveStorService {
|
||||
}
|
||||
//判断是否已生成过了任务,无未生成则插入任务
|
||||
JSONObject task = wo_Task.query("is_delete = '0' and taskdtl_type='07' and task_status='01' and start_point_code='" + jo.getString("start_point_code") + "'").uniqueResult(0);
|
||||
|
||||
if (task != null) {
|
||||
jo.put("task_id", task.getString("task_id"));
|
||||
} else {
|
||||
JSONObject checkTask = wo_Task.query("is_delete = '0' and taskdtl_type='07' and task_status<>'99' and next_point_code='" + point.getString("point_code") + "'").uniqueResult(0);
|
||||
if (checkTask!=null){
|
||||
throw new BadRequestException("当前点位"+point.getString("point_code")+"已经生成任务"+checkTask.getString("task_code"));
|
||||
}
|
||||
task = new JSONObject();
|
||||
String task_id = IdUtil.getSnowflake(1, 1).nextId() + "";
|
||||
String task_code = CodeUtil.getNewCode("TASK_CODE");
|
||||
|
||||
task.put("taskdtl_id", task_id);
|
||||
task.put("task_id", task_id);
|
||||
task.put("task_code", task_code);
|
||||
|
||||
Reference in New Issue
Block a user