|
@@ -1,11 +1,13 @@
|
|
|
using FluentValidation.Results;
|
|
|
using Hotline.FlowEngine.Workflows;
|
|
|
using Hotline.Orders;
|
|
|
+using Hotline.Settings.Hotspots;
|
|
|
using Hotline.Share.Attributes;
|
|
|
using Hotline.Share.Dtos.Snapshot;
|
|
|
using Hotline.Share.Enums.FlowEngine;
|
|
|
using Hotline.Share.Enums.Order;
|
|
|
using Hotline.Share.Enums.Snapshot;
|
|
|
+using Hotline.Share.Tools;
|
|
|
using Hotline.Snapshot;
|
|
|
using Hotline.Snapshot.Interfaces;
|
|
|
using Hotline.Tools;
|
|
@@ -17,26 +19,66 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using XF.Domain.Authentications;
|
|
|
using XF.Domain.Dependency;
|
|
|
using XF.Domain.Exceptions;
|
|
|
+using XF.Domain.Repository;
|
|
|
using static NPOI.SS.Format.CellNumberFormatter;
|
|
|
|
|
|
namespace Hotline.Application.Snapshot;
|
|
|
public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
|
|
|
{
|
|
|
- public readonly IOrderSnapshotRepository _orderSnapshotRepository;
|
|
|
- public readonly IRedPackRecordRepository _redPackRecordRepository;
|
|
|
- public readonly IIndustryRepository _industryRepository;
|
|
|
- public readonly IIndustryCaseRepository _industryCaseRepository;
|
|
|
- public readonly IRedPackAuditRepository _redPackAuditRepository;
|
|
|
+ private readonly IOrderSnapshotRepository _orderSnapshotRepository;
|
|
|
+ private readonly IRedPackRecordRepository _redPackRecordRepository;
|
|
|
+ private readonly IIndustryRepository _industryRepository;
|
|
|
+ private readonly IIndustryCaseRepository _industryCaseRepository;
|
|
|
+ private readonly IRedPackAuditRepository _redPackAuditRepository;
|
|
|
+ private readonly IRepository<Hotspot> _hotspotTypeRepository;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
|
|
|
- public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository)
|
|
|
+ public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository, IRepository<Hotspot> hotspotTypeRepository, ISessionContext sessionContext)
|
|
|
{
|
|
|
_orderSnapshotRepository = orderSnapshotRepository;
|
|
|
_redPackRecordRepository = redPackRecordRepository;
|
|
|
_industryRepository = industryRepository;
|
|
|
_industryCaseRepository = industryCaseRepository;
|
|
|
_redPackAuditRepository = redPackAuditRepository;
|
|
|
+ _hotspotTypeRepository = hotspotTypeRepository;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ISugarQueryable<HotspotStatisticsOutDto> GetHotspotStatistics(HotspotStatisticsInDto dto)
|
|
|
+ {
|
|
|
+ var IsCenter = _sessionContext.OrgIsCenter;
|
|
|
+ string count = "2";
|
|
|
+ string countx = string.Empty;
|
|
|
+ if (dto.HotspotCode.NotNullOrEmpty())
|
|
|
+ {
|
|
|
+ count = (dto.HotspotCode.Length + 2).ToString();
|
|
|
+ dto.HotspotCode.Length.ToString();
|
|
|
+ }
|
|
|
+ return _hotspotTypeRepository.Queryable()
|
|
|
+ .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
|
|
|
+ .LeftJoin<OrderSnapshot>((it, o, s) => o.Id == s.Id)
|
|
|
+ .Where((it, o, s) => o.CreationTime >= dto.StartTime && o.CreationTime <= dto.EndTime && s.Id != null)
|
|
|
+ .WhereIF(dto.HotspotCode.IsNullOrEmpty(), (it, o) => o.Id != null)
|
|
|
+ .WhereIF(dto.HotspotCode.NotNullOrEmpty(), (it, o) => it.ParentId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(countx)) == dto.HotspotCode)
|
|
|
+ .WhereIF(IsCenter == false, (it, o) => o.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
|
|
|
+ .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)) })
|
|
|
+ .Select((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)),
|
|
|
+ SumCount = SqlFunc.AggregateCount(it.HotSpotName)
|
|
|
+ })
|
|
|
+ .MergeTable()
|
|
|
+ .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
|
|
|
+ .Select((x, q) => new HotspotStatisticsOutDto
|
|
|
+ {
|
|
|
+ HotspotCode = x.HotspotCode,
|
|
|
+ SumCount = x.SumCount,
|
|
|
+ HotspotName = q.HotSpotName,
|
|
|
+ HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -109,7 +151,7 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
|
|
|
if (industry.CaseName == industry.Name)
|
|
|
industry.IndustryName = $"{industry.Name}({industry.ShouldAmount?.ToString("f2")})";
|
|
|
else
|
|
|
- {
|
|
|
+ {
|
|
|
industry.IndustryName = $"{industry.Name}-{industry.CaseName}({industry.ShouldAmount?.ToString("f2")})";
|
|
|
}
|
|
|
}
|