philip 4 years ago
parent b572ec1cb7
commit 4c4871942e

@ -1099,6 +1099,11 @@
<select id="findSfcDispatchBySfc" resultType="com.foreverwin.mesnac.common.dto.SfcDispatchDto">
SELECT *
FROM Z_SFC_DISPATCH zsd where SFC=#{dto.sfc} AND site=#{dto.site} AND STEP_ID=#{dto.stepId} AND OPERATION=#{dto.operation} AND RESRCE=#{dto.resrce}
FROM Z_SFC_DISPATCH zsd where site=#{site}
<if test="dto.sfc!=null"> AND SFC=#{dto.sfc}</if>
<if test="dto.stepId!=null"> AND STEP_ID=#{dto.stepId}</if>
<if test="dto.operation!=null"> AND OPERATION=#{dto.operation}</if>
<if test="dto.resrce!=null"> AND RESRCE=#{dto.resrce}</if>
<if test="dto.handle!=null"> AND HANDLE=#{dto.handle}</if>
</select>
</mapper>

@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
*
@ -35,6 +36,11 @@ public class SfcDataAssembleController {
public R loadSfcAssemble(SfcDto sfcDto) {
return R.ok(sfcDataAssembleService.loadSfcAssemble(sfcDto));
}
@ResponseBody
@PostMapping("/assembleInventory")
public R loadSfcAssemble(@RequestBody Map<String, Object> paramMap) {
return R.ok(sfcDataAssembleService.assembleInventory(paramMap));
}
/**
* id
*

@ -29,7 +29,7 @@ public interface SfcDataAssembleService extends IService<SfcDataAssemble> {
List<SfcDataAssemble> selectList(SfcDataAssemble sfcDataAssemble);
Object loadSfcAssemble(SfcDto sfcDto);
Map<String, Object> loadSfcAssemble(SfcDto sfcDto);
Map<String, Object> assembleInventory(Map<String, Object> paramMap) throws BaseException;
}

@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.foreverwin.mesnac.common.dto.SfcDispatchDto;
import com.foreverwin.mesnac.common.enums.DispatchStatusEnum;
import com.foreverwin.mesnac.common.enums.HandleEnum;
import com.foreverwin.mesnac.common.service.SfcDispatchCommonService;
import com.foreverwin.mesnac.common.util.ExceptionUtil;
import com.foreverwin.mesnac.meapi.dto.SfcDto;
@ -20,8 +19,6 @@ import com.foreverwin.modular.core.exception.BaseException;
import com.foreverwin.modular.core.meext.MEServices;
import com.foreverwin.modular.core.util.CommonMethods;
import com.foreverwin.modular.core.util.FrontPage;
import com.sap.me.inventory.InventoryServiceInterface;
import com.sap.me.inventory.InventoryValidateAndAddRequest;
import com.sap.me.production.AssembleComponentsRequest;
import com.sap.me.production.AssemblyComponent;
import com.sap.me.production.AssemblyDataField;
@ -57,6 +54,7 @@ public class SfcDataAssembleServiceImpl extends ServiceImpl<SfcDataAssembleMappe
private InventoryService inventoryService;
@Autowired
private OperationService operationService;
@Override
public IPage<SfcDataAssemble> selectPage(FrontPage<SfcDataAssemble> frontPage, SfcDataAssemble sfcDataAssemble) {
QueryWrapper<SfcDataAssemble> queryWrapper = new QueryWrapper<>();
@ -72,7 +70,7 @@ public class SfcDataAssembleServiceImpl extends ServiceImpl<SfcDataAssembleMappe
}
@Override
public Object loadSfcAssemble(SfcDto sfcDto) {
public Map<String, Object> loadSfcAssemble(SfcDto sfcDto) {
//构造参数
String site = CommonMethods.getSite();
String user = CommonMethods.getUser();
@ -81,19 +79,23 @@ public class SfcDataAssembleServiceImpl extends ServiceImpl<SfcDataAssembleMappe
String resrce = sfcDto.getResrce();
String workCenter = sfcDto.getWorkCenter();
String stepId = sfcDto.getStepId();
SfcDispatchDto sfcDispatchDto=new SfcDispatchDto();
SfcDispatchDto sfcDispatchDto = new SfcDispatchDto();
sfcDispatchDto.setSfc(sfc);
sfcDispatchDto.setStepId(stepId);
sfcDispatchDto.setResrce(resrce);
sfcDispatchDto.setOperation(operation);
SfcDispatchDto sfcDispatchBySfc = sfcDispatchCommonService.findSfcDispatchBySfc(sfcDispatchDto);
if(sfcDispatchBySfc==null||!sfcDispatchBySfc.getDispatchStatus().equals(DispatchStatusEnum.START)){
if (sfcDispatchBySfc == null || !sfcDispatchBySfc.getDispatchStatus().equals(DispatchStatusEnum.START.getCode())) {
throw new BaseException("未在生产操作面板中执行开始操作!");
}
Map<String, Object> resultMap = new HashMap<String, Object>();
//查询装配数据
List<Map<String, Object>> assembleList = sfcDataAssembleMapper.querySfcAssemble(sfcDispatchBySfc.getHandle());
if (assembleList == null) {
throw new BaseException("没有装配物料");
}
resultMap.put("SfcDispatchBO", sfcDispatchBySfc.getHandle());
resultMap.put("ASSEMBLE_LIST", assembleList);
return resultMap;
}
@ -101,218 +103,118 @@ public class SfcDataAssembleServiceImpl extends ServiceImpl<SfcDataAssembleMappe
@Override
public Map<String, Object> assembleInventory(Map<String, Object> paramMap) throws BaseException {
String site = (String) paramMap.get("SITE");
String user = (String) paramMap.get("USER");
String site = CommonMethods.getSite();
String user = CommonMethods.getUser();
String inventoryId = (String) paramMap.get("INVENTORY_ID");
String sfcDispatchBo = (String) paramMap.get("SFC_DATA_MAIN_BO");
String sfcDispatchBo = (String) paramMap.get("SfcDispatchBo");
String sfc = (String) paramMap.get("SFC");
String barCode = inventoryId;
BigDecimal assembleQty = new BigDecimal((String) paramMap.get("QTY"));
SfcDispatchDto sfcDispatch=new SfcDispatchDto();
SfcDispatchDto sfcDispatch = new SfcDispatchDto();
sfcDispatch.setHandle(sfcDispatchBo);
SfcDispatchDto sfcDataMain = sfcDispatchCommonService.findSfcDispatchBySfc(sfcDispatch);
//判断条码是否存在
Inventory inv = inventoryService.getById("InventoryBO:" + site + "," + inventoryId);
/*if(inv.getQtyOnHand() <= 0){
throw new BaseException("物料条码["+inventoryId+"]已无库存数量,无法装配!");
}*/
String[] inventoryIds = null;
if(inv == null){
//一定为拆机,扫描的条码格式为 派工单*步骤标识*物料*SFC*BOM组件顺序
int result1 = inventoryId.indexOf("*");
if (result1 == -1) {
throw new BaseException("物料条码[" + barCode + "]不存在!");
}
inventoryIds = inventoryId.split("\\*");
if (inventoryIds.length != 5) {
throw new BaseException("物料条码[" + barCode + "]不存在!");
}
//判断扫描的条码是否符合
Map<String, Object> sfcDismantling = sfcDataAssembleMapper.querySfcDismantling(sfcDispatchBo);
if(!inventoryIds[0].equals(sfcDismantling.get("DISPATCH_NO")) || !inventoryIds[1].equals(sfcDismantling.get("STEP_ID"))
|| !inventoryIds[3].equals(sfcDismantling.get("SFC"))){
throw new BaseException("物料条码[" + barCode + "]不在装配列表中!");
}
if (inv == null) {
throw new BaseException("物料条码[" + barCode + "]不存在!");
}
//获取需装配数据,判断是为拆机还是装配
List<Map<String, Object>> assembleList = sfcDataAssembleMapper.querySfcAssemble(sfcDispatchBo);
String isFlag = "N";//是否在装配列表中
String isAssemble = "";//装配情况按颜色区分GREEN已装配/拆机完成YELLOW未装配/拆机完成WHITE未进行装配/拆机完成
String item = "";//物料
String isDismantling = "N";//是否为拆机
String itemBo = "";
String bomCompBo = "";
double seq = 0;
BigDecimal qty = BigDecimal.ZERO;
BigDecimal assembleQty = BigDecimal.ZERO;
//for循环判断是否为拆机
for(int i = 0; i < assembleList.size(); i++){
if(inv != null && assembleList.get(i).get("ITEM_BO").equals(inv.getItemBo())){
//为装配或拆机
isDismantling = (String) assembleList.get(i).get("IS_DISMANTLING");
isFlag = "Y";
}else if(inv == null && HandleEnum.ITEM.getPart((String) assembleList.get(i).get("ITEM_BO"),1).equals(inventoryIds[2])
&& "Y".equals(assembleList.get(i).get("IS_DISMANTLING"))){
//一定为拆机
isFlag = "Y";
isDismantling = "Y";
}
}
if(isFlag.equals("N")){
throw new BaseException("物料条码["+barCode+"]不在装配列表中!");
}
BigDecimal assembledQty = BigDecimal.ZERO;
//条码不存在且为装配组件提示报错
if(inv == null && "N".equals(isDismantling)){
throw new BaseException("物料条码["+barCode+"]不存在!");
}
//for循环构造数据
isFlag = "N";
for(int i = 0; i < assembleList.size(); i++){
if("N".equals(isDismantling)) {
//装配
if (assembleList.get(i).get("ITEM_BO").equals(inv.getItemBo())) {
isFlag = "Y";
qty = (new BigDecimal(String.valueOf(assembleList.get(i).get("QTY"))));
assembleQty = (new BigDecimal(String.valueOf(assembleList.get(i).get("ASSEMBLE_QTY"))));
item = (String) assembleList.get(i).get("ITEM");
isAssemble = (String) assembleList.get(i).get("IS_ASSEMBLE");
seq = (new BigDecimal(String.valueOf(assembleList.get(i).get("SEQ")))).doubleValue();
itemBo = (String) assembleList.get(i).get("ITEM_BO");
bomCompBo = (String) assembleList.get(i).get("BOM_COMPONENT_BO");
}
}else{
//拆机
if(inv != null){
//条码存在
throw new BaseException("物料条码["+barCode+"]已被拆机,无法再次进行拆机!");
}else{
if(HandleEnum.ITEM.getPart((String) assembleList.get(i).get("ITEM_BO"),1).equals(inventoryIds[2]) && inventoryIds[4].equals(String.valueOf(assembleList.get(i).get("SEQ")))){
isFlag = "Y";
qty = (new BigDecimal(String.valueOf(assembleList.get(i).get("QTY"))));
assembleQty = (new BigDecimal(String.valueOf(assembleList.get(i).get("ASSEMBLE_QTY"))));
item = (String) assembleList.get(i).get("ITEM");
isAssemble = (String) assembleList.get(i).get("IS_ASSEMBLE");
seq = (new BigDecimal(String.valueOf(assembleList.get(i).get("SEQ")))).doubleValue();
itemBo = (String) assembleList.get(i).get("ITEM_BO");
bomCompBo = (String) assembleList.get(i).get("BOM_COMPONENT_BO");
}
}
for (int i = 0; i < assembleList.size(); i++) {
//装配
if (assembleList.get(i).get("ITEM_BO").equals(inv.getItemBo())) {
isFlag = "Y";
qty = (new BigDecimal(String.valueOf(assembleList.get(i).get("QTY"))));
assembledQty = (new BigDecimal(String.valueOf(assembleList.get(i).get("ASSEMBLE_QTY"))));
item = (String) assembleList.get(i).get("ITEM");
isAssemble = (String) assembleList.get(i).get("IS_ASSEMBLE");
seq = (new BigDecimal(String.valueOf(assembleList.get(i).get("SEQ")))).doubleValue();
itemBo = (String) assembleList.get(i).get("ITEM_BO");
bomCompBo = (String) assembleList.get(i).get("BOM_COMPONENT_BO");
}
}
if(isFlag.equals("N")){
throw new BaseException("物料条码["+barCode+"]不在装配列表中!");
if (isFlag.equals("N")) {
throw new BaseException("物料条码[" + barCode + "]不在装配列表中!");
}
if(isAssemble.equals("GREEN")){
String dismantlingDesc = "N".equals(isDismantling) ? "装配" : "拆机";
throw new BaseException("物料["+item+"]已"+ dismantlingDesc +"完成,无需再进行"+ dismantlingDesc +"");
if (isAssemble.equals("GREEN")) {
throw new BaseException("物料[" + item + "]已装配完成,无需再进行装配!");
}
//装配
if("N".equals(isDismantling)) {
if(inv.getQtyOnHand().doubleValue() <= 0){
throw new BaseException("物料条码["+barCode+"]已无库存数量,无法装配!");
}
//校验
List<Map<String, Object>> validateList = sfcDataAssembleMapper.validateSfcAssemble(site, inventoryId, sfcDispatchBo);
if (validateList.size() > 0) {
for (int i = 0; i < validateList.size(); i++) {
Map<String, Object> validateMap = validateList.get(i);
String statusMess = (String) validateMap.get("STATUS_MESS");
String status = statusMess.substring(0, 1);
if ("N".equals(status)) {
String mess = statusMess.substring(2, statusMess.length());
throw new BaseException(mess);
}
}
}
//物料消耗,添加装配数据,无需扣减库存
BigDecimal qtyOnHand = BigDecimal.ZERO;
if (inv.getQtyOnHand().subtract (qty.subtract(assembleQty) ).doubleValue() > 0) {
qtyOnHand = inv.getQtyOnHand() .subtract (qty.subtract(assembleQty));
}
BigDecimal assembleSfcQty = inv.getQtyOnHand() .subtract(qtyOnHand) ;
//inv.setQtyOnHand(qtyOnHand);
//inventoryService.saveOrUpdate(inv);
//标准物料消耗
AssembleComponentsRequest assembleComponentsRequest = new AssembleComponentsRequest();
List<AssemblyComponent> componentList = new ArrayList<AssemblyComponent>();
List<AssemblyDataField> adf = new ArrayList<AssemblyDataField>();
AssemblyComponent ac = new AssemblyComponent();
String[] str = {"INVENTORY_ID_SFC", "SLOT_QTY"};
for (int j = 0; j < str.length; j++) {
AssemblyDataField ad = new AssemblyDataField();
ad.setAttribute(str[j]);
String value = inv.getInventoryId();
if ("SLOT_QTY".equals(str[j])) {
value = String.valueOf(assembleSfcQty);
}
ad.setValue(value);
adf.add(ad);
}
ac.setActualComponentRef(inv.getItemBo());
ac.setTimeBased(false);
ac.setBomComponentRef(bomCompBo);
ac.setAssemblyDataFields(adf);
ac.setQty(assembleSfcQty);
ac.setSetErpSentFlag(false);
componentList.add(ac);
assembleComponentsRequest.setResourceRef("ResourceBO:" + site + "," + sfcDataMain.getResrce());
assembleComponentsRequest.setStepId(sfcDataMain.getStepId());
String operationBo = operationService.getCurrentRevisionRef(site, sfcDataMain.getOperation()).getHandle();
assembleComponentsRequest.setOperationRef(operationBo);
assembleComponentsRequest.setEvent("baseFinished:AssemblyPoint");
assembleComponentsRequest.setComponentList(componentList);
assembleComponentsRequest.setSfcRef("SFCBO:" + site + "," + sfc);
try {
AssemblyServiceInterface assemblyService = null;
assemblyService = MEServices.create("com.sap.me.production", "AssemblyService", site);
assemblyService.assembleComponents(assembleComponentsRequest);
} catch (Exception e) {
ExceptionUtil.throwException(e);
if (inv.getQtyOnHand().doubleValue() <= 0) {
throw new BaseException("物料条码[" + barCode + "]已无库存数量,无法装配!");
}
//标准物料消耗
AssembleComponentsRequest assembleComponentsRequest = new AssembleComponentsRequest();
List<AssemblyComponent> componentList = new ArrayList<AssemblyComponent>();
List<AssemblyDataField> adf = new ArrayList<>();
AssemblyComponent ac = new AssemblyComponent();
String[] str = {"INVENTORY_ID_SFC", "SLOT_QTY"};
for (int j = 0; j < str.length; j++) {
AssemblyDataField ad = new AssemblyDataField();
ad.setAttribute(str[j]);
String value = inv.getInventoryId();
if ("SLOT_QTY".equals(str[j])) {
value = String.valueOf(assembleQty);
}
ad.setValue(value);
adf.add(ad);
}
ac.setActualComponentRef(inv.getItemBo());
ac.setTimeBased(false);
ac.setBomComponentRef(bomCompBo);
ac.setAssemblyDataFields(adf);
ac.setQty(assembleQty);
ac.setSetErpSentFlag(false);
componentList.add(ac);
assembleComponentsRequest.setResourceRef("ResourceBO:" + site + "," + sfcDataMain.getResrce());
assembleComponentsRequest.setStepId(sfcDataMain.getStepId());
String operationBo = operationService.getCurrentRevisionRef(site, sfcDataMain.getOperation()).getHandle();
assembleComponentsRequest.setOperationRef(operationBo);
assembleComponentsRequest.setEvent("baseFinished:AssemblyPoint");
assembleComponentsRequest.setComponentList(componentList);
assembleComponentsRequest.setSfcRef("SFCBO:" + site + "," + sfc);
try {
AssemblyServiceInterface assemblyService = null;
assemblyService = MEServices.create("com.sap.me.production", "AssemblyService", site);
assemblyService.assembleByComponents(assembleComponentsRequest);
} catch (Exception e) {
ExceptionUtil.throwException(e);
}
SfcDataAssemble assemble = new SfcDataAssemble();
assemble.setHandle("SfcDataAssembleBO:" + site + "," + UUID.randomUUID().toString());
assemble.setSite(site);
assemble.setSfcDispatchBo(sfcDispatchBo);
assemble.setStatus("A");
assemble.setInventoryBo(inv.getHandle());
assemble.setSeq(seq);
assemble.setItemBo(inv.getItemBo());
assemble.setAssembleQty(assembleSfcQty);
assemble.setCreatedUser(user);
assemble.setCreatedDateTime(LocalDateTime.now());
assemble.setModifiedDateTime(LocalDateTime.now());
assemble.setModifyUser(user);
sfcDataAssembleMapper.insert(assemble);
}else{
SfcDataAssemble assemble = new SfcDataAssemble();
assemble.setHandle("SfcDataAssembleBO:" + site + "," + UUID.randomUUID().toString());
assemble.setSite(site);
assemble.setSfcDispatchBo(sfcDispatchBo);
assemble.setStatus("A");
assemble.setInventoryBo(inv.getHandle());
assemble.setSeq(seq);
assemble.setItemBo(inv.getItemBo());
assemble.setAssembleQty(assembleQty);
assemble.setCreatedUser(user);
assemble.setCreatedDateTime(LocalDateTime.now());
assemble.setModifiedDateTime(LocalDateTime.now());
assemble.setModifyUser(user);
sfcDataAssembleMapper.insert(assemble);
BigDecimal assembleSfcQty = qty;
//生成库存
InventoryServiceInterface inventoryServiceInterface = null;
try {
inventoryServiceInterface = MEServices.create("com.sap.me.inventory", "InventoryService", site);
} catch (ClassNotFoundException e) {
throw new BaseException(e.getMessage());
}
InventoryValidateAndAddRequest invAddRequest = new InventoryValidateAndAddRequest();
invAddRequest.setInventoryId(inventoryId);
invAddRequest.setQuantityOnHand(assembleSfcQty);
invAddRequest.setItemRef(itemBo);
String shopOrderBo = HandleEnum.SHOP_ORDER.getHandle(site, sfcDataMain.getShopOrder());
invAddRequest.setShopOrderLocationRef(shopOrderBo);
try {
inventoryServiceInterface.validateAndAdd(invAddRequest);
} catch (com.sap.me.frame.domain.BusinessException e) {
ExceptionUtil.throwException( e);
}
}
return null;
}

@ -436,12 +436,11 @@
WHERE DA.SFC_DISPATCH_BO = #{sfcDispatchBo}
GROUP BY DA.ITEM_BO, DA.SEQ
)
SELECT CASE WHEN CF2.VALUE='Y' THEN N'-' ELSE N'+' END || N'物料:'||I.ITEM||'/'||I.REVISION||N' 数量:'|| S.QTY * BC.QTY ITEM_REVISION,
SELECT '物料:'||I.ITEM||'/'||I.REVISION||N' 数量:'|| S.QTY * BC.QTY ITEM_REVISION,
S.QTY * BC.QTY QTY,NVL(SD.ASSEMBLE_QTY,0) ASSEMBLE_QTY,I.HANDLE ITEM_BO,I.ITEM,IT.DESCRIPTION ITEM_DESC,
CASE WHEN NVL(SD.ASSEMBLE_QTY,0) = 0 THEN 'WHITE'
WHEN NVL(SD.ASSEMBLE_QTY,0) = S.QTY * BC.QTY THEN 'GREEN'
ELSE 'YELLOW' END IS_ASSEMBLE,BC.HANDLE BOM_COMPONENT_BO,
CASE WHEN CF2.VALUE='Y' THEN 'Y' ELSE 'N' END IS_DISMANTLING, BC."SEQUENCE" SEQ
ELSE 'YELLOW' END IS_ASSEMBLE,BC.HANDLE BOM_COMPONENT_BO, BC."SEQUENCE" SEQ
FROM Z_SFC_DISPATCH DM
INNER JOIN SFC S ON S.SITE = DM.SITE AND S.SFC = DM.SFC
INNER JOIN SFC_BOM SB ON SB.SFC_BO = S.HANDLE
@ -449,8 +448,6 @@
INNER JOIN ITEM I ON I.HANDLE = BC.COMPONENT_GBO
LEFT JOIN ITEM_T IT ON IT.ITEM_BO = I.HANDLE AND IT.LOCALE ='zh'
INNER JOIN CUSTOM_FIELDS I_CF ON I_CF.HANDLE = I.HANDLE AND I_CF."ATTRIBUTE" = 'ACCESSORY_TYPE' AND I_CF.VALUE ='9'
INNER JOIN BOM_OPERATION BO ON BO.BOM_COMPONENT_BO = BC.HANDLE
AND BO.OPERATION_BO = 'OperationBO:'||S.SITE||','||DM.OPERATION||',#'
INNER JOIN CUSTOM_FIELDS CF ON CF.HANDLE = BC.HANDLE AND CF."ATTRIBUTE" = 'STEP_ID' AND CF.VALUE = DM.STEP_ID
LEFT JOIN SFC_DATA SD ON SD.ITEM_BO = I.HANDLE AND BC."SEQUENCE" = SD.SEQ
WHERE DM.HANDLE = #{sfcDispatchBo}

Loading…
Cancel
Save