您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

72 行
2.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace DataVAPI.Model
  7. {
  8. /// <summary>
  9. /// 返回消息
  10. /// </summary>
  11. public class JsonMsg<T> where T : class
  12. {
  13. /// <summary>
  14. /// 状态码
  15. /// </summary>
  16. public int code { get; set; }
  17. /// <summary>
  18. /// 消息
  19. /// </summary>
  20. public string msg { get; set; }
  21. /// <summary>
  22. /// 描述
  23. /// </summary>
  24. public string ms { get; set; }
  25. /// <summary>
  26. /// 内容
  27. /// </summary>
  28. public IOTData<T> obj { get; set; }
  29. ///// <summary>
  30. ///// 返回数据
  31. ///// </summary>
  32. //public IOTData<T> oTData { get; set; }
  33. /// <summary>
  34. /// 图标
  35. /// </summary>
  36. public int icon { get; set; }
  37. public static JsonMsg<T> OK(T obj, string msg = "接口名称", string mso = "调用接口成功")
  38. {
  39. string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用成功,描述:" + mso + obj}";
  40. ConsoleColor currentForeColor = Console.ForegroundColor;
  41. Console.ForegroundColor = ConsoleColor.Green;
  42. Console.WriteLine(str);
  43. Console.ForegroundColor = currentForeColor;
  44. ;
  45. return new JsonMsg<T>() { code = 1, ms = mso, msg = "成功", obj = new IOTData<T> { data = obj }, icon = 1};
  46. }
  47. public static JsonMsg<T> Error(T obj, string msg = "接口名称", string mso = "调用接口成功失败")
  48. {
  49. string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用失败,描述:" + mso + obj}";
  50. ConsoleColor currentForeColor = Console.ForegroundColor;
  51. Console.ForegroundColor = ConsoleColor.Red;
  52. Console.WriteLine(str);
  53. Console.ForegroundColor = currentForeColor;
  54. return new JsonMsg<T>() { code = 0, ms = mso, msg = "失败",icon = 1, obj = new IOTData<T> { data = obj } };
  55. }
  56. }
  57. public class IOTData<T> where T : class
  58. {
  59. public T data { get; set; }
  60. }
  61. }