|
@@ -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);
|
|
|
+ //}
|
|
|
+
|
|
|
}
|
|
|
}
|