@@ -5,6 +5,7 @@ package org.nl.wms.basedata.master.service.impl;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.map.MapUtil ;
import cn.hutool.core.util.IdUtil ;
import cn.hutool.core.util.NumberUtil ;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import com.alibaba.fastjson.JSON ;
@@ -20,6 +21,7 @@ import org.nl.wms.basedata.master.service.MaterialParametersService;
import org.nl.wms.basedata.master.service.MaterialbaseService ;
import org.nl.wms.basedata.master.service.dto.MaterialParametersDto ;
import org.nl.wms.basedata.master.service.dto.MaterialbaseDto ;
import org.nl.wms.basedata.pdm.service.impl.WastecchangeServiceImpl ;
import org.nl.wql.WQL ;
import org.nl.wql.core.bean.WQLObject ;
import org.nl.wql.util.WqlUtil ;
@@ -318,4 +320,149 @@ public class MaterialParametersServiceImpl implements MaterialParametersService
return resultJSONArray ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public JSONObject sync ( JSONObject whereJson ) {
/*
* 1.PG粉碳平衡修正
* 2.软废碳平衡修正
*/
WQLObject productMstTab = WQLObject . getWQLObject ( " MD_PD_ProductBOM " ) ; // 产品bom单主表
WQLObject productDtlTab = WQLObject . getWQLObject ( " MD_PD_ProductBOMDtl " ) ; // 产品bom单明细表
WQLObject wasTab = WQLObject . getWQLObject ( " PDM_BI_WasteCChange " ) ; // 软废碳平衡修正表
WQLObject materTab = WQLObject . getWQLObject ( " md_me_materialbase " ) ; // 物料表
WQLObject extTab = WQLObject . getWQLObject ( " MD_ME_ProducMaterialExt " ) ; // 成品物料扩展信息表
JSONObject result = new JSONObject ( ) ;
// 1.判断此物料是PG粉还是RF
boolean is_pgf = materialbaseService . isAlongMaterType ( MaterOptTypeEnum . PGF . getCode ( ) , whereJson . getString ( " material_id " ) , null ) ;
boolean is_rf = materialbaseService . isAlongMaterType ( MaterOptTypeEnum . RF . getCode ( ) , whereJson . getString ( " material_id " ) , null ) ;
String material_id = whereJson . getString ( " material_id " ) ;
JSONObject jsonMater = materTab . query ( " material_id = ' " + material_id + " ' " ) . uniqueResult ( 0 ) ;
JSONObject jsonExtMater = extTab . query ( " material_id = ' " + material_id + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( jsonExtMater ) ) throw new BadRequestException ( " 此PGF扩展属性不存在 " ) ;
if ( is_pgf ) {
/*
* PG粉碳平衡修正:
* 1.查询此PG粉产品bom明细表第一个碳化钨
* 2.查询此碳化钨 软废碳平衡修正表获得全部软废类型的值
* 3.查询软废:物料表,软废编码 = PG粉编码 + '-CF'
* 4.依次修改16种软废类型的碳平衡
* 软废碳平衡=pg粉碳平衡+CF修正值
*/
// 1.查询此物料的产品bom明细表中第一个出现的碳化钨
// 查主表
JSONObject jsonProductMst = productMstTab . query ( " material_id = ' " + material_id + " ' and is_used = '1' and is_delete = '0' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( jsonProductMst ) ) throw new BadRequestException ( " 此产品没有创建bom单或者已删除、未启用 " ) ;
// 查明细
JSONArray productDtlArr = productDtlTab . query ( " bom_id = ' " + jsonProductMst . getString ( " bom_id " ) + " ' order by seqno ASC " ) . getResultJSONArray ( 0 ) ;
if ( ObjectUtil . isEmpty ( productDtlArr ) ) throw new BadRequestException ( " 此产品bom单暂无明细 " ) ;
// 找出第一个碳化钨
String thw_material_id = " " ;
for ( int i = 0 ; i < productDtlArr . size ( ) ; i + + ) {
JSONObject jsonProductDtl = productDtlArr . getJSONObject ( i ) ;
boolean is_thw = materialbaseService . isAlongMaterType ( MaterOptTypeEnum . THW . getCode ( ) , jsonProductDtl . getString ( " material_id " ) , null ) ;
if ( is_thw ) {
thw_material_id = jsonProductDtl . getString ( " material_id " ) ;
break ;
}
}
// 2.查询此碳化钨 软废碳平衡修正表获得全部软废类型的值 并转化成数组(便于处理数据)
JSONObject jsonThwMater = materTab . query ( " material_id = ' " + thw_material_id + " ' " ) . uniqueResult ( 0 ) ;
JSONObject jsonWas = wasTab . query ( " material_id = ' " + thw_material_id + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( jsonWas ) ) throw new BadRequestException ( " 此碳化钨软废修正数据不存在: " + jsonThwMater . getString ( " material_code " ) ) ;
// 将此碳化钨的软废类型转化为数组
JSONArray wasArr = new WastecchangeServiceImpl ( ) . contentShift ( jsonWas ) ;
// 3.查询软废:物料表,软废编码 = PG粉编码 + '-CF' (以软废类型CF为例)
for ( int j = 0 ; j < wasArr . size ( ) ; j + + ) {
JSONObject jsonWasDtl = wasArr . getJSONObject ( j ) ;
String rf_type_code = jsonMater . getString ( " material_code " ) + " - " + jsonWasDtl . getString ( " name " ) ;
JSONObject jsonRfMater = materTab . query ( " material_code = ' " + rf_type_code + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isNotEmpty ( jsonRfMater ) ) {
// 4.依次修改16种软废类型的碳平衡: 软废碳平衡=pg粉碳平衡+CF修正值
JSONObject jsonRfExt = extTab . query ( " material_id = ' " + jsonRfMater . getString ( " material_id " ) + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( jsonRfExt ) ) throw new BadRequestException ( " 此软废扩展信息不存在: " + rf_type_code ) ;
double rf_c_balance = NumberUtil . add ( jsonExtMater . getDoubleValue ( " c_balance " ) , jsonWasDtl . getDoubleValue ( " value " ) ) ;
jsonRfExt . put ( " c_balance " , String . valueOf ( rf_c_balance ) ) ;
extTab . update ( jsonRfExt ) ;
}
}
result . put ( " c_balance " , " " ) ;
}
if ( is_rf ) {
/*
* 软废粉碳平衡修正:
* 1.找PG粉: 查物料表: PG粉编码 = 此软废编码去掉最后一个'-'和后面的内容
* 2.找碳化钨: 此PG粉产品BOM明细第一个碳化钨
* 3.找修正值:废类型为编码最后'-'后的内容 : 如JZ16-P-A2-20-JY : 软废类型就是 JY
* 查此碳化钨的软废修正表对应的软废类型:软废碳平衡=pg粉碳平衡+此软废修正值
* 4.最后将计算后的值返回给页面
*/
// 1.找PG粉: 查物料表: PG粉编码 = 此软废编码去掉最后一个'-'和后面的内容
String pg_material_code = jsonMater . getString ( " material_code " ) . substring ( 0 , jsonMater . getString ( " material_code " ) . lastIndexOf ( " - " ) ) ;
JSONObject jsonPgfMater = materTab . query ( " material_code = ' " + pg_material_code + " ' " ) . uniqueResult ( 0 ) ;
// 2.找碳化钨: 此PG粉产品BOM明细第一个碳化钨
// 查主表
JSONObject jsonProductMst = productMstTab . query ( " material_id = ' " + jsonPgfMater . getString ( " material_id " ) + " ' and is_used = '1' and is_delete = '0' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( jsonProductMst ) ) throw new BadRequestException ( " 此产品没有创建bom单或者已删除、未启用 " + pg_material_code ) ;
// 查明细
JSONArray productDtlArr = productDtlTab . query ( " bom_id = ' " + jsonProductMst . getString ( " bom_id " ) + " ' order by seqno ASC " ) . getResultJSONArray ( 0 ) ;
if ( ObjectUtil . isEmpty ( productDtlArr ) ) throw new BadRequestException ( " 此产品bom单暂无明细 " + pg_material_code ) ;
// 找出第一个碳化钨
String thw_material_id = " " ;
for ( int i = 0 ; i < productDtlArr . size ( ) ; i + + ) {
JSONObject jsonProductDtl = productDtlArr . getJSONObject ( i ) ;
boolean is_thw = materialbaseService . isAlongMaterType ( MaterOptTypeEnum . THW . getCode ( ) , jsonProductDtl . getString ( " material_id " ) , null ) ;
if ( is_thw ) {
thw_material_id = jsonProductDtl . getString ( " material_id " ) ;
break ;
}
}
// 3.找修正值:废类型为编码最后'-'后的内容
JSONObject jsonThwMater = materTab . query ( " material_id = ' " + thw_material_id + " ' " ) . uniqueResult ( 0 ) ;
JSONObject jsonWas = wasTab . query ( " material_id = ' " + thw_material_id + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( jsonWas ) ) throw new BadRequestException ( " 此碳化钨软废修正数据不存在: " + jsonThwMater . getString ( " material_name " ) ) ;
// 将此碳化钨的软废类型转化为数组
JSONArray wasArr = new WastecchangeServiceImpl ( ) . contentShift ( jsonWas ) ;
String rf_type_code = jsonMater . getString ( " material_code " ) . substring ( jsonMater . getString ( " material_code " ) . lastIndexOf ( " - " ) + 1 , jsonMater . getString ( " material_code " ) . length ( ) ) ;
double value = 0 ;
for ( int j = 0 ; j < wasArr . size ( ) ; j + + ) {
JSONObject jsonWasDtl = wasArr . getJSONObject ( j ) ;
if ( StrUtil . equals ( rf_type_code , jsonWasDtl . getString ( " name " ) ) ) {
value = jsonWasDtl . getDoubleValue ( " value " ) ;
break ;
}
}
// 软废碳平衡=pg粉碳平衡+此软废修正值
JSONObject jsonPgfExt = extTab . query ( " material_id = ' " + jsonPgfMater . getString ( " material_id " ) + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( jsonPgfExt ) ) throw new BadRequestException ( " 此PG粉扩展属性不存在: " + pg_material_code ) ;
double c_balance = NumberUtil . add ( jsonPgfExt . getDoubleValue ( " c_balance " ) , value ) ;
result . put ( " c_balance " , String . valueOf ( c_balance ) ) ;
}
return result ;
}
}