diff --git a/WeiCloud.Fusion/ParkingLotService/ParkLotInfoService/IParkingLotDataService.cs b/WeiCloud.Fusion/ParkingLotService/ParkLotInfoService/IParkingLotDataService.cs index d6639dd..86b07f0 100644 --- a/WeiCloud.Fusion/ParkingLotService/ParkLotInfoService/IParkingLotDataService.cs +++ b/WeiCloud.Fusion/ParkingLotService/ParkLotInfoService/IParkingLotDataService.cs @@ -18,7 +18,7 @@ namespace ParkLotInfoService Task> DoorLockSendCommand(int doorId, string command); Task PostDoorControlRecord(DoorStateRecordDto dto); Task PostDoorEqState(DoorEqStateDto dto); - Task> PushLifangDoorData(string tppic, string address); + Task> PushLifangDoorData(string tppic, string address,string token); #endregion } } diff --git a/WeiCloud.Fusion/ParkingLotService/ParkLotInfoService/ParkingLotDataService.cs b/WeiCloud.Fusion/ParkingLotService/ParkLotInfoService/ParkingLotDataService.cs index d7d3944..ce10510 100644 --- a/WeiCloud.Fusion/ParkingLotService/ParkLotInfoService/ParkingLotDataService.cs +++ b/WeiCloud.Fusion/ParkingLotService/ParkLotInfoService/ParkingLotDataService.cs @@ -26,6 +26,7 @@ using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using Pipelines.Sockets.Unofficial.Arenas; using System.Threading; using Microsoft.EntityFrameworkCore; +using NewLife.IP; namespace ParkLotInfoService @@ -62,9 +63,11 @@ namespace ParkLotInfoService { ApiResult result = new ApiResult() { Code = RequestBackStatuEnum.success.Value, Msg = "接口请求成功" }; //ParkingAccessRecordDto dto=new ParkingAccessRecordDto(); + long projectId = 0; try { - + var projectIdStr = _configuration["PorjectId"]; + long.TryParse(projectIdStr, out projectId); ////ParkingAccessRecord record = new ParkingAccessRecord() { Id=1,CarCode="001"}; ////_context.ParkingAccessRecords.Add(record); ////var res = await _context.SaveChangesAsync(); @@ -77,7 +80,7 @@ namespace ParkLotInfoService result.Msg = "上传数据为空"; return result; } - ParkingAccessRecord record = new ParkingAccessRecord() { Id = UidGenerator.Uid(), CarCode = model.CarCode, ChannelId = model.ChannelId, ChannelName = model.ChannelName, Guid = model.GUID, ImagePath = model.ImagePath, InOrOut = model.InOrOut, InTime = model.InTime, ParkId = model.ParkId, PassTime = model.PassTime, ProjectId = model.ProjectId, CreateTime = DateTime.Now }; + ParkingAccessRecord record = new ParkingAccessRecord() { Id = UidGenerator.Uid(), CarCode = model.carCode, ChannelId = model.channelId, ChannelName = model.channelName, Guid = model.GUID, ImagePath = model.imagePath, InOrOut = model.inOrOut, InTime = model.inTime, ParkId = model.parkId, PassTime = model.passTime, ProjectId = projectId, CreateTime = DateTime.Now }; _context.ParkingAccessRecords.Add(record); var res = await _context.SaveChangesAsync(); _logger.LogInformation($"停车记录插入成功{record.Id}"); @@ -152,8 +155,8 @@ namespace ParkLotInfoService string json = System.Text.Json.JsonSerializer.Serialize(parmJson, options); var content = new StringContent(json, Encoding.UTF8, "application/json"); - _ = Task.Run(async () => - { + //_ = Task.Run(async () => + //{ try { var httpResponse = client.PostAsync(url, content); @@ -173,7 +176,7 @@ namespace ParkLotInfoService { _logger.LogError(this.GetType().FullName + " PostSearchResult", string.Format("抛出了异常信息: 请求超时,请求失败;{0}", ex.Message)); } - }); + // }); return resStr; } public async Task> GetIpPing() @@ -246,7 +249,7 @@ namespace ParkLotInfoService /// public async Task PostDoorControlRecord(DoorStateRecordDto dto) { - TokenDto result = new TokenDto() { Ret = "SUCCESS", Suc = 200 }; + TokenDto result = new TokenDto() { Ret = "FAIL", Suc = 2005 }; long projectId = 0; try { @@ -256,11 +259,15 @@ namespace ParkLotInfoService { projectId = long.Parse(proStr); } - DoorStateRecord door = new DoorStateRecord() { DoorId = dto.DoorId, State =(short) dto.TypeId, StateTime =DateTime.Parse(dto.Date) , DoorName = dto.DoorName, StateDesc = dto.TypeName,CreateTime = DateTime.Now , ProjectId = projectId,Id = UidGenerator.Uid() }; + + DoorStateRecord door = new DoorStateRecord() { Id = UidGenerator.Uid(),DoorId = dto.doorId, State =(short) dto.typeId, StateTime =DateTime.Parse(dto.date) , DoorName = dto.doorName, StateDesc = dto.typeName,CreateTime = DateTime.Now , ProjectId = projectId }; _context.DoorStateRecords.Add(door); + _logger.LogError(this.GetType().FullName + " PostDoorControlRecord 入库前", string.Format("入库请求;{0}",_context.DoorStateRecords.Count())); var res= await _context.SaveChangesAsync(); if (res > 0) { + _logger.LogError(this.GetType().FullName + " PostDoorControlRecord 入库后", string.Format("入库成功息: 请求超时,请求失败;{0}", door.Id)); + result.Object = door.Id.ToString(); result.Ret = "SUCCESS"; result.Suc = 200; } @@ -272,7 +279,7 @@ namespace ParkLotInfoService } catch (Exception ex) { - _logger.LogError(this.GetType().FullName + " PostDoorControlRecord", string.Format("抛出了异常信息: 请求超时,请求失败;{0}", ex.Message)); + _logger.LogError(this.GetType().FullName + " PostDoorControlRecord 保存记录--", string.Format("抛出了异常信息: 请求超时,请求失败;{0}", ex.Message)); } return result; @@ -312,7 +319,7 @@ namespace ParkLotInfoService return result; } //找出当前订阅推送的门禁id对应的设备 - var doorLock=doorlocks.Where(a => a.DeciveId == dto.Deviceld).FirstOrDefault(); + var doorLock=doorlocks.Where(a => a.DeciveId == dto.deviceld).FirstOrDefault(); if (doorLock == null) { return result; @@ -324,7 +331,7 @@ namespace ParkLotInfoService return result; } //redis中门禁状态的点位对象封装 - RealDataOnlyValueBo real = new RealDataOnlyValueBo() { Id = realId.GetValueOrDefault(), Realvalue = dto.Type.ToString(), Updatetime = DateTime.Now }; + RealDataOnlyValueBo real = new RealDataOnlyValueBo() { Id = realId.GetValueOrDefault(), Realvalue = dto.type.ToString(), Updatetime = DateTime.Now }; _dictionaryService.PushValue("ProOnlyValue" + projectId, realId.ToString(), real, 1); } catch (Exception ex) @@ -347,7 +354,8 @@ namespace ParkLotInfoService string api = $"custom/v1/sendCommand?doorId={doorId}&command={command}"; try { - var str = await GetLifangDoorLockPostData(api, null); + string token =await GetLifangDoorLockToken(); + var str = await GetLifangDoorLockPostData(api, null,token); if (string.IsNullOrEmpty(str)) { result.Code = RequestBackStatuEnum.diy.Value; @@ -391,7 +399,16 @@ namespace ParkLotInfoService var clientSecret = _configuration["ThirdApi:DoorLockClientSecret"]; var grantType = _configuration["ThirdApi:DoorLockGrantType"]; var apiUrl = $"{url}token/v1/oauth/token?client_id={clientId}&client_secret={clientSecret}&grant_type={grantType}"; - var client = _httpClientFactory.CreateClient(); + + var handler = new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true + }; + + using var client = new HttpClient(handler); + + //var client = _httpClientFactory.CreateClient(); + client.Timeout = TimeSpan.FromMinutes(1);//设置超时时间 try { @@ -404,8 +421,8 @@ namespace ParkLotInfoService { return token; } - var tokenModel = JsonConvert.DeserializeObject(resStr); - token = tokenModel == null ? string.Empty : tokenModel.Object; + var tokenModel = JsonConvert.DeserializeObject(resStr); + token = tokenModel == null ? string.Empty : tokenModel.obj; } // 处理响应... } @@ -426,11 +443,11 @@ namespace ParkLotInfoService /// /// /// - private async Task GetLifangDoorLockPostData(string apiName, object parmJson) + private async Task GetLifangDoorLockPostData(string apiName, object parmJson,string token) { string json = string.Empty; - //获取token - var token = await GetLifangDoorLockToken(); + ////获取token + //var token = await GetLifangDoorLockToken(); if (string.IsNullOrEmpty(token)) { return string.Empty; @@ -444,7 +461,7 @@ namespace ParkLotInfoService // 添加 Header token参数 client.DefaultRequestHeaders.Add("TOKEN", token); // 添加 Header Content-Type - client.DefaultRequestHeaders.Add("Content-Type", "application/json"); + //client.DefaultRequestHeaders.Add("Content-Type", "application/json"); client.Timeout = TimeSpan.FromMinutes(1);//设置超时时间 var options = new JsonSerializerOptions @@ -490,7 +507,7 @@ namespace ParkLotInfoService /// /// - public async Task> PushLifangDoorData(string tppic, string address) + public async Task> PushLifangDoorData(string tppic, string address,string token) { ApiResult result = new ApiResult() { Code=RequestBackStatuEnum.success.Value,Msg="接口请求成功!"}; TokenDto resDto = new TokenDto() { Ret= "SUCESS",Suc= 200 }; @@ -508,8 +525,8 @@ namespace ParkLotInfoService result.Msg = "获取订阅信息订阅失败!"; return result; } - PushDoorDto dto = new PushDoorDto() { Uuid = uuid, Expire = expire, Address = address, Topic = tppic }; - var res = await GetLifangDoorLockPostData(api, dto); + PushDoorDto dto = new PushDoorDto() { uuid = uuid, expire = expire, address = address, topic = tppic }; + var res = await GetLifangDoorLockPostData(api, dto,token); if (string.IsNullOrEmpty(res)) { result.Code = RequestBackStatuEnum.fail.Value; diff --git a/WeiCloud.Fusion/ParkingLotService/ParkingLotEntity/ParkingLotModelDto/ParkingAccessRecordDto.cs b/WeiCloud.Fusion/ParkingLotService/ParkingLotEntity/ParkingLotModelDto/ParkingAccessRecordDto.cs index fa1237e..c703032 100644 --- a/WeiCloud.Fusion/ParkingLotService/ParkingLotEntity/ParkingLotModelDto/ParkingAccessRecordDto.cs +++ b/WeiCloud.Fusion/ParkingLotService/ParkingLotEntity/ParkingLotModelDto/ParkingAccessRecordDto.cs @@ -12,35 +12,35 @@ namespace ParkingLotEntity.ParkingLotModelDto #region 停车场 public class ParkingAccessRecordDto { - /// - /// 项目id - /// - public long ProjectId { get; set; } + ///// + ///// 项目id + ///// + //public long ProjectId { get; set; } /// /// 车牌号码 /// - public string? CarCode { get; set; } + public string? carCode { get; set; } /// /// 进场时间(出场时若找不到场内车辆信息,则为空) /// - public DateTime? InTime { get; set; } + public DateTime? inTime { get; set; } /// /// 过场时间(进场时等于进场时间,出场时为出场时间) /// - public DateTime? PassTime { get; set; } + public DateTime? passTime { get; set; } /// /// 车场 ID /// - public string? ParkId { get; set; } + public string? parkId { get; set; } /// /// 0:进场,1:出场 /// - public string? InOrOut { get; set; } + public string? inOrOut { get; set; } /// /// 车辆本次进场出场标识 @@ -50,17 +50,17 @@ namespace ParkingLotEntity.ParkingLotModelDto /// /// 通道 ID /// - public string? ChannelId { get; set; } + public string? channelId { get; set; } /// /// 通道名称 /// - public string? ChannelName { get; set; } + public string? channelName { get; set; } /// /// 图片路径地址 /// - public string? ImagePath { get; set; } + public string? imagePath { get; set; } } public class ParkingAccessRecord2Dto @@ -270,27 +270,33 @@ namespace ParkingLotEntity.ParkingLotModelDto /// /// 门名称 /// - public string DoorName { get; set; } + public string doorName { get; set; } /// /// 门Id /// - public int DoorId { get; set; } + public int doorId { get; set; } /// /// 门状态 /// 0关 1进开门 2出开门 3报警开门 4报警关门 5进出开门 6门未关 7关(出) 8关(进) 9按钮开门 10紧急关门 11紧急开门 12遥控开门 13遥控关门 14布防关(出) 15布防关(进) 16紧急关(出) 17紧急关(进) 18常闭关(出) 19常闭关(进) 20防撬关(出) 21防撬关(进) 22门开(遥控关) 23门开(紧急关) 24常开 25常闭 26布防 27自动布防 28手动布防 29权限不足 33自控 99未知状态 /// - public int TypeId { get; set; } + public int typeId { get; set; } /// /// 门状态名称 /// - public string TypeName { get; set; } + public string typeName { get; set; } /// /// 门态时间 /// - public string Date { get; set; } + public string date { get; set; } } + public class DoorRecordResponse + { + public string obj { get; set; } + public string ret { get; set; } + public int suc { get; set; } + } /// /// 门禁设备在线状态 /// @@ -299,23 +305,23 @@ namespace ParkingLotEntity.ParkingLotModelDto /// /// 门禁名称 /// - public string DeviceName { get; set; } = string.Empty; + public string deviceName { get; set; } = string.Empty; /// /// 门禁Id /// - public int Deviceld { get; set; } + public int deviceld { get; set; } /// /// 门禁状态 1上线 2掉线 /// - public int Type { get; set; } + public int type { get; set; } /// ///门禁状态名称 /// - public string TypeName { get; set; } = string.Empty; + public string typeName { get; set; } = string.Empty; /// /// 门状态时间 /// - public string Date { get; set; } + public string date { get; set; } } /// @@ -323,10 +329,10 @@ namespace ParkingLotEntity.ParkingLotModelDto /// public class PushDoorDto { - public string Uuid { get; set; } = string.Empty; - public string Topic { get; set; } = string.Empty; - public string Address { get; set; } = string.Empty; - public int Expire { get; set; } + public string uuid { get; set; } = string.Empty; + public string topic { get; set; } = string.Empty; + public string address { get; set; } = string.Empty; + public int expire { get; set; } } #endregion } diff --git a/WeiCloud.Fusion/ParkingLotService/ParkingLotEntity/ParkingLotModels/WeiCloudFusionContext.cs b/WeiCloud.Fusion/ParkingLotService/ParkingLotEntity/ParkingLotModels/WeiCloudFusionContext.cs index 2e38f9a..e6c5fdc 100644 --- a/WeiCloud.Fusion/ParkingLotService/ParkingLotEntity/ParkingLotModels/WeiCloudFusionContext.cs +++ b/WeiCloud.Fusion/ParkingLotService/ParkingLotEntity/ParkingLotModels/WeiCloudFusionContext.cs @@ -22,7 +22,7 @@ public partial class WeiCloudFusionContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263. - => optionsBuilder.UseMySql("server=v4.weienergy.cn;database=WeiCloud.Fusion;user=root;password=Zrhdb#2019;port=3307", Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.18-mysql")); + => optionsBuilder.UseMySql("server=172.17.76.210;database=WeiCloud.Fusion;user=root;password=Zrhdb##2022;port=3306;default command timeout=100;CharSet=utf8;SslMode=None;allowPublicKeyRetrieval=true", Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.18-mysql")); protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/Controllers/ParkLotInfoController.cs b/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/Controllers/ParkLotInfoController.cs index a2e260b..ad2b8dc 100644 --- a/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/Controllers/ParkLotInfoController.cs +++ b/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/Controllers/ParkLotInfoController.cs @@ -45,7 +45,7 @@ namespace ParkingLotService.API.Controllers /// /// /// - [HttpPost] + [HttpGet] public async Task> DoorLockSendCommand(int doorId, string command) { return await _parkingLotDataService.DoorLockSendCommand(doorId, command); diff --git a/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/HostService/PingService .cs b/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/HostService/PingService .cs index 181d62a..e225104 100644 --- a/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/HostService/PingService .cs +++ b/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/HostService/PingService .cs @@ -11,15 +11,15 @@ namespace ParkingLotService.API.HostService { private readonly ILogger _logger; private readonly IServiceScopeFactory _serviceScopeFactory; - private readonly string _ipAddress; + // private readonly string _ipAddress; private readonly IConfiguration _configuration; private Timer _timer; private bool _isTaskRunning; - private readonly int _interval = 60000;//1分钟 + private readonly int _interval = 300000;//5分钟 public PingService(ILogger logger, IServiceScopeFactory serviceScopeFactory, IConfiguration configuration) { _logger = logger; - _ipAddress = "8.8.8.8"; // 替换为你要ping的IP + //_ipAddress = "8.8.8.8"; // 替换为你要ping的IP _serviceScopeFactory = serviceScopeFactory; _timer = new Timer(DoWork, null, Timeout.Infinite, Timeout.Infinite); _configuration = configuration; @@ -43,14 +43,16 @@ namespace ParkingLotService.API.HostService using var scope = _serviceScopeFactory.CreateScope(); var service = scope.ServiceProvider.GetRequiredService(); //停车识别仪状态获取 - await service.GetIpPing(); + //await service.GetIpPing(); + #region 门禁 + var tokenStr= await service.GetLifangDoorLockToken(); //门禁的门开关等状态 var myAddress = _configuration["MyApiAddress"];//本地地址,第三方需要回调的地址 //门的开关记录 - await service.PushLifangDoorData("SUBSCRIBE:MJ_DOOR_STATUS_EVENT", $"{myAddress}/api/ParkLotInfo/PostDoorControlRecord"); + await service.PushLifangDoorData("SUBSCRIBE:MJ_DOOR_STATUS_EVENT", $"{myAddress}/api/ParkLotInfo/PostDoorControlRecord", tokenStr); //门禁设备在线状态 - await service.PushLifangDoorData("SUBSCRIBE:DEVICE_ONLINE_EVENT", $"{myAddress}/api/ParkLotInfo/PostDoorEqState"); - //await service.CreateAbnormalEnergyAlarm(); //用能异动告警轮询 + await service.PushLifangDoorData("SUBSCRIBE:DEVICE_ONLINE_EVENT", $"{myAddress}/api/ParkLotInfo/PostDoorEqState", tokenStr); + #endregion // 任务完成后,重新启动 Timer 计时 _timer.Change(_interval, Timeout.Infinite); // 每隔 1分钟触发一次 } @@ -67,7 +69,7 @@ namespace ParkingLotService.API.HostService /// public Task StartAsync(CancellationToken cancellationToken) - { // 启动 Timer,每隔 5 秒触发一次 + { // 启动 Timer,每隔 5分钟 触发一次 _timer.Change(0, _interval); _logger.LogInformation("Timed Hosted Service started."); diff --git a/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/appsettings.json b/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/appsettings.json index 6ae71fa..aa00d98 100644 --- a/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/appsettings.json +++ b/WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/appsettings.json @@ -8,13 +8,13 @@ "RedisPrefix": "AXYJPT_", // "XX.V6_", // //, "TenantType": "false", "RedisNodes": "Zrhredis#2019@v4.weienergy.cn:6380", - "WeiCloudFusionDBConn": "server=v4.weienergy.cn;uid=root;pwd=Zrhdb#2019;port=3307;database=WeiCloud.Fusion;default command timeout=100;CharSet=utf8;SslMode=None;allowPublicKeyRetrieval=true", - "WeiCloudDBConn": "server=v4.weienergy.cn;uid=root;pwd=Zrhdb#2019;port=3307;database=WeiCloudDB.AXYJPT;default command timeout=100;CharSet=utf8;SslMode=None;allowPublicKeyRetrieval=true", + "WeiCloudFusionDBConn": "demo.weienergy.cn;uid=root;pwd=Zrhdb##2022;port=3306;database=WeiCloud.Fusion;default command timeout=100;CharSet=utf8;SslMode=None;allowPublicKeyRetrieval=true", + "WeiCloudDBConn": "server=demo.weienergy.cn;uid=root;pwd=Zrhdb##2022;port=3306;database=WeiCloudDB.AXYJPT;default command timeout=100;CharSet=utf8;SslMode=None;allowPublicKeyRetrieval=true", "AllowedHosts": "*", "ThirdApi": { - "LifangParkLotApiAddress": "192.168.21.22:9988/Parking/Handheld/", + "LifangParkLotApiAddress": "http://demo.weienergy.cn:15231/Parking/Handheld/", //"192.168.21.22:9988/Parking/Handheld/", "LifangParkLotViewIps": "192.168.5.93,192.168.5.95,192.168.5.102,192.168.5.104", - "DoorLockApi": "http://192.168.21.21:8080/open-api/", + "DoorLockApi": "http://demo.weienergy.cn:15230/open-api/", //"http://192.168.21.21:8080/open-api/", "DoorLockClientId": 69591850, "DoorLockClientSecret": "WHcpAryKFc28suzL", "DoorLockGrantType": "client_credentials", @@ -22,5 +22,5 @@ "Expire": 7200 //单位秒 }, "PorjectId": "530522108656160", - "MyApiAddress": "http://192.168.21.22:9988/Parking/Handheld/"//本项目的地址,需要提供给第三方 + "MyApiAddress": "https://demo.weienergy.cn/axparting" // "http://192.168.21.22:9988/Parking/Handheld/"//本项目的地址,需要提供给第三方 }