|
|
|
@ -4,14 +4,17 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.foreverwin.mesnac.common.enums.HandleEnum;
|
|
|
|
|
import com.foreverwin.mesnac.common.util.ExceptionUtil;
|
|
|
|
|
import com.foreverwin.mesnac.common.util.StringUtil;
|
|
|
|
|
import com.foreverwin.modular.core.exception.BusinessException;
|
|
|
|
|
import com.foreverwin.modular.core.meext.MEServices;
|
|
|
|
|
import com.sap.me.common.MaterialType;
|
|
|
|
|
import com.sap.me.common.ObjectAliasEnum;
|
|
|
|
|
import com.sap.me.common.ObjectReference;
|
|
|
|
|
import com.sap.me.productdefinition.ItemConfigurationServiceInterface;
|
|
|
|
|
import com.sap.me.productdefinition.ItemFullConfiguration;
|
|
|
|
|
import com.sap.me.productdefinition.QuantityRestriction;
|
|
|
|
|
import com.sap.me.common.ProcurementType;
|
|
|
|
|
import com.sap.me.productdefinition.*;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 物料主数据操作类
|
|
|
|
@ -46,6 +49,123 @@ public class ItemWSClient {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增物料
|
|
|
|
|
*
|
|
|
|
|
* @param jsonObject
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String insert(JSONObject jsonObject) {
|
|
|
|
|
try {
|
|
|
|
|
String site = (String) jsonObject.get("site");
|
|
|
|
|
String item = jsonObject.getString("item");
|
|
|
|
|
//物料描述
|
|
|
|
|
String itemDescription = jsonObject.getString("itemDesc");
|
|
|
|
|
//计量单位
|
|
|
|
|
String unitOfMeasure = jsonObject.getString("unit");
|
|
|
|
|
//状态
|
|
|
|
|
String statusBo = HandleEnum.STATUS.getHandle(site, "201");
|
|
|
|
|
|
|
|
|
|
//物料类型(FERT(已完成)/ROH(原始)/HALB(半成品)/KMAT(可配置)/INST(安装)/VERP(包装)/FHMI(生产资源/工具)/CSTM(自定义))
|
|
|
|
|
String itemTypeDesc = jsonObject.getString("materialType");
|
|
|
|
|
if (!"已完成".equals(itemTypeDesc) && !"原始".equals(itemTypeDesc) && !"半成品".equals(itemTypeDesc)) {
|
|
|
|
|
throw BusinessException.build("物料类型可维护的值为:FERT(已完成)、ROH(原始)、HALB(半成品)");
|
|
|
|
|
}
|
|
|
|
|
String itemType = "ROH";
|
|
|
|
|
switch (itemTypeDesc) {
|
|
|
|
|
case "原始":
|
|
|
|
|
itemType = "ROH";
|
|
|
|
|
break;
|
|
|
|
|
case "半成品":
|
|
|
|
|
itemType = "HALB";
|
|
|
|
|
break;
|
|
|
|
|
case "已完成":
|
|
|
|
|
itemType = "FERT";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//采购类型(M(制造)/P(采购)/B(制造/采购))
|
|
|
|
|
String procurementTypeDesc = jsonObject.getString("itemType");
|
|
|
|
|
if (!"M".equals(procurementTypeDesc) && !"P".equals(procurementTypeDesc) && !"B".equals(procurementTypeDesc)) {
|
|
|
|
|
throw BusinessException.build("采购类型可维护的值为:M(制造)、P(采购)、B(制造/采购)");
|
|
|
|
|
}
|
|
|
|
|
String procurementType = "P";
|
|
|
|
|
switch (procurementTypeDesc) {
|
|
|
|
|
case "采购":
|
|
|
|
|
itemType = "P";
|
|
|
|
|
break;
|
|
|
|
|
case "制造/采购":
|
|
|
|
|
itemType = "B";
|
|
|
|
|
break;
|
|
|
|
|
case "制造":
|
|
|
|
|
itemType = "M";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//批次大小
|
|
|
|
|
String lotSize = jsonObject.getString("lotSize");
|
|
|
|
|
lotSize = StringUtil.notBlank(lotSize) ? lotSize : "999999";
|
|
|
|
|
|
|
|
|
|
//数量限制
|
|
|
|
|
String qtyRestrictionDesc = jsonObject.getString("qtyRestriction");
|
|
|
|
|
|
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
//物料标准API
|
|
|
|
|
ItemConfigurationServiceInterface itemServiceInterFace = MEServices.create("com.sap.me.productdefinition", "ItemConfigurationService", site);
|
|
|
|
|
|
|
|
|
|
//创建物料
|
|
|
|
|
ItemConfiguration itemConfiguration = new ItemConfiguration();
|
|
|
|
|
itemConfiguration.setItem(item);
|
|
|
|
|
itemConfiguration.setRevision("A");
|
|
|
|
|
itemConfiguration.setProcurementType(ProcurementType.fromValue(procurementType));
|
|
|
|
|
itemConfiguration.setLotSize(new BigDecimal(lotSize));
|
|
|
|
|
itemConfiguration.setRef(HandleEnum.ITEM.getHandle(site, item, "A"));
|
|
|
|
|
itemConfiguration.setCurrentRevision(true);
|
|
|
|
|
itemConfiguration.setUnitOfMeasurement(unitOfMeasure);
|
|
|
|
|
itemConfiguration.setMaterialType(MaterialType.fromValue(itemType));
|
|
|
|
|
|
|
|
|
|
String dataTypeBo = "DataTypeBO:" +site+ ",ASSEMBLY,INV_NAC";
|
|
|
|
|
itemConfiguration.setInventoryAssemblyDataTypeRef(dataTypeBo);
|
|
|
|
|
//物料描述赋值
|
|
|
|
|
List<ItemTranslation> itemTranslationList = new ArrayList<>();
|
|
|
|
|
ItemTranslation itemTranslation = new ItemTranslation();
|
|
|
|
|
itemTranslation.setLocale("zh");
|
|
|
|
|
itemTranslation.setDescription(itemDescription);
|
|
|
|
|
itemTranslationList.add(itemTranslation);
|
|
|
|
|
itemConfiguration.setItemTranslationList(itemTranslationList);
|
|
|
|
|
itemConfiguration.setStatusRef(statusBo);
|
|
|
|
|
//数量限制
|
|
|
|
|
switch (qtyRestrictionDesc) {
|
|
|
|
|
case "仅1.0":
|
|
|
|
|
itemConfiguration.setQuantityRestriction(QuantityRestriction.ONLY_1);
|
|
|
|
|
break;
|
|
|
|
|
case "任意数字":
|
|
|
|
|
itemConfiguration.setQuantityRestriction(QuantityRestriction.ANY_NUMBER);
|
|
|
|
|
break;
|
|
|
|
|
case "正数":
|
|
|
|
|
itemConfiguration.setQuantityRestriction(QuantityRestriction.WHOLE_NUMBER);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
itemConfiguration.setQuantityRestriction(QuantityRestriction.ANY_NUMBER);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建物料
|
|
|
|
|
itemServiceInterFace.createItem(itemConfiguration);
|
|
|
|
|
|
|
|
|
|
//自定义字段保存
|
|
|
|
|
CustomDataWSClient.update(jsonObject, itemConfiguration.getRef(), ObjectAliasEnum.ITEM.value());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ExceptionUtil.getExceptionMsg(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新物料
|
|
|
|
|
*
|
|
|
|
|