You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
506 lines
24 KiB
506 lines
24 KiB
using Common.Shared.Application.BaseModels; |
|
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; |
|
|
|
namespace ThirdPartyServices.DomainService.ShenZhouShengAn |
|
{ |
|
public class SunPalaceBoardSafetyService : ISunPalaceBoardSafetyService |
|
{ |
|
private readonly IThirdPartyProviderService _tokenProviderService; |
|
private readonly ILogger<SunPalaceBoardSafetyService> _logger; |
|
private readonly IConfiguration _configuration; |
|
|
|
public SunPalaceBoardSafetyService(IThirdPartyProviderService thirdPartyProviderService, ILogger<SunPalaceBoardSafetyService> logger, IConfiguration configuration) |
|
{ |
|
_tokenProviderService = thirdPartyProviderService; |
|
_logger = logger; |
|
_configuration = configuration; |
|
} |
|
|
|
/// <summary> |
|
/// 获得四色图图层列表 |
|
/// </summary> |
|
/// <param name="ubpid">用户单位标记码</param> |
|
/// <returns></returns> |
|
/// <exception cref="NotImplementedException"></exception> |
|
public async Task<ApiResult<FloorResDto>> GetListFloor() |
|
{ |
|
ApiResult<FloorResDto> result = new ApiResult<FloorResDto>() { Code = 200, Msg = "接口调用成功", Data = null }; |
|
|
|
try |
|
{ |
|
//获取token |
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
if (string.IsNullOrWhiteSpace(token)) |
|
{ |
|
_logger.LogWarning("GetListFloor接口获取token失败"); |
|
return ApiResult<FloorResDto>.IsFail("GetListFloor接口获取token失败"); |
|
} |
|
|
|
//获取用户配置 |
|
HttpClientResult<LoginUsersConfiguration> loginUsers = await _tokenProviderService.GetUserConfiguration(token); |
|
if (loginUsers.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetListFloor接口获取用户配置失败"); |
|
return ApiResult<FloorResDto>.IsFail("GetListFloor接口获取用户配置失败"); |
|
} |
|
|
|
//生产风险识别 |
|
HttpClientResult<List<FloorDto>> riskResult = await _tokenProviderService |
|
.SendAndParseAsync<int, HttpClientResult<List<FloorDto>>>( |
|
"https://zrh.szdunan.cn/v1/api/riskFourcoloringMap/getlistFloor", |
|
token, loginUsers.Data.Ubpid, HttpMethod.Post); |
|
|
|
if (riskResult.Data != null) |
|
{ |
|
result.Data = new FloorResDto { Data = riskResult.Data }; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
_logger.LogWarning(ex, "GetListFloor接口出错"); |
|
return ApiResult<FloorResDto>.IsFail($"GetListFloor接口出错{ex.Message}"); |
|
} |
|
|
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 生产风险识别(盾安云数据)-智慧建筑的看板上使用 |
|
/// </summary> |
|
/// <param name="dto"></param> |
|
/// <returns></returns> |
|
public async Task<ApiResult<DangerRiskAreaResDto>> GetProductionRiskEchart() |
|
{ |
|
ApiResult<DangerRiskAreaResDto> result = new() { Code = 200, Msg = "接口调用成功", Data = new DangerRiskAreaResDto() { DangerInfos = [], ProductionRiskStats = [] } }; |
|
try |
|
{ |
|
//获取token |
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
if (string.IsNullOrWhiteSpace(token)) |
|
{ |
|
_logger.LogWarning("GetProductionRiskEchart接口获取token失败"); |
|
return ApiResult<DangerRiskAreaResDto>.IsFail("GetProductionRiskEchart接口获取token失败"); |
|
} |
|
|
|
//获取用户配置 |
|
HttpClientResult<LoginUsersConfiguration> loginUsers = await _tokenProviderService.GetUserConfiguration(token); |
|
if (loginUsers.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetProductionRiskEchart接口获取用户配置失败"); |
|
return ApiResult<DangerRiskAreaResDto>.IsFail("GetProductionRiskEchart接口获取用户配置失败"); |
|
} |
|
|
|
//获取单位信息 |
|
HttpClientResult<BranchResDto> branchs = await _tokenProviderService.GetBranchPermissions(token, loginUsers.Data.Uid); |
|
if (branchs.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetProductionRiskEchart接口获取单位信息失败"); |
|
return ApiResult<DangerRiskAreaResDto>.IsFail("GetProductionRiskEchart接口获取单位信息失败"); |
|
} |
|
|
|
//生产风险识别 |
|
|
|
HttpClientResult<DangerRiskAreaResDto> riskResult = await _tokenProviderService.SendAndParseAsync<RiskAreaQueryDto, HttpClientResult<DangerRiskAreaResDto>>( |
|
"https://zrh.szdunan.cn/v1/api/home/risk/index", token, |
|
new RiskAreaQueryDto |
|
{ |
|
Branch_Id = branchs.Data.BranchPermissionIds[0], |
|
Ubpid = loginUsers.Data.Ubpid, |
|
Uid = loginUsers.Data.Uid |
|
}, HttpMethod.Post); |
|
|
|
if (riskResult.Code != "Error" || riskResult.Data != null) |
|
result.Data.ProductionRiskStats = riskResult.Data.ProductionRiskStats; |
|
|
|
//获取隐患信息 |
|
string[] dangerStatus = ["0", "1", "2",]; //0-待核查,1-待整改,2-待验收 |
|
int[] dangerLevel = [3]; //2一般隐患,3重大隐患。目前只要重大隐患,如果要查询一般隐患,可以将2添加到数组中 |
|
List<DangerInfo> dangerInfoList = []; |
|
DangerInfo dangerInfo = new DangerInfo(); |
|
|
|
var tasks = new List<Task<DangerInfo>>(); |
|
|
|
foreach (string status in dangerStatus) |
|
{ |
|
tasks.Add(Task.Run(async () => |
|
{ |
|
var info = new DangerInfo { Status = status }; |
|
|
|
// 1. 查该状态下的总数 |
|
string jsonResult = await _tokenProviderService.SendJsonAsync<DangerInfoQueryDto>("https://zrh.szdunan.cn/v1/api/danger/ledger/dangerInfo/new", token, new DangerInfoQueryDto { Ubpid = loginUsers.Data.Ubpid, Status = status }, HttpMethod.Post); |
|
|
|
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; |
|
|
|
return info; |
|
})); |
|
} |
|
|
|
dangerInfoList = [.. (await Task.WhenAll(tasks))]; |
|
//3.待排查 |
|
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); |
|
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); |
|
|
|
result.Data.DangerInfos = dangerInfoList; |
|
} |
|
catch (Exception ex) |
|
{ |
|
_logger.LogWarning(ex, "GetProductionRiskEchart接口出错"); |
|
return ApiResult<DangerRiskAreaResDto>.IsFail($"GetProductionRiskEchart接口出错{ex.Message}"); |
|
} |
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 获取指定区域ID的隐患数据 |
|
/// </summary> |
|
/// <param name="regionId">返回本区域隐患(不包含下属子区域隐患)</param> |
|
/// <param name="pRegionId">返回本区域及下属子区域隐患</param> |
|
/// <returns></returns> |
|
public async Task<ApiResult<DangerInfoRootResDto>> GetDangerInfos(DangerInfoQueryDto dto) |
|
{ |
|
ApiResult<DangerInfoRootResDto> result = new() { Code = 200, Msg = "接口调用成功", Data = new() }; |
|
try |
|
{ |
|
//获取token |
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
if (string.IsNullOrWhiteSpace(token)) |
|
{ |
|
_logger.LogWarning("GetDangerInfos接口获取token失败"); |
|
return ApiResult<DangerInfoRootResDto>.IsFail("GetDangerInfos接口获取token失败"); |
|
} |
|
|
|
//获取用户配置 |
|
HttpClientResult<LoginUsersConfiguration> loginUsers = await _tokenProviderService.GetUserConfiguration(token); |
|
if (loginUsers.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetDangerInfos接口获取用户配置失败"); |
|
return ApiResult<DangerInfoRootResDto>.IsFail("GetDangerInfos接口获取用户配置失败"); |
|
} |
|
|
|
//获取单位信息 |
|
HttpClientResult<BranchResDto> branchs = await _tokenProviderService.GetBranchPermissions(token, loginUsers.Data.Uid); |
|
if (branchs.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetDangerInfos接口获取单位信息失败"); |
|
return ApiResult<DangerInfoRootResDto>.IsFail("GetDangerInfos接口获取单位信息失败"); |
|
} |
|
dto.Ubpid = loginUsers.Data.Ubpid; |
|
// dto.Branch_id = branchs.Data.BranchPermissionIds[0]; |
|
|
|
var jsonResult = await _tokenProviderService.SendJsonAsync<DangerInfoQueryDto>("https://zrh.szdunan.cn/v1/api/danger/ledger/dangerInfo/new", token, dto, HttpMethod.Post); |
|
|
|
var root = JsonSerializer.Deserialize<HttpClientResult<DangerInfoRootResDto>>(jsonResult); |
|
if (root != null) |
|
{ |
|
result.Data = root.Data; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
_logger.LogWarning(ex, "GetDangerInfos接口出错"); |
|
return ApiResult<DangerInfoRootResDto>.IsFail($"GetDangerInfos接口出错{ex.Message}"); |
|
} |
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 获得四色图区域列表 |
|
/// </summary> |
|
/// <param name="floorId"></param> |
|
/// <returns></returns> |
|
public async Task<ApiResult<RootReqDto>> GetRiskMapInfo(int floorId) |
|
{ |
|
ApiResult<RootReqDto> result = new ApiResult<RootReqDto>() { Code = 200, Msg = "接口调用成功", Data = null }; |
|
|
|
try |
|
{ |
|
//获取token |
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
if (string.IsNullOrWhiteSpace(token)) |
|
{ |
|
_logger.LogWarning("GetRiskMapInfo接口获取token失败"); |
|
return ApiResult<RootReqDto>.IsFail("GetRiskMapInfo接口获取token失败"); |
|
} |
|
|
|
//获取用户配置 |
|
HttpClientResult<LoginUsersConfiguration> loginUsers = await _tokenProviderService.GetUserConfiguration(token); |
|
if (loginUsers.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetRiskMapInfo接口获取用户配置失败"); |
|
return ApiResult<RootReqDto>.IsFail("GetRiskMapInfo接口获取用户配置失败"); |
|
} |
|
|
|
//生产风险识别 |
|
HttpClientResult<object> riskResult = await _tokenProviderService |
|
.SendAndParseAsync<RiskFourcoMapReqDto, HttpClientResult<object>>( |
|
"https://zrh.szdunan.cn/v1/api/riskFourcoloringMap/getRiskFourColoringMapInfo", |
|
token, new RiskFourcoMapReqDto |
|
{ |
|
Floor = floorId, |
|
Ubpid = loginUsers.Data.Ubpid |
|
}, HttpMethod.Post); |
|
|
|
if (riskResult != null && riskResult.Data != null && riskResult.Data.ToString()!.Length > 10) |
|
{ |
|
RootReqDto httpClientResult = JsonSerializer.Deserialize<RootReqDto>(riskResult.Data.ToString()!)!; |
|
if (httpClientResult != null) |
|
{ |
|
result.Data = httpClientResult; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
_logger.LogWarning(ex, $"GetRiskMapInfo接口出错"); |
|
return ApiResult<RootReqDto>.IsFail($"GetRiskMapInfo接口出错{ex.Message}"); |
|
} |
|
|
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 获得危险作业(施工)数据 |
|
/// </summary> |
|
/// <param name="dto"></param> |
|
/// <returns></returns> |
|
/// <exception cref="NotImplementedException"></exception> |
|
public async Task<ApiResult<LedgerDto>> GetLedger(WorkTaskQueryParamsDto dto) |
|
{ |
|
ApiResult<LedgerDto> result = new ApiResult<LedgerDto>() { Code = 200, Msg = "接口调用成功", Data = null }; |
|
|
|
try |
|
{ |
|
//获取token |
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
if (string.IsNullOrWhiteSpace(token)) |
|
{ |
|
_logger.LogWarning("GetProductionRiskEchart接口获取token失败"); |
|
return ApiResult<LedgerDto>.IsFail("GetProductionRiskEchart接口获取token失败"); |
|
} |
|
|
|
//获取用户配置 |
|
HttpClientResult<LoginUsersConfiguration> loginUsers = await _tokenProviderService.GetUserConfiguration(token); |
|
if (loginUsers.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetProductionRiskEchart接口获取用户配置失败"); |
|
return ApiResult<LedgerDto>.IsFail("GetProductionRiskEchart接口获取用户配置失败"); |
|
} |
|
|
|
//获取单位信息 |
|
HttpClientResult<BranchResDto> branchs = await _tokenProviderService.GetBranchPermissions(token, loginUsers.Data.Uid); |
|
if (branchs.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetProductionRiskEchart接口获取单位信息失败"); |
|
return ApiResult<LedgerDto>.IsFail("GetProductionRiskEchart接口获取单位信息失败"); |
|
} |
|
|
|
dto.Ubpid = loginUsers.Data.Ubpid.ToString(); |
|
|
|
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) |
|
{ |
|
result.Data = httpClientResult; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
_logger.LogWarning(ex, "GetRiskMapInfo接口出错"); |
|
return ApiResult<LedgerDto>.IsFail($"GetRiskMapInfo接口出错{ex.Message}"); |
|
} |
|
|
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 获取隐患详情 |
|
/// </summary> |
|
/// <param name="id"></param> |
|
/// <returns></returns> |
|
/// <exception cref="NotImplementedException"></exception> |
|
public async Task<ApiResult<HazardDataDto>> GetDangerDetail(DangerDetailReqDto dto) |
|
{ |
|
ApiResult<HazardDataDto> result = new ApiResult<HazardDataDto>() { Code = 200, Msg = "接口调用成功", Data = null }; |
|
|
|
try |
|
{ |
|
//获取token |
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
if (string.IsNullOrWhiteSpace(token)) |
|
{ |
|
_logger.LogWarning("GetDangerDetail接口获取token失败"); |
|
return ApiResult<HazardDataDto>.IsFail("GetDangerDetail接口获取token失败"); |
|
} |
|
|
|
HttpClientResult<object> riskResult = await _tokenProviderService |
|
.SendAndParseAsync<DangerDetailReqDto, HttpClientResult<object>>( |
|
"https://zrh.szdunan.cn/v1/api/danger/rectification/check/detail", |
|
token, dto, HttpMethod.Post); |
|
|
|
if (riskResult != null && riskResult.Data != null && riskResult.Data.ToString()!.Length > 10) |
|
{ |
|
HazardDataDto httpClientResult = JsonSerializer.Deserialize<HazardDataDto>(riskResult.Data.ToString()!)!; |
|
if (httpClientResult != null) |
|
{ |
|
result.Data = httpClientResult; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
_logger.LogWarning(ex, "GetDangerDetail接口出错"); |
|
return ApiResult<HazardDataDto>.IsFail($"GetDangerDetail接口出错{ex.Message}"); |
|
} |
|
|
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 11、获得危害辨识项目数据 |
|
/// </summary> |
|
/// <returns></returns> |
|
/// <exception cref="NotImplementedException"></exception> |
|
public async Task<ApiResult<List<InjureResDto>>> GetInjureInfo() |
|
{ |
|
ApiResult<List<InjureResDto>> result = new ApiResult<List<InjureResDto>>() { Code = 200, Msg = "接口调用成功", Data = null }; |
|
|
|
try |
|
{ |
|
//获取token |
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
if (string.IsNullOrWhiteSpace(token)) |
|
{ |
|
_logger.LogWarning("GetInjureInfo接口获取token失败"); |
|
return ApiResult<List<InjureResDto>>.IsFail("GetInjureInfo接口获取token失败"); |
|
} |
|
|
|
//获取用户配置 |
|
HttpClientResult<LoginUsersConfiguration> loginUsers = await _tokenProviderService.GetUserConfiguration(token); |
|
if (loginUsers.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetInjureInfo接口获取用户配置失败"); |
|
return ApiResult<List<InjureResDto>>.IsFail("GetInjureInfo接口获取用户配置失败"); |
|
} |
|
InjureReqDto dto = new() |
|
{ |
|
Ubpid = loginUsers.Data.Ubpid, |
|
Uid = loginUsers.Data.Uid |
|
}; |
|
|
|
HttpClientResult<object> riskResult = await _tokenProviderService |
|
.SendAndParseAsync<InjureReqDto, HttpClientResult<object>>( |
|
"https://zrh.szdunan.cn/v1/api/risk/init/injure", |
|
token, dto, HttpMethod.Post); |
|
|
|
if (riskResult != null && riskResult.Data != null && riskResult.Data.ToString()!.Length > 10) |
|
{ |
|
List<InjureResDto> httpClientResult = JsonSerializer.Deserialize<List<InjureResDto>>(riskResult.Data.ToString()!)!; |
|
if (httpClientResult != null) |
|
{ |
|
result.Data = httpClientResult; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
_logger.LogWarning(ex, "GetInjureInfo接口出错"); |
|
return ApiResult<List<InjureResDto>>.IsFail($"GetInjureInfo接口出错{ex.Message}"); |
|
} |
|
|
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 得区域(空间)列表树数据 |
|
/// </summary> |
|
/// <returns></returns> |
|
/// <exception cref="NotImplementedException"></exception> |
|
public async Task<ApiResult<RegionStructureRootDto>> GetRegionRootInfo(RegionRootInfoReqDto dto) |
|
{ |
|
ApiResult<RegionStructureRootDto> result = new ApiResult<RegionStructureRootDto>() { Code = 200, Msg = "接口调用成功", Data = null }; |
|
|
|
try |
|
{ |
|
//获取token |
|
var token = await _tokenProviderService.GetTokenAsync(_configuration["ThirdParty:SzdunanCode"]!); |
|
if (string.IsNullOrWhiteSpace(token)) |
|
{ |
|
_logger.LogWarning("GetRegionRootInfo接口获取token失败"); |
|
return ApiResult<RegionStructureRootDto>.IsFail("GetRegionRootInfo接口获取token失败"); |
|
} |
|
|
|
//获取用户配置 |
|
HttpClientResult<LoginUsersConfiguration> loginUsers = await _tokenProviderService.GetUserConfiguration(token); |
|
if (loginUsers.Code == "Error") |
|
{ |
|
_logger.LogWarning("GetRegionRootInfo接口获取用户配置失败"); |
|
return ApiResult<RegionStructureRootDto>.IsFail("GetRegionRootInfo接口获取用户配置失败"); |
|
} |
|
dto.Ubpid = loginUsers.Data.Ubpid; |
|
|
|
HttpClientResult<object> riskResult = await _tokenProviderService |
|
.SendAndParseAsync<RegionRootInfoReqDto, HttpClientResult<object>>( |
|
"https://zrh.szdunan.cn/v1/api/region/index_no_check_region", |
|
token, dto, HttpMethod.Post); |
|
|
|
if (riskResult != null && riskResult.Data != null && riskResult.Data.ToString()!.Length > 10) |
|
{ |
|
RegionStructureRootDto httpClientResult = JsonSerializer.Deserialize<RegionStructureRootDto>(riskResult.Data.ToString()!)!; |
|
if (httpClientResult != null) |
|
{ |
|
result.Data = httpClientResult; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
_logger.LogWarning(ex, "GetRegionRootInfo接口出错"); |
|
return ApiResult<RegionStructureRootDto>.IsFail($"GetRegionRootInfo接口出错{ex.Message}"); |
|
} |
|
|
|
return result; |
|
} |
|
} |
|
} |