|
@@ -8,6 +8,7 @@ using IMES_Middleware_Platform.Api.Domain.FuelDispenser.Dto;
|
|
|
using IMES_Middleware_Platform.Api.Services.Module;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
@@ -34,11 +35,15 @@ namespace IMES_Middleware_Platform.Api.Services.Association
|
|
|
{
|
|
|
private readonly IConfiguration _configuration;
|
|
|
public readonly IFuelDispenserRepository _fuelDispenserRepository;
|
|
|
+ public readonly IAlarmHistoryRepository _alarmHistoryRepository;
|
|
|
+ public readonly ILifeCycleRepository _lifeCycleRepository;
|
|
|
static string token = string.Empty;
|
|
|
- public AssociationService(IConfiguration configuration, IFuelDispenserRepository fuelDispenserRepository)
|
|
|
+ public AssociationService(IConfiguration configuration, IFuelDispenserRepository fuelDispenserRepository, IAlarmHistoryRepository alarmHistoryRepository, ILifeCycleRepository lifeCycleRepository)
|
|
|
{
|
|
|
_configuration = configuration;
|
|
|
_fuelDispenserRepository = fuelDispenserRepository;
|
|
|
+ _alarmHistoryRepository = alarmHistoryRepository;
|
|
|
+ _lifeCycleRepository = lifeCycleRepository;
|
|
|
}
|
|
|
|
|
|
public Task<LocalApiDto> GetAllStation(string areaType, string search)
|
|
@@ -54,21 +59,11 @@ namespace IMES_Middleware_Platform.Api.Services.Association
|
|
|
[HttpPost]
|
|
|
public async Task GetDispensersAsync(string expand1, string expand2, string search)
|
|
|
{
|
|
|
-
|
|
|
HttpHelper helper = new HttpHelper();
|
|
|
-
|
|
|
string postUrl = "https://cma-fds.org.cn/api/v1/dispensers";
|
|
|
var size = 20;
|
|
|
var page = 0;
|
|
|
- //string result = await helper.GetDispensersDataAsync(postUrl, token, "", expand1, expand2, search, size, page);// "supplier", "station"
|
|
|
- //Root myObject = Newtonsoft.Json.JsonConvert.DeserializeObject<Root>(result);
|
|
|
- //int totalRequests = myObject != null ? (int)Math.Ceiling((double)myObject.TotalElements / size) : 0;
|
|
|
await GetAllDataAsync(postUrl, token, expand1, expand2, search, size);
|
|
|
- //if (myObject != null)
|
|
|
- //{
|
|
|
- // await AddFuelDispenserAsync(myObject);
|
|
|
- //}
|
|
|
- //return myObject;
|
|
|
}
|
|
|
[HttpPost]
|
|
|
public async Task<UserResponseDto> GetTokenAsync(UserLogin user)
|
|
@@ -94,6 +89,16 @@ namespace IMES_Middleware_Platform.Api.Services.Association
|
|
|
token = myObject.Token;
|
|
|
return myObject;
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 电子档案
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="postUrl"></param>
|
|
|
+ /// <param name="token"></param>
|
|
|
+ /// <param name="expand1"></param>
|
|
|
+ /// <param name="expand2"></param>
|
|
|
+ /// <param name="search"></param>
|
|
|
+ /// <param name="pageSize"></param>
|
|
|
+ /// <returns></returns>
|
|
|
public async Task GetAllDataAsync(string postUrl, string token, string expand1, string expand2, string search, int pageSize)
|
|
|
{
|
|
|
int currentPage = 0;
|
|
@@ -108,6 +113,7 @@ namespace IMES_Middleware_Platform.Api.Services.Association
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
await AddFuelDispenserAsync(myObject);
|
|
|
|
|
|
// 增加当前页数
|
|
@@ -115,6 +121,184 @@ namespace IMES_Middleware_Platform.Api.Services.Association
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 获取生命周期
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task GetLifecycleAsync(int id)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string jsonString = @"
|
|
|
+ [
|
|
|
+ {
|
|
|
+ ""启用"": [
|
|
|
+ [""disable"", ""enable""],
|
|
|
+ [""bind"", ""enable""]
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ ""维修"": [
|
|
|
+ [""enable"", ""disable""],
|
|
|
+ [""bind"", ""disable""]
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ ""加油站注册"": [
|
|
|
+ [""factory"", ""bind""]
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ ""出厂注册"": [
|
|
|
+ [""register"", ""factory""],
|
|
|
+ [""bind"", ""factory""]
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]";
|
|
|
+ JArray jsonArray = JArray.Parse(jsonString);
|
|
|
+ int currentPage = 0;
|
|
|
+ int pageSize = 20;
|
|
|
+ HttpHelper helper = new HttpHelper();
|
|
|
+ List<LifecycleDto> list = new List<LifecycleDto>();
|
|
|
+ List<int> intList = new List<int>();
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ string result = await helper.GetLifecycleAsync("https://cma-fds.org.cn/api/v1/audits?", token, id, pageSize, currentPage);
|
|
|
+ LifecycleRoot myObject = Newtonsoft.Json.JsonConvert.DeserializeObject<LifecycleRoot>(result);
|
|
|
+ if (myObject == null || myObject.Content == null || myObject.Content.Count == 0)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ for (var i = 0; i < myObject.Content.Count(); i++)
|
|
|
+ {
|
|
|
+ DateTime? CreatedDate = myObject.Content[i].CreatedDate.HasValue
|
|
|
+ ? DateTimeOffset.FromUnixTimeMilliseconds(myObject.Content[i].CreatedDate.Value).UtcDateTime
|
|
|
+ : (DateTime?)null;
|
|
|
+ var device = myObject.Content[i].Content.DeviceStatus;
|
|
|
+ string keyName = string.Empty;
|
|
|
+ if (device is string)
|
|
|
+ {
|
|
|
+ // 处理字符串类型
|
|
|
+ keyName = ((string)device) == "register" ? "备案":"";
|
|
|
+ // 进行相应的操作
|
|
|
+ }
|
|
|
+ else if (device is JArray)
|
|
|
+ {
|
|
|
+ // 处理字符串数组类型
|
|
|
+ JArray statusArray = (JArray)device;
|
|
|
+ foreach (JObject item in jsonArray)
|
|
|
+ {
|
|
|
+ foreach (var kvp in item)
|
|
|
+ {
|
|
|
+ //keyName = kvp.Key;
|
|
|
+
|
|
|
+ JArray innerArray = (JArray)kvp.Value;
|
|
|
+ foreach (JArray subArray in innerArray)
|
|
|
+ {
|
|
|
+ // Compare each element in the subArray with statusArray
|
|
|
+ bool isEqual = JArray.DeepEquals(subArray, statusArray);
|
|
|
+ if (isEqual)
|
|
|
+ {
|
|
|
+ keyName = kvp.Key;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LifecycleDto lifecycleDto = new LifecycleDto()
|
|
|
+ {
|
|
|
+ CreatedDate = CreatedDate,
|
|
|
+ FuelId = id,
|
|
|
+ Operation = keyName,
|
|
|
+ Operator = myObject.Content[i].CreatedBy.Name,
|
|
|
+ OperatorID = myObject.Content[i].CreatedBy.Id,
|
|
|
+ LifeCycleID = myObject.Content[i].Id
|
|
|
+ };
|
|
|
+ list.Add(lifecycleDto);
|
|
|
+ intList.Add(lifecycleDto.LifeCycleID);
|
|
|
+ }
|
|
|
+ // 增加当前页数
|
|
|
+ currentPage++;
|
|
|
+ }
|
|
|
+ var lifeCycle = _lifeCycleRepository.Where(x => intList.Contains(x.LifeCycleID)).ToList();
|
|
|
+ lifeCycle.ForEach(a =>
|
|
|
+ {
|
|
|
+ list.RemoveAll(e => e.LifeCycleID == a.LifeCycleID);
|
|
|
+ });
|
|
|
+ if (list != null)
|
|
|
+ {
|
|
|
+ await _lifeCycleRepository.InsertAsync(LifecycleDto.ToFuelDispenserList(list));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取报警历史
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task GetAlarmHistoryAsync(int id)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ int currentPage = 0;
|
|
|
+ int pageSize = 20;
|
|
|
+ HttpHelper helper = new HttpHelper();
|
|
|
+ List<int> intList = new List<int>();
|
|
|
+ List<AlarmHistoryDto> historyDtos = new List<AlarmHistoryDto>();
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ string result = await helper.GetAlarmHistoryAsync("https://cma-fds.org.cn/api/v1/notices?", token, id, pageSize, currentPage);
|
|
|
+ AlarmHistoryRoot myObject = Newtonsoft.Json.JsonConvert.DeserializeObject<AlarmHistoryRoot>(result);
|
|
|
+ if (myObject == null || myObject.Content == null || myObject.Content.Count == 0)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ for (var i = 0; i < myObject.Content.Count(); i++)
|
|
|
+ {
|
|
|
+ string origin = myObject.Content[i].origin;
|
|
|
+ DateTime? CreatedDate = myObject.Content[i].createdDate.HasValue
|
|
|
+ ? DateTimeOffset.FromUnixTimeMilliseconds(myObject.Content[i].createdDate.Value).UtcDateTime
|
|
|
+ : (DateTime?)null;
|
|
|
+ AlarmHistoryDto alarmHistoryDto = new AlarmHistoryDto
|
|
|
+ {
|
|
|
+ FuelId = id,
|
|
|
+ GasStation = myObject.Content[i].Station?.Name,
|
|
|
+ AlarmDescription = myObject.Content[i].Alarm?.description,
|
|
|
+ AlarmSource = origin == "blackBox" ? "安全装置" : origin == "platform" ? "云平台" : null,
|
|
|
+ SerialNumber = myObject.Content[i].dispenser.SerialNum,
|
|
|
+ AlarmType = myObject.Content[i].Alarm?.type,
|
|
|
+ CreatedDate = CreatedDate,
|
|
|
+ Name = myObject.Content[i].dispenser.Name,
|
|
|
+ AlarmHistoryID = myObject.Content[i].id
|
|
|
+ };
|
|
|
+ historyDtos.Add(alarmHistoryDto);
|
|
|
+ intList.Add(alarmHistoryDto.AlarmHistoryID);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 增加当前页数
|
|
|
+ currentPage++;
|
|
|
+ }
|
|
|
+ var alarmHistory = _alarmHistoryRepository.Where(x => intList.Contains(x.AlarmHistoryID)).ToList();
|
|
|
+ alarmHistory.ForEach(a =>
|
|
|
+ {
|
|
|
+ historyDtos.RemoveAll(e => e.AlarmHistoryID == a.AlarmHistoryID);
|
|
|
+ });
|
|
|
+ if (historyDtos != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ await _alarmHistoryRepository.InsertAsync(AlarmHistoryDto.ToFuelDispenserList(historyDtos));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
public async Task RepeatOperation(int numberOfTimes)
|
|
|
{
|
|
|
for (int i = 0; i < numberOfTimes; i++)
|
|
@@ -128,7 +312,8 @@ namespace IMES_Middleware_Platform.Api.Services.Association
|
|
|
{
|
|
|
for (var i = 0; i < myObject.Content.Count(); i++)
|
|
|
{
|
|
|
-
|
|
|
+ await GetLifecycleAsync(myObject.Content[i].Id);
|
|
|
+ await GetAlarmHistoryAsync(myObject.Content[i].Id);
|
|
|
DateTime? ProductTime = myObject.Content[i].ProductTime.HasValue
|
|
|
? DateTimeOffset.FromUnixTimeMilliseconds(myObject.Content[i].ProductTime.Value).UtcDateTime
|
|
|
: (DateTime?)null;
|
|
@@ -148,10 +333,14 @@ namespace IMES_Middleware_Platform.Api.Services.Association
|
|
|
StartupDate = StartTime, // 使用实际的启动时间
|
|
|
InstallationDate = null, // 使用实际的安装时间
|
|
|
DeviceStatus = myObject.Content[i].DeviceStatus,
|
|
|
- OnlineStatus = myObject.Content[i].OnlineStatus// 假设在线状态为1,可以根据实际情况设置
|
|
|
+ OnlineStatus = myObject.Content[i].OnlineStatus,// 假设在线状态为1,可以根据实际情况设置
|
|
|
+ AccuracyLevel = myObject.Content[i].AccuracyLevel,//准确度等级
|
|
|
+ MeasureRang = myObject.Content[i].MeasureRang,//测量范围
|
|
|
+ ModelSpec = myObject.Content[i].ModelSpec,//规格参数
|
|
|
+ FuelId = myObject.Content[i].Id
|
|
|
};
|
|
|
var fuelDispenser = _fuelDispenserRepository.Where(x => x.SerialNumber == fuelDispenserDto.SerialNumber).First();
|
|
|
- if (fuelDispenser != null)
|
|
|
+ if (fuelDispenser == null)
|
|
|
{
|
|
|
await _fuelDispenserRepository.InsertAsync(fuelDispenserDto.ToFuelDispenser(fuelDispenserDto));
|
|
|
}
|