using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.MECF.Framework.Common.Utilities; using MECF.Framework.Common.Utilities; using System; using System.Collections.Generic; namespace MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel { public class RecipeHistory { /// /// GUID编号 /// public string StrGuid { get; set; } /// /// 登录的用户名 /// public string RoleName { get; set; } /// /// Recipe类型 /// public string ProcessType { get; set; } /// /// 快照时Recipe名称 /// public string RecipeName { get; set; } /// /// 从XML转成string类型的Recipe内容 /// public string RecipeFromXML { get; set; } /// /// Recipe使用GZip压缩 /// private string RecipeGZip; /// /// Recipe内容压缩后转成哈希值 /// public string HashCode { get; set; } /// /// 保存Receip时记录时间 /// public string CreateTime { get; set; } /// /// 预留空白1,默认为null /// public string Spare1 { get; set; } /// /// 预留空白2,默认为null /// public string Spare2 { get; set; } #region 数据库操作 public bool SaveDB() { //只有存储时,才自动给这些属性赋值 CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); StrGuid = Guid.NewGuid().ToString(); HashCode = Sha256.EncodeString(RecipeFromXML); RecipeGZip = StringGZip.CompressString(RecipeFromXML); return QueryDataClient.Instance.Service.ExcuteTransAction(new List { SaveCmd() }); } /// /// 根据Recipe名称,返回此名称产生的所有历史记录 /// /// /// public List QueryDB(string recipeName) { string cmd = $"select * from recipe_history_data where recipe_name = '{recipeName}'"; var dt = QueryDataClient.Instance.Service.QueryData(cmd); if (dt != null && dt.Rows.Count > 0) { List recipeMemories = new List(); for (int i = 0; i < dt.Rows.Count; i++) { recipeMemories.Add(new RecipeHistory() { StrGuid = dt.Rows[i]["str_guid"].ToString(), RoleName = dt.Rows[i]["role_name"].ToString(), ProcessType = dt.Rows[i]["process_type"].ToString(), RecipeName = dt.Rows[i]["recipe_name"].ToString(), HashCode = dt.Rows[i]["hash_code"].ToString(), //RecipeFromXML = StringGZip.DecompressString( dt.Rows[0]["recipe_gzip"].ToString()), //一般情况下这个内容都很大,返回集合中不对该属性赋值。 CreateTime = dt.Rows[i]["create_time"].ToString(), Spare1 = dt.Rows[i]["spare1"].ToString(), Spare2 = dt.Rows[i]["spare2"].ToString() }); if (i >= 25) break; } return recipeMemories; } return null; } /// /// 根据Recipe名称+createTime,返回特定记录 /// /// /// /// public RecipeHistory QueryDB(RecipeHistory recipeHistory) { string cmd = $"select * from recipe_history_data where str_guid = '{recipeHistory.StrGuid}'"; var dt = QueryDataClient.Instance.Service.QueryData(cmd); if (dt != null && dt.Rows.Count > 0) { return new RecipeHistory() { StrGuid = dt.Rows[0]["str_guid"].ToString(), RoleName = dt.Rows[0]["role_name"].ToString(), ProcessType = dt.Rows[0]["process_type"].ToString(), RecipeName = dt.Rows[0]["recipe_name"].ToString(), HashCode = dt.Rows[0]["hash_code"].ToString(), RecipeFromXML = StringGZip.DecompressString( dt.Rows[0]["recipe_gzip"].ToString()),//数据库查询时返回解压后的正确数据 CreateTime = dt.Rows[0]["create_time"].ToString(), Spare1 = dt.Rows[0]["spare1"].ToString(), Spare2 = dt.Rows[0]["spare2"].ToString() }; } return null; } private string SaveCmd() { string cmd_data_insert = "insert into recipe_history_data" + "(str_guid,role_name,process_type,recipe_name,hash_code,recipe_gzip, create_time,spare1,spare2)" + $"values ('{StrGuid}'," + $"'{RoleName}'," + $"'{ProcessType}'," + $"'{RecipeName}'," + $"'{HashCode}'," + $"'{RecipeGZip}'," + $"'{CreateTime}'," + $"'{Spare1}'," + $"'{Spare2}')"; return cmd_data_insert; } #endregion } }