using ivf_tl_Entity.Entity.Alarm;
using ivf_tl_Entity.Entity.Result;
using ivf_tl_Entity.Enums;
using ivf_tl_Entity.Response;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Markup;
using System.Xml.Linq;
namespace ivf_tl_Service.HttpProvider
{
public class AlarmProvider
{
LogService LogService { get; set; }
HttpServiceCall httpServiceCall1 { get; set; }
public AlarmProvider(HttpServiceCall _httpServiceCall, LogService _logService)
{
httpServiceCall1 = _httpServiceCall;
LogService = _logService;
}
private void ExLog(Exception ex, string name)
{
LogService.ExceptionLog(ex, $"AlarmProvider.{name}", LogEnum.RunException);
}
private void ErrorLog(string message, LogEnum logType)
{
LogService.TLLog($"AlarmProvider.{message}", logType);
}
///
/// 查询所有报警联系人及配置信息
///
///
public List GetAlarmPersonnelListApi()
{
string funcName = "GetAlarmPersonnelListApi";
try
{
string url = "/api/tl/control/alarmSetting/getAlarmPersonnellist";
string resultString = httpServiceCall1.callWebService(url);
if (string.IsNullOrEmpty(resultString)) return new List();
ResultEntity> rs = JsonConvert.DeserializeObject>>(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return new List();
}
if (rs.data != null && rs.data.Any()) return rs.data;
ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return new List();
}
catch (Exception ex)
{
ExLog(ex, funcName);
return new List();
}
}
///
/// 查询所有报警类型及其报警编码信息
///
///
public List GetTypeAndTemplateListApi()
{
string funcName = "GetTypeAndTemplateListApi";
try
{
string url = "/api/tl/control/alarmSetting/getTypeAndTemplateList";
string resultString = httpServiceCall1.callWebService(url);
if (string.IsNullOrEmpty(resultString)) return new List();
ResultEntity> rs = JsonConvert.DeserializeObject>>(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return new List();
}
if (rs.data != null && rs.data.Any()) return rs.data;
ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return new List();
}
catch (Exception ex)
{
ExLog(ex, funcName);
return new List();
}
}
///
/// 修改报警配置信息
///
///
public string UpdateAlarmDetailApi(long id, long smsTemplateId, long callTemplateId, int intervalTime, int state)
{
string funcName = "UpdateAlarmDetailApi";
try
{
string url = "/api/tl/control/alarmSetting/updatePersonnelPermission";
string body = JsonConvert.SerializeObject(new { id, smsTemplateId, callTemplateId, intervalTime, state });
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
///
/// 添加的报警配置信息
///
///
public string AddAlarmDetailApi(AlarmDetailEntity alarmDetail)
{
string funcName = "AddAlarmDetailApi";
try
{
string url = "/api/tl/control/alarmSetting/insertPersonnelPermission";
string body = JsonConvert.SerializeObject(new
{
alarmPersonnelId = alarmDetail.userId,
smsTemplateId = alarmDetail.smsTemplateId,
callTemplateId = alarmDetail.callTemplateId,
intervalTime = alarmDetail.intervalTime,
alarmTypeId = alarmDetail.alarmTypeId,
});
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject>(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
if (string.IsNullOrEmpty(rs.data))
{
ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return $"服务器返回id为空";
}
if (long.TryParse(rs.data, out long newId))
{
alarmDetail.perId = newId;
}
else
{
ErrorLog($"{funcName}接口返回成功,但是没有返回正确Id {resultString}", LogEnum.RunError);
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
///
/// 添加报警联系人信息
///
///
public string AddAlarmUserApi(string name, string phone, int sms, int tel)
{
string funcName = "AddAlarmUserApi";
try
{
string url = "/api/tl/control/alarmSetting/addAlarmPersonnel";
string body = JsonConvert.SerializeObject(new { name, phone, sms, tel });
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
///
/// 修改报警联系人信息
///
///
public string UpdateAlarmUserApi(long id, string name, string phone, int sms, int tel)
{
string funcName = "UpdateAlarmUserApi";
try
{
string url = "/api/tl/control/alarmSetting/updateAlarmPersonnel";
string body = JsonConvert.SerializeObject(new { id, name, phone, sms, tel });
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
///
/// 通过id删除报警联系人
///
///
public string DeleteAlarmUserApi(long id)
{
string funcName = "DeleteAlarmUserApi";
try
{
string url = "/api/tl/control/alarmSetting/deleteAlarmPersonnel";
Dictionary body = new Dictionary { { "id", id.ToString() } };
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
///
/// 报警数据接口 带条件查询系统异常
///
///
public AlarmHistoryResult SearchAlarmHistoryApi(SearchAlarmResponse searchAlarm)
{
string funcName = "SearchAlarmHistoryApi";
try
{
string url = "/api/tl/control/alarm/getAlarm";
string body = JsonConvert.SerializeObject(searchAlarm, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return new AlarmHistoryResult() { IsSuccess = false };
var rs = JsonConvert.DeserializeObject>(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return new AlarmHistoryResult() { IsSuccess = false };
}
if (rs.data != null) return rs.data;
ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return new AlarmHistoryResult();
}
catch (Exception ex)
{
ExLog(ex, funcName);
return new AlarmHistoryResult() { IsSuccess = false };
}
}
///
/// 报警数据接口 带条件查询系统异常数量
///
///
public AlarmHistoryNumResult SearchAlarmHistoryNumApi(SearchAlarmResponse searchAlarm)
{
string funcName = "SearchAlarmHistoryNumApi";
try
{
string url = "/api/tl/control/alarm/getAlarmNum";
string body = JsonConvert.SerializeObject(searchAlarm, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return new AlarmHistoryNumResult();
var rs = JsonConvert.DeserializeObject>(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return new AlarmHistoryNumResult();
}
if (rs.data != null) return rs.data;
ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return new AlarmHistoryNumResult();
}
catch (Exception ex)
{
ExLog(ex, funcName);
return new AlarmHistoryNumResult();
}
}
public string SetAlarmNotifyApi(long id, int notify)
{
string funcName = "SetAlarmNotifyApi";
try
{
string url = "/api/tl/control/alarm/muteAlarm";
string body = JsonConvert.SerializeObject(new { id, notify });
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
public List GetTypeAndTemplateListNewApi()
{
string funcName = "GetTypeAndTemplateListNewApi";
try
{
string url = "api/tl/control/alarmSettingNew/getTypeAndTemplateList";
string resultString = httpServiceCall1.callWebService(url);
if (string.IsNullOrEmpty(resultString)) return new List();
ResultEntity> rs = JsonConvert.DeserializeObject>>(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return new List();
}
if (rs.data != null && rs.data.Any()) return rs.data;
ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return new List();
}
catch (Exception ex)
{
ExLog(ex, funcName);
return new List();
}
}
public List GetAlarmPersonnelListNewApi()
{
string funcName = "GetAlarmPersonnelListNewApi";
try
{
string url = "/api/tl/control/alarmSettingNew/getAlarmPersonnelList";
string resultString = httpServiceCall1.callWebService(url);
if (string.IsNullOrEmpty(resultString)) return new List();
ResultEntity> rs = JsonConvert.DeserializeObject>>(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return new List();
}
if (rs.data != null && rs.data.Any()) return rs.data;
ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return new List();
}
catch (Exception ex)
{
ExLog(ex, funcName);
return new List();
}
}
public string UpdateAlarmTypeApi(AlarmTypeEntity alarmTypeEntity, int intervalTime, int alarmLevel)
{
//return "失败测试";
string funcName = "UpdateAlarmTypeApi";
try
{
string url = "/api/tl/control/alarmSettingNew/UpdateAlarmType";
string body = JsonConvert.SerializeObject(new
{
alarmLevel = alarmLevel,
alarmTitle = alarmTypeEntity.alarmTitle,
id = alarmTypeEntity.id,
intervalTime = intervalTime,
mute = alarmTypeEntity.mute,
});
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
public string DeleteAlarmPersonneApi(long id)
{
string funcName = "DeleteAlarmPersonneApi";
try
{
string url = "/api/tl/control/alarmSettingNew/deleteAlarmPersonnel";
Dictionary body = new Dictionary { { "id", id.ToString() } };
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
public string AddAlarmPersonnelApi(AlarmPersonne alarmPersonne)
{
string funcName = "AddAlarmPersonnelApi";
try
{
string url = "/api/tl/control/alarmSettingNew/addAlarmPersonnel";
string body = JsonConvert.SerializeObject(new { name = alarmPersonne.name, phone = alarmPersonne.phone });
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject>(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
if (rs.data == null)
{
ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return $"服务器返回id为空";
}
if (long.TryParse(rs.data.ToString(), out long newId))
{
alarmPersonne.id = newId;
}
else
{
ErrorLog($"{funcName}接口返回成功,但是没有返回正确Id {resultString}", LogEnum.RunError);
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
public string UpdateAlarmPersonneApi(AlarmPersonne alarmPersonne)
{
string funcName = "UpdateAlarmPersonneApi";
try
{
string url = "/api/tl/control/alarmSettingNew/updateAlarmPersonnel";
string body = JsonConvert.SerializeObject(new
{
id = alarmPersonne.id,
name = alarmPersonne.name,
phone = alarmPersonne.phone
});
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
public string SetAlarmPersonnelLevelApi(Dictionary keyValuePairs)
{
string funcName = "SetAlarmPersonnelLevelApi";
try
{
string url = "/api/tl/control/alarmSettingNew/configAlarmPersonnelLevel";
var resultArray = keyValuePairs.Select(kvp => new { id = kvp.Key, level = kvp.Value });
string body = JsonConvert.SerializeObject(resultArray);
string resultString = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
return rs.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, funcName);
return ex.Message;
}
}
}
}