ic材料出库: 金思维材料出库时补充来源单据
- 新增检查特殊条件的方法,判断是否为C034组织 - 新增处理备料计划特殊逻辑的方法,补充来源相关数据 - 添加备料计划数据查询和处理相关方法
This commit is contained in:
parent
983cc1ecb8
commit
dd2003a1e2
|
@ -1,20 +1,15 @@
|
|||
package nccloud.api.impl.ic.m4d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import nc.bs.dao.BaseDAO;
|
||||
import nc.bs.framework.common.NCLocator;
|
||||
import nc.bs.scmpub.query.SCMBillQuery;
|
||||
import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil;
|
||||
import nc.jdbc.framework.processor.ColumnProcessor;
|
||||
import nc.jdbc.framework.processor.MapListProcessor;
|
||||
import nc.pubimpl.ic.api.maintain.BillMaintainTool;
|
||||
import nc.pubitf.ic.m4d.api.IMaterialOutMaintainAPI;
|
||||
import nc.vo.bd.material.MaterialVO;
|
||||
import nc.vo.ic.general.define.ICBillFlag;
|
||||
import nc.vo.ic.general.define.ICBillHeadVO;
|
||||
import nc.vo.ic.general.util.ICLocationUtil;
|
||||
|
@ -25,6 +20,7 @@ import nc.vo.ic.m4d.entity.MaterialOutVO;
|
|||
import nc.vo.ic.pub.define.ICPubMetaNameConst;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.pub.VOStatus;
|
||||
import nc.vo.pubapp.pattern.pub.SqlBuilder;
|
||||
import nc.vo.scmpub.check.billvalidate.BillVOsCheckRule;
|
||||
import nc.vo.scmpub.res.billtype.ICBillType;
|
||||
import nccloud.api.ic.m4d.IAPIMaterialOutMaintain;
|
||||
|
@ -35,6 +31,10 @@ import nccloud.api.impl.ic.pub.check.CheckProhibitUpdateFields;
|
|||
import nccloud.openapi.ic.util.ICAPILocationVOUtils;
|
||||
import nccloud.openapi.scmpub.pub.TransferCodeToPKTool;
|
||||
import nccloud.openapi.scmpub.pub.TransferMapToVOTool;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,6 +47,8 @@ import nccloud.openapi.scmpub.pub.TransferMapToVOTool;
|
|||
|
||||
public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain{
|
||||
|
||||
private static final BaseDAO DAO = new BaseDAO();
|
||||
|
||||
@Override
|
||||
public MaterialOutVO[] save(List<Map<String, Object>> paramList) throws BusinessException {
|
||||
// MapList转聚合VOList
|
||||
|
@ -64,6 +66,12 @@ public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain{
|
|||
aggVOList = TransferCodeToPKTool.transferAggVO(aggVOList);
|
||||
// 翻译货位
|
||||
ICAPILocationVOUtils.translate(vos);
|
||||
|
||||
boolean isSpecialCase = checkSpecialCondition(paramList);
|
||||
// 如果判定成功,处理金思维的材料出库,将来源的相关数据补充上
|
||||
if (isSpecialCase) {
|
||||
processPickingPlanSpecialLogic(vos);
|
||||
}
|
||||
//其他数据填充
|
||||
new MaterialOutSaveFillValue().setDefaultValue(vos);
|
||||
|
||||
|
@ -269,4 +277,135 @@ public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain{
|
|||
return materialOut.insertBills(vos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否满足特殊条件:C034组织
|
||||
*/
|
||||
private boolean checkSpecialCondition(List<Map<String, Object>> materialOutVOS) throws BusinessException {
|
||||
|
||||
List<MaterialOutVO> aggVOList =
|
||||
TransferMapToVOTool.transferMapToAggVO(materialOutVOS, MaterialOutVO.class);
|
||||
MaterialOutVO[] vos =
|
||||
aggVOList.toArray(new MaterialOutVO[aggVOList.size()]);
|
||||
|
||||
if(Objects.isNull(materialOutVOS)){
|
||||
return false;
|
||||
}
|
||||
for (MaterialOutVO materialOutVO : vos) {
|
||||
MaterialOutHeadVO head = materialOutVO.getHead();
|
||||
// 提取组织
|
||||
String pkOrg = head.getPk_org();
|
||||
// 翻译成code
|
||||
// String orgCode = transferCodeByPk(StockOrgVO.getDefaultTableName(), StockOrgVO.CODE, StockOrgVO.PK_ORG, pkOrg);
|
||||
// 这是未翻译的,传进来的原始数据转换的,所以直接比较
|
||||
if("C034".equals(pkOrg)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理备料计划特殊逻辑
|
||||
*/
|
||||
private void processPickingPlanSpecialLogic(MaterialOutVO[] vos) throws BusinessException {
|
||||
|
||||
for (MaterialOutVO vo : vos) {
|
||||
MaterialOutBodyVO[] bodyVOs = vo.getBodys();
|
||||
if (bodyVOs != null) {
|
||||
for (MaterialOutBodyVO bodyVO : bodyVOs) {
|
||||
// 获取物料编码
|
||||
String materialCode = transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE, MaterialVO.PK_MATERIAL, bodyVO.getCmaterialvid());
|
||||
if (StringUtils.isEmpty(materialCode)|| StringUtils.isEmpty(bodyVO.getCsourcebillbid())) {
|
||||
continue;
|
||||
}
|
||||
// 基于mmpickmview视图查询备料计划相关数据
|
||||
String sql = buildPickingPlanQuery(materialCode,bodyVO.getCsourcebillbid());
|
||||
|
||||
try {
|
||||
List<Map<String, Object>> pickingPlanData = (List<Map<String, Object>>) DAO.executeQuery(sql, new MapListProcessor());
|
||||
|
||||
// 不唯一或者找不到,这样是有问题,抛出
|
||||
if(pickingPlanData==null || pickingPlanData.isEmpty()){
|
||||
throw new BusinessException("根据生产订单明细主键和物料编码去查询bip的中间视图mmpickmview找不到数据,无法进行材料出库的上游主键赋值,请检查数据,报错SQL:"+sql);
|
||||
}
|
||||
|
||||
if(pickingPlanData.size()!=1){
|
||||
throw new BusinessException("根据生产订单明细主键和物料编码去查询bip的中间视图mmpickmview不唯一,无法进行材料出库的上游主键赋值,请检查数据,报错SQL:"+sql);
|
||||
}
|
||||
|
||||
if (pickingPlanData != null && !pickingPlanData.isEmpty()) {
|
||||
// 处理查询到的备料计划数据
|
||||
processPickingPlanData(bodyVO, pickingPlanData);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("查询备料计划数据失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建备料计划查询SQL(基于mmpickmview视图)
|
||||
*/
|
||||
private String buildPickingPlanQuery(String materialCode,String cpmohid) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ");
|
||||
sql.append(" CODE,"); // 物料编码
|
||||
sql.append(" PK_BILLTYPECODE,"); // 备料计划交易类型编码
|
||||
sql.append(" CPICKMID,"); // 备料计划主键
|
||||
sql.append(" CMOID,"); // 流程生产订单行主
|
||||
sql.append(" CPMOHID,"); // 流程生产订单主键
|
||||
sql.append(" VROWNO,"); // 备料计划明细行号
|
||||
sql.append(" CPICKM_BID "); // 备料计划明细主键
|
||||
sql.append("FROM MMPICKMVIEW ");
|
||||
sql.append("WHERE CODE = '").append(materialCode).append("' AND ")
|
||||
.append("cmoid ='").append(cpmohid).append("'");
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理备料计划数据
|
||||
*/
|
||||
private void processPickingPlanData(MaterialOutBodyVO bodyVO, List<Map<String, Object>> pickingPlanData) {
|
||||
if (pickingPlanData == null || pickingPlanData.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> firstRow = pickingPlanData.get(0);
|
||||
|
||||
// 设置备料计划相关字段
|
||||
if (firstRow.get("cpickmid") != null) {
|
||||
bodyVO.setCsourcebillhid(firstRow.get("cpickmid").toString()); // 来源单据ID
|
||||
}
|
||||
|
||||
if (firstRow.get("cpickm_bid") != null) {
|
||||
bodyVO.setCsourcebillbid(firstRow.get("cpickm_bid").toString()); // 来源单据行ID
|
||||
}
|
||||
|
||||
if (firstRow.get("pk_billtypecode") != null) {
|
||||
bodyVO.setCsourcetranstype(firstRow.get("pk_billtypecode").toString()); // 交易类型编码
|
||||
}
|
||||
bodyVO.setCsourcetype("55A3");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键查询编码
|
||||
*/
|
||||
private String transferCodeByPk(String tableName, String selectField, String pkField, String pk) throws BusinessException {
|
||||
if (nc.vo.cmp.util.StringUtils.isEmpty(pk)) {
|
||||
return null;
|
||||
}
|
||||
SqlBuilder sqlBuilder = new SqlBuilder();
|
||||
sqlBuilder.append(" select " + selectField);
|
||||
sqlBuilder.append(" from " + tableName);
|
||||
sqlBuilder.append(" where ");
|
||||
sqlBuilder.append(pkField, pk);
|
||||
Object o = DAO.executeQuery(sqlBuilder.toString(), new ColumnProcessor());
|
||||
if (o == null) {
|
||||
throw new BusinessException("未查询到编码信息,sql【" + sqlBuilder + "】");
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue