using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using DOAN.Model;
using DOAN.Model.Dto;
using DOAN.Model.MES.base_;
using DOAN.Model.MES.base_.Dto;
using DOAN.Repository;
using DOAN.Service.MES.base_.IService;
using System.Linq;
using Microsoft.IdentityModel.Tokens;
using Mapster;
namespace DOAN.Service.MES.base_
{
///
/// 设备信息Service业务层处理
///
[AppService(ServiceType = typeof(IBaseDeviceService), ServiceLifetime = LifeTime.Transient)]
public class BaseDeviceService : BaseService, IBaseDeviceService
{
///
/// 查询设备信息列表
///
///
///
public PagedInfo GetList(BaseDeviceQueryDto parm)
{
var predicate = Expressionable.Create()
.AndIF(!string.IsNullOrEmpty(parm.DeviceCode), it => it.DeviceCode.Contains(parm.DeviceCode))
.AndIF(!string.IsNullOrEmpty(parm.DeviceName), it => it.DeviceName.Contains(parm.DeviceName))
.AndIF(!string.IsNullOrEmpty(parm.DeviceSpecification), it => it.DeviceSpecification.Contains(parm.DeviceSpecification))
.AndIF(!string.IsNullOrEmpty(parm.DeviceSupplier), it => it.DeviceSupplier.Contains(parm.DeviceSupplier))
.AndIF(parm.FkWorkStation > -1, it => it.FkWorkStation == parm.FkWorkStation)
.AndIF(parm.Status > -1, it => it.Status == parm.Status)
;
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage(parm);
return response;
}
///
/// 查询设备信息列表 未绑定工位的设备
///
///
///
public List GetList_nobind(int id)
{
var response= Context.Queryable().Where(it => (it.Status==1&&it.FkWorkStation == null) || (it.Status == 1 && it.FkWorkStation == id))
.ToList().Adapt>();
return response;
}
///
/// 获取详情
///
///
///
public BaseDevice GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
///
/// 添加设备信息
///
///
///
public BaseDevice AddBaseDevice(BaseDevice model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
///
/// 修改设备信息
///
///
///
public int UpdateBaseDevice(BaseDevice model)
{
//var response = Update(w => w.Id == model.Id, it => new BaseDevice()
//{
// FkWorkStation = model.FkWorkStation,
// DeviceCode = model.DeviceCode,
// DeviceName = model.DeviceName,
// DeviceSpecification = model.DeviceSpecification,
// PurchaseTime = model.PurchaseTime,
// DeviceSupplier = model.DeviceSupplier,
// Remark = model.Remark,
// Status = model.Status,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
}
}