|
|
@@ -0,0 +1,157 @@
|
|
|
+using Attribute;
|
|
|
+using Base;
|
|
|
+using Common;
|
|
|
+using Dto;
|
|
|
+using Enums;
|
|
|
+using Extensions;
|
|
|
+using Filters;
|
|
|
+using Infrastructure;
|
|
|
+using Infrastructure.Model;
|
|
|
+using Mapster;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Middleware;
|
|
|
+using Model;
|
|
|
+using Model.Base;
|
|
|
+using Services;
|
|
|
+using Util;
|
|
|
+using Vo;
|
|
|
+
|
|
|
+namespace Controllers.Feign
|
|
|
+{
|
|
|
+ public class VsCodeController : BaseController
|
|
|
+ {
|
|
|
+ private readonly IVersionsService versionsService;
|
|
|
+ private readonly IVersionForProjectService versionForProjectService;
|
|
|
+ private readonly IMakeFilesService makeFilesService;
|
|
|
+
|
|
|
+ public VsCodeController(IVersionsService versionsService, IVersionForProjectService versionForProjectService, IMakeFilesService makeFilesService)
|
|
|
+ {
|
|
|
+ this.versionsService = versionsService;
|
|
|
+ this.versionForProjectService = versionForProjectService;
|
|
|
+ this.makeFilesService = makeFilesService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// vscode项目版本列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="param"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("/api/vscode/versions")]
|
|
|
+ public IActionResult versions([FromQuery] VersionDto para)
|
|
|
+ {
|
|
|
+ TokenModel tokenModel = JwtUtil.GetLoginUser(HttpContext);
|
|
|
+ if(tokenModel == null)
|
|
|
+ {
|
|
|
+ return ToResponse(ResultCode.BAD_REQUEST, "用户未登录");
|
|
|
+ }
|
|
|
+ List<VersionVo> list = new List<VersionVo>();
|
|
|
+ VersionForProject ver = versionForProjectService.GetFirst(m => m.databaseId == para.serverId) ?? new VersionForProject();
|
|
|
+ var versions = versionsService.GetList(m => m.serverId == para.serverId && m.groupId == tokenModel.userId);
|
|
|
+ foreach(var version in versions)
|
|
|
+ {
|
|
|
+ VersionVo item = new VersionVo();
|
|
|
+ item.versionId = version.versionId;
|
|
|
+ item.batchNo = version.versionNo;
|
|
|
+ if(version.versionNo.StartsWith("java")) item.verNo = ver.javaVersion;
|
|
|
+ if(version.versionNo.StartsWith("net")) item.verNo = ver.netVersion;
|
|
|
+ if(version.versionNo.StartsWith("vue")) item.verNo = ver.frontendVersion;
|
|
|
+ if(version.versionNo.StartsWith("py")) item.verNo = ver.pythonVersion;
|
|
|
+ item.createTime = version.createTime == null ? "" : version.createTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+ list.Add(item);
|
|
|
+ }
|
|
|
+ return SUCCESS(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// vscode项目文件列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="param"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("/api/vscode/files")]
|
|
|
+ public IActionResult files([FromQuery] FileDto para)
|
|
|
+ {
|
|
|
+ TokenModel tokenModel = JwtUtil.GetLoginUser(HttpContext);
|
|
|
+ if(tokenModel == null)
|
|
|
+ {
|
|
|
+ return ToResponse(ResultCode.BAD_REQUEST, "用户未登录");
|
|
|
+ }
|
|
|
+ Versions version = versionsService.GetFirst(m => m.versionId == para.versionId) ?? new Versions();
|
|
|
+ VersionForProject ver = versionForProjectService.GetFirst(m => m.databaseId == version.serverId) ?? new VersionForProject();
|
|
|
+ int verNo = 1;
|
|
|
+ if(version.versionNo.StartsWith("java")) verNo = ver.javaVersion;
|
|
|
+ if(version.versionNo.StartsWith("net")) verNo = ver.netVersion;
|
|
|
+ if(version.versionNo.StartsWith("vue")) verNo = ver.frontendVersion;
|
|
|
+ if(version.versionNo.StartsWith("py")) verNo = ver.pythonVersion;
|
|
|
+ List<FileVo> list = GetFileList(para.versionId, verNo, 0);
|
|
|
+ return SUCCESS(list);
|
|
|
+ }
|
|
|
+ public List<FileVo> GetFileList(int versionId, int verNo, int parentFileId = 0)
|
|
|
+ {
|
|
|
+ List<FileVo> list = new List<FileVo>();
|
|
|
+ var files = makeFilesService.GetList(m => m.versionId == versionId && m.parentFileId == parentFileId);
|
|
|
+ foreach(var file in files)
|
|
|
+ {
|
|
|
+ FileVo item = new FileVo();
|
|
|
+ item.fileId = file.fileId;
|
|
|
+ item.versionId = file.versionId;
|
|
|
+ item.fileVersionNo = file.fileVersionNo;
|
|
|
+ item.verNo = verNo;
|
|
|
+ item.fileName = file.fileName.TrimEnd('/');
|
|
|
+ item.createTime = file.createTime == null ? "" : file.createTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+ item.downloadPath = !string.IsNullOrEmpty(file.downloadPath) ? OssHelper.Instance.SourceHost + file.downloadPath : null;
|
|
|
+ item.localPath = file.fileType == "path" ? null : file.localPath;
|
|
|
+ List<FileVo> Children = GetFileList(versionId, verNo, file.fileId);
|
|
|
+ if(Children.Count > 0)
|
|
|
+ {
|
|
|
+ item.children = Children;
|
|
|
+ }
|
|
|
+ bool op = true;
|
|
|
+ if(string.IsNullOrEmpty(file.localPath) && Children.Count <= 0)
|
|
|
+ {
|
|
|
+ op = false;
|
|
|
+ }
|
|
|
+ if(op) list.Add(item);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// vscode项目所有文件列表(包含无效文件)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="param"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("/api/vscode/filesForAll")]
|
|
|
+ public IActionResult filesForAll([FromQuery] FileDto para)
|
|
|
+ {
|
|
|
+ TokenModel tokenModel = JwtUtil.GetLoginUser(HttpContext);
|
|
|
+ if(tokenModel == null)
|
|
|
+ {
|
|
|
+ return ToResponse(ResultCode.BAD_REQUEST, "用户未登录");
|
|
|
+ }
|
|
|
+ List<FileVo> list = GetFileList(para.versionId, 0);
|
|
|
+ return SUCCESS(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// vscode项目文件内容
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="param"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("/api/vscode/getFile")]
|
|
|
+ public IActionResult getFile([FromBody] GetFileDto para)
|
|
|
+ {
|
|
|
+ TokenModel tokenModel = JwtUtil.GetLoginUser(HttpContext);
|
|
|
+ if(tokenModel == null)
|
|
|
+ {
|
|
|
+ return ToResponse(ResultCode.BAD_REQUEST, "用户未登录");
|
|
|
+ }
|
|
|
+ var item = makeFilesService.GetFirst(m => m.fileId == para.fileId) ?? new MakeFiles();
|
|
|
+ // CheckCode.Transfer(para.fileContent, item.DownloadPath, item.FileType); //检查代码增量
|
|
|
+ GetFileVo data = new GetFileVo();
|
|
|
+ data.fileId = item.fileId;
|
|
|
+ data.downloadPath = OssHelper.Instance.SourceHost + item.downloadPath.TrimStart('/');
|
|
|
+ data.localPath = item.localPath;
|
|
|
+ return SUCCESS(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|