精密铸造-根据采购入库进行无备料领料-V1
This commit is contained in:
		
							parent
							
								
									c6f9c1a729
								
							
						
					
					
						commit
						9bee99b80b
					
				|  | @ -58,6 +58,8 @@ public class InsertBP implements IInsertBP<PurchaseInVO>, | |||
|         processor.addAfterRule(new InsertOrSignRewritePayPlanInvoiceRule(IPaymentUtil.STORE_RECEIPT_DATE)); | ||||
|         // 흙욋데괏닸쀼畇꽃뭔북谿마운셕뺍 | ||||
|         processor.addAfterRule(new M45SaveAndRewriteCTPayPlan()); | ||||
|         // 精密铸造-无备料领料 | ||||
|         processor.addAfterRule(new NoItemsDeliverMaterialRule()); | ||||
| 
 | ||||
|         // processor.addAfterRule(new InsertRewritePORule()); | ||||
|     } | ||||
|  |  | |||
|  | @ -0,0 +1,252 @@ | |||
| package nc.bs.ic.m45.insert.rule; | ||||
| 
 | ||||
| import nc.bs.dao.BaseDAO; | ||||
| import nc.bs.dao.DAOException; | ||||
| 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.pickm.IPickmBusinessService; | ||||
| import nc.itf.mmpac.pmo.pac0002.IPMOQueryService; | ||||
| import nc.itf.mmpac.pmo.pac0002.IPMOTransTypeQueryService; | ||||
| import nc.itf.uap.IUAPQueryBS; | ||||
| import nc.jdbc.framework.processor.ColumnProcessor; | ||||
| import nc.jdbc.framework.processor.MapProcessor; | ||||
| import nc.pubitf.mmpac.pickm.mo.IPickmQueryServiceForMO; | ||||
| import nc.util.mmf.framework.base.MMArrayUtil; | ||||
| import nc.util.mmf.framework.base.MMValueCheck; | ||||
| import nc.vo.bd.material.MaterialVO; | ||||
| import nc.vo.bd.stordoc.StordocVO; | ||||
| import nc.vo.ic.m45.entity.PurchaseInBodyVO; | ||||
| import nc.vo.ic.m45.entity.PurchaseInHeadVO; | ||||
| import nc.vo.ic.m45.entity.PurchaseInVO; | ||||
| import nc.vo.ml.NCLangRes4VoTransl; | ||||
| import nc.vo.mmpac.pickm.entity.AggPickmVO; | ||||
| import nc.vo.mmpac.pickm.entity.PickmHeadVO; | ||||
| import nc.vo.mmpac.pickm.entity.PickmItemVO; | ||||
| import nc.vo.mmpac.pickm.enumeration.FbillstatusEnum; | ||||
| import nc.vo.mmpac.pickm.param.PickmTransParam; | ||||
| import nc.vo.mmpac.pmo.pac0002.constant.PMOConstLang; | ||||
| 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.OrgVO; | ||||
| import nc.vo.pmpub.common.utils.ArrayUtils; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pub.VOStatus; | ||||
| import nc.vo.pub.lang.UFBoolean; | ||||
| 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 java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * 精密铸造-根据采购入库进行无备料领料 | ||||
|  * | ||||
|  * @author mzr | ||||
|  * @date 2025/10/14 | ||||
|  */ | ||||
| public class NoItemsDeliverMaterialRule implements IRule<PurchaseInVO> { | ||||
|     private static final String LOG_INFO_NAME = "qyMesLog"; | ||||
|     private static final Log logger = Log.getInstance(LOG_INFO_NAME); | ||||
|     public BaseDAO dao; | ||||
| 
 | ||||
|     public BaseDAO getDao() { | ||||
|         if (dao == null) { | ||||
|             dao = new BaseDAO(); | ||||
|         } | ||||
|         return dao; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void process(PurchaseInVO[] vos) { | ||||
|         if (ArrayUtils.isEmpty(vos)) { | ||||
|             return; | ||||
|         } | ||||
|         try { | ||||
|             noItemsDeliverMaterial(vos); | ||||
|         } catch (BusinessException e) { | ||||
|             logger.error("NoItemsDeliverMaterialRule-exp:" + e.getMessage(), e); | ||||
|             ExceptionUtils.wrappException(e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void noItemsDeliverMaterial(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(); | ||||
|             // 判断是否是精密铸造(C038) | ||||
|             if (!"null".equals(orgId) && orgId.equals(pkOrg)) { | ||||
|                 Map<String, String> configParams = MyHelper.getConfigParams("jm-config", null); | ||||
|                 if (configParams.isEmpty()) { | ||||
|                     ExceptionUtils.wrappBusinessException("自定义档案中的jm-config参数未配置"); | ||||
|                 } | ||||
|                 for (PurchaseInBodyVO body : bodys) { | ||||
|                     String cmaterialvid = body.getCmaterialvid(); | ||||
|                     String condition = "pk_material = '" + cmaterialvid + "'"; | ||||
|                     String materialCode = hyPub.findColValue(MaterialVO.getDefaultTableName(), MaterialVO.CODE, condition) + ""; | ||||
|                     // 根据该费用物料无备料领料 | ||||
|                     String configMaterialCode = configParams.get("noItemCode"); | ||||
|                     if (configMaterialCode == null || configMaterialCode.isEmpty()) { | ||||
|                         ExceptionUtils.wrappBusinessException("自定义档案中的物料参数未配置"); | ||||
|                     } | ||||
|                     if (configMaterialCode.equals(materialCode)) { | ||||
|                         // 批次号=流程生产订单明细id | ||||
|                         String vbatchcode = body.getVbatchcode(); | ||||
|                         if (vbatchcode == null || vbatchcode.isEmpty()) { | ||||
|                             ExceptionUtils.wrappBusinessException("未存储流程生产明细id,无法进行无备料领料"); | ||||
|                         } | ||||
|                         // 流程生产订单明细id | ||||
|                         String mobid = vbatchcode; | ||||
|                         // ====领料前校验流程生产订单-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]; | ||||
|                         List<String> cmoidList = new ArrayList<>(); | ||||
|                         PMOHeadVO headvo = aggvo.getParentVO(); | ||||
|                         if (PMOFBillstatusEnum.AUDIT.equalsValue(headvo.getFbillstatus())) { | ||||
|                             Map<String, UFBoolean> trantypeMap = null; | ||||
| 
 | ||||
|                             try { | ||||
|                                 trantypeMap = NCLocator.getInstance().lookup(IPMOTransTypeQueryService.class).getBunplannpickingByTranTypeIDs(new String[]{headvo.getCtrantypeid()}); | ||||
|                             } catch (BusinessException e) { | ||||
|                                 ExceptionUtils.wrappException(e); | ||||
|                             } | ||||
| 
 | ||||
|                             if (trantypeMap == null || UFBoolean.FALSE.equals(trantypeMap.get(headvo.getCtrantypeid()))) { | ||||
|                                 ExceptionUtils.wrappBusinessException(PMOConstLang.getUnPickmDeliverTransTypeInfo()); | ||||
|                             } | ||||
| 
 | ||||
|                             PMOItemVO[] items = aggvo.getChildrenVO(); | ||||
|                             if (!MMArrayUtil.isEmpty(items)) { | ||||
|                                 if (items.length > 1) { | ||||
|                                     ExceptionUtils.wrappBusinessException(PMOConstLang.getSingleRowSelectedInfo()); | ||||
|                                 } | ||||
| 
 | ||||
|                                 for (PMOItemVO item : items) { | ||||
|                                     if (!PMOFItemStatusEnum.PLAN.equalsValue(item.getFitemstatus())) { | ||||
|                                         cmoidList.add(item.getCmoid()); | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                         if (cmoidList.isEmpty()) { | ||||
|                             ExceptionUtils.wrappBusinessException(PMOConstLang.getMSG_RULE_NO_ROWDATA()); | ||||
|                         } | ||||
|                         // ====领料前校验流程生产订单-end==== | ||||
| 
 | ||||
|                         // ====领料前校验流程备料计划-start==== | ||||
|                         // 根据流程生产订单明细id查询备料计划 | ||||
|                         PickmTransParam param = new PickmTransParam(); | ||||
|                         param.setSourceBillRowID(mobid); | ||||
|                         IPickmQueryServiceForMO pickmQueryServiceForMO = NCLocator.getInstance().lookup(IPickmQueryServiceForMO.class); | ||||
|                         AggPickmVO[] vos = pickmQueryServiceForMO.queryPickmByMO(new PickmTransParam[]{param}); | ||||
|                         if (MMValueCheck.isEmpty(vos)) { | ||||
|                             ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("5008100_0", "05008100-0014")); | ||||
|                         } | ||||
|                         if (vos.length > 1) { | ||||
|                             ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("5008100_0", "05008100-0015")); | ||||
|                         } | ||||
|                         if (FbillstatusEnum.PLAN_STATE.equalsValue(vos[0].getParentVO().getFbillstatus())) { | ||||
|                             // 只有审核态或完成态的备料计划才能进行无备料领料! | ||||
|                             ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("5008100_0", "05008100-0016")); | ||||
|                         } | ||||
|                         // ====领料前校验流程备料计划-end==== | ||||
|                         AggPickmVO pickmVO = vos[0]; | ||||
|                         PickmHeadVO pickmHeadVO = pickmVO.getParentVO(); | ||||
|                         String cpickmid = pickmHeadVO.getCpickmid(); | ||||
|                         List<PickmItemVO> itemVOS = new ArrayList<>(); | ||||
|                         String warehouseId = getWarehouseInfo(pkOrg, configParams); | ||||
|                         if (MMValueCheck.isEmpty(warehouseId) || "~".equals(warehouseId)) { | ||||
|                             ExceptionUtils.wrappBusinessException("请检查仓库编码是否配置正确"); | ||||
|                         } | ||||
|                         Map<String, Object> materialMap = getMaterialInfo(cmaterialvid); | ||||
|                         String pkMeasdoc = ""; | ||||
|                         if (materialMap != null) { | ||||
|                             pkMeasdoc = materialMap.get("pk_measdoc") + ""; | ||||
|                         } | ||||
|                         PickmItemVO itemVO = new PickmItemVO(); | ||||
|                         itemVO.setCpickmid(cpickmid); | ||||
|                         itemVO.setPk_group("00"); | ||||
|                         itemVO.setPk_org(pkOrg); | ||||
|                         itemVO.setPk_org_v(pkOrg); | ||||
|                         itemVO.setCdeliverorgvid(pkOrg);// 发料组织 | ||||
|                         itemVO.setCdeliverorgid(pkOrg);// 发料组织 | ||||
|                         itemVO.setVrowno("10");// 行号 | ||||
|                         itemVO.setCbmaterialid(cmaterialvid); | ||||
|                         itemVO.setCbmaterialvid(cmaterialvid); | ||||
|                         itemVO.setCbastunitid(pkMeasdoc); | ||||
|                         itemVO.setCbunitid(pkMeasdoc); | ||||
|                         itemVO.setVbchangerate("1/1"); | ||||
|                         itemVO.setCoutstockid(warehouseId);// 发料仓库 | ||||
|                         // 需用日期 | ||||
|                         itemVO.setDrequiredate(new UFDate()); | ||||
|                         // 获取采购入库表体的应收主数量 nshouldnum | ||||
|                         UFDouble nshouldnum = body.getNshouldnum(); | ||||
|                         itemVO.setNplanoutastnum(nshouldnum);// 计划出库数量 | ||||
|                         itemVO.setNplanoutnum(nshouldnum);// 计划出库主数量 | ||||
|                         itemVO.setNunitastnum(nshouldnum);// 单位定额 | ||||
|                         itemVO.setNunitnum(nshouldnum);// 主单位定额 | ||||
|                         itemVO.setNunituseastnum(nshouldnum);// 单位用量 | ||||
|                         itemVO.setNunitusenum(nshouldnum);// 单位主用量 | ||||
|                         itemVO.setAttributeValue("nquotastnum", nshouldnum);// 定额用量 | ||||
|                         itemVO.setAttributeValue("nquotnum", nshouldnum);// 主定额用量 | ||||
|                         itemVO.setFsupplytype(1);// 供应方式 一般发料=0,定量发料=1 | ||||
|                         itemVO.setStatus(VOStatus.NEW); | ||||
|                         itemVOS.add(itemVO); | ||||
|                         // 调用无备料领料的标准业务方法 | ||||
|                         IPickmBusinessService service = NCLocator.getInstance().lookup(IPickmBusinessService.class); | ||||
|                         service.noItemsDeliverMaterial(itemVOS.toArray(new PickmItemVO[0])); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private String getWarehouseInfo(String pk_org, Map<String, String> configParams) throws DAOException { | ||||
|         String warehouseCode = configParams.get("warehouseCode"); | ||||
|         SqlBuilder sqlBuilder = new SqlBuilder(); | ||||
|         sqlBuilder.append(" select " + StordocVO.PK_STORDOC); | ||||
|         sqlBuilder.append(" from " + StordocVO.getDefaultTableName()); | ||||
|         sqlBuilder.append(" where dr = 0"); | ||||
|         sqlBuilder.append(" and "); | ||||
|         sqlBuilder.append(StordocVO.CODE, warehouseCode); | ||||
|         sqlBuilder.append(" and "); | ||||
|         sqlBuilder.append(StordocVO.PK_ORG, pk_org); | ||||
|         String warehouseId = (String) getDao().executeQuery(sqlBuilder.toString(), new ColumnProcessor()); | ||||
|         return warehouseId; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 获取物料的信息 | ||||
|      * | ||||
|      * @param cbmaterialvid | ||||
|      * @return | ||||
|      * @throws BusinessException | ||||
|      */ | ||||
|     private Map<String, Object> getMaterialInfo(String cbmaterialvid) throws BusinessException { | ||||
|         if (cbmaterialvid == null || cbmaterialvid.isEmpty()) { | ||||
|             return null; | ||||
|         } | ||||
|         IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); | ||||
|         String sql = " select pk_material,pk_measdoc" + | ||||
|                 " from bd_material" + | ||||
|                 " where pk_material = '" + cbmaterialvid + "' "; | ||||
|         return (Map<String, Object>) queryBS.executeQuery(sql, new MapProcessor()); | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue