|
|
|
|
@ -0,0 +1,235 @@
|
|
|
|
|
package com.op.wms.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
|
import com.op.common.core.utils.uuid.IdUtils;
|
|
|
|
|
import com.op.common.core.web.domain.AjaxResult;
|
|
|
|
|
import com.op.system.api.RemoteSapService;
|
|
|
|
|
import com.op.system.api.domain.sap.SapBackflushMPQuery;
|
|
|
|
|
import com.op.wms.domain.OdsProcureOutOrder;
|
|
|
|
|
import com.op.wms.domain.query.BatchProductionMaterialQuery;
|
|
|
|
|
import com.op.wms.mapper.MesPrepareMapper;
|
|
|
|
|
import com.op.wms.mapper.OdsProcureOutOrderMapper;
|
|
|
|
|
import com.op.wms.service.IWmsRawMaterialOutService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* remark
|
|
|
|
|
*
|
|
|
|
|
* @author 019117
|
|
|
|
|
* @date
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class WmsRawMaterialOutServiceImpl implements IWmsRawMaterialOutService {
|
|
|
|
|
|
|
|
|
|
private final OdsProcureOutOrderMapper odsProcureOutOrderMapper;
|
|
|
|
|
|
|
|
|
|
private final MesPrepareMapper mesPrepareMapper;
|
|
|
|
|
|
|
|
|
|
private final RemoteSapService remoteSapService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
public List<OdsProcureOutOrder> getTransferMaterialList(BatchProductionMaterialQuery query) {
|
|
|
|
|
|
|
|
|
|
//获取当前生产工单号
|
|
|
|
|
List<String> workOrderCodeList = mesPrepareMapper.selectMesPrepareList(query);
|
|
|
|
|
|
|
|
|
|
//查询包材出库单是否有数据(查询每张订单是否都有物料)
|
|
|
|
|
for (String code : workOrderCodeList) {
|
|
|
|
|
query.setUserDefined6(code);
|
|
|
|
|
List<OdsProcureOutOrder> list = odsProcureOutOrderMapper.getBatchProductionMaterialList(query);
|
|
|
|
|
if (list.isEmpty()){
|
|
|
|
|
//如果没有数据则从生产工单获取到生产物料
|
|
|
|
|
OdsProcureOutOrder order = new OdsProcureOutOrder();
|
|
|
|
|
order.setWorkorderCode(code);
|
|
|
|
|
List<OdsProcureOutOrder> orderList= odsProcureOutOrderMapper.selectMesPrepareDetailBC(order);
|
|
|
|
|
Integer orderItem = 0;
|
|
|
|
|
for (OdsProcureOutOrder order1: orderList) {
|
|
|
|
|
orderItem++;
|
|
|
|
|
OdsProcureOutOrder odsProcureOutOrder1 = new OdsProcureOutOrder();
|
|
|
|
|
odsProcureOutOrder1.setID(IdUtils.fastSimpleUUID());
|
|
|
|
|
odsProcureOutOrder1.setSiteCode(query.getFactoryCode());
|
|
|
|
|
odsProcureOutOrder1.setProduceCode(query.getCode());
|
|
|
|
|
odsProcureOutOrder1.setOutNumber(new BigDecimal("0"));
|
|
|
|
|
odsProcureOutOrder1.setMaterialCode(order1.getMaterialCode());
|
|
|
|
|
odsProcureOutOrder1.setMaterialDesc(order1.getMaterialDesc());
|
|
|
|
|
odsProcureOutOrder1.setPlanDate(new Date());
|
|
|
|
|
odsProcureOutOrder1.setUnit(order1.getUnit());
|
|
|
|
|
odsProcureOutOrder1.setActive("1");
|
|
|
|
|
odsProcureOutOrder1.setOrderStatus("1");
|
|
|
|
|
odsProcureOutOrder1.setPlanNumber(order1.getPlanNumber());
|
|
|
|
|
odsProcureOutOrder1.setUserDefined2(String.format("%05d", orderItem));
|
|
|
|
|
odsProcureOutOrder1.setUserDefined3("ZC");
|
|
|
|
|
odsProcureOutOrder1.setUserDefined4(query.getCode());
|
|
|
|
|
odsProcureOutOrder1.setUserDefined10("1");
|
|
|
|
|
odsProcureOutOrder1.setUserDefined5(order1.getNeedDate());
|
|
|
|
|
odsProcureOutOrder1.setUserDefined6(code);
|
|
|
|
|
odsProcureOutOrder1.setCreateBy(query.getOperator());
|
|
|
|
|
odsProcureOutOrder1.setCreateDate(new Date());
|
|
|
|
|
//写入包材出库单
|
|
|
|
|
odsProcureOutOrderMapper.insertWmsOdsProcureOutOrder(odsProcureOutOrder1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//重新查询(相同物料需要合并计算)
|
|
|
|
|
query.setUserDefined6(null);
|
|
|
|
|
return odsProcureOutOrderMapper.getBatchProductionMaterialList(query);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
public AjaxResult submitTransferMaterialList(OdsProcureOutOrder params) {
|
|
|
|
|
|
|
|
|
|
//更新出库单及新增出库明细
|
|
|
|
|
updateOdsProcureOutOrder(params);
|
|
|
|
|
|
|
|
|
|
//获取已完成,但没有过账的转储物料
|
|
|
|
|
BatchProductionMaterialQuery query = new BatchProductionMaterialQuery();
|
|
|
|
|
query.setUserDefined3("ZC");
|
|
|
|
|
query.setOrderStatus("3");
|
|
|
|
|
query.setActive("1");
|
|
|
|
|
query.setUserDefined10("1");
|
|
|
|
|
List<OdsProcureOutOrder> orderList = odsProcureOutOrderMapper.getBatchProductionMaterialList(query);
|
|
|
|
|
|
|
|
|
|
if (orderList.isEmpty()){
|
|
|
|
|
return AjaxResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Map<String,Object>> list = new ArrayList<>();
|
|
|
|
|
for(OdsProcureOutOrder order : orderList){
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
map.put("PLANT", params.getFactoryCode());
|
|
|
|
|
map.put("LGORT", "0001");
|
|
|
|
|
map.put("MATNR", order.getMaterialCode());
|
|
|
|
|
map.put("QUANTITY", order.getOutNumber());
|
|
|
|
|
map.put("MEINS", order.getUnit());
|
|
|
|
|
map.put("MOVE_STLOC", "0087");
|
|
|
|
|
list.add(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//过账
|
|
|
|
|
R result = remoteSapService.sapTransferPosting(list);
|
|
|
|
|
return postHandle(result,orderList);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
public AjaxResult submitReverseMaterialList(OdsProcureOutOrder params) {
|
|
|
|
|
//更新出库单及新增出库明细
|
|
|
|
|
updateOdsProcureOutOrder(params);
|
|
|
|
|
|
|
|
|
|
//获取已完成,但没有过账的反冲物料
|
|
|
|
|
BatchProductionMaterialQuery query = new BatchProductionMaterialQuery();
|
|
|
|
|
query.setUserDefined3("X");
|
|
|
|
|
query.setOrderStatus("3");
|
|
|
|
|
query.setActive("1");
|
|
|
|
|
query.setUserDefined10("1");
|
|
|
|
|
List<OdsProcureOutOrder> orderList = odsProcureOutOrderMapper.getBatchProductionMaterialList(query);
|
|
|
|
|
if (orderList.isEmpty()){
|
|
|
|
|
return AjaxResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Map<String,Object>> list = new ArrayList<>();
|
|
|
|
|
for(OdsProcureOutOrder order : orderList){
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
map.put("PLANT", params.getFactoryCode());
|
|
|
|
|
map.put("LGORT", "0001");
|
|
|
|
|
map.put("MATNR", order.getMaterialCode());
|
|
|
|
|
map.put("QUANTITY", order.getOutNumber());
|
|
|
|
|
map.put("MEINS", order.getUnit());
|
|
|
|
|
map.put("MOVE_STLOC", "0013");
|
|
|
|
|
list.add(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
R result = remoteSapService.sapTransferPosting(list);
|
|
|
|
|
return postHandle(result,orderList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新出库单及出库明细
|
|
|
|
|
private void updateOdsProcureOutOrder(OdsProcureOutOrder params) {
|
|
|
|
|
List<OdsProcureOutOrder> orderList = params.getOrderList();
|
|
|
|
|
|
|
|
|
|
//遍历列表
|
|
|
|
|
for (OdsProcureOutOrder order : orderList) {
|
|
|
|
|
//计划数量
|
|
|
|
|
BigDecimal planQty = order.getPlanNumber();
|
|
|
|
|
//已出数量
|
|
|
|
|
BigDecimal outQty = order.getOutNumber();
|
|
|
|
|
//当前需出库数量
|
|
|
|
|
BigDecimal currentQty = order.getQty();
|
|
|
|
|
//应出数量 = 已出+需出
|
|
|
|
|
BigDecimal totalQty = BigDecimal.ZERO;
|
|
|
|
|
if (currentQty == null) {
|
|
|
|
|
totalQty = outQty;
|
|
|
|
|
}else {
|
|
|
|
|
totalQty = outQty.add(currentQty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//已出+需出=计划数量,则满足出库状态
|
|
|
|
|
if (totalQty.compareTo(planQty) >= 0) {
|
|
|
|
|
order.setOrderStatus("3");
|
|
|
|
|
}else {
|
|
|
|
|
order.setOrderStatus("2");
|
|
|
|
|
}
|
|
|
|
|
if ("1".equals(order.getIsPost())){
|
|
|
|
|
order.setOrderStatus("3");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("3".equals(order.getOrderStatus())) {
|
|
|
|
|
//应出数量为0,返回错误
|
|
|
|
|
if (totalQty.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
throw new RuntimeException("物料编码:"+ order.getMaterialCode() + ",出库数量为0,无法过账");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新已出数量
|
|
|
|
|
order.setOutNumber(totalQty);
|
|
|
|
|
order.setLastUpdateBy(params.getCreateBy());
|
|
|
|
|
order.setLastUpdateDate(new Date());
|
|
|
|
|
//更新出库单
|
|
|
|
|
odsProcureOutOrderMapper.updateWmsOdsProcureOutOrder(order);
|
|
|
|
|
//新增出库明细
|
|
|
|
|
order.setID(IdUtils.fastSimpleUUID());
|
|
|
|
|
order.setActive("1");
|
|
|
|
|
order.setCreateBy(params.getCreateBy());
|
|
|
|
|
order.setCreateDate(new Date());
|
|
|
|
|
order.setUserDefined1(null);
|
|
|
|
|
order.setUserDefined2(null);
|
|
|
|
|
odsProcureOutOrderMapper.insertWmsRawMissionOut(order);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//过账信息处理
|
|
|
|
|
private AjaxResult postHandle(R result, List<OdsProcureOutOrder> list) {
|
|
|
|
|
int code = result.getCode();
|
|
|
|
|
OdsProcureOutOrder order = new OdsProcureOutOrder();
|
|
|
|
|
String msg = result.getMsg();
|
|
|
|
|
order.setUserDefined11(msg);
|
|
|
|
|
if (code == 200) {
|
|
|
|
|
//过账成功
|
|
|
|
|
Map<String,Object> map = (Map<String,Object>) result.getData();
|
|
|
|
|
String userDefined9 = (String) map.get("postCode");
|
|
|
|
|
order.setUserDefined9(userDefined9);
|
|
|
|
|
//成功
|
|
|
|
|
order.setUserDefined10("2");
|
|
|
|
|
odsProcureOutOrderMapper.updateWMSOdsProcureOutOrderByids(order, list);
|
|
|
|
|
return AjaxResult.success(msg);
|
|
|
|
|
} else {
|
|
|
|
|
order.setUserDefined9("");
|
|
|
|
|
//失败
|
|
|
|
|
order.setUserDefined10("3");
|
|
|
|
|
odsProcureOutOrderMapper.updateWMSOdsProcureOutOrderByids(order, list);
|
|
|
|
|
return AjaxResult.error(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|