浏览代码

提供同步生成文件的接口

lichunlei 3 月之前
父节点
当前提交
fa98e22bd8
共有 3 个文件被更改,包括 35 次插入6 次删除
  1. 16 0
      Controllers/Feign/VsCodeController.cs
  2. 6 0
      Model/Dto/FileDto.cs
  3. 13 6
      Task/MakeHelper.cs

+ 16 - 0
Controllers/Feign/VsCodeController.cs

@@ -13,6 +13,7 @@ using Middleware;
 using Model;
 using Model.Base;
 using Services;
+using Tasks;
 using Util;
 using Vo;
 
@@ -153,5 +154,20 @@ namespace Controllers.Feign
             data.localPath = item.localPath;
             return SUCCESS(data);
         }
+    
+    
+        /// <summary>
+        /// 生成文件
+        /// </summary>
+        /// <param name="param"></param>
+        /// <returns></returns>
+        [HttpPost("/v1/omega_make/vscode/makeFile")]
+        public IActionResult makeFile([FromBody] MakeFileDto para)
+        {
+            string res = MakeHelper.Instance.DoQueue(para.content);
+            return SUCCESS(res);
+        }
+    
+    
     }
 }

+ 6 - 0
Model/Dto/FileDto.cs

@@ -19,6 +19,12 @@ namespace Dto
         public string? fileContent { get; set; }
     }
 
+    public class MakeFileDto
+    {
+        //数据
+        public string content { get; set; }
+    }
+
     public class InitServerDto
     {
         //服务Id

+ 13 - 6
Task/MakeHelper.cs

@@ -30,7 +30,7 @@ namespace Tasks
             }
         }
 
-        public void DoQueue(string content)
+        public string DoQueue(string content, bool push = true)
         {
             try
             {
@@ -53,7 +53,7 @@ namespace Tasks
                 // string templateString = Function.ReadInstance("Template/" + modePath + ".json");
                 var templateService = App.GetRequiredService<IMakeTemplateService>();
                 var template = templateService.GetFirst(m => m.templateName == modePath);
-                if(template == null) return;
+                if(template == null) return "";
                 string templateString = template.templateContent;
                 templateString = HttpUtility.UrlDecode(templateString);
                 //解析模板内容
@@ -77,9 +77,9 @@ namespace Tasks
                 fileName = Util.Maker.replaceKeyToValue(jsonObj["data"], fileName);
                 Function.WritePage(path, fileName, resultString);
                 string startPath = Function.getPath(path + fileName);
-                OssHelper.Instance.Upload(startPath);
                 if(serviceId > 0 && projectId > 0)
                 {
+                    OssHelper.Instance.Upload(startPath);
                     addFile(projectId, serviceId, int.Parse(Function.CheckInt(userId)), versionNo, fileName, path + fileName, path + fileName, fileType, javaVersion, "java");
                 }
                 //生成数据入库
@@ -107,14 +107,21 @@ namespace Tasks
                     item.updateBy = attach["createBy"].ToString();
                     makeDataService.Update(item);
                 }
-                RabbitMQClient.Instance.Push("MakeCallBackQueue", content + "#cut#" + resultString);
+                if(push)
+                {
+                    RabbitMQClient.Instance.Push("MakeCallBackQueue", content + "#cut#" + resultString);
+                    return "";
+                }
+                else
+                {
+                    return content + "#cut#" + resultString;
+                }
             }
             catch (Exception ex)
             {
                 Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex, "生成异常");
+                return "";
             }
-            //MQ回调解析的结果
-            // RabbitMQClient.Instance.Push("MakeSqlCallBackQueue", requestId + "#cut#" + attach + "#cut#" + resultString);
         }
 
         //生成代码版本