|
- using DataVAPI.Model;
- using DataVAPI.ModelDataBus;
- using DataVAPI.ServerDB.MongoDB;
- using DataVAPI.Tool.IOT;
- using DataVAPI.UpAndDown;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
-
- namespace DataVAPI.Controllers
- {
- /// <summary>
- /// MG数据库:日志表 LogTable
- /// </summary>
- public class LogController : BaseController
- {
-
- MongoDbHelper<LogTable> mg = new MongoDbHelper<LogTable>(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<LogTable> Create(LogTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(auth.ClientId))
- {
- return JsonMsg<LogTable>.Error(null, st, "设备ID不能为空"); ;
- }
- mg.Insert(auth);
- return JsonMsg<LogTable>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<LogTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 批量新增数据
- /// </summary>
- /// <param name="auth">日志消息</param>
- [HttpPost]
- public JsonMsg<List<LogTable>> Creates(List<LogTable> auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.Inserts(auth);
- return JsonMsg<List<LogTable>>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LogTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 修改数据
- /// </summary>
- /// <param name="auth"></param>
- /// <returns></returns>
- [HttpPost]
- public JsonMsg<LogTable> Modify(LogTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.UpdateID(auth);
- return JsonMsg<LogTable>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<LogTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据ID查询数据
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<LogTable> QueryOne(string id)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<LogTable>.OK(mg.QueryOne(id), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<LogTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据客户端ID查询当日未处理信息
- /// </summary>
- /// <param name="clientId"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<LogTable>> QueryClientId(string clientId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<LogTable>>.OK(mg.QueryClientId(clientId), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LogTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据设备ID查询当日未处理信息
- /// </summary>
- /// <param name="clientId"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<LogTable>> QueryDeviceId(string clientId, string deviceId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<LogTable>>.OK(mg.QueryDeviceId(clientId, deviceId), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LogTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据设备名称查询当日未处理信息
- /// </summary>
- /// <param name="DeviceName"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<LogTable>> 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<LogTable>>.OK(mg.QueryAllTime(device.ClientId, device.DeviceId, starttime, stoptime), st);
- }
- else return JsonMsg<List<LogTable>>.OK(mg.QueryClientId(device.ClientId), st);
- }
- return JsonMsg<List<LogTable>>.OK(null, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LogTable>>.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<LogTable>> Query(string clientId, string deviceId, DateTime starttime, DateTime endtime)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<LogTable>>.OK(mg.QueryAllTime(clientId, deviceId, starttime, endtime), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LogTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 分页查询
- /// </summary>
- /// <param name="chid"></param>
- /// <param name="datesta"></param>
- /// <param name="datastop"></param>
- /// <param name="PageNumber"></param>
- /// <param name="PageSize"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<PaginationListModel<LogTable>> 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<LogTable>>.OK(mg.BasePagQuery(clientId, deviceId, datesta, datastop, PageNumber, PageSize), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<PaginationListModel<LogTable>>.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);
- }
- }
-
- /// <summary>
- /// 查询设备所有文件
- /// </summary>
- /// <param name="DeviceName"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<object> QueryLogFile(string DeviceName)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(DeviceName))
- {
- return JsonMsg<object>.Error(null, st, "设备名称不能为空");
- }
- else
- {
- return JsonMsg<object>.OK(Sample.FileQueryALL(DeviceName), st);
- }
- }
- catch (Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- }
- }
|