diff --git a/ic/src/private/nc/bs/ic/m45/insert/InsertBP.java b/ic/src/private/nc/bs/ic/m45/insert/InsertBP.java index 7caa840b..c909e5d3 100644 --- a/ic/src/private/nc/bs/ic/m45/insert/InsertBP.java +++ b/ic/src/private/nc/bs/ic/m45/insert/InsertBP.java @@ -6,14 +6,7 @@ import nc.bs.ic.general.insert.rule.before.CheckCliabilityValue; import nc.bs.ic.general.rule.after.AtpAfterUpdate; import nc.bs.ic.general.rule.before.CtplcustomeridCheck; import nc.bs.ic.m45.base.BPPlugInPoint; -import nc.bs.ic.m45.base.rule.FillCostOrgRule; -import nc.bs.ic.m45.base.rule.PurchaseBillCheckRule; -import nc.bs.ic.m45.base.rule.PurchaseInAssetWarehouseCheck; -import nc.bs.ic.m45.base.rule.PurchaseInVOScaleCheckRule; -import nc.bs.ic.m45.base.rule.PurchaseinRetMarginProcess; -import nc.bs.ic.m45.base.rule.PurchaseinRetMarginProcessFor5805; -import nc.bs.ic.m45.base.rule.ReturnSnIsExistInEquipcardCheck; -import nc.bs.ic.m45.base.rule.VmiCheckRule; +import nc.bs.ic.m45.base.rule.*; import nc.bs.ic.m45.insert.rule.*; import nc.bs.ic.pub.base.ICAroundProcesser; import nc.bs.ic.pub.base.IInsertRuleProvider; @@ -36,7 +29,7 @@ public class InsertBP implements IInsertBP, @Override public void addAfterRule(PurchaseInVO[] vos, AroundProcesser processor) { - //红字采购入库单保存的时候,增加判断逻辑,如果表头仓库是直运仓,不检查物料的现存量 放在前面设置session + // 红字采购入库单保存的时候,增加判断逻辑,如果表头仓库是直运仓,不检查物料的现存量 放在前面设置session processor.addAfterRule(new IsRedBookThrough()); /** @@ -49,7 +42,7 @@ public class InsertBP implements IInsertBP, processor.addAfterRule(new InsertRewriteITRule()); processor.addAfterRule(new MobAfterPurchaseInSave()); processor.addAfterRule(new FeeDetailInsert()); - //红字采购入库单原单退回保存回写累计入库退回主数量,由于预留处理需要查询蓝字采购入库单,回写操作应放在现存量更新规则(OnhandAfterUpdate)之后 + // 红字采购入库单原单退回保存回写累计入库退回主数量,由于预留处理需要查询蓝字采购入库单,回写操作应放在现存量更新规则(OnhandAfterUpdate)之后 ((ICAroundProcesser) processor).addAfterRuleAt(new InsertRedReturnInRewriteRule(), AtpAfterUpdate.class); ((ICAroundProcesser) processor).addAfterRuleAt(new InsertRedReturnInRewriteSORule(), InsertRedReturnInRewriteRule.class); // 回写付款计划 @@ -58,8 +51,8 @@ public class InsertBP implements IInsertBP, processor.addAfterRule(new InsertOrSignRewritePayPlanInvoiceRule(IPaymentUtil.STORE_RECEIPT_DATE)); // 入库单保存回写采购合同付款计划 processor.addAfterRule(new M45SaveAndRewriteCTPayPlan()); - // 精密铸造-无备料领料 - processor.addAfterRule(new NoItemsDeliverMaterialRule()); + // 精密铸造-领料 + processor.addAfterRule(new ManualMaterialPickupRule()); // processor.addAfterRule(new InsertRewritePORule()); } @@ -74,7 +67,7 @@ public class InsertBP implements IInsertBP, processor.addBeforeRule(new PurchaseBillCheckRule()); processor.addBeforeRule(new PurchaseInAssetWarehouseCheck()); // 当数量(主数量,数量,报价数量)与采购订单一致时,使采购入库单表体价格和单价与采购订单一致 - //下面的规则处理会使入库单的改价不生效 hujieh + // 下面的规则处理会使入库单的改价不生效 hujieh // processor.addBeforeRule(new AdjustPriceAndMnyWhenSameNumRule()); processor.addBeforeRule(new CtplcustomeridCheck()); processor.addBeforeRule(new VmiCheckRule()); @@ -85,11 +78,11 @@ public class InsertBP implements IInsertBP, processor.addBeforeRule(new PurchaseInVOScaleCheckRule()); processor.addBeforeRule(new InsertCheckMaterialUnit()); // 利润中心校验规则 - processor.addBeforeRule(new CheckCliabilityValue(MetaNameConst.CLIABILITYOID,MetaNameConst.CIOLIABILITYOID)); + processor.addBeforeRule(new CheckCliabilityValue(MetaNameConst.CLIABILITYOID, MetaNameConst.CIOLIABILITYOID)); // 来源于进口模块--流向单,填充报价单位、报价换算率 processor.addBeforeRule(new FillInVqtunitRule()); - //2025年6月13日09点38分 -- 物料档案基本页签启用项目辅助属性+库存组织未启用项目,采购入库单保存时(包含接口导入)清除行项目,材料出库单保存时(包含接口导入)清除行项目 + // 2025年6月13日09点38分 -- 物料档案基本页签启用项目辅助属性+库存组织未启用项目,采购入库单保存时(包含接口导入)清除行项目,材料出库单保存时(包含接口导入)清除行项目 processor.addBeforeRule(new PurchaseInProjectRule()); } diff --git a/ic/src/private/nc/bs/ic/m45/insert/rule/ManualMaterialPickupRule.java b/ic/src/private/nc/bs/ic/m45/insert/rule/ManualMaterialPickupRule.java new file mode 100644 index 00000000..a6958b22 --- /dev/null +++ b/ic/src/private/nc/bs/ic/m45/insert/rule/ManualMaterialPickupRule.java @@ -0,0 +1,248 @@ +package nc.bs.ic.m45.insert.rule; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.InvocationInfoProxy; +import nc.bs.framework.common.NCLocator; +import nc.bs.logging.Log; +import nc.bs.trade.business.HYPubBO; +import nc.bs.uapbd.util.MyHelper; +import nc.impl.pubapp.pattern.rule.IRule; +import nc.itf.mmpac.pmo.pac0002.IPMOQueryService; +import nc.itf.uap.IUAPQueryBS; +import nc.util.mmf.framework.base.MMArrayUtil; +import nc.util.mmf.framework.base.MMValueCheck; +import nc.vo.bd.material.MaterialVO; +import nc.vo.ic.m45.entity.PurchaseInBodyVO; +import nc.vo.ic.m45.entity.PurchaseInHeadVO; +import nc.vo.ic.m45.entity.PurchaseInVO; +import nc.vo.ic.m4d.entity.MaterialOutVO; +import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO; +import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO; +import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO; +import nc.vo.mmpac.pmo.pac0002.enumeration.PMOFBillstatusEnum; +import nc.vo.mmpac.pmo.pac0002.enumeration.PMOFItemStatusEnum; +import nc.vo.org.DeptVO; +import nc.vo.org.OrgVO; +import nc.vo.pmpub.common.utils.ArrayUtils; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.pubapp.pattern.pub.SqlBuilder; +import nc.vo.scmf.ic.mbatchcode.BatchcodeVO; +import nccloud.api.ic.m4d.IAPIMaterialOutMaintain; + +import java.util.*; + +/** + * 精密铸造-根据采购入库进行手工领料 + * + * @author mzr + * @date 2025/10/31 + */ +public class ManualMaterialPickupRule implements IRule { + private static final String LOG_INFO_NAME = "jmqylog"; + private static final Log logger = Log.getInstance(LOG_INFO_NAME); + public BaseDAO dao; + + public BaseDAO getDao() { + if (dao == null) { + dao = new BaseDAO(); + } + return dao; + } + + private IUAPQueryBS queryBS = null; + + public final IUAPQueryBS getQueryBS() { + if (null == queryBS) { + queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); + } + return queryBS; + } + + @Override + public void process(PurchaseInVO[] vos) { + if (ArrayUtils.isEmpty(vos)) { + return; + } + try { + handelMaterial(vos); + } catch (BusinessException e) { + logger.error("ManualMaterialPickupRule-exp:" + e.getMessage(), e); + ExceptionUtils.wrappException(e); + } + } + + private void handelMaterial(PurchaseInVO[] inVOS) throws BusinessException { + String orgCondition = "code = 'C038' and enablestate = '2' and isbusinessunit='Y'"; + HYPubBO hyPub = new HYPubBO(); + String orgId = hyPub.findColValue(OrgVO.getDefaultTableName(), OrgVO.PK_ORG, orgCondition) + ""; + // 精密铸造,生成采购入库成功后再进行领料 + for (PurchaseInVO inVO : inVOS) { + PurchaseInHeadVO head = inVO.getHead(); + PurchaseInBodyVO[] bodys = inVO.getBodys(); + String pkOrg = head.getPk_org(); + String vbillcode = head.getVbillcode(); + UFDate dbilldate = head.getDbilldate(); + // 判断是否是精密铸造(C038) + if (!"null".equals(orgId) && orgId.equals(pkOrg)) { + Map configParams = MyHelper.getConfigParams("jm-config", null); + if (configParams.isEmpty()) { + ExceptionUtils.wrappBusinessException("自定义档案中的jm-config参数未配置"); + } + String warehouseCode = configParams.get("warehouseCode"); + if (MMValueCheck.isEmpty(warehouseCode) || "~".equals(warehouseCode)) { + ExceptionUtils.wrappBusinessException("请检查仓库编码是否配置正确"); + } + String configMaterialCode = configParams.get("noItemCode"); + if (configMaterialCode == null || configMaterialCode.isEmpty()) { + ExceptionUtils.wrappBusinessException("自定义档案中的物料参数未配置"); + } + String trantypecode = configParams.get("in-trantypecode"); + if (trantypecode == null || trantypecode.isEmpty()) { + ExceptionUtils.wrappBusinessException("自定义档案中的单据类型参数未配置"); + } + Set rowIds = new HashSet<>(); + for (PurchaseInBodyVO body : bodys) { + String cmaterialvid = body.getCmaterialvid(); + String condition = "pk_material = '" + cmaterialvid + "'"; + String materialCode = hyPub.findColValue(MaterialVO.getDefaultTableName(), MaterialVO.CODE, condition) + ""; + if (configMaterialCode.equals(materialCode)) { + // 批次号=流程生产订单明细id + String vbatchcode = body.getVbatchcode(); + if (vbatchcode == null || vbatchcode.isEmpty()) { + continue; + } + rowIds.add(vbatchcode); + } + } + if (rowIds.isEmpty()) { + ExceptionUtils.wrappBusinessException("没有符合条件的流程生产订单信息,无法进行领料"); + } + // 根据流程生产订单明细id分单生成材料出库 + for (String mobid : rowIds) { + // 流程生产订单明细id + // ====领料前校验流程生产订单-start==== + IPMOQueryService pmoQuery = NCLocator.getInstance().lookup(IPMOQueryService.class); + PMOAggVO[] pmoAggVOS = pmoQuery.queryPMOAggVOByBid(new String[]{mobid}); + if (MMValueCheck.isEmpty(pmoAggVOS)) { + ExceptionUtils.wrappBusinessException("查询不到对应的流程生产订单,无法进行领料"); + } + PMOAggVO aggvo = pmoAggVOS[0]; + PMOHeadVO pmoHeadvo = aggvo.getParentVO(); + if (!PMOFBillstatusEnum.AUDIT.equalsValue(pmoHeadvo.getFbillstatus())) { + ExceptionUtils.wrappBusinessException("流程生产订单未审核通过,无法进行领料"); + } + PMOItemVO[] items = aggvo.getChildrenVO(); + PMOItemVO pmoItemVO = null; + if (!MMArrayUtil.isEmpty(items)) { + for (PMOItemVO item : items) { + String cmoid = item.getCmoid(); + if (mobid.equals(cmoid)) { + if (!PMOFItemStatusEnum.PUT.equalsValue(item.getFitemstatus()) && + !PMOFItemStatusEnum.AUDIT.equalsValue(item.getFitemstatus()) + ) { + ExceptionUtils.wrappBusinessException("流程生产订单明细未完成,无法进行领料"); + } + pmoItemVO = item; + } + } + } + if (pmoItemVO == null) { + return; + } + // ====领料前校验流程生产订单-end==== + // 查询领料部门 + String cdeptid = pmoItemVO.getCdeptid(); + Object deptCode = hyPub.findColValue(DeptVO.getDefaultTableName(), DeptVO.CODE, + "pk_dept = '" + cdeptid + "'"); + if (deptCode == null) { + ExceptionUtils.wrappBusinessException("查询不到领料部门,无法进行领料"); + } + String cmaterialvidPmo = pmoItemVO.getCmaterialvid(); + Object materialCodePmo = hyPub.findColValue(MaterialVO.getDefaultTableName(), MaterialVO.CODE, "pk_material = '" + cmaterialvidPmo + "'"); + if (materialCodePmo == null) { + ExceptionUtils.wrappBusinessException("查询不到产成品信息,无法进行领料"); + } + JSONObject headOutJson = new JSONObject(); + headOutJson.put("pk_org", "C038"); + headOutJson.put("pk_org_v", "C038"); + headOutJson.put("cdptvid", deptCode + ""); + headOutJson.put("cwarehouseid", warehouseCode); + headOutJson.put("vtrantypecode", trantypecode); + headOutJson.put("dbilldate", dbilldate);// 单据日期 + headOutJson.put("vnote", vbillcode); + headOutJson.put("billmaker", "BIP"); + JSONArray bodyOutArr = new JSONArray(); + for (PurchaseInBodyVO body : bodys) { + JSONObject bodyJson = new JSONObject(); + String cmaterialvid = body.getCmaterialvid(); + String condition = "pk_material = '" + cmaterialvid + "'"; + String materialCode = hyPub.findColValue(MaterialVO.getDefaultTableName(), MaterialVO.CODE, condition) + ""; + // 根据该费用物料进行领料 + if (configMaterialCode.equals(materialCode) && mobid.equals(body.getVbatchcode())) { + // 批次号=流程生产订单明细id + String vbatchcode = body.getVbatchcode(); + if (vbatchcode == null || vbatchcode.isEmpty()) { + ExceptionUtils.wrappBusinessException("未存储流程生产明细id,无法进行领料"); + } + // 获取采购入库表体的应收主数量 nshouldnum + UFDouble nshouldnum = body.getNshouldnum(); + bodyJson.put("cmaterialvid", cmaterialvid); + bodyJson.put("nshouldnum", nshouldnum);// 应发主数量 + bodyJson.put("nshouldassistnum", nshouldnum);// 应发数量 + bodyJson.put("nnum", nshouldnum);// 实发主数量 + bodyJson.put("nassistnum", nshouldnum);// 实发数量 + bodyJson.put("dbizdate", dbilldate);// 出库日期 + bodyJson.put("vchangerate", "1/1"); + // 批次号赋值 + bodyJson.put("vbatchcode", mobid);// 批次号 + Map batchMap = getBatchCodeVO(cmaterialvid, mobid); + String pkBatchcode = batchMap.get(mobid); + bodyJson.put("pk_batchcode", pkBatchcode);// 批次档案id + bodyJson.put("vproductbatch", pmoHeadvo.getVbillcode());// 生产订单号 + bodyJson.put("ccostobject", materialCodePmo + "");// 产成品 + bodyOutArr.add(bodyJson); + } + } + if (bodyOutArr.isEmpty()) { + continue; + } + Map params = new HashMap<>(); + params.put("ic_material_h", headOutJson); + params.put("ic_material_b", bodyOutArr); + List> paramList = new ArrayList<>(); + paramList.add(params); + IAPIMaterialOutMaintain materialOut = + NCLocator.getInstance().lookup(IAPIMaterialOutMaintain.class); + MaterialOutVO[] materialOutVOs = materialOut.save(paramList); + } + + } + } + } + + public Map getBatchCodeVO(String cbmaterialvid, String vbatchcode) + throws BusinessException { + Map resMap = new HashMap<>(); + SqlBuilder sb = new SqlBuilder(); + sb.append("pk_group", InvocationInfoProxy.getInstance().getGroupId()); + sb.append(" and "); + sb.append("nvl(dr,0)", 0); + sb.append(" and "); + sb.append("cmaterialvid", cbmaterialvid); + sb.append(" and "); + sb.append("vbatchcode", vbatchcode); + Collection vos = this.getQueryBS().retrieveByClause(BatchcodeVO.class, sb.toString()); + for (BatchcodeVO vo : vos) { + String pk_batchcode = vo.getPk_batchcode(); + String vbatchcode1 = vo.getVbatchcode(); + resMap.put(vbatchcode1, pk_batchcode); + } + return resMap; + } + +}