From c96a961af3f8731bb0e1e5bf5cb35cc0eed9cee0 Mon Sep 17 00:00:00 2001 From: zds <2388969634@qq.com> Date: Thu, 29 Sep 2022 21:12:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/AutoformulaServiceImpl.java | 571 ++++++++++-------- 1 file changed, 327 insertions(+), 244 deletions(-) diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/AutoformulaServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/AutoformulaServiceImpl.java index 43c1ed9a..ff0433a8 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/AutoformulaServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/AutoformulaServiceImpl.java @@ -608,6 +608,7 @@ public class AutoformulaServiceImpl implements AutoformulaService { else{//抑制剂 bomdlt.put("finished_qty",0); bomdlt.put("need_sum_qty",nedd_qty); + bomdlt.put("z1_sum",0); yzj_map.put(bomdtl_material_id,bomdlt); } } @@ -670,7 +671,8 @@ public class AutoformulaServiceImpl implements AutoformulaService { }else //需配碳粉 if(CT1 Z_sum = new AtomicReference<>(0.0); + AtomicReference Z_sum_per = new AtomicReference<>(0.0); //计算不需要移库的添加剂(抑制剂) yzj_map.forEach((key,tjj_map_jo)->{ //获取添加剂id @@ -690,12 +693,13 @@ public class AutoformulaServiceImpl implements AutoformulaService { .process() .uniqueResult(0); if(tjj_finished!=null){ - //已配重量 - double finished_qty = tjj_map_jo.getDouble("finished_qty"); //质保书含量比 double value = tjj_finished.getDouble("value"); //当前含量重量 double finished = X22p*value/100.0; + + //累计各碳化钨中已含添加剂重量百分比 + Z_sum_per.set(Z_sum_per.get() + value/100.0); //累计各碳化钨中已含添加剂重量 Z_sum.set(Z_sum.get() + finished); } @@ -705,14 +709,15 @@ public class AutoformulaServiceImpl implements AutoformulaService { JSONObject FactoryWarranty = bomdlts_plan_map.get(bomdlt_Cr3C2.getString("stockrecord_id")); //该批次含碳比 double X22 = FactoryWarranty.getDouble("is_tan"); - //X22p减=[产品碳平衡*(X11p+X12p+X21p+X22p+软废碳化钨)-(X11p* X11碳含量+X12p* X12碳含量+X21p* X21碳含量+X22p* X22碳含量+软废含碳量)]/(1-X22碳含量) - double X22_jian = ((c_balance/100.0)*(CT1_weight)-CT1)/(1-X22/100.0); + //X22p减=(产品碳平衡*(Z_sum已+CT1_weight)-CT1-Z_sum已)/(1- X22碳含量- X22Z1含量+产品碳平衡*X22Z1含量) + + double X22_jian = ((c_balance/100.0)*(CT1_weight+Z_sum.get())-CT1-Z_sum.get())/(1-X22/100.0-Z_sum_per.get()+(c_balance/100.0)*Z_sum_per.get()); //更新碳化钨配粉重量 double bom_ivt_qty = X22p-X22_jian; if(bom_ivt_qty < 0){ throw new BadRequestException("碳化钨配粉结果为负数,当前配粉无解!"); } - double C = X22_jian; + double C = X22_jian + bom_ivt_qty*Z_sum_per.get(); if(C < 0){ throw new BadRequestException("补碳结果为负数,当前配粉无解!"); }else if(C >= 0){ @@ -741,9 +746,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { yzj_map.put(tjj_material_id,tjj_map_jo); } }); - - //统计除钨以外其他总重 - AtomicReference total_sum = new AtomicReference<>(0.0); //判断已含添加剂与需配添加剂大小 yzj_map.forEach((key,tjj_map_now)->{ //需配添加剂重量 @@ -761,7 +763,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { tjj_map_now.put("is_active","1"); tjj_map_now.put("quality_scode","01"); yzj_list.add(tjj_map_now); - total_sum.set(total_sum.get()+need_qty-finished_qty); } }); if(C>0){ @@ -780,32 +781,12 @@ public class AutoformulaServiceImpl implements AutoformulaService { C_weight.put("is_active","1"); C_weight.put("quality_scode","01"); cw_list.add(C_weight); - total_sum.set(total_sum.get()+C); - } - bomdlts_plan_map.forEach((key,bomdlts_plan_now)->{ - //需配添加剂重量 - double bom_ivt_qty_now = NumberUtil.round(bomdlts_plan_now.getDouble("bom_ivt_qty"),3).doubleValue(); - total_sum.set(total_sum.get() + bom_ivt_qty_now); - }); - double W = new_qty - total_sum.get(); - if(W>0){ - JSONObject W_weight = new JSONObject(); - W_weight.put("formula_qty",W); - //钨分类id - W_weight.put("material_id","1503644362234531840"); - W_weight.put("material_name","钨粉"); - W_weight.put("material_code","09030103"); - W_weight.put("material_type","02"); - W_weight.put("is_need_move","0"); - W_weight.put("is_need_manage","1"); - W_weight.put("is_rf_xl","0"); - W_weight.put("ivt_level","01"); - W_weight.put("is_active","1"); - W_weight.put("quality_scode","01"); - cw_list.add(W_weight); } + } - }else{//大于等于2条库粗你明细时 + } + //大于等于2条库粗你明细时 + else{ //最后一个为X22p JSONObject bomdlt_Cr3C2_X22p = bomdlts_Cr3C2.getJSONObject(bomdlts_Cr3C2.size()-1); //倒数第二为X21p @@ -827,38 +808,43 @@ public class AutoformulaServiceImpl implements AutoformulaService { double X21c = X21p*X21/100.0; - AtomicReference Z_sum = new AtomicReference<>(0.0); - //循环碳化钨 - for(int i=0;i{ - //获取添加剂id - String tjj_material_id = tjj_map_jo.getString("material_id"); - JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") - .addParam("material_id",jo.getString("material_id")) - .addParam("pcsn",jo.getString("pcsn")) - .addParam("item_material_id",tjj_material_id) - .addParam("flag","5") - .process() - .uniqueResult(0); - if(tjj_finished!=null){ - //质保书含量比 - double value = tjj_finished.getDouble("value"); - //当前含量重量 - double finished = bom_ivt_qty_jo*value/100.0; - //累计各碳化钨中已含添加剂重量 - Z_sum.set(Z_sum.get() + finished); - } - }); - } - boolean flag = true; //设X21p减=0,解方程 if(flag){ - //X22p减=[产品碳平衡*(X11p+X12p+X21p+X22p+软废碳化钨)-(X11p* X11碳含量+X12p* X12碳含量+X21p* X21碳含量+X22p* X22碳含量+软废含碳量)]/(1-X22碳含量) - double X22_jian = ((c_balance/100.0)*(CT1_weight)-CT1)/(1-X22/100.0); + AtomicReference Z_sum = new AtomicReference<>(0.0); + AtomicReference Z_sum_per = new AtomicReference<>(0.0); + //循环碳化钨 + for(int i=0;i{ + //获取添加剂id + String tjj_material_id = tjj_map_jo.getString("material_id"); + JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") + .addParam("material_id",jo.getString("material_id")) + .addParam("pcsn",jo.getString("pcsn")) + .addParam("item_material_id",tjj_material_id) + .addParam("flag","5") + .process() + .uniqueResult(0); + if(tjj_finished!=null){ + //质保书含量比 + double value = tjj_finished.getDouble("value"); + //当前含量重量 + double finished = bom_ivt_qty_jo*value/100.0; + //累计各碳化钨中已含添加剂重量百分比 + if(stockrecord_id.equals(bomdlt_Cr3C2_X22p.getString("stockrecord_id"))){ + Z_sum_per.set(Z_sum_per.get() + value/100.0); + } + //累计各碳化钨中已含添加剂重量 + Z_sum.set(Z_sum.get() + finished); + } + }); + } + //X22p减=(产品碳平衡*(Z_sum已+CT1_weight)-CT1-Z_sum已)/(1- X22碳含量- X22Z1含量+产品碳平衡*X22Z1含量) + double X22_jian = ((c_balance/100.0)*(CT1_weight+Z_sum.get())-CT1-Z_sum.get())/(1-X22/100.0-Z_sum_per.get()+(c_balance/100.0)*Z_sum_per.get()); //更新碳化钨配粉重量 double bom_ivt_qty = X22p-X22_jian; if(bom_ivt_qty<0){ @@ -866,6 +852,41 @@ public class AutoformulaServiceImpl implements AutoformulaService { }else{ //解得钨粉重量 double C = X22_jian; + //统计除钨以外其他总重 + AtomicReference total_sum = new AtomicReference<>(0.0); + //循环碳化钨 + for(int i=0;i{ + //获取添加剂id + String tjj_material_id = tjj_map_jo.getString("material_id"); + JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") + .addParam("material_id",jo.getString("material_id")) + .addParam("pcsn",jo.getString("pcsn")) + .addParam("item_material_id",tjj_material_id) + .addParam("flag","5") + .process() + .uniqueResult(0); + if(tjj_finished!=null){ + //已配重量 + double finished_qty = tjj_map_jo.getDouble("finished_qty"); + //质保书含量比 + double value = tjj_finished.getDouble("value"); + //当前含量重量 + double finished = finalBom_ivt_qty_jo *value/100.0; + //累计各碳化钨中已含添加剂重量 + total_sum.set(total_sum.get()+finished); + } + }); + } + C = C + total_sum.get(); if(C<0){ flag = false; }else if(C>=0){ @@ -903,8 +924,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { }); } - //统计除钨以外其他总重 - AtomicReference total_sum = new AtomicReference<>(0.0); //判断已含添加剂与需配添加剂大小 yzj_map.forEach((key,tjj_map_now)->{ //需配添加剂重量 @@ -922,7 +941,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { tjj_map_now.put("is_active","1"); tjj_map_now.put("quality_scode","01"); yzj_list.add(tjj_map_now); - total_sum.set(total_sum.get()+need_qty-finished_qty); } }); @@ -944,43 +962,94 @@ public class AutoformulaServiceImpl implements AutoformulaService { cw_list.add(C_weight); total_sum.set(total_sum.get()+C); } - bomdlts_plan_map.forEach((key,bomdlts_plan_now)->{ - //需配添加剂重量 - double bom_ivt_qty_now = NumberUtil.round(bomdlts_plan_now.getDouble("bom_ivt_qty"),3).doubleValue(); - total_sum.set(total_sum.get() + bom_ivt_qty_now); - }); - double W = new_qty - total_sum.get(); - if(W>0 && W>=0.001){ - JSONObject W_weight = new JSONObject(); - W_weight.put("formula_qty",W); - //钨分类id - W_weight.put("material_id","1503644362234531840"); - W_weight.put("material_name","钨粉"); - W_weight.put("material_code","09030103"); - W_weight.put("material_type","02"); - W_weight.put("is_need_move","0"); - W_weight.put("is_need_manage","1"); - W_weight.put("is_rf_xl","0"); - W_weight.put("ivt_level","01"); - W_weight.put("is_active","1"); - W_weight.put("quality_scode","01"); - cw_list.add(W_weight); - } } } } if(!flag){ + AtomicReference Z_sum = new AtomicReference<>(0.0); + AtomicReference Z22_sum_per = new AtomicReference<>(0.0); + AtomicReference Z21_sum_per = new AtomicReference<>(0.0); + //循环碳化钨 + for(int i=0;i{ + //获取添加剂id + String tjj_material_id = tjj_map_jo.getString("material_id"); + JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") + .addParam("material_id",jo.getString("material_id")) + .addParam("pcsn",jo.getString("pcsn")) + .addParam("item_material_id",tjj_material_id) + .addParam("flag","5") + .process() + .uniqueResult(0); + if(tjj_finished!=null){ + //质保书含量比 + double value = tjj_finished.getDouble("value"); + //当前含量重量 + double finished = bom_ivt_qty_jo*value/100.0; + //累计各碳化钨中已含添加剂重量百分比 + if(stockrecord_id.equals(bomdlt_Cr3C2_X21p.getString("stockrecord_id"))){ + Z21_sum_per.set(Z21_sum_per.get() + value/100.0); + } + if(stockrecord_id.equals(bomdlt_Cr3C2_X22p.getString("stockrecord_id"))){ + Z22_sum_per.set(Z22_sum_per.get() + value/100.0); + } + //累计各碳化钨中已含添加剂重量 + Z_sum.set(Z_sum.get() + finished); + } + }); + } //设X22p减=X22p,解方程 // X21p减=[产品碳平衡*(X11p+X12p+X21p+X22p+Z已总) - (X11p* X11碳含量+X12p* X12碳含量+(X21p)* X21碳含量+Z已总+X22p)]/(1-X21碳含量) - double X21_jian = ((c_balance/100.0)*(CT1_weight) - (CT1-X22c) - X22p)/(1-X21/100.0); + //X21p减=[(CT1_weight+z_sum已-X22p含抑制剂总和)*产品碳平衡-( CT1-X22p* X22碳含量+X22p)-(z_sum已-X22p含抑制剂总和)]/(1-X21碳含量-X21p抑制剂总含量+X21p抑制剂总含量*产品碳平衡) + double X21_jian = ((c_balance/100.0)*(CT1_weight+Z_sum.get()-Z22_sum_per.get()) - (CT1+X22p-X22p*X22c/100.0) -(Z_sum.get()-Z22_sum_per.get()))/(1-X21/100.0-Z21_sum_per.get() +Z21_sum_per.get()*(c_balance/100.0)); + + //更新碳化钨配粉重量 + double bom_ivt_qty = X21p-X21_jian; + //统计除钨以外其他总重 + AtomicReference total_sum = new AtomicReference<>(0.0); + //循环碳化钨 + for(int i=0;i{ + //获取添加剂id + String tjj_material_id = tjj_map_jo.getString("material_id"); + JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") + .addParam("material_id",jo.getString("material_id")) + .addParam("pcsn",jo.getString("pcsn")) + .addParam("item_material_id",tjj_material_id) + .addParam("flag","5") + .process() + .uniqueResult(0); + if(tjj_finished!=null){ + //质保书含量比 + double value = tjj_finished.getDouble("value"); + //当前含量重量 + double finished = finalBom_ivt_qty_jo *value/100.0; + //累计各碳化钨中已含添加剂重量 + total_sum.set(total_sum.get() + finished); + } + }); + } //解得钨粉重量 - double C = X22p + X21_jian; + double C = X22p + X21_jian+total_sum.get(); if(C<0){ throw new BadRequestException("加碳粉为负数,当前配粉无解!"); }else if(C>=0){ - //更新碳化钨配粉重量 - double bom_ivt_qty = X21p-X21_jian; if(bom_ivt_qty<0){ throw new BadRequestException("碳化钨倒数第二条配粉结果为负数,当前配粉无解!"); } @@ -1018,8 +1087,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { } }); } - //统计除钨以外其他总重 - AtomicReference total_sum = new AtomicReference<>(0.0); //判断已含添加剂与需配添加剂大小 yzj_map.forEach((key,tjj_map_now)->{ //需配添加剂重量 @@ -1037,7 +1104,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { tjj_map_now.put("is_active","1"); tjj_map_now.put("quality_scode","01"); yzj_list.add(tjj_map_now); - total_sum.set(total_sum.get() + need_qty-finished_qty); } }); @@ -1057,29 +1123,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { C_weight.put("is_active","1"); C_weight.put("quality_scode","01"); cw_list.add(C_weight); - total_sum.set(total_sum.get()+C); - } - bomdlts_plan_map.forEach((key,bomdlts_plan_now)->{ - //需配添加剂重量 - double bom_ivt_qty_now = NumberUtil.round(bomdlts_plan_now.getDouble("bom_ivt_qty"),3).doubleValue(); - total_sum.set(total_sum.get() + bom_ivt_qty_now); - }); - double W = new_qty - total_sum.get(); - if(W>0 && W>=0.001){ - JSONObject W_weight = new JSONObject(); - W_weight.put("formula_qty",W); - //钨分类id - W_weight.put("material_id","1503644362234531840"); - W_weight.put("material_name","钨粉"); - W_weight.put("material_code","09030103"); - W_weight.put("material_type","02"); - W_weight.put("is_need_move","0"); - W_weight.put("is_need_manage","1"); - W_weight.put("is_rf_xl","0"); - W_weight.put("ivt_level","01"); - W_weight.put("is_active","1"); - W_weight.put("quality_scode","01"); - cw_list.add(W_weight); } } } @@ -1844,7 +1887,8 @@ public class AutoformulaServiceImpl implements AutoformulaService { }else //需配碳粉 if(CT1 Z_sum = new AtomicReference<>(0.0); + AtomicReference Z_sum_per = new AtomicReference<>(0.0); //计算不需要移库的添加剂(抑制剂) tjj_map.forEach((key,tjj_map_jo)->{ //获取添加剂id @@ -1868,24 +1913,27 @@ public class AutoformulaServiceImpl implements AutoformulaService { .uniqueResult(0); if(tjj_finished!=null){ //质保书含量比 - double value_jo = tjj_finished.getDouble("value"); + double tjj_finished_value = tjj_finished.getDouble("value"); //当前含量重量 - double finished = X22p*value_jo/100.0; + double finished = X22p*tjj_finished_value/100.0; + + //累计各碳化钨中已含添加剂重量百分比 + Z_sum_per.set(Z_sum_per.get() + tjj_finished_value/100.0); //累计各碳化钨中已含添加剂重量 Z_sum.set(Z_sum.get() + finished); } }); - //X22p减=[产品碳平衡*(X11p+X12p+X21p+X22p+软废碳化钨)-(X11p* X11碳含量+X12p* X12碳含量+X21p* X21碳含量+X22p* X22碳含量+软废含碳量)]/(1-X22碳含量) - double X22_jian = ((c_balance/100.0)*(CT1_weight)-CT1)/(1-X22/100.0); + //X22p减=(产品碳平衡*(Z_sum已+CT1_weight)-CT1-Z_sum已)/(1- X22碳含量- X22Z1含量+产品碳平衡*X22Z1含量) + + double X22_jian = ((c_balance/100.0)*(CT1_weight+Z_sum.get())-CT1-Z_sum.get())/(1-X22/100.0-Z_sum_per.get()+(c_balance/100.0)*Z_sum_per.get()); //更新碳化钨配粉重量 double bom_ivt_qty = X22p-X22_jian; if(bom_ivt_qty < 0){ throw new BadRequestException("碳化钨配粉结果为负数,当前配粉无解!"); } - double C = X22_jian; - - if(C<0){ - throw new BadRequestException("加碳粉为负数,当前配粉无解!"); + double C = X22_jian + bom_ivt_qty*Z_sum_per.get(); + if(C < 0){ + throw new BadRequestException("补碳结果为负数,当前配粉无解!"); } bomdlt_Cr3C2.put("bom_ivt_qty",bom_ivt_qty); bomdlts_plan_map.put(bomdlt_Cr3C2.getString("stockrecord_id"),bomdlt_Cr3C2); @@ -1912,8 +1960,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { tjj_map.put(tjj_material_id,tjj_map_jo); } }); - //统计除钨以外其他总重 - AtomicReference total_sum = new AtomicReference<>(0.0); if(C>0){ JSONObject C_weight = new JSONObject(); @@ -1931,13 +1977,7 @@ public class AutoformulaServiceImpl implements AutoformulaService { C_weight.put("is_active","1"); C_weight.put("quality_scode","01"); cw_list.add(C_weight); - total_sum.set(total_sum.get() + C); } - bomdlts_plan_map.forEach((key,bomdlts_plan_now)->{ - //需配添加剂重量 - double bom_ivt_qty_now = NumberUtil.round(bomdlts_plan_now.getDouble("bom_ivt_qty"),3).doubleValue(); - total_sum.set(total_sum.get() + bom_ivt_qty_now); - }); //判断已含添加剂与需配添加剂大小 tjj_map.forEach((key,tjj_map_now)->{ //需配添加剂重量 @@ -1955,27 +1995,11 @@ public class AutoformulaServiceImpl implements AutoformulaService { tjj_map_now.put("is_active","1"); tjj_map_now.put("quality_scode","01"); yzj_list.add(tjj_map_now); - total_sum.set(total_sum.get() + need_qty-finished_qty); } }); - double W = new_qty - total_sum.get(); - if(W>0){ - JSONObject W_weight = new JSONObject(); - W_weight.put("formula_qty",W); - //钨分类id - W_weight.put("material_id","1503644362234531840"); - W_weight.put("material_name","钨粉"); - W_weight.put("material_code","09030103"); - W_weight.put("material_type","02"); - W_weight.put("is_need_move","0"); - W_weight.put("is_need_manage","1"); - W_weight.put("is_rf_xl","0"); - W_weight.put("ivt_level","01"); - W_weight.put("is_active","1"); - W_weight.put("quality_scode","01"); - cw_list.add(W_weight); - } - }else{//大于等于2条库粗你明细时 + } + //大于等于2条库粗你明细时 + else{ //最后一个为X22p JSONObject bomdlt_Cr3C2_X22p = bomdlts_Cr3C2.getJSONObject(bomdlts_Cr3C2.size()-1); //倒数第二为X21p @@ -1997,38 +2021,43 @@ public class AutoformulaServiceImpl implements AutoformulaService { double X21c = X21p*X21/100.0; - AtomicReference Z_sum = new AtomicReference<>(0.0); - //循环碳化钨 - for(int i=0;i{ - //获取添加剂id - String tjj_material_id = tjj_map_jo.getString("material_id"); - JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") - .addParam("material_id",jo.getString("material_id")) - .addParam("pcsn",jo.getString("pcsn")) - .addParam("item_material_id",tjj_material_id) - .addParam("flag","5") - .process() - .uniqueResult(0); - if(tjj_finished!=null){ - //质保书含量比 - double value_jo = tjj_finished.getDouble("value"); - //当前含量重量 - double finished = bom_ivt_qty_jo*value_jo/100.0; - //累计各碳化钨中已含添加剂重量 - Z_sum.set(Z_sum.get() + finished); - } - }); - } - boolean flag = true; //设X21p减=0,解方程 if(flag){ - //X22p减=[产品碳平衡*(X11p+X12p+X21p+X22p+软废碳化钨)-(X11p* X11碳含量+X12p* X12碳含量+X21p* X21碳含量+X22p* X22碳含量+软废含碳量)]/(1-X22碳含量) - double X22_jian = ((c_balance/100.0)*(CT1_weight)-CT1)/(1-X22/100.0); + AtomicReference Z_sum = new AtomicReference<>(0.0); + AtomicReference Z_sum_per = new AtomicReference<>(0.0); + //循环碳化钨 + for(int i=0;i{ + //获取添加剂id + String tjj_material_id = tjj_map_jo.getString("material_id"); + JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") + .addParam("material_id",jo.getString("material_id")) + .addParam("pcsn",jo.getString("pcsn")) + .addParam("item_material_id",tjj_material_id) + .addParam("flag","5") + .process() + .uniqueResult(0); + if(tjj_finished!=null){ + //质保书含量比 + double tjj_finished_value = tjj_finished.getDouble("value"); + //当前含量重量 + double finished = bom_ivt_qty_jo*tjj_finished_value/100.0; + //累计各碳化钨中已含添加剂重量百分比 + if(stockrecord_id.equals(bomdlt_Cr3C2_X22p.getString("stockrecord_id"))){ + Z_sum_per.set(Z_sum_per.get() + tjj_finished_value/100.0); + } + //累计各碳化钨中已含添加剂重量 + Z_sum.set(Z_sum.get() + finished); + } + }); + } + //X22p减=(产品碳平衡*(Z_sum已+CT1_weight)-CT1-Z_sum已)/(1- X22碳含量- X22Z1含量+产品碳平衡*X22Z1含量) + double X22_jian = ((c_balance/100.0)*(CT1_weight+Z_sum.get())-CT1-Z_sum.get())/(1-X22/100.0-Z_sum_per.get()+(c_balance/100.0)*Z_sum_per.get()); //更新碳化钨配粉重量 double bom_ivt_qty = X22p-X22_jian; if(bom_ivt_qty<0){ @@ -2036,6 +2065,39 @@ public class AutoformulaServiceImpl implements AutoformulaService { }else{ //解得钨粉重量 double C = X22_jian; + //统计除钨以外其他总重 + AtomicReference total_sum = new AtomicReference<>(0.0); + //循环碳化钨 + for(int i=0;i{ + //获取添加剂id + String tjj_material_id = tjj_map_jo.getString("material_id"); + JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") + .addParam("material_id",jo.getString("material_id")) + .addParam("pcsn",jo.getString("pcsn")) + .addParam("item_material_id",tjj_material_id) + .addParam("flag","5") + .process() + .uniqueResult(0); + if(tjj_finished!=null){ + //质保书含量比 + double tjj_finished_value = tjj_finished.getDouble("value"); + //当前含量重量 + double finished = finalBom_ivt_qty_jo *tjj_finished_value/100.0; + //累计各碳化钨中已含添加剂重量 + total_sum.set(total_sum.get()+finished); + } + }); + } + C = C + total_sum.get(); if(C<0){ flag = false; }else if(C>=0){ @@ -2072,8 +2134,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { } }); } - //统计除钨以外其他总重 - AtomicReference total_sum = new AtomicReference<>(0.0); if(C>0){ JSONObject C_weight = new JSONObject(); @@ -2093,11 +2153,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { cw_list.add(C_weight); total_sum.set(total_sum.get() + C); } - bomdlts_plan_map.forEach((key,bomdlts_plan_now)->{ - //需配添加剂重量 - double bom_ivt_qty_now = NumberUtil.round(bomdlts_plan_now.getDouble("bom_ivt_qty"),3).doubleValue(); - total_sum.set(total_sum.get() + bom_ivt_qty_now); - }); //判断已含添加剂与需配添加剂大小 tjj_map.forEach((key,tjj_map_now)->{ //需配添加剂重量 @@ -2115,40 +2170,95 @@ public class AutoformulaServiceImpl implements AutoformulaService { tjj_map_now.put("is_active","1"); tjj_map_now.put("quality_scode","01"); yzj_list.add(tjj_map_now); - total_sum.set(total_sum.get() + need_qty-finished_qty); } }); - double W = new_qty - total_sum.get(); - if(W>0){ - JSONObject W_weight = new JSONObject(); - W_weight.put("formula_qty",W); - //钨分类id - W_weight.put("material_id","1503644362234531840"); - W_weight.put("material_name","钨粉"); - W_weight.put("material_code","09030103"); - W_weight.put("material_type","02"); - W_weight.put("is_need_move","0"); - W_weight.put("is_need_manage","1"); - W_weight.put("is_rf_xl","0"); - W_weight.put("ivt_level","01"); - W_weight.put("is_active","1"); - W_weight.put("quality_scode","01"); - cw_list.add(W_weight); - } } } } if(!flag){ + AtomicReference Z_sum = new AtomicReference<>(0.0); + AtomicReference Z22_sum_per = new AtomicReference<>(0.0); + AtomicReference Z21_sum_per = new AtomicReference<>(0.0); + //循环碳化钨 + for(int i=0;i{ + //获取添加剂id + String tjj_material_id = tjj_map_jo.getString("material_id"); + JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") + .addParam("material_id",jo.getString("material_id")) + .addParam("pcsn",jo.getString("pcsn")) + .addParam("item_material_id",tjj_material_id) + .addParam("flag","5") + .process() + .uniqueResult(0); + if(tjj_finished!=null){ + //质保书含量比 + double tjj_finished_value = tjj_finished.getDouble("value"); + //当前含量重量 + double finished = bom_ivt_qty_jo*tjj_finished_value/100.0; + //累计各碳化钨中已含添加剂重量百分比 + if(stockrecord_id.equals(bomdlt_Cr3C2_X21p.getString("stockrecord_id"))){ + Z21_sum_per.set(Z21_sum_per.get() + tjj_finished_value/100.0); + } + if(stockrecord_id.equals(bomdlt_Cr3C2_X22p.getString("stockrecord_id"))){ + Z22_sum_per.set(Z22_sum_per.get() + tjj_finished_value/100.0); + } + //累计各碳化钨中已含添加剂重量 + Z_sum.set(Z_sum.get() + finished); + } + }); + } //设X22p减=X22p,解方程 - // X21p减=[产品碳平衡*(X11p+X12p+X21p+X22p+Z已总) - (X11p* X11碳含量+X12p* X12碳含量+(X21p)* X21碳含量+Z已总+X22p)]/(1-X21碳含量) - double X21_jian = ((c_balance/100.0)*(CT1_weight) - (CT1-X22c) - X22p)/(1-X21/100.0); + //X21p减=[(CT1_weight+z_sum已-X22p含抑制剂总和)*产品碳平衡-( CT1-X22p* X22碳含量+X22p)-(z_sum已-X22p含抑制剂总和)]/(1-X21碳含量-X21p抑制剂总含量+X21p抑制剂总含量*产品碳平衡) + + double X21_jian = ((c_balance/100.0)*(CT1_weight+Z_sum.get()-Z22_sum_per.get()) - (CT1+X22p-X22p*X22c/100.0) -(Z_sum.get()-Z22_sum_per.get()))/(1-X21/100.0-Z21_sum_per.get() +Z21_sum_per.get()*(c_balance/100.0)); + + //更新碳化钨配粉重量 + double bom_ivt_qty = X21p-X21_jian; + //统计除钨以外其他总重 + AtomicReference total_sum = new AtomicReference<>(0.0); + //循环碳化钨 + for(int i=0;i{ + //获取添加剂id + String tjj_material_id = tjj_map_jo.getString("material_id"); + JSONObject tjj_finished = WQL.getWO("QPF_AUTOFORMULA01") + .addParam("material_id",jo.getString("material_id")) + .addParam("pcsn",jo.getString("pcsn")) + .addParam("item_material_id",tjj_material_id) + .addParam("flag","5") + .process() + .uniqueResult(0); + if(tjj_finished!=null){ + //质保书含量比 + double tjj_finished_value = tjj_finished.getDouble("value"); + //当前含量重量 + double finished = finalBom_ivt_qty_jo *tjj_finished_value/100.0; + //累计各碳化钨中已含添加剂重量 + total_sum.set(total_sum.get() + finished); + } + }); + } //解得钨粉重量 - double C = X22p + X21_jian; + double C = X22p + X21_jian+total_sum.get(); if(C<0){ throw new BadRequestException("加碳粉为负数,当前配粉无解!"); }else if(C>=0){ - //更新碳化钨配粉重量 - double bom_ivt_qty = X21p-X21_jian; if(bom_ivt_qty<0){ throw new BadRequestException("碳化钨倒数第二条配粉结果为负数,当前配粉无解!"); } @@ -2186,8 +2296,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { } }); } - //统计除钨以外其他总重 - AtomicReference total_sum = new AtomicReference<>(0.0); if(C>0){ JSONObject C_weight = new JSONObject(); @@ -2205,13 +2313,7 @@ public class AutoformulaServiceImpl implements AutoformulaService { C_weight.put("is_active","1"); C_weight.put("quality_scode","01"); cw_list.add(C_weight); - total_sum.set(total_sum.get() + C); } - bomdlts_plan_map.forEach((key,bomdlts_plan_now)->{ - //需配添加剂重量 - double bom_ivt_qty_now = NumberUtil.round(bomdlts_plan_now.getDouble("bom_ivt_qty"),3).doubleValue(); - total_sum.set(total_sum.get() + bom_ivt_qty_now); - }); //判断已含添加剂与需配添加剂大小 tjj_map.forEach((key,tjj_map_now)->{ //需配添加剂重量 @@ -2229,33 +2331,16 @@ public class AutoformulaServiceImpl implements AutoformulaService { tjj_map_now.put("is_active","1"); tjj_map_now.put("quality_scode","01"); yzj_list.add(tjj_map_now); - total_sum.set(total_sum.get() + need_qty-finished_qty); } }); - double W = new_qty - total_sum.get(); - if(W>0){ - JSONObject W_weight = new JSONObject(); - W_weight.put("formula_qty",W); - //钨分类id - W_weight.put("material_id","1503644362234531840"); - W_weight.put("material_name","钨粉"); - W_weight.put("material_code","09030103"); - W_weight.put("material_type","02"); - W_weight.put("is_need_move","0"); - W_weight.put("is_need_manage","1"); - W_weight.put("is_rf_xl","0"); - W_weight.put("ivt_level","01"); - W_weight.put("is_active","1"); - W_weight.put("quality_scode","01"); - cw_list.add(W_weight); - } } } } }else //需配钨粉 if(CT1>CT2){ - if(bomdlts_Cr3C2.size()==1){//只配库存明细时 + //只配库存明细时 + if(bomdlts_Cr3C2.size()==1){ //假设钨粉重量为W JSONObject bomdlt_Cr3C2 = bomdlts_Cr3C2.getJSONObject(0); //获取碳含量 @@ -3405,9 +3490,6 @@ public class AutoformulaServiceImpl implements AutoformulaService { double need_qty = bomdlt.getDouble("formula_qty"); W = NumberUtil.round(W - need_qty,3).doubleValue(); } - /*if(W<0){ - throw new BadRequestException("补钨粉重量为负数,请检查bom及其他参数!"); - }*/ if(W>0){ JSONObject W_weight = new JSONObject(); W_weight.put("formula_qty",W); @@ -3428,7 +3510,8 @@ public class AutoformulaServiceImpl implements AutoformulaService { //需配碳粉 if(CT1