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