Forráskód Böngészése

Merge branch 'develop' of http://106.12.23.251:10080/TEAMMODEL/TEAMModelOS into develop

psycho 5 éve
szülő
commit
2352bb4729

+ 38 - 0
TEAMModelOS.SDK/Helper/Common/JsonHelper/ClassSerializers.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Helper.Common.JsonHelper
+{
+    /// <summary>
+    ///   对象与二进制流的互相转换。
+    /// </summary>
+    public class ClassSerializers
+    {
+        #region 对象与二进制流的互相转换
+        /// <summary>
+        ///   将对象流转换成二进制流
+        /// </summary>
+        public static MemoryStream SerializeBinary(object request) //将对象流转换成二进制流
+        {
+            BinaryFormatter serializer = new BinaryFormatter();
+            MemoryStream memStream = new MemoryStream(); //创建一个内存流存储区
+            serializer.Serialize(memStream, request); //将对象序列化为内存流中
+            return memStream;
+        }
+        /// <summary>
+        ///   将二进制流转换成对象
+        /// </summary>
+        public static object DeSerializeBinary(MemoryStream memStream) //将二进制流转换成对象
+        {
+            memStream.Position = 0;
+            BinaryFormatter deserializer = new BinaryFormatter();
+            object newobj = deserializer.Deserialize(memStream); //将内存流反序列化为对象
+            memStream.Close(); //关闭内存流,并释放
+            return newobj;
+        }
+        #endregion
+    }
+}

+ 18 - 0
TEAMModelOS.SDK/Module/AzureBlob/Container/AzureBlobModel.cs

@@ -54,6 +54,24 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Container
             Extension = f.Name.Substring(f.Name.LastIndexOf(".") + 1, (f.Name.Length - f.Name.LastIndexOf(".") - 1)); //扩展名
             Timestamp = DateTimeHelper.ConvertToDateTime(time);
         }
+
+        public AzureBlobModel(string fileName, string Container, string groupName, string newName, string contentType ,long length)
+        {
+            long time = DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
+            ContentType = contentType;
+            ContentDisposition = "form-data; name=\"file\"; filename=\"" + fileName + "\"";
+            FileName = fileName;
+            // Headers = f.Headers.Values;
+            RealName = groupName + "/" + newName;
+            Folder = groupName;
+            Length = length;
+            Name = "file";
+            UploadTime = time;
+            PartitionKey = Container;
+            RowKey = Guid.NewGuid().ToString();
+            Extension = fileName.Substring(fileName.LastIndexOf(".") + 1, (fileName.Length - fileName.LastIndexOf(".") - 1)); //扩展名
+            Timestamp = DateTimeHelper.ConvertToDateTime(time);
+        }
         [Required(ErrorMessage = "{0} 必须填写")]
         public string Folder { get; set; }
         [Required(ErrorMessage = "{0} 必须填写")]

+ 89 - 14
TEAMModelOS.SDK/Module/AzureBlob/Implements/AzureBlobDBRepository.cs

@@ -17,6 +17,8 @@ using Microsoft.WindowsAzure.Storage.Shared.Protocol;
 using TEAMModelOS.SDK.Extension.SnowFlake;
 using TEAMModelOS.SDK.Context.Constant;
 using Microsoft.AspNetCore.StaticFiles;
+using System.Runtime.Serialization.Formatters.Binary;
+using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 
 namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
 {
@@ -71,7 +73,7 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
         //    //await UploadFiles(null, new FileContainer() );
         //}
 
-        public async Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file,string fileSpace="common")
+        public async Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file,string fileSpace= "common" , bool contentTypeDefault = false)
         {
             string groupName = fileSpace+"/" +DateTime.Now.ToString("yyyyMMdd");
             string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
@@ -97,7 +99,6 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
             //    await blobClient.SetServicePropertiesAsync(serviceProperties);
             //}
 
-
             StorageUri url = blobContainer.StorageUri;
             List<AzureBlobModel> list = new List<AzureBlobModel>();
             foreach (FormFile f in file)
@@ -120,10 +121,13 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
                 var parsedContentDisposition = ContentDispositionHeaderValue.Parse(f.ContentDisposition);
                 var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
                 var blockBlob = blobContainer.GetBlockBlobReference(name);
-                ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
-                if (!string.IsNullOrEmpty(content_type))
-                {
-                    blockBlob.Properties.ContentType = content_type;
+
+                if (!contentTypeDefault) {
+                    ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
+                    if (!string.IsNullOrEmpty(content_type))
+                    {
+                        blockBlob.Properties.ContentType = content_type;
+                    }
                 }
                 await blockBlob.UploadFromStreamAsync(f.OpenReadStream());
                 AzureBlobModel model = new AzureBlobModel(f, _options.Container, groupName, name)
@@ -134,7 +138,7 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
             }
             return list;
         }
-        public async Task<AzureBlobModel> UploadPath(string path, string fileSpace = "common") {
+        public async Task<AzureBlobModel> UploadPath(string path, string fileSpace = "common" , bool contentTypeDefault = false) {
             string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd");
             string newFileName = DateTime.Now.ToString("HHmmssfffffff");
             blobContainer = blobClient.GetContainerReference(groupName);
@@ -156,15 +160,24 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
             }
             string fileext = file.Name.Substring(file.Name.LastIndexOf(".") > 0 ? file.Name.LastIndexOf(".") : 0);
 
-            var parsedContentDisposition = ContentDispositionHeaderValue.Parse("form-data; name=\"files\"; filename=\"" + file.Name + "\"");
+          //  var parsedContentDisposition = ContentDispositionHeaderValue.Parse("form-data; name=\"files\"; filename=\"" + file.Name + "\"");
             var blockBlob = blobContainer.GetBlockBlobReference(name);
-            ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
-            if (!string.IsNullOrEmpty(content_type))
+            string content_type = "application/octet-stream";
+            if (!contentTypeDefault)
             {
-                blockBlob.Properties.ContentType = content_type;
+                ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
+                if (!string.IsNullOrEmpty(contenttype))
+                {
+                    blockBlob.Properties.ContentType = contenttype;
+                    content_type = contenttype;
+                }
+                else
+                {
+                    blockBlob.Properties.ContentType = content_type;
+                }
             }
-            else {
-                content_type = "application/octet-stream";
+            else
+            {
                 blockBlob.Properties.ContentType = content_type;
             }
             await blockBlob.UploadFromFileAsync(path);
@@ -177,8 +190,61 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
             return model;
         }
 
+        public async Task<AzureBlobModel> UploadObject(string fileName,object obj, string fileSpace = "common", bool contentTypeDefault =true)
+        {
+            string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd");
+            string newFileName = DateTime.Now.ToString("HHmmssfffffff");
+            blobContainer = blobClient.GetContainerReference(groupName);
+            StorageUri url = blobContainer.StorageUri;
+            //FileInfo file = new FileInfo(path);
+            string[] names = fileName.Split(".");
+            string name = "";
+            for (int i = 0; i < names.Length - 1; i++)
+            {
+                name = name + names[i];
+            }
+            if (names.Length <= 1)
+            {
+                name = fileName + "_" + newFileName;
+            }
+            else
+            {
+                name = name + "_" + newFileName + "." + names[names.Length - 1];
+            }
+            var blockBlob = blobContainer.GetBlockBlobReference(name);
+            //  var parsedContentDisposition = ContentDispositionHeaderValue.Parse("form-data; name=\"files\"; filename=\"" + file.Name + "\"");
+            string fileext = fileName.Substring(fileName.LastIndexOf(".") > 0 ? fileName.LastIndexOf(".") : 0);
+            string content_type = "application/octet-stream";
+            if (!contentTypeDefault)
+            {
+                ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
+                if (!string.IsNullOrEmpty(contenttype))
+                {
+                    blockBlob.Properties.ContentType = contenttype;
+                    content_type = contenttype;
+                }
+                else
+                {
+                    blockBlob.Properties.ContentType = content_type;
+                }
+            }
+            else {
+                blockBlob.Properties.ContentType = content_type;
+            }
+            string objStr = obj.ToJson();
+            long length = System.Text.Encoding.Default.GetBytes(objStr).Length;
+            await blockBlob.UploadTextAsync(objStr);
+            //var provider = new FileExtensionContentTypeProvider();
+            //var memi = provider.Mappings[fileext];
+            AzureBlobModel model = new AzureBlobModel(fileName, _options.Container, groupName, name, content_type , length)
+            {
+                BlobUrl = url.PrimaryUri.ToString().Split("?")[0] + "/" + name
+            };
+            return model;
+        }
+
 
-        public async Task<AzureBlobModel> UploadWord(IFormFile file, string fileSpace = "wordfiles")
+        public async Task<AzureBlobModel> UploadFile(IFormFile file, string fileSpace = "wordfiles", bool contentTypeDefault = true)
         {
             long  bizno= IdWorker.getInstance().NextId();
             string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd")+"/"+ bizno;
@@ -203,6 +269,15 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
             var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
             var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
             var blockBlob = blobContainer.GetBlockBlobReference(name);
+            string fileext = filename.Substring(filename.LastIndexOf(".") > 0 ? filename.LastIndexOf(".") : 0);
+            if (!contentTypeDefault)
+            {
+                ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
+                if (!string.IsNullOrEmpty(content_type))
+                {
+                    blockBlob.Properties.ContentType = content_type;
+                }
+            }
             await blockBlob.UploadFromStreamAsync(file.OpenReadStream());
             AzureBlobModel model = new AzureBlobModel(file, _options.Container, groupName, name)
             {

+ 5 - 3
TEAMModelOS.SDK/Module/AzureBlob/Interfaces/IAzureBlobDBRepository.cs

@@ -7,8 +7,10 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Interfaces
 {
     public interface IAzureBlobDBRepository
     {
-        Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file ,string fileSpace="common");
-        Task<AzureBlobModel> UploadWord(IFormFile file, string fileSpace = "wordfiles");
-        Task<AzureBlobModel> UploadPath(string path, string fileSpace = "common");
+        Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file ,string fileSpace="common" ,bool contentTypeDefault = false);
+        Task<AzureBlobModel> UploadFile(IFormFile file, string fileSpace = "wordfiles", bool contentTypeDefault = true);
+        Task<AzureBlobModel> UploadPath(string path, string fileSpace = "common", bool contentTypeDefault = false);
+        Task<AzureBlobModel> UploadObject(string fileName, object obj, string fileSpace = "common", bool contentTypeDefault = true);
+        
     }
 }

+ 1 - 0
TEAMModelOS.SDK/TEAMModelOS.SDK.csproj

@@ -4,6 +4,7 @@
     <TargetFramework>netcoreapp2.2</TargetFramework>
     <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
     <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
+    <Version>1.0.3</Version>
   </PropertyGroup>
 
   <ItemGroup>

+ 22 - 3
TEAMModelOS/Controllers/Core/FileController.cs

@@ -6,6 +6,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
+using TEAMModelOS.Model.Core.Dtos;
 using TEAMModelOS.SDK.Context.Constant.Common;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
@@ -146,8 +147,6 @@ namespace TEAMModelOS.Controllers.Core
 
 
 
-
-
         /// <summary>
         /// </summary>
         /// <param name="request"></param>
@@ -156,7 +155,27 @@ namespace TEAMModelOS.Controllers.Core
         public async Task<BaseJosnRPCResponse> saveBlob(JosnRPCRequest<AzureBlobModel> request)
         {
             JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
-             AzureBlobModel  model = await _azureBlobModelService.SaveOrUpdate<AzureBlobModel>(request.@params);
+            AzureBlobModel model = await _azureBlobModelService.SaveOrUpdate<AzureBlobModel>(request.@params);
+            if (model != null && !string.IsNullOrEmpty(model.RowKey))
+            {
+                return responseBuilder.Data(model).build();
+            }
+            else
+            {
+                return responseBuilder.Data(null).build();
+            }
+        }
+
+
+        /// <summary>
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpGet("uploadObj")]
+        public async Task<BaseJosnRPCResponse> uploadObj()
+        {
+            JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
+            AzureBlobModel  model = await _azureBlobDBRepository.UploadObject("aaa.json",new CodeValue {Code="中文",Value= "𝑏𝑛" });
             if (model != null && !string.IsNullOrEmpty(model.RowKey))
             {
                 return responseBuilder.Data(model).build();

+ 36 - 36
TEAMModelOS/package.json

@@ -17,11 +17,11 @@
     "update-packages": "npx npm-check -u"
   },
   "dependencies": {
-    "@ckeditor/ckeditor5-build-inline": "^12.1.0",
-    "animate.css": "^3.7.0",
+    "@ckeditor/ckeditor5-build-inline": "^12.3.1",
+    "animate.css": "^3.7.2",
     "axios": "^0.19.0",
     "bcryptjs": "^2.4.3",
-    "core-js": "^2.5.3",
+    "core-js": "^2.6.9",
     "d3": "^5.9.2",
     "echarts": "^4.2.1",
     "iview": "^3.4.2",
@@ -31,64 +31,64 @@
     "videojs-contrib-hls.js": "^3.2.0",
     "vue": "^2.6.9",
     "vue-ckeditor5": "^0.4.1",
-    "vue-infinite-loading": "^2.4.3",
-    "vue-router": "^3.0.2",
-    "vue-scroll": "^2.1.9",
+    "vue-infinite-loading": "^2.4.4",
+    "vue-router": "^3.0.7",
+    "vue-scroll": "^2.1.12",
     "vue-server-renderer": "^2.6.9",
     "vue-template-compiler": "^2.6.9",
     "vue-video-player": "^5.0.2",
-    "vuex": "^3.1.0",
+    "vuex": "^3.1.1",
     "vuex-router-sync": "^5.0.0",
     "wangeditor": "^3.1.1"
   },
   "devDependencies": {
-    "@babel/core": "^7.2.2",
-    "@babel/plugin-proposal-class-properties": "^7.0.0",
-    "@babel/plugin-proposal-decorators": "^7.0.0",
-    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
-    "@babel/plugin-proposal-function-sent": "^7.0.0",
+    "@babel/core": "^7.5.5",
+    "@babel/plugin-proposal-class-properties": "^7.5.5",
+    "@babel/plugin-proposal-decorators": "^7.4.4",
+    "@babel/plugin-proposal-export-namespace-from": "^7.5.2",
+    "@babel/plugin-proposal-function-sent": "^7.5.0",
     "@babel/plugin-proposal-json-strings": "^7.0.0",
     "@babel/plugin-proposal-numeric-separator": "^7.0.0",
     "@babel/plugin-proposal-throw-expressions": "^7.0.0",
     "@babel/plugin-syntax-dynamic-import": "^7.0.0",
     "@babel/plugin-syntax-import-meta": "^7.0.0",
-    "@babel/plugin-transform-async-to-generator": "^7.0.0",
-    "@babel/plugin-transform-runtime": "^7.0.0",
-    "@babel/preset-env": "^7.0.0",
-    "@babel/register": "^7.0.0",
-    "@babel/runtime": "^7.3.1",
-    "@fortawesome/fontawesome-svg-core": "^1.2.13",
-    "@fortawesome/free-brands-svg-icons": "^5.7.0",
-    "@fortawesome/free-solid-svg-icons": "^5.7.0",
+    "@babel/plugin-transform-async-to-generator": "^7.5.0",
+    "@babel/plugin-transform-runtime": "^7.5.5",
+    "@babel/preset-env": "^7.5.5",
+    "@babel/register": "^7.5.5",
+    "@babel/runtime": "^7.5.5",
+    "@fortawesome/fontawesome-svg-core": "^1.2.21",
+    "@fortawesome/free-brands-svg-icons": "^5.10.1",
+    "@fortawesome/free-solid-svg-icons": "^5.10.1",
     "@fortawesome/vue-fontawesome": "^0.1.5",
     "aspnet-webpack": "^3.0.0",
-    "babel-eslint": "^10.0.1",
-    "babel-loader": "^8.0.5",
-    "babel-plugin-import": "^1.11.0",
+    "babel-eslint": "^10.0.2",
+    "babel-loader": "^8.0.6",
+    "babel-plugin-import": "^1.12.0",
     "cross-env": "^5.2.0",
     "css-loader": "^2.1.1",
-    "eslint": "^5.15.2",
+    "eslint": "^5.16.0",
     "eslint-config-standard": "^12.0.0",
-    "eslint-plugin-html": "^5.0.0",
-    "eslint-plugin-import": "^2.9.0",
+    "eslint-plugin-html": "^5.0.5",
+    "eslint-plugin-import": "^2.18.2",
     "eslint-plugin-node": "^8.0.1",
-    "eslint-plugin-promise": "^4.0.1",
+    "eslint-plugin-promise": "^4.2.1",
     "eslint-plugin-standard": "^4.0.0",
-    "event-source-polyfill": "^1.0.5",
+    "event-source-polyfill": "^1.0.7",
     "file-loader": "^3.0.1",
     "font-awesome": "^4.7.0",
     "less-loader": "^4.1.0",
     "mini-css-extract-plugin": "^0.5.0",
-    "node-sass": "^4.8.2",
-    "optimize-css-assets-webpack-plugin": "^5.0.1",
+    "node-sass": "^4.12.0",
+    "optimize-css-assets-webpack-plugin": "^5.0.3",
     "sass-loader": "^7.1.0",
     "style-loader": "^0.23.1",
     "url-loader": "^1.1.2",
-    "vue-i18n": "^8.9.0",
-    "vue-loader": "^15.7.0",
-    "webpack": "^4.29.0",
-    "webpack-cli": "^3.3.0",
-    "webpack-dev-server": "^3.1.14",
-    "webpack-hot-middleware": "^2.21.2"
+    "vue-i18n": "^8.12.0",
+    "vue-loader": "^15.7.1",
+    "webpack": "^4.39.1",
+    "webpack-cli": "^3.3.6",
+    "webpack-dev-server": "^3.7.2",
+    "webpack-hot-middleware": "^2.25.0"
   }
 }