162 lines
5.8 KiB
C#
162 lines
5.8 KiB
C#
using System;
|
|
using System.Linq;
|
|
using DOAN.Model;
|
|
using DOAN.Model.Dto;
|
|
using DOAN.Model.MES.dev;
|
|
using DOAN.Model.MES.dev.Dto;
|
|
using DOAN.Repository;
|
|
using DOAN.Service.MES.dev.IService;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using Mapster;
|
|
using SqlSugar;
|
|
|
|
namespace DOAN.Service.MES.dev
|
|
{
|
|
/// <summary>
|
|
/// 备品备件基本信息表Service业务层处理
|
|
/// </summary>
|
|
[AppService(
|
|
ServiceType = typeof(IDeviceSparePartsService),
|
|
ServiceLifetime = LifeTime.Transient
|
|
)]
|
|
public class DeviceSparePartsService : BaseService<DeviceSpareParts>, IDeviceSparePartsService
|
|
{
|
|
/// <summary>
|
|
/// 查询备品备件基本信息表列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<DeviceSparePartsDto> GetList(DeviceSparePartsQueryDto parm)
|
|
{
|
|
var predicate = Expressionable
|
|
.Create<DeviceSpareParts>()
|
|
.AndIF(
|
|
!string.IsNullOrEmpty(parm.PartName),
|
|
s => s.PartName.Contains(parm.PartName)
|
|
)
|
|
.AndIF(
|
|
!string.IsNullOrEmpty(parm.PartCode),
|
|
s => s.PartCode.Contains(parm.PartCode)
|
|
)
|
|
.AndIF(
|
|
!string.IsNullOrEmpty(parm.Description),
|
|
s => s.Description.Contains(parm.Description)
|
|
)
|
|
.AndIF(parm.CategoryId > -1, s => s.CategoryId == parm.CategoryId.Value)
|
|
.AndIF(parm.FkSupplierId > -1, s => s.FkSupplierId == parm.FkSupplierId.Value);
|
|
var response = Context
|
|
.Queryable<DeviceSpareParts, DevicePartsSuppliers, DevicePartsCategories>(
|
|
(s, sp, pc) =>
|
|
new JoinQueryInfos(
|
|
JoinType.Left,
|
|
s.FkSupplierId == sp.SupplierId,
|
|
JoinType.Left,
|
|
s.CategoryId == pc.CategoryId
|
|
)
|
|
)
|
|
.Where(predicate.ToExpression())
|
|
.Select(
|
|
(s, sp, pc) =>
|
|
new DeviceSparePartsDto
|
|
{
|
|
// 映射原有字段
|
|
PartId = s.PartId,
|
|
PartName = s.PartName,
|
|
PartCode = s.PartCode,
|
|
Description = s.Description,
|
|
CategoryId = s.CategoryId,
|
|
CategoryName = pc.CategoryName,
|
|
UnitOfMeasure = s.UnitOfMeasure,
|
|
MinStockLevel = s.MinStockLevel,
|
|
MaxStockLevel = s.MaxStockLevel,
|
|
CreatedAt = s.CreatedAt,
|
|
UpdatedAt = s.UpdatedAt,
|
|
FkSupplierId = sp.SupplierId,
|
|
SupplierName = sp.SupplierName,
|
|
Phone = sp.Phone
|
|
}
|
|
)
|
|
.ToPage(parm);
|
|
/*var response = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.ToPage<DeviceSpareParts, DeviceSparePartsDto>(parm);*/
|
|
|
|
return response;
|
|
}
|
|
|
|
public List<DeviceSparePartsDto> GetListNOPage(string query)
|
|
{
|
|
var response = Queryable()
|
|
.WhereIF(
|
|
!string.IsNullOrEmpty(query),
|
|
x => x.PartName.Contains(query) || x.PartCode.Contains(query)
|
|
)
|
|
.ToList()
|
|
.Adapt<List<DeviceSpareParts>, List<DeviceSparePartsDto>>();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="PartId"></param>
|
|
/// <returns></returns>
|
|
public DeviceSpareParts GetInfo(int PartId)
|
|
{
|
|
var response = Queryable().Where(x => x.PartId == PartId).First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加备品备件基本信息表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public DeviceSpareParts AddDeviceSpareParts(DeviceSpareParts model)
|
|
{
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改备品备件基本信息表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateDeviceSpareParts(DeviceSpareParts model)
|
|
{
|
|
//var response = Update(w => w.PartId == model.PartId, it => new DeviceSpareParts()
|
|
//{
|
|
// PartName = model.PartName,
|
|
// PartNumber = model.PartNumber,
|
|
// Description = model.Description,
|
|
// UnitOfMeasure = model.UnitOfMeasure,
|
|
// MinStockLevel = model.MinStockLevel,
|
|
// MaxStockLevel = model.MaxStockLevel,
|
|
// CreatedAt = model.CreatedAt,
|
|
// UpdatedAt = model.UpdatedAt,
|
|
//});
|
|
//return response;
|
|
return Update(model, true);
|
|
}
|
|
|
|
public List<DropdownOption> GetSupplierOptions()
|
|
{
|
|
return Context
|
|
.Queryable<DevicePartsSuppliers>()
|
|
.Select(s => new DropdownOption { Value = s.SupplierId, Label = s.SupplierName })
|
|
.ToList();
|
|
}
|
|
|
|
public List<DropdownOption> GetDevicePartsCategoriesOptions()
|
|
{
|
|
return Context
|
|
.Queryable<DevicePartsCategories>()
|
|
.Select(s => new DropdownOption { Value = s.CategoryId, Label = s.CategoryName })
|
|
.ToList();
|
|
}
|
|
}
|
|
}
|