Knowledge.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using Abp;
  2. using Castle.MicroKernel.Registration;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Reflection.Metadata;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Web;
  11. namespace DataTransmission.Joint
  12. {
  13. public class Knowledge
  14. {
  15. private readonly CommonTool tool = new CommonTool();
  16. public DataTable GetKnowledge(string st_time, string end_time) {
  17. var conn = tool.GetConSqlServer();
  18. var sql = $@"SELECT HR.*,HC.* FROM dbo.SYS22_HelpRecord HR
  19. LEFT JOIN dbo.SYS23_HelpContent HC ON HR.SHR_ID =HC.SHC_SRID
  20. WHERE SHR_AuditFlag =2 AND HR.SHR_DelFlag = 0 ";
  21. //HR.SHR_Date >= '{st_time}' AND HR.SHR_Date <= '{end_time}' AND
  22. return tool.GetDataTable(sql, conn);
  23. }
  24. public string GetKnowledgeSql(DataRow item)
  25. {
  26. DataTable kType = GetKnowledgeType();
  27. DataTable pgType = GetPgKnowledgeType();
  28. //var num = 0;
  29. //foreach (DataRow item in table.Rows)
  30. //{
  31. var knowledgeSql = $@"INSERT INTO ""public"".""knowledge"" (""Id"", ""HotspotId"", ""Code"", ""Title"", ""Summary"", ""Content"", ""PageView"", ""IsPublic"",
  32. ""Status"", ""OnShelfTime"", ""OffShelfTime"", ""ExpiredTime"", ""Version"", ""HotspotExternal"", ""Additions"", ""Knowledges"",
  33. ""WorkflowId"",""ExpiredTimeConfigId"", ""LastModificationTime"", ""IsDeleted"", ""DeletionTime"", ""CreationTime"", ""CreatorOrgId"", ""CreatorId"",
  34. ""AreaId"",""CreatorOrgName"", ""CreatorName"", ""FlowedOrgIds"", ""FlowedUserIds"", ""CreatorOrgLevel"", ""Attribution"", ""SearchNum"",
  35. ""Score"", ""CommentNum"",""SourceOrganizeId"", ""Keywords"", ""FileJson"", ""Renewaln"", ""HandlerUsers"", ""HandlerOrgs"") VALUES";
  36. var pgConn = tool.GetConPgSql();
  37. var pgKnowledge = tool.GetDataTable($@" SELECT * from knowledge where ""Code"" ='{item["SHR_ID"]}' ", pgConn);
  38. var Content = item["SHC_TCONTENT"] == null ? "" : item["SHC_TCONTENT"];
  39. var IsPublic = item["SHR_Public"].ToString() == "0" ? "f" : "t";
  40. var KnowledgeId = SequentialGuidGenerator.Instance.Create().ToString("D");
  41. var code = item["SHR_ID"].ToString();
  42. if (pgKnowledge != null && pgKnowledge.Rows.Count > 0)
  43. {
  44. //num++;
  45. //continue;
  46. return string.Empty;
  47. }
  48. //if (num == 0)
  49. //{
  50. knowledgeSql += $@"('{KnowledgeId}', '', '{code}', '{item["SHR_Title"]}', NULL, '{Content}', 0, '{IsPublic}',
  51. 3, '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}',NULL, NULL, 0, '', NULL, '[]',
  52. NULL, NULL, '2024-03-08 16:38:10.896183', 'f', NULL, '2024-03-07 16:18:28.240546', '001', '08dbba85-02b4-4c0d-83e9-a6e35977c105',
  53. '001','热线中心', '', '[]', '[]', 1, '中心知识库', 0,
  54. '0', 0, '001', '[]', NULL, 'f', '[]', '[]')
  55. ";
  56. // num++;
  57. // //continue;
  58. //}
  59. //knowledgeSql += $@",('{KnowledgeId}', '', '{code}', '{item["SHR_Title"]}', NULL, '{Content}', 0, '{IsPublic}',
  60. // 3, '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}',NULL, NULL, 0, '', NULL, '[]',
  61. // NULL, NULL, '2024-03-08 16:38:10.896183', 'f', NULL, '2024-03-07 16:18:28.240546', '001', '08dbba85-02b4-4c0d-83e9-a6e35977c105',
  62. // '001','市民热线服务系统', '', '[]', '[]', 1, '中心知识库', 0,
  63. // '0', 0, '001', '[]', NULL, 'f', '[]', '[]',
  64. // '[{{""Key"":""{typeId}"",""Value"":""{typeName}"",""Splice"":""{spliceName}""}}]')";
  65. //num++;
  66. //}
  67. knowledgeSql += ";";
  68. var typeT = kType.AsEnumerable().Where(x => x.Field<Int32>("SDICT_ID").ToString() == item["SHR_DictCode"].ToString());
  69. DataTable pgTypeNew = new DataTable();
  70. var typeName = string.Empty;
  71. var spliceName = string.Empty;
  72. Content = HttpUtility.HtmlDecode(Content.ToString());
  73. Content = HttpUtility.HtmlDecode(Content.ToString().Replace("&lt;", "<").Replace("&gt;", ">"));
  74. if (typeT.Any())
  75. {
  76. var typeTable = kType.AsEnumerable().Where(x => x.Field<Int32>("SDICT_ID").ToString() == item["SHR_DictCode"].ToString()).CopyToDataTable();
  77. DataRow typeRow = typeTable.Rows[0];
  78. spliceName = GetTypeSpliceName2(kType, typeRow["SDICT_Name"].ToString(), typeRow);
  79. typeName = typeRow["SDICT_Name"].ToString();
  80. pgTypeNew = GetPgKnowledgeType(spliceName);
  81. var KnowledgeTypeId = SequentialGuidGenerator.Instance.Create().ToString("D");
  82. var typeId = pgTypeNew.Rows.Count > 0 ? pgTypeNew.Rows[0]["Id"].ToString() : "";
  83. var sql = $@"INSERT INTO ""public"".""knowledge_relation_type"" (""KnowledgeId"", ""KnowledgeTypeId"", ""KnowledgeTypeName"", ""KnowledgeTypeSpliceName"")
  84. VALUES ('{KnowledgeId}', '{KnowledgeTypeId}', '{typeName}', '{spliceName}');";
  85. knowledgeSql += sql;
  86. }
  87. return knowledgeSql += ";";
  88. }
  89. public DataTable GetKnowledgeType() {
  90. var conn = tool.GetConSqlServer();
  91. var sql = $@"SELECT *,'' AS NewTypeId FROM dbo.SYS15_DICT WHERE SDICT_Type =3 AND SDICT_Key ='Lore' AND SDICT_PID !=0 ";
  92. return tool.GetDataTable(sql,conn);
  93. }
  94. public string GetKnowledgeTypeSql()
  95. {
  96. var data = GetKnowledgeType();
  97. //var sql = $@"INSERT INTO ""public"".""knowledge_type"" (""Id"", ""Name"", ""SpliceName"", ""IsEnable"", ""Sort"", ""ParentId"", ""LastModificationTime"", ""IsDeleted"",
  98. // ""DeletionTime"", ""CreationTime"", ""CreatorOrgId"", ""CreatorId"", ""AreaId"", ""CreatorOrgName"", ""CreatorName"", ""CreatorOrgLevel"") VALUES ";
  99. var sql = $@"INSERT INTO ""public"".""knowledge_type"" (""Id"", ""Name"", ""SpliceName"", ""IsEnable"", ""Sort"", ""ParentId"", ""LastModificationTime"", ""IsDeleted"",
  100. ""DeletionTime"", ""CreationTime"", ""CreatorOrgId"", ""CreatorId"", ""AreaId"", ""CreatorOrgName"", ""CreatorName"", ""CreatorOrgLevel"",""OldTypeId"") VALUES ";
  101. var num = 0;
  102. foreach (DataRow row in data.Rows)
  103. {
  104. row["NewTypeId"] = SequentialGuidGenerator.Instance.Create().ToString("D");
  105. }
  106. foreach (DataRow item in data.Rows)
  107. {
  108. var pgConn = tool.GetConPgSql();
  109. var spliceName = GetTypeSpliceName2(data, item["SDICT_Name"].ToString(), item);
  110. //var pgType = tool.GetDataTable($@" SELECT * FROM knowledge_type WHERE ""Name""='{item["SDICT_Name"]}' and ""SpliceName"" = '{spliceName}' ", pgConn);
  111. //if (pgType != null && pgType.Rows.Count > 0)
  112. //{
  113. // continue;
  114. //}
  115. DataRow pRow = data.AsEnumerable().FirstOrDefault(x => x.Field<int>("SDICT_ID") == int.Parse(item["SDICT_PID"].ToString()));
  116. var pid = int.Parse(item["SDICT_PID"].ToString()) == 85 || pRow == null ? "NULL" : $@"'{pRow["NewTypeId"]}'";
  117. if (num == 0)
  118. {
  119. //sql += $@"('{item["NewTypeId"]}', '{item["SDICT_Name"]}', '{spliceName}', 't', 0, {pid}, NULL, 'f', NULL, '2023-11-14 11:14:51.320991', '001', '08daa5f2-1878-4cfa-8764-1244f0229994',
  120. // '001', '12345政务服务便民热线', '初始系统管理账号', 1)";
  121. sql += $@"('{item["NewTypeId"]}', '{item["SDICT_Name"]}', '{spliceName}', 't', {item["SDICT_OrderID"]}, {pid}, NULL, 'f', NULL, '2023-11-14 11:14:51.320991', '001', '08daa5f2-1878-4cfa-8764-1244f0229994',
  122. '001', '热线中心', '初始系统管理账号', 1,'{item["SDICT_ID"]}')";
  123. num++;
  124. continue;
  125. }
  126. //sql += $@",('{item["NewTypeId"]}', '{item["SDICT_Name"]}', '{spliceName}', 't', 0, {pid}, NULL, 'f', NULL, '2023-11-14 11:14:51.320991', '001', '08daa5f2-1878-4cfa-8764-1244f0229994',
  127. // '001', '12345政务服务便民热线', '初始系统管理账号', 1)";
  128. sql += $@",('{item["NewTypeId"]}', '{item["SDICT_Name"]}', '{spliceName}', 't', {item["SDICT_OrderID"]}, {pid}, NULL, 'f', NULL, '2023-11-14 11:14:51.320991', '001', '08daa5f2-1878-4cfa-8764-1244f0229994',
  129. '001', '热线中心', '初始系统管理账号', 1,'{item["SDICT_ID"]}')";
  130. num++;
  131. }
  132. return sql + ";";
  133. }
  134. public string GetTypeSpliceName(DataTable data , string spliceName,DataRow row)
  135. {
  136. if (int.Parse(row["SDICT_PID"].ToString()) != 85) {
  137. DataRow pRow = data.AsEnumerable().FirstOrDefault(x => x.Field<int>("SDICT_ID") == int.Parse(row["SDICT_PID"].ToString()));
  138. if (pRow != null)
  139. {
  140. spliceName += "-" + pRow["SDICT_Name"].ToString();
  141. if (int.Parse(pRow["SDICT_PID"].ToString()) > 0)
  142. {
  143. spliceName = GetTypeSpliceName(data, spliceName, pRow);
  144. }
  145. }
  146. }
  147. return spliceName;
  148. }
  149. public string GetTypeSpliceName2(DataTable data, string spliceName, DataRow row)
  150. {
  151. if (int.Parse(row["SDICT_PID"].ToString()) != 85)
  152. {
  153. DataRow pRow = data.AsEnumerable().FirstOrDefault(x => x.Field<int>("SDICT_ID") == int.Parse(row["SDICT_PID"].ToString()));
  154. if (pRow != null)
  155. {
  156. spliceName = pRow["SDICT_Name"].ToString() + "-" + spliceName;
  157. if (int.Parse(pRow["SDICT_PID"].ToString()) > 0)
  158. {
  159. spliceName = GetTypeSpliceName2(data, spliceName, pRow);
  160. }
  161. }
  162. }
  163. return spliceName;
  164. }
  165. public DataTable GetPgKnowledgeType(string spliceName ="")
  166. {
  167. var conn = tool.GetConPgSql();
  168. var sql = $@"SELECT * from knowledge_type ";
  169. if (!string.IsNullOrEmpty(spliceName)) sql = $@"SELECT * from knowledge_type where ""SpliceName"" ='{spliceName}' ";
  170. return tool.GetDataTable(sql, conn);
  171. }
  172. public DataTable GetPgHotspot(string fullName = "")
  173. {
  174. var conn = tool.GetConPgSql();
  175. var sql = $@"SELECT * from hotspot ";
  176. if (!string.IsNullOrEmpty(fullName)) sql = $@"SELECT * from hotspot WHERE ""HotSpotFullName"" ='{fullName}' ";
  177. return tool.GetDataTable(sql, conn);
  178. }
  179. public string GetTypeSpliceName(string id)
  180. {
  181. var name = string.Empty;
  182. var conn = tool.GetConSqlServer();
  183. var sql = $@" SELECT * FROM dbo.fn_GetDICTParentIDName({id}) WHERE ParentID != 0 ORDER BY ID ";
  184. var data = tool.GetDataTable(sql, conn);
  185. var num = 0;
  186. if (data != null && data.Rows.Count > 0)
  187. {
  188. foreach (DataRow item in data.Rows )
  189. {
  190. if (num == 0)
  191. {
  192. name += item["Name"].ToString();
  193. num++;
  194. continue;
  195. }
  196. name += "-"+ item["Name"].ToString();
  197. }
  198. }
  199. return name;
  200. }
  201. }
  202. }