1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using Cksoft.Unity;
- using Cksoft.Unity.Log4NetConfig;
- using DllEapDal.OFILM;
- using DllEapEntity;
- using DllEapEntity.OFILM;
- using Microsoft.Extensions.Configuration;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace WebStatusToolkit.Notice
- {
- public class OfilmLanxinNoticeService
- {
- public static async void NoticeDisconn(Machine mac, MacStatus entity, string errorinfo)
- {
- var lanxinConfig = AppConfigurtaionServices.Configuration.GetSection("LanXinConfig").Get<LanxinConfig>();
- if (lanxinConfig == null)
- {
- errorinfo = "配置文件中LanXin节点未找到或配置不正确";
- LogHelper<OfilmLanxinNoticeService>.LogError(errorinfo, "断线提醒", string.Empty);
- return;
- }
- try
- {
- using (IDatabase db = DbFactory.Base("eap"))
- {
- var configDal = new NoticeConfigDal(db);
- var config = configDal.GetByFactory(mac.FactoryId);
- if (config == null || config.NoticeConfigDetails == null || config.NoticeConfigDetails.Count() <= 0)
- {
- errorinfo = "获取该园区配置失败";
- LogHelper<OfilmLanxinNoticeService>.LogError($"推送机台[{entity.MacCode + " " + entity.STime.ToString("yyyy-MM-dd HH:mm:ss")}]断线信息失败:{errorinfo ?? "获取配置信息失败"}", "断线提醒", string.Empty);
- return;
- }
- var toUsers = string.Join(",", config.NoticeConfigDetails.Select(c => c.FCode));
- var sql = $"SELECT COUNT(1) FROM NoticeHistory where maccode='{mac.FCode}' and rectime>='{DateTime.Now.ToString("yyyy-MM-dd 00:00:00")}'";
- var count = Convert.ToInt32(db.FindList<string>(sql).FirstOrDefault() ?? "0");
- var machineInfo = $"{mac.FactoryName}的机台[{mac.FCode}]";
- string content = $"{machineInfo}已于[{entity.STime.ToString("yyyy-MM-dd HH:mm:ss")}]断开连接,本日已断线【{count + 1}】次," +
- $"请及时处理!";
- var requestData = new LanxinRequestDto
- {
- Appid = lanxinConfig.Appid,
- Secret = lanxinConfig.Secret,
- Tousers = toUsers,
- Content = content
- };
- var json = JsonConvert.SerializeObject(requestData);
- var res = HttpRequestHelper<OfilmLanxinReponseDto>.Post(lanxinConfig.Url, json, ref errorinfo, "application/json");
- if (res == null || res.Code != 1)
- {
- LogHelper<OfilmLanxinNoticeService>.LogFatal($"推送机台[{content}]断线信息失败:{res.Message ?? "请求蓝信接口异常"}", "断线提醒", string.Empty);
- return;
- }
- var history = new NoticeHistory
- {
- MacCode = entity.MacCode,
- RecTime = DateTime.Now
- };
- if (db.InsertFor(history, string.Empty) < 0)
- {
- LogHelper<OfilmLanxinNoticeService>.LogError($"推送机台[{content}]断线信息失败", "断线提醒", string.Empty);
- return;
- }
- LogHelper<OfilmLanxinNoticeService>.LogFatal($"推送机台[{content}]断线信息成功", "断线提醒", string.Empty);
- }
- }
- catch (Exception ex)
- {
- LogHelper<OfilmLanxinNoticeService>.LogError($"推送机台[{mac.FCode} {entity.STime.ToString("yyyy-MM-dd HH:mm:ss")}]断线信息失败:{ex.Message}", "断线提醒", string.Empty);
- }
- }
- }
- }
|