shgx_tz_mom/ZR.Service/mes/md/MdBOMService.cs

92 lines
2.8 KiB
C#
Raw Normal View History

2023-10-06 16:09:13 +08:00
using Infrastructure.Attribute;
using SqlSugar;
using System.Linq;
using ZR.Model.mes.md;
using ZR.Service.MES.md.IService;
namespace ZR.Service.MES.md
{
[AppService(ServiceType = typeof(IMdBOMService), ServiceLifetime = LifeTime.Transient)]
2023-10-08 16:07:48 +08:00
public class MdBOMService : BaseService<MdBom>, IMdBOMService
2023-10-06 16:09:13 +08:00
{
2023-10-08 16:07:48 +08:00
public int deleteBOM(int[] ids)
2023-10-06 16:09:13 +08:00
{
2023-10-08 16:07:48 +08:00
return Delete(ids);
}
public List<MdUnit> GetAllunitList()
{
2024-06-07 11:04:26 +08:00
return Context.Queryable<MdUnit>().Where(it => it.EnableFlag == 'Y').ToList();
2023-10-08 16:07:48 +08:00
}
public int UpdateBOM(MdBom mdBom)
{
2024-06-07 11:04:26 +08:00
return Context.Updateable(mdBom).WhereColumns(it => new { it.Id, it.ProductCode }).ExecuteCommand();
2023-10-06 16:09:13 +08:00
}
2023-10-08 16:07:48 +08:00
int IMdBOMService.AddBom(MdBom bom)
2023-10-06 16:09:13 +08:00
{
2023-10-08 16:07:48 +08:00
return Insert(bom);
2023-10-06 16:09:13 +08:00
}
2024-06-07 11:04:26 +08:00
2023-10-08 16:07:48 +08:00
2023-10-06 16:09:13 +08:00
(int, List<MdBom>) IMdBOMService.GetAll(string productCode, string productName, int pageNum, int pageSize)
{
int totalNum = 0;
if (string.IsNullOrEmpty(productCode) && string.IsNullOrEmpty(productName))
{
2023-10-08 16:07:48 +08:00
List<MdBom> data = Context.Queryable<MdBom>().ToTree(it => it.Child, it => it.ParentProductId, null);
totalNum = data.Count();
data = data.Skip(pageSize * (pageNum - 1)).Take(pageSize).ToList();
2023-10-06 16:09:13 +08:00
return (totalNum, data);
2023-10-08 16:07:48 +08:00
2023-10-06 16:09:13 +08:00
}
else
{
var predicate = Expressionable.Create<MdBom>()
2023-10-08 16:07:48 +08:00
.AndIF(!string.IsNullOrEmpty(productCode), it => it.ProductCode.Contains(productCode))
.AndIF(!string.IsNullOrEmpty(productName), it => it.ProductName.Contains(productName))
2024-06-07 11:04:26 +08:00
.And(it => it.ParentProductId == null)
2023-10-08 16:07:48 +08:00
.ToExpression();
2023-10-06 16:09:13 +08:00
2023-10-08 16:07:48 +08:00
List<MdBom> data = Context.Queryable<MdBom>().Where(predicate).ToList();
totalNum = data.Count();
List<MdBom> dataSons = new List<MdBom>();
if (data != null && data.Count > 0)
2023-10-06 16:09:13 +08:00
{
foreach (var item in data)
{
2023-10-08 16:07:48 +08:00
List<MdBom> data1 = Context.Queryable<MdBom>().ToTree(it => it.Child, it => it.ParentProductId, item.Id);
2024-06-07 11:04:26 +08:00
item.Child = data1;
2023-10-06 16:09:13 +08:00
}
}
2023-10-08 16:07:48 +08:00
data = data.Skip(pageSize * (pageNum - 1)).Take(pageSize).ToList();
return (totalNum, data);
2023-10-06 16:09:13 +08:00
2023-10-08 16:07:48 +08:00
}
2023-10-06 16:09:13 +08:00
}
2023-10-08 16:07:48 +08:00
List<MdBom> IMdBOMService.QueryBOM(string queryString)
2023-10-06 16:09:13 +08:00
{
2023-10-08 16:07:48 +08:00
var predicate = Expressionable.Create<MdBom>()
.AndIF(!string.IsNullOrEmpty(queryString), it => it.ProductCode.Contains(queryString))
.ToExpression();
2024-06-07 11:04:26 +08:00
return Context.Queryable<MdBom>().Where(predicate).ToList();
2023-10-06 16:09:13 +08:00
}
2023-10-08 16:07:48 +08:00
2024-06-07 11:04:26 +08:00
2023-10-08 16:07:48 +08:00
2023-10-06 16:09:13 +08:00
}
}