148 lines
6.2 KiB
C#
148 lines
6.2 KiB
C#
using Kingdee.BOS;
|
||
using Kingdee.BOS.App;
|
||
using Kingdee.BOS.App.Core.Convertible;
|
||
using Kingdee.BOS.Contracts;
|
||
using Kingdee.BOS.Core.Const;
|
||
using Kingdee.BOS.Core.DynamicForm.Operation;
|
||
using Kingdee.BOS.Core.DynamicForm;
|
||
using Kingdee.BOS.Core.DynamicForm.PlugIn;
|
||
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
||
using Kingdee.BOS.Core.List;
|
||
using Kingdee.BOS.Core.Metadata;
|
||
using Kingdee.BOS.Core.Metadata.ConvertElement;
|
||
using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
|
||
using Kingdee.BOS.Orm;
|
||
using Kingdee.BOS.Orm.DataEntity;
|
||
using Kingdee.BOS.Util;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Linq;
|
||
using System.Text;
|
||
|
||
namespace GZ.LJY000.Biori.UHIK_PRD_PACKAGE_INSTOCK
|
||
{
|
||
[HotUpdate, Description("组装单生成汇报单")]
|
||
public class OperationEventPlugInEx : AbstractOperationServicePlugIn
|
||
{
|
||
public override void OnPreparePropertys(PreparePropertysEventArgs e)
|
||
{
|
||
base.OnPreparePropertys(e);
|
||
|
||
e.FieldKeys.Add("FPMoBillTypeId");
|
||
e.FieldKeys.Add("FMoillTypeId_Id");
|
||
e.FieldKeys.Add("FMoId");
|
||
e.FieldKeys.Add("FMoEntryId");
|
||
e.FieldKeys.Add("FMoBillTypeId");
|
||
e.FieldKeys.Add("FMOBillNo");
|
||
}
|
||
|
||
public override void EndOperationTransaction(EndOperationTransactionArgs e)
|
||
{
|
||
base.EndOperationTransaction(e);
|
||
|
||
if (this.FormOperation.OperationId == 1)
|
||
{
|
||
var dataEntityList = new List<DynamicObject>();
|
||
|
||
foreach (var data in e.DataEntitys)
|
||
{
|
||
var srcBillEntryId = data["FPSrcBillEntryId"];
|
||
if (srcBillEntryId != null && srcBillEntryId.Long2Int() > 0)
|
||
dataEntityList.Add(data);
|
||
|
||
if (dataEntityList.Any())
|
||
DoCreateMoRpt(dataEntityList);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void DoCreateMoRpt(List<DynamicObject> dataEntitys)
|
||
{
|
||
try
|
||
{
|
||
IConvertService service = ServiceHelper.GetService<IConvertService>();
|
||
|
||
//获取元数据服务
|
||
IMetaDataService metadataService = ServiceHelper.GetService<IMetaDataService>();
|
||
|
||
//获取ViewService
|
||
IViewService viewService = ServiceHelper.GetService<IViewService>();
|
||
//获取源单元数据
|
||
|
||
//# *源单据标识
|
||
var sourceFormId = "PRD_MO";
|
||
//# *目标单据标识
|
||
var targetFormId = "PRD_MORPT";
|
||
|
||
var convertRuleId = "PRD_MO2MORPT";
|
||
|
||
var ruleMeta = service.GetConvertRule(this.Context, convertRuleId);
|
||
|
||
if (ruleMeta != null)
|
||
{
|
||
FormMetadata sourceMetada = metadataService.Load(this.Context, sourceFormId) as FormMetadata;
|
||
|
||
var policies = ruleMeta.Rule.Policies;
|
||
var policie7002 = policies.FirstOrDefault(x => x.ElementType == 7002) as DefaultConvertPolicyElement;
|
||
var policie7009 = policies.FirstOrDefault(x => x.ElementType == 7009) as BillTypeMapPolicyElement;
|
||
if (policie7009 == null)
|
||
throw new Exception("转换单据中,单据类型属性类型值:7009不存在。");
|
||
|
||
foreach (var item in dataEntitys)
|
||
{
|
||
foreach (var entity in item["FEntity"] as DynamicObjectCollection)
|
||
{
|
||
var sourceBillTypeId = entity["FMoBillTypeId_Id"].ToString();
|
||
var billTypeMap = policie7009.BillTypeMaps.FirstOrDefault(x => x.SourceBillTypeId == sourceBillTypeId);
|
||
|
||
if (billTypeMap == null)
|
||
throw new Exception($"转换规则中,{sourceBillTypeId}源单单据类型不存在!");
|
||
|
||
var selectedRows = new List<ListSelectedRow>();
|
||
selectedRows.Add(new ListSelectedRow("0", entity["FMoEntryId"].ToString(), 0, sourceFormId) { EntryEntityKey = policie7002.SourceEntryKey });
|
||
var pushArgs = new PushArgs(ruleMeta.Rule, selectedRows.ToArray());
|
||
pushArgs.TargetBillTypeId = billTypeMap.TargetBillTypeId;
|
||
|
||
OperateOption option = OperateOption.Create();//选项参数
|
||
//不按照整单下推
|
||
option.SetVariableValue(ConvertConst.SelectByBillId, false);
|
||
|
||
//源单数据转换目标数据
|
||
ConvertOperationResult convertResult = service.Push(this.Context, pushArgs, option);
|
||
|
||
DynamicObject[] destObjs = convertResult.TargetDataEntities.Select(r => r.DataEntity).ToArray();
|
||
|
||
FormMetadata destFormMetadata = metadataService.Load(this.Context, targetFormId) as FormMetadata;
|
||
|
||
string msg = string.Empty;
|
||
|
||
#region 自动保存
|
||
IOperationResult saveResult = ServiceHelper.GetService<ISaveService>().SaveAndAudit(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create());
|
||
|
||
if (!saveResult.IsSuccess)
|
||
{
|
||
if (saveResult.ValidationErrors != null && saveResult.ValidationErrors.Count > 0)
|
||
{
|
||
var errorInfo = string.Join(";", saveResult.ValidationErrors.Select(x => x.Message));
|
||
|
||
throw new KDBusinessException("", "未知原因导致自动保存失败原因:" + errorInfo);
|
||
}
|
||
|
||
throw new KDBusinessException("", "未知原因导致自动保存失败原因:" + JsonUtil.SerializeWithOutNull(saveResult));
|
||
}
|
||
#endregion
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
}
|