|
@@ -0,0 +1,62 @@
|
|
|
+using Hotline.Application.Snapshot.Contracts;
|
|
|
+using Hotline.Orders;
|
|
|
+using Hotline.Share.Dtos.Snapshot;
|
|
|
+using Hotline.Share.Enums.CallCenter;
|
|
|
+using Hotline.Share.Enums.Snapshot;
|
|
|
+using Hotline.Share.Tools;
|
|
|
+using Hotline.Snapshot.IRepository;
|
|
|
+using SqlSugar;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using XF.Domain.Dependency;
|
|
|
+
|
|
|
+namespace Hotline.Application.Snapshot;
|
|
|
+
|
|
|
+public class PointsRecordApplication : IPointsRecordApplication, IScopeDependency
|
|
|
+{
|
|
|
+ private readonly ISnapshotPointsRecordRepository _snapshotPointsRecordRepository;
|
|
|
+ private readonly ICitizenRepository _citizenRepository;
|
|
|
+
|
|
|
+ public PointsRecordApplication(ISnapshotPointsRecordRepository snapshotPointsRecordRepository, ICitizenRepository citizenRepository)
|
|
|
+ {
|
|
|
+ _snapshotPointsRecordRepository = snapshotPointsRecordRepository;
|
|
|
+ _citizenRepository = citizenRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ISugarQueryable<PointsItemsOutDto> GetPointsItems(PointsItemsInDto dto)
|
|
|
+ {
|
|
|
+ var query = _snapshotPointsRecordRepository.Queryable()
|
|
|
+ .LeftJoin<Citizen>((points, citizen) => points.UserId == citizen.Id)
|
|
|
+ .WhereIF(dto.PhoneNumber.NotNullOrEmpty(), (points, citizen) => dto.PhoneNumber == citizen.PhoneNumber)
|
|
|
+ .Where((points, citizen) => points.CreationTime >= dto.StartTime && points.CreationTime <= dto.EndTime)
|
|
|
+ .GroupBy((points, citizen) => new { points.UserId, citizen.IsSecurityMax, citizen.Name, citizen.PhoneNumber })
|
|
|
+ .Select((points, citizen) => new PointsItemsOutDto
|
|
|
+ {
|
|
|
+ IsSecurityMax = citizen.IsSecurityMax ?? false,
|
|
|
+ Rank = SqlFunc.MappingColumn<int>("DENSE_RANK() OVER (ORDER BY SUM(CASE WHEN \"points\".\"Direction\" = 1 THEN \"points\".\"Points\" ELSE 0 END) DESC)"),
|
|
|
+ OutTotalPoint = SqlFunc.AggregateSum(SqlFunc.IIF(points.Direction == EPointsDirection.Out, points.Points, 0)),
|
|
|
+ OutPoints = SqlFunc.AggregateSum(SqlFunc.IIF(points.Direction == EPointsDirection.Out && points.Source == EPointsSource.Audit, points.Points, 0)),
|
|
|
+ TotalPoints = SqlFunc.AggregateSum(points.Points),
|
|
|
+ InTotalPoint = SqlFunc.AggregateSum(SqlFunc.IIF(points.Direction == EPointsDirection.In, points.Points, 0)),
|
|
|
+ UserName = citizen.Name,
|
|
|
+ PhoneNumber = citizen.PhoneNumber
|
|
|
+ })
|
|
|
+ .OrderByPropertyNameIF(dto.SortField.NotNullOrEmpty() && dto.SortRule == 0, dto.SortField, OrderByType.Desc)
|
|
|
+ .OrderByPropertyNameIF(dto.SortField.NotNullOrEmpty() && dto.SortRule == 1, dto.SortField, OrderByType.Asc);
|
|
|
+#if DEBUG
|
|
|
+ var sql = query.ToSqlString();
|
|
|
+#endif
|
|
|
+ return query;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task UpdateIsSecurityMaxAsync(UpdateIsSecurityMaxAsync dto, CancellationToken token)
|
|
|
+ {
|
|
|
+ await _citizenRepository.Updateable()
|
|
|
+ .SetColumns(citizen => citizen.IsSecurityMax, dto.IsSecurityMax)
|
|
|
+ .Where(citizen => citizen.Id == dto.UserId)
|
|
|
+ .ExecuteCommandAsync(token);
|
|
|
+ }
|
|
|
+}
|