@ -55,20 +55,30 @@ public class SapItemSyncImpl implements SapItemSyncService {
try {
// 获取调用 RFC 函数对象
//获取连接
// JCoDestination dest = SAPConnUtils.connect();
log . info ( "物料基础数据同步输入参数---------" + JSONObject . toJSONString ( sapItemQuery ) ) ;
JCoRepository repository = dest . getRepository ( ) ;
JCoFunction func = repository . getFunction ( "ZMMR_MES_MAT_GET" ) ;
if ( func = = null ) {
throw new RuntimeException ( "Function does not exist in SAP" ) ;
}
/ * 传 参 数
P_WERKS 工 厂
S_MATNR 物 料 号
S_MATKL 物 料 组
S_ERSDA 创 建 日 期
S_LAEDA 最 后 更 改 日 期 * /
sapItemQuery . setMatnr ( "000000040000005209" ) ;
if ( ! StringUtils . isNull ( sapItemQuery . getWerks ( ) ) ) {
JCoParameterList jCoParameterList = func . getImportParameterList ( ) ;
jCoParameterList . setValue ( "P_WERKS" , sapItemQuery . getWerks ( ) ) ;
}
if ( ! StringUtils . isNull ( sapItemQuery . getMatnr ( ) ) ) {
JCoTable S_MATNR = func . getTableParameterList ( ) . getTable ( "S_MATNR" ) ;
S_MATNR . appendRow ( ) ;
S_MATNR . setValue ( Constants . SIGN , "I" ) ;
S_MATNR . setValue ( Constants . OPTION , "EQ" ) ;
S_MATNR . setValue ( Constants . LOW , sapItemQuery . getMatnr ( ) ) ;
}
if ( ! StringUtils . isNull ( sapItemQuery . getMatnr ( ) ) ) {
JCoTable S_MATNR = func . getTableParameterList ( ) . getTable ( "S_MATNR" ) ;
S_MATNR . appendRow ( ) ;
@ -93,27 +103,24 @@ public class SapItemSyncImpl implements SapItemSyncService {
S_ERSDA . setValue ( Constants . LOW , sapItemQuery . getErsda ( ) ) ;
S_ERSDA . setValue ( "HIGH" , END_DATE ) ;
}
// if (!StringUtils.isNull(sapItemQuery.getLaeda())) {
// JCoTable S_LAEDA = func.getTableParameterList().getTable("S_LAEDA");
// S_LAEDA.appendRow();
// S_LAEDA.setValue(Constants.SIGN, "I");
// S_LAEDA.setValue(Constants.OPTION, "BT");
// S_LAEDA.setValue(Constants.LOW, sapItemQuery.getLaeda());
// S_LAEDA.setValue("HIGH", END_DATE);
// }
if ( ! StringUtils . isNull ( sapItemQuery . getLaeda ( ) ) ) {
JCoTable S_LAEDA = func . getTableParameterList ( ) . getTable ( "S_LAEDA" ) ;
S_LAEDA . appendRow ( ) ;
S_LAEDA . setValue ( Constants . SIGN , "I" ) ;
S_LAEDA . setValue ( Constants . OPTION , "BT" ) ;
S_LAEDA . setValue ( Constants . LOW , sapItemQuery . getLaeda ( ) ) ;
S_LAEDA . setValue ( "HIGH" , END_DATE ) ;
}
// 获取调用 RFC 函数对象
func . execute ( dest ) ;
// 获取 内表 - ZMES_PRO
JCoTable maraTable = func . getTableParameterList ( ) . getTable ( "LT_MARA" ) ;
JCoRecordMetaData metaData = maraTable . getRecordMetaData ( ) ;
// System.out.println("###" + metaData.toString());
// 加载数据源
DynamicDataSourceContextHolder . push ( "ds_1000" ) ;
List < SapBaseProduct > sapBaseProductList = new ArrayList < > ( ) ;
for ( int i = 0 ; i < maraTable . getNumRows ( ) ; i + + ) {
SapBaseProduct baseProduct = new SapBaseProduct ( ) ;
maraTable . setRow ( i ) ;
String WERKS = maraTable . getString ( "WERKS" ) ;
String MATNR = maraTable . getString ( "MATNR" ) ;
String MAKTX = maraTable . getString ( "MAKTX" ) ;
String EAN11 = maraTable . getString ( "EAN11" ) ;
@ -146,7 +153,8 @@ public class SapItemSyncImpl implements SapItemSyncService {
String MVGR5_NM = maraTable . getString ( "MVGR5_NM" ) ;
String LAEDA = maraTable . getString ( "LAEDA" ) ;
String ERSDA = maraTable . getString ( "LAEDA" ) ;
log . info ( "物料基础数据同步数据输出----" +
log . info ( i + "物料基础数据同步数据输出----" +
"工厂:" + WERKS +
"物料号:" + MATNR +
"物料描述(短文本):" + MAKTX +
"国际文件号(EAN/UPC): " + EAN11 +
@ -175,35 +183,7 @@ public class SapItemSyncImpl implements SapItemSyncService {
" 物料组描述 : " + MVGR3_NM +
"创建日期:" + ERSDA +
"上次更改日期:" + LAEDA ) ;
// System.out.println(
// "物料号:" + MATNR+
// "物料描述(短文本):" + MAKTX+
// "国际文件号(EAN/UPC): " + EAN11+
// "物料类型:" + MTART+
// "物料类型描述:" + MTBEZ+
// "物料组:" + MATKL+
// "物料组描述:" + WGBEZ+
// "毛重:" + BRGEW+
// "净重:" + NTGEW+
// "体积:" + VOLUM+
// "体积单位:" + VOLEH+
// "基本计量单位:" + MEINS+
// "帐面库存单位的可选计量单位 : " + MEINH+
// "基本计量单位转换分子:" + UMREZ+
// "转换为基本计量单位的分母:" + UMREN+
// "在客户级标记要删除的物料:" + LVORM+
// "数量:" + MENGE+
// "总货架寿命 : " + MHDHB+
// "产品组:" + SPART+
// "产品组描述:" + SPART_NM+
// "物料组1: " + MVGR1+
// "物料组1描述: " + MVGR1_NM+
// "物料组2: " + MVGR2+
// "物料组2描述: " + MVGR2_NM+
// " 物料组3: " + MVGR3+
// " 物料组描述 : " + MVGR3_NM+
// "创建日期:"+ERSDA+
// "上次更改日期:"+LAEDA);
baseProduct . setFactoryCode ( WERKS ) ;
baseProduct . setProductCode ( MATNR ) ;
baseProduct . setProductDescZh ( MAKTX ) ;
baseProduct . setProductGroup ( MATKL ) ;
@ -221,7 +201,7 @@ public class SapItemSyncImpl implements SapItemSyncService {
sapBaseProductList . add ( baseProduct ) ;
}
//this.importProducts(sapBaseProductList)
return R . ok ( this . importProducts ( sapBaseProductList )) ;
return R . ok ( this . importProducts ( sapBaseProductList ,sapItemQuery . getWerks ( ) )) ;
} catch ( Exception e ) {
return R . fail ( e . getMessage ( ) ) ;
}
@ -355,7 +335,7 @@ public class SapItemSyncImpl implements SapItemSyncService {
public String importProducts ( List < SapBaseProduct > sapBaseProductList ) {
public String importProducts ( List < SapBaseProduct > sapBaseProductList ,String factoryCode ) {
if ( StringUtils . isNull ( sapBaseProductList ) | | sapBaseProductList . size ( ) = = 0 ) {
throw new ServiceException ( "同步物料数据为空!" ) ;
}
@ -363,7 +343,7 @@ public class SapItemSyncImpl implements SapItemSyncService {
int failureNum = 0 ;
StringBuilder successMsg = new StringBuilder ( ) ;
StringBuilder failureMsg = new StringBuilder ( ) ;
DynamicDataSourceContextHolder . push ( "ds_" + factoryCode ) ;
for ( SapBaseProduct sapBaseProduct : sapBaseProductList ) {
try {
// 验证是否存在这个物料
@ -371,12 +351,14 @@ public class SapItemSyncImpl implements SapItemSyncService {
if ( StringUtils . isNull ( u ) ) {
BeanValidators . validateWithException ( validator , sapBaseProduct ) ;
sapBaseProduct . setCreateBy ( "job" ) ;
sapBaseProduct . setCreateTime ( DateUtils . getNowDate ( ) ) ;
sapBaseProductMapper . insertBaseProduct ( sapBaseProduct ) ;
successNum + + ;
successMsg . append ( "<br/>" + successNum + "、物料 " + sapBaseProduct . getProductCode ( ) + " 同步成功" ) ;
} else if ( ! StringUtils . isNull ( u ) ) {
sapBaseProduct . setProductId ( u . getProductId ( ) ) ;
sapBaseProduct . setCreateBy ( "job" ) ;
sapBaseProduct . setUpdateBy ( "job" ) ;
sapBaseProduct . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
sapBaseProductMapper . updateBaseProduct ( sapBaseProduct ) ;
successNum + + ;
successMsg . append ( "<br/>" + successNum + "、物料 " + sapBaseProduct . getProductCode ( ) + " 更新成功" ) ;
@ -431,8 +413,8 @@ public class SapItemSyncImpl implements SapItemSyncService {
qcCheckTaskIncomeDTO . setMaterialName ( maraTable . getString ( "MAKTX" ) ) ; //物料描述
qcCheckTaskIncomeDTO . setQuality ( new BigDecimal ( maraTable . getString ( "MENGE" ) ) ) ; //数量
qcCheckTaskIncomeDTO . setUnit ( maraTable . getString ( "MEINS" ) ) ; //单位
String inputDateTime = maraTable . getString ( "CPUDT" ) + maraTable . getString ( "CPUTM" ) ;
SimpleDateFormat inputFormat = new SimpleDateFormat ( "yyyy MMddHHmmss") ;
String inputDateTime = maraTable . getString ( "CPUDT" ) + " " + maraTable . getString ( "CPUTM" ) ;
SimpleDateFormat inputFormat = new SimpleDateFormat ( "yyyy - MM- dd HH: mm: ss") ;
// 将原始日期时间字符串解析为Date对象
Date date = inputFormat . parse ( inputDateTime ) ;
qcCheckTaskIncomeDTO . setIncomeTime ( date ) ;