@ -3,11 +3,14 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging ;
using Newtonsoft.Json ;
using Newtonsoft.Json.Serialization ;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text ;
using ParkingLotEntity.DB ;
using ParkingLotEntity.ParkingLotModelDto ;
using ParkingLotEntity.ParkingLotModelDto.BaseModels ;
using ParkingLotEntity.ParkingLotModels ;
using Pipelines.Sockets.Unofficial.Arenas ;
using System.Collections ;
using System.Collections.Generic ;
using System.Net.NetworkInformation ;
using System.Text ;
using System.Text.Encodings.Web ;
@ -255,7 +258,7 @@ namespace ParkLotInfoService
projectId = long . Parse ( proStr ) ;
}
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 } ;
DoorStateRecord door = new DoorStateRecord ( ) { Id = UidGenerator . Uid ( ) , DoorId = dto . doorId , State = ( short ) dto . typeId , StateTime = string . IsNullOrEmpty ( dto . date ) ? DateTime . Now : DateTime . Parse ( dto . date ) , DoorName = dto . doorName , StateDesc = dto . typeName , CreateTime = DateTime . Now , ProjectId = projectId } ;
_ context . DoorStateRecords . Add ( door ) ;
_l ogger . LogError ( this . GetType ( ) . FullName + " PostDoorControlRecord 入库前" , string . Format ( "入库请求;{0}" , _ context . DoorStateRecords . Count ( ) ) ) ;
var res = await _ context . SaveChangesAsync ( ) ;
@ -296,14 +299,17 @@ namespace ParkLotInfoService
{
projectId = long . Parse ( proStr ) ;
}
//入库
_ context . DoorControlStates . Add ( new DoorControlState ( ) { Id = UidGenerator . Uid ( ) , DeviceId = dto . deviceld , Type = ( short ) dto . type , StateTime = string . IsNullOrEmpty ( dto . date ) ? DateTime . Now : Convert . ToDateTime ( dto . date ) , CreateTime = DateTime . Now , DeviceName = dto . deviceName , TypeName = dto . typeName , ProjectId = projectId } ) ;
var res = await _ context . SaveChangesAsync ( ) ;
//门禁的设备状态写入redis
//找出所有的门禁设备
var data = await _d BContext . PtThings . ToListAsync ( ) ;
var eqPthings = await _d BContext . PtThings . Where ( a = > a . ParamCode = = "AccessControl" ) . Select ( d = > d . Id ) . ToListAsync ( ) ;
if ( eqPthings = = null | | eqPthings . Count = = 0 )
{ return result ; }
var doorlocks = await _d BContext . PtThingMapLabels . Where ( m = > eqPthings . Contains ( m . ThingId ) & & m . LabelCode . Contains ( "安消门禁Id_" ) ) . Select ( d = > new { Id = d . ThingId , DeciveId = int . Parse ( d . LabelCode . Substring ( d . LabelCode . LastIndexOf ( "_" ) + 1 ) ) } ) . ToListAsync ( ) ;
var datda = await _d BContext . PtThingMapLabels . Where ( m = > eqPthings . Contains ( m . ThingId ) & & m . LabelCode . Contains ( "安消门禁Id_" ) ) . Select ( d = > new { Id = d . ThingId , DeciveId = d . LabelCode } ) . ToListAsync ( ) ;
var doorlocks = await _d BContext . PtThingMapLabels . Where ( m = > eqPthings . Contains ( m . ThingId ) & & m . LabelCode . Contains ( "安消门禁Dev Id_" ) ) . Select ( d = > new { Id = d . ThingId , DeciveId = int . Parse ( d . LabelCode . Substring ( d . LabelCode . LastIndexOf ( "_" ) + 1 ) ) } ) . ToListAsync ( ) ;
if ( doorlocks = = null | | doorlocks . Count = = 0 )
{
return result ;
@ -331,7 +337,7 @@ namespace ParkLotInfoService
}
catch ( Exception ex )
{
_l ogger . LogError ( this . GetType ( ) . FullName + " PostDoorControlRecord " , string . Format ( "抛出了异常信息: 请求超时,请求失败;{0}" , ex . Message ) ) ;
_l ogger . LogError ( this . GetType ( ) . FullName + " PostDoorEqState " , string . Format ( "抛出了异常信息: 请求超时,请求失败;{0}" , ex . Message ) ) ;
}
return result ;
}
@ -534,7 +540,7 @@ namespace ParkLotInfoService
if ( resModel = = null | | resModel . Suc ! = 2 0 0 )
{
result . Code = RequestBackStatuEnum . diy . Value ;
result . Msg = "下空 失败!" ;
result . Msg = "订阅 失败!" ;
}
result . Data = resModel ;
}
@ -557,7 +563,76 @@ namespace ParkLotInfoService
// _logger.LogError(this.GetType().FullName + " PushLifangDoorRecord ", string.Format("抛出了异常信息:{0}", ex));
// }
//}
public async Task < ApiResult < int > > PostDoorData ( )
{
ApiResult < int > result = new ApiResult < int > ( ) { Code = RequestBackStatuEnum . success . Value , Msg = "接口请求成功!" } ;
//获取所有门禁接口名
string api = "custom/v1/getDoor" ;
long projectId = 0 ;
List < Record > records = new List < Record > ( ) ;
try
{
string token = await GetLifangDoorLockToken ( ) ;
var parm = new DoorInfoParmDto ( ) ; /*{ pageSize = 200, pageNumber = 0 };*/
parm . pageNumber = 1 ;
parm . pageSize = 2 0 ;
//项目id
string proStr = _ configuration [ "PorjectId" ] ;
if ( ! string . IsNullOrEmpty ( proStr ) )
{
long . TryParse ( proStr , out projectId ) ;
}
var doors = await _ context . DoorInfos . ToListAsync ( ) ;
if ( doors ! = null & & doors . Count > 0 )
{
_ context . DoorInfos . RemoveRange ( doors ) ;
}
for ( int i = 0 ; i < = 5 0 ; i + + )
{
parm . pageNumber = i ;
var res = await GetDoorsRecord ( api , parm , token ) ;
if ( res = = null | | res . Count = = 0 )
{
continue ;
}
records . AddRange ( res ) ;
}
foreach ( var item in records )
{
DoorInfo door = new DoorInfo ( ) { Id = UidGenerator . Uid ( ) , DoorId = item . doorId , DoorName = item . doorName , DeviceSysId = ( short ) item . deviceSysId , AreaIdList = item . areaIdList = = null ? string . Empty : string . Join ( "," , item . areaIdList ) , DevType = ( short ) item . devType , ChannelNo = ( short ) item . channelNo } ;
_ context . DoorInfos . Add ( door ) ;
}
var resData = await _ context . SaveChangesAsync ( ) ;
result . Data = resData ;
}
catch ( Exception ex )
{
_l ogger . LogError ( this . GetType ( ) . FullName + " PostDoorData " , string . Format ( "抛出了异常信息:{0}" , ex ) ) ;
}
return result ;
}
private async Task < List < Record > > GetDoorsRecord ( string api , DoorInfoParmDto parm , string token )
{
List < Record > records = new List < Record > ( ) ;
var res = await GetLifangDoorLockPostData ( api , parm , token ) ;
if ( string . IsNullOrEmpty ( res ) )
{
return records ;
}
var resModel = JsonConvert . DeserializeObject < DoorResponseDto > ( res ) ;
if ( resModel = = null | | resModel . suc ! = 2 0 0 | | resModel . obj = = null )
{
return records ;
}
//var obj = resModel.obj;
//var data = JsonConvert.DeserializeObject<DoorResponse>(obj);
if ( resModel . obj . records = = null | | resModel . obj . records . Count = = 0 )
{
return records ;
}
return resModel . obj . records ;
}
#endregion 门禁
}
}