BLLCore.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using WMS.BZServices.UserCenterManager;
  6. using WMS.Info;
  7. using WMS.Util;
  8. namespace WMS.BZServices
  9. {
  10. public class BZBLLCore
  11. {
  12. const string CacheKeys = "BLLList";
  13. private static IBLL GetBLLObj(string BLLNo, EAppType eAppType)
  14. {
  15. try
  16. {
  17. string ck = CacheKeys + (int)eAppType;
  18. var BLLClassList = new Dictionary<string, Type>();
  19. Assembly asm = Assembly.GetExecutingAssembly();
  20. foreach (var t in asm.GetTypes())
  21. {
  22. if (t.GetInterfaces().Contains(typeof(IBLL)))
  23. {
  24. BLLClassList.Add(GetBLLClassNo(t), t);
  25. }
  26. }
  27. if (!BLLClassList.ContainsKey(BLLNo.ToUpper()))
  28. {
  29. throw new Exception("请求业务不存在。");
  30. }
  31. return Activator.CreateInstance(BLLClassList[BLLNo.ToUpper()]) as IBLL;
  32. }
  33. catch (Exception ex)
  34. {
  35. throw ex;
  36. }
  37. }
  38. public static string GetBLLClassNo(Type T)
  39. {
  40. return (T.Namespace + "." + T.Name).ToUpper();
  41. }
  42. public static string GetBLLClassNo(object obj)
  43. {
  44. return GetBLLClassNo(obj.GetType());
  45. }
  46. public static ResInfo BLLExec(ReqInfo ReqData)
  47. {
  48. var BLLExec = new BZBLLExecInfo();
  49. try
  50. {
  51. if (ReqData == null)
  52. {
  53. throw new Exception("请求数据为空。");
  54. }
  55. if (string.IsNullOrWhiteSpace(ReqData.BLLNo))
  56. {
  57. throw new Exception("请求业务编号为空。");
  58. }
  59. BLLExec.BLLObj = GetBLLObj(ReqData.BLLNo, ReqData.AppType);
  60. BLLExec.BLLObj.InJsonData = ReqData.JsonData;
  61. BLLExec.BLLObj.LoginUser = BZLoginBLLCore.GetLoginUser(ReqData.EncryptTokenNo);
  62. BLLExec.BLLObj.Exec();
  63. //写日志
  64. SysLogService.WriteLog(BLLExec, ELogType.Work);
  65. return BZSysExCore.GetResSucc(BLLExec.BLLObj.SuccessMsg, BLLExec.BLLObj.OutObjData);
  66. }
  67. catch (Exception ex)
  68. {
  69. BLLExec.Ex = ex;
  70. SysLogService.WriteLog(BLLExec, ELogType.Work);
  71. return BZSysExCore.GetResErr(ex, BLLExec.BLLObj == null ? null : BLLExec.BLLObj.OutObjData);
  72. }
  73. }
  74. public static ResInfo BLLExec(LoginUserInfo LoginUser, string InJsonData, string BLLNo, ELogType eLogType)
  75. {
  76. var BLLExec = new BZBLLExecInfo();
  77. try
  78. {
  79. if (string.IsNullOrWhiteSpace(BLLNo))
  80. {
  81. throw BZSysExCore.ThrowFailException("请求业务编号为空。");
  82. }
  83. BLLExec.BLLObj = GetBLLObj(BLLNo, LoginUser.AppType);
  84. BLLExec.BLLObj.InJsonData = InJsonData;
  85. BLLExec.BLLObj.LoginUser = LoginUser;
  86. BLLExec.BLLObj.Exec();
  87. //写日志
  88. SysLogService.WriteLog(BLLExec, eLogType);
  89. return BZSysExCore.GetResSucc(BLLExec.BLLObj.SuccessMsg, BLLExec.BLLObj.OutObjData);
  90. }
  91. catch (Exception ex)
  92. {
  93. BLLExec.Ex = ex;
  94. SysLogService.WriteLog(BLLExec, eLogType);
  95. return BZSysExCore.GetResErr(ex, BLLExec.BLLObj == null ? null : BLLExec.BLLObj.OutObjData);
  96. }
  97. }
  98. }
  99. }