|
- 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数据库:大屏信息表 ScreenController
- /// </summary>
- public class ScreenController : BaseController
- {
- MongoDbHelper<LargeScreenTable> mg = new MongoDbHelper<LargeScreenTable>(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<LargeScreenTable> CreateOrUpdate(LargeScreenTable largeScreenTable)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(largeScreenTable.devicename))
- {
- return JsonMsg<LargeScreenTable>.Error(null, st, "设备名称不能为空"); ;
- }
- LargeScreenTable largeScreen = mg.QueryDeviceName(largeScreenTable.devicename);
-
- if (largeScreen != null)
- {
- largeScreenTable.Id = largeScreen.Id;
- mg.UpdateID(largeScreenTable);
- }
- else
- {
- mg.Insert(largeScreenTable);
- }
- return JsonMsg<LargeScreenTable>.OK(largeScreenTable, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<LargeScreenTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 新增一条数据
- /// </summary>
- [HttpPost]
- public JsonMsg<LargeScreenTable> Create(LargeScreenTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(auth.ClientId))
- {
- return JsonMsg<LargeScreenTable>.Error(null, st, "设备ID不能为空"); ;
- }
- mg.Insert(auth);
- return JsonMsg<LargeScreenTable>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<LargeScreenTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 批量新增数据
- /// </summary>
- /// <param name="auth">日志消息</param>
- [HttpPost]
- public JsonMsg<List<LargeScreenTable>> Creates(List<LargeScreenTable> auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.Inserts(auth);
- return JsonMsg<List<LargeScreenTable>>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LargeScreenTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 修改数据
- /// </summary>
- /// <param name="auth"></param>
- /// <returns></returns>
- [HttpPost]
- public JsonMsg<LargeScreenTable> Modify(LargeScreenTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.UpdateID(auth);
- return JsonMsg<LargeScreenTable>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<LargeScreenTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据ID查询数据
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<LargeScreenTable> QueryOne(string id)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<LargeScreenTable>.OK(mg.QueryOne(id), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<LargeScreenTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据客户端ID查询当日未处理信息
- /// </summary>
- /// <param name="clientId"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<LargeScreenTable>> QueryClientId(string clientId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<LargeScreenTable>>.OK(mg.QueryClientId(clientId), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LargeScreenTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据设备ID查询当日未处理信息
- /// </summary>
- /// <param name="clientId"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<LargeScreenTable>> QueryDeviceId(string clientId, string deviceId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<LargeScreenTable>>.OK(mg.QueryDeviceId(clientId, deviceId), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LargeScreenTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据设备名称查询当日未处理信息
- /// </summary>
- /// <param name="DeviceName"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<LargeScreenTable>> 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<LargeScreenTable>>.OK(mg.QueryAllTime(device.ClientId, device.DeviceId, starttime, stoptime), st);
- }
- else return JsonMsg<List<LargeScreenTable>>.OK(mg.QueryClientId(device.ClientId), st);
- }
- return JsonMsg<List<LargeScreenTable>>.OK(null, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LargeScreenTable>>.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<LargeScreenTable>> Query(string clientId, string deviceId, DateTime starttime, DateTime endtime)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<LargeScreenTable>>.OK(mg.QueryAllTime(clientId, deviceId, starttime, endtime), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<LargeScreenTable>>.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<LargeScreenTable>> 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<LargeScreenTable>>.OK(mg.BasePagQuery(clientId, deviceId, datesta, datastop, PageNumber, PageSize), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<PaginationListModel<LargeScreenTable>>.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);
- }
- }
- }
- }
|