RecipeEditHistoryRecorder.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using Aitex.Core.RT.DBCore;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using MECF.Framework.Common.CommonData;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace MECF.Framework.Common.DBCore
  12. {
  13. public class RecipeEditHistoryRecorder
  14. {
  15. public static void SaveRecipeHistory(RecipeHistory recipeHistory)
  16. {
  17. try
  18. {
  19. string guid = Guid.NewGuid().ToString();
  20. string sql = string.Format("INSERT INTO \"Recipe_History\"(\"guid\", \"createdBy\", \"creationTime\",\"lastRevisedBy\", \"lastRevisionTime\", \"recipe_description\", \"recipe_type\", \"recipe_name\", \"recipe_path\", \"recipe_version\", \"recipe_level\", \"recipe_premission\", \"recipe_compare\", \"recipe_content\")VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}');",
  21. guid,
  22. recipeHistory.CreatedBy,
  23. recipeHistory.CreationTime.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  24. recipeHistory.LastRevisedBy,
  25. recipeHistory.LastRevisionTime.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  26. recipeHistory.Recipe_Description,
  27. recipeHistory.Recipe_Type,
  28. recipeHistory.Recipe_Name,
  29. recipeHistory.Recipe_Path,
  30. recipeHistory.Recipe_Version,
  31. recipeHistory.Recipe_Level,
  32. recipeHistory.Recipe_Premission,
  33. recipeHistory.Recipe_Compare,
  34. recipeHistory.Recipe_Content);
  35. DB.Insert(sql);
  36. var saveNumber = SC.GetValue<int>("System.Recipe.RecipeSaveNumber");
  37. ClearByRecipePathHistory(recipeHistory.Recipe_Path, saveNumber);
  38. }
  39. catch (Exception)
  40. {
  41. throw;
  42. }
  43. }
  44. public static List<RecipeHistory> QueryDBRecipeHistory(string sql)
  45. {
  46. List<RecipeHistory> result = new List<RecipeHistory>();
  47. try
  48. {
  49. DataSet ds = DB.ExecuteDataset(sql);
  50. if (ds == null)
  51. return result;
  52. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  53. {
  54. RecipeHistory ev = new RecipeHistory();
  55. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  56. ev.CreatedBy = ds.Tables[0].Rows[i]["createdBy"].ToString();
  57. if (!ds.Tables[0].Rows[i]["creationTime"].Equals(DBNull.Value))
  58. { ev.CreationTime = ((DateTime)ds.Tables[0].Rows[i]["creationTime"]); }
  59. ev.LastRevisedBy = ds.Tables[0].Rows[i]["lastRevisedBy"].ToString();
  60. if (!ds.Tables[0].Rows[i]["lastRevisionTime"].Equals(DBNull.Value))
  61. { ev.LastRevisionTime = ((DateTime)ds.Tables[0].Rows[i]["lastRevisionTime"]); }
  62. ev.Recipe_Description = ds.Tables[0].Rows[i]["recipe_description"].ToString();
  63. ev.Recipe_Type = ds.Tables[0].Rows[i]["recipe_type"].ToString();
  64. ev.Recipe_Name = ds.Tables[0].Rows[i]["recipe_name"].ToString();
  65. ev.Recipe_Path = ds.Tables[0].Rows[i]["recipe_path"].ToString();
  66. ev.Recipe_Compare = ds.Tables[0].Rows[i]["recipe_compare"].ToString();
  67. ev.Recipe_Content = ds.Tables[0].Rows[i]["recipe_content"].ToString();
  68. result.Add(ev);
  69. }
  70. }
  71. catch (Exception ex)
  72. {
  73. LOG.Write(ex);
  74. }
  75. return result;
  76. }
  77. private static List<RecipeHistory> QueryByRecipePath(string sql)
  78. {
  79. List<RecipeHistory> result = new List<RecipeHistory>();
  80. try
  81. {
  82. DataSet ds = DB.ExecuteDataset(sql);
  83. if (ds == null)
  84. return result;
  85. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  86. {
  87. RecipeHistory ev = new RecipeHistory();
  88. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  89. ev.CreatedBy = ds.Tables[0].Rows[i]["createdBy"].ToString();
  90. if (!ds.Tables[0].Rows[i]["creationTime"].Equals(DBNull.Value))
  91. { ev.CreationTime = ((DateTime)ds.Tables[0].Rows[i]["creationTime"]); }
  92. ev.LastRevisedBy = ds.Tables[0].Rows[i]["lastRevisedBy"].ToString();
  93. if (!ds.Tables[0].Rows[i]["lastRevisionTime"].Equals(DBNull.Value))
  94. { ev.LastRevisionTime = ((DateTime)ds.Tables[0].Rows[i]["lastRevisionTime"]); }
  95. ev.Recipe_Description = ds.Tables[0].Rows[i]["recipe_description"].ToString();
  96. ev.Recipe_Type = ds.Tables[0].Rows[i]["recipe_type"].ToString();
  97. ev.Recipe_Name = ds.Tables[0].Rows[i]["recipe_name"].ToString();
  98. ev.Recipe_Path = ds.Tables[0].Rows[i]["recipe_path"].ToString();
  99. ev.Recipe_Level = ds.Tables[0].Rows[i]["recipe_level"].ToString();
  100. ev.Recipe_Version = ds.Tables[0].Rows[i]["recipe_version"].ToString();
  101. ev.Recipe_Premission = ds.Tables[0].Rows[i]["recipe_premission"].ToString();
  102. ev.Recipe_Compare = ds.Tables[0].Rows[i]["recipe_compare"].ToString();
  103. ev.Recipe_Content = ds.Tables[0].Rows[i]["recipe_content"].ToString();
  104. result.Add(ev);
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. LOG.Write(ex);
  110. }
  111. return result;
  112. }
  113. public static List<RecipeHistory> QueryByRecipePathHistory(string RecipePath, DateTime startTime, DateTime endTime, int row = 20)
  114. {
  115. string sql = string.Format("SELECT * FROM \"Recipe_History\" where \"recipe_path\" = '{0}' limit {1};", RecipePath, row);
  116. return QueryByRecipePath(sql);
  117. }
  118. public static List<RecipeHistory> QueryByRecipePathHistory(string RecipePath, int row = 20)
  119. {
  120. string sql = string.Format("SELECT * FROM \"Recipe_History\" where \"recipe_path\" = '{0}' limit {1};", RecipePath, row);
  121. return QueryByRecipePath(sql);
  122. }
  123. public static bool ClearByRecipePathHistory(string RecipePath)
  124. {
  125. return true;
  126. }
  127. public static bool ClearByRecipePathHistory(string RecipePath, DateTime startTime, DateTime endTime)
  128. {
  129. return true;
  130. }
  131. /// <summary>
  132. /// 根据RecipePath删除记录
  133. /// </summary>
  134. /// <param name="RecipePath">查询路径</param>
  135. /// <param name="saveNumber">删除后保留记录条数</param>
  136. /// <returns>删除是否成功</returns>
  137. public static bool ClearByRecipePathHistory(string RecipePath, int saveNumber)
  138. {
  139. try
  140. {
  141. List<RecipeHistory> result = new List<RecipeHistory>();
  142. string sql = string.Format("SELECT * FROM \"Recipe_History\" where \"recipe_path\" = '{0}' order by \"creationTime\" ASC;", RecipePath);
  143. DataSet ds = DB.ExecuteDataset(sql);
  144. if (ds == null)
  145. return true;
  146. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  147. {
  148. RecipeHistory ev = new RecipeHistory();
  149. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  150. ev.CreatedBy = ds.Tables[0].Rows[i]["createdBy"].ToString();
  151. if (!ds.Tables[0].Rows[i]["creationTime"].Equals(DBNull.Value))
  152. { ev.CreationTime = ((DateTime)ds.Tables[0].Rows[i]["creationTime"]); }
  153. ev.LastRevisedBy = ds.Tables[0].Rows[i]["lastRevisedBy"].ToString();
  154. if (!ds.Tables[0].Rows[i]["lastRevisionTime"].Equals(DBNull.Value))
  155. { ev.LastRevisionTime = ((DateTime)ds.Tables[0].Rows[i]["lastRevisionTime"]); }
  156. ev.Recipe_Description = ds.Tables[0].Rows[i]["recipe_description"].ToString();
  157. ev.Recipe_Type = ds.Tables[0].Rows[i]["recipe_type"].ToString();
  158. ev.Recipe_Name = ds.Tables[0].Rows[i]["recipe_name"].ToString();
  159. ev.Recipe_Path = ds.Tables[0].Rows[i]["recipe_path"].ToString();
  160. ev.Recipe_Level = ds.Tables[0].Rows[i]["recipe_level"].ToString();
  161. ev.Recipe_Version = ds.Tables[0].Rows[i]["recipe_version"].ToString();
  162. ev.Recipe_Premission = ds.Tables[0].Rows[i]["recipe_premission"].ToString();
  163. ev.Recipe_Compare = ds.Tables[0].Rows[i]["recipe_compare"].ToString();
  164. ev.Recipe_Content = ds.Tables[0].Rows[i]["recipe_content"].ToString();
  165. result.Add(ev);
  166. }
  167. if (result.Count > saveNumber)
  168. {
  169. for (int i = 0; i < result.Count - saveNumber; i++)
  170. {
  171. string sql1 = string.Format("Delete FROM \"Recipe_History\" where \"guid\" = '{0}'", result[i].Guid);
  172. DB.ExecuteNonQuery(sql1);
  173. }
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. LOG.Write(ex);
  179. }
  180. return true;
  181. }
  182. }
  183. }