Przeglądaj źródła

优化生成逻辑

lichunlei 4 miesięcy temu
rodzic
commit
cb8ed3be0a
2 zmienionych plików z 11 dodań i 9 usunięć
  1. 1 1
      Task/MakeHelper.cs
  2. 10 8
      Util/Maker.cs

+ 1 - 1
Task/MakeHelper.cs

@@ -39,7 +39,7 @@ namespace Tasks
                 string requestId = jsonObj["requestId"].ToString();
                 //模板文件路径
                 string modePath = jsonObj["modePath"].ToString();
-                // if(modePath.Contains("controller"))
+                // if(modePath.Contains("controller") && content.Contains("DoubleAward"))
                 // {
                 //     string packageName = "123123123";
                 // }

+ 10 - 8
Util/Maker.cs

@@ -38,6 +38,8 @@ namespace Util
                     templateString = templateString.Replace("<<ym:" + key + ">>", "");
                 }
             }
+            templateString = PublicMake(templateString, "-top2");
+            templateString = PublicMake(templateString, "-top");
             templateString = PublicMake(templateString);
             return templateString;
         }
@@ -210,25 +212,25 @@ namespace Util
         #endregion
 
         #region 公共标签处理
-        public static string PublicMake(string content)
+        public static string PublicMake(string content, string level = "")
         {
-            MatchCollection mc = Regex.Matches(content, "<<ym-if:.*?>>[\\s\\S]*?<</ym-if>>");
+            MatchCollection mc = Regex.Matches(content, "<<ym-if" + level + ":.*?>>[\\s\\S]*?<</ym-if" + level + ">>");
             foreach (Match m in mc)
             {
                 string matchValue = m.Value;
-                Match head = Regex.Match(matchValue.Replace("<</ym-if>>", ""), "<<ym-if:.*?>>");
+                Match head = Regex.Match(matchValue.Replace("<</ym-if" + level + ">>", ""), "<<ym-if" + level + ":.*?>>");
                 if (head.Success)
                 {
                     string headValue = head.Value;
-                    string resultValue = matchValue.Replace(headValue, "").Replace("<</ym-if>>", "");
+                    string resultValue = matchValue.Replace(headValue, "").Replace("<</ym-if" + level + ">>", "");
                     string elseValue = "";
-                    if (resultValue.Contains("<<ym-else>>"))
+                    if (resultValue.Contains("<<ym-else" + level + ">>"))
                     {
-                        string[] valueData = resultValue.Split(new string[] { "<<ym-else>>" }, StringSplitOptions.None);
+                        string[] valueData = resultValue.Split(new string[] { "<<ym-else" + level + ">>" }, StringSplitOptions.None);
                         resultValue = valueData[0];
                         elseValue = valueData[1];
                     }
-                    string condition = headValue.Substring(8, headValue.Length - 10);
+                    string condition = headValue.Substring(8 + level.Length, headValue.Length - 10 - level.Length);
                     condition = condition.Replace("isEmpty", "IsNullOrEmpty");
                     condition = condition.Replace("start(", "StartsWith(");
                     condition = condition.Replace("True", "true");
@@ -255,7 +257,7 @@ namespace Util
                 string jsonObjString = jsonObj.ToJson();
                 if (keyArr.Length == 1)
                 {
-                    if (jsonObjString.Contains("\"" + key + "\""))
+                    if (jsonObjString.Contains("\"" + key + "\"") && jsonObj.Keys.Contains(key))
                     {
                         templateString = templateString.Replace(matchValue, jsonObj[key].ToString());
                     }