Files
U8-Import/NX.ERP.U8/Mom/BomDAL.cs

122 lines
3.9 KiB
C#
Raw Normal View History

2021-05-15 14:01:12 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dapper;
namespace NX.ERP.U8.Mom
{
2021-05-19 15:19:27 +08:00
/// <summary>
/// BOM
/// </summary>
2021-05-15 14:01:12 +08:00
public class BomDAL
{
2021-05-19 15:19:27 +08:00
/// <summary>
/// 获取BOM清单
/// </summary>
/// <param name="strWhere"></param>
/// <param name="Params"></param>
/// <returns></returns>
2021-05-15 14:01:12 +08:00
public IEnumerable<NX.ERP.Model.Response.MOM.Bom> GetList(string strWhere="", object Params = null)
{
2021-06-04 14:48:56 +08:00
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
2021-05-15 14:01:12 +08:00
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
2021-11-30 13:57:13 +08:00
left join bom_opcomponentopt as f on d.OptionsId=f.OptionsId
2021-05-15 14:01:12 +08:00
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<int, Model.Response.MOM.Bom>();
conn.Query<Model.Response.MOM.Bom, Model.Response.MOM.OptionComponent, Model.Response.MOM.Bom>(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;
}
}
2021-06-04 11:22:42 +08:00
public IEnumerable<NX.ERP.Model.Response.MOM.Bom> GetList(long Pubufts)
{
return this.GetList("CONVERT(BIGINT,a.Ufts) >@Pubufts", new { Pubufts });
}
2021-05-15 14:01:12 +08:00
2021-05-21 13:06:45 +08:00
public IEnumerable<NX.ERP.Model.Response.MOM.Bom> GetList(NX.ERP.Model.Request.Bom bom)
{
List<string> where = new List<string>();
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 ");
}
2021-05-24 11:12:32 +08:00
if (bom.ModifyDate!=null)
{
2021-06-03 12:06:26 +08:00
where.Add(" ISNULL(a.ModifyDate,CreateDate) >=@ModifyDate or a.RelsTime>=@ModifyDate ");
2021-05-24 11:12:32 +08:00
}
2021-05-21 13:06:45 +08:00
2021-06-03 12:06:26 +08:00
if (bom.Pubufts != null)
{
2021-06-03 16:04:28 +08:00
where.Add("CONVERT(BIGINT,a.Ufts) >@Pubufts ");
2021-06-03 12:06:26 +08:00
}
2021-05-21 13:06:45 +08:00
return this.GetList(string.Join(" and ", where.ToArray()), new
{
ParentCode = bom.ParentCode,
VersionDesc =$"%{bom.VersionDesc}%",
BomType = bom.BomType,
Version =bom.Version,
2021-06-03 12:06:26 +08:00
bom.ModifyDate,
bom.Pubufts
2021-05-21 13:06:45 +08:00
}); ;
}
2021-05-15 14:01:12 +08:00
}
}