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.Entity; 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 { /// /// 标准BOM /// 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 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> ?? $"{input["body"]}".ToObject>>(); 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 Save(Dictionary 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 { bSuccess = true, message = "新增成功", result = $"{id}" }; } catch (U8MReferenceBENotExistException ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "新增失败", result = ex.Message }; } catch (TargetInvocationException ex) { if (ex.InnerException is U8MReferenceBENotExistException) { logInfo.Error(ex.InnerException.Message, ex.InnerException); return new BaseResult { bSuccess = false, message = "新增失败", result = ex.InnerException.Message }; } else { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "新增失败", result = ex.Message }; } } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "新增失败", result = ex.Message }; } } } }