This commit is contained in:
PastSaid
2025-01-01 08:21:58 +08:00
parent 9725ab5376
commit 3d15fd4b7e
59 changed files with 3013 additions and 1324 deletions

View File

@@ -19,10 +19,12 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Kingdee.BOS.ServiceHelper;
using Kingdee.K3.BD.BarCode.Core.DataModel.WebApi;
namespace GZ.LJY000.Biori.UHIK_PRD_PACKAGE_INSTOCK
{
[HotUpdate, Description("组装单生成汇报单")]
[HotUpdate, Description("组装单服务插件#")]
public class OperationEventPlugInEx : AbstractOperationServicePlugIn
{
public override void OnPreparePropertys(PreparePropertysEventArgs e)
@@ -30,34 +32,59 @@ namespace GZ.LJY000.Biori.UHIK_PRD_PACKAGE_INSTOCK
base.OnPreparePropertys(e);
e.FieldKeys.Add("FPMoBillTypeId");
e.FieldKeys.Add("FMoillTypeId_Id");
e.FieldKeys.Add("FPSrcBillEntryId");
e.FieldKeys.Add("FMoBillTypeId_Id");
e.FieldKeys.Add("FMoId");
e.FieldKeys.Add("FMoEntryId");
e.FieldKeys.Add("FMoBillTypeId");
e.FieldKeys.Add("FMOBillNo");
e.FieldKeys.Add("FCreateMORpt");
e.FieldKeys.Add("FQty");
e.FieldKeys.Add("FRptQty");
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
// 保存8提交9审核1反审核26
if (this.FormOperation.OperationId == 1)
{
var dataEntityList = new List<DynamicObject>();
var billNos = new List<string>();
//this.Context.UserId
//this.Context.CurrentOrganizationInfo.ID
#region
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);
if (!Convert.ToBoolean(data["FCreateMORpt"]))
continue;
var srcBillEntryId = data["FPSrcBillEntryId"];
if (srcBillEntryId != null && srcBillEntryId.Long2Int() > 0)
{
dataEntityList.Add(data);
}
}
if (dataEntityList.Any())
DoCreateMoRpt(dataEntityList);
#endregion
#region
#endregion
}
}
private void DoCreateMoRpt(List<DynamicObject> dataEntitys)
private void DoCreateMoRpt2(List<DynamicObject> dataEntitys)
{
try
{
@@ -89,10 +116,21 @@ namespace GZ.LJY000.Biori.UHIK_PRD_PACKAGE_INSTOCK
if (policie7009 == null)
throw new Exception("转换单据中单据类型属性类型值7009不存在。");
if (policie7002 == null)
throw new Exception("转换单据中单据类型属性类型值7002不存在。");
var ids = new List<int>();
foreach (var item in dataEntitys)
{
foreach (var entity in item["FEntity"] as DynamicObjectCollection)
{
var rptQty = Convert.ToDecimal(entity["FRptQty"]);
var qty = Convert.ToDecimal(entity["FQty"]);
if (qty <= rptQty)
continue;
var sourceBillTypeId = entity["FMoBillTypeId_Id"].ToString();
var billTypeMap = policie7009.BillTypeMaps.FirstOrDefault(x => x.SourceBillTypeId == sourceBillTypeId);
@@ -131,9 +169,186 @@ namespace GZ.LJY000.Biori.UHIK_PRD_PACKAGE_INSTOCK
throw new KDBusinessException("", "未知原因导致自动保存失败原因:" + JsonUtil.SerializeWithOutNull(saveResult));
}
ids.Add(entity["Id"].Long2Int());
#endregion
}
}
if (ids.Any())
{
var updSql = $@"/*dialect*/
UPDATE t3e SET t3e.FRPTQTY = ISNULL(t1.选单入库合格数量,0)
FROM T_PRD_MO t0
INNER JOIN T_PRD_MOENTRY t0e on t0.FID = t0e.FID
OUTER APPLY (
SELECT t1e.FMOENTRYID,t1e.FMOBILLNO,SUM(t1e.FFINISHQTY) '选单入库合格数量'
FROM T_PRD_MORPT t1
INNER JOIN T_PRD_MORPTENTRY t1e on t1.FID = t1e.FID
INNER JOIN T_PRD_MORPTENTRY_A t1e_a on t1e_a.FENTRYID = t1e.FENTRYID
WHERE t1e.FMOENTRYID = t0e.FENTRYID
AND t1.FDOCUMENTSTATUS = 'C'
GROUP BY t1e.FMOENTRYID,t1e.FMOBILLNO
) t1
INNER JOIN T_PRD_PACKAGEINSTOCKENTRY t3e on t3e.FMOENTRYID = t0e.FENTRYID
WHERE 1 = 1
AND t0.FDOCUMENTSTATUS = 'C'
AND t3e.FEntryID IN ({string.Join(",", ids)})
";
var isOk = DBServiceHelper.Execute(this.Context, updSql);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
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不存在。");
if (policie7002 == null)
throw new Exception("转换单据中单据类型属性类型值7002不存在。");
var ids = new List<int>();
foreach (var item in dataEntitys)
{
var sourceBillDict = new Dictionary<string, List<ListSelectedRow>>();
var sourceBillTypeDict = new Dictionary<string, string>();
var packEntryIds = new Dictionary<string, List<int>>();
foreach (var entity in item["FEntity"] as DynamicObjectCollection)
{
var rptQty = Convert.ToDecimal(entity["FRptQty"]);
var qty = Convert.ToDecimal(entity["FQty"]);
if (qty <= rptQty)
continue;
var sourceBillTypeId = entity["FMoBillTypeId_Id"].ToString();
var billTypeMap = policie7009.BillTypeMaps.FirstOrDefault(x => x.SourceBillTypeId == sourceBillTypeId);
if (billTypeMap == null)
throw new Exception($"转换规则中,{sourceBillTypeId}源单单据类型不存在!");
if (!sourceBillDict.ContainsKey(sourceBillTypeId))
sourceBillDict.Add(sourceBillTypeId, new List<ListSelectedRow>());
sourceBillDict[sourceBillTypeId].Add(new ListSelectedRow("0", entity["FMoEntryId"].ToString(), 0, sourceFormId) { EntryEntityKey = policie7002.SourceEntryKey });
if (!sourceBillTypeDict.ContainsKey(sourceBillTypeId))
sourceBillTypeDict.Add(sourceBillTypeId, billTypeMap.TargetBillTypeId);
if (!packEntryIds.ContainsKey(sourceBillTypeId))
packEntryIds.Add(sourceBillTypeId, new List<int>());
packEntryIds[sourceBillTypeId].Add(entity["Id"].Long2Int());
}
foreach (var dict in sourceBillDict)
{
var selectedRows = dict.Value;
//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;
pushArgs.TargetBillTypeId = sourceBillTypeDict[dict.Key];
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));
}
ids.AddRange(packEntryIds[dict.Key]);
#endregion
}
}
if (ids.Any())
{
var updSql = $@"/*dialect*/
UPDATE t3e SET t3e.FRPTQTY = ISNULL(t1.选单入库合格数量,0)
FROM T_PRD_MO t0
INNER JOIN T_PRD_MOENTRY t0e on t0.FID = t0e.FID
OUTER APPLY (
SELECT t1e.FMOENTRYID,t1e.FMOBILLNO,SUM(t1e.FFINISHQTY) '选单入库合格数量'
FROM T_PRD_MORPT t1
INNER JOIN T_PRD_MORPTENTRY t1e on t1.FID = t1e.FID
INNER JOIN T_PRD_MORPTENTRY_A t1e_a on t1e_a.FENTRYID = t1e.FENTRYID
WHERE t1e.FMOENTRYID = t0e.FENTRYID
AND t1.FDOCUMENTSTATUS = 'C'
GROUP BY t1e.FMOENTRYID,t1e.FMOBILLNO
) t1
INNER JOIN T_PRD_PACKAGEINSTOCKENTRY t3e on t3e.FMOENTRYID = t0e.FENTRYID
WHERE 1 = 1
AND t0.FDOCUMENTSTATUS = 'C'
AND t3e.FEntryID IN ({string.Join(",", ids)})
";
var isOk = DBServiceHelper.Execute(this.Context, updSql);
}
}
}
catch (Exception ex)