|
@@ -0,0 +1,195 @@
|
|
|
+using NPOI.SS.Formula.PTG;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using ZhonTai.Admin.Core.Consts;
|
|
|
+using ZhonTai.Admin.Services.Project;
|
|
|
+using ZhonTai.DynamicApi.Attributes;
|
|
|
+using ZhonTai.DynamicApi;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using ZhonTai.Admin.Core.Dto;
|
|
|
+using ZhonTai.Admin.Services.ProjectLink.Dto;
|
|
|
+using ZhonTai.Admin.Domain.Org;
|
|
|
+using ZhonTai.Admin.Domain.KuaKe;
|
|
|
+using ZhonTai.Admin.Domain.Tenant;
|
|
|
+using ZhonTai.Admin.Domain.Platform;
|
|
|
+using ZhonTai.Admin.Services.AdKuake.Dto;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
+using ZhonTai.Admin.Core.Auth;
|
|
|
+using ZhonTai.Admin.Core.Entities;
|
|
|
+using ZhonTai.Admin.Domain.Project;
|
|
|
+using ZhonTai.Admin.Services.Project.Dto;
|
|
|
+using ZhonTai.Admin.Core.Helpers;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
+using System.IO;
|
|
|
+using Yitter.IdGenerator;
|
|
|
+using ZhonTai.Admin.Domain.File;
|
|
|
+
|
|
|
+namespace ZhonTai.Admin.Services.AdKuake
|
|
|
+{
|
|
|
+ public class IAdKuaKeService
|
|
|
+ {
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 夸克后端服务
|
|
|
+ /// </summary>
|
|
|
+ [Order(10)]
|
|
|
+ [DynamicApi(Area = AdminConsts.AreaName)]
|
|
|
+ public partial class AdKuaKeService : BaseService, IProjectService, IDynamicApi
|
|
|
+ {
|
|
|
+ private IKuaKeRepository _kuaKeRepository => LazyGetRequiredService<IKuaKeRepository>();
|
|
|
+ private IHttpContextAccessor _httpContextAccessor => LazyGetRequiredService<IHttpContextAccessor>();
|
|
|
+
|
|
|
+ public AdKuaKeService()
|
|
|
+ {
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 查询分页
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ public async Task<PageOutput<AdKuaKePageOutput>> GetPageAsync(PageInput<AdKuaKePageInput> input)
|
|
|
+ {
|
|
|
+ var BeginDate = input.Filter?.BeginDate;
|
|
|
+ var EndDate = input.Filter?.EndDate;
|
|
|
+ var TenantId = input.Filter?.TenantId;
|
|
|
+ var Status = input.Filter?.Status;
|
|
|
+ var key = input.Filter?.Keyword;
|
|
|
+
|
|
|
+ var list =await _kuaKeRepository.Select.From<TenantEntity, OrgEntity, PlatformUserEntity>(
|
|
|
+ (kuake, tenant, org, user) => kuake.LeftJoin(m => m.TenantId == tenant.Id)
|
|
|
+ .LeftJoin(m => m.UserId == user.Id)
|
|
|
+ .LeftJoin(m => tenant.OrgId == org.Id)
|
|
|
+ .WhereIf(BeginDate.HasValue, m => m.CreatedTime >= BeginDate)
|
|
|
+ .WhereIf(EndDate.HasValue, m => m.CreatedTime <= EndDate)
|
|
|
+ .WhereIf(TenantId.HasValue && TenantId.Value > 0, m => m.TenantId == TenantId)
|
|
|
+ .WhereIf(Status.HasValue && Status > 0, m => m.Status >= Status)
|
|
|
+ .WhereIf(!string.IsNullOrEmpty(key), m => m.KuaKeID == key || m.Name == key || m.Phone == key)
|
|
|
+ )
|
|
|
+ .DisableGlobalFilter(FilterNames.Tenant)
|
|
|
+ .OrderByDescending((kuake, tenant, org, user) => kuake.CreatedTime)
|
|
|
+ .OrderByDescending((kuake, tenant, org, user) => kuake.Id)
|
|
|
+ .Count(out var total)
|
|
|
+ .Page(input.CurrentPage, input.PageSize)
|
|
|
+ .ToListAsync((kuake, tenant, org, user) => new AdKuaKePageOutput()
|
|
|
+ {
|
|
|
+ Id = kuake.Id,
|
|
|
+ OrgName = org.Name,
|
|
|
+ UserName = user.Name,
|
|
|
+ UserRole=user.Role,
|
|
|
+ CreatedTime = kuake.CreatedTime.Value,
|
|
|
+ KuaKeID = kuake.KuaKeID,
|
|
|
+ Name = kuake.Name,
|
|
|
+ Phone = kuake.Phone,
|
|
|
+ Industry = kuake.Industry,
|
|
|
+ Platfrom = kuake.Platfrom,
|
|
|
+ Status = kuake.Status
|
|
|
+ });
|
|
|
+
|
|
|
+ var data = new PageOutput<AdKuaKePageOutput>()
|
|
|
+ {
|
|
|
+ List = list,
|
|
|
+ Total = total
|
|
|
+ };
|
|
|
+
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 更新状态
|
|
|
+ /// </summary>
|
|
|
+ ///<param name="Id"></param>
|
|
|
+ ///<param name="status">状态 2成功 3失败</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task UpdateStatusAsync(UpdateKuaKeStatusInput input)
|
|
|
+ {
|
|
|
+ if (!(input?.Ids.Count() > 0))
|
|
|
+ {
|
|
|
+ throw ResultOutput.Exception("请选择操作信息");
|
|
|
+ }
|
|
|
+ if (!new int[] { 2, 3 }.Contains(input.Status))
|
|
|
+ {
|
|
|
+ throw ResultOutput.Exception("请做出有效操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ var count = await _kuaKeRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => input.Ids.Contains(m.Id) && m.Status == 1).CountAsync();
|
|
|
+ if (input.Ids.Count != count)
|
|
|
+ {
|
|
|
+ throw ResultOutput.Exception("部分数据状态已更新,请刷新后重试");
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新项目
|
|
|
+ var result = await _kuaKeRepository.UpdateDiy.SetDto(
|
|
|
+ new
|
|
|
+ {
|
|
|
+ Status = input.Status,
|
|
|
+ })
|
|
|
+ .Where(m => input.Ids.Contains(m.Id) && m.Status == 1).DisableGlobalFilter(FilterNames.Tenant).ExecuteAffrowsAsync();
|
|
|
+ if (result <= 0)
|
|
|
+ {
|
|
|
+ throw ResultOutput.Exception("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 导出Excel
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ public async Task<string> GetExcelAsync(PageInput<AdKuaKePageInput> input)
|
|
|
+ {
|
|
|
+ var BeginDate = input.Filter?.BeginDate;
|
|
|
+ var EndDate = input.Filter?.EndDate;
|
|
|
+ var TenantId = input.Filter?.TenantId;
|
|
|
+ var Status = input.Filter?.Status;
|
|
|
+ var key = input.Filter?.Keyword;
|
|
|
+
|
|
|
+ var list = await _kuaKeRepository.Select
|
|
|
+ .WhereIf(BeginDate.HasValue, m => m.CreatedTime >= BeginDate)
|
|
|
+ .WhereIf(EndDate.HasValue, m => m.CreatedTime <= EndDate)
|
|
|
+ .WhereIf(TenantId.HasValue && TenantId.Value > 0, m => m.TenantId == TenantId)
|
|
|
+ .WhereIf(Status.HasValue && Status > 0, m => m.Status >= Status)
|
|
|
+ .WhereIf(!string.IsNullOrEmpty(key), m => m.KuaKeID == key || m.Name == key || m.Phone == key)
|
|
|
+ .DisableGlobalFilter(FilterNames.Tenant)
|
|
|
+ .OrderByDescending(m => m.CreatedTime)
|
|
|
+ .OrderByDescending(m => m.Id)
|
|
|
+ .ToListAsync(m => new AdKuaKeExcelOutput()
|
|
|
+ {
|
|
|
+ CreatedTime = m.CreatedTime.Value.ToString("yyyy-MM-dd HH:mm"),
|
|
|
+ KuaKeID = m.KuaKeID,
|
|
|
+ Name = m.Name,
|
|
|
+ Industry = m.Industry,
|
|
|
+ Platfrom = m.Platfrom
|
|
|
+ });
|
|
|
+ //导入数据
|
|
|
+ list.Insert(0,new AdKuaKeExcelOutput() {
|
|
|
+ KuaKeID="夸克ID",
|
|
|
+ Name= "姓名",
|
|
|
+ Industry= "行业",
|
|
|
+ Platfrom= "推广平台",
|
|
|
+ CreatedTime= "申请时间"
|
|
|
+ });
|
|
|
+ var json=Newtonsoft.Json.JsonConvert.SerializeObject(list);
|
|
|
+ var env = LazyGetRequiredService<IWebHostEnvironment>();
|
|
|
+
|
|
|
+ string filename = FreeUtil.NewMongodbId() + ".xlsx";
|
|
|
+ string filepath = "kuake" + Path.DirectorySeparatorChar + DateTime.Today.ToString("yyyyMMdd");
|
|
|
+ var path = Path.Combine(env.WebRootPath, filepath).ToPath();
|
|
|
+ if (!Directory.Exists(path))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(path);
|
|
|
+ }
|
|
|
+ path = path + Path.DirectorySeparatorChar + filename;
|
|
|
+
|
|
|
+ NOPIHelper.WriteExcel(json,path,1);
|
|
|
+
|
|
|
+ string url= $"{_httpContextAccessor.HttpContext.Request.Scheme}://{_httpContextAccessor.HttpContext.Request.Host.Value}/{filepath}/{filename}";
|
|
|
+
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|