using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Repository;
using ZR.Service.Business.IBusinessService;
using System.Linq;
using ZR.Model.MES.dev;
using ZR.Model.MES.dev.Dto;
namespace ZR.Service.MES.dev
{
///
/// 设备台账Service业务层处理
///
[AppService(ServiceType = typeof(IDeviceAccountService), ServiceLifetime = LifeTime.Transient)]
public class DeviceAccountService : BaseService, IDeviceAccountService
{
///
/// 查询设备台账列表
///
///
///
public PagedInfo GetList(DeviceAccountQueryDto parm)
{
var predicate = Expressionable.Create()
.AndIF(!string.IsNullOrEmpty(parm.DeviceName),it=>it.DeviceName.Contains(parm.DeviceName))
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), it => it.DeviceSpecification.Contains(parm.DeviceSpecification))
.AndIF(parm.Status > -1, it => it.Status == parm.Status)
.AndIF(parm.FkDeviceType > 0, it => it.FkDeviceType== parm.FkDeviceType)
;
var response = Queryable()
.Where(predicate.ToExpression())
.OrderByDescending(it => it.UpdatedTime)
.OrderByDescending(it => it.CreatedTime)
.ToPage(parm);
return response;
}
///
/// 获取详情
///
///
///
public DeviceAccount GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
///
/// 添加设备台账
///
///
///
public DeviceAccount AddDeviceAccount(DeviceAccount model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
///
/// 修改设备台账
///
///
///
public int UpdateDeviceAccount(DeviceAccount model)
{
//var response = Update(w => w.Id == model.Id, it => new DeviceAccount()
//{
// FkDeviceType = model.FkDeviceType,
// DeviceName = model.DeviceName,
// DeviceCode = model.DeviceCode,
// Workshop = model.Workshop,
// Workline = model.Workline,
// Status = model.Status,
// DeviceImage = model.DeviceImage,
// DeviceFile = model.DeviceFile,
// DeviceSpecification = model.DeviceSpecification,
// ResponsiblePerson = model.ResponsiblePerson,
// Remark = model.Remark,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
}
}