From b909a8d9a6db47832ed560e0e58c45d9bbe328cc Mon Sep 17 00:00:00 2001 From: LiuXin Date: Tue, 16 Sep 2025 17:58:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common.Shared.Application.csproj | 2 +- .../SunPlaceBoardWorkOrderReqDto.cs | 57 ++++++- .../SunPalaceBoardSafetyController.cs | 11 ++ .../RequestDto/ThirdPartyProviderQueryDto.cs | 30 +--- .../ISunPalaceBoardSafetyService.cs | 2 + .../SunPalaceBoardSafetyService.cs | 152 +++++++++++++++++- 6 files changed, 221 insertions(+), 33 deletions(-) diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj index 09fb475..16882fb 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj @@ -7,7 +7,7 @@ Common.Shared.Application - 2.6.0 + 2.9.0 zrh-lx zrh-lx 包含所有公共使用的 DTO、契约、接口模型等,供微服务之间共享使用 diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/RequestDto/SunPlaceBoardWorkOrderReqDto.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/RequestDto/SunPlaceBoardWorkOrderReqDto.cs index 44f7432..c429653 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/RequestDto/SunPlaceBoardWorkOrderReqDto.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/RequestDto/SunPlaceBoardWorkOrderReqDto.cs @@ -78,7 +78,7 @@ namespace Common.Shared.Application.SafetyFirePro.RequestDto /// 1 /// 必填项 [JsonPropertyName("page")] - public int? Page { get; set; } + public int? Page { get; set; } = 1; /// /// 每页数据数量 @@ -86,7 +86,7 @@ namespace Common.Shared.Application.SafetyFirePro.RequestDto /// 10 /// 不传则默认为10 [JsonPropertyName("page_size")] - public int? PageSize { get; set; } + public int? PageSize { get; set; } = 20; /// /// 作业状态 @@ -109,6 +109,57 @@ namespace Common.Shared.Application.SafetyFirePro.RequestDto /// "ubpid" /// 必填项 [JsonPropertyName("ubpid")] - public string Ubpid { get; set; } + public string? Ubpid { get; set; } + + /// + /// 当为1的时候是统计,其他的时候查询列表 + /// + public int? Type { get; set; } + } + + /// + /// 隐患详情请求参数 + /// + public class DangerDetailReqDto + { + /// + /// 隐患id + /// + public int Id { get; set; } + } + + /// + /// 区域(空间)列表树数据 + /// + public class RegionRootInfoReqDto + { + /// + /// 传0则返回当前单位所有数据,传其他数字,如is_switch_branch=1,则逐级返回该id之上的父节点和之下的所有子孙节点数据 + /// + public int? region_id { get; set; } + + /// + /// 0忽略region_id参数,1启用region_id参数 + /// + public int Is_switch_branch { get; set; } = 0; + + public int? Ubpid { get; set; } + } + + /// + /// 施工作业统计 + /// + public class StatisticsInfoDto + { + /// + /// 统计 + /// + public int Total { get; set; } + + /// + /// 状态:未开始:1、2,已结束:6、7、8、11、12、13,进行中:3(排除已超时的)、4, + /// 已超时:对于超时状态的作业,是在状态3中,检查每个数据的预计结束时间是否小于当前时间来筛选的 + /// + public string Name { get; set; } } } \ No newline at end of file diff --git a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs index f256334..b445c40 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs @@ -111,5 +111,16 @@ namespace ThirdPartyServices.API.Controllers.ShenZhouShengAn { return await _secSituationService.GetRegionRootInfo(dto); } + + /// + /// 获得危险作业(施工)数据统计 + /// + /// + /// + [HttpPost("statistics")] + public async Task>> GetStatistics(WorkTaskQueryParamsDto dto) + { + return await _secSituationService.GetStatistics(dto); + } } } \ No newline at end of file diff --git a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs index 4c1b175..112f89f 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs @@ -80,17 +80,7 @@ namespace ThirdPartyServices.Application.ShenZhouShengAn.RequestDto public int Ubpid { get; set; } } - /// - /// 隐患详情请求参数 - /// - public class DangerDetailReqDto - { - /// - /// 隐患id - /// - public int Id { get; set; } - } - + /// /// 危害辨识项目数据请求参数 /// @@ -101,21 +91,5 @@ namespace ThirdPartyServices.Application.ShenZhouShengAn.RequestDto public int Uid { get; set; } } - /// - /// 区域(空间)列表树数据 - /// - public class RegionRootInfoReqDto - { - /// - /// 传0则返回当前单位所有数据,传其他数字,如is_switch_branch=1,则逐级返回该id之上的父节点和之下的所有子孙节点数据 - /// - public int? region_id { get; set; } - - /// - /// 0忽略region_id参数,1启用region_id参数 - /// - public int Is_switch_branch { get; set; } = 0; - - public int? Ubpid { get; set; } - } + } \ No newline at end of file diff --git a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs index 0847663..1db1643 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs @@ -39,5 +39,7 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn Task> GetRegionRootInfo(RegionRootInfoReqDto dto ); + + Task>> GetStatistics(WorkTaskQueryParamsDto dto); } } \ No newline at end of file diff --git a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs index b1022f4..18893a7 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs @@ -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; } + + /// + /// 获得危险作业(施工)数据统计 + /// + /// + /// + /// + public async Task>> GetStatistics(WorkTaskQueryParamsDto dto) + { + ApiResult> result = new ApiResult>() { 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>.IsFail("GetStatistics接口获取token失败"); + } + + //获取用户配置 + HttpClientResult loginUsers = await _tokenProviderService.GetUserConfiguration(token); + if (loginUsers.Code == "Error") + { + _logger.LogWarning("GetStatistics接口获取用户配置失败"); + return ApiResult>.IsFail("GetStatistics接口获取用户配置失败"); + } + + //获取单位信息 + HttpClientResult branchs = await _tokenProviderService.GetBranchPermissions(token, loginUsers.Data.Uid); + if (branchs.Code == "Error") + { + _logger.LogWarning("GetStatistics接口获取单位信息失败"); + return ApiResult>.IsFail("GetStatistics接口获取单位信息失败"); + } + + dto.Ubpid = loginUsers.Data.Ubpid.ToString(); + List 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 riskResult = await _tokenProviderService + .SendAndParseAsync>( + "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(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>.IsFail($"GetStatistics接口出错{ex.Message}"); + } + + return result; + } + + private static List MergeStatistics(List 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 } + ]; + } } } \ No newline at end of file