You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
5.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data.Common;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.Json;
  8. using System.Threading.Tasks;
  9. using Dapper;
  10. using Microsoft.Extensions.Configuration;
  11. using Npgsql;
  12. using Shentun.Utilities;
  13. namespace Shentun.Peis.PlugIns
  14. {
  15. public class ColumnReferencePlugInsBase : IColumnReferencePlugIns
  16. {
  17. protected IConfiguration AppConfig;
  18. protected IConfiguration InterfaceConfig;
  19. protected string? ConnctionStr;
  20. protected string AppSql;
  21. private List<ColumnReferenceColumn> _columns;
  22. private List<ColumnReferenceColumn> _interfaceColumns;
  23. public ColumnReferencePlugInsBase(string parmValue)
  24. {
  25. AppConfig = new ConfigurationBuilder()
  26. .SetBasePath(DirectoryHelper.GetAppDirectory()) // 设置基础路径为当前目录
  27. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  28. .Build();
  29. ConnctionStr = AppConfig.GetSection("ConnectionStrings")
  30. .GetSection("Default").Value;
  31. var configurationBuilder = new ConfigurationBuilder()
  32. .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
  33. InterfaceConfig = configurationBuilder.Build();
  34. AppSql = InterfaceConfig.GetSection("App").GetSection("Sql").Value;
  35. var columns = InterfaceConfig.GetSection("App").GetSection("Columns").Value;
  36. string[]? columnArry;
  37. if (columns != null)
  38. {
  39. columns = columns.Replace(",", ",");
  40. columnArry = columns.Split(',');
  41. _columns = new List<ColumnReferenceColumn>();
  42. foreach (var column in columnArry)
  43. {
  44. var singleColumns = column.Split('=');
  45. if (singleColumns.Length == 2)
  46. {
  47. _columns.Add(new ColumnReferenceColumn()
  48. {
  49. Column = singleColumns[0],
  50. Name = singleColumns[1]
  51. });
  52. }
  53. }
  54. }
  55. columns = InterfaceConfig.GetSection("Interface").GetSection("Columns").Value;
  56. if(columns != null)
  57. {
  58. columns = columns.Replace(",", ",");
  59. columnArry = columns.Split(',');
  60. _interfaceColumns = new List<ColumnReferenceColumn>();
  61. foreach (var columnName in columnArry)
  62. {
  63. var singleColumns = columnName.Split('=');
  64. if (singleColumns.Length == 2)
  65. {
  66. _interfaceColumns.Add(new ColumnReferenceColumn()
  67. {
  68. Column = singleColumns[0],
  69. Name = singleColumns[1]
  70. });
  71. }
  72. }
  73. }
  74. }
  75. public virtual List<ColumnReferenceColumn> GetAppColumns()
  76. {
  77. if (_columns == null || _columns.Count() == 0)
  78. {
  79. return new List<ColumnReferenceColumn>()
  80. {
  81. new ColumnReferenceColumn()
  82. {
  83. Column = "Code",
  84. Name = "编码"
  85. },
  86. new ColumnReferenceColumn()
  87. {
  88. Column = "DisplayName",
  89. Name = "名称"
  90. }
  91. };
  92. }
  93. return _columns;
  94. }
  95. public virtual List<ColumnReferenceColumn> GetInterfaceColumns()
  96. {
  97. if (_interfaceColumns == null || _interfaceColumns.Count() == 0)
  98. {
  99. return new List<ColumnReferenceColumn>()
  100. {
  101. new ColumnReferenceColumn()
  102. {
  103. Column = "Code",
  104. Name = "编码"
  105. },
  106. new ColumnReferenceColumn()
  107. {
  108. Column = "DisplayName",
  109. Name = "名称"
  110. }
  111. };
  112. }
  113. return _interfaceColumns;
  114. }
  115. public virtual async Task<List<ColumnReferenceCodeValue>> GetAppCodeValuesAsync()
  116. {
  117. using (DbConnection conn = new NpgsqlConnection(ConnctionStr))
  118. {
  119. var list = (await conn.QueryAsync<ColumnReferenceCodeValue>(AppSql)).ToList();
  120. return list;
  121. }
  122. }
  123. public virtual async Task<List<ColumnReferenceCodeValue>> GetInterfaceCodeValuesAsync()
  124. {
  125. return new List<ColumnReferenceCodeValue>()
  126. {
  127. };
  128. }
  129. public virtual async Task<List<ColumnReferenceFilterCodeValue>> GetAppFilterCodeValuesAsync()
  130. {
  131. throw new NotImplementedException();
  132. }
  133. public virtual string GetAppFilterColumnName()
  134. {
  135. return null;
  136. }
  137. }
  138. }