using System;
using SqlSugar;
using Infrastructure.Attribute;
using MDM.Services.IPlantService;
using MDM.Service;
using MDM.Model;
using MDM.Model.Plant;
using MDM.Model.Plant.Dto;
using MDM.Repository;
namespace MDM.Services.Plant
{
///
/// 工厂/站点Service业务层处理
///
[AppService(ServiceType = typeof(IPlantFactorySiteService), ServiceLifetime = LifeTime.Transient)]
public class PlantFactorySiteService : BaseService, IPlantFactorySiteService
{
///
/// 查询工厂/站点列表
///
///
///
public PagedInfo GetList(PlantFactorySiteQueryDto parm)
{
var predicate = Expressionable.Create()
.AndIF(!string.IsNullOrEmpty(parm.SiteCode), it => it.SiteCode.Contains(parm.SiteCode))
.AndIF(!string.IsNullOrEmpty(parm.SiteName), it => it.SiteCode.Contains(parm.SiteName))
.AndIF(!string.IsNullOrEmpty(parm.SiteType), it => it.SiteType == parm.SiteType)
.AndIF(parm.Status != null, it => it.Status == parm.Status)
;
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage(parm);
return response;
}
///
/// 获取详情
///
///
///
public PlantFactorySite GetInfo(int SiteId)
{
var response = Queryable()
.Where(x => x.SiteId == SiteId)
.First();
return response;
}
///
/// 添加工厂/站点
///
///
///
public PlantFactorySite AddPlantFactorySite(PlantFactorySite model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
///
/// 修改工厂/站点
///
///
///
public int UpdatePlantFactorySite(PlantFactorySite model)
{
//var response = Update(w => w.SiteId == model.SiteId, it => new PlantFactorySite()
//{
// SiteName = model.SiteName,
// SiteType = model.SiteType,
// Description = model.Description,
// Address = model.Address,
// Status = model.Status,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
}
}