HelperBase.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using JLHHJSvr.LJException;
  2. using JLHHJSvr.LJFramework.Tools;
  3. using LJLib.InstallHelper;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Runtime.CompilerServices;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace JLHHJSvr.BLL
  13. {
  14. internal abstract class HelperBase
  15. {
  16. /// <summary>
  17. /// 数据库连接
  18. /// </summary>
  19. public SqlCommand cmd { get; set; }
  20. /// <summary>
  21. /// ERP数据库连接
  22. /// </summary>
  23. public SqlCommand erp_cmd { get; set; }
  24. /// <summary>
  25. /// 预留的上下文
  26. /// </summary>
  27. public Context context { get; set; }
  28. public static T GetHelper<T>(SqlCommand cmd, Context context = null) where T : HelperBase, new()
  29. {
  30. var rslt = new T();
  31. rslt.cmd = cmd;
  32. rslt.context = context ?? new Context();
  33. return rslt;
  34. }
  35. public static T GetHelper<T>(SqlCommand cmd, SqlCommand erp_cmd,Context context = null) where T : HelperBase, new()
  36. {
  37. var rslt = new T();
  38. rslt.cmd = cmd;
  39. rslt.erp_cmd = erp_cmd;
  40. rslt.context = context ?? new Context();
  41. return rslt;
  42. }
  43. public JObject DoExecute(string apiName, JObject request)
  44. {
  45. var url = GlobalVar.ERP_API_URL + "/api/common/" + apiName;
  46. if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
  47. {
  48. url = "https://" + url;
  49. }
  50. var rslt = LJHttpUtil.PostRequest(url, request);
  51. var errMsg = rslt.GetValue("ErrMsg");
  52. if (errMsg != null && !string.IsNullOrEmpty(errMsg.ToString()))
  53. {
  54. throw new LJCommonException(errMsg.ToString());
  55. }
  56. return rslt;
  57. }
  58. public sealed class Context
  59. {
  60. private DateTime _opdate = DateTime.Now;
  61. public DateTime opdate
  62. {
  63. get { return _opdate; }
  64. set { _opdate = value; }
  65. }
  66. /// <summary>
  67. /// 用户登陆信息
  68. /// </summary>
  69. public TokenData tokendata { get; set; }
  70. }
  71. }
  72. }