shgx_tz_mom/ZR.Service/mes/andon/AndonAlarmAreaService.cs
quowingwang f7a3e5c57c 安灯
2025-12-24 14:39:13 +08:00

126 lines
4.1 KiB
C#

using Infrastructure.Attribute;
using Infrastructure.Model;
using SqlSugar;
using ZR.Model;
using ZR.Model.MES.andon;
using ZR.Model.MES.andon.Dto;
using ZR.Repository;
using ZR.Service.mes.andon.Iservice;
namespace ZR.Service.mes.andon
{
/// <summary>
/// 报警区域表Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IAndonAlarmAreaService), ServiceLifetime = LifeTime.Transient)]
public class AndonAlarmAreaService : BaseService<AndonAlarmArea>, IAndonAlarmAreaService
{
/// <summary>
/// 查询报警区域表列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<AndonAlarmAreaDto> GetList(AndonAlarmAreaQueryDto parm)
{
var predicate = Expressionable.Create<AndonAlarmArea>();
predicate.AndIF(!string.IsNullOrEmpty(parm.Area), w => w.Area.Contains(parm.Area));
var response = Queryable()
// 左连接自身表,别名 t_parent 代表父级区域
.LeftJoin<AndonAlarmArea>((t, t_parent) => t.ParentId == t_parent.Id)
.Where(predicate.ToExpression())
// 字段映射:将父级区域的 Area 赋值给 DTO 的 ParentArea
.Select((t, t_parent) => new AndonAlarmAreaDto
{
Id = t.Id,
ParentId = t.ParentId,
ParentArea = t_parent == null ? string.Empty : t_parent.Area,
Area = t.Area,
CreatedBy = t.CreatedBy,
CreatedTime = t.CreatedTime,
UpdatedBy = t.UpdatedBy,
UpdatedTime = t.UpdatedTime
})
.ToPage(parm);
return response;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public AndonAlarmArea GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加报警区域表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public AndonAlarmArea AddAndonAlarmArea(AndonAlarmArea model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改报警区域表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateAndonAlarmArea(AndonAlarmArea model)
{
//var response = Update(w => w.Id == model.Id, it => new AndonAlarmArea()
//{
// ParentId = model.ParentId,
// Area = model.Area,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
public ApiResult GetPullDownP()
{
var response = Queryable()
.Where(a => a.ParentId == null || a.ParentId == 0)
.Select(a => new AlarmAreaPullDownDto
{
label = a.Area,
value = a.Id
}).ToList();
return ApiResult.Success("成功", response);
}
public ApiResult GetPullDownByPID(AlarmAreaPullDownDto parm)
{
if (parm != null)
{
var response = Queryable()
.Where(a => a.ParentId == parm.value)
.Select(a => new AlarmAreaPullDownDto
{
label = a.Area,
value = a.Id
}).ToList();
return ApiResult.Success("成功", response);
}
else
{
return ApiResult.Error("参数错误");
}
}
}
}