需求背景:在批号主档上加了一些二开字段,当入库类单据保存时,需要从单据上读取对应的字段值写入批号主档
问题描述:二开插件的思路是先load出每行分录上的批号主档的数据包,然后将单据分录上对应的字段值写入到批号主档数据包中,最后调用save。大部分字段都能正确更新到批号中。但是F_DM_REAL_Width这个字段,偶发性的会更新失败(单据保存成功,但F_DM_REAL_Width的值没带入到批号中),但往往再次保存又成功了。概率比较低,开发环境一直未能重现。怀疑是不是因为这个字段上有两个下划线所以有问题?实在想不到别的原因了。
(这个插件是很多单据共用的,这些单据上的字段会有所差异,所以都加了是否存在属性的判断。)
namespace Kingdee.K3.DM.SCM.Bussiness.PlugIn.app
{
[Description("入库类单据批号保存时带入二开字段值")]
public class BatchMainFileFlotSplitPlugin : AbstractOperationServicePlugIn
{
//‘备注’字段的属性名
private static string[] remarkFieldKey = new string[] { "Note", "EntryNote", "Description", "Memo", "NoteEntry", "ENote", "EntryNote" };
public override void EndOperationTransaction(BOS.Core.DynamicForm.PlugIn.Args.EndOperationTransactionArgs e)
{
foreach (var item in e.DataEntitys)
{
string formId = "";
if (item.DynamicObjectType.Name.Equals("InvInit"))
{
formId = "STK_InvInit";
}
else if (item.DynamicObjectType.Name.Equals("StockConvert"))
{
formId = "STK_StockConvert";
}
else
{
formId = item["FFormId"].ToString();
}
DynamicObjectCollection details = null;
switch (formId)
{
case "STK_MISCELLANEOUS"://其它入库
details = item["STK_MISCELLANEOUSENTRY"] as DynamicObjectCollection;
break;
case "STK_InStock"://采购入库
details = item["InStockEntry"] as DynamicObjectCollection;
break;
case "SP_InStock"://简单生产入库
details = item["Entity"] as DynamicObjectCollection;
break;
case "STK_TRANSFERIN"://分布式调入
details = item["STK_STKTRANSFERINENTRY"] as DynamicObjectCollection;
break;
case "STK_OEMInStock"://受托入库
details = item["OEMInStockEntry"] as DynamicObjectCollection;
break;
case "PUR_ReceiveBill"://采购收料
details = item["PUR_ReceiveEntry"] as DynamicObjectCollection;
break;
case "STK_InvInit"://初始库存
details = item["InvInitDetail"] as DynamicObjectCollection;
break;
case "PRD_INSTOCK"://生产入库
details = item["Entity"] as DynamicObjectCollection;
break;
case "STK_AssembledApp"://组装拆卸
details = item["ProductEntity"] as DynamicObjectCollection;
break;
case "STK_LOTADJUST"://批号调整
details = item["STK_LOTADJUSTENTRY"] as DynamicObjectCollection;
break;
case "STK_TransferDirect"://直接调拨
details = item["TransferDirectEntry"] as DynamicObjectCollection;
break;
case "SAL_RETURNSTOCK"://销售退货
details = item["SAL_RETURNSTOCKENTRY"] as DynamicObjectCollection;
break;
case "STK_StockConvert"://形态转换
details = item["StockConvertEntry"] as DynamicObjectCollection;
break;
case "STK_StatusConvert"://库存状态转换
details = item["StatusConvertEntry"] as DynamicObjectCollection;
break;
default: break;
}
if (details == null)
{
return;
}
Dictionary
if (dict.Count() > 0)
{
//加载批号主档数据包
string filter = string.Format("FLOTID IN ({0})", string.Join(",", dict.Values.Distinct()));
OQLFilter of = OQLFilter.CreateHeadEntityFilter(filter);
DynamicObject[] lotMasters = BusinessDataServiceHelper.Load(this.Context, "BD_BatchMainFile", null, of);
foreach (var entryItem in details)
{
long lotId = 0;
if (dict.TryGetValue(Convert.ToInt64(entryItem["Id"]), out lotId))
{
DynamicObject lotObj = lotMasters.Where(s => Convert.ToInt64(s["Id"]) == lotId).FirstOrDefault();
if (entryItem.DynamicObjectType.Properties.ContainsKey("ConvertType") && Convert.ToString(entryItem["ConvertType"]) == "A")
{
continue;
}
if (null != lotObj && Convert.ToInt16((lotObj as DynamicObject)["BizType"]) == 1)
{
//更改批号的属性值
this.getSqlParams(formId, entryItem, item, lotObj);
}
}
}
ISaveService service = Kingdee.BOS.App.ServiceHelper.GetService
service.Save(this.Context, lotMasters);
}
}
}
private void getSqlParams(string formId, DynamicObject entryItem, DynamicObject item, DynamicObject lotObj)
{
string billTypeId = null;
if (item.DynamicObjectType.Properties.Contains("BillTypeId_Id"))
{
billTypeId = Convert.ToString(item["BillTypeId_Id"]);
}
else if (item.DynamicObjectType.Properties.Contains("FBillTypeId_Id"))
{
billTypeId = Convert.ToString(item["FBillTypeId_Id"]);
}
if (this.FormOperation.Operation.EqualsIgnoreCase("Save"))
{
// 销售订单号
string saleOrderNo = null;
if ("STK_MISCELLANEOUS".Equals(formId) || "PRD_INSTOCK".Equals(formId) || "STK_TransferDirect".Equals(formId)
|| "STK_AssembledApp".Equals(formId))
{
saleOrderNo = Convert.ToString(entryItem["F_DM_SaleOrderNo"]);
}
else if ("STK_InStock".Equals(formId) || "STK_InvInit".Equals(formId))
{
saleOrderNo = Convert.ToString(entryItem["F_DM_SaleBillNo"]);
}
if (!string.IsNullOrWhiteSpace(saleOrderNo))
{
lotObj["F_DM_SaleOrderNo"] = saleOrderNo;
}
//长度
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_Long"))
{
lotObj["F_DM_Length"] = entryItem["F_DM_Long"];
}
//宽度
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_Width"))
{
lotObj["F_DM_Width"] = entryItem["F_DM_Width"];
}
//实测厚度
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_MeasureThickness"))
{
lotObj["F_DM_MeasureThickness"] = entryItem["F_DM_MeasureThickness"];
}
//钢厂参考厚度
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_SteelThickness"))
{
lotObj["F_DM_SteelThickness"] = entryItem["F_DM_SteelThickness"];
}
//实际宽度
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_REAL_Width"))
{
lotObj["F_DM_REAL_Width"] = entryItem["F_DM_REAL_Width"];
}
//卷号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_VolumeNo"))
{
string volumeNo = Convert.ToString(entryItem["F_DM_VolumeNo"]);
lotObj["F_DM_VolumeNo"] = volumeNo;
}
//质保书
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_CertificateNo"))
{
string certificateNo = Convert.ToString(entryItem["F_DM_CertificateNo"]);
lotObj["F_DM_CertificateNo"] = certificateNo;
}
//炉号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_FurnaceNo"))
{
string furnaceNo = Convert.ToString(entryItem["F_DM_FurnaceNo"]);
lotObj["F_DM_FurnaceNo"] = furnaceNo;
}
//钢厂批次号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_SteelLotNo"))
{
string SteelLotNo = Convert.ToString(entryItem["F_DM_SteelLotNo"]);
lotObj["F_DM_SteelLotNo"] = SteelLotNo;
}
//程序号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_ProgramNo"))
{
string F_DM_ProgramNo = Convert.ToString(entryItem["F_DM_ProgramNo"]);
lotObj["F_DM_ProgramNo"] = F_DM_ProgramNo;
}
//规格
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_Specifications"))
{
string Spec = Convert.ToString(entryItem["F_DM_Specifications"]);
lotObj["F_DM_Specifications"] = Spec;
}
//计重方式
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_WeightStyle"))
{
string weightStyle = Convert.ToString(entryItem["F_DM_WeightStyle"]);
lotObj["F_DM_WeightStyle"] = weightStyle;
}
else if (entryItem.DynamicObjectType.Properties.Contains("F_DM_WeightStyleIn"))
{
string weightStyle = Convert.ToString(entryItem["F_DM_WeightStyleIn"]);
lotObj["F_DM_WeightStyle"] = weightStyle;
}
//生产性质
if (item.DynamicObjectType.Properties.Contains("F_DM_ProductionPropertyId"))
{
string prdProp = Convert.ToString(item["F_DM_ProductionPropertyId"]);
lotObj["F_DM_ProductionPropertyId"] = prdProp;
}
//公差类型
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_DeviationType_Id"))
{
lotObj["F_DM_DeviationType"] = entryItem["F_DM_DeviationType"];
lotObj["F_DM_DeviationType_Id"] = entryItem["F_DM_DeviationType_Id"];
}
//质量等级
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_QTYGradId_Id"))
{
lotObj["F_DM_QTYGradId"] = entryItem["F_DM_QTYGradId"];
lotObj["F_DM_QTYGradId_Id"] = entryItem["F_DM_QTYGradId_Id"];
}
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_QTYGradeId_Id"))
{
lotObj["F_DM_QTYGradId"] = entryItem["F_DM_QTYGradeId"];
lotObj["F_DM_QTYGradId_Id"] = entryItem["F_DM_QTYGradeId_Id"];
}
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_ExecuteStandId_Id"))
{
lotObj["F_DM_ExecuteStandId"] = entryItem["F_DM_ExecuteStandId"];
lotObj["F_DM_ExecuteStandId_Id"] = entryItem["F_DM_ExecuteStandId_Id"];
}
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_CusId_Id") && formId != "SAL_RETURNSTOCK")
{
lotObj["CustId"] = entryItem["F_DM_CusId"];
lotObj["CustId_Id"] = entryItem["F_DM_CusId_Id"];
}
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_CustId_Id") && formId != "SAL_RETURNSTOCK")
{
lotObj["CustId"] = entryItem["F_DM_CustId"];
lotObj["CustId_Id"] = entryItem["F_DM_CustId_Id"];
}
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_Customer_Id") && formId != "SAL_RETURNSTOCK")
{
lotObj["CustId"] = entryItem["F_DM_Customer"];
lotObj["CustId_Id"] = entryItem["F_DM_Customer_Id"];
}
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_CustomerId_Id") && formId != "SAL_RETURNSTOCK")
{
lotObj["CustId"] = entryItem["F_DM_CustomerId"];
lotObj["CustId_Id"] = entryItem["F_DM_CustomerId_Id"];
}
if (formId.Equals("STK_OEMInStock"))
{
if (item.DynamicObjectType.Properties.Contains("CustId_Id"))
{
lotObj["CustId"] = item["CustId"];
lotObj["CustId_Id"] = item["CustId_Id"];
}
}
//定价宽度
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_SaleWidthId_Id"))
{
lotObj["F_DM_SaleWidthId"] = entryItem["F_DM_SaleWidthId"];
lotObj["F_DM_SaleWidthId_Id"] = entryItem["F_DM_SaleWidthId_Id"];
}
//包装方式
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_PackingId_Id"))
{
lotObj["F_DM_PackingId"] = entryItem["F_DM_PackingId"];
lotObj["F_DM_PackingId_Id"] = entryItem["F_DM_PackingId_Id"];
}
//表面
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_SurfaceId_Id"))
{
lotObj["F_DM_SurfaceId"] = entryItem["F_DM_SurfaceId"];
lotObj["F_DM_SurfaceId_Id"] = entryItem["F_DM_SurfaceId_Id"];
}
//边部
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_EdgeId_Id"))
{
lotObj["F_DM_EdgeId"] = entryItem["F_DM_EdgeId"];
lotObj["F_DM_EdgeId_Id"] = entryItem["F_DM_EdgeId_Id"];
}
//标准厚度
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_SaleThickness"))
{
lotObj["F_DM_StardardThickness"] = entryItem["F_DM_SaleThickness"];
}
else if (entryItem.DynamicObjectType.Properties.Contains("F_DM_StardardThicknesstext"))
{
lotObj["F_DM_StardardThickness"] = entryItem["F_DM_StardardThicknesstext"];
}
else if (entryItem.DynamicObjectType.Properties.Contains("F_DM_StardardThickness"))
{
lotObj["F_DM_StardardThickness"] = entryItem["F_DM_StardardThickness"];
}
//产品类别
if ("STK_MISCELLANEOUS".Equals(formId) && "55fbd760569659".Equals(billTypeId))
{
lotObj["F_DM_PrdType"] = "2";
}
else if ("STK_TransferDirect".Equals(formId))
{
if ("565c650671905c".Equals(billTypeId))
{
lotObj["F_DM_PrdType"] = "4";
}
}
else if ("PRD_INSTOCK".Equals(formId) && "2".Equals(entryItem["F_DM_NewType"]))
{
lotObj["F_DM_PrdType"] = "3";
}
else if (null == lotObj["F_DM_PrdType"] || Convert.ToString(lotObj["F_DM_PrdType"]).Equals("0"))
{
lotObj["F_DM_PrdType"] = "1";
}
//归档厚度
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_FilingthickId_Id"))
{
lotObj["F_DM_FilingthickId"] = entryItem["F_DM_FilingthickId"];
lotObj["F_DM_FilingthickId_Id"] = entryItem["F_DM_FilingthickId_Id"];
}
//净重
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_NetWeight"))
{
lotObj["F_DM_NetWeight"] = entryItem["F_DM_NetWeight"];
}
//理重
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_PhysicalWeight"))
{
lotObj["F_DM_PhysicalWeight"] = entryItem["F_DM_PhysicalWeight"];
}
//生产入库单/标准生产其他入库单 并包号 更新到批号主档
if ((formId.Equals("STK_MISCELLANEOUS") || formId.Equals("PRD_INSTOCK") || formId.Equals("STK_InvInit"))
&& entryItem.DynamicObjectType.Properties.Contains("F_DM_PackageNo"))
{
lotObj["F_DM_PackingNo"] = entryItem["F_DM_PackageNo"];
}
//初始入库
else if (entryItem.DynamicObjectType.Properties.Contains("F_DM_PackingNo"))
{
lotObj["F_DM_PackingNo"] = entryItem["F_DM_PackingNo"];
}
//备注
foreach (string fieldKey in remarkFieldKey)
{
if (entryItem.DynamicObjectType.Properties.Contains(fieldKey))
{
string remark = Convert.ToString(entryItem[fieldKey]);
lotObj["F_DM_Remark"] = remark;
break;
}
}
//大明图纸号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_DrawingNo"))
{
string drawNo = Convert.ToString(entryItem["F_DM_DrawingNo"]);
lotObj["F_DM_DrawingNo"] = drawNo;
}
//客户图纸号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_CustDrawingNo"))
{
string custDrawingNo = Convert.ToString(entryItem["F_DM_CustDrawingNo"]);
lotObj["F_DM_CustDrawingNo"] = custDrawingNo;
}
//质量信息
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_Quality"))
{
string quality = Convert.ToString(entryItem["F_DM_Quality"]);
lotObj["F_DM_ZLXX"] = quality;
}
//客户零件号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_PartNo"))
{
string partNo = Convert.ToString(entryItem["F_DM_PartNo"]);
lotObj["F_DM_PartNo"] = partNo;
}
//生产入库日期
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_PrdInDate"))
{
lotObj["F_DM_PrdInDate"] = entryItem["F_DM_PrdInDate"];
}
//最初入库日期
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_OrginDate"))
{
lotObj["F_DM_OrginDate"] = entryItem["F_DM_OrginDate"];
}
//源批号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_MaterialLotId_Id") && null != entryItem["F_DM_MaterialLotId"])
{
lotObj["F_DM_MaterialLotId"] = entryItem["F_DM_MaterialLotId"];
lotObj["F_DM_MaterialLotId_Id"] = entryItem["F_DM_MaterialLotId_Id"];
}
//原始入库批号
if (entryItem.DynamicObjectType.Properties.Contains("F_DM_OriginId_Id") && null != entryItem["F_DM_OriginId"])
{
lotObj["F_DM_OriginId"] = entryItem["F_DM_OriginId"];
lotObj["F_DM_OriginId_Id"] = entryItem["F_DM_OriginId_Id"];
}
}
if (this.FormOperation.Operation.EqualsIgnoreCase("Audit"))
{
if (item.DynamicObjectType.Properties.Contains("ApproveDate") && (formId.Equals("PRD_INSTOCK") || ("STK_MISCELLANEOUS".Equals(formId) && "55fbd760569659".Equals(billTypeId))))
{
lotObj["F_DM_PrdInDate"] = item["ApproveDate"];
}
else if (item.DynamicObjectType.Properties.Contains("ApproveDate") && new string[] { "STK_InStock", "STK_InvInit", "STK_OEMInStock", "SAL_RETURNSTOCK", "STK_MISCELLANEOUS" }.Contains(formId)
&& !"55fbd760569659".Equals(billTypeId))
{
lotObj["F_DM_OrginDate"] = item["ApproveDate"];
}
}
}
}
}
推荐阅读