using System; using System.Collections.Generic; using System.Linq; using System.Text; using Dapper; namespace NX.ERP.U8.Mom { /// /// BOM /// public class BomDAL { /// /// 获取BOM清单 /// /// /// /// public IEnumerable GetList(string strWhere="", object Params = null) { var strSQL = @"select ISNULL(a.ModifyDate,CreateDate) ModifyDate,CONVERT(BIGINT,a.Ufts) AS pubufts,a.BomId,a.Version,a.Status, a.VersionDesc,a.BomType,c.InvCode as ParentCode ,x.cInvName as ParentName ,x.cInvStd as ParentSpecsModel,' ' as id ,d.BomId, d.SortSeq, e.InvCode as ComponentCode ,y.cInvName as ComponentName,y.cInvStd as ComponentSpecsModel ,d.BaseQtyN, d.BaseQtyD ,f.WIPType,d.EffBegDate,d.EffEndDate from bom_bom as a left join bom_parent as b on a.BomId=b.BomId left join bas_part as c on b.ParentId=c.PartId left join Inventory as x on c.InvCode=x.cInvCode left join bom_opcomponent as d on a.BomId=d.BomId left join bom_opcomponentopt as f on d.OpComponentId=f.OptionsId left join bas_part as e on d.ComponentId=e.PartId left join Inventory as y on e.InvCode=y.cInvCode"; if (!string.IsNullOrEmpty(strWhere)) { strSQL += $" where {strWhere} "; } using (var conn = U8LoginContext.Instance.Connection) { var lookup = new Dictionary(); conn.Query(strSQL, (bom, comp) => { if (!lookup.TryGetValue(bom.BomId, out var _bom)) { lookup.Add(bom.BomId, bom); } else { bom = _bom; } bom.OptionComponents.Add(comp); return bom; }, Params, null, true, "id", 10, System.Data.CommandType.Text); ; return lookup.Values; } } public IEnumerable GetList(long Pubufts) { return this.GetList("CONVERT(BIGINT,a.Ufts) >@Pubufts", new { Pubufts }); } public IEnumerable GetList(NX.ERP.Model.Request.Bom bom) { List where = new List(); if (!string.IsNullOrEmpty(bom.ParentCode)) { where.Add(" c.InvCode = @ParentCode "); } if (!string.IsNullOrEmpty(bom.VersionDesc)) { where.Add(" a.VersionDesc like @VersionDesc "); } if (bom.BomType.HasValue) { where.Add(" a.BomType = @BomType "); } if (bom.Version.HasValue) { where.Add(" a.Version = @Version "); } if (bom.ModifyDate!=null) { where.Add(" ISNULL(a.ModifyDate,CreateDate) >=@ModifyDate or a.RelsTime>=@ModifyDate "); } if (bom.Pubufts != null) { where.Add("CONVERT(BIGINT,a.Ufts) >@Pubufts "); } return this.GetList(string.Join(" and ", where.ToArray()), new { ParentCode = bom.ParentCode, VersionDesc =$"%{bom.VersionDesc}%", BomType = bom.BomType, Version =bom.Version, bom.ModifyDate, bom.Pubufts }); ; } } }