diff --git a/WebFirst/database/sqlite.db b/WebFirst/database/sqlite.db index bb11b1a4..07b8ee12 100644 Binary files a/WebFirst/database/sqlite.db and b/WebFirst/database/sqlite.db differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index ad7c241a..7b4c6ac9 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -277,27 +277,27 @@ 文件 - + - 使用本地存储,未进行数据库记录 + 文件上传下载 - + - + - 文件下载 + 文件下载,只需用文件code即可 - - + - + - 文件上传 + 多文件上传,type可空,默认上传至File文件夹下,swagger返回雪花id精度是有问题的 - - + 文件类型,可空 + 多文件表单 + 描述 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs index ac3be741..cbae0b8b 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/FileController.cs @@ -2,15 +2,18 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Hosting; +using SqlSugar; using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Threading.Tasks; +using Yi.Framework.Common.Const; using Yi.Framework.Common.Enum; using Yi.Framework.Common.Models; using Yi.Framework.Interface; +using Yi.Framework.Model.Models; using Yi.Framework.WebCore; namespace Yi.Framework.ApiMicroservice.Controllers @@ -22,40 +25,41 @@ namespace Yi.Framework.ApiMicroservice.Controllers [ApiController] public class FileController : ControllerBase { - private IUserService _iUserService; + private IFileService _iFileService; private readonly IHostEnvironment _env; + /// - /// 使用本地存储,未进行数据库记录 + /// 文件上传下载 /// - /// + /// /// - public FileController(IUserService iUserService, IHostEnvironment env) + public FileController(IFileService iFileService, IHostEnvironment env) { - _iUserService = iUserService; + _iFileService = iFileService; _env = env; } /// - /// 文件下载 + /// 文件下载,只需用文件code即可 /// - /// - /// + /// /// - [Route("/api/file/{type}/{fileName}")] + [Route("/api/file/{code}")] [HttpGet] - public IActionResult Get(string type, string fileName) + public async Task Get(long code) { - type = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(type.ToLower()); - if (!Enum.IsDefined(typeof(PathEnum), type)) + var file = await _iFileService._repository.GetByIdAsync(code); + if (file is null) { return new NotFoundResult(); } try { - var path = Path.Combine($"wwwroot/{type}", fileName); + //路径为: 文件路径/文件id+文件扩展名 + var path = Path.Combine($"{PathConst.wwwroot}/{file.FilePath}", file.Id.ToString()+ Path.GetExtension(file.FileName)); var stream = System.IO.File.OpenRead(path); - var MimeType = Common.Helper.MimeHelper.GetMimeMapping(fileName); - return new FileStreamResult(stream, MimeType); + var MimeType = Common.Helper.MimeHelper.GetMimeMapping(file.FileName); + return File(stream, MimeType, file.FileName); } catch { @@ -64,28 +68,63 @@ namespace Yi.Framework.ApiMicroservice.Controllers } /// - /// 文件上传 + /// 多文件上传,type可空,默认上传至File文件夹下,swagger返回雪花id精度是有问题的 /// - /// - /// + /// 文件类型,可空 + /// 多文件表单 + /// 描述 /// - [Route("/api/Upload/{type}")] + [Route("/api/file/Upload/{type?}")] [HttpPost] - public async Task Upload(string type,IFormFile file) + public async Task Upload([FromRoute] string? type, [FromForm] IFormFileCollection file,[FromQuery] string? remark) { - type = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(type.ToLower()); - if (!Enum.IsDefined(typeof(PathEnum), type)) + if (type is null) { - return Result.Error("上传失败!文件类型不存在!"); + type = PathEnum.File.ToString(); } + else + { + type = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(type!.ToLower()); + if (!Enum.IsDefined(typeof(PathEnum), type)) + { + //后续类型可从字典表中获取 + return Result.Error("上传失败!文件类型不支持!"); + } + } + + if (file.Count() == 0) + { + return Result.Error("未选择文件"); + } + //批量插入 + List datas = new(); + + //返回的codes + List codes = new(); try { - string filename = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); - using (var stream = new FileStream(Path.Combine($"wwwroot/{type}", filename), FileMode.CreateNew, FileAccess.Write)) + foreach (var f in file) { - await file.CopyToAsync(stream); + FileEntity data = new(); + data.Id = SnowFlakeSingle.Instance.NextId(); + data.FileSize = ((decimal)f.Length) / 1024; + data.FileName = f.FileName; + data.FileType = Common.Helper.MimeHelper.GetMimeMapping(f.FileName); + data.FilePath = type; + data.Remark = remark; + data.IsDeleted = false; + + //落盘文件,文件名为雪花id+自己的扩展名 + string filename = data.Id.ToString() + Path.GetExtension(f.FileName); + using (var stream = new FileStream(Path.Combine($"{PathConst.wwwroot}/{type}", filename), FileMode.CreateNew, FileAccess.Write)) + { + await f.CopyToAsync(stream); + } + //将文件信息添加到数据库 + datas.Add(data); + codes.Add(data.Id); } - return Result.Success().SetData(filename); + return Result.Success().SetData(codes).SetStatus(await _iFileService._repository.InsertRangeAsync(datas)); } catch { diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580060882677927936.png b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580060882677927936.png new file mode 100644 index 00000000..dc4b7124 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580060882677927936.png differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580060882711482368.txt b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580060882711482368.txt new file mode 100644 index 00000000..26e6ef52 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580060882711482368.txt @@ -0,0 +1,60 @@ +全套CI持续集成流程 +1、用户在cf-site前端文本框输入必要信息 + +2、cf-site前端调用git-cli接口 + +3、检测用户是否存在,如果不存在就创建git用户 + +4、创建对应仓库并附上对应组织关系 + +5、创建仓库附上dev,test,main等分支 + +6、给git用户附上对应权限 + +7、本地服务器git秘钥进行存储 + +8、 进入临时代码文件夹: cd 临时文件 + +9、克隆远程空仓库:git clone git@gitlab.hymson.com.cn:root/test1.git + +10、进入仓库项目目录:cd 进入项目 + +11、选择分支:git switch -c dev + +12、远程调用cf-cli脚手架将模板文件cli生成 + +13、解压模板文件并将文件以特定格式移动到特定位置 + +14、本地上载全部更新:git add . + +15、添加上传描述:git commit -m "building" + +16、更新远程仓库git push -u origin main + +17、删除临时文件夹 + +18、返回前端仓库地址 + +全套CD持续部署流程 +1、密钥连接jenkins + +2、远程调用cf-cli Job模板生文件 + +3、cf-cli 根据ci的流程返回的参数来Job生成模板 + +4、修改仓库url + +5、修改job的name + +6、修改job的启动项目文件 + +7、创建Cd jenkins job在对应视图中 + +8、上传特定job + +9、触发job + +10、浏览线上网址 + + +CI合并CD,最终返回 仓库地址+线上地址 、 Consul服务注册发现地址,确认服务存活状态 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066004657115136.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066004657115136.jpg new file mode 100644 index 00000000..fbeee125 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066004657115136.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066025611857920.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066025611857920.jpg new file mode 100644 index 00000000..fbeee125 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066025611857920.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066165693222912.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066165693222912.gif new file mode 100644 index 00000000..d916a66d Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066165693222912.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066176795545600.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066176795545600.gif new file mode 100644 index 00000000..d0be1ed6 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066176795545600.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066186081734656.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066186081734656.gif new file mode 100644 index 00000000..d916a66d Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066186081734656.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066511362592768.ico b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066511362592768.ico new file mode 100644 index 00000000..e0895f23 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066511362592768.ico differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066558196191232.png b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066558196191232.png new file mode 100644 index 00000000..5b2d9dc6 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066558196191232.png differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066911880876032.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066911880876032.gif new file mode 100644 index 00000000..d916a66d Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580066911880876032.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067179167092736.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067179167092736.gif new file mode 100644 index 00000000..d916a66d Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067179167092736.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067767632138240.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067767632138240.gif new file mode 100644 index 00000000..d916a66d Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067767632138240.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067767665692672.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067767665692672.jpg new file mode 100644 index 00000000..fbeee125 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067767665692672.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862444380160.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862444380160.gif new file mode 100644 index 00000000..d0be1ed6 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862444380160.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862448574464.png b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862448574464.png new file mode 100644 index 00000000..dc4b7124 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862448574464.png differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862456963072.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862456963072.gif new file mode 100644 index 00000000..d916a66d Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862456963072.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862465351680.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862465351680.jpg new file mode 100644 index 00000000..fbeee125 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580067862465351680.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406252670976.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406252670976.gif new file mode 100644 index 00000000..d0be1ed6 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406252670976.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406261059584.png b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406261059584.png new file mode 100644 index 00000000..dc4b7124 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406261059584.png differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406269448192.gif b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406269448192.gif new file mode 100644 index 00000000..d916a66d Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406269448192.gif differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406277836800.png b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406277836800.png new file mode 100644 index 00000000..5b2d9dc6 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406277836800.png differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406282031104.jpg b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406282031104.jpg new file mode 100644 index 00000000..fbeee125 Binary files /dev/null and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/wwwroot/image/1580068406282031104.jpg differ diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index 90c2d750..62d44a87 100644 Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IFileService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IFileService.cs new file mode 100644 index 00000000..044a213e --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IFileService.cs @@ -0,0 +1,9 @@ +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Interface +{ + public partial interface IFileService:IBaseService + { + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/FileEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/FileEntity.cs new file mode 100644 index 00000000..4f0e5a77 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/FileEntity.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json.Serialization; +using SqlSugar; +namespace Yi.Framework.Model.Models +{ + /// + /// 文件表 + /// + [SugarTable("File")] + public partial class FileEntity:IBaseModelEntity + { + public FileEntity() + { + this.CreateTime = DateTime.Now; + } + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )] + public long Id { get; set; } + /// + /// 文件类型 + /// + [SugarColumn(ColumnName="FileType" )] + public string FileType { get; set; } + /// + /// 文件大小 + /// + [SugarColumn(ColumnName="FileSize" )] + public decimal? FileSize { get; set; } + /// + /// 文件名 + /// + [SugarColumn(ColumnName="FileName" )] + public string FileName { get; set; } + /// + /// 文件路径 + /// + [SugarColumn(ColumnName="FilePath" )] + public string FilePath { get; set; } + /// + /// 创建者 + /// + [SugarColumn(ColumnName="CreateUser" )] + public long? CreateUser { get; set; } + /// + /// 创建时间 + /// + [SugarColumn(ColumnName="CreateTime" )] + public DateTime? CreateTime { get; set; } + /// + /// 修改者 + /// + [SugarColumn(ColumnName="ModifyUser" )] + public long? ModifyUser { get; set; } + /// + /// 修改时间 + /// + [SugarColumn(ColumnName="ModifyTime" )] + public DateTime? ModifyTime { get; set; } + /// + /// 是否删除 + /// + [SugarColumn(ColumnName="IsDeleted" )] + public bool? IsDeleted { get; set; } + /// + /// 租户Id + /// + [SugarColumn(ColumnName="TenantId" )] + public long? TenantId { get; set; } + /// + /// 排序字段 + /// + [SugarColumn(ColumnName="OrderNum" )] + public int? OrderNum { get; set; } + /// + /// 描述 + /// + [SugarColumn(ColumnName="Remark" )] + public string Remark { get; set; } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/FileService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/FileService.cs new file mode 100644 index 00000000..591508f2 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/FileService.cs @@ -0,0 +1,14 @@ +using SqlSugar; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Service +{ + public partial class FileService : BaseService, IFileService + { + public FileService(IRepository repository) : base(repository) + { + } + } +} diff --git a/Yi.Vue3.x.Vant/src/api/fileApi.ts b/Yi.Vue3.x.Vant/src/api/fileApi.ts index 4137b018..2000eef4 100644 --- a/Yi.Vue3.x.Vant/src/api/fileApi.ts +++ b/Yi.Vue3.x.Vant/src/api/fileApi.ts @@ -3,7 +3,7 @@ import myaxios from '@/utils/myaxios.ts' export default{ upload(type:string,data:any){ return myaxios({ - url: `/upload/${type}`, + url: `/file/upload/${type}`, headers:{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, method: 'POST', data:data diff --git a/Yi.Vue3.x.Vant/src/view/login.vue b/Yi.Vue3.x.Vant/src/view/login.vue index a422c54d..ce9dc851 100644 --- a/Yi.Vue3.x.Vant/src/view/login.vue +++ b/Yi.Vue3.x.Vant/src/view/login.vue @@ -5,6 +5,7 @@
+ 真不错 \ No newline at end of file + + \ No newline at end of file diff --git a/Yi.Vue3.x.Vant/src/view/send/imageText.vue b/Yi.Vue3.x.Vant/src/view/send/imageText.vue index 3745018d..90d66a9c 100644 --- a/Yi.Vue3.x.Vant/src/view/send/imageText.vue +++ b/Yi.Vue3.x.Vant/src/view/send/imageText.vue @@ -66,13 +66,25 @@ onMounted(() => { visible.value = true; }); const afterRead = (file: any) => { + file.status = "uploading"; file.message = "上传中..."; var formData = new FormData(); - formData.append("file", file.file); + //一个文件 + if(file.length==undefined) + { + formData.append("file", file.file); + } +else +{ +//多个文件 +file.forEach((f:any) => { + formData.append("file", f.file); +}); +} fileApi.upload("image", formData) .then((response: any) => { - images.value.push(response.data); + images.value.push(...response.data); file.status = "done"; file.message = "成功"; })