소스 검색

Merge branch 'master' of https://git.zhongjie51.com/zhongjie51/99ditui

lifa 2 년 전
부모
커밋
03a5b6eaab

+ 0 - 18
.github/workflows/gitee-sync.yml

@@ -1,18 +0,0 @@
-name: Publish 
-on:
-    push:
-        branches:
-            - master
-            - dev
-            
-jobs:
-    build:
-        runs-on: ubuntu-latest
-        steps:
-            - name: Sync to Gitee 💕
-              uses: wearerequired/git-mirror-action@master
-              env:
-                  SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_HOME }}
-              with:
-                  source-repo: "git@github.com:zhontai/Admin.Core.git"
-                  destination-repo: "git@gitee.com:zhontai/Admin.Core.git"

+ 137 - 0
src/platform/ZhonTai.Admin/Core/Helpers/ExcelHelper.cs

@@ -0,0 +1,137 @@
+using OfficeOpenXml.Style;
+using OfficeOpenXml;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Dto;
+
+namespace ZhonTai.Admin.Core.Helpers
+{
+    public class ExcelHelper
+    {
+        //public static void DownloadExcel<T>(List<T> list, string sWebRootFolder, string FileName, bool isFirstCloumnName = true)
+        //{
+        //    try
+        //    {
+        //        //判断文件是否存在,不存在创建
+        //        if (!Directory.Exists(sWebRootFolder))
+        //            Directory.CreateDirectory(sWebRootFolder);
+
+        //        //创建默认文件
+        //        if (FileName.IsNull())
+        //        {
+        //            FileName = "Sheet1.xlsx";
+        //        }
+        //        if (!FileName.EndsWith(".xlsx"))
+        //        {
+        //            FileName += ".xlsx";
+        //        }
+        //        //判断同名文件
+        //        string filepath = Path.Combine(sWebRootFolder, FileName);
+        //        FileInfo file = new FileInfo(filepath);
+        //        if (file.Exists)
+        //        {
+        //            file.Delete();
+        //        }
+        //        using (ExcelPackage package = new ExcelPackage(file))
+        //        {
+        //            //添加 workesheet
+        //            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(FileName);
+
+        //            //添加数据
+        //            PropertyInfo[] props = typeof(T).GetProperties();
+        //            for (int i = 0; i < list.Count; i++)
+        //            {
+        //                worksheet.Row(i + 1).CustomHeight = true;//自动调整行高
+        //                for (int j = 0; j < props.Length; j++)
+        //                {
+        //                    //设置第一列
+        //                    if (isFirstCloumnName && i == 0)
+        //                    {
+        //                        worksheet.Cells[i + 1, j + 1].Style.Font.Bold = true;
+        //                        //worksheet.Cells[i + 1, j + 1].Style.WrapText = true;                                
+        //                    }
+
+        //                    worksheet.Cells[1, 1].Style.Font.Size = 12;//字体大小
+        //                    worksheet.Cells[i + 1, j + 1].Style.Font.Name = "微软雅黑";//字体
+        //                    worksheet.Cells[i + 1, j + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
+        //                    worksheet.Cells[i + 1, j + 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
+        //                    //设置单元格内容 
+        //                    var v = props[j].GetValue(list[i]);
+        //                    string val = v == null ? "" : v.ToString();
+        //                    worksheet.Cells[i + 1, j + 1].Value = props[j].GetValue(list[i]);
+        //                }
+        //            }
+        //            worksheet.Cells.Style.ShrinkToFit = true;//单元格自动适应大小                    
+        //            package.Save();
+        //        }
+        //        return ResultOutput.Ok(filepath, "导出成功");
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        return ResultOutput.NotOk("导出失败");
+        //    }
+        //}
+
+        /// <summary>
+        /// 导入
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="FileName"></param>
+        /// <returns></returns>
+        public static IEnumerable<T> LoadFromExcel<T>(string FileName) where T : new()
+        {
+            FileInfo existingFile = new FileInfo(FileName);
+            List<T> resultList = new List<T>();
+            Dictionary<string, int> dicHeader = new Dictionary<string, int>();
+            using (ExcelPackage package = new ExcelPackage(existingFile))
+            {
+                ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
+                int colstart = worksheet.Dimension.Start.Column;
+                int colend = worksheet.Dimension.End.Column;
+                int rowstart = worksheet.Dimension.Start.Row;
+                int rowend = worksheet.Dimension.End.Row;
+
+                for (int i = colstart; i <= colend; i++)
+                {
+                    dicHeader[worksheet.Cells[rowstart, i].Value.ToString()] = i;
+                }
+
+                List<PropertyInfo> propertyInfosList = new List<PropertyInfo>(typeof(T).GetProperties());
+                for (int row = rowstart + 1; row <= rowend; row++)
+                {
+                    T result = new T();
+                    foreach (PropertyInfo p in propertyInfosList)
+                    {
+                        try
+                        {
+                            ExcelRange cell = worksheet.Cells[row, dicHeader[p.Name]];
+                            if (cell.Value == null)
+                                continue;
+                            switch (p.PropertyType.Name.ToLower())
+                            {
+                                case "string":
+                                    p.SetValue(result, cell.GetValue<string>());
+                                    break;
+                                default:
+                                    break;
+                            }
+                        }
+                        catch (Exception)
+                        {
+
+                            throw;
+                        }
+                    }
+                    resultList.Add(result);
+                }
+            }
+            return resultList;
+        }
+    }
+}

+ 13 - 0
src/platform/ZhonTai.Admin/Services/ProjectLink/Dto/LinkExcelInput.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.ProjectLink.Dto
+{
+    public class LinkExcelInput
+    {
+        public int MyProperty { get; set; }
+    }
+}

+ 24 - 0
src/platform/ZhonTai.Admin/Services/ProjectLink/Dto/ProjectLinkGetPageDto.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.ProjectLink.Dto
+{
+    public class ProjectLinkGetPageDto
+    {
+        /// <summary>
+        /// 是否使用 1使用 0未使用
+        /// </summary>
+        public int IsUse { get; set; }
+        /// <summary>
+        /// 公司
+        /// </summary>
+        public string Company { get; set; }
+        /// <summary>
+        /// 关键字 编号,业务员姓名,手机号
+        /// </summary>
+        public string Keywords { get; set; }
+    }
+}

+ 69 - 0
src/platform/ZhonTai.Admin/Services/ProjectLink/Dto/ProjectLinkListOutput.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.ProjectLink.Dto
+{
+    public class ProjectLinkListOutput
+    {
+        /// <summary>
+        /// 公司(推广码来源)
+        /// </summary>
+        public string Company { get; set; }
+        /// <summary>
+        /// 所属平台
+        /// </summary>
+        public string OrgName { get; set; }
+        /// <summary>
+        /// 二维码类型
+        /// </summary>
+        public string QrcodeType { get; set; }
+        /// <summary>
+        /// 编号
+        /// </summary>
+        public string Num { get; set; }
+        /// <summary>
+        /// 短链
+        /// </summary>
+        public string ShortUrl { get; set; }
+        /// <summary>
+        /// 二维码链接
+        /// </summary>
+        public string QrcodeUrl { get; set; }
+        /// <summary>
+        /// 推广口令
+        /// </summary>
+        public string ShareCommand { get; set; }
+        /// <summary>
+        /// 是否使用 1使用
+        /// </summary>
+        public int IsUse { get; set; }
+        /// <summary>
+        /// 使用时间
+        /// </summary>
+        public DateTime UseTime { get; set; }
+        /// <summary>
+        /// 业务员姓名
+        /// </summary>
+        public string Salesman { get; set; }
+        /// <summary>
+        /// 业务员手机号
+        /// </summary>
+        public string SalesmanPhone { get; set; }
+        /// <summary>
+        /// 业务员省
+        /// </summary>
+        public string SalesmanProvince { get; set; }
+        /// <summary>
+        /// 业务员市
+        /// </summary>
+        public string SalesmanCity { get; set; }
+        /// <summary>
+        /// 业务员备注
+        /// </summary>
+        public string SalesmanRemark { get; set; }
+        public long TenantId { get; set; }
+    }
+}

+ 184 - 1
src/platform/ZhonTai.Admin/Services/ProjectLink/ProjectLinkService.cs

@@ -1,14 +1,197 @@
-using System;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using OnceMi.AspNetCore.OSS;
+using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Configs;
+using ZhonTai.Admin.Core.Consts;
+using ZhonTai.Admin.Core.Dto;
+using ZhonTai.Admin.Core.Helpers;
+using ZhonTai.Admin.Domain.File;
+using ZhonTai.Admin.Domain.ProjectLink;
+using ZhonTai.Admin.Repositories;
 using ZhonTai.Admin.Services.Project;
+using ZhonTai.Admin.Services.ProjectLink.Dto;
+using ZhonTai.Common.Files;
+using ZhonTai.Common.Helpers;
 using ZhonTai.DynamicApi;
 
 namespace ZhonTai.Admin.Services.ProjectLink
 {
+    /// <summary>
+    /// 项目推广码服务
+    /// </summary>
     public class ProjectLinkService : BaseService, IProjectLinkService, IDynamicApi
     {
+        private IProjectLinkRepository _ProjectLinkRepository => LazyGetRequiredService<IProjectLinkRepository>();
+        private OSSConfig _oSSConfig => LazyGetRequiredService<IOptions<OSSConfig>>().Value;
+        private IHttpContextAccessor _httpContextAccessor => LazyGetRequiredService<IHttpContextAccessor>();
+
+        public ProjectLinkService()
+        {
+        }
+
+        ///// <summary>
+        ///// 查询模块
+        ///// </summary>
+        ///// <param name="id"></param>
+        ///// <returns></returns>
+        //public async Task<ProjectLinkGetOutput> GetAsync(long id)
+        //{
+        //    var result = await _ProjectLinkRepository.GetAsync<ProjectLinkGetOutput>(id);
+        //    return result;
+        //}
+
+        /// <summary>
+        /// 查询分页
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<PageOutput<ProjectLinkListOutput>> GetPageAsync(PageInput<ProjectLinkGetPageDto> input)
+        {
+            var IsUse = input.Filter?.IsUse;
+            var Company = input.Filter?.Company;
+            var key = input.Filter?.Keywords;
+
+            var list = await _ProjectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant)
+                .WhereIf(IsUse.HasValue && IsUse.Value >= 0, a => a.IsUse == IsUse)
+                .WhereIf(Company.NotNull(), a => a.Company == Company)
+            .WhereIf(key.NotNull(), a => a.Num == key || a.Salesman == key || a.SalesmanPhone == key)
+            .Count(out var total)
+            .OrderByDescending(true, c => c.Id)
+            .Page(input.CurrentPage, input.PageSize)
+            .ToListAsync(m => new ProjectLinkListOutput()
+            {
+                Company = m.Company,
+                OrgName = m.TenantId.ToString(),
+                Num = m.Num,
+                ShortUrl = m.ShortUrl,
+                QrcodeUrl = m.QrcodeUrl,
+                ShareCommand = m.ShareCommand,
+                IsUse = m.IsUse,
+                UseTime = m.UseTime,
+                Salesman = m.Salesman,
+                SalesmanPhone = m.SalesmanPhone,
+                SalesmanRemark = m.SalesmanRemark,
+            });
+
+            var data = new PageOutput<ProjectLinkListOutput>()
+            {
+                List = list,
+                Total = total
+            };
+
+            return data;
+        }
+        /// <summary>
+        /// 上传推广码文件
+        /// </summary>
+        /// <param name="file">文件</param>
+        /// <param name="ProjectId">文件目录</param>
+        /// <param name="Company">文件重命名</param>
+        /// <returns></returns>
+        public async Task UploadLinkAsync([Required] IFormFile file,[Required] long ProjectId, [Required] string Company)
+        {
+            var localUploadConfig = _oSSConfig.LocalUploadConfig;
+
+            var extention = Path.GetExtension(file.FileName).ToLower();
+            if (extention != "excel")
+            {
+                throw new Exception($"请上传excel格式文件");
+            }
+            var hasIncludeExtension = localUploadConfig.IncludeExtension?.Length > 0;
+            if (hasIncludeExtension && !localUploadConfig.IncludeExtension.Contains(extention))
+            {
+                throw new Exception($"不允许上传{extention}文件格式");
+            }
+            var hasExcludeExtension = localUploadConfig.ExcludeExtension?.Length > 0;
+            if (hasExcludeExtension && localUploadConfig.ExcludeExtension.Contains(extention))
+            {
+                throw new Exception($"不允许上传{extention}文件格式");
+            }
+
+            var fileLenth = file.Length;
+            if (fileLenth > localUploadConfig.MaxSize)
+            {
+                throw new Exception($"文件大小不能超过{new FileSize(localUploadConfig.MaxSize)}");
+            }
+            if (ProjectId <= 0) { 
+
+            }
+
+            string fileDirectory = "link";
+
+            string SaveFileName = FreeUtil.NewMongodbId().ToString();
+
+            var filePath = Path.Combine(fileDirectory, SaveFileName + extention).ToPath();
+
+            var uploadHelper = LazyGetRequiredService<UploadHelper>();
+            var env = LazyGetRequiredService<IWebHostEnvironment>();
+            fileDirectory = Path.Combine(env.WebRootPath, fileDirectory).ToPath();
+            if (!Directory.Exists(fileDirectory))
+            {
+                Directory.CreateDirectory(fileDirectory);
+            }
+            filePath = Path.Combine(env.WebRootPath, filePath).ToPath();
+            await uploadHelper.SaveAsync(file, filePath);
+
+            var list= ExcelHelper.LoadFromExcel<LinkExcelInput>(filePath);            
+        }
+
+        ///// <summary>
+        ///// 修改
+        ///// </summary>
+        ///// <param name="input"></param>
+        ///// <returns></returns>
+        //public async Task UpdateAsync(ProjectLinkUpdateInput input)
+        //{
+        //    var entity = await _ProjectLinkRepository.GetAsync(input.Id);
+        //    if (!(entity?.Id > 0))
+        //    {
+        //        throw ResultOutput.Exception("模块不存在");
+        //    }
+
+        //    Mapper.Map(input, entity);
+        //    await _ProjectLinkRepository.UpdateAsync(entity);
+        //}
+
+        ///// <summary>
+        ///// 彻底删除
+        ///// </summary>
+        ///// <param name="id"></param>
+        ///// <returns></returns>
+        //public async Task DeleteAsync(long id)
+        //{
+        //    await _ProjectLinkRepository.DeleteAsync(m => m.Id == id);
+        //}
+
+        ///// <summary>
+        ///// 删除
+        ///// </summary>
+        ///// <param name="id"></param>
+        ///// <returns></returns>
+        //public async Task SoftDeleteAsync(long id)
+        //{
+        //    await _ProjectLinkRepository.SoftDeleteAsync(id);
+        //}
+
+        ///// <summary>
+        ///// 批量删除
+        ///// </summary>
+        ///// <param name="ids"></param>
+        ///// <returns></returns>
+        //public async Task BatchSoftDeleteAsync(long[] ids)
+        //{
+        //    await _ProjectLinkRepository.SoftDeleteAsync(ids);
+        //}
+
     }
 }

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

@@ -11,6 +11,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+	<PackageReference Include="EPPlus" Version="6.2.3" />
 	<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" />