Browse Source

字符串转二维码接口

lifa 1 year ago
parent
commit
4ff0c26728

+ 3 - 2
src/hosts/DiTui.Host/DiTui.Host.csproj

@@ -27,9 +27,10 @@
 		<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.695" />
 	</ItemGroup>
 
-	<ItemGroup >
-		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.695"/>
+	<ItemGroup>
+		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.695" />
 		<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.695" />
+		<PackageReference Include="Gma.QrCodeNet" Version="0.4.1.2" />
 	</ItemGroup>
 	
 	

+ 1 - 0
src/hosts/ZhonTai.Host/ZhonTai.Host.csproj

@@ -27,6 +27,7 @@
 	<ItemGroup>
 		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.693" />
 		<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.693" />
+		<PackageReference Include="Gma.QrCodeNet" Version="0.4.1.2" />
 	</ItemGroup>
 	
 	<ItemGroup>

+ 33 - 0
src/platform/ZhonTai.Admin/Services/DiTuiAPI/DiTuiAPIService.cs

@@ -20,6 +20,11 @@ using ZhonTai.Common.Extensions;
 using System.Linq.Expressions;
 using Microsoft.AspNetCore.Http;
 using ZhonTai.Admin.Domain.Org;
+using Gma.QrCodeNet.Encoding.Windows.Render;
+using Gma.QrCodeNet.Encoding;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Drawing;
 
 namespace ZhonTai.Admin.Services.DiTuiAPI
 {
@@ -308,6 +313,34 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
             return userInfo;
         }
 
+        /// <summary>
+        /// 字符串转Qrcode
+        /// </summary>
+        /// <param name="content">要转二维码的内容</param>
+        /// <param name="moduleSize">二维码大小 25px 的倍数,默认9(既 225X225px)</param>
+        /// <returns></returns>
+        [HttpGet]
+        [AllowAnonymous]
+        [NoOprationLog]
+        public string GetQRCode(string content, int moduleSize = 9)
+        {
+            if (string.IsNullOrEmpty(content))
+            {
+                throw ResultOutput.Exception("内容不可为空");
+            }
+
+            var encoder = new QrEncoder(ErrorCorrectionLevel.M);
+            QrCode qrCode = encoder.Encode(content);
+            GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(moduleSize, QuietZoneModules.Two), Brushes.Black, Brushes.White);
+
+            MemoryStream memoryStream = new MemoryStream();
+            render.WriteToStream(qrCode.Matrix, ImageFormat.Jpeg, memoryStream);
+            byte[] arr = memoryStream.ToArray();
+            string base64Str = "data:image/jpeg;base64," + Convert.ToBase64String(arr);
+            return base64Str;
+
+        }
+
         /// <summary>
         /// 获得token
         /// </summary>

+ 33 - 2
src/platform/ZhonTai.Admin/Services/DiTuiAPI/ProjectsService.cs

@@ -11,6 +11,8 @@ using ZhonTai.Admin.Core.Attributes;
 using ZhonTai.Admin.Core.Configs;
 using ZhonTai.Admin.Core.Consts;
 using ZhonTai.Admin.Core.Dto;
+using ZhonTai.Admin.Domain.KuaKe;
+using ZhonTai.Admin.Domain.Project;
 using ZhonTai.Admin.Domain.User;
 using ZhonTai.Admin.Repositories.KuaKe;
 using ZhonTai.Admin.Repositories.Project;
@@ -107,7 +109,10 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
             var listProject = new List<MyProject>();
             if (listProjectId.Count() > 0)
             {
-                listProject = await _projectRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => listProjectId.Contains(m.Id)).ToListAsync(m => new MyProject(
+                listProject = await _projectRepository.Select.DisableGlobalFilter(FilterNames.Tenant)
+                    .Where(m => listProjectId.Contains(m.Id))
+                    .Where(m => m.Status == 2 || m.Status == 4 || m.Status == 5)
+                    .ToListAsync(m => new MyProject(
                     m.Id,
                     m.Name,
                     m.Logo,
@@ -367,12 +372,38 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
             {
                 string kuaKeStatus = null;
                 kuaKeStatus = input.Filter?.KuaKeStatus == "0"? null : input.Filter?.KuaKeStatus;
+                Expression<Func<KuaKeEntity, bool>> where = null;
+                //where = where.Or(input.Mobile.NotNull(), a => a.Mobile == input.Mobile)
+                //    .Or(input.Email.NotNull(), a => a.Email == input.Email);
+
+                //switch (kuaKeStatus)
+                //{
+                //    case "2":
+                //        where = (a => a.Status == 2 || a.Status == 1);
+                //        break;
+
+                //}
+
+                if (kuaKeStatus == "0" || string.IsNullOrEmpty(kuaKeStatus))
+                {
+                    where = null;
+                }
+                else if (kuaKeStatus == "2")
+                {
+                    where = (a => a.Status == 1 || a.Status == 2);
+                }
+                else
+                {
+                    where = (a => a.Status == Convert.ToInt16(kuaKeStatus));
+                }
+
                 list = _kuaKeRepository.Select.DisableGlobalFilter(FilterNames.Tenant)
                 //list = _ProjectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant)
                     .WhereIf(ProjectId.HasValue && ProjectId.Value > 0, a => a.ProjectId == ProjectId)
                     .WhereIf(Salesman.NotNull(), a => a.Name.Contains(Salesman))
                     .WhereIf(SalesmanPhone.NotNull(), a => a.Phone.Contains(SalesmanPhone))
-                    .WhereIf(kuaKeStatus.NotNull(), a => a.Status.ToString().Contains(kuaKeStatus))
+                    //.WhereIf(kuaKeStatus.NotNull(), a => a.Status.ToString().Contains(kuaKeStatus))
+                    .Where(where)
                     .Where(a => a.TenantId == User.TenantId)
                     .OrderByDescending(a => a.CreatedTime)
                 .Count(out total)

+ 1 - 0
src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj

@@ -23,6 +23,7 @@
 		<PackageReference Include="FreeSql.Cloud" Version="1.6.5" />
 		<PackageReference Include="FreeSql.Repository" Version="3.2.693" />
 		<PackageReference Include="FreeScheduler" Version="1.1.0" />
+		<PackageReference Include="Gma.QrCodeNet" Version="0.4.1.2" />
 		<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
 		<PackageReference Include="Lazy.SlideCaptcha.Core" Version="2.0.0" />
 		<PackageReference Include="Mapster" Version="7.3.0" />

+ 9 - 1
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -5751,6 +5751,14 @@
             </summary>
             <returns></returns>
         </member>
+        <member name="M:ZhonTai.Admin.Services.DiTuiAPI.DiTuiAPIService.GetQRCode(System.String,System.Int32)">
+            <summary>
+            字符串转Qrcode
+            </summary>
+            <param name="content">要转二维码的内容</param>
+            <param name="moduleSize">二维码大小 25px 的倍数,默认9(既 225X225px)</param>
+            <returns></returns>
+        </member>
         <member name="M:ZhonTai.Admin.Services.DiTuiAPI.DiTuiAPIService.GetToken(ZhonTai.Admin.Services.Auth.Dto.AuthLoginOutput)">
             <summary>
             获得token
@@ -6070,7 +6078,7 @@
         </member>
         <member name="P:ZhonTai.Admin.Services.DiTuiAPI.Dto.ProjectQrcodePageInput.KuaKeStatus">
             <summary>
-            夸克类型状态 0 全部 1未报备 2 报备中 3 报备成功 4报备失败
+            夸克类型状态 0 全部 1 报备中 2 报备成功 3报备失败
             </summary>
         </member>
         <member name="P:ZhonTai.Admin.Services.DiTuiAPI.Dto.ProjectQrcodePageOutput.Id">

+ 4 - 0
src/platform/ZhonTai.ApiUI/ZhonTai.ApiUI.csproj

@@ -22,4 +22,8 @@
 	<ItemGroup>
 		<EmbeddedResource Include="src/dist/**/*" />
 	</ItemGroup>
+
+	<ItemGroup>
+	  <PackageReference Include="Gma.QrCodeNet" Version="0.4.1.2" />
+	</ItemGroup>
 </Project>

+ 1 - 0
src/platform/ZhonTai.Common/ZhonTai.Common.csproj

@@ -11,6 +11,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+	<PackageReference Include="Gma.QrCodeNet" Version="0.4.1.2" />
 	<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
 	<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
 	<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />

+ 4 - 0
src/platform/ZhonTai.DynamicApi/ZhonTai.DynamicApi.csproj

@@ -11,4 +11,8 @@
 	<ItemGroup>
 		<FrameworkReference Include="Microsoft.AspNetCore.App" />
 	</ItemGroup>
+
+	<ItemGroup>
+	  <PackageReference Include="Gma.QrCodeNet" Version="0.4.1.2" />
+	</ItemGroup>
 </Project>

+ 1 - 0
src/tests/ZhonTai.Tests/ZhonTai.Tests.csproj

@@ -6,6 +6,7 @@
 	</PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="Gma.QrCodeNet" Version="0.4.1.2" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.5" />
     <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.5" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />