| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using ddAlter.DB;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- namespace ddAlter.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class xyController : ControllerBase
- {
- public readonly xyDBContext _context;
- public readonly IHttpClientFactory _httpClientFactory;
- public xyController(xyDBContext context, IHttpClientFactory httpClientFactory)
- {
- _context = context;
- _httpClientFactory = httpClientFactory;
- }
- [HttpGet]
- [Route("missing-call-record-alter")]
- async public Task<ActionResult> MissingCallRecordAlter()
- {
- var data = _context.RecordCount.FromSqlRaw(@"select COUNT(1) as num from T_Call_CallRecords where CallType=0 and BeginTime>DATEADD(MINUTE,-10,GETDATE()) and (CallState=1 or WaitStartTime is not null)
- and BusinessType not in (select F_Key from T_Sys_DHKeys with(nolock) where F_Type = 2 or F_Type = 3)").ToList();
- if (data == null || data.Count <= 0 || data[0].num < 1)
- {
- // 发送报警
- var msg = new
- {
- msgtype = "text",
- text = new
- {
- content = "【信阳-报警】连续10分钟内没有录音生成,请检查服务状态!"
- },
- at = new
- {
- isAtAll = true
- }
- };
- // https://oapi.dingtalk.com/robot/send?access_token=d4efe5b71f2e92a11ff89bb8ad704319e2d874ef5e590e8a78247405542bf637
- var sendMessage = JsonConvert.SerializeObject(msg);
- var request = new HttpRequestMessage(HttpMethod.Post, "/robot/send?access_token=d4efe5b71f2e92a11ff89bb8ad704319e2d874ef5e590e8a78247405542bf637")
- {
- Content = new StringContent(sendMessage, Encoding.UTF8, "application/json")
- };
- var client = _httpClientFactory.CreateClient("client_dd");
- client.Timeout = TimeSpan.FromSeconds(10);
-
- var response = await client.SendAsync(request);
- var result = response.Content.ReadAsStringAsync();
- return Ok(new
- {
- msg = result,
- num = data[0].num
- }) ;
- }
- return Ok(new
- {
- num = data[0].num
- });
- }
- }
- }
|