Merge branch 'master' of https://gitee.com/doan-tech/zhuangpei-mesbackend
This commit is contained in:
commit
4a6d4c3ccc
@ -2,6 +2,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Service.MES.andon.IService;
|
||||
using ZR.Model.MES.andon.Dto;
|
||||
using ZR.Model.Dto;
|
||||
using ZR.Service.MES.andon;
|
||||
|
||||
namespace DOAN.WebApi.Controllers.MES.andon
|
||||
{
|
||||
@ -17,7 +19,19 @@ namespace DOAN.WebApi.Controllers.MES.andon
|
||||
_andonDataAnalysisServcie= andonDataAnalysisServcie;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询故障记录表列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("list")]
|
||||
[ActionPermissionFilter(Permission = "andonManagement:andonfaultrecord:list")]
|
||||
public IActionResult QueryAndonFaultRecord([FromBody] AndonFaultRecordQueryDto parm)
|
||||
{
|
||||
|
||||
var response = _andonDataAnalysisServcie.GetList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取故障类型
|
||||
/// </summary>
|
||||
|
||||
@ -87,19 +87,45 @@
|
||||
}
|
||||
},
|
||||
//邮箱配置信息
|
||||
//"MailOptions": {
|
||||
// //发件人名称
|
||||
// "FromName": "3143976203<xu3143976203@foxmail.com>",
|
||||
// //发送人邮箱
|
||||
// "FromEmail": "3143976203@qq.com", //eg:xxxx@qq.com
|
||||
// //发送人邮箱密码
|
||||
// "Password": "wwxcrgvbotxxdcfg",
|
||||
// //协议
|
||||
// "Smtp": "smtp.qq.com",
|
||||
// "Port": 465,
|
||||
// "Signature": "系统邮件,请勿回复! ",
|
||||
// "UseSsl": true
|
||||
//},
|
||||
"MailOptions": {
|
||||
//发件人名称
|
||||
"FromName": "system",
|
||||
"FromName": "gx.andon@gam.com.cn",
|
||||
//发送人邮箱
|
||||
"FromEmail": "", //eg:xxxx@qq.com
|
||||
"FromEmail": "gx.andon@gam.com.cn ", //eg:xxxx@qq.com
|
||||
//发送人邮箱密码
|
||||
"Password": "",
|
||||
"Password": "chejinggx",
|
||||
//协议
|
||||
"Smtp": "smtp.qq.com",
|
||||
"Port": 587,
|
||||
"Signature": "系统邮件,请勿回复!",
|
||||
"Smtp": "smtp.gam.com.cn",
|
||||
"Port": 25,
|
||||
"Signature": "上海干巷Andon系统邮件,请勿回复! ",
|
||||
"UseSsl": true
|
||||
},
|
||||
//"MailOptions": {
|
||||
// //发件人名称
|
||||
// "FromName": "gx.andon@gam.com.cn",
|
||||
// //发送人邮箱
|
||||
// "FromEmail": "gx.andon@gam.com.cn", //eg:xxxx@qq.com
|
||||
// //发送人邮箱密码
|
||||
// "Password": "chejinggx",
|
||||
// //协议
|
||||
// "Smtp": "mai.gam.com.cn",
|
||||
// "Port": 25,
|
||||
// "Signature": "系统邮件,请勿回复! ",
|
||||
// "UseSsl": false
|
||||
//},
|
||||
//redis服务配置
|
||||
"RedisServer": {
|
||||
"open": 0, //是否启用redis
|
||||
|
||||
@ -89,16 +89,16 @@
|
||||
//邮箱配置信息
|
||||
"MailOptions": {
|
||||
//发件人名称
|
||||
"FromName": "system",
|
||||
"FromName": "gx.andon@gam.com.cn",
|
||||
//发送人邮箱
|
||||
"FromEmail": "", //eg:xxxx@qq.com
|
||||
"FromEmail": "gx.andon@gam.com.cn", //eg:xxxx@qq.com
|
||||
//发送人邮箱密码
|
||||
"Password": "",
|
||||
"Password": "chejinggx",
|
||||
//协议
|
||||
"Smtp": "smtp.qq.com",
|
||||
"Port": 587,
|
||||
"Signature": "系统邮件,请勿回复!",
|
||||
"UseSsl": true
|
||||
"Smtp": "mai.gam.com.cn",
|
||||
"Port": 25,
|
||||
"Signature": "上海干巷Andon系统邮件,请勿回复! ",
|
||||
"UseSsl": false
|
||||
},
|
||||
//redis服务配置
|
||||
"RedisServer": {
|
||||
|
||||
@ -27,6 +27,17 @@ namespace ZR.Model.MES.andon
|
||||
/// </summary>
|
||||
public string color { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 邮箱
|
||||
/// </summary>
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主管
|
||||
/// </summary>
|
||||
public string Director { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
|
||||
@ -7,9 +7,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using ZR.Model.Dto;
|
||||
using ZR.Model;
|
||||
using ZR.Model.MES.andon;
|
||||
using ZR.Model.MES.andon.Dto;
|
||||
using ZR.Model.MES.dev;
|
||||
using ZR.Repository;
|
||||
using ZR.Service.MES.andon.IService;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
@ -18,6 +21,25 @@ namespace ZR.Service.MES.andon
|
||||
[AppService(ServiceType = typeof(IAndonDataAnalysisServcie), ServiceLifetime = LifeTime.Transient)]
|
||||
public class AndonDataAnalysisServcie : BaseService<AndonFaultRecord>, IAndonDataAnalysisServcie
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询故障记录表列表 今日全部 和以前未签到异常
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<AndonFaultRecordDto> GetList(AndonFaultRecordQueryDto parm)
|
||||
{
|
||||
var predicate = Expressionable.Create<AndonFaultRecord>()
|
||||
.AndIF(parm.DateTimeRange.Count() == 2 && parm.DateTimeRange[0] > DateTime.MinValue, it => it.StartTime >= parm.DateTimeRange[0])
|
||||
.AndIF(parm.DateTimeRange.Count() == 2 && parm.DateTimeRange[1] > DateTime.MinValue, it => it.StartTime <= parm.DateTimeRange[1])
|
||||
.OrIF(parm.DateTimeRange.Count() == 2 , it => it.StartTime < parm.DateTimeRange[0] && it.Status == 1)
|
||||
;
|
||||
|
||||
var response = Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.ToPage<AndonFaultRecord, AndonFaultRecordDto>(parm);
|
||||
|
||||
return response;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1.获取安灯报警类型字典
|
||||
/// </summary>
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using SqlSugar.IOC;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Common;
|
||||
using ZR.Model.Dto;
|
||||
using ZR.Model.MES.andon;
|
||||
using ZR.Service.MES.andon.IService;
|
||||
@ -13,6 +19,10 @@ namespace ZR.Service.MES.andon
|
||||
[AppService(ServiceType = typeof(IAndonInteractionService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class AndonInteractionService : BaseService<AndonFaultRecord>, IAndonInteractionService
|
||||
{
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private OptionsSetting OptionsSetting;
|
||||
|
||||
public AndonInteractionService(IOptions<OptionsSetting> options) { OptionsSetting = options.Value; }
|
||||
/// <summary>
|
||||
/// 呼叫请求
|
||||
/// </summary>
|
||||
@ -35,19 +45,113 @@ namespace ZR.Service.MES.andon
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
record.Status = 2;
|
||||
return Update(record, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取待响应的 记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<AndonFaultRecord> WaitingResponse()
|
||||
{
|
||||
return Context.Queryable<AndonFaultRecord>().Where(it=>it.Status == 1).ToList();
|
||||
return Context.Queryable<AndonFaultRecord>().Where(it => it.Status == 1).ToList();
|
||||
}
|
||||
|
||||
|
||||
private static List<AndonFaultDict> GetFaultDicts()
|
||||
{
|
||||
return DbScoped.SugarScope.CopyNew().Queryable<AndonFaultDict>().ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 监测超时发送邮件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string[] MonitoringMails()
|
||||
{
|
||||
string[] result =null;
|
||||
// 获取异常字典
|
||||
List<AndonFaultDict> andonFaults = GetFaultDicts();
|
||||
// 获取超时记录
|
||||
DateTime Overtime = DateTime.Now.AddHours(-1);
|
||||
List<AndonFaultRecord> AlarmRecord = Context.Queryable<AndonFaultRecord>().Where(it => it.Status == 1).Where(it => it.StartTime <= Overtime).ToList();
|
||||
|
||||
if (AlarmRecord.Count > 0 && andonFaults.Count > 0)
|
||||
{
|
||||
result = new string[AlarmRecord.Count];
|
||||
foreach (var alarm in AlarmRecord)
|
||||
{
|
||||
|
||||
foreach (var fault in andonFaults)
|
||||
{
|
||||
|
||||
if (alarm.FaultDict == fault.Name)
|
||||
{
|
||||
double overSpan =Math.Round((DateTime.Now - alarm.StartTime.Value).TotalHours,2) ;
|
||||
SendEmailDto sendEmailVo = new SendEmailDto();
|
||||
sendEmailVo.Subject = "上海干巷总装车间 Andon [报警升级]通知";
|
||||
// 邮箱责任
|
||||
sendEmailVo.ToUser=fault.Email?? "qianhao.xu@doan-tech.com";
|
||||
StringBuilder msg=new StringBuilder();
|
||||
msg.Append($"Dear [{fault.Director}]经理:");
|
||||
msg.Append("\n");
|
||||
msg.Append("\n");
|
||||
msg.Append($"[{alarm.LineCode}]产线发生[{alarm.FaultDict}]类型异常, [{alarm.AskPerson}]报警人 在{alarm.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss")}时间发起报警,已经超过{overSpan}小时未处理,请立刻到现场扫码签到并处理异常,报警内容如下:\n");
|
||||
msg.Append("\n");
|
||||
msg.Append($"{alarm.FaultContext??"[无报警内容]"}。");
|
||||
msg.Append("\n");
|
||||
msg.Append("\n");
|
||||
msg.Append("\n");
|
||||
msg.Append($"Andon系统将每10分钟发送一次邮件,直至[{alarm.FaultDict}]类型异常,被签到并处理!");
|
||||
msg.Append("\n");
|
||||
msg.Append("\n");
|
||||
msg.Append("\n");
|
||||
msg.Append("如果邮件中有任务不清楚的地方或者需要我们提供任何帮助,请联系苏州道安自动化有限公司IT部门,邮件地址为qianhao.xu@doan-tech.com");
|
||||
|
||||
sendEmailVo.Content = msg.ToString();
|
||||
sendEmailVo.SendMe = true;
|
||||
sendEmailVo.AddTime = DateTime.Now;
|
||||
result[AlarmRecord.IndexOf(alarm)] = SendEmail(sendEmailVo);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送邮件任务
|
||||
/// </summary>
|
||||
/// <param name="sendEmailVo"></param>
|
||||
/// <returns></returns>
|
||||
private string SendEmail(SendEmailDto sendEmailVo)
|
||||
{
|
||||
if (sendEmailVo == null)
|
||||
{
|
||||
return "请求参数不完整";
|
||||
}
|
||||
if (string.IsNullOrEmpty(OptionsSetting.MailOptions.FromEmail) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password))
|
||||
{
|
||||
return "请配置邮箱信息";
|
||||
}
|
||||
|
||||
MailHelper mailHelper = new();
|
||||
|
||||
string[] toUsers = sendEmailVo.ToUser.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
||||
if (sendEmailVo.SendMe)
|
||||
{
|
||||
toUsers.Append(mailHelper.FromEmail);
|
||||
}
|
||||
string result = mailHelper.SendMail(toUsers, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent);
|
||||
|
||||
logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}, 结果{result}");
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.Dto;
|
||||
using ZR.Model;
|
||||
using ZR.Model.MES.andon;
|
||||
using ZR.Model.MES.andon.Dto;
|
||||
|
||||
@ -11,6 +13,7 @@ namespace ZR.Service.MES.andon.IService
|
||||
{
|
||||
public interface IAndonDataAnalysisServcie
|
||||
{
|
||||
PagedInfo<AndonFaultRecordDto> GetList(AndonFaultRecordQueryDto parm);
|
||||
List<AndonFaultDict> GetListFault();
|
||||
List<AbnormalDurationRatioResult> AbnormalDurationRatio(AndonAnalysisQueryDto query);
|
||||
List<AbnormalDurationRatioResult> AbnormalNumDurationRatio(AndonAnalysisQueryDto query);
|
||||
|
||||
@ -15,5 +15,10 @@ namespace ZR.Service.MES.andon.IService
|
||||
int CallHandle(AndonFaultRecord query);
|
||||
int SignIn(AndonFaultRecord response);
|
||||
List<AndonFaultRecord> WaitingResponse();
|
||||
/// <summary>
|
||||
/// 监测超时发送邮件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string[] MonitoringMails();
|
||||
}
|
||||
}
|
||||
|
||||
64
ZR.Tasks/TaskScheduler/Job_Email_send.cs
Normal file
64
ZR.Tasks/TaskScheduler/Job_Email_send.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Quartz;
|
||||
using Quartz.Impl.Triggers;
|
||||
using Quartz.Impl;
|
||||
using SqlSugar.IOC;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.MES.dev;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.MES.andon.IService;
|
||||
|
||||
namespace ZR.Tasks.TaskScheduler
|
||||
{
|
||||
/// <summary>
|
||||
/// 超过一个小时就发送邮箱
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(Job_Email_send), ServiceLifetime = LifeTime.Scoped)]
|
||||
public class Job_Email_send : JobBase, IJob
|
||||
{
|
||||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private readonly IAndonInteractionService _andonInteractionService;
|
||||
public Job_Email_send(IAndonInteractionService andonInteractionService)
|
||||
{
|
||||
_andonInteractionService= andonInteractionService;
|
||||
}
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
await ExecuteJob(context, async () => await Run(context));
|
||||
}
|
||||
public async Task Run(IJobExecutionContext context)
|
||||
{
|
||||
AbstractTrigger trigger = (context as JobExecutionContextImpl).Trigger as AbstractTrigger;
|
||||
//var info = await tasksQzService.CopyNew().GetByIdAsync(trigger.JobName);
|
||||
var info = await DbScoped.SugarScope.CopyNew().Queryable<SysTasks>().FirstAsync(f => f.ID == trigger.JobName);
|
||||
if (info == null)
|
||||
{
|
||||
throw new CustomException($"任务{trigger?.JobName}_邮件发送定时调度请求执行失败,任务不存在");
|
||||
}
|
||||
|
||||
string[] result = _andonInteractionService.MonitoringMails();
|
||||
if (result.Length > 0)
|
||||
{
|
||||
foreach (string s in result)
|
||||
{
|
||||
logger.Info($"任务【{info.Name}】_邮件发送定时调度请求执行结果={s}\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info($"任务【{info.Name}】_邮件发送定时调度请求执行结果 没有数据\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user