ExpressionEvaluator.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Variables;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace PTMedicalInsurance.Common
  9. {
  10. class ExpressionEvaluator
  11. {
  12. /// <summary>
  13. /// 将long转为yyyy-MM-dd
  14. /// </summary>
  15. /// <param name="timestamp"></param>
  16. /// <returns></returns>
  17. public static string LongToDate(object timestamp)
  18. {
  19. string strValue = timestamp?.ToString();
  20. return Utils.ConvertLongToDate(strValue);
  21. }
  22. /// <summary>
  23. /// 标准化为yyyy-MM-dd
  24. /// </summary>
  25. /// <param name="dateTime"></param>
  26. /// <returns></returns>
  27. public static string ShortDate(object dateTime)
  28. {
  29. string strValue = (dateTime??"").ToString();
  30. return Utils.ConvertShortDate(strValue);
  31. }
  32. /// <summary>
  33. /// 保存到扩展节点
  34. /// </summary>
  35. /// <param name="dateTime"></param>
  36. /// <returns></returns>
  37. public static void SaveToExpand(string key,object value)
  38. {
  39. if (key == null) return;
  40. Utils.ExpandData(key, value);
  41. }
  42. /// <summary>
  43. /// 获取全局变量
  44. /// </summary>
  45. /// <param name="value"></param>
  46. /// <returns></returns>
  47. public static string GlobaVariables(object value)
  48. {
  49. string key = value?.ToString();
  50. if (key!=null && key.StartsWith("Global_"))
  51. {
  52. string varKey = key.Replace("Global_","");
  53. switch (varKey)
  54. {
  55. case "mdtrtid":
  56. return Global.pat.mdtrtID;
  57. case "gender":
  58. return Global.pat.gend;
  59. case "name":
  60. return Global.pat.name;
  61. case "psn":
  62. return Global.pat.psn_no;
  63. case "birthday":
  64. return Global.pat.brdy;
  65. case "age":
  66. return Global.pat.age;
  67. case "insutype":
  68. return Global.pat.insuType;
  69. case "medtype":
  70. return Global.pat.medType;
  71. case "clearway":
  72. return Global.Set.clearingWay;
  73. case "insuplc":
  74. return Utils.GetInsuCode();
  75. case "mdtrtarea":
  76. return Global.pat.mdtrtarea_admvs;
  77. case "ectoken":
  78. return Global.pat.ecToken;
  79. default:
  80. return string.Empty;
  81. }
  82. }
  83. return string.Empty;
  84. }
  85. /// <summary>
  86. /// 动态表达式
  87. /// </summary>
  88. /// <param name="person"></param>
  89. /// <param name="expression"></param>
  90. /// <returns></returns>
  91. public object Run(string data, string expression)
  92. {
  93. //var options = ScriptOptions.Default
  94. // .AddReferences(typeof(string).Assembly)
  95. // .AddImports("System");
  96. //try
  97. //{
  98. // return CSharpScript.EvaluateAsync(expression, options, person).Result;
  99. //}
  100. //catch (CompilationErrorException e)
  101. //{
  102. // throw new InvalidOperationException("Compilation error: " + e.Diagnostics, e);
  103. //}
  104. return null;
  105. }
  106. }
  107. }