售票登记-收款处理单据转换
This commit is contained in:
		
							parent
							
								
									fefd6e772e
								
							
						
					
					
						commit
						37788ee807
					
				|  | @ -0,0 +1,174 @@ | ||||||
|  | package shjh.jhzj7.fi.fi.plugin.convert; | ||||||
|  | 
 | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||||
|  | import kd.bos.dataentity.metadata.dynamicobject.DynamicProperty; | ||||||
|  | import kd.bos.entity.ExtendedDataEntity; | ||||||
|  | import kd.bos.entity.botp.plugin.AbstractConvertPlugIn; | ||||||
|  | import kd.bos.entity.botp.plugin.args.AfterBuildQueryParemeterEventArgs; | ||||||
|  | import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs; | ||||||
|  | import kd.bos.entity.botp.runtime.ConvertConst; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import kd.bos.orm.query.QCP; | ||||||
|  | import kd.bos.orm.query.QFilter; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.sdk.plugin.Plugin; | ||||||
|  | 
 | ||||||
|  | import java.util.*; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 单据转换插件 | ||||||
|  |  * 收票登记-收款处理,付款人携带 | ||||||
|  |  */ | ||||||
|  | public class RecPayerConvertPlugin extends AbstractConvertPlugIn implements Plugin { | ||||||
|  | 
 | ||||||
|  |     private final static Log logger = LogFactory.getLog(RecPayerConvertPlugin.class); | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void afterBuildQueryParemeter(AfterBuildQueryParemeterEventArgs e) { | ||||||
|  |         //对方户名 | ||||||
|  |         e.addSrcField("delivername"); | ||||||
|  |         //资金组织 | ||||||
|  |         e.addSrcField("company"); | ||||||
|  |         //交票人类型 | ||||||
|  |         e.addSrcField("payeetype"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void afterConvert(AfterConvertEventArgs e) { | ||||||
|  |         logger.info("进入 afterConvert 方法,开始处理售票登记-收款处理单据转换逻辑..."); | ||||||
|  | 
 | ||||||
|  |         try { | ||||||
|  |             // 获取源单字段 | ||||||
|  |             Map<String, DynamicProperty> fldProperties = e.getFldProperties(); | ||||||
|  | 
 | ||||||
|  |             ExtendedDataEntity[] extendedDataEntities = e.getTargetExtDataEntitySet().FindByEntityKey("cas_recbill"); | ||||||
|  |             for (ExtendedDataEntity billEntity : extendedDataEntities) { | ||||||
|  |                 // 获取单据数据包 | ||||||
|  |                 DynamicObject bill = billEntity.getDataEntity(); | ||||||
|  |                 String payeetype = (String) this.getSourceData(billEntity, fldProperties, "payeetype"); | ||||||
|  |                 if ("cdm_receivablebill".equals(bill.getString("sourcebilltype"))&&"bd_customer".equals(payeetype)){ | ||||||
|  |                     this.carryCustomerRule(bill,billEntity,fldProperties); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |             } | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             logger.error("售票登记-收款处理单据转换出错"+ex.getMessage()); | ||||||
|  |         } | ||||||
|  |         logger.info("afterConvert 方法执行完毕。"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     private void carryCustomerRule(DynamicObject bill, ExtendedDataEntity billEntity, Map<String, DynamicProperty> fldProperties) { | ||||||
|  |         //对方户名 | ||||||
|  |         String accountName = (String) this.getSourceData(billEntity, fldProperties, "delivername"); | ||||||
|  |         if (accountName==null){ | ||||||
|  |             logger.error("未获取源单户名,转换终止!"); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         //资金组织 | ||||||
|  |         Long companyId = (Long) this.getSourceData(billEntity, fldProperties, "company"); | ||||||
|  |         if (companyId==null){ | ||||||
|  |             logger.error("未获取源单资金组织,转换终止!"); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         DynamicObject company = BusinessDataServiceHelper.loadSingle(companyId, "bos_org"); | ||||||
|  |         QFilter qFilter = new QFilter("shjh_dfhm", QCP.equals, accountName); | ||||||
|  |         //新增收款入账中心-资金组织&&映射表组织过滤 | ||||||
|  |         qFilter.and(new QFilter("shjh_org.id", QCP.equals, companyId)); | ||||||
|  |         qFilter.and(new QFilter("enable", QCP.equals, "1")); | ||||||
|  |         //1.对方户名与客户名称映射表 shjh_dfhmcust | ||||||
|  |         DynamicObject shjhDfhmcust = BusinessDataServiceHelper.loadSingle("shjh_dfhmcust", qFilter.toArray()); | ||||||
|  |         if (null != shjhDfhmcust) { | ||||||
|  |             DynamicObject shjhCustomer = shjhDfhmcust.getDynamicObject("shjh_customer"); | ||||||
|  |             if (null != shjhCustomer) { | ||||||
|  |                 bill.set("payer", shjhCustomer.getPkValue()); //付款人id | ||||||
|  |                 bill.set("payernumber", shjhCustomer.getString("number")); //付款人编码 | ||||||
|  |                 bill.set("payername", shjhCustomer.getString("name")); //付款人名称 | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             //2.规则生单未配置客户——>取收款入账中心客户 | ||||||
|  |             QFilter customerFilter = new QFilter("name", QCP.equals, accountName); | ||||||
|  |             customerFilter.and(new QFilter("group.name", QCP.not_equals, "员工")); | ||||||
|  |             //可用状态 | ||||||
|  |             customerFilter.and(new QFilter("enable", QCP.equals, "1")); | ||||||
|  |             DynamicObject[] bd_customer = BusinessDataServiceHelper.load("bd_customer", "id,name", customerFilter.toArray()); | ||||||
|  |             boolean exitCustomerArray = false; | ||||||
|  |             if (null != bd_customer && bd_customer.length != 0) { | ||||||
|  |                 if (bd_customer.length == 1) { | ||||||
|  |                     bill.set("payer", bd_customer[0].getPkValue()); //付款人id | ||||||
|  |                     bill.set("payernumber", bd_customer[0].getString("number")); //付款人编码 | ||||||
|  |                     bill.set("payername", bd_customer[0].getString("name")); //付款人名称 | ||||||
|  |                     exitCustomerArray = true; | ||||||
|  |                 } else { | ||||||
|  |                     //存在多个客户,判断组织编码companyNumber是否在客户基础资料客户组5分录中的销售公司编码中配置 | ||||||
|  |                     List<DynamicObject> matchingCustomers = new ArrayList<>(); | ||||||
|  | 
 | ||||||
|  |                     for (int i = 0; i < bd_customer.length; i++) { | ||||||
|  |                         Set<String> numberSet = new HashSet<>(); | ||||||
|  |                         DynamicObject customer = BusinessDataServiceHelper.loadSingle(bd_customer[i].getPkValue(), "bd_customer"); | ||||||
|  |                         if (customer != null) { | ||||||
|  |                             DynamicObjectCollection dynamicObjectCollection = customer.getDynamicObjectCollection("shjh_entry_five"); | ||||||
|  |                             if (dynamicObjectCollection != null && dynamicObjectCollection.size() != 0) { | ||||||
|  |                                 for (DynamicObject item : dynamicObjectCollection) { | ||||||
|  |                                     String saleCompanyNum = item.getString("shjh_salecompanynum"); | ||||||
|  |                                     if (saleCompanyNum != null && !"".equals(saleCompanyNum)) { | ||||||
|  |                                         numberSet.add(saleCompanyNum); | ||||||
|  |                                     } | ||||||
|  |                                 } | ||||||
|  |                                 if (numberSet.contains(company.getString("number"))) { | ||||||
|  |                                     matchingCustomers.add(bd_customer[i]); | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     // 处理匹配结果 | ||||||
|  |                     if (matchingCustomers.size() == 1) { | ||||||
|  |                         // 只有一个客户匹配,使用该客户 | ||||||
|  |                         bill.set("payer", matchingCustomers.get(0).getPkValue()); | ||||||
|  |                         bill.set("payernumber", matchingCustomers.get(0).getString("number")); | ||||||
|  |                         bill.set("payername", matchingCustomers.get(0).getString("name")); | ||||||
|  |                         exitCustomerArray = true; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             if (!exitCustomerArray) { | ||||||
|  |                 //4.规则生单未配置客户——>默认不确定客户 | ||||||
|  |                 QFilter qFilter1 = new QFilter("number", QCP.equals, "1042086"); //4000042 | ||||||
|  |                 DynamicObject bdCustomer = BusinessDataServiceHelper.loadSingle("bd_customer", qFilter1.toArray()); | ||||||
|  |                 if (null != bdCustomer) { | ||||||
|  |                     bill.set("payer", bdCustomer.getPkValue()); //付款人id | ||||||
|  |                     bill.set("payernumber", bdCustomer.getString("number")); //付款人编码 | ||||||
|  |                     bill.set("payername", bdCustomer.getString("name")); //付款人名称 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |         } | ||||||
|  |         bill.set("shjh_xdgzkh", true);//设置收款单标记位 从规则携带客户等信息 为true | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 获取源单字段数据 | ||||||
|  |      * | ||||||
|  |      * @param billEntity    源单数据包 | ||||||
|  |      * @param fldProperties 源单字段 | ||||||
|  |      * @param name          字段标识 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     private Object getSourceData(ExtendedDataEntity billEntity, Map<String, DynamicProperty> fldProperties, String name) { | ||||||
|  |         List<DynamicObject> sourceRows = (List<DynamicObject>) billEntity.getValue(ConvertConst.ConvExtDataKey_SourceRows); | ||||||
|  |         if (sourceRows == null || sourceRows.isEmpty()) { | ||||||
|  |             logger.warn("未获取到源单行数据,跳过处理。"); | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |         DynamicObject srcRow = sourceRows.get(0); | ||||||
|  |         // 获取源单 ID | ||||||
|  |         DynamicProperty idProperty = fldProperties.get(name); | ||||||
|  |         if (idProperty == null) { | ||||||
|  |             logger.warn("未获取到源单 ID 属性,跳过处理。"); | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |         return idProperty.getValue(srcRow); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue