public ClearProcBO(string sysCode) { ProcName = DataOpr.GetClearProcName(sysCode); OriginProcText = DataOpr.GetProcText(ProcName); if (OriginProcText.IsEmpty()) { OriginProcText = SQLTemplet.GetInitClearProc(sysCode, ConfigDS.SysList.GetSysInfo(sysCode).SysName); } ProcNoNotes = SQLExt.DelNotes(OriginProcText); ProcText = OriginProcText; // TODO:需要拆分吗? AllSQL = GetAllSQL(); BUSQL = GetBUSQL(); }
/// <summary> /// 生成脚本 /// </summary> /// <param name="comparaResult">会将提示信息标识在Remark字段中</param> /// <returns>存储过程名:存储过程脚本</returns> private KeyValuePair <string, string> CreateSQL(ref KeyValuePair <string, List <ComparaResult> > comparaResult) { string sysCode = comparaResult.Key; var comparaData = comparaResult.Value; // 获取清空存储过程 var clearProc = new ClearProcBO(sysCode); if (clearProc.ProcNoNotes.IsEmpty()) { throw new DomainException($"不存在存储过程:{clearProc.ProcName},请创建后重试!"); } #region 分析 // 存储新增的清空脚本 var addSQLOfAll = new List <string>(); var addSQLOfBU = new List <string>(); comparaData.ForEach(e => { if (e.IsClear) { switch (e.Flag) { case StatusFlag.Add: if (clearProc.IsFind(e.TableName)) { e.Remark = clearProc.ProcName + "中已存在该表,请检查!\r\nPS:未添加该表的清空SQL,请确认。"; e.IsAssert = true; } else { e.Remark = "已添加该表的清空SQL,请确认。"; addSQLOfAll.Add(clearProc.FormatAllSQL(e)); if (e.IsClearOfBU) { addSQLOfBU.Add("\r\n" + clearProc.FormatBUSQL(e)); } } break; case StatusFlag.Edit: if (!clearProc.IsFind(e.TableName)) { e.Remark = clearProc.ProcName + "中不存在该表,请检查!\r\nPS:已补充该表的清空SQL,请确认。"; e.IsAssert = true; addSQLOfAll.Add(clearProc.FormatAllSQL(e)); if (e.IsClearOfBU) { addSQLOfBU.Add("\r\n" + clearProc.FormatBUSQL(e)); } } break; case StatusFlag.Delete: if (!clearProc.IsFind(e.TableName, true)) { e.Remark = clearProc.ProcName + "中已删除该表,请检查!"; } else { e.Remark = "请【手动删除】该表相关清空SQL!"; e.IsAssert = true; } break; } } else { if (clearProc.IsFind(e.TableName, true)) { e.Remark = clearProc.ProcName + "中存在该表,请【手动删除】该表相关清空SQL!"; e.IsAssert = true; } } }); #endregion #region 更新 List <string> rows = clearProc.SplitRow(clearProc.ProcText); int beginEndCount = 0; // 记录Begin-End对出现次数 int insertIndexAll = 0; int insertIndexBU = 0; bool isAddAll = false; // TODO:查找追加位置 rows.SafeForEach((str, i) => { if (Regex.IsMatch(str, @"\bBEGIN\b")) { beginEndCount++; return(true); } if (Regex.IsMatch(str, @"\bEND\b")) { beginEndCount--; if (beginEndCount == 0) { if (!isAddAll) { isAddAll = true; insertIndexAll = i; } else { insertIndexBU = i; return(false); } } } return(true); }); rows.InsertRange(insertIndexBU, addSQLOfBU); rows.InsertRange(insertIndexAll, addSQLOfAll); string result = SQLTemplet.FormatClearProc(clearProc.ProcName, rows.Join("\r\n")); #endregion return(new KeyValuePair <string, string>(clearProc.ProcName, result)); }