UserConditionHelper.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using wispro.sp.entity.workflowDefine;
  9. namespace wispro.sp.share.Utility
  10. {
  11. public class UserConditionHelper
  12. {
  13. public static string UserFieldLabel(UserField userField, string bindObjectType)
  14. {
  15. switch (userField.UserConditionType)
  16. {
  17. case UserConditionType.Department:
  18. return $"部门:{userField.Department}";
  19. break;
  20. case UserConditionType.DepartmentPosition:
  21. return $"[部门:{userField.Department}].[职位:{userField.Positon}]";
  22. break;
  23. case UserConditionType.UserDepartment:
  24. switch (userField.UserType)
  25. {
  26. case UserType.BindObjectProperty:
  27. Type t = Type.GetType(bindObjectType);
  28. return $"{ObjectHelper.GetPropertyDescription(userField.UserValue, bindObjectType)}部门";
  29. break;
  30. case UserType.DoActionUser:
  31. return $"[{userField.UserValue}处理人部门]";
  32. break;
  33. case UserType.LoginUser:
  34. return $"[登录用户部门]";
  35. break;
  36. case UserType.Staff:
  37. return $"[{userField.UserValue}部门]";
  38. break;
  39. }
  40. break;
  41. case UserConditionType.UserDepartmentPosition:
  42. switch (userField.UserType)
  43. {
  44. case UserType.BindObjectProperty:
  45. return $"[{ObjectHelper.GetPropertyDescription(userField.UserValue, bindObjectType)}部门职位:{userField.Positon}]";
  46. break;
  47. case UserType.DoActionUser:
  48. return $"[{userField.UserValue}处理人部门职位:{userField.Positon}]";
  49. break;
  50. case UserType.LoginUser:
  51. return $"[登录用户部门职位:{userField.Positon}]";
  52. break;
  53. case UserType.Staff:
  54. break;
  55. }
  56. break;
  57. case UserConditionType.Staff:
  58. switch (userField.UserType)
  59. {
  60. case UserType.BindObjectProperty:
  61. return $"[{ObjectHelper.GetPropertyDescription(userField.UserValue, bindObjectType)}";
  62. break;
  63. case UserType.DoActionUser:
  64. return $"[{userField.UserValue}处理人].[部门].[职位:{userField.Positon}]";
  65. break;
  66. case UserType.LoginUser:
  67. return "登录用户";
  68. break;
  69. case UserType.Staff:
  70. return $"用户:{userField.UserValue}";
  71. break;
  72. }
  73. break;
  74. }
  75. return "";
  76. }
  77. public static Dictionary<string,string> GetPropertyDescription<T>(string stringType)
  78. {
  79. Dictionary<string, string> retDic = new Dictionary<string, string>();
  80. Type type = Type.GetType(stringType);
  81. foreach(var property in type.GetProperties())
  82. {
  83. if(property.PropertyType == typeof(T))
  84. {
  85. DescriptionAttribute att =
  86. property.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute;
  87. if (att == null)
  88. {
  89. retDic.Add(property.Name, property.Name);
  90. }
  91. else
  92. {
  93. retDic.Add(att.Description, property.Name);
  94. }
  95. }
  96. }
  97. return retDic;
  98. }
  99. }
  100. }