提交
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UFIDA.U8.Framework.Api.ControlObject.Common;
|
||||
using UFIDA.U8.Framework.Api.ControlObject.Json;
|
||||
using UFIDA.U8.Framework.Api.ControlObject.Models;
|
||||
using UFSoft.U8.Framework.BizBase;
|
||||
using UFSoft.U8.Framework.ContextSrv;
|
||||
using UFSoft.U8.U8M.BFDispatcher;
|
||||
using UFSoft.U8.U8M.Common;
|
||||
using UFSoft.U8.U8M.DOSchema.BO;
|
||||
using UFSoft.U8.U8M.DOSchema.SF;
|
||||
using UFSoft.U8.U8M.Exceptions;
|
||||
using UFSoft.U8.U8MCommon.GSetup;
|
||||
|
||||
namespace UFIDA.U8.Framework.Api.ControlObject.U8M
|
||||
{
|
||||
/// <summary>
|
||||
/// 标准BOM
|
||||
/// </summary>
|
||||
public class StandardBom
|
||||
{
|
||||
protected readonly ILog logInfo = LogManager.GetLogger("logInfo");
|
||||
|
||||
private IContextContainer callar { get; set; }
|
||||
|
||||
public StandardBom()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private StandardBomDs GetEmptyDs()
|
||||
{
|
||||
var standardBomDs = new StandardBomDs();
|
||||
var standardBomRow = standardBomDs.StandardBom.NewStandardBomRow();
|
||||
standardBomRow.BomType = 1;
|
||||
standardBomRow.VersionEffDate = MParameters.Instance.DefaultVersionDate;
|
||||
standardBomRow.Status = (byte)MParameters.Instance.Options.BomDefaultStatus;
|
||||
standardBomDs.StandardBom.AddStandardBomRow(standardBomRow);
|
||||
var bomParentRow = standardBomDs.BomParent.NewBomParentRow();
|
||||
bomParentRow.BomId = standardBomRow.BomId;
|
||||
bomParentRow.AutoId = $"{Guid.NewGuid()}";
|
||||
standardBomDs.BomParent.AddBomParentRow(bomParentRow);
|
||||
return standardBomDs;
|
||||
}
|
||||
|
||||
private StandardBomDs GetVoucherDs(Dictionary<string, object> input)
|
||||
{
|
||||
var ds = GetEmptyDs();
|
||||
|
||||
var be = new UFSoft.U8.BO.BE.BomEntity(ds);
|
||||
|
||||
be.BomType = EnumBOMCatalogType.StandardBom;
|
||||
|
||||
var beHead = new BEHelper(be.Bom);
|
||||
|
||||
beHead.SetValue(input);
|
||||
|
||||
beHead.SetPartId();
|
||||
|
||||
var bodys = input["body"] as List<Dictionary<string, object>> ?? $"{input["body"]}".ToObject<List<Dictionary<string, object>>>();
|
||||
|
||||
for (var i = 0; i < bodys.Count; i++)
|
||||
{
|
||||
var body = bodys[i];
|
||||
var detail = be.Bom.Components[i];
|
||||
|
||||
var beBody = new BEHelper(detail);
|
||||
|
||||
beBody.SetValue(body);
|
||||
|
||||
beBody.SetPartId();
|
||||
}
|
||||
|
||||
return (StandardBomDs)be.InstanceBom.DataObject;
|
||||
}
|
||||
|
||||
public BaseResult<string> Save(Dictionary<string, object> input)
|
||||
{
|
||||
try
|
||||
{
|
||||
callar = new DefaultContextContainer();
|
||||
|
||||
var ds = GetVoucherDs(input);
|
||||
|
||||
if (ds == null)
|
||||
{
|
||||
throw new Exception("未能构建数据集");
|
||||
}
|
||||
|
||||
//var context = new DefaultContextContainer();
|
||||
//context.context["taskid"] = taskId;
|
||||
|
||||
logInfo.Debug("单据编码:BO11,开始保存");
|
||||
|
||||
var id = BOMExecutor.BFStandardBom_Save(ds, callar);
|
||||
|
||||
|
||||
logInfo.Debug($"单据编码:BO11,保存完成,id:{id}");
|
||||
|
||||
return new BaseResult<string> { bSuccess = true, message = "新增成功", result = $"{id}" };
|
||||
|
||||
}
|
||||
catch (U8MReferenceBENotExistException ex)
|
||||
{
|
||||
logInfo.Error(ex.Message, ex);
|
||||
|
||||
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
{
|
||||
if (ex.InnerException is U8MReferenceBENotExistException)
|
||||
{
|
||||
logInfo.Error(ex.InnerException.Message, ex.InnerException);
|
||||
|
||||
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.InnerException.Message };
|
||||
}
|
||||
else
|
||||
{
|
||||
logInfo.Error(ex.Message, ex);
|
||||
|
||||
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
logInfo.Error(ex.Message, ex);
|
||||
|
||||
return new BaseResult<string> { bSuccess = false, message = "新增失败", result = ex.Message };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user