报警记录处理过程

This commit is contained in:
quowingwang 2025-12-11 11:11:56 +08:00
parent 467f71a150
commit af414d27c9
12 changed files with 483 additions and 56 deletions

View File

@ -4,14 +4,15 @@ using ZR.Admin.WebApi.Filters;
using ZR.Model.MES.andon;
using ZR.Model.MES.andon.Dto;
using ZR.Service.mes.andon.Iservice;
//创建时间2025-12-10
//创建时间2025-12-11
namespace ZR.Admin.WebApi.Controllers.andon
{
/// <summary>
/// 报警记录
/// </summary>
[Route("mes/AndonAlarmRecord")]
[AllowAnonymous]
[Verify]
[Route("business/AndonAlarmRecord")]
public class AndonAlarmRecordController : BaseController
{
/// <summary>

View File

@ -0,0 +1,109 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Model.MES.andon;
using ZR.Model.MES.andon.Dto;
using ZR.Service.mes.andon.Iservice;
//创建时间2025-12-11
namespace ZR.Admin.WebApi.Controllers.andon
{
/// <summary>
/// 安灯报警处理过程
/// </summary>
[Verify]
[Route("business/AndonAlarmRecordProcess")]
public class AndonAlarmRecordProcessController : BaseController
{
/// <summary>
/// 安灯报警处理过程接口
/// </summary>
private readonly IAndonAlarmRecordProcessService _AndonAlarmRecordProcessService;
public AndonAlarmRecordProcessController(IAndonAlarmRecordProcessService AndonAlarmRecordProcessService)
{
_AndonAlarmRecordProcessService = AndonAlarmRecordProcessService;
}
/// <summary>
/// 查询安灯报警处理过程列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "business:andonalarmrecordprocess:list")]
public IActionResult QueryAndonAlarmRecordProcess([FromQuery] AndonAlarmRecordProcessQueryDto parm)
{
var response = _AndonAlarmRecordProcessService.GetList(parm);
return SUCCESS(response);
}
/// <summary>
/// 查询安灯报警处理过程详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "business:andonalarmrecordprocess:query")]
public IActionResult GetAndonAlarmRecordProcess(int Id)
{
var response = _AndonAlarmRecordProcessService.GetInfo(Id);
var info = response.Adapt<AndonAlarmRecordProcess>();
return SUCCESS(info);
}
/// <summary>
/// 添加安灯报警处理过程
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "business:andonalarmrecordprocess:add")]
[Log(Title = "安灯报警处理过程", BusinessType = BusinessType.INSERT)]
public IActionResult AddAndonAlarmRecordProcess([FromBody] AndonAlarmRecordProcessDto parm)
{
var modal = parm.Adapt<AndonAlarmRecordProcess>().ToCreate(HttpContext);
var response = _AndonAlarmRecordProcessService.AddAndonAlarmRecordProcess(modal);
return SUCCESS(response);
}
/// <summary>
/// 更新安灯报警处理过程
/// </summary>
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "business:andonalarmrecordprocess:edit")]
[Log(Title = "安灯报警处理过程", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateAndonAlarmRecordProcess([FromBody] AndonAlarmRecordProcessDto parm)
{
var modal = parm.Adapt<AndonAlarmRecordProcess>().ToUpdate(HttpContext);
var response = _AndonAlarmRecordProcessService.UpdateAndonAlarmRecordProcess(modal);
return ToResponse(response);
}
/// <summary>
/// 删除安灯报警处理过程
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:andonalarmrecordprocess:delete")]
[Log(Title = "安灯报警处理过程", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteAndonAlarmRecordProcess(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _AndonAlarmRecordProcessService.Delete(idsArr);
return ToResponse(response);
}
}
}

View File

@ -13,52 +13,30 @@ namespace ZR.Model.MES.andon
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 报警编码
/// </summary>
[SugarColumn(ColumnName = "alarm_code")]
public string AlarmCode { get; set; }
/// <summary>
/// 产线
/// </summary>
[SugarColumn(ColumnName = "line_code")]
public string LineCode { get; set; }
/// <summary>
/// 产线名称
/// </summary>
[SugarColumn(ColumnName = "line_name")]
public string LineName { get; set; }
/// <summary>
/// 报警类型
/// </summary>
[SugarColumn(ColumnName = "alarm_type")]
public string AlarmType { get; set; }
/// <summary>
/// 发送方
/// </summary>
public string Sender { get; set; }
/// <summary>
/// 发送时间
/// </summary>
[SugarColumn(ColumnName = "send_time")]
public DateTime? SendTime { get; set; }
/// <summary>
/// 接收方
/// </summary>
public string Receiver { get; set; }
/// <summary>
/// 响应时间
/// </summary>
[SugarColumn(ColumnName = "response_time")]
public DateTime? ResponseTime { get; set; }
/// <summary>
/// 处理结束时间
/// </summary>
[SugarColumn(ColumnName = "handle_time")]
public DateTime? HandleTime { get; set; }
/// <summary>
/// 持续时间
/// </summary>
[SugarColumn(ColumnName = "duration_time")]
public int? DurationTime { get; set; }
/// <summary>
/// 报警级别
/// </summary>
@ -71,6 +49,45 @@ namespace ZR.Model.MES.andon
[SugarColumn(ColumnName = "alarm_info")]
public string AlarmInfo { get; set; }
/// <summary>
/// 发送方ID
/// </summary>
public string Sender { get; set; }
/// <summary>
/// 发送方名称
/// </summary>
[SugarColumn(ColumnName = "sender_name")]
public string SenderName { get; set; }
/// <summary>
/// 发送时间
/// </summary>
[SugarColumn(ColumnName = "send_time")]
public DateTime? SendTime { get; set; }
/// <summary>
/// 接收方
/// </summary>
public string Receiver { get; set; }
/// <summary>
/// 接收方名称
/// </summary>
[SugarColumn(ColumnName = "receiver_name")]
public string ReceiverName { get; set; }
/// <summary>
/// 序号
/// </summary>
public int? Sequence { get; set; }
/// <summary>
/// 持续时间
/// </summary>
[SugarColumn(ColumnName = "duration_time")]
public int? DurationTime { get; set; }
/// <summary>
/// 状态(未处理、已处理、上报、超时)
/// </summary>
@ -82,6 +99,11 @@ namespace ZR.Model.MES.andon
[SugarColumn(ColumnName = "handle_result")]
public string HandleResult { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remarks { get; set; }
/// <summary>
/// 创建人
/// </summary>

View File

@ -0,0 +1,74 @@
namespace ZR.Model.MES.andon
{
/// <summary>
/// 安灯报警处理过程
/// </summary>
[SugarTable("andon_alarm_record_process")]
public class AndonAlarmRecordProcess
{
/// <summary>
/// 主键
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 报警记录编码
/// </summary>
[SugarColumn(ColumnName = "alarm_code")]
public string AlarmCode { get; set; }
/// <summary>
/// 操作
/// </summary>
public string Operate { get; set; }
/// <summary>
/// 操作人
/// </summary>
public string Operator { get; set; }
/// <summary>
/// 操作人名称
/// </summary>
[SugarColumn(ColumnName = "operator_name")]
public string OperatorName { get; set; }
/// <summary>
/// 操作时间
/// </summary>
[SugarColumn(ColumnName = "operate_time")]
public DateTime? OperateTime { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remarks { get; set; }
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnName = "cREATED_BY")]
public string CreatedBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnName = "cREATED_TIME")]
public DateTime? CreatedTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
[SugarColumn(ColumnName = "uPDATED_BY")]
public string UpdatedBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[SugarColumn(ColumnName = "uPDATED_TIME")]
public DateTime? UpdatedTime { get; set; }
}
}

View File

@ -17,30 +17,38 @@ namespace ZR.Model.MES.andon.Dto
[Required(ErrorMessage = "主键不能为空")]
public int Id { get; set; }
public string AlarmCode { get; set; }
public string LineCode { get; set; }
public string LineName { get; set; }
public string AlarmType { get; set; }
public string Sender { get; set; }
public DateTime? SendTime { get; set; }
public string Receiver { get; set; }
public DateTime? ResponseTime { get; set; }
public DateTime? HandleTime { get; set; }
public int? DurationTime { get; set; }
public string AlarmLevel { get; set; }
public string AlarmInfo { get; set; }
public string Sender { get; set; }
public string SenderName { get; set; }
public DateTime? SendTime { get; set; }
public string Receiver { get; set; }
public string ReceiverName { get; set; }
public int? Sequence { get; set; }
public int? DurationTime { get; set; }
public string Status { get; set; }
public string HandleResult { get; set; }
public string Remarks { get; set; }
public string CreatedBy { get; set; }
public DateTime? CreatedTime { get; set; }

View File

@ -0,0 +1,43 @@
using System.ComponentModel.DataAnnotations;
namespace ZR.Model.MES.andon.Dto
{
/// <summary>
/// 安灯报警处理过程查询对象
/// </summary>
public class AndonAlarmRecordProcessQueryDto : PagerInfo
{
}
/// <summary>
/// 安灯报警处理过程输入输出对象
/// </summary>
public class AndonAlarmRecordProcessDto
{
[Required(ErrorMessage = "主键不能为空")]
public int Id { get; set; }
public string AlarmCode { get; set; }
public string Operate { get; set; }
public string Operator { get; set; }
public string OperatorName { get; set; }
public DateTime? OperateTime { get; set; }
public string Remarks { get; set; }
public string CreatedBy { get; set; }
public DateTime? CreatedTime { get; set; }
public string UpdatedBy { get; set; }
public DateTime? UpdatedTime { get; set; }
}
}

View File

@ -0,0 +1,83 @@
using Infrastructure.Attribute;
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(IAndonAlarmRecordProcessService), ServiceLifetime = LifeTime.Transient)]
public class AndonAlarmRecordProcessService : BaseService<AndonAlarmRecordProcess>, IAndonAlarmRecordProcessService
{
/// <summary>
/// 查询安灯报警处理过程列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<AndonAlarmRecordProcessDto> GetList(AndonAlarmRecordProcessQueryDto parm)
{
var predicate = Expressionable.Create<AndonAlarmRecordProcess>();
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage<AndonAlarmRecordProcess, AndonAlarmRecordProcessDto>(parm);
return response;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public AndonAlarmRecordProcess GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加安灯报警处理过程
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public AndonAlarmRecordProcess AddAndonAlarmRecordProcess(AndonAlarmRecordProcess model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改安灯报警处理过程
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateAndonAlarmRecordProcess(AndonAlarmRecordProcess model)
{
//var response = Update(w => w.Id == model.Id, it => new AndonAlarmRecordProcess()
//{
// AlarmCode = model.AlarmCode,
// Operate = model.Operate,
// Operator = model.Operator,
// OperatorName = model.OperatorName,
// OperateTime = model.OperateTime,
// Remarks = model.Remarks,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
}
}

View File

@ -6,7 +6,6 @@ using ZR.Model.MES.andon.Dto;
using ZR.Repository;
using ZR.Service.mes.andon.Iservice;
namespace ZR.Service.mes.andon
{
/// <summary>
@ -65,18 +64,22 @@ namespace ZR.Service.mes.andon
{
//var response = Update(w => w.Id == model.Id, it => new AndonAlarmRecord()
//{
// AlarmCode = model.AlarmCode,
// LineCode = model.LineCode,
// LineName = model.LineName,
// AlarmType = model.AlarmType,
// Sender = model.Sender,
// SendTime = model.SendTime,
// Receiver = model.Receiver,
// ResponseTime = model.ResponseTime,
// HandleTime = model.HandleTime,
// DurationTime = model.DurationTime,
// AlarmLevel = model.AlarmLevel,
// AlarmInfo = model.AlarmInfo,
// Sender = model.Sender,
// SenderName = model.SenderName,
// SendTime = model.SendTime,
// Receiver = model.Receiver,
// ReceiverName = model.ReceiverName,
// Sequence = model.Sequence,
// DurationTime = model.DurationTime,
// Status = model.Status,
// HandleResult = model.HandleResult,
// Remarks = model.Remarks,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,

View File

@ -0,0 +1,23 @@
using System;
using ZR.Model;
using System.Collections.Generic;
using ZR.Model.MES.andon;
using ZR.Model.MES.andon.Dto;
namespace ZR.Service.mes.andon.Iservice
{
/// <summary>
/// 安灯报警处理过程service接口
/// </summary>
public interface IAndonAlarmRecordProcessService : IBaseService<AndonAlarmRecordProcess>
{
PagedInfo<AndonAlarmRecordProcessDto> GetList(AndonAlarmRecordProcessQueryDto parm);
AndonAlarmRecordProcess GetInfo(int Id);
AndonAlarmRecordProcess AddAndonAlarmRecordProcess(AndonAlarmRecordProcess parm);
int UpdateAndonAlarmRecordProcess(AndonAlarmRecordProcess parm);
}
}

View File

@ -0,0 +1,61 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ZR.Service.mes.andon
{
public class ScheduledBackgroundService:BackgroundService
{
private readonly ILogger<ScheduledBackgroundService> _logger;
private readonly IServiceScopeFactory _scopeFactory;
private readonly TimeSpan _interval = TimeSpan.FromMinutes(5);
public ScheduledBackgroundService(
ILogger<ScheduledBackgroundService> logger,
IServiceScopeFactory scopeFactory)
{
_logger = logger;
_scopeFactory = scopeFactory;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation($"定时后台服务启动,执行间隔: {_interval.TotalMinutes}分钟");
// 延迟启动,等待应用完全初始化
await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken);
while (!stoppingToken.IsCancellationRequested)
{
try
{
_logger.LogInformation($"开始执行定时任务: {DateTime.Now:HH:mm:ss}");
//// 使用 Scope 获取 Scoped 服务
//using (var scope = _scopeFactory.CreateScope())
//{
// var myService = scope.ServiceProvider.GetRequiredService<IMyBusinessService>();
// await myService.ProcessDataAsync();
//}
_logger.LogInformation($"定时任务完成");
}
catch (Exception ex)
{
_logger.LogError(ex, "定时任务执行异常");
}
// 等待指定间隔
await Task.Delay(_interval, stoppingToken);
}
_logger.LogInformation("定时后台服务停止");
}
}
}