|
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using 服务API.Model;
- using 服务API.ServerDB.MongoDB;
-
- namespace 服务API.Controllers
- {
- /// <summary>
- /// MG数据库:大屏信息表 ScreenController
- /// </summary>
- public class ScreenController :BaseController
- {
- MongoDbHelper<LargeScreenTable> mg = new MongoDbHelper<LargeScreenTable>(DataBus.DataBus.connStr,DataBus.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.IdStr = largeScreen.IdStr;
- largeScreenTable.Id = largeScreen.Id;
- mg.UpdateID(largeScreenTable);
- }
- else
- {
- mg.Insert(largeScreenTable);
- }
- return JsonMsg<LargeScreenTable>.OK(largeScreenTable,st);
- }
- catch (System.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 (System.Exception ex)
- {
- return JsonMsg<LargeScreenTable>.Error(null,st,ex.Message);
- }
- }
- /// <summary>
- /// 批量新增一条数据
- /// </summary>
- [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 (System.Exception ex)
- {
- return JsonMsg<List<LargeScreenTable>>.Error(null,st,ex.Message);
- }
- }
- /// <summary>
- /// 修改数据
- /// </summary>
- [HttpPost]
- public JsonMsg<LargeScreenTable> Modify(LargeScreenTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.UpdateID(auth);
- return JsonMsg<LargeScreenTable>.OK(auth,st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<LargeScreenTable>.Error(null,st,ex.Message);
- }
- }
- /// <summary>
- /// 根据唯一ID查询数据
- /// </summary>
- /// <param name="id">唯一ID</param>
- [HttpGet]
- public JsonMsg<LargeScreenTable> QueryOne(string id)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<LargeScreenTable>.OK(mg.QueryOne(id),st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<LargeScreenTable>.Error(null,st,ex.Message);
- }
- }
- /// <summary>
- /// 根据客户端ID 时间查询大屏信息
- /// </summary>
- /// <param name="clientId">客户端ID</param>
- /// <param name="starttime">开始时间</param>
- /// <param name="endtime">结束时间</param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<LargeScreenTable>> Query(string clientId,DateTime starttime,DateTime endtime)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<LargeScreenTable>>.OK(mg.QueryAllTime(clientId,starttime,endtime),st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<List<LargeScreenTable>>.Error(null,st,ex.Message);
- }
- }
- /// <summary>
- /// 分页查询
- /// </summary>
- /// <param name="clientId">客户端ID</param>
- /// <param name="starttime">开始时间</param>
- /// <param name="endtime">结束时间</param>
- /// <param name="PageNumber">页码</param>
- /// <param name="PageSize">每页大小</param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<PaginationListModel<LargeScreenTable>> BasePagQuery(string clientId,DateTime starttime,DateTime endtime,int PageNumber = 1,int PageSize = 100)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<PaginationListModel<LargeScreenTable>>.OK(mg.BasePagQuery(clientId,starttime,endtime,PageNumber,PageSize),st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<PaginationListModel<LargeScreenTable>>.Error(null,st,ex.Message);
- }
- }
- /// <summary>
- /// 根据设备名称查询当
- /// </summary>
- /// <param name="DeviceName"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<LargeScreenTable> QueryDeviceName(string DeviceName)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(DeviceName))
- {
- return JsonMsg<LargeScreenTable>.Error(null,st,"设备名称不能为空"); ;
- }
- return JsonMsg<LargeScreenTable>.OK(mg.QueryDeviceName(DeviceName),st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<LargeScreenTable>.Error(null,st,ex.Message);
- }
- }
- /// <summary>
- /// 删除数据(假删除-只做标记)
- /// </summary>
- /// <param name="id">唯一id</param>
- [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 (System.Exception ex)
- {
- return JsonMsg<string>.Error(null,st,ex.Message);
- }
- }
- /// <summary>
- /// 删除数据
- /// </summary>
- /// <param name="id">唯一id</param>
- [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 (System.Exception ex)
- {
- return JsonMsg<string>.Error(null,st,ex.Message);
- }
- }
- }
- }
|