|
|
@ -1,6 +1,10 @@
|
|
|
|
package com.foreverwin.mesnac.dispatch.service.impl;
|
|
|
|
package com.foreverwin.mesnac.dispatch.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
import com.foreverwin.mesnac.common.constant.DataImportConstant;
|
|
|
|
import com.foreverwin.mesnac.common.enums.HandleEnum;
|
|
|
|
import com.foreverwin.mesnac.common.enums.HandleEnum;
|
|
|
|
|
|
|
|
import com.foreverwin.mesnac.common.util.ExceptionUtil;
|
|
|
|
import com.foreverwin.mesnac.dispatch.model.IssueItem;
|
|
|
|
import com.foreverwin.mesnac.dispatch.model.IssueItem;
|
|
|
|
import com.foreverwin.mesnac.dispatch.mapper.IssueItemMapper;
|
|
|
|
import com.foreverwin.mesnac.dispatch.mapper.IssueItemMapper;
|
|
|
|
import com.foreverwin.mesnac.dispatch.model.ItemBatch;
|
|
|
|
import com.foreverwin.mesnac.dispatch.model.ItemBatch;
|
|
|
@ -12,14 +16,17 @@ import com.foreverwin.mesnac.meapi.model.Item;
|
|
|
|
import com.foreverwin.mesnac.meapi.service.InventoryService;
|
|
|
|
import com.foreverwin.mesnac.meapi.service.InventoryService;
|
|
|
|
import com.foreverwin.mesnac.meapi.service.ItemService;
|
|
|
|
import com.foreverwin.mesnac.meapi.service.ItemService;
|
|
|
|
import com.foreverwin.modular.core.exception.BusinessException;
|
|
|
|
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.MaterialType;
|
|
|
|
|
|
|
|
import com.sap.me.common.ObjectReference;
|
|
|
|
|
|
|
|
import com.sap.me.inventory.*;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.List;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -37,8 +44,6 @@ public class IssueItemServiceImpl extends ServiceImpl<IssueItemMapper, IssueItem
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ItemService itemService;
|
|
|
|
private ItemService itemService;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IssueItemMapper issueItemMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ItemBatchService itemBatchService;
|
|
|
|
private ItemBatchService itemBatchService;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private InventoryService inventoryService;
|
|
|
|
private InventoryService inventoryService;
|
|
|
@ -78,4 +83,101 @@ public class IssueItemServiceImpl extends ServiceImpl<IssueItemMapper, IssueItem
|
|
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void issueItem(String site, String user, JSONObject jsonObject) {
|
|
|
|
|
|
|
|
JSONArray jsonArray = jsonObject.getJSONArray("inventoryItems");
|
|
|
|
|
|
|
|
if (jsonArray == null || jsonArray.size() <= 0) {
|
|
|
|
|
|
|
|
throw BusinessException.build("发料清单不能为空!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String item = jsonObject.getString("item");
|
|
|
|
|
|
|
|
Item itemModel = itemService.selectCurrent(site, item);
|
|
|
|
|
|
|
|
if (itemModel == null) {
|
|
|
|
|
|
|
|
throw BusinessException.build("物料{0}没有维护当前版本!", item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String itemBo = itemModel.getHandle();
|
|
|
|
|
|
|
|
String materialType = itemModel.getMaterialType();
|
|
|
|
|
|
|
|
Boolean oddments = jsonObject.getBoolean("oddments");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LocalDateTime dateTime = LocalDateTime.now();
|
|
|
|
|
|
|
|
List<IssueItem> issueItemList = new ArrayList<>();
|
|
|
|
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
if (!oddments) {
|
|
|
|
|
|
|
|
//非余料发料 原材料-创建库存,计算发料数量; 半成品-只计算发料数量
|
|
|
|
|
|
|
|
InventoryServiceInterface meInventoryService;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
meInventoryService = MEServices.create("com.sap.me.inventory", "InventoryService", site);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw BusinessException.build("获取标准库存操作服务失败:" + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
|
|
|
|
JSONObject _jsonObject = jsonArray.getJSONObject(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String inventory = _jsonObject.getString("inventory");
|
|
|
|
|
|
|
|
String qty = _jsonObject.getString("qty");
|
|
|
|
|
|
|
|
BigDecimal qtyOnHand = new BigDecimal(qty);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (MaterialType.RAW.value().equals(materialType)) {
|
|
|
|
|
|
|
|
List<ItemBatch> itemBatchList = itemBatchService.findItemBatch(site, item, inventory);
|
|
|
|
|
|
|
|
if (itemBatchList == null || itemBatchList.size() <= 0) {
|
|
|
|
|
|
|
|
throw BusinessException.build("扫描的物料条码【 " + inventory + " 】不存在!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
//查询库存是否存在
|
|
|
|
|
|
|
|
ObjectReference objectReference = new ObjectReference();
|
|
|
|
|
|
|
|
String inventoryBo = HandleEnum.INVENTORY.getHandle(site, inventory);
|
|
|
|
|
|
|
|
objectReference.setRef(inventoryBo);
|
|
|
|
|
|
|
|
com.sap.me.inventory.Inventory inventoryModel = meInventoryService.findInventoryByRef(objectReference);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inventoryModel == null) {
|
|
|
|
|
|
|
|
//库存创建
|
|
|
|
|
|
|
|
InventoryValidateAndAddRequest request = new InventoryValidateAndAddRequest();
|
|
|
|
|
|
|
|
request.setItemRef(itemBo);
|
|
|
|
|
|
|
|
request.setInventoryId(inventory);
|
|
|
|
|
|
|
|
request.setQuantityOnHand(qtyOnHand);
|
|
|
|
|
|
|
|
meInventoryService.validateAndAdd(request);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
qtyOnHand = qtyOnHand.add(inventoryModel.getQtyOnHand());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//库存修改
|
|
|
|
|
|
|
|
InventoryValidateAndUpdateWithReceiveQuantityOverrideRequest request = new InventoryValidateAndUpdateWithReceiveQuantityOverrideRequest();
|
|
|
|
|
|
|
|
request.setItemRef(itemBo);
|
|
|
|
|
|
|
|
request.setInventoryId(inventory);
|
|
|
|
|
|
|
|
request.setReceiveQty(qtyOnHand);
|
|
|
|
|
|
|
|
request.setQuantityOnHand(qtyOnHand);
|
|
|
|
|
|
|
|
request.setModifiedDateTime(inventoryModel.getModifiedDateTime());
|
|
|
|
|
|
|
|
meInventoryService.validateAndUpdateWithReceiveQtyOverride(request);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
ExceptionUtil.throwException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发料明细记录
|
|
|
|
|
|
|
|
IssueItem issueItem = new IssueItem();
|
|
|
|
|
|
|
|
issueItem.setHandle("IssueItemBO:" + site + "," + UUID.randomUUID().toString());
|
|
|
|
|
|
|
|
issueItem.setSite(site);
|
|
|
|
|
|
|
|
issueItem.setCallItemNo("");
|
|
|
|
|
|
|
|
issueItem.setShopOrder("");
|
|
|
|
|
|
|
|
issueItem.setSfc("");
|
|
|
|
|
|
|
|
issueItem.setItem(item);
|
|
|
|
|
|
|
|
issueItem.setInventory(inventory);
|
|
|
|
|
|
|
|
issueItem.setQty(new BigDecimal(qty));
|
|
|
|
|
|
|
|
issueItem.setCreateUser(user);
|
|
|
|
|
|
|
|
issueItem.setCreatedDateTime(dateTime);
|
|
|
|
|
|
|
|
issueItem.setModifyUser(user);
|
|
|
|
|
|
|
|
issueItem.setModifiedDateTime(dateTime);
|
|
|
|
|
|
|
|
issueItemList.add(issueItem);
|
|
|
|
|
|
|
|
}//end for
|
|
|
|
|
|
|
|
}// end if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
if (issueItemList != null && issueItemList.size() > 0) {
|
|
|
|
|
|
|
|
this.saveBatch(issueItemList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|