This commit is contained in:
2022-10-19 19:52:48 +08:00
2 changed files with 153 additions and 18 deletions

View File

@@ -20,6 +20,7 @@ import org.nl.wql.core.bean.WQLObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
@@ -81,6 +82,9 @@ public class AutoformulaServiceImpl implements AutoformulaService {
double new_qty = workorder_qty;
//纯粉重量
double net_qty = workorder_qty;
//rf最高开单重量
HashMap<String,JSONObject> rf_plan_map = new HashMap<String,JSONObject>();
if(waste_limit_down==0 && waste_limit_up==0){//不添加软废
//新料配粉环节
JSONObject ret = this.autoCalculationBy01_xinliao(json);
@@ -129,6 +133,7 @@ public class AutoformulaServiceImpl implements AutoformulaService {
for(int i=0;i<MaterialSets.size();i++){
JSONObject MaterialSet = MaterialSets.getJSONObject(i);
String set_material_id = MaterialSet.getString("set_material_id");
double add_rate = MaterialSet.getDouble("add_rate");
JSONArray now_ivts = WQL.getWO("QPF_AUTOFORMULA01")
.addParam("material_id",set_material_id)
.addParam("is_active",value_is_active)
@@ -136,7 +141,21 @@ public class AutoformulaServiceImpl implements AutoformulaService {
.addParam("workorder_id",workorder_id)
.addParam("flag","22")
.process().getResultJSONArray(0);
ivts.addAll(now_ivts);
for(int j=0;j<now_ivts.size();j++){
JSONObject jo = now_ivts.getJSONObject(j);
double can_qty = net_qty*add_rate/100.0;
JSONObject jo2 = new JSONObject();
jo2.put("can_qty",can_qty);
jo2.put("can_left_qty",can_qty);
rf_plan_map.put(set_material_id,jo2);
double sum_ivt_qty = jo.getDouble("sum_ivt_qty");
if(can_qty >= sum_ivt_qty){
jo.put("can_qty",sum_ivt_qty);
}else{
jo.put("can_qty",can_qty);
}
ivts.add(jo);
}
}
if(ivts.size()!=0){
//软废纯粉库存总量
@@ -145,7 +164,13 @@ public class AutoformulaServiceImpl implements AutoformulaService {
for(int i=0;i<ivts.size();i++){
JSONObject ivt = ivts.getJSONObject(i);
String ivt_material_id = ivt.getString("material_id");
if(ivt.getDouble("sum_ivt_qty")<=0 || ivt.getDouble("sum_ivt_qty")<0.01){
double can_qty = ivt.getDouble("can_qty");
if(can_qty<=0 || can_qty<0.01){
continue;
}
JSONObject can_jo = rf_plan_map.get(ivt_material_id);
double can_left_qty = can_jo.getDouble("can_left_qty");
if(can_left_qty <=0){
continue;
}
JSONObject ProductMaterialExt = MD_ME_ProductMaterialExt.query("material_id='"+ivt_material_id+"'").uniqueResult(0);
@@ -156,7 +181,15 @@ public class AutoformulaServiceImpl implements AutoformulaService {
if(net_rate==0){
throw new BadRequestException("软废"+ivt.getString("material_code")+" "+ivt.getString("material_name")+"未配置纯粉系数!");
}
double ivt_qty = ivt.getDouble("sum_ivt_qty")*net_rate/100.0;
if(can_qty <= can_left_qty){
can_qty = can_qty;
can_jo.put("can_left_qty",can_left_qty-can_qty);
}else{
can_qty = can_left_qty;
can_jo.put("can_left_qty",can_left_qty-can_qty);
}
rf_plan_map.put(ivt_material_id,can_jo);
double ivt_qty = can_qty*net_rate/100.0;
//Rp*纯粉系数
ivt.put("net_rate_qty",ivt_qty);
//纯粉系数
@@ -1580,6 +1613,8 @@ public class AutoformulaServiceImpl implements AutoformulaService {
double new_qty = workorder_qty;
//纯粉重量
double net_qty = workorder_qty;
//rf最高开单重量
HashMap<String,JSONObject> rf_plan_map = new HashMap<String,JSONObject>();
//1.需添加软废
if(waste_limit_down==100 || waste_limit_up== 100){
throw new BadRequestException("软废含量上限或下限不能等于100%");
@@ -1620,7 +1655,22 @@ public class AutoformulaServiceImpl implements AutoformulaService {
.addParam("quality_scode","02")
.addParam("flag","22")
.process().getResultJSONArray(0);
ivts.addAll(now_ivts);
double add_rate = MaterialSet.getDouble("add_rate");
for(int j=0;j<now_ivts.size();j++){
JSONObject jo = now_ivts.getJSONObject(j);
double can_qty = net_qty*add_rate/100.0;
JSONObject jo2 = new JSONObject();
jo2.put("can_qty",can_qty);
jo2.put("can_left_qty",can_qty);
rf_plan_map.put(set_material_id,jo2);
double sum_ivt_qty = jo.getDouble("sum_ivt_qty");
if(can_qty >= sum_ivt_qty){
jo.put("can_qty",sum_ivt_qty);
}else{
jo.put("can_qty",can_qty);
}
ivts.add(jo);
}
}
if(ivts.size()!=0){
//软废纯粉库存总量
@@ -1628,7 +1678,7 @@ public class AutoformulaServiceImpl implements AutoformulaService {
JSONArray ivts_new = new JSONArray();
for(int i=0;i<ivts.size();i++){
JSONObject ivt = ivts.getJSONObject(i);
if(ivt.getDouble("sum_ivt_qty")<=0 || ivt.getDouble("sum_ivt_qty")<0.01){
if(ivt.getDouble("can_qty")<=0 || ivt.getDouble("can_qty")<0.01){
continue;
}
String ivt_material_id = ivt.getString("material_id");
@@ -1640,7 +1690,7 @@ public class AutoformulaServiceImpl implements AutoformulaService {
if(net_rate==0){
throw new BadRequestException("软废"+ivt.getString("material_code")+" "+ivt.getString("material_name")+"未配置纯粉系数!");
}
double ivt_qty = ivt.getDouble("sum_ivt_qty")*net_rate/100.0;
double ivt_qty = ivt.getDouble("can_qty")*net_rate/100.0;
//Rp*纯粉系数
ivt.put("net_rate_qty",ivt_qty);
//纯粉系数
@@ -1651,7 +1701,7 @@ public class AutoformulaServiceImpl implements AutoformulaService {
rf_ivts = rf_ivts + ivt_qty;
}
if(rf_ivts>=waste_limit_down_weight){
Number rf_left_weight = waste_limit_up_weight;;
Number rf_left_weight = waste_limit_up_weight;
//需配软废总重
double rf_total_weight = 0;
//需配软废纯粉总重
@@ -1659,7 +1709,8 @@ public class AutoformulaServiceImpl implements AutoformulaService {
for(int i=0;i<ivts_new.size();i++){
JSONObject ivt_new = ivts_new.getJSONObject(i);
//可分配库存重量
double ivt_qty = ivt_new.getDouble("sum_ivt_qty");
double ivt_qty = ivt_new.getDouble("can_qty");
//纯粉系数
double net_rate = ivt_new.getDouble("net_rate");
ivt_qty = NumberUtil.roundDown(ivt_qty,3).doubleValue();
@@ -1670,6 +1721,19 @@ public class AutoformulaServiceImpl implements AutoformulaService {
}else{
formula_qty = rf_up;
}
String rf_material_id = ivt_new.getString("material_id");
JSONObject can_jo = rf_plan_map.get(rf_material_id);
double can_left_qty = can_jo.getDouble("can_left_qty");
if(can_left_qty <=0){
continue;
}
if(can_left_qty<= formula_qty){
formula_qty = can_left_qty;
}else{
formula_qty = formula_qty;
}
double now_ivt_qty = formula_qty * net_rate / 100.0;
//已分配软废总量
@@ -1678,6 +1742,10 @@ public class AutoformulaServiceImpl implements AutoformulaService {
rf_left_weight = NumberUtil.round(NumberUtil.sub(rf_left_weight,now_ivt_qty),3);
//累加软废纯粉重量
rf_net_total_weight = rf_net_total_weight + now_ivt_qty;
BigDecimal formula_qty_now = NumberUtil.round(formula_qty,3);
can_jo.put("can_left_qty",can_left_qty-formula_qty_now.doubleValue());
rf_plan_map.put(rf_material_id,can_jo);
//分配软废重量
ivt_new.put("formula_qty",NumberUtil.round(formula_qty,3));
//纯粉重量
@@ -1686,9 +1754,7 @@ public class AutoformulaServiceImpl implements AutoformulaService {
ivt_new.put("is_need_move","1");
ivt_new.put("is_need_manage","1");
ivt_new.put("is_rf_xl","1");
//获取软废Bom统计软废总含碳化钨
String rf_material_id = ivt_new.getString("material_id");
JSONArray rf_bomdlts = WQL.getWO("QPF_AUTOFORMULA01")
.addParam("material_id",rf_material_id)
.addParam("is_need_manage","1")
@@ -2826,6 +2892,10 @@ public class AutoformulaServiceImpl implements AutoformulaService {
double new_qty = workorder_qty;
//纯粉重量
double net_qty = workorder_qty;
//rf最高开单重量
HashMap<String,JSONObject> rf_plan_map = new HashMap<String,JSONObject>();
if(waste_limit_up!=0){//添加软废
//R下
double waste_limit_down_weight = workorder_qty * waste_limit_down/100.0;
@@ -2869,7 +2939,23 @@ public class AutoformulaServiceImpl implements AutoformulaService {
.addParam("workorder_id",workorder_id)
.addParam("flag","22")
.process().getResultJSONArray(0);
ivts.addAll(now_ivts);
double add_rate = MaterialSet.getDouble("add_rate");
for(int j=0;j<now_ivts.size();j++){
JSONObject jo = now_ivts.getJSONObject(j);
double can_qty = net_qty*add_rate/100.0;
JSONObject jo2 = new JSONObject();
jo2.put("can_qty",can_qty);
jo2.put("can_left_qty",can_qty);
rf_plan_map.put(set_material_id,jo2);
double sum_ivt_qty = jo.getDouble("sum_ivt_qty");
if(can_qty >= sum_ivt_qty){
jo.put("can_qty",sum_ivt_qty);
}else{
jo.put("can_qty",can_qty);
}
ivts.add(jo);
}
}
if(ivts.size()!=0){
//软废纯粉库存总量
@@ -2877,10 +2963,17 @@ public class AutoformulaServiceImpl implements AutoformulaService {
JSONArray ivts_new = new JSONArray();
for(int i=0;i<ivts.size();i++){
JSONObject ivt = ivts.getJSONObject(i);
if(ivt.getDouble("sum_ivt_qty") <=0 || ivt.getDouble("sum_ivt_qty") <0.01){
double can_qty = ivt.getDouble("can_qty");
if(ivt.getDouble("can_qty") <=0 || ivt.getDouble("can_qty") <0.01){
continue;
}
String ivt_material_id = ivt.getString("material_id");
JSONObject can_jo = rf_plan_map.get(ivt_material_id);
double can_left_qty = can_jo.getDouble("can_left_qty");
if(can_left_qty <=0){
continue;
}
JSONObject ProductMaterialExt = MD_ME_ProductMaterialExt.query("material_id='"+ivt_material_id+"'").uniqueResult(0);
if(ProductMaterialExt ==null){
throw new BadRequestException("软废"+ivt.getString("material_code")+" "+ivt.getString("material_name")+"未配置成品物料扩展信息!");
@@ -2889,7 +2982,15 @@ public class AutoformulaServiceImpl implements AutoformulaService {
if(net_rate==0){
throw new BadRequestException("软废"+ivt.getString("material_code")+" "+ivt.getString("material_name")+"未配置纯粉系数!");
}
double ivt_qty = ivt.getDouble("sum_ivt_qty")*net_rate/100.0;
if(can_qty <= can_left_qty){
can_qty = can_qty;
can_jo.put("can_left_qty",can_left_qty-can_qty);
}else{
can_qty = can_left_qty;
can_jo.put("can_left_qty",can_left_qty-can_qty);
}
rf_plan_map.put(ivt_material_id,can_jo);
double ivt_qty = can_qty*net_rate/100.0;
//Rp*纯粉系数
ivt.put("net_rate_qty",ivt_qty);
//纯粉系数
@@ -3140,6 +3241,9 @@ public class AutoformulaServiceImpl implements AutoformulaService {
//1.需添加软废
//R下
double waste_limit_down_weight = workorder_qty * waste_limit_down/100.0;
//rf最高开单重量
HashMap<String,JSONObject> rf_plan_map = new HashMap<String,JSONObject>();
//获取可分配的软废集合
JSONArray MaterialSets = WQL.getWO("QPF_AUTOFORMULA01")
.addParam("material_id",material_id)
@@ -3171,7 +3275,23 @@ public class AutoformulaServiceImpl implements AutoformulaService {
.addParam("workorder_id",workorder_id)
.addParam("flag","22")
.process().getResultJSONArray(0);
ivts.addAll(now_ivts);
double add_rate = MaterialSet.getDouble("add_rate");
for(int j=0;j<now_ivts.size();j++){
JSONObject jo = now_ivts.getJSONObject(j);
double can_qty = net_qty*add_rate/100.0;
JSONObject jo2 = new JSONObject();
jo2.put("can_qty",can_qty);
jo2.put("can_left_qty",can_qty);
rf_plan_map.put(set_material_id,jo2);
double sum_ivt_qty = jo.getDouble("sum_ivt_qty");
if(can_qty >= sum_ivt_qty){
jo.put("can_qty",sum_ivt_qty);
}else{
jo.put("can_qty",can_qty);
}
ivts.add(jo);
}
}
if(ivts.size()!=0){
//1.计算配粉所需重量环节
@@ -3211,10 +3331,11 @@ public class AutoformulaServiceImpl implements AutoformulaService {
JSONArray ivts_new = new JSONArray();
for(int i=0;i<ivts.size();i++){
JSONObject ivt = ivts.getJSONObject(i);
if(ivt.getDouble("sum_ivt_qty") <=0 || ivt.getDouble("sum_ivt_qty") <0.01){
if(ivt.getDouble("can_qty") <=0 || ivt.getDouble("can_qty") <0.01){
continue;
}
String ivt_material_id = ivt.getString("material_id");
JSONObject ProductMaterialExt = MD_ME_ProductMaterialExt.query("material_id='"+ivt_material_id+"'").uniqueResult(0);
if(ProductMaterialExt ==null){
throw new BadRequestException("软废"+ivt.getString("material_code")+" "+ivt.getString("material_name")+"未配置成品物料扩展信息!");
@@ -3223,7 +3344,8 @@ public class AutoformulaServiceImpl implements AutoformulaService {
if(net_rate==0){
throw new BadRequestException("软废"+ivt.getString("material_code")+" "+ivt.getString("material_name")+"未配置纯粉系数!");
}
double net_rate_qty = ivt.getDouble("sum_ivt_qty")*net_rate/100.0;
double net_rate_qty = ivt.getDouble("can_qty")*net_rate/100.0;
//Rp*纯粉系数
ivt.put("net_rate_qty",net_rate_qty);
//纯粉系数
@@ -3241,18 +3363,26 @@ public class AutoformulaServiceImpl implements AutoformulaService {
outer:
for(int i=0;i<ivts_new.size();i++){
JSONObject ivt_new = ivts_new.getJSONObject(i);
double ivt_qty = ivt_new.getDouble("sum_ivt_qty");
double ivt_qty = ivt_new.getDouble("can_qty");
ivt_qty = NumberUtil.roundDown(ivt_qty,3).doubleValue();
if(ivt_qty <=0){
continue;
}
String rf_material_id = ivt_new.getString("material_id");
JSONObject can_jo = rf_plan_map.get(rf_material_id);
double can_left_qty = can_jo.getDouble("can_left_qty");
if(can_left_qty <=0){
continue;
}
//软废纯粉系数
double net_rate = ivt_new.getDouble("net_rate");
String rf_material_id = ivt_new.getString("material_id");
//计算R1p=min(Y1/h1/纯粉系数X1/h2/纯粉系数X2/h3/纯粉系数...)
//c、更新R1p=min(R1,R1p)
List<Double> doubles = new ArrayList<Double>();
doubles.add(ivt_qty);
doubles.add(can_left_qty);
//doubles集合
HashMap<String,JSONObject> doubles_map = new HashMap<String,JSONObject>();
//获取软废Bom
@@ -3294,6 +3424,10 @@ public class AutoformulaServiceImpl implements AutoformulaService {
//进行集合排序
Collections.sort(doubles);
double rf_up_formula_qty = doubles.get(0);
can_jo.put("can_left_qty",can_left_qty-rf_up_formula_qty);
rf_plan_map.put(rf_material_id,can_jo);
//计算不需要移库的添加剂
doubles_map.forEach((key,fi_bomdtl)->{
String fi_bomdtl_material_id = fi_bomdtl.getString("material_id");

View File

@@ -339,6 +339,7 @@
WHERE
1 = 1
and producmaterialext.net_rate>0
and ProductMaterialSet.add_rate>0
OPTION 输入.material_id <> ""
ProductMaterialSet.material_id = 输入.material_id
ENDOPTION