123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using Ropin.Core.Extensions.Redis;
- using Ropin.Core.Extensions;
- using Ropin.Inspection.Api.Common.Options;
- using Ropin.Inspection.Api.Common.Token;
- using Ropin.Inspection.Service.Interface;
- using Ropin.Inspection.Service.SYS.Interface;
- using Ropin.Inspection.Service;
- using System.Net.Http;
- using Ropin.Inspection.Common.Helper;
- using Microsoft.AspNetCore.Authorization;
- using Ropin.Inspection.Api.Common;
- using System.Threading.Tasks;
- using Ropin.Inspection.Model;
- using System.Collections.Generic;
- using System;
- using Newtonsoft.Json;
- using Microsoft.AspNetCore.Identity;
- using Microsoft.Extensions.Configuration;
- using Ropin.Inspection.Service.VMC.Interface;
- namespace Ropin.Inspection.Api.Controllers.Base
- {
- public class AIController : BaseController
- {
- private readonly IHttpClientFactory _httpClientFactory;
- private readonly AIProjectHelper aIHelper;
- private readonly ITsysMessageService _TsysMessageService;
- private readonly IPushMsgService _pushMsgService;
- private readonly IVmcCameraService _vmcCameraService;
- private string IsUpdateAI = "false";
- public AIController(IHttpClientFactory httpClientFactory, ITsysMessageService tsysMessageService, IPushMsgService pushMsgService, IConfiguration configuration, IVmcCameraService vmcCameraService)
- {
- aIHelper = new AIProjectHelper(httpClientFactory);
- _TsysMessageService = tsysMessageService;
- _pushMsgService = pushMsgService;
- string IsUpdate = configuration.GetSection("AIIsUpdate")?.Value;
- IsUpdateAI = !string.IsNullOrEmpty(IsUpdate) ? IsUpdate : "false";
- _vmcCameraService = vmcCameraService;
- }
- /// <summary>
- /// AI登录
- /// </summary>
- /// <returns></returns>
- [HttpGet("AiLogin")]
- [AllowAnonymous]
- public async Task<AILoginOutput> AiLogin()
- {
- var token = await aIHelper.GetToken();
- return token;
- }
- /// <summary>
- /// AI-获取历史报警记录
- /// </summary>
- /// <returns></returns>
- [HttpGet("AiHistoricAlmrecord/{Devno}/{Page}/{pageSize}")]
- [AllowAnonymous]
- public async Task<ApiResult<AISqlSugarPagedList<AlmRecordOutput>>> AiHistoricAlmrecord(string Devno, int Page = 1, int pageSize = 10, long? entityId = null)
- {
- var data = await aIHelper.GetHistoricAlmrecord(Devno, Page, pageSize, entityId);
- return new ApiResult<AISqlSugarPagedList<AlmRecordOutput>>(data, ReturnCode.Success);
- }
- /// <summary>
- /// AI-获取报警处理列表
- /// </summary>
- /// <returns></returns>
- [HttpGet("AiAlmDispose/{Devno}/{Page}/{pageSize}")]
- [AllowAnonymous]
- public async Task<ApiResult<AISqlSugarPagedList<AlmRecordOutput>>> AiAlmDispose(string Devno, int Page = 1, int pageSize = 10, long? entityId = null)
- {
- var data = await aIHelper.GetAlmDispose(Devno, Page, pageSize, entityId);
- return new ApiResult<AISqlSugarPagedList<AlmRecordOutput>>(data, ReturnCode.Success);
- }
- /// <summary>
- /// AI-报警数据保存到环保消息表数据
- /// </summary>
- /// <returns></returns>
- [HttpGet("AiAlmSaveMessage")]
- [AllowAnonymous]
- public async Task<ApiResult> AiAlmSaveMessage()
- {
- //40124884581189;33379713109829
- var data = await aIHelper.GetAlmDispose("", 1, 100, 40124884581189);
- //var data = await aIHelper.GetHistoricAlmrecord("", 1, 10, 40124884581189);
- if (data != null)
- {
- foreach (var item in data.Items)
- {
- if (item != null)
- {
- var textJson = new
- {
- PanoramaId = item.PanoramaId,
- PanoramaUrl = item.PanoramaUrl,
- RoiJson = item.RoiJson,
- NonRoiJson = item.NonRoiJson,
- DetectionFrameJson = item.DetectionFrameJson
- };
- var datas = JsonConvert.SerializeObject(textJson);
- MessageFile messageFile = new MessageFile();
- messageFile.Text = datas;
- messageFile.Type = "FILE_TYP_006";
- string msg = item.Event_Name;
- if (string.IsNullOrEmpty(msg))
- {
- msg = item.Event_Code;
- }
- TpushMsgModel model = new TpushMsgModel
- {
- C_DevStoreCode = "d705ceb5-7473-4b19-91dd-d3eff223f05b",
- C_MsgTypeCode = "MSG_TYPE_024",
- Subject = item.Device_TypeName + "报警",
- Msg = msg,
- UserName = "AI盒子",
- UserMobile = "",
- CreateOn = item.StartTime?.ToString("yyyy-MM-dd HH:mm:ss"),
- GenerationType = 1,
- msgStatus = 1,
- FileList = new List<MessageFile> { messageFile }
- };
- bool bol = await _pushMsgService.PushAlarmMsgAsync(model, model.Subject);
- if (bol && IsUpdateAI == "true")
- {
- DateTime updTime = DateTime.Now;
- var updData = new
- {
- Id = item.Id,
- ConfrimContent = "环保测试数据,自动确认",
- Mistake = false,
- Confirmed = true,
- ConfirmTime = updTime,
- ConfirmUserName = "环保同步程序",
- Closed = true,
- CloseContent = "环保测试数据,自动关闭",
- EndTime = updTime,
- CloseUserName = "环保同步程序"
- };
- var dataStr = JsonConvert.SerializeObject(updData);
- bool result = await aIHelper.UpdateAlm(dataStr);
- //bool result = await aIHelper.UpdateAlmIsDelete(item.Id);
- }
- }
- }
- }
- //TsysMessageSearchModel searchModel = new TsysMessageSearchModel();
- //searchModel.IsPagination = true;
- //searchModel.C_MsgTypeCode = "MSG_TYPE_024";
- //var msgData = await _TsysMessageService.GetConditionAsync(searchModel);
- return new ApiResult(ReturnCode.Success);
- }
- [HttpPost]
- [AllowAnonymous]
- [Route("pushData/alarmData/{deviceNo}")]
- public async Task<ApiResult<object>> AlarmData([FromRoute] string deviceNo, [FromBody] AlarmDataModel alarmDataModel)
- {
- var devIds = await _vmcCameraService.GetCameraByTDH(alarmDataModel.deviceNo);
- devIds.ForEach(async x =>
- {
- List<MessageFile> messageFiles = new List<MessageFile>();
- messageFiles.Add(new MessageFile
- {
- Text = alarmDataModel.panoramaDataId,
- Type = "FILE_TYP_006"
- });
- messageFiles.Add(new MessageFile
- {
- Text = alarmDataModel.snapshotDataId,
- Type = "FILE_TYP_006"
- });
- messageFiles.Add(new MessageFile
- {
- Text = alarmDataModel.relatedSnapshotDataId,
- Type = "FILE_TYP_006"
- });
- TpushMsgModel model = new TpushMsgModel
- {
- C_DevStoreCode = x,
- C_MsgTypeCode = "MSG_TYPE_024",
- Subject = "AI盒子报警",
- Msg = alarmDataModel.alarmType,
- UserName = "AI盒子",
- UserMobile = "",
- CreateOn = alarmDataModel.captureTime,
- GenerationType = 1,
- msgStatus = 1,
- FileList = messageFiles
- };
- bool bol = await _pushMsgService.PushAlarmMsgAsync(model, model.Subject);
- });
- return new ApiResult<object>(new object { });
- }
- }
- }
|