|
- using DataVAPI.Model;
- using DataVAPI.ModelDataBus;
- using DataVAPI.ServerDB.MongoDB;
- using DataVAPI.Tool.IOT;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
-
- namespace DataVAPI.Controllers
- {
- /// <summary>
- /// MG数据库:告警表 AlarmTable
- /// </summary>
- public class AlarmController : BaseController
- {
- MongoDbHelper<AlarmTable> mg = new MongoDbHelper<AlarmTable>(DataBus.connStr, DataBus.dbName);
- MongoDbHelper<DeviceTable> mgsb = new MongoDbHelper<DeviceTable>(DataBus.connStr, DataBus.dbName);
-
- string st = System.Reflection.MethodBase.GetCurrentMethod().Name;
-
- /// <summary>
- /// 新增一条数据
- /// </summary>
- [HttpPost]
- public JsonMsg<AlarmTable> Create(AlarmTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(auth.ClientId))
- {
- return JsonMsg<AlarmTable>.Error(null, st, "设备ID不能为空"); ;
- }
- mg.Insert(auth);
- return JsonMsg<AlarmTable>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<AlarmTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 批量新增一条数据
- /// </summary>
- /// <param name="auth">告警消息</param>
- [HttpPost]
- public JsonMsg<List<AlarmTable>> Creates(List<AlarmTable> auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.Inserts(auth);
- return JsonMsg<List<AlarmTable>>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 修改数据
- /// </summary>
- /// <param name="auth"></param>
- /// <returns></returns>
- [HttpPost]
- public JsonMsg<AlarmTable> Modify(AlarmTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.UpdateID(auth);
- return JsonMsg<AlarmTable>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<AlarmTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据唯一ID查询数据
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<AlarmTable> QueryOne(string id)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<AlarmTable>.OK(mg.QueryOne(id), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<AlarmTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据客户端ID查询当日未处理信息
- /// </summary>
- /// <param name="clientId"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<AlarmTable>> QueryClientId(string clientId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<AlarmTable>>.OK(mg.QueryClientId(clientId), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据设备ID查询当日未处理信息
- /// </summary>
- /// <param name="clientId"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<AlarmTable>> QueryDeviceId(string clientId, string deviceId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(clientId))
- return JsonMsg<List<AlarmTable>>.Error(null, st, "客户端ID不能为空"); ;
- return JsonMsg<List<AlarmTable>>.OK(mg.QueryDeviceId(clientId, deviceId), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据设备名称、时间查询未处理信息
- /// </summary>
- /// <param name="clientId"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<AlarmTable>> QueryDeviceName(string DeviceName, string StartTime, string StopTime)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- DeviceTable device = mgsb.QueryDeviceName(DeviceName);
- if (device != null)
- {
- if (!string.IsNullOrEmpty(StartTime) && !string.IsNullOrEmpty(StopTime))
- {
- DateTime starttime, stoptime;
- starttime = Tools.ConvertLongToDateTime(long.Parse(StartTime));
- stoptime = Tools.ConvertLongToDateTime(long.Parse(StopTime));
- return JsonMsg<List<AlarmTable>>.OK(mg.QueryAllTime(device.ClientId, device.DeviceId, starttime, stoptime), st);
- }
- else return JsonMsg<List<AlarmTable>>.OK(mg.QueryDeviceId(device.ClientId,device.DeviceId), st);
- }
- return JsonMsg<List<AlarmTable>>.OK(null, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据客户端ID、设备ID、时间查询告警信息
- /// </summary>
- /// <param name="clientId">客户端ID</param>
- /// <param name="deviceId">设备ID</param>
- /// <param name="starttime">开始时间</param>
- /// <param name="endtime">结束时间</param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<AlarmTable>> Query(string clientId, string deviceId, DateTime starttime, DateTime endtime)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<AlarmTable>>.OK(mg.QueryAllTime(clientId, deviceId, starttime, endtime), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 分页查询
- /// </summary>
- /// <param name="clientId">客户端ID</param>
- /// <param name="datesta">开始时间</param>
- /// <param name="datastop">结束时间</param>
- /// <param name="PageNumber">页</param>
- /// <param name="PageSize">大小</param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<PaginationListModel<AlarmTable>> BasePagQuery(string clientId, string deviceId, DateTime datesta, DateTime datastop, int PageNumber = 1, int PageSize = 100)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<PaginationListModel<AlarmTable>>.OK(mg.BasePagQuery(clientId, deviceId, datesta, datastop, PageNumber, PageSize), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<PaginationListModel<AlarmTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 删除数据(假删除-只做标记)
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<string> Delete(string id)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(id))
- {
- return JsonMsg<string>.Error(null, st, "设备ID不能为空"); ;
- }
- else
- {
- mg.Modify(id, "State", "n");
- return JsonMsg<string>.OK("success!", st);
- }
- }
- catch (Exception ex)
- {
- return JsonMsg<string>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 删除数据
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<string> DeleteDate(string id)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(id))
- {
- return JsonMsg<string>.Error(null, st, "设备ID不能为空"); ;
- }
- else
- {
- mg.Delete(id);
- return JsonMsg<string>.OK("success!", st);
- }
- }
- catch (Exception ex)
- {
- return JsonMsg<string>.Error(null, st, ex.Message);
- }
- }
- }
- }
|