|
|
|
|
@ -3,7 +3,6 @@ using Common.Shared.Application.SafetyFirePro.RequestDto; |
|
|
|
|
using Common.Shared.Application.SafetyFirePro.ResponseDto; |
|
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
|
using MongoDB.Bson.IO; |
|
|
|
|
using System.Text.Json; |
|
|
|
|
using ThirdPartyServices.Application.ShenZhouShengAn.RequestDto; |
|
|
|
|
using ThirdPartyServices.Application.ShenZhouShengAn.ResponseDto; |
|
|
|
|
@ -502,5 +501,156 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 获得危险作业(施工)数据统计 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="dto"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
/// <exception cref="NotImplementedException"></exception> |
|
|
|
|
public async Task<ApiResult<List<StatisticsInfoDto>>> GetStatistics(WorkTaskQueryParamsDto dto) |
|
|
|
|
{ |
|
|
|
|
ApiResult<List<StatisticsInfoDto>> result = new ApiResult<List<StatisticsInfoDto>>() { Code = 200, Msg = "接口调用成功", Data = null }; |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
//获取token |
|
|
|
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
|
|
|
if (string.IsNullOrWhiteSpace(token)) |
|
|
|
|
{ |
|
|
|
|
_logger.LogWarning("GetStatistics接口获取token失败"); |
|
|
|
|
return ApiResult<List<StatisticsInfoDto>>.IsFail("GetStatistics接口获取token失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取用户配置 |
|
|
|
|
HttpClientResult<LoginUsersConfiguration> loginUsers = await _tokenProviderService.GetUserConfiguration(token); |
|
|
|
|
if (loginUsers.Code == "Error") |
|
|
|
|
{ |
|
|
|
|
_logger.LogWarning("GetStatistics接口获取用户配置失败"); |
|
|
|
|
return ApiResult<List<StatisticsInfoDto>>.IsFail("GetStatistics接口获取用户配置失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取单位信息 |
|
|
|
|
HttpClientResult<BranchResDto> branchs = await _tokenProviderService.GetBranchPermissions(token, loginUsers.Data.Uid); |
|
|
|
|
if (branchs.Code == "Error") |
|
|
|
|
{ |
|
|
|
|
_logger.LogWarning("GetStatistics接口获取单位信息失败"); |
|
|
|
|
return ApiResult<List<StatisticsInfoDto>>.IsFail("GetStatistics接口获取单位信息失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dto.Ubpid = loginUsers.Data.Ubpid.ToString(); |
|
|
|
|
List<StatisticsInfoDto> data = []; |
|
|
|
|
if (dto.Type == 1) |
|
|
|
|
{ |
|
|
|
|
//查询未开始,status=1、2 |
|
|
|
|
int[] statusNot = [1, 2, 3, 4, 6, 7, 8, 11, 12, 13]; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < statusNot.Length; i++) |
|
|
|
|
{ |
|
|
|
|
dto.Status = statusNot[i].ToString(); |
|
|
|
|
dto.Page = 1; |
|
|
|
|
dto.PageSize = 1; |
|
|
|
|
HttpClientResult<object> riskResult = await _tokenProviderService |
|
|
|
|
.SendAndParseAsync<WorkTaskQueryParamsDto, HttpClientResult<object>>( |
|
|
|
|
"https://zrh.szdunan.cn/v1/api/ticket/safe/ledger", |
|
|
|
|
token, dto, HttpMethod.Post); |
|
|
|
|
|
|
|
|
|
if (riskResult != null && riskResult.Data != null && riskResult.Data.ToString()!.Length > 10) |
|
|
|
|
{ |
|
|
|
|
LedgerDto httpClientResult = JsonSerializer.Deserialize<LedgerDto>(riskResult.Data.ToString()!)!; |
|
|
|
|
if (httpClientResult != null) |
|
|
|
|
{ |
|
|
|
|
if (statusNot[i] == 3) |
|
|
|
|
{ |
|
|
|
|
int c = 0; |
|
|
|
|
//统计状态为3但是实际结束时间大于计划结束时间的 |
|
|
|
|
if (httpClientResult.Data != null && httpClientResult.Data.Count > 0) |
|
|
|
|
{ |
|
|
|
|
for (int j = 0; j < httpClientResult.Data.Count; j++) |
|
|
|
|
{ |
|
|
|
|
if (httpClientResult.Data[j].EndAt != "" && httpClientResult.Data[j].FinishTime != "") |
|
|
|
|
{ |
|
|
|
|
if (Convert.ToDateTime(httpClientResult.Data[j].EndAt) < Convert.ToDateTime(httpClientResult.Data[j].FinishTime)) |
|
|
|
|
{ |
|
|
|
|
c++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
StatisticsInfoDto statisticsInfoDto = new() |
|
|
|
|
{ |
|
|
|
|
Name = statusNot[i].ToString() + "已超时", |
|
|
|
|
Total = httpClientResult.Total, |
|
|
|
|
}; |
|
|
|
|
data.Add(statisticsInfoDto); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
StatisticsInfoDto statisticsInfoDto = new() |
|
|
|
|
{ |
|
|
|
|
Name = statusNot[i].ToString(), |
|
|
|
|
Total = httpClientResult.Total, |
|
|
|
|
}; |
|
|
|
|
data.Add(statisticsInfoDto); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result.Data = MergeStatistics(data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
_logger.LogWarning(ex, "GetStatistics接口出错"); |
|
|
|
|
return ApiResult<List<StatisticsInfoDto>>.IsFail($"GetStatistics接口出错{ex.Message}"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static List<StatisticsInfoDto> MergeStatistics(List<StatisticsInfoDto> originalStats) |
|
|
|
|
{ |
|
|
|
|
// 防御性判断:若原始列表为空,返回默认4项(Total均为0) |
|
|
|
|
if (originalStats == null || !originalStats.Any()) |
|
|
|
|
{ |
|
|
|
|
return |
|
|
|
|
[ |
|
|
|
|
new() { Name = "未开始", Total = 0 }, |
|
|
|
|
new() { Name = "已结束", Total = 0 }, |
|
|
|
|
new() { Name = "进行中", Total = 0 }, |
|
|
|
|
new() { Name = "已超时", Total = 0 } |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 1. 未开始:name=1、2 的Total求和 |
|
|
|
|
var notStartedTotal = originalStats |
|
|
|
|
.Where(dto => dto.Name is "1" or "2") |
|
|
|
|
.Sum(dto => dto.Total); |
|
|
|
|
|
|
|
|
|
// 2. 已结束:name=6、7、8、11、12、13 的Total求和 |
|
|
|
|
var finishedTotal = originalStats |
|
|
|
|
.Where(dto => dto.Name is "6" or "7" or "8" or "11" or "12" or "13") |
|
|
|
|
.Sum(dto => dto.Total); |
|
|
|
|
|
|
|
|
|
// 3. 进行中:name=3、4 的Total求和(排除"3已超时") |
|
|
|
|
var inProgressTotal = originalStats |
|
|
|
|
.Where(dto => dto.Name is "3" or "4") |
|
|
|
|
.Sum(dto => dto.Total); |
|
|
|
|
|
|
|
|
|
// 4. 已超时:name="3已超时" 的Total求和 |
|
|
|
|
var timeoutTotal = originalStats |
|
|
|
|
.Where(dto => dto.Name == "3已超时") |
|
|
|
|
.Sum(dto => dto.Total); |
|
|
|
|
|
|
|
|
|
// 构造合并后的结果列表 |
|
|
|
|
return |
|
|
|
|
[ |
|
|
|
|
new() { Name = "未开始", Total = notStartedTotal }, |
|
|
|
|
new() { Name = "已结束", Total = finishedTotal }, |
|
|
|
|
new() { Name = "进行中", Total = inProgressTotal }, |
|
|
|
|
new() { Name = "已超时", Total = timeoutTotal } |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |