using Yw.DAL.PostgreSql;
namespace PBS.DAL.WE.PostgreSql
{
///
/// 用水器具
///
public class Utensil : BaseDAL_Paras_Flags_TagName_Sorter_UseStatus, IUtensil
{
///
///
///
public override ConnectionConfig ConnectionConfig
{
get { return HStation.WE.ConfigHelper.PostgreSqlConnectionConfig; }
}
///
/// 通过 GroupID 获取
///
public List GetByGroupID(long GroupID)
{
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => x.GroupID == GroupID).ToList();
}
}
///
/// 通过 GroupIds 获取
///
public List GetByGroupIds(List GroupIds)
{
if (GroupIds == null || !GroupIds.Any())
{
return default;
}
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => GroupIds.Contains(x.GroupID)).ToList();
}
}
///
/// 更新 GroupID
///
public bool UpdateGroupID(long ID, long GroupID)
{
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
{
return db.Updateable()
.SetColumns(x => x.GroupID == GroupID)
.Where(x => x.ID == ID)
.ExecuteCommand() > 0;
}
}
///
/// 批量更新 GroupID
///
public bool UpdateGroupIds(List<(long ID, long GroupID)> list)
{
if (list == null || list.Count < 1)
return false;
using (var db = new SqlSugarClient(this.ConnectionConfig))
{
var entityList = list.Select(x => new Entity.WE.Utensil() { ID = x.ID, GroupID = x.GroupID }).ToList();
return db.Updateable(entityList)
.UpdateColumns(nameof(Entity.WE.Utensil.GroupID))
.ExecuteCommandHasChange();
}
}
}
}