|
@@ -2921,37 +2921,104 @@ namespace Hotline.Api.Controllers.Bi
|
|
|
public async Task<object> HotspotAndAreaStatistics([FromQuery]HotspotAndAreaStatisticsReq dto)
|
|
|
{
|
|
|
dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
|
|
|
- var areaList = await _systemOrganizeRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == 6).ToListAsync();
|
|
|
- List<dynamic> list = new List<dynamic>();
|
|
|
+ var areaList = await _systemAreaRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == 6 && x.Id!= "510000").OrderBy(x=>x.Id).ToListAsync();
|
|
|
+ List<dynamic> returnList = new List<dynamic>();
|
|
|
foreach (var item in areaList)
|
|
|
{
|
|
|
- var table =await _orderRepository.Queryable()
|
|
|
- .Where(x => x.CreationTime >= dto.StartTime && x.CreationTime < dto.EndTime && x.AreaCode.StartsWith(item.Id))
|
|
|
- .GroupByIF(dto.HotspotLevel == 1, x => new {
|
|
|
- HotspotId = x.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2"))
|
|
|
- })
|
|
|
- .GroupByIF(dto.HotspotLevel == 2, x => new {
|
|
|
- HotspotId = x.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("4"))
|
|
|
- })
|
|
|
- .GroupByIF(dto.HotspotLevel == 3, x => new {
|
|
|
- HotspotId = x.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
|
|
|
- })
|
|
|
- .GroupByIF(dto.HotspotLevel == 4, x => new {
|
|
|
- HotspotId = x.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"),SqlFunc.MappingColumn<int>("8"))
|
|
|
- })
|
|
|
- .Select(x => new {
|
|
|
- HotspotId = SqlFunc.IIF(dto.HotspotLevel == 1, x.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")),
|
|
|
- SqlFunc.IIF(dto.HotspotLevel == 2, x.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("4")),
|
|
|
- SqlFunc.IIF(dto.HotspotLevel == 3, x.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
|
|
|
- SqlFunc.IIF(dto.HotspotLevel == 4, x.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("8")), "")))),
|
|
|
- Key = item.Id,
|
|
|
- AreaName = item.AreaName,
|
|
|
- Count = 1//SqlFunc.AggregateSum(SqlFunc.IIF(x.Hotspot.))
|
|
|
- }).ToPivotListAsync(x=>x.Key,x=> new { x.HotspotId,x.AreaName},x=>x.Sum(x=> x.Count));
|
|
|
- list.AddRange(table);
|
|
|
- }
|
|
|
+ List<dynamic> list = new List<dynamic>();
|
|
|
|
|
|
- return new { AreaList = areaList,Data = list};
|
|
|
+ switch (dto.HotspotLevel)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ list = await _orderRepository.Queryable()
|
|
|
+ .LeftJoin<Hotspot>((it, o) => it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")) == o.Id)
|
|
|
+ .Where((it, o) => it.CreationTime >= dto.StartTime && it.CreationTime < dto.EndTime && it.AreaCode.StartsWith(item.Id) && SqlFunc.Length(it.HotspotId)>=2)
|
|
|
+ .GroupBy((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")),
|
|
|
+ o.HotSpotFullName,
|
|
|
+ o.OrderBy
|
|
|
+ })
|
|
|
+ .OrderBy((it,o)=> new {
|
|
|
+ o.OrderBy
|
|
|
+ } )
|
|
|
+ .Select((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")),
|
|
|
+ Key = item.Id,
|
|
|
+ HotSpotNameOne = o.HotSpotFullName,
|
|
|
+ Count = SqlFunc.AggregateCount(o.HotSpotFullName)
|
|
|
+ }).ToPivotListAsync(x => x.Key, x => new { x.HotspotId, x.HotSpotNameOne }, x => x.Sum(x => x.Count));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ list = await _orderRepository.Queryable()
|
|
|
+ .LeftJoin<Hotspot>((it, o) => it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("4")) == o.Id)
|
|
|
+ .Where((it, o) => it.CreationTime >= dto.StartTime && it.CreationTime < dto.EndTime && it.AreaCode.StartsWith(item.Id) && SqlFunc.Length(it.HotspotId) >= 4)
|
|
|
+ .GroupBy((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("4")),
|
|
|
+ o.HotSpotFullName,
|
|
|
+ o.OrderBy
|
|
|
+ })
|
|
|
+ .OrderBy((it, o) => new {
|
|
|
+ o.OrderBy
|
|
|
+ })
|
|
|
+ .Select((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("4")),
|
|
|
+ Key = item.Id,
|
|
|
+ HotSpotName = o.HotSpotFullName,
|
|
|
+ Count = SqlFunc.AggregateCount(o.HotSpotFullName)
|
|
|
+ }).ToPivotListAsync(x => x.Key, x => new { x.HotspotId, x.HotSpotName }, x => x.Sum(x => x.Count));
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ list = await _orderRepository.Queryable()
|
|
|
+ .LeftJoin<Hotspot>((it, o) => it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
|
|
|
+ .Where((it, o) => it.CreationTime >= dto.StartTime && it.CreationTime < dto.EndTime && it.AreaCode.StartsWith(item.Id) && SqlFunc.Length(it.HotspotId) >= 6)
|
|
|
+ .GroupBy((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
|
|
|
+ o.HotSpotFullName,
|
|
|
+ o.OrderBy
|
|
|
+ })
|
|
|
+ .OrderBy((it, o) => new {
|
|
|
+ o.OrderBy
|
|
|
+ })
|
|
|
+ .Select((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
|
|
|
+ Key = item.Id,
|
|
|
+ HotSpotName = o.HotSpotFullName,
|
|
|
+ Count = SqlFunc.AggregateCount(o.HotSpotFullName)
|
|
|
+ }).ToPivotListAsync(x => x.Key, x => new { x.HotspotId, x.HotSpotName }, x => x.Sum(x => x.Count));
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ list = await _orderRepository.Queryable()
|
|
|
+ .LeftJoin<Hotspot>((it, o) => it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("8")) == o.Id && SqlFunc.Length(it.HotspotId) >= 8)
|
|
|
+ .Where((it, o) => it.CreationTime >= dto.StartTime && it.CreationTime < dto.EndTime && it.AreaCode.StartsWith(item.Id))
|
|
|
+ .GroupBy((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("8")),
|
|
|
+ o.HotSpotFullName,
|
|
|
+ o.OrderBy
|
|
|
+ })
|
|
|
+ .OrderBy((it, o) => new {
|
|
|
+ o.OrderBy
|
|
|
+ })
|
|
|
+ .Select((it, o) => new
|
|
|
+ {
|
|
|
+ HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("8")),
|
|
|
+ Key = item.Id,
|
|
|
+ HotSpotName = o.HotSpotFullName,
|
|
|
+ Count = SqlFunc.AggregateCount(o.HotSpotFullName)
|
|
|
+ }).ToPivotListAsync(x => x.Key, x => new { x.HotspotId, x.HotSpotName }, x => x.Sum(x => x.Count));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ returnList.AddRange(list);
|
|
|
+ }
|
|
|
+ return new { AreaList = areaList,Data = returnList };
|
|
|
}
|
|
|
}
|
|
|
|