|
@@ -1,37 +1,167 @@
|
|
|
using Core.Service_Middleware_Platform.Api.Core;
|
|
using Core.Service_Middleware_Platform.Api.Core;
|
|
|
|
|
+using DotNetCore.CAP.Internal;
|
|
|
|
|
+using IdentityModel;
|
|
|
using IMES_Middleware_Platform.Api.Core.Consts;
|
|
using IMES_Middleware_Platform.Api.Core.Consts;
|
|
|
|
|
+using IMES_Middleware_Platform.Api.Core.Handlers;
|
|
|
|
|
+using IMES_Middleware_Platform.Api.Domain.FuelDispenser;
|
|
|
|
|
+using IMES_Middleware_Platform.Api.Domain.FuelDispenser.Dto;
|
|
|
|
|
+using IMES_Middleware_Platform.Api.Services.Module;
|
|
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
|
+using System.ComponentModel;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
|
+using System.Net;
|
|
|
|
|
+using System.Net.Http;
|
|
|
|
|
+using System.Reactive;
|
|
|
using System.Text;
|
|
using System.Text;
|
|
|
|
|
+using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
using ZhonTai.Admin.Core.Configs;
|
|
using ZhonTai.Admin.Core.Configs;
|
|
|
|
|
+using ZhonTai.Admin.Core.Db;
|
|
|
|
|
+using ZhonTai.Admin.Core.Logs;
|
|
|
|
|
+using ZhonTai.Admin.Services;
|
|
|
using ZhonTai.Common.Helpers;
|
|
using ZhonTai.Common.Helpers;
|
|
|
|
|
+using ZhonTai.DynamicApi;
|
|
|
|
|
+using ZhonTai.DynamicApi.Attributes;
|
|
|
|
|
|
|
|
namespace IMES_Middleware_Platform.Api.Services.Association
|
|
namespace IMES_Middleware_Platform.Api.Services.Association
|
|
|
{
|
|
{
|
|
|
- public class AssociationService : IAssociationService
|
|
|
|
|
|
|
+ [Order(1010)]
|
|
|
|
|
+ [DynamicApi(Area = ApiConsts.AreaName)]
|
|
|
|
|
+ public class AssociationService : BaseService, IAssociationService, IDynamicApi
|
|
|
{
|
|
{
|
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IConfiguration _configuration;
|
|
|
- public AssociationService(IConfiguration configuration)
|
|
|
|
|
|
|
+ public readonly IFuelDispenserRepository _fuelDispenserRepository;
|
|
|
|
|
+ static string token = string.Empty;
|
|
|
|
|
+ public AssociationService(IConfiguration configuration, IFuelDispenserRepository fuelDispenserRepository)
|
|
|
{
|
|
{
|
|
|
_configuration = configuration;
|
|
_configuration = configuration;
|
|
|
|
|
+ _fuelDispenserRepository = fuelDispenserRepository;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Task<LocalApiDto> GetAllStation(string areaType, string search)
|
|
public Task<LocalApiDto> GetAllStation(string areaType, string search)
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
throw new NotImplementedException();
|
|
throw new NotImplementedException();
|
|
|
}
|
|
}
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 加油机统计
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="user"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ [HttpPost]
|
|
|
|
|
+ public async Task GetDispensersAsync(string expand1, string expand2, string search)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ HttpHelper helper = new HttpHelper();
|
|
|
|
|
|
|
|
- public Task<UserResponseDto> GetToken(UserLogin user)
|
|
|
|
|
|
|
+ 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)
|
|
|
{
|
|
{
|
|
|
|
|
+ HttpHelper helper = new HttpHelper();
|
|
|
var middleAppConfig = ConfigHelper.Get<MiddleAppConfig>("appconfig");
|
|
var middleAppConfig = ConfigHelper.Get<MiddleAppConfig>("appconfig");
|
|
|
if (middleAppConfig.IsDevLogin)
|
|
if (middleAppConfig.IsDevLogin)
|
|
|
{
|
|
{
|
|
|
user = user.TestLogin();
|
|
user = user.TestLogin();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ var json = JsonSerializer.Serialize(new
|
|
|
|
|
+ {
|
|
|
|
|
+ email = user.Email,
|
|
|
|
|
+ mobile = user.Mobile,
|
|
|
|
|
+ name = user.Name,
|
|
|
|
|
+ password = user.Password
|
|
|
|
|
+ });
|
|
|
|
|
+ string postUrl = "https://cma-fds.org.cn/api/v1/users/login";
|
|
|
|
|
+ HttpContent postContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
|
+ string postResponse = await helper.PostAsync(postUrl, postContent);
|
|
|
|
|
+ UserResponseDto myObject = Newtonsoft.Json.JsonConvert.DeserializeObject<UserResponseDto>(postResponse);
|
|
|
|
|
+ token = myObject.Token;
|
|
|
|
|
+ return myObject;
|
|
|
|
|
+ }
|
|
|
|
|
+ public async Task GetAllDataAsync(string postUrl, string token, string expand1, string expand2, string search, int pageSize)
|
|
|
|
|
+ {
|
|
|
|
|
+ int currentPage = 0;
|
|
|
|
|
+ HttpHelper helper = new HttpHelper();
|
|
|
|
|
+ while (true)
|
|
|
|
|
+ {
|
|
|
|
|
+ string result = await helper.GetDispensersDataAsync(postUrl, token, "", expand1, expand2, search, pageSize, currentPage);
|
|
|
|
|
+
|
|
|
|
|
+ Root myObject = Newtonsoft.Json.JsonConvert.DeserializeObject<Root>(result);
|
|
|
|
|
+
|
|
|
|
|
+ if (myObject == null || myObject.Content == null || myObject.Content.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ await AddFuelDispenserAsync(myObject);
|
|
|
|
|
+
|
|
|
|
|
+ // 增加当前页数
|
|
|
|
|
+ currentPage++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ public async Task RepeatOperation(int numberOfTimes)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int i = 0; i < numberOfTimes; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 在这里执行你想要重复的操作
|
|
|
|
|
+ Console.WriteLine($"Executing operation {i + 1} of {numberOfTimes}");
|
|
|
|
|
+ // 例如,你可以调用其他方法、发送请求、处理数据等等
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ public async Task AddFuelDispenserAsync(Root myObject)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (var i = 0; i < myObject.Content.Count(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ DateTime? ProductTime = myObject.Content[i].ProductTime.HasValue
|
|
|
|
|
+ ? DateTimeOffset.FromUnixTimeMilliseconds(myObject.Content[i].ProductTime.Value).UtcDateTime
|
|
|
|
|
+ : (DateTime?)null;
|
|
|
|
|
+ DateTime? StartTime = myObject.Content[i].StartTime.HasValue
|
|
|
|
|
+ ? DateTimeOffset.FromUnixTimeMilliseconds(myObject.Content[i].StartTime.Value).UtcDateTime
|
|
|
|
|
+ : (DateTime?)null;
|
|
|
|
|
+ FuelDispenserDto fuelDispenserDto = new FuelDispenserDto
|
|
|
|
|
+ {
|
|
|
|
|
+ Name = myObject.Content[i].Name,
|
|
|
|
|
+ OilCompany = myObject?.Content[i]?.Station?.Company?.Name,
|
|
|
|
|
+ GasStation = myObject.Content[i].Station?.Name,
|
|
|
|
|
+ SerialNumber = myObject.Content[i].SerialNum,
|
|
|
|
|
+ Model = myObject.Content[i].Type,
|
|
|
|
|
+ GunCount = myObject.Content[i].NozzleControlsTotal, // 例如,假设有4个枪
|
|
|
|
|
+ Manufacturer = myObject.Content[i].Supplier?.Description,
|
|
|
|
|
+ ManufactureDate = ProductTime, // 使用实际的出厂时间
|
|
|
|
|
+ StartupDate = StartTime, // 使用实际的启动时间
|
|
|
|
|
+ InstallationDate = null, // 使用实际的安装时间
|
|
|
|
|
+ DeviceStatus = myObject.Content[i].DeviceStatus,
|
|
|
|
|
+ OnlineStatus = myObject.Content[i].OnlineStatus// 假设在线状态为1,可以根据实际情况设置
|
|
|
|
|
+ };
|
|
|
|
|
+ var fuelDispenser = _fuelDispenserRepository.Where(x => x.SerialNumber == fuelDispenserDto.SerialNumber).First();
|
|
|
|
|
+ if (fuelDispenser != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ await _fuelDispenserRepository.InsertAsync(fuelDispenserDto.ToFuelDispenser(fuelDispenserDto));
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ fuelDispenser.DeviceStatus = fuelDispenserDto.DeviceStatus;
|
|
|
|
|
+ fuelDispenser.OnlineStatus = fuelDispenserDto.OnlineStatus;
|
|
|
|
|
+ await _fuelDispenserRepository.UpdateAsync(fuelDispenser);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- throw new ArgumentNullException();
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|