|
- using DataVAPI.Model;
- using DataVAPI.ModelDataBus;
- using DataVAPI.ServerDB.MongoDB;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- namespace DataVAPI.Controllers
- {
- /// <summary>
- /// MG数据库:设备信息表 DeviceTable
- /// </summary>
- public class DeviceController : BaseController
- {
- MongoDbHelper<DeviceTable> mg = new MongoDbHelper<DeviceTable>(DataBus.connStr, DataBus.dbName);
-
- string st = System.Reflection.MethodBase.GetCurrentMethod().Name;
-
- /// <summary>
- /// 新增一条数据
- /// </summary>
- [HttpPost]
- public JsonMsg<DeviceTable> Create(DeviceTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- if (string.IsNullOrEmpty(auth.ClientId))
- {
- return JsonMsg<DeviceTable>.Error(null, st, "设备ID不能为空"); ;
- }
- mg.Insert(auth);
- return JsonMsg<DeviceTable>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<DeviceTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 批量新增N条数据
- /// </summary>
- [HttpPost]
- public JsonMsg<List<DeviceTable>> Creates(List<DeviceTable> auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.Inserts(auth);
- return JsonMsg<List<DeviceTable>>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<DeviceTable>>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 修改数据:IdStr不能为空
- /// </summary>
- [HttpPost]
- public JsonMsg<DeviceTable> Modify(DeviceTable auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- mg.UpdateID(auth);
- return JsonMsg<DeviceTable>.OK(auth, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<DeviceTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据ID查询数据
- /// </summary>
- /// <param name="id">ID</param>
- [HttpGet]
- public JsonMsg<DeviceTable> QueryOne(string id)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<DeviceTable>.OK(mg.QueryOne(id), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<DeviceTable>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 根据设备名称查询数据
- /// </summary>
- /// <param name="id">ID</param>
- [HttpGet]
- public JsonMsg<DeviceTable> QueryDeviceName(string DeviceName)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- DeviceTable device = mg.QueryDeviceName(DeviceName);
- return JsonMsg<DeviceTable>.OK(device, st);
- }
- catch (Exception ex)
- {
- return JsonMsg<DeviceTable>.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<DeviceTable>> Query(string clientId, string deviceId, DateTime starttime, DateTime endtime)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<List<DeviceTable>>.OK(mg.QueryAllTime(clientId, deviceId, starttime, endtime), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<List<DeviceTable>>.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<DeviceTable>> BasePagQuery(string clientId, string deviceId, DateTime starttime, DateTime endtime, int PageNumber = 1, int PageSize = 100)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- return JsonMsg<PaginationListModel<DeviceTable>>.OK(mg.BasePagQuery(clientId, deviceId, starttime, endtime, PageNumber, PageSize), st);
- }
- catch (Exception ex)
- {
- return JsonMsg<PaginationListModel<DeviceTable>>.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 (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 (Exception ex)
- {
- return JsonMsg<string>.Error(null, st, ex.Message);
- }
- }
- }
- }
|