From 3fde17e668faffa770263bd2be24afb1f37a69d1 Mon Sep 17 00:00:00 2001 From: LiuXin Date: Wed, 10 Sep 2025 17:20:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SunPlaceBoardWorkOrderReqDto.cs | 52 +++++++++++++ .../ResponseDto/SunPalaceBoardResDto.cs | 76 ++++++++++++++++--- .../SunPalaceBoardSafetyController.cs | 14 +++- .../ISunPalaceBoardSafetyService.cs | 9 +-- .../SunPalaceBoardSafetyService.cs | 65 +++++++++++++++- 5 files changed, 199 insertions(+), 17 deletions(-) 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 efabd52..53a2a0c 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 @@ -66,4 +66,56 @@ namespace Common.Shared.Application.SafetyFirePro.RequestDto /// public string? BxDeptCode { get; set; } } + + /// + /// 作业任务查询参数实体类 + /// + public class WorkTaskQueryParamsDto + { + /// + /// 页数 + /// + /// 1 + /// 必填项 + [JsonPropertyName("page")] + public int? Page { get; set; } + + /// + /// 每页数据数量 + /// + /// 10 + /// 不传则默认为10 + [JsonPropertyName("page_size")] + public int? PageSize { get; set; } + + /// + /// 作业状态 + /// + /// 3 + /// 1:待审批, 2:待作业前检查, 3:作业中, 4:抽作业前检查, 6:作业结束, 7:延期结束, 8:超时结束, 11:审批不通过, 12:作业中止, 13:强行结束 + [JsonPropertyName("status")] + public string? Status { get; set; } + + /// + /// 作业单位部门id + /// + /// 8888 + [JsonPropertyName("branch_id")] + public int? BranchId { get; set; } + + /// + /// 作业活动所在区域id + /// + /// 8888 + [JsonPropertyName("region_id")] + public int? RegionId { get; set; } + + /// + /// ubpid参数 + /// + /// "ubpid" + /// 必填项 + [JsonPropertyName("ubpid")] + public string Ubpid { get; set; } + } } \ No newline at end of file diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/ResponseDto/SunPalaceBoardResDto.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/ResponseDto/SunPalaceBoardResDto.cs index e156c57..7b2dba2 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/ResponseDto/SunPalaceBoardResDto.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/SafetyFirePro/ResponseDto/SunPalaceBoardResDto.cs @@ -433,11 +433,14 @@ namespace Common.Shared.Application.SafetyFirePro.ResponseDto [JsonConverter(typeof(FlexibleCenterConverter))] public List> Center { get; set; } - [JsonPropertyName("gaodu_x")] - public int GaoduX { get; set; } + //[JsonPropertyName("gaodu_x")] + //public int? GaoduX { get; set; } - [JsonPropertyName("gaodu_y")] - public int GaoduY { get; set; } + //[JsonPropertyName("gaodu_y")] + //public int? GaoduY { get; set; } + + [JsonPropertyName("gaodu")] + public int? Gaodu { get; set; } /// /// 色块id @@ -815,21 +818,76 @@ namespace Common.Shared.Application.SafetyFirePro.ResponseDto public sealed class FlexiblePointConverter : JsonConverter { - public override PointDto Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override PointDto Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options) { + // 解析JSON节点,避免直接操作reader导致位置偏移 using var doc = JsonDocument.ParseValue(ref reader); var root = doc.RootElement; + // 1. 处理「对象格式」(如 {"x":609.5,"y":309.703125}) if (root.ValueKind == JsonValueKind.Object) - return new PointDto { X = root.GetProperty("x").GetDouble(), Y = root.GetProperty("y").GetDouble() }; + { + // 兼容属性缺失的异常场景(避免崩溃,返回默认值) + bool hasX = root.TryGetProperty("x", out var xElement); + bool hasY = root.TryGetProperty("y", out var yElement); + + if (hasX && hasY && TryParseDouble(xElement, out var x) && TryParseDouble(yElement, out var y)) + { + return new PointDto { X = x, Y = y }; + } + return default; + } + // 2. 处理「数组格式」(含数字数组[338,129.203125]和字符串数组["116.079126","39.927465"]) if (root.ValueKind == JsonValueKind.Array && root.GetArrayLength() >= 2) - return new PointDto { X = root[0].GetDouble(), Y = root[1].GetDouble() }; + { + var xElement = root[0]; // 数组第一个元素(x值) + var yElement = root[1]; // 数组第二个元素(y值) + // 解析x和y(兼容数字/字符串类型) + if (TryParseDouble(xElement, out var x) && TryParseDouble(yElement, out var y)) + { + return new PointDto { X = x, Y = y }; + } + return default; + } + + // 3. 其他未定义格式(返回默认PointDto) return default; } - public override void Write(Utf8JsonWriter writer, PointDto value, JsonSerializerOptions options) - => writer.WriteStartObject(); // 如需写回再实现 + public override void Write( + Utf8JsonWriter writer, + PointDto value, + JsonSerializerOptions options) + { + // 序列化时统一按「对象格式」输出(与实体类定义一致,便于后续使用) + writer.WriteStartObject(); + writer.WriteNumber("x", value.X); + writer.WriteNumber("y", value.Y); + writer.WriteEndObject(); + } + + #region 私有辅助方法:统一处理JsonElement(数字/字符串)转double + /// + /// 兼容「数字类型」和「字符串类型」的JsonElement,解析为double + /// 例:116.079126 → 116.079126;"116.079126" → 116.079126 + /// + private bool TryParseDouble(JsonElement element, out double result) + { + return element.ValueKind switch + { + // 若元素是数字,直接获取double + JsonValueKind.Number => element.TryGetDouble(out result), + // 若元素是字符串,尝试解析为double + JsonValueKind.String => double.TryParse(element.GetString(), out result), + // 其他类型(如布尔值),解析失败 + _ => (result = 0, false).Item2 + }; + } + #endregion } } \ 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 a4b0fb2..cf266cd 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs @@ -1,4 +1,5 @@ -using Common.Shared.Application.SafetyFirePro.ResponseDto; +using Common.Shared.Application.SafetyFirePro.RequestDto; +using Common.Shared.Application.SafetyFirePro.ResponseDto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Text.Json; @@ -65,5 +66,16 @@ namespace ThirdPartyServices.API.Controllers.ShenZhouShengAn { return await _secSituationService.GetRiskMapInfo(floorId); } + + /// + /// 获得危险作业(施工)数据 + /// + /// + /// + [HttpPost("ledger")] + public async Task GetLedger(WorkTaskQueryParamsDto dto) + { + return await _secSituationService.GetLedger(dto); + } } } \ 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 442190c..c352527 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs @@ -1,14 +1,11 @@ -using Common.Shared.Application.SafetyFirePro.ResponseDto; +using Common.Shared.Application.SafetyFirePro.RequestDto; +using Common.Shared.Application.SafetyFirePro.ResponseDto; using System.Text.Json; namespace ThirdPartyServices.DomainService.ShenZhouShengAn { public interface ISunPalaceBoardSafetyService { - //Task>> GetHiddenDangerTrend(SecSituationQueryDto dto); - - //Task>> GetIdCardAlarmEchart(); - Task GetProductionRiskEchart(); /// @@ -27,6 +24,6 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn Task GetDangerInfos(string? regionId, string? pRegionId); - //Task> GetUnAlarmInfoList(AlarmEventEchartQueryDto dto); + Task GetLedger(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 7578a01..bb95aa4 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs @@ -1,4 +1,5 @@ -using Common.Shared.Application.SafetyFirePro.ResponseDto; +using Common.Shared.Application.SafetyFirePro.RequestDto; +using Common.Shared.Application.SafetyFirePro.ResponseDto; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using MongoDB.Bson.IO; @@ -297,5 +298,67 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn return result; } + + /// + /// 获得危险作业(施工)数据 + /// + /// + /// + /// + public async Task GetLedger(WorkTaskQueryParamsDto dto) + { + var result = new RootReqDto(); + + try + { + //获取token + var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); + if (string.IsNullOrWhiteSpace(token)) + { + _logger.LogWarning("GetProductionRiskEchart接口获取token失败"); + return result; + } + + //获取用户配置 + HttpClientResult loginUsers = await _tokenProviderService.GetUserConfiguration(token); + if (loginUsers.Code == "Error") + { + _logger.LogWarning("GetProductionRiskEchart接口获取用户配置失败"); + return result; + } + + //获取单位信息 + HttpClientResult branchs = await _tokenProviderService.GetBranchPermissions(token, loginUsers.Data.Uid); + if (branchs.Code == "Error") + { + _logger.LogWarning("GetProductionRiskEchart接口获取单位信息失败"); + + return result; + } + + dto.Ubpid = loginUsers.Data.Ubpid.ToString(); + dto.BranchId = branchs.Data.BranchPermissionIds[0]; + + 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) + { + RootReqDto httpClientResult = JsonSerializer.Deserialize(riskResult.Data.ToString()!)!; + if (httpClientResult != null) + { + result = httpClientResult; + } + } + } + catch (Exception ex) + { + _logger.LogWarning(ex, $"GetRiskMapInfo接口出错"); + } + + return result; + } } } \ No newline at end of file