AIController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Options;
  4. using Ropin.Core.Extensions.Redis;
  5. using Ropin.Core.Extensions;
  6. using Ropin.Inspection.Api.Common.Options;
  7. using Ropin.Inspection.Api.Common.Token;
  8. using Ropin.Inspection.Service.Interface;
  9. using Ropin.Inspection.Service.SYS.Interface;
  10. using Ropin.Inspection.Service;
  11. using System.Net.Http;
  12. using Ropin.Inspection.Common.Helper;
  13. using Microsoft.AspNetCore.Authorization;
  14. using Ropin.Inspection.Api.Common;
  15. using System.Threading.Tasks;
  16. using Ropin.Inspection.Model;
  17. using System.Collections.Generic;
  18. using System;
  19. using Newtonsoft.Json;
  20. namespace Ropin.Inspection.Api.Controllers.Base
  21. {
  22. public class AIController : BaseController
  23. {
  24. private readonly IHttpClientFactory _httpClientFactory;
  25. private readonly AIProjectHelper aIHelper;
  26. private readonly ITsysMessageService _TsysMessageService;
  27. private readonly IPushMsgService _pushMsgService;
  28. public AIController(IHttpClientFactory httpClientFactory, ITsysMessageService tsysMessageService, IPushMsgService pushMsgService)
  29. {
  30. aIHelper = new AIProjectHelper(httpClientFactory);
  31. _TsysMessageService = tsysMessageService;
  32. _pushMsgService = pushMsgService;
  33. }
  34. /// <summary>
  35. /// AI登录
  36. /// </summary>
  37. /// <returns></returns>
  38. [HttpGet("AiLogin")]
  39. [AllowAnonymous]
  40. public async Task<AILoginOutput> AiLogin()
  41. {
  42. var token = await aIHelper.GetToken();
  43. return token;
  44. }
  45. /// <summary>
  46. /// AI-获取历史报警记录
  47. /// </summary>
  48. /// <returns></returns>
  49. [HttpGet("AiHistoricAlmrecord/{Devno}/{Page}/{pageSize}")]
  50. [AllowAnonymous]
  51. public async Task<ApiResult<AISqlSugarPagedList<AlmRecordOutput>>> AiHistoricAlmrecord(string Devno,int Page=1,int pageSize=10, long? entityId = null)
  52. {
  53. var data = await aIHelper.GetHistoricAlmrecord(Devno,Page,pageSize, entityId);
  54. return new ApiResult<AISqlSugarPagedList<AlmRecordOutput>>(data, ReturnCode.Success);
  55. }
  56. /// <summary>
  57. /// AI-获取报警处理列表
  58. /// </summary>
  59. /// <returns></returns>
  60. [HttpGet("AiAlmDispose/{Devno}/{Page}/{pageSize}")]
  61. [AllowAnonymous]
  62. public async Task<ApiResult<AISqlSugarPagedList<AlmRecordOutput>>> AiAlmDispose(string Devno, int Page = 1, int pageSize = 10, long? entityId = null)
  63. {
  64. var data = await aIHelper.GetAlmDispose(Devno, Page, pageSize, entityId);
  65. return new ApiResult<AISqlSugarPagedList<AlmRecordOutput>>(data, ReturnCode.Success);
  66. }
  67. /// <summary>
  68. /// AI-报警数据保存到环保消息表数据
  69. /// </summary>
  70. /// <returns></returns>
  71. [HttpGet("AiAlmSaveMessage")]
  72. [AllowAnonymous]
  73. public async Task<ApiResult> AiAlmSaveMessage()
  74. {
  75. //40124884581189
  76. var data = await aIHelper.GetAlmDispose("", 0, 10, 33379713109829);
  77. //var data = await aIHelper.GetHistoricAlmrecord("", 1, 10, 33379713109829);
  78. if (data!=null)
  79. {
  80. foreach (var item in data.Items)
  81. {
  82. if (item!=null)
  83. {
  84. var textJson = new
  85. {
  86. PanoramaId = item.PanoramaId,
  87. PanoramaUrl = item.PanoramaUrl,
  88. RoiJson = item.RoiJson,
  89. NonRoiJson = item.NonRoiJson,
  90. DetectionFrameJson = item.DetectionFrameJson
  91. };
  92. var datas = JsonConvert.SerializeObject(textJson);
  93. MessageFile messageFile = new MessageFile();
  94. messageFile.Text = datas;
  95. messageFile.Type = "FILE_TYP_006";
  96. TpushMsgModel model = new TpushMsgModel
  97. {
  98. C_DevStoreCode = "d705ceb5-7473-4b19-91dd-d3eff223f05b",
  99. C_MsgTypeCode = "MSG_TYPE_024",
  100. Subject = item.Device_TypeName + "报警",
  101. Msg = item.Event_Name,
  102. UserName = "AI",
  103. UserMobile = "",
  104. CreateOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  105. GenerationType = 1,
  106. msgStatus = 1,
  107. FileList=new List<MessageFile> { messageFile }
  108. };
  109. bool bol = await _pushMsgService.PushAlarmMsgAsync(model, model.Subject);
  110. //if (bol)
  111. //{
  112. // bool result= await aIHelper.UpdateAlmIsDelete(item.Id);
  113. //}
  114. }
  115. }
  116. }
  117. TsysMessageSearchModel searchModel = new TsysMessageSearchModel();
  118. searchModel.IsPagination = true;
  119. searchModel.C_MsgTypeCode = "MSG_TYPE_024";
  120. var msgData = await _TsysMessageService.GetConditionAsync(searchModel);
  121. return new ApiResult<IEnumerable<TsysMessageViewModel>>(msgData, ReturnCode.Success);
  122. }
  123. }
  124. }