HelperBase.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 = "http://127.0.0.1:" + GlobalVar.ERP_HTTPPort + "/api/common/" + apiName;
  46. var rslt = LJHttpUtil.PostRequest(url, request);
  47. var errMsg = rslt.GetValue("ErrMsg");
  48. if (errMsg != null && !string.IsNullOrEmpty(errMsg.ToString()))
  49. {
  50. throw new LJCommonException(errMsg.ToString());
  51. }
  52. return rslt;
  53. }
  54. public sealed class Context
  55. {
  56. private DateTime _opdate = DateTime.Now;
  57. public DateTime opdate
  58. {
  59. get { return _opdate; }
  60. set { _opdate = value; }
  61. }
  62. /// <summary>
  63. /// 用户登陆信息
  64. /// </summary>
  65. public TokenData tokendata { get; set; }
  66. }
  67. }
  68. }