| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- 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);
- }
- /// <summary>
- /// 查询所有报警联系人及配置信息
- /// </summary>
- /// <returns></returns>
- public List<AlarmUserEntity> GetAlarmPersonnelListApi()
- {
- string funcName = "GetAlarmPersonnelListApi";
- try
- {
- string url = "/api/tl/control/alarmSetting/getAlarmPersonnellist";
- string resultString = httpServiceCall1.callWebService(url);
- if (string.IsNullOrEmpty(resultString)) return new List<AlarmUserEntity>();
- ResultEntity<List<AlarmUserEntity>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AlarmUserEntity>>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return new List<AlarmUserEntity>();
- }
- if (rs.data != null && rs.data.Any()) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new List<AlarmUserEntity>();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new List<AlarmUserEntity>();
- }
- }
- /// <summary>
- /// 查询所有报警类型及其报警编码信息
- /// </summary>
- /// <returns></returns>
- public List<AlarmTypeEntity> GetTypeAndTemplateListApi()
- {
- string funcName = "GetTypeAndTemplateListApi";
- try
- {
- string url = "/api/tl/control/alarmSetting/getTypeAndTemplateList";
- string resultString = httpServiceCall1.callWebService(url);
- if (string.IsNullOrEmpty(resultString)) return new List<AlarmTypeEntity>();
- ResultEntity<List<AlarmTypeEntity>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AlarmTypeEntity>>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return new List<AlarmTypeEntity>();
- }
- if (rs.data != null && rs.data.Any()) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new List<AlarmTypeEntity>();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new List<AlarmTypeEntity>();
- }
- }
- /// <summary>
- /// 修改报警配置信息
- /// </summary>
- /// <returns></returns>
- 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<ResultEntity>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return rs.message;
- }
- return null;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return ex.Message;
- }
- }
- /// <summary>
- /// 添加的报警配置信息
- /// </summary>
- /// <returns></returns>
- 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<ResultEntity<string>>(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;
- }
- }
- /// <summary>
- /// 添加报警联系人信息
- /// </summary>
- /// <returns></returns>
- 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<ResultEntity>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return rs.message;
- }
- return null;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return ex.Message;
- }
- }
- /// <summary>
- /// 修改报警联系人信息
- /// </summary>
- /// <returns></returns>
- 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<ResultEntity>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return rs.message;
- }
- return null;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return ex.Message;
- }
- }
- /// <summary>
- /// 通过id删除报警联系人
- /// </summary>
- /// <returns></returns>
- public string DeleteAlarmUserApi(long id)
- {
- string funcName = "DeleteAlarmUserApi";
- try
- {
- string url = "/api/tl/control/alarmSetting/deleteAlarmPersonnel";
- Dictionary<string, string> body = new Dictionary<string, string> { { "id", id.ToString() } };
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
- var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return rs.message;
- }
- return null;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return ex.Message;
- }
- }
- /// <summary>
- /// 报警数据接口 带条件查询系统异常
- /// </summary>
- /// <returns></returns>
- 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<ResultEntity<AlarmHistoryResult>>(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 };
- }
- }
- /// <summary>
- /// 报警数据接口 带条件查询系统异常数量
- /// </summary>
- /// <returns></returns>
- 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<ResultEntity<AlarmHistoryNumResult>>(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<ResultEntity>(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<AlarmTypeEntity> GetTypeAndTemplateListNewApi()
- {
- string funcName = "GetTypeAndTemplateListNewApi";
- try
- {
- string url = "api/tl/control/alarmSettingNew/getTypeAndTemplateList";
- string resultString = httpServiceCall1.callWebService(url);
- if (string.IsNullOrEmpty(resultString)) return new List<AlarmTypeEntity>();
- ResultEntity<List<AlarmTypeEntity>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AlarmTypeEntity>>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return new List<AlarmTypeEntity>();
- }
- if (rs.data != null && rs.data.Any()) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new List<AlarmTypeEntity>();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new List<AlarmTypeEntity>();
- }
- }
- public List<AlarmPersonne> GetAlarmPersonnelListNewApi()
- {
- string funcName = "GetAlarmPersonnelListNewApi";
- try
- {
- string url = "/api/tl/control/alarmSettingNew/getAlarmPersonnelList";
- string resultString = httpServiceCall1.callWebService(url);
- if (string.IsNullOrEmpty(resultString)) return new List<AlarmPersonne>();
- ResultEntity<List<AlarmPersonne>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AlarmPersonne>>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return new List<AlarmPersonne>();
- }
- if (rs.data != null && rs.data.Any()) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new List<AlarmPersonne>();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new List<AlarmPersonne>();
- }
- }
- 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<ResultEntity>(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<string, string> body = new Dictionary<string, string> { { "id", id.ToString() } };
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return "服务器返回空";
- var rs = JsonConvert.DeserializeObject<ResultEntity>(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<ResultEntity<object>>(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<ResultEntity>(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<long, int> 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<ResultEntity>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return rs.message;
- }
- return null;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return ex.Message;
- }
- }
- }
- }
|