增加一个统计接口

pull/30/head
刘鑫 2 months ago
parent 9086dd3bee
commit b909a8d9a6
  1. 2
      WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj
  2. 57
      WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/RequestDto/SunPlaceBoardWorkOrderReqDto.cs
  3. 11
      WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs
  4. 30
      WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs
  5. 2
      WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs
  6. 152
      WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs

@ -7,7 +7,7 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>Common.Shared.Application</PackageId>
<Version>2.6.0</Version>
<Version>2.9.0</Version>
<Authors>zrh-lx</Authors>
<Company>zrh-lx</Company> <!-- 可选 -->
<Description>包含所有公共使用的 DTO、契约、接口模型等,供微服务之间共享使用</Description>

@ -78,7 +78,7 @@ namespace Common.Shared.Application.SafetyFirePro.RequestDto
/// <example>1</example>
/// <remarks>必填项</remarks>
[JsonPropertyName("page")]
public int? Page { get; set; }
public int? Page { get; set; } = 1;
/// <summary>
/// 每页数据数量
@ -86,7 +86,7 @@ namespace Common.Shared.Application.SafetyFirePro.RequestDto
/// <example>10</example>
/// <remarks>不传则默认为10</remarks>
[JsonPropertyName("page_size")]
public int? PageSize { get; set; }
public int? PageSize { get; set; } = 20;
/// <summary>
/// 作业状态
@ -109,6 +109,57 @@ namespace Common.Shared.Application.SafetyFirePro.RequestDto
/// <example>"ubpid"</example>
/// <remarks>必填项</remarks>
[JsonPropertyName("ubpid")]
public string Ubpid { get; set; }
public string? Ubpid { get; set; }
/// <summary>
/// 当为1的时候是统计,其他的时候查询列表
/// </summary>
public int? Type { get; set; }
}
/// <summary>
/// 隐患详情请求参数
/// </summary>
public class DangerDetailReqDto
{
/// <summary>
/// 隐患id
/// </summary>
public int Id { get; set; }
}
/// <summary>
/// 区域(空间)列表树数据
/// </summary>
public class RegionRootInfoReqDto
{
/// <summary>
/// 传0则返回当前单位所有数据,传其他数字,如is_switch_branch=1,则逐级返回该id之上的父节点和之下的所有子孙节点数据
/// </summary>
public int? region_id { get; set; }
/// <summary>
/// 0忽略region_id参数,1启用region_id参数
/// </summary>
public int Is_switch_branch { get; set; } = 0;
public int? Ubpid { get; set; }
}
/// <summary>
/// 施工作业统计
/// </summary>
public class StatisticsInfoDto
{
/// <summary>
/// 统计
/// </summary>
public int Total { get; set; }
/// <summary>
/// 状态:未开始:1、2,已结束:6、7、8、11、12、13,进行中:3(排除已超时的)、4,
/// 已超时:对于超时状态的作业,是在状态3中,检查每个数据的预计结束时间是否小于当前时间来筛选的
/// </summary>
public string Name { get; set; }
}
}

@ -111,5 +111,16 @@ namespace ThirdPartyServices.API.Controllers.ShenZhouShengAn
{
return await _secSituationService.GetRegionRootInfo(dto);
}
/// <summary>
/// 获得危险作业(施工)数据统计
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost("statistics")]
public async Task<ApiResult<List<StatisticsInfoDto>>> GetStatistics(WorkTaskQueryParamsDto dto)
{
return await _secSituationService.GetStatistics(dto);
}
}
}

@ -80,17 +80,7 @@ namespace ThirdPartyServices.Application.ShenZhouShengAn.RequestDto
public int Ubpid { get; set; }
}
/// <summary>
/// 隐患详情请求参数
/// </summary>
public class DangerDetailReqDto
{
/// <summary>
/// 隐患id
/// </summary>
public int Id { get; set; }
}
/// <summary>
/// 危害辨识项目数据请求参数
/// </summary>
@ -101,21 +91,5 @@ namespace ThirdPartyServices.Application.ShenZhouShengAn.RequestDto
public int Uid { get; set; }
}
/// <summary>
/// 区域(空间)列表树数据
/// </summary>
public class RegionRootInfoReqDto
{
/// <summary>
/// 传0则返回当前单位所有数据,传其他数字,如is_switch_branch=1,则逐级返回该id之上的父节点和之下的所有子孙节点数据
/// </summary>
public int? region_id { get; set; }
/// <summary>
/// 0忽略region_id参数,1启用region_id参数
/// </summary>
public int Is_switch_branch { get; set; } = 0;
public int? Ubpid { get; set; }
}
}

@ -39,5 +39,7 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn
Task<ApiResult<RegionStructureRootDto>> GetRegionRootInfo(RegionRootInfoReqDto dto
);
Task<ApiResult<List<StatisticsInfoDto>>> GetStatistics(WorkTaskQueryParamsDto dto);
}
}

@ -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 }
];
}
}
}
Loading…
Cancel
Save