Files
shgx_tz_mes_backend_sync/ZR.Service/mes/md/MdBOMService.cs

100 lines
3.1 KiB
C#
Raw Normal View History

2023-10-06 16:09:13 +08:00
using Infrastructure.Attribute;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZR.Model.mes.md;
using ZR.Service.mes.md.IService;
using ZR.Service.MES.md.IService;
using static System.Runtime.InteropServices.JavaScript.JSType;
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()
{
return Context.Queryable<MdUnit>().Where(it=>it.EnableFlag=='Y').ToList();
}
public int UpdateBOM(MdBom mdBom)
{
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
}
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))
.And(it=>it.ParentProductId==null)
.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);
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();
return Context.Queryable<MdBom>().Where(predicate).ToList();
2023-10-06 16:09:13 +08:00
}
2023-10-08 16:07:48 +08:00
2023-10-06 16:09:13 +08:00
}
}