123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Caching.Memory;
- using Microsoft.Extensions.Options;
- using Ropin.Core.Common;
- 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 Newtonsoft.Json;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Api.Wx;
- using Ropin.Inspection.Model.SearchModel;
- using Ropin.Inspection.Model.ViewModel.SYS;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Service.SYS;
- using System.Net.Http.Headers;
- using System.Threading.Tasks;
- using System;
- using UAParser;
- using ZXing.Aztec.Internal;
- using Ropin.Inspection.Model.SearchModel.DEV;
- using Ropin.Inspection.Service.LGS.Interface;
- using Ropin.Inspection.Model.ViewModel.LGS;
- using System.Net.Sockets;
- using Ropin.Inspection.Model.ViewModel.DEV;
- using Ropin.Inspection.Repository.DEV.Interface;
- using Ropin.Inspection.Service.DEV.Interface;
- using InfluxData.Net.InfluxDb.Models;
- using RabbitMQ.Client;
- using System.Collections.Generic;
- using Ropin.Inspection.Model.Entities;
- using NPOI.SS.Formula.Functions;
- using Newtonsoft.Json.Linq;
- using System.Linq;
- using System.Security.Cryptography.X509Certificates;
- namespace Ropin.Inspection.Api.Controllers.Base
- {
- public class RabbitMQController : BaseController
- {
- private readonly RabbitMQModel _options;
- private readonly ILargeScreenEventService _largeScreenEventRepository;
- private readonly ILargeScreenControlService _largeScreenControRepository;
- private readonly IDEVCmdService _ldevCmdRepository;
- public RabbitMQController(IOptionsMonitor<RabbitMQModel> options, ILargeScreenEventService largeScreenEventRepository, ILargeScreenControlService largeScreenControRepository, IDEVCmdService ldevCmdRepository)
- {
- _options = options.Get("RabbitMQModel");
- _largeScreenEventRepository = largeScreenEventRepository;
- _largeScreenControRepository = largeScreenControRepository;
- _ldevCmdRepository = ldevCmdRepository;
- }
- /// <summary>
- /// 发送指令
- /// </summary>
- /// <returns></returns>
- [HttpPost("SendCommand")]
- public async Task<ApiResult> SendCommand(SendCmdModel model)
- {
- if (model == null|| string.IsNullOrEmpty(model.C_ControlCode)|| string.IsNullOrEmpty(model.C_CmdId))
- {
- return new ApiResult(ReturnCode.ArgsError, "参数错误");
- }
- try
- {
- string cmdId = model.C_CmdId;
- //var cmdList = await _ldevCmdRepository.GetInstructionByCmdCode((new DevInstructionSearchModel() { CmdCode = cmdId }));
- var cmdList = await _ldevCmdRepository.GetInstructionConditionAsync((new DevInstructionSearchModel() { CmdCode = cmdId, IsPagination = false, C_Status = "1" }));
- if (cmdList==null|| cmdList.Count() == 0)
- {
- return new ApiResult(ReturnCode.DataError, "该命令下没有要执行的指令");
- }
- cmdList = cmdList.OrderBy(x => x.I_ExeOrder).ToList();
- List<TLGS_LargeScreenEvent> LargeScreenEvent=new List<TLGS_LargeScreenEvent> ();
- List<SendComRabbitMQParam> RabbitMQParamList=new List<SendComRabbitMQParam> ();
- foreach ( var item in cmdList)
- {
- string id = Guid.NewGuid().ToString();
- TLGS_LargeScreenEvent large = new TLGS_LargeScreenEvent();
- large.C_ID = id;
- large.C_ControlCode = model.C_ControlCode;
- large.C_DevStoreCode = model.C_DevStoreCode;
- large.C_BoxCode = item.C_BoxCode;
- large.C_Name = model.C_Name;
- large.C_Type = model.C_Type;
- large.C_Status = "2";
- LargeScreenEvent.Add(large);
- RabbitMQParamList.Add(new SendComRabbitMQParam
- {
- EveId = id,
- BoxId = item.C_BoxCode,
- cmdId = cmdId,
- pms = item.C_Params,
- protocol = item.C_Protocol,
- sort = item.I_ExeOrder
- });
- }
- if (RabbitMQParamList != null && RabbitMQParamList.Count > 0)
- {
- _options.msgStr = JsonConvert.SerializeObject(RabbitMQParamList);
- bool bol = await RabbitMQHelper.SnedRabbitMQ_ExchangeDirect(_options);
- if (!bol)
- {
- return new ApiResult(ReturnCode.DataError, "发送指令失败");
- }
- }
- if (LargeScreenEvent != null && LargeScreenEvent.Count > 0)
- {
- string status = "2";// bol ? "2" : "3";
- await _largeScreenEventRepository.CreateListAsync(LargeScreenEvent, status);
- }
- //return new ApiResult<RabbitMQModel>(_options, ReturnCode.Success);
- return new ApiResult(ReturnCode.Success);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 设备报警【手动报警】
- /// </summary>
- /// <returns></returns>
- [HttpPost("DevManualAddAlmMsg")]
- public async Task<ApiResult> DevManualAddAlmMsg(TpushMsgModel model)
- {
- if (model == null || string.IsNullOrEmpty(model.C_DevStoreCode) || string.IsNullOrEmpty(model.Msg))
- {
- return new ApiResult(ReturnCode.ArgsError, "参数错误");
- }
- try
- {
- model.CreateOn = DateTime.Now.ToString();
- _options.msgStr = JsonConvert.SerializeObject(model);
- _options.QueueName = "rabbit.alarmDevice";
- bool bol = await RabbitMQHelper.SnedRabbitMQ_ExchangeDirect(_options);
- if (!bol) {
- return new ApiResult(ReturnCode.DataError, "发送指令失败");
- }
- return new ApiResult(ReturnCode.Success);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- }
- }
|