|
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace DataVAPI.Model
- {
- /// <summary>
- /// 返回消息
- /// </summary>
- public class JsonMsg<T> where T : class
- {
- /// <summary>
- /// 状态码
- /// </summary>
- public int code { get; set; }
-
- /// <summary>
- /// 消息
- /// </summary>
- public string msg { get; set; }
-
- /// <summary>
- /// 描述
- /// </summary>
- public string ms { get; set; }
-
- /// <summary>
- /// 内容
- /// </summary>
- public IOTData<T> obj { get; set; }
-
- ///// <summary>
- ///// 返回数据
- ///// </summary>
- //public IOTData<T> oTData { get; set; }
-
- /// <summary>
- /// 图标
- /// </summary>
- public int icon { get; set; }
-
-
- public static JsonMsg<T> OK(T obj, string msg = "接口名称", string mso = "调用接口成功")
- {
- string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用成功,描述:" + mso + JsonConvert.SerializeObject(obj)}";
- ConsoleColor currentForeColor = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(str);
- Console.ForegroundColor = currentForeColor;
- return new JsonMsg<T>() { code = 1, ms = mso, msg = "成功", obj = new IOTData<T> { data = obj }, icon = 1};
- }
-
- public static JsonMsg<T> Error(T obj, string msg = "接口名称", string mso = "调用接口成功失败")
- {
- string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用失败,描述:" + mso + JsonConvert.SerializeObject(obj)}";
- ConsoleColor currentForeColor = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(str);
- Console.ForegroundColor = currentForeColor;
- return new JsonMsg<T>() { code = 0, ms = mso, msg = "失败",icon = 1, obj = new IOTData<T> { data = obj } };
- }
- }
-
- public class IOTData<T> where T : class
- {
- public T data { get; set; }
- }
- }
|