Utils.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.Json;
  5. namespace AI.Platform.Page.Pages.Media
  6. {
  7. public class Utils
  8. {
  9. private static Dictionary<string, string> _StateDic = new Dictionary<string, string>()
  10. {
  11. { "idle","空闲" },{ "lock","锁枪" },{ "offline","脱机" },{ "lift","提枪" },{ "authorised","授权" },{ "start","开始" },{ "fueling","加油中" }
  12. };
  13. /// <summary>
  14. /// 根据数据库中的油枪状态json转中文拼接
  15. /// </summary>
  16. /// <param name="jsonStr"></param>
  17. /// <returns></returns>
  18. public static string MachineStateJsonToString(string jsonStr)
  19. {
  20. List<string>? list = JsonSerializer.Deserialize<List<string>>(jsonStr);
  21. if (list == null || list.Count == 0) return "";
  22. var result = "";
  23. foreach(string item in list)
  24. {
  25. string? state = _StateDic.GetValueOrDefault(item);
  26. if (state == null || state.Length == 0) continue;
  27. result += state + ",";
  28. }
  29. return result.Remove(result.Length - 1);
  30. }
  31. public static string JoinDateTime(DateTime start,DateTime end)
  32. {
  33. return $"{start}-{end}";
  34. }
  35. }
  36. }