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 d779d21..f84fd67 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.0.0 + 2.1.0 zrh-lx zrh-lx 包含所有公共使用的 DTO、契约、接口模型等,供微服务之间共享使用 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 742e725..7aca665 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 @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Common.Shared.Application.SafetyFirePro.ResponseDto { @@ -239,4 +240,402 @@ namespace Common.Shared.Application.SafetyFirePro.ResponseDto } #endregion 太阳宫看板-设备设施态势返回体 + + #region 太阳宫看板-风险管控可视化 + + // 1) 定义响应模型 + public class FloorDto + { + [JsonPropertyName("id")] + public int Id { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("floor_number")] + public int FloorNumber { get; set; } + + [JsonPropertyName("sort")] + public int Sort { get; set; } + + [JsonPropertyName("region_id")] + public int RegionId { get; set; } + + [JsonPropertyName("is_3d")] + public int Is3d { get; set; } + + [JsonPropertyName("jiaodu")] + public int Jiaodu { get; set; } + } + + /// + /// 四色图图层列表 + /// + public class FloorResDto + { + public List Data { get; set; } = []; + } + + #endregion 太阳宫看板-风险管控可视化 + + #region 太阳宫看板-隐患数据 + + /// + /// 根节点 + /// + public class RootReqDto + { + /// + /// 地图缩放系数 + /// + [JsonPropertyName("zoom")] + public string Zoom { get; set; } + + /// + /// 地图中心坐标 [经度,纬度] + /// + [JsonPropertyName("center")] + [JsonConverter(typeof(FlexibleCenterConverter))] + public List> Center { get; set; } + + /// + /// 底图数据 + /// + [JsonPropertyName("changquArr")] + public List ChangquArr { get; set; } + + /// + /// 色块区域相关数据 + /// + [JsonPropertyName("seKualArr")] + public List SeKualArr { get; set; } + } + + public class ChangquDto + { + [JsonPropertyName("drawType")] + public string DrawType { get; set; } + + [JsonPropertyName("center")] + [JsonConverter(typeof(FlexibleCenterConverter))] + public List> Center { get; set; } + + [JsonPropertyName("imgurl")] + public string ImgUrl { get; set; } + + [JsonPropertyName("region_id")] + public int RegionId { get; set; } + + [JsonPropertyName("parent_id")] + public int ParentId { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("point")] + public List> Point { get; set; } + + [JsonPropertyName("id")] + public int Id { get; set; } + + [JsonPropertyName("monitor")] + public List Monitor { get; set; } + } + + public class MonitorDto + { + [JsonPropertyName("id")] + public int Id { get; set; } + + [JsonPropertyName("uid")] + public int Uid { get; set; } + + [JsonPropertyName("ubpid")] + public int Ubpid { get; set; } + + [JsonPropertyName("user_id")] + public string UserId { get; set; } + + [JsonPropertyName("enterprise_region_id")] + public int EnterpriseRegionId { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("category_id")] + public int? CategoryId { get; set; } + + [JsonPropertyName("channel")] + public string Channel { get; set; } + + [JsonPropertyName("location")] + public string Location { get; set; } + + [JsonPropertyName("status")] + public string Status { get; set; } + + [JsonPropertyName("pull_url")] + public string PullUrl { get; set; } + + [JsonPropertyName("push_url")] + public string PushUrl { get; set; } + + [JsonPropertyName("content")] + public string Content { get; set; } + + [JsonPropertyName("created_at")] + public string CreatedAt { get; set; } + + [JsonPropertyName("updated_at")] + public string UpdatedAt { get; set; } + + [JsonPropertyName("deleted_at")] + public string DeletedAt { get; set; } + } + + /// + /// 色块区域相关数据 + /// + public class SeKualDto + { + /// + ///色块区域id + /// + [JsonPropertyName("region_id")] + public int RegionId { get; set; } + + /// + /// 色块父区域id + /// + [JsonPropertyName("parent_id")] + public int ParentId { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + /// + /// 色块形状类型 + /// + [JsonPropertyName("drawType")] + public string DrawType { get; set; } + + /// + /// 色块名称坐标位置 + /// + [JsonPropertyName("textPoint")] + public List TextPoint { get; set; } // 有时是数字,有时是字符串 + + /// + /// 色块图像各顶点经纬度 + /// + [JsonPropertyName("center")] + [JsonConverter(typeof(FlexibleCenterConverter))] + public List> Center { get; set; } + + [JsonPropertyName("gaodu_x")] + public int GaoduX { get; set; } + + [JsonPropertyName("gaodu_y")] + public int GaoduY { get; set; } + + /// + /// 色块id + /// + [JsonPropertyName("id")] + public int Id { get; set; } + + [JsonPropertyName("monitor")] + public List Monitor { get; set; } + + [JsonPropertyName("ristType")] + public RistTypeWrapper RistType { get; set; } + + [JsonPropertyName("riskPointCount")] + public List RiskPointCount { get; set; } + + /// + /// 风险等级颜色 + /// + [JsonPropertyName("color")] + public string Color { get; set; } + + [JsonPropertyName("sumCount")] + public int SumCount { get; set; } + + [JsonPropertyName("dangerStatistics")] + public DangerStatisticsDto DangerStatistics { get; set; } + + /// + /// 相关危险作业数量 + /// + [JsonPropertyName("ticket_do_count")] + public int TicketDoCount { get; set; } + + /// + /// 相关应急物资数量 + /// + [JsonPropertyName("contingency_material_count")] + public int ContingencyMaterialCount { get; set; } + + /// + /// 相关消防设备数量 + /// + [JsonPropertyName("fire_equipment_count")] + public int FireEquipmentCount { get; set; } + } + + public class RistTypeWrapper + { + /// + /// 风险点总数 + /// + [JsonPropertyName("sumCount")] + public int SumCount { get; set; } + + /// + /// 各风险点类型数据 + /// + [JsonPropertyName("ristType")] + public List RistType { get; set; } + } + + public class RistTypeDto + { + /// + /// 风险点类型id + /// + [JsonPropertyName("id")] + public int Id { get; set; } + + /// + /// 风险点类型名称 + /// + [JsonPropertyName("name")] + public string Name { get; set; } + + /// + /// 风险点类型包含风险点数 + /// + [JsonPropertyName("count")] + public int Count { get; set; } + } + + /// + /// 风险 + /// + public class RiskPointCountDto + { + /// + /// 风险类型 + /// + [JsonPropertyName("name")] + public string Name { get; set; } + + /// + /// 风险统计数量 + /// + [JsonPropertyName("count")] + public string Count { get; set; } + } + + /// + /// 隐患统计 + /// + public class DangerStatisticsDto + { + /// + /// 年度隐患总数 + /// + [JsonPropertyName("sumDanger")] + public int SumDanger { get; set; } + + /// + /// 年度重大隐患数 + /// + [JsonPropertyName("majorDanger")] + public int MajorDanger { get; set; } + + /// + /// 年度一般隐患数 + /// + [JsonPropertyName("generalDanger")] + public int GeneralDanger { get; set; } + + /// + /// 当前隐患未整改完毕数 + /// + [JsonPropertyName("dangerNum")] + public int DangerNum { get; set; } + + /// + /// 当前隐患逾期未整改完毕数 + /// + [JsonPropertyName("delay")] + public int Delay { get; set; } + } + + public sealed class FlexibleCenterConverter : JsonConverter>> + { + public override List> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + using var doc = JsonDocument.ParseValue(ref reader); + var root = doc.RootElement; + + if (root.ValueKind != JsonValueKind.Array) + return new List>(); + + // 空数组 -> [] + if (root.GetArrayLength() == 0) + return new List>(); + + // 判断第一项是数字还是数组 + var first = root[0]; + if (first.ValueKind == JsonValueKind.Number || first.ValueKind == JsonValueKind.String) + { + // 一维: [x, y] 或 ["116.1","39.9"] -> [[x, y]] + var list = new List(root.GetArrayLength()); + foreach (var e in root.EnumerateArray()) + { + if (e.ValueKind == JsonValueKind.String) + { + if (double.TryParse(e.GetString(), out var v)) list.Add(v); + } + else if (e.ValueKind == JsonValueKind.Number) + { + list.Add(e.GetDouble()); + } + } + return new List> { list }; + } + else if (first.ValueKind == JsonValueKind.Array) + { + // 二维: [[x1,y1],[x2,y2]] + var outer = new List>(root.GetArrayLength()); + foreach (var inner in root.EnumerateArray()) + { + var pair = new List(inner.GetArrayLength()); + foreach (var e in inner.EnumerateArray()) + { + if (e.ValueKind == JsonValueKind.String) + { + if (double.TryParse(e.GetString(), out var v)) pair.Add(v); + } + else if (e.ValueKind == JsonValueKind.Number) + { + pair.Add(e.GetDouble()); + } + } + outer.Add(pair); + } + return outer; + } + + return new List>(); + } + + public override void Write(Utf8JsonWriter writer, List> value, JsonSerializerOptions options) + => JsonSerializer.Serialize(writer, value, options); + + #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 fc33414..d499ef8 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Controllers/ShenZhouShengAn/SunPalaceBoardSafetyController.cs @@ -1,5 +1,6 @@ using Common.Shared.Application.SafetyFirePro.ResponseDto; using Microsoft.AspNetCore.Mvc; +using System.Text.Json; using ThirdPartyServices.DomainService.ShenZhouShengAn; namespace ThirdPartyServices.API.Controllers.ShenZhouShengAn @@ -24,12 +25,32 @@ namespace ThirdPartyServices.API.Controllers.ShenZhouShengAn /// /// 生产风险识别(盾安云数据)智慧建筑的看板上使用 /// - /// /// [HttpGet("productionRisk")] public async Task GetProductionRiskEchart() { return await _secSituationService.GetProductionRiskEchart(); } + + /// + ///获得四色图图层列表 + /// + /// + [HttpGet("listFloor")] + public async Task GetListFloor() + { + return await _secSituationService.GetListFloor(); + } + + /// + /// 获得四色图区域列表 + /// + /// 图层id + /// + [HttpGet("getRiskMapInfo")] + public async Task GetRiskMapInfo(int floorId) + { + return await _secSituationService.GetRiskMapInfo(floorId); + } } } \ No newline at end of file diff --git a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Program.cs b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Program.cs index b8f3507..34c6009 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Program.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.API/Program.cs @@ -45,6 +45,13 @@ namespace ThirdPartyServices.API #endregion Cors + //jsonСд + builder.Services.AddControllers() + .AddJsonOptions(options => + { + options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; + }); + #region SwaggerUI builder.Services.AddEndpointsApiExplorer(); diff --git a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs index 45a1209..f3db3ef 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.Application/ShenZhouShengAn/RequestDto/ThirdPartyProviderQueryDto.cs @@ -65,4 +65,14 @@ namespace ThirdPartyServices.Application.ShenZhouShengAn.RequestDto public string? End_time { get; set; } } + + /// + /// 获得四色图区域列表请求参数 + /// + public class RiskFourcoMapReqDto + { + public int Floor { get; set; } + + 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 2d41352..aec2996 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ISunPalaceBoardSafetyService.cs @@ -1,5 +1,5 @@ -using Common.Shared.Application.BaseModels; -using Common.Shared.Application.SafetyFirePro.ResponseDto; +using Common.Shared.Application.SafetyFirePro.ResponseDto; +using System.Text.Json; namespace ThirdPartyServices.DomainService.ShenZhouShengAn { @@ -11,6 +11,20 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn Task GetProductionRiskEchart(); + /// + /// 获得四色图图层列表 + /// + /// 用户单位标记码 + /// + Task GetListFloor(); + + /// + /// 获得四色图区域列表 + /// + /// 图层id + /// + Task GetRiskMapInfo(int floorId); + //Task> GetUnAlarmInfoList(AlarmEventEchartQueryDto 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 ce27ada..8222437 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs @@ -1,7 +1,8 @@ using Common.Shared.Application.SafetyFirePro.ResponseDto; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Linq; +using MongoDB.Bson.IO; +using System.Text.Json; using ThirdPartyServices.Application.ShenZhouShengAn.RequestDto; using ThirdPartyServices.Application.ShenZhouShengAn.ResponseDto; @@ -20,6 +21,50 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn _configuration = configuration; } + /// + /// 获得四色图图层列表 + /// + /// 用户单位标记码 + /// + /// + public async Task GetListFloor() + { + var result = new FloorResDto(); + + try + { + //获取token + var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); + if (string.IsNullOrWhiteSpace(token)) + { + _logger.LogWarning("GetListFloor接口获取token失败"); + return result; + } + + //获取用户配置 + HttpClientResult loginUsers = await _tokenProviderService.GetUserConfiguration(token); + if (loginUsers.Code == "Error") + { + _logger.LogWarning("GetListFloor接口获取用户配置失败"); + return result; + } + + //生产风险识别 + HttpClientResult> riskResult = await _tokenProviderService + .SendAndParseAsync>>( + "https://zrh.szdunan.cn/v1/api/riskFourcoloringMap/getlistFloor", + token, loginUsers.Data.Ubpid, HttpMethod.Post); + + result = new FloorResDto { Data = riskResult.Data }; + } + catch (Exception ex) + { + _logger.LogWarning(ex, "GetListFloor接口出错"); + } + + return result; + } + /// /// 生产风险识别(盾安云数据)-智慧建筑的看板上使用 /// @@ -89,17 +134,19 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn // 1. 查该状态下的总数 string jsonResult = await _tokenProviderService.SendJsonAsync("https://zrh.szdunan.cn/v1/api/danger/ledger/dangerInfo/new", token, new DangerInfoQueryDto { Ubpid = loginUsers.Data.Ubpid, Status = status }, HttpMethod.Post); - var jObj = JObject.Parse(jsonResult); - int total = jObj["data"]?["total"]?.Value() ?? 0; + using JsonDocument doc = JsonDocument.Parse(jsonResult); + JsonElement root = doc.RootElement; + + int total = 0; + if (root.TryGetProperty("data", out JsonElement dataElement)) + { + if (dataElement.TryGetProperty("total", out JsonElement totalElement)) + { + total = totalElement.GetInt32(); + } + } info.StatusCount = total; - //// 2. 查该状态 + 等级下的总数(只要一个等级的话可以直接取) - //jsonResult = await _tokenProviderService.SendJsonAsync("https://zrh.szdunan.cn/v1/api/danger/ledger/dangerInfo/new", token, new DangerInfoQueryDto { Ubpid = loginUsers.Data.Ubpid, Status = status, Result = "3" }, HttpMethod.Post); - - //jObj = JObject.Parse(jsonResult); - //int levelTotal = jObj["data"]?["total"]?.Value() ?? 0; - //info.DangerLevelCount = levelTotal; - return info; })); } @@ -109,8 +156,19 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn DateTime startTime = new DateTime(DateTime.Today.Year, 1, 1); dangerInfo = new DangerInfo(); var jsonBranch = await _tokenProviderService.SendJsonAsync("https://zrh.szdunan.cn/v1/api/danger/task/index_branch", token, new DangerInfoQueryDto { Status = "0", Branch_id = branchs.Data.BranchPermissionIds[0], Start_time = startTime.ToString("yyyy-MM-dd HH:mm:ss"), End_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }, HttpMethod.Post); - var jObj = JObject.Parse(jsonBranch); - int total = jObj["data"]?["total"]?.Value() ?? 0; + using JsonDocument doc = JsonDocument.Parse(jsonBranch); + JsonElement root = doc.RootElement; + + int total = 0; + if (root.TryGetProperty("data", out JsonElement dataElement)) + { + // 如果"data"存在,再尝试获取"total" + if (dataElement.TryGetProperty("total", out JsonElement totalElement)) + { + // 尝试转换为int(如果类型不匹配,也会返回默认值0) + total = totalElement.GetInt32(); + } + } dangerInfo.StatusCount = total; dangerInfo.Status = "3"; //待排查 dangerInfoList.Add(dangerInfo); @@ -123,5 +181,52 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn } return result; } + + /// + /// 获得四色图区域列表 + /// + /// + /// + public async Task GetRiskMapInfo(int floorId) + { + var result = new RootReqDto(); + + try + { + //获取token + var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); + if (string.IsNullOrWhiteSpace(token)) + { + _logger.LogWarning("GetRiskMapInfo接口获取token失败"); + return result; + } + + //获取用户配置 + HttpClientResult loginUsers = await _tokenProviderService.GetUserConfiguration(token); + if (loginUsers.Code == "Error") + { + _logger.LogWarning("GetRiskMapInfo接口获取用户配置失败"); + return result; + } + + //生产风险识别 + HttpClientResult riskResult = await _tokenProviderService + .SendAndParseAsync>( + "https://zrh.szdunan.cn/v1/api/riskFourcoloringMap/getRiskFourColoringMapInfo", + token, new RiskFourcoMapReqDto + { + Floor = floorId, + Ubpid = loginUsers.Data.Ubpid + }, HttpMethod.Post); + + result = riskResult.Data; + } + catch (Exception ex) + { + _logger.LogWarning(ex, "GetRiskMapInfo接口出错"); + } + + return result; + } } } \ No newline at end of file