commit
ff001263c5
151 changed files with 55594 additions and 0 deletions
@ -0,0 +1,63 @@ |
|||
############################################################################### |
|||
# Set default behavior to automatically normalize line endings. |
|||
############################################################################### |
|||
* text=auto |
|||
|
|||
############################################################################### |
|||
# Set default behavior for command prompt diff. |
|||
# |
|||
# This is need for earlier builds of msysgit that does not have it on by |
|||
# default for csharp files. |
|||
# Note: This is only used by command line |
|||
############################################################################### |
|||
#*.cs diff=csharp |
|||
|
|||
############################################################################### |
|||
# Set the merge driver for project and solution files |
|||
# |
|||
# Merging from the command prompt will add diff markers to the files if there |
|||
# are conflicts (Merging from VS is not affected by the settings below, in VS |
|||
# the diff markers are never inserted). Diff markers may cause the following |
|||
# file extensions to fail to load in VS. An alternative would be to treat |
|||
# these files as binary and thus will always conflict and require user |
|||
# intervention with every merge. To do so, just uncomment the entries below |
|||
############################################################################### |
|||
#*.sln merge=binary |
|||
#*.csproj merge=binary |
|||
#*.vbproj merge=binary |
|||
#*.vcxproj merge=binary |
|||
#*.vcproj merge=binary |
|||
#*.dbproj merge=binary |
|||
#*.fsproj merge=binary |
|||
#*.lsproj merge=binary |
|||
#*.wixproj merge=binary |
|||
#*.modelproj merge=binary |
|||
#*.sqlproj merge=binary |
|||
#*.wwaproj merge=binary |
|||
|
|||
############################################################################### |
|||
# behavior for image files |
|||
# |
|||
# image files are treated as binary by default. |
|||
############################################################################### |
|||
#*.jpg binary |
|||
#*.png binary |
|||
#*.gif binary |
|||
|
|||
############################################################################### |
|||
# diff behavior for common document formats |
|||
# |
|||
# Convert binary document formats to text before diffing them. This feature |
|||
# is only available from the command line. Turn it on by uncommenting the |
|||
# entries below. |
|||
############################################################################### |
|||
#*.doc diff=astextplain |
|||
#*.DOC diff=astextplain |
|||
#*.docx diff=astextplain |
|||
#*.DOCX diff=astextplain |
|||
#*.dot diff=astextplain |
|||
#*.DOT diff=astextplain |
|||
#*.pdf diff=astextplain |
|||
#*.PDF diff=astextplain |
|||
#*.rtf diff=astextplain |
|||
#*.RTF diff=astextplain |
@ -0,0 +1,13 @@ |
|||
### 该问题是怎么引起的? |
|||
|
|||
|
|||
|
|||
### 重现步骤 |
|||
|
|||
|
|||
|
|||
### 报错信息 |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,15 @@ |
|||
### 相关的Issue |
|||
|
|||
|
|||
### 原因(目的、解决的问题等) |
|||
|
|||
|
|||
### 描述(做了什么,变更了什么) |
|||
|
|||
|
|||
### 测试用例 |
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,341 @@ |
|||
## Ignore Visual Studio temporary files, build results, and |
|||
## files generated by popular Visual Studio add-ons. |
|||
## |
|||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore |
|||
|
|||
# User-specific files |
|||
*.rsuser |
|||
*.suo |
|||
*.user |
|||
*.userosscache |
|||
*.sln.docstates |
|||
|
|||
# User-specific files (MonoDevelop/Xamarin Studio) |
|||
*.userprefs |
|||
|
|||
# Build results |
|||
[Dd]ebug/ |
|||
[Dd]ebugPublic/ |
|||
[Rr]elease/ |
|||
[Rr]eleases/ |
|||
x64/ |
|||
x86/ |
|||
[Aa][Rr][Mm]/ |
|||
[Aa][Rr][Mm]64/ |
|||
bld/ |
|||
[Bb]in/ |
|||
[Oo]bj/ |
|||
[Ll]og/ |
|||
|
|||
# Visual Studio 2015/2017 cache/options directory |
|||
.vs/ |
|||
# Uncomment if you have tasks that create the project's static files in wwwroot |
|||
#wwwroot/ |
|||
|
|||
# Visual Studio 2017 auto generated files |
|||
Generated\ Files/ |
|||
|
|||
# MSTest test Results |
|||
[Tt]est[Rr]esult*/ |
|||
[Bb]uild[Ll]og.* |
|||
|
|||
# NUNIT |
|||
*.VisualState.xml |
|||
TestResult.xml |
|||
|
|||
# Build Results of an ATL Project |
|||
[Dd]ebugPS/ |
|||
[Rr]eleasePS/ |
|||
dlldata.c |
|||
|
|||
# Benchmark Results |
|||
BenchmarkDotNet.Artifacts/ |
|||
|
|||
# .NET Core |
|||
project.lock.json |
|||
project.fragment.lock.json |
|||
artifacts/ |
|||
|
|||
# StyleCop |
|||
StyleCopReport.xml |
|||
|
|||
# Files built by Visual Studio |
|||
*_i.c |
|||
*_p.c |
|||
*_h.h |
|||
*.ilk |
|||
*.meta |
|||
*.obj |
|||
*.iobj |
|||
*.pch |
|||
*.pdb |
|||
*.ipdb |
|||
*.pgc |
|||
*.pgd |
|||
*.rsp |
|||
*.sbr |
|||
*.tlb |
|||
*.tli |
|||
*.tlh |
|||
*.tmp |
|||
*.tmp_proj |
|||
*_wpftmp.csproj |
|||
*.log |
|||
*.vspscc |
|||
*.vssscc |
|||
.builds |
|||
*.pidb |
|||
*.svclog |
|||
*.scc |
|||
|
|||
# Chutzpah Test files |
|||
_Chutzpah* |
|||
|
|||
# Visual C++ cache files |
|||
ipch/ |
|||
*.aps |
|||
*.ncb |
|||
*.opendb |
|||
*.opensdf |
|||
*.sdf |
|||
*.cachefile |
|||
*.VC.db |
|||
*.VC.VC.opendb |
|||
|
|||
# Visual Studio profiler |
|||
*.psess |
|||
*.vsp |
|||
*.vspx |
|||
*.sap |
|||
|
|||
# Visual Studio Trace Files |
|||
*.e2e |
|||
|
|||
# TFS 2012 Local Workspace |
|||
$tf/ |
|||
|
|||
# Guidance Automation Toolkit |
|||
*.gpState |
|||
|
|||
# ReSharper is a .NET coding add-in |
|||
_ReSharper*/ |
|||
*.[Rr]e[Ss]harper |
|||
*.DotSettings.user |
|||
|
|||
# JustCode is a .NET coding add-in |
|||
.JustCode |
|||
|
|||
# TeamCity is a build add-in |
|||
_TeamCity* |
|||
|
|||
# DotCover is a Code Coverage Tool |
|||
*.dotCover |
|||
|
|||
# AxoCover is a Code Coverage Tool |
|||
.axoCover/* |
|||
!.axoCover/settings.json |
|||
|
|||
# Visual Studio code coverage results |
|||
*.coverage |
|||
*.coveragexml |
|||
|
|||
# NCrunch |
|||
_NCrunch_* |
|||
.*crunch*.local.xml |
|||
nCrunchTemp_* |
|||
|
|||
# MightyMoose |
|||
*.mm.* |
|||
AutoTest.Net/ |
|||
|
|||
# Web workbench (sass) |
|||
.sass-cache/ |
|||
|
|||
# Installshield output folder |
|||
[Ee]xpress/ |
|||
|
|||
# DocProject is a documentation generator add-in |
|||
DocProject/buildhelp/ |
|||
DocProject/Help/*.HxT |
|||
DocProject/Help/*.HxC |
|||
DocProject/Help/*.hhc |
|||
DocProject/Help/*.hhk |
|||
DocProject/Help/*.hhp |
|||
DocProject/Help/Html2 |
|||
DocProject/Help/html |
|||
|
|||
# Click-Once directory |
|||
publish/ |
|||
|
|||
# Publish Web Output |
|||
*.[Pp]ublish.xml |
|||
*.azurePubxml |
|||
# Note: Comment the next line if you want to checkin your web deploy settings, |
|||
# but database connection strings (with potential passwords) will be unencrypted |
|||
*.pubxml |
|||
*.publishproj |
|||
|
|||
# Microsoft Azure Web App publish settings. Comment the next line if you want to |
|||
# checkin your Azure Web App publish settings, but sensitive information contained |
|||
# in these scripts will be unencrypted |
|||
PublishScripts/ |
|||
|
|||
# NuGet Packages |
|||
*.nupkg |
|||
# The packages folder can be ignored because of Package Restore |
|||
**/[Pp]ackages/* |
|||
# except build/, which is used as an MSBuild target. |
|||
!**/[Pp]ackages/build/ |
|||
# Uncomment if necessary however generally it will be regenerated when needed |
|||
#!**/[Pp]ackages/repositories.config |
|||
# NuGet v3's project.json files produces more ignorable files |
|||
*.nuget.props |
|||
*.nuget.targets |
|||
|
|||
# Microsoft Azure Build Output |
|||
csx/ |
|||
*.build.csdef |
|||
|
|||
# Microsoft Azure Emulator |
|||
ecf/ |
|||
rcf/ |
|||
|
|||
# Windows Store app package directories and files |
|||
AppPackages/ |
|||
BundleArtifacts/ |
|||
Package.StoreAssociation.xml |
|||
_pkginfo.txt |
|||
*.appx |
|||
|
|||
# Visual Studio cache files |
|||
# files ending in .cache can be ignored |
|||
*.[Cc]ache |
|||
# but keep track of directories ending in .cache |
|||
!?*.[Cc]ache/ |
|||
|
|||
# Others |
|||
ClientBin/ |
|||
~$* |
|||
*~ |
|||
*.dbmdl |
|||
*.dbproj.schemaview |
|||
*.jfm |
|||
*.pfx |
|||
*.publishsettings |
|||
orleans.codegen.cs |
|||
|
|||
# Including strong name files can present a security risk |
|||
# (https://github.com/github/gitignore/pull/2483#issue-259490424) |
|||
#*.snk |
|||
|
|||
# Since there are multiple workflows, uncomment next line to ignore bower_components |
|||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) |
|||
#bower_components/ |
|||
# ASP.NET Core default setup: bower directory is configured as wwwroot/lib/ and bower restore is true |
|||
**/wwwroot/lib/ |
|||
|
|||
# RIA/Silverlight projects |
|||
Generated_Code/ |
|||
|
|||
# Backup & report files from converting an old project file |
|||
# to a newer Visual Studio version. Backup files are not needed, |
|||
# because we have git ;-) |
|||
_UpgradeReport_Files/ |
|||
Backup*/ |
|||
UpgradeLog*.XML |
|||
UpgradeLog*.htm |
|||
ServiceFabricBackup/ |
|||
*.rptproj.bak |
|||
|
|||
# SQL Server files |
|||
*.mdf |
|||
*.ldf |
|||
*.ndf |
|||
|
|||
# Business Intelligence projects |
|||
*.rdl.data |
|||
*.bim.layout |
|||
*.bim_*.settings |
|||
*.rptproj.rsuser |
|||
|
|||
# Microsoft Fakes |
|||
FakesAssemblies/ |
|||
|
|||
# GhostDoc plugin setting file |
|||
*.GhostDoc.xml |
|||
|
|||
# Node.js Tools for Visual Studio |
|||
.ntvs_analysis.dat |
|||
node_modules/ |
|||
|
|||
# Visual Studio 6 build log |
|||
*.plg |
|||
|
|||
# Visual Studio 6 workspace options file |
|||
*.opt |
|||
|
|||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) |
|||
*.vbw |
|||
|
|||
# Visual Studio LightSwitch build output |
|||
**/*.HTMLClient/GeneratedArtifacts |
|||
**/*.DesktopClient/GeneratedArtifacts |
|||
**/*.DesktopClient/ModelManifest.xml |
|||
**/*.Server/GeneratedArtifacts |
|||
**/*.Server/ModelManifest.xml |
|||
_Pvt_Extensions |
|||
|
|||
# Paket dependency manager |
|||
.paket/paket.exe |
|||
paket-files/ |
|||
|
|||
# FAKE - F# Make |
|||
.fake/ |
|||
|
|||
# JetBrains Rider |
|||
.idea/ |
|||
*.sln.iml |
|||
|
|||
# CodeRush personal settings |
|||
.cr/personal |
|||
|
|||
# Python Tools for Visual Studio (PTVS) |
|||
__pycache__/ |
|||
*.pyc |
|||
|
|||
# Cake - Uncomment if you are using it |
|||
# tools/** |
|||
# !tools/packages.config |
|||
|
|||
# Tabs Studio |
|||
*.tss |
|||
|
|||
# Telerik's JustMock configuration file |
|||
*.jmconfig |
|||
|
|||
# BizTalk build output |
|||
*.btp.cs |
|||
*.btm.cs |
|||
*.odx.cs |
|||
*.xsd.cs |
|||
|
|||
# OpenCover UI analysis results |
|||
OpenCover/ |
|||
|
|||
# Azure Stream Analytics local run output |
|||
ASALocalRun/ |
|||
|
|||
# MSBuild Binary and Structured Log |
|||
*.binlog |
|||
|
|||
# NVidia Nsight GPU debugger configuration file |
|||
*.nvuser |
|||
|
|||
# MFractors (Xamarin productivity tool) working folder |
|||
.mfractor/ |
|||
|
|||
# Local History for Visual Studio |
|||
.localhistory/ |
|||
|
|||
# BeatPulse healthcheck temp database |
|||
healthchecksdb |
@ -0,0 +1,160 @@ |
|||
using System; |
|||
using GPSBusiness.Enum; |
|||
using GPSBusiness.Helper; |
|||
using GPSBusiness.GPSStandard; |
|||
using Newtonsoft.Json; |
|||
|
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
public static class BbGpsStandardService |
|||
{ |
|||
/// <summary>
|
|||
/// 获取返回给设备的数据
|
|||
/// </summary>
|
|||
/// <param name="bytes"></param>
|
|||
/// <param name="standardToCarGpsHandler"></param>
|
|||
/// <param name="conid"></param>
|
|||
/// <param name="mdtText"></param>
|
|||
/// <returns></returns>
|
|||
public static GPSResponseData GetGpsResponseDataForEqu(byte[] bytes, |
|||
IStandardToCarGPSHandler standardToCarGpsHandler, IntPtr conid, string mdtText) |
|||
{ |
|||
byte[] byteDataId = new byte[2]; |
|||
//反转义
|
|||
byte[] buffer = ByteConvert.Fzy(bytes); |
|||
Array.Copy(buffer, 1, byteDataId, 0, 2); |
|||
Array.Reverse(byteDataId); |
|||
UInt16 uint16DataId = BitConverter.ToUInt16(byteDataId, 0); |
|||
string dataId = uint16DataId.ToString("X2").PadLeft(4, '0'); |
|||
string terminalNo = ByteConvert.ByteArrayToHexStr(buffer).Substring(11, 11);//设备号
|
|||
|
|||
"NO".Log().Debug(ByteConvert.ByteArrayToHexStr(buffer).ToString()); |
|||
DataHead dataHead = new DataHead(); |
|||
dataHead.Frombytes(dataHead, buffer); |
|||
"GetGpsResponseDataForEqu".Log().DebugFormat(" >terminalNo={0},uint16DataId=0x{1}", terminalNo, dataId); |
|||
//"GetGpsResponseDataForEqu".Log().DebugFormat(" >dataHead={0}", JsonConvert.SerializeObject(dataHead));
|
|||
//接收信息(分类)
|
|||
#region 0x0002,终端心跳
|
|||
if (uint16DataId == 0x0002) |
|||
{ |
|||
//平台通用应答
|
|||
var responds = CommonResponse(dataHead); |
|||
//确定该心跳是否为沃瑞特的gps,是则后续进行:gps在线状态更新。MyGpsServer.UpdateGpsRealTimeGpsStateWrt(gpsModel);
|
|||
//var vehicle = standardToCarGpsHandler.GetGps(bytes, terminalNo, conid, true);
|
|||
//if (vehicle != null && vehicle.TerminalType == TerminalTypeEnum.C12.ToEnumInt())
|
|||
//{
|
|||
// responds.GpsInfo = vehicle;
|
|||
//}
|
|||
|
|||
return responds; |
|||
} |
|||
#endregion
|
|||
#region 0x0100,终端注册 0x0100
|
|||
if (uint16DataId == 0x0100) |
|||
{ |
|||
//注册消息
|
|||
var model = new Data_0100(); |
|||
model.FromBytes(model, dataHead.DataContent); |
|||
//应答消息
|
|||
var model2 = new Data_8100 |
|||
{ |
|||
Mdt_SerialNo = dataHead.DataSerialNo, |
|||
Result = 0x00, |
|||
AuthorizationCode = "regist123" |
|||
}; |
|||
//0:成功;1:车辆已被注册;2:数据库中无该车辆;3:终端已被注册;4:数据库中无该终端
|
|||
var dataHeadModel = new DataHead |
|||
{ |
|||
DataID = 0x8100, |
|||
CenterID = dataHead.CenterID, |
|||
MdtID = dataHead.MdtID |
|||
}; |
|||
return new GPSResponseData() |
|||
{ |
|||
ReturnData = model2.GetBytes(dataHeadModel), |
|||
}; |
|||
} |
|||
#endregion
|
|||
#region 0x0102,终端鉴权,鉴权7-8次不成功,终端为再次注册
|
|||
if (uint16DataId == 0x0102) |
|||
{ |
|||
return CommonResponse(dataHead); |
|||
} |
|||
#endregion
|
|||
#region 0x0200,位置数据0x0200
|
|||
if (uint16DataId == 0x0200) |
|||
{ |
|||
var responds = CommonResponse(dataHead); |
|||
responds.GpsInfo = standardToCarGpsHandler.GetGps(bytes, terminalNo, conid, false); |
|||
"GetGpsResponseDataForEqu".Log().DebugFormat(" >GpsInfo={0}", JsonConvert.SerializeObject(responds.GpsInfo)); |
|||
return responds; |
|||
} |
|||
#endregion
|
|||
#region 0x0704,定位数据批量上传--0x0704,(沃瑞特:盲区补传)
|
|||
if (uint16DataId == 0x0704) |
|||
{ |
|||
//处理gps批量数据。然后通用回复。
|
|||
return CommonResponse(dataHead) ; |
|||
} |
|||
#endregion
|
|||
#region 0xA003,请求服务器时间0xA003,回应:0xB003。//沃瑞特gps
|
|||
if (uint16DataId == 0xA003) |
|||
{ |
|||
var now = DateTime.Now; |
|||
int year = Convert.ToInt32(now.Year.ToString().Substring(2, 2)); |
|||
byte rYear = ByteConvert.IntToBcd(year); |
|||
byte rMonth = ByteConvert.IntToBcd(now.Month); |
|||
byte rDay = ByteConvert.IntToBcd(now.Day); |
|||
byte rHour = ByteConvert.IntToBcd(now.Hour); |
|||
byte rMinute = ByteConvert.IntToBcd(now.Minute); |
|||
byte rSecond = ByteConvert.IntToBcd(now.Second); |
|||
byte[] times = { rYear, rMonth, rDay, rHour, rMinute, rSecond }; |
|||
|
|||
var model = new Data_B003 |
|||
{ |
|||
Mdt_SerialNo = dataHead.DataSerialNo, |
|||
SysTime = times |
|||
}; |
|||
var dataHeadModel = new DataHead |
|||
{ |
|||
DataID = 0xB003, |
|||
CenterID = dataHead.CenterID, |
|||
MdtID = dataHead.MdtID, |
|||
}; |
|||
return new GPSResponseData() |
|||
{ |
|||
ReturnData = model.GetBytes(dataHeadModel), |
|||
}; |
|||
} |
|||
#endregion
|
|||
//0x8001,平台通用应答
|
|||
return CommonResponse(dataHead); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 通用回复
|
|||
/// </summary>
|
|||
/// <param name="dataHead"></param>
|
|||
/// <returns></returns>
|
|||
private static GPSResponseData CommonResponse(DataHead dataHead) |
|||
{ |
|||
var model2 = new Data_8001 |
|||
{ |
|||
Mdt_SerialNo = dataHead.DataSerialNo, |
|||
Mdt_DataID = dataHead.DataID, |
|||
Result = 0x00 |
|||
}; |
|||
var dataHeadModel = new DataHead |
|||
{ |
|||
DataID = 0x8001, |
|||
CenterID = dataHead.CenterID, |
|||
MdtID = dataHead.MdtID |
|||
}; |
|||
var responds = new GPSResponseData() |
|||
{ |
|||
ReturnData = model2.GetBytes(dataHeadModel) |
|||
}; |
|||
return responds; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,77 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
public class DataHead |
|||
{ |
|||
public static int intSerialNo = 0; |
|||
/// <summary>
|
|||
/// 获取流水号
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public int GetSerialNo() |
|||
{ |
|||
if (intSerialNo >= 255) |
|||
{ |
|||
intSerialNo = 0; |
|||
} |
|||
intSerialNo++; |
|||
return intSerialNo; |
|||
} |
|||
/// <summary>
|
|||
/// 消息ID
|
|||
/// </summary>
|
|||
public UInt16 DataID; |
|||
/// <summary>
|
|||
/// 消息体属性
|
|||
/// </summary>
|
|||
public UInt16 DataAttribute; |
|||
/// <summary>
|
|||
/// 终端手机号=centerid+mdtid
|
|||
/// </summary>
|
|||
public UInt16 CenterID; |
|||
public byte[] MdtID; |
|||
/// <summary>
|
|||
/// 消息流水号
|
|||
/// </summary>
|
|||
public UInt16 DataSerialNo; |
|||
/// <summary>
|
|||
/// 消息体
|
|||
/// </summary>
|
|||
public byte[] DataContent; |
|||
public byte[] GetBytes() |
|||
{ |
|||
this.DataAttribute = (UInt16)this.DataContent.Length; |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(ByteConvert.ToBytes(this.DataID)); |
|||
bb.Append(ByteConvert.ToBytes(this.DataAttribute)); |
|||
bb.Append(ByteConvert.ToBytes(this.CenterID)); |
|||
bb.Append(this.MdtID); |
|||
bb.Append(ByteConvert.ToBytes(this.DataSerialNo)); |
|||
if (this.DataContent.Length > 0) |
|||
{ |
|||
bb.Append(this.DataContent); |
|||
} |
|||
byte Crc = ByteConvert.GetCRC(bb.GetBytes(), 0, bb.GetBytes().Length); |
|||
ByteBuilder bb2 = new ByteBuilder(); |
|||
bb2.Append(0x7e); |
|||
bb2.Append(bb.GetBytes()); |
|||
bb2.Append(Crc); |
|||
bb2.Append(0x7e); |
|||
return bb2.GetBytes(); |
|||
} |
|||
public void Frombytes(DataHead model, byte[] buffer) |
|||
{ |
|||
model.DataID = ByteConvert.ToUInt16(buffer, 1); |
|||
model.DataAttribute = ByteConvert.ToUInt16(buffer, 3);//buffer.Length - 15
|
|||
model.CenterID = ByteConvert.ToUInt16(buffer, 5); |
|||
model.MdtID = ByteConvert.ToBytes(buffer, 7, 4); |
|||
model.DataSerialNo = ByteConvert.ToUInt16(buffer, 11); |
|||
if (buffer.Length > 15) |
|||
{ |
|||
//消息体属性 暂定为消息体长度
|
|||
model.DataContent = ByteConvert.ToBytes(buffer, 13, this.DataAttribute); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 终端通用应答
|
|||
/// </summary>
|
|||
public class Data_0001 |
|||
{ |
|||
/// <summary>
|
|||
/// 应答流水号--对应的平台消息的流水号
|
|||
/// </summary>
|
|||
public UInt16 PT_SerialNo; |
|||
/// <summary>
|
|||
/// 应答ID--对应的平台消息的ID
|
|||
/// </summary>
|
|||
public UInt16 PT_DataID; |
|||
/// <summary>
|
|||
/// 结果--0:成功/确认;1:失败;2:消息有误;3:不支持
|
|||
/// </summary>
|
|||
public byte Result; |
|||
public void FromBytes(Data_0001 model, byte[] buffer) |
|||
{ |
|||
model.PT_SerialNo = ByteConvert.ToUInt16(buffer, 0); |
|||
model.PT_DataID = ByteConvert.ToUInt16(buffer, 2); |
|||
model.Result = buffer[4]; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,49 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 终端注册
|
|||
/// </summary>
|
|||
public class Data_0100 |
|||
{ |
|||
/// <summary>
|
|||
/// 省域ID
|
|||
/// </summary>
|
|||
public UInt16 ProvinceID; |
|||
/// <summary>
|
|||
/// 市县域ID
|
|||
/// </summary>
|
|||
public UInt16 CityID; |
|||
/// <summary>
|
|||
/// 制造商ID
|
|||
/// </summary>
|
|||
public byte[] Factory; |
|||
/// <summary>
|
|||
/// 终端型号
|
|||
/// </summary>
|
|||
public byte[] MdtType; |
|||
/// <summary>
|
|||
/// 终端ID
|
|||
/// </summary>
|
|||
public byte[] MdtID; |
|||
/// <summary>
|
|||
/// 车牌颜色
|
|||
/// </summary>
|
|||
public byte NumberColor; |
|||
/// <summary>
|
|||
/// 车牌
|
|||
/// </summary>
|
|||
public string Number; |
|||
public void FromBytes(Data_0100 model, byte[] buffer) |
|||
{ |
|||
model.ProvinceID = ByteConvert.ToUInt16(buffer, 0); |
|||
model.CityID = ByteConvert.ToUInt16(buffer, 2); |
|||
model.Factory = ByteConvert.ToBytes(buffer, 4, 5); |
|||
model.MdtType = ByteConvert.ToBytes(buffer, 9, 8); |
|||
model.MdtID = ByteConvert.ToBytes(buffer, 17, 7); |
|||
model.NumberColor = buffer[24]; |
|||
model.Number = ByteConvert.ToString(buffer, 25, buffer.Length - 25); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// Öն˼øÈ¨
|
|||
/// </summary>
|
|||
public class Data_0102 |
|||
{ |
|||
/// <summary>
|
|||
/// ¼øÈ¨Âë
|
|||
/// </summary>
|
|||
public string AuthorizationCode; |
|||
public void FromBytes(Data_0102 model, byte[] buffer) |
|||
{ |
|||
int length = buffer.Length; |
|||
if (length > 0) |
|||
model.AuthorizationCode = ByteConvert.ToString(buffer, 0, length); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 查询终端参数应答
|
|||
/// </summary>
|
|||
public class Data_0104 |
|||
{ |
|||
/// <summary>
|
|||
/// 应答流水号
|
|||
/// </summary>
|
|||
public UInt16 PT_SerialNo; |
|||
/// <summary>
|
|||
/// 应答参数个数
|
|||
/// </summary>
|
|||
public byte ReturnSum; |
|||
/// <summary>
|
|||
/// 应答的值
|
|||
/// </summary>
|
|||
public byte[] RetrunValue; |
|||
public void FromBytes(Data_0104 model, byte[] buffer) |
|||
{ |
|||
model.PT_SerialNo = ByteConvert.ToUInt16(buffer, 0); |
|||
model.ReturnSum = buffer[2]; |
|||
model.RetrunValue = ByteConvert.ToBytes(buffer, 3, buffer.Length - 3); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 事件报告
|
|||
/// </summary>
|
|||
public class Data_0301 |
|||
{ |
|||
public byte SetID; |
|||
public void FromBytes(Data_0301 model, byte[] buffer) |
|||
{ |
|||
model.SetID = buffer[0]; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// ÌáÎÊÓ¦´ð
|
|||
/// </summary>
|
|||
public class Data_0302 |
|||
{ |
|||
public UInt16 PT_SerialNo; |
|||
public byte Answer; |
|||
public void FromBytes(Data_0302 model, byte[] buffer) |
|||
{ |
|||
model.PT_SerialNo = ByteConvert.ToUInt16(buffer, 0); |
|||
model.Answer = buffer[2]; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,16 @@ |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 信息点播/取消
|
|||
/// </summary>
|
|||
public class Data_0303 |
|||
{ |
|||
public byte DataType; |
|||
public byte SetSign; |
|||
public void FromBytes(Data_0303 model, byte[] buffer) |
|||
{ |
|||
model.DataType = buffer[0]; |
|||
model.SetSign = buffer[1]; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆控制应答
|
|||
/// </summary>
|
|||
public class Data_0500 |
|||
{ |
|||
/// <summary>
|
|||
/// 应答流水号
|
|||
/// </summary>
|
|||
public UInt16 PT_SerialNo; |
|||
/// <summary>
|
|||
/// 位置信息汇报消息体
|
|||
/// </summary>
|
|||
public byte[] GPS_Data; |
|||
public void FromBytes(Data_0500 model, byte[] buffer) |
|||
{ |
|||
model.PT_SerialNo = ByteConvert.ToUInt16(buffer, 0); |
|||
model.GPS_Data = ByteConvert.ToBytes(buffer, 1, buffer.Length - 1); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 平台通用应答
|
|||
/// </summary>
|
|||
public class Data_8001 |
|||
{ |
|||
/// <summary>
|
|||
/// 应答流水号--对应的终端消息的流水号
|
|||
/// </summary>
|
|||
public UInt16 Mdt_SerialNo; |
|||
/// <summary>
|
|||
/// 应答ID--对应的终端消息的ID
|
|||
/// </summary>
|
|||
public UInt16 Mdt_DataID; |
|||
/// <summary>
|
|||
/// 结果--0:成功/确认;1:失败;2:消息有误;3:不支持;4:报警处理确认
|
|||
/// </summary>
|
|||
public byte Result; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(ByteConvert.ToBytes(this.Mdt_SerialNo)); |
|||
bb.Append(ByteConvert.ToBytes(this.Mdt_DataID)); |
|||
bb.Append(this.Result); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 终端注册应答
|
|||
/// </summary>
|
|||
public class Data_8100 |
|||
{ |
|||
/// <summary>
|
|||
/// 应答流水号--对应的终端注册消息的流水号
|
|||
/// </summary>
|
|||
public UInt16 Mdt_SerialNo; |
|||
/// <summary>
|
|||
/// 结果--0:成功;1:车辆已被注册;2:数据库中无该车辆;3:终端已被注册;4:数据库中无该终端
|
|||
/// </summary>
|
|||
public byte Result; |
|||
/// <summary>
|
|||
/// 鉴权码--只有在成功后才有该字段
|
|||
/// </summary>
|
|||
public string AuthorizationCode; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(ByteConvert.ToBytes(this.Mdt_SerialNo)); |
|||
bb.Append(this.Result); |
|||
if (this.Result == 0x00) |
|||
{ |
|||
bb.Append(ByteConvert.ToBytes(this.AuthorizationCode)); |
|||
} |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 设置终端参数
|
|||
/// </summary>
|
|||
public class Data_8103 |
|||
{ |
|||
/// <summary>
|
|||
/// 参数总数
|
|||
/// </summary>
|
|||
public byte ParameterSum; |
|||
/// <summary>
|
|||
/// 参数ID
|
|||
/// </summary>
|
|||
public UInt16 ParameterID; |
|||
/// <summary>
|
|||
/// 参数长度
|
|||
/// </summary>
|
|||
public byte ParameterLength; |
|||
/// <summary>
|
|||
/// 参数值
|
|||
/// </summary>
|
|||
public UInt16 ParameterValue; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.ParameterSum); |
|||
bb.Append(ByteConvert.ToBytes(this.ParameterID)); |
|||
bb.Append(ByteConvert.ToBytes(this.ParameterLength)); |
|||
bb.Append(ByteConvert.ToBytes(this.ParameterValue)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// ÖÕ¶Ë¿ØÖÆ
|
|||
/// </summary>
|
|||
public class Data_8105 |
|||
{ |
|||
public byte Command; |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 位置信息查询
|
|||
/// </summary>
|
|||
public class Data_8201 |
|||
{ |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 临时位置跟踪控制
|
|||
/// </summary>
|
|||
public class Data_8202 |
|||
{ |
|||
/// <summary>
|
|||
/// 时间间隔
|
|||
/// </summary>
|
|||
public UInt16 TimeIntermission; |
|||
/// <summary>
|
|||
/// 位置跟踪有效期
|
|||
/// </summary>
|
|||
public UInt32 TimeValid; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(ByteConvert.ToBytes(this.TimeIntermission)); |
|||
bb.Append(ByteConvert.ToBytes(this.TimeValid)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 文本信息下发
|
|||
/// </summary>
|
|||
public class Data_8300 |
|||
{ |
|||
/// <summary>
|
|||
/// 标志
|
|||
/// </summary>
|
|||
public byte TextSign; |
|||
/// <summary>
|
|||
/// 文本信息
|
|||
/// </summary>
|
|||
public string TextInformation; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.TextSign); |
|||
bb.Append(ByteConvert.ToBytes(this.TextInformation)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,42 @@ |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 事件设置
|
|||
/// </summary>
|
|||
public class Data_8301 |
|||
{ |
|||
/// <summary>
|
|||
/// 设置类型
|
|||
/// </summary>
|
|||
public byte SetType; |
|||
/// <summary>
|
|||
/// 设置总数
|
|||
/// </summary>
|
|||
public byte SetSum; |
|||
/// <summary>
|
|||
/// 事件ID
|
|||
/// </summary>
|
|||
public byte SetID; |
|||
/// <summary>
|
|||
/// 事件内容长度
|
|||
/// </summary>
|
|||
public byte Setength; |
|||
/// <summary>
|
|||
/// 事件内容
|
|||
/// </summary>
|
|||
public string SetContent; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.SetType); |
|||
bb.Append(this.SetSum); |
|||
bb.Append(this.SetID); |
|||
bb.Append(this.Setength); |
|||
bb.Append(ByteConvert.ToBytes(this.SetContent)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 提问下发
|
|||
/// </summary>
|
|||
public class Data_8302 |
|||
{ |
|||
/// <summary>
|
|||
/// 标志
|
|||
/// </summary>
|
|||
public byte QuestionSign; |
|||
/// <summary>
|
|||
/// 问题内容长度
|
|||
/// </summary>
|
|||
public byte QuestionLength; |
|||
/// <summary>
|
|||
/// 问题
|
|||
/// </summary>
|
|||
public string QuestionContent; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.QuestionSign); |
|||
bb.Append(this.QuestionLength); |
|||
bb.Append(ByteConvert.ToBytes(this.QuestionContent)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 信息点播菜单设置
|
|||
/// </summary>
|
|||
public class Data_8303 |
|||
{ |
|||
/// <summary>
|
|||
/// 设置类型
|
|||
/// </summary>
|
|||
public byte SetType; |
|||
/// <summary>
|
|||
/// 信息项总数
|
|||
/// </summary>
|
|||
public byte DataSum; |
|||
/// <summary>
|
|||
/// 包消息数
|
|||
/// </summary>
|
|||
public byte PacketSum; |
|||
/// <summary>
|
|||
/// 信息类型
|
|||
/// </summary>
|
|||
public byte DataType; |
|||
/// <summary>
|
|||
/// 信息名称长度
|
|||
/// </summary>
|
|||
public UInt16 DataNameLength; |
|||
/// <summary>
|
|||
/// 信息名称
|
|||
/// </summary>
|
|||
public string DataName; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.SetType); |
|||
bb.Append(this.DataSum); |
|||
bb.Append(this.PacketSum); |
|||
bb.Append(this.DataType); |
|||
bb.Append(ByteConvert.ToBytes(this.DataNameLength)); |
|||
bb.Append(ByteConvert.ToBytes(this.DataName)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 信息服务
|
|||
/// </summary>
|
|||
public class Data_8304 |
|||
{ |
|||
/// <summary>
|
|||
/// 信息类型
|
|||
/// </summary>
|
|||
public byte DataType; |
|||
/// <summary>
|
|||
/// 信息长度
|
|||
/// </summary>
|
|||
public UInt16 DataLength; |
|||
/// <summary>
|
|||
/// 信息内容
|
|||
/// </summary>
|
|||
public string DataContent; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.DataType); |
|||
bb.Append(ByteConvert.ToBytes(this.DataLength)); |
|||
bb.Append(ByteConvert.ToBytes(this.DataContent)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// µç»°»Ø²¦
|
|||
/// </summary>
|
|||
public class Data_8400 |
|||
{ |
|||
/// <summary>
|
|||
/// ±êÖ¾
|
|||
/// </summary>
|
|||
public byte PhoneSign; |
|||
/// <summary>
|
|||
/// µç»°ºÅÂë
|
|||
/// </summary>
|
|||
public string PhoneNumber; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.PhoneSign); |
|||
bb.Append(ByteConvert.ToBytes(this.PhoneNumber)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 设置电话本
|
|||
/// </summary>
|
|||
public class Data_8401 |
|||
{ |
|||
/// <summary>
|
|||
/// 设置类型
|
|||
/// </summary>
|
|||
public byte SetType; |
|||
/// <summary>
|
|||
/// 联系人总数
|
|||
/// </summary>
|
|||
public byte ContactPeopleSum; |
|||
/// <summary>
|
|||
/// 标志
|
|||
/// </summary>
|
|||
public byte Sign; |
|||
/// <summary>
|
|||
/// 号码长度
|
|||
/// </summary>
|
|||
public byte PhoneLength; |
|||
/// <summary>
|
|||
/// 电话号码
|
|||
/// </summary>
|
|||
public string PhoneNumber; |
|||
/// <summary>
|
|||
/// 联系人长度
|
|||
/// </summary>
|
|||
public byte ContactPeopleLength; |
|||
/// <summary>
|
|||
/// 联系人
|
|||
/// </summary>
|
|||
public string ContactPeople; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.SetType); |
|||
bb.Append(this.ContactPeopleSum); |
|||
bb.Append(this.Sign); |
|||
bb.Append(this.PhoneLength); |
|||
bb.Append(ByteConvert.ToBytes(this.PhoneNumber)); |
|||
bb.Append(this.ContactPeopleLength); |
|||
bb.Append(ByteConvert.ToBytes(this.ContactPeople)); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,22 @@ |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// ³µÁ¾¿ØÖÆ
|
|||
/// </summary>
|
|||
public class Data_8500 |
|||
{ |
|||
/// <summary>
|
|||
/// ¿ØÖƱêÖ¾
|
|||
/// </summary>
|
|||
public byte ControlSign; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(this.ControlSign); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 客户的平台下发LED显示的内容通过透传指令0x8900下发
|
|||
/// </summary>
|
|||
public class Data_8900 |
|||
{ |
|||
/// <summary>
|
|||
/// 要显示的消息内容
|
|||
/// </summary>
|
|||
public byte[] data; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(ByteConvert.HexStringToByte("7E")); |
|||
bb.Append(data); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using GPSBusiness.Helper; |
|||
namespace GPSBusiness.BBGPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 沃瑞特gps:请求服务器时间应答
|
|||
/// </summary>
|
|||
public class Data_B003 |
|||
{ |
|||
/// <summary>
|
|||
/// 应答流水号--对应的终端注册消息的流水号
|
|||
/// </summary>
|
|||
public UInt16 Mdt_SerialNo; |
|||
/// <summary>
|
|||
/// 系统时间
|
|||
/// </summary>
|
|||
public byte[] SysTime; |
|||
public byte[] GetBytes(DataHead model) |
|||
{ |
|||
ByteBuilder bb = new ByteBuilder(); |
|||
bb.Append(ByteConvert.ToBytes(this.Mdt_SerialNo)); |
|||
bb.Append(this.SysTime); |
|||
model.DataContent = bb.GetBytes(); |
|||
byte[] bModel = ByteConvert.Zy(model.GetBytes()); |
|||
return bModel; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,158 @@ |
|||
using log4net; |
|||
using Newtonsoft.Json; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Configuration; |
|||
using System.Text; |
|||
using GpsModels; |
|||
|
|||
namespace GPSBusiness.BaiDu |
|||
{ |
|||
public class BaiduGpsServercs |
|||
{ |
|||
public static ILog log = LogManager.GetLogger(""); |
|||
private static string BaiduApiUrl = ConfigurationSettings.AppSettings["BaiduApiUrl"]; |
|||
private static string BaiduAk = ConfigurationSettings.AppSettings["BaiduAk"]; |
|||
/// <summary>
|
|||
/// 批量转换百度坐标(单次最大100)
|
|||
/// </summary>
|
|||
public static List<GpsModel> Changes100(List<GpsModel> list) |
|||
{ |
|||
try |
|||
{ |
|||
var reList = new List<GpsModel>(); |
|||
string url = BaiduApiUrl + "/geoconv/v1/?coords="; |
|||
foreach (var item in list) |
|||
{ |
|||
url += item.Longitude + "," + item.Latitude + ";"; |
|||
} |
|||
url = url.Remove(url.Length - 1) + "&from=1&to=5&ak=" + BaiduAk; |
|||
System.Net.WebRequest wReq = System.Net.WebRequest.Create(url); |
|||
System.Net.WebResponse wResp = wReq.GetResponse(); |
|||
System.IO.Stream respStream = wResp.GetResponseStream(); |
|||
using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.UTF8)) |
|||
{ |
|||
string value = reader.ReadToEnd(); |
|||
if (!string.IsNullOrEmpty(value)) |
|||
{ |
|||
BaiduApiResult result = JsonConvert.DeserializeObject<BaiduApiResult>(value); |
|||
if (result.status == 0) |
|||
{ |
|||
List<coordinate> xy = JsonConvert.DeserializeObject<List<coordinate>>(result.result.ToString()); |
|||
for (int i = 0; i < xy.Count; i++) |
|||
{ |
|||
if (xy[i] != null) |
|||
{ |
|||
list[i].Longitude = xy[i].x; |
|||
list[i].Latitude = xy[i].y; |
|||
reList.Add(list[i]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return reList; |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
log.Error("百度坐标转换 Exception:" + e.Message + e.StackTrace); |
|||
return null; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 批量坐标转地址(单次最大20)
|
|||
/// </summary>
|
|||
public static List<GpsModel> AddressChanges20(List<GpsModel> list) |
|||
{ |
|||
try |
|||
{ |
|||
var reList = new List<GpsModel>(); |
|||
string url = BaiduApiUrl + "/geocoder/v2/?callback=renderReverse&location="; |
|||
var count = 0; |
|||
var multy = 0; |
|||
foreach (var item in list) |
|||
{ |
|||
url += item.Latitude + "," + item.Longitude + "|"; |
|||
count++; |
|||
if (count % 20 == 0) |
|||
{ |
|||
url = url.Remove(url.Length - 1) + "&batch=true&pois=0&extensions_road=true&extensions_town=true&latest_admin=1&output=json&pois=1&ak=" + BaiduAk; |
|||
System.Net.WebRequest wReq = System.Net.WebRequest.Create(url); |
|||
System.Net.WebResponse wResp = wReq.GetResponse(); |
|||
System.IO.Stream respStream = wResp.GetResponseStream(); |
|||
using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.UTF8)) |
|||
{ |
|||
string value = reader.ReadToEnd(); |
|||
if (!string.IsNullOrEmpty(value)) |
|||
{ |
|||
BaiduAddressApiResult result = JsonConvert.DeserializeObject<BaiduAddressApiResult>(value); |
|||
if (result.status == 0) |
|||
{ |
|||
List<addresss> add = JsonConvert.DeserializeObject<List<addresss>>(result.areas.ToString()); |
|||
|
|||
for (int i = 0; i < add.Count; i++) |
|||
{ |
|||
if (add[i] != null) |
|||
{ |
|||
list[i + multy*20].Address = add[i].city + add[i].district + add[i].town; |
|||
reList.Add(list[i]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
url = BaiduApiUrl + "/geocoder/v2/?callback=renderReverse&location="; |
|||
} |
|||
} |
|||
return reList; |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
log.Error("百度坐标转换 Exception:" + e.Message + e.StackTrace); |
|||
return list; |
|||
} |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// ApiResult
|
|||
/// </summary>
|
|||
public class BaiduApiResult |
|||
{ |
|||
public int status { get; set; } |
|||
public string message { get; set; } |
|||
public object result { get; set; } |
|||
} |
|||
/// <summary>
|
|||
/// 坐标
|
|||
/// </summary>
|
|||
public class coordinate |
|||
{ |
|||
/// <summary>
|
|||
/// 纬度
|
|||
/// </summary>
|
|||
public decimal x { get; set; } |
|||
/// <summary>
|
|||
/// 经度
|
|||
/// </summary>
|
|||
public decimal y { get; set; } |
|||
} |
|||
/// <summary>
|
|||
/// BaiduAddressApiResult
|
|||
/// </summary>
|
|||
public class BaiduAddressApiResult |
|||
{ |
|||
public int status { get; set; } |
|||
public object areas { get; set; } |
|||
} |
|||
/// <summary>
|
|||
/// 坐标
|
|||
/// </summary>
|
|||
public class addresss |
|||
{ |
|||
public string country { get; set; } |
|||
public string province { get; set; } |
|||
public string city { get; set; } |
|||
public string district { get; set; } |
|||
public string town { get; set; } |
|||
} |
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,10 @@ |
|||
namespace GPSBusiness.Enum |
|||
{ |
|||
public static class EnumExtension |
|||
{ |
|||
public static int ToEnumInt(this TerminalTypeEnum sucEnum) |
|||
{ |
|||
return (int)sucEnum; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
using System.ComponentModel; |
|||
|
|||
namespace GPSBusiness.Enum |
|||
{ |
|||
/// <summary>
|
|||
/// 1 博实结KM02-2线
|
|||
|
|||
/// </summary>
|
|||
public enum TerminalTypeEnum |
|||
{ |
|||
/// <summary>
|
|||
/// 博实结KG_M08四线
|
|||
/// </summary>
|
|||
[Description("博实结KG_M08四线")] |
|||
BSJKGM_08 = 1, |
|||
|
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Enum |
|||
{ |
|||
/// <summary>
|
|||
/// Redis表前缀
|
|||
/// </summary>
|
|||
public class RedisPrefixEnum |
|||
{ |
|||
/// <summary>
|
|||
/// Acc前缀
|
|||
/// </summary>
|
|||
[Description("Acc前缀")] |
|||
public static string FirstAcc = "FirstAcc_"; |
|||
/// <summary>
|
|||
/// 作业状态前缀
|
|||
/// </summary>
|
|||
[Description("作业状态前缀")] |
|||
public static string FirstWork = "FirstWork_"; |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Enum |
|||
{ |
|||
/// <summary>
|
|||
/// 状态 1Acc 2作业状态
|
|||
/// </summary>
|
|||
public enum StatusEnum |
|||
{ |
|||
/// <summary>
|
|||
/// Acc状态
|
|||
/// </summary>
|
|||
[Description("Acc")] |
|||
Acc = 1, |
|||
/// <summary>
|
|||
/// 作业状态
|
|||
/// </summary>
|
|||
[Description("作业状态")] |
|||
Work = 2, |
|||
} |
|||
} |
@ -0,0 +1,227 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{5699F908-5B5C-4228-9EB7-6113B2B3992D}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>GPSBusiness</RootNamespace> |
|||
<AssemblyName>GPSBusiness</AssemblyName> |
|||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<TargetFrameworkProfile /> |
|||
<NuGetPackageImportStamp> |
|||
</NuGetPackageImportStamp> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>..\bin\x64\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<PlatformTarget>x64</PlatformTarget> |
|||
<Prefer32Bit>false</Prefer32Bit> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<Prefer32Bit>false</Prefer32Bit> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="DnsClient, Version=1.4.0.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\DnsClient.1.4.0\lib\net471\DnsClient.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="log4net"> |
|||
<HintPath>..\lib\log4net.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="MongoDB.Bson, Version=2.13.1.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\MongoDB.Bson.2.13.1\lib\net452\MongoDB.Bson.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="MongoDB.Driver, Version=2.13.1.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\MongoDB.Driver.2.13.1\lib\net452\MongoDB.Driver.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="MongoDB.Driver.Core, Version=2.13.1.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\MongoDB.Driver.Core.2.13.1\lib\net452\MongoDB.Driver.Core.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="MongoDB.Libmongocrypt, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\MongoDB.Libmongocrypt.1.2.3\lib\net472\MongoDB.Libmongocrypt.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="MySql.Data, Version=6.7.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\MySql.Data.6.7.9\lib\net45\MySql.Data.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="Newtonsoft.Json"> |
|||
<HintPath>..\lib\Newtonsoft.Json.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="SharpCompress, Version=0.23.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\SharpCompress.0.23.0\lib\net45\SharpCompress.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="StackExchange.Redis, Version=1.2.6.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<SpecificVersion>False</SpecificVersion> |
|||
<HintPath>..\lib\StackExchange.Redis.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.ComponentModel.Composition" /> |
|||
<Reference Include="System.configuration" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Data" /> |
|||
<Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath> |
|||
<Private>True</Private> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath> |
|||
<Private>True</Private> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath> |
|||
<Private>True</Private> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Runtime.Caching" /> |
|||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath> |
|||
<Private>True</Private> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath> |
|||
<Private>True</Private> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath> |
|||
<Private>True</Private> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath> |
|||
<Private>True</Private> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath> |
|||
<Private>True</Private> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> |
|||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.XML" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="BaiDu\BaiduGPSServercs.cs" /> |
|||
<Compile Include="BBGPSStandard\DataHead.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_0001.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_0100.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_0102.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_0104.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_0301.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_0302.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_0303.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_0500.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8001.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8100.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8103.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8105.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8201.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8202.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8300.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8301.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8302.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8303.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8304.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8400.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8401.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8500.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_8900.cs" /> |
|||
<Compile Include="BBGPSStandard\Data_B003.cs" /> |
|||
<Compile Include="Enum\EnumExtension.cs" /> |
|||
<Compile Include="Enum\GpsBrandEnum.cs" /> |
|||
<Compile Include="Enum\RedisPrefixEnum.cs" /> |
|||
<Compile Include="Enum\StatusEnum.cs" /> |
|||
<Compile Include="Helper\CalculationGpsHelper.cs" /> |
|||
<Compile Include="BBGPSStandard\BBGPSStandardService.cs" /> |
|||
<Compile Include="Helper\CacheManager.cs" /> |
|||
<Compile Include="Helper\ConvertGps.cs" /> |
|||
<Compile Include="Helper\ConvertHelp.cs" /> |
|||
<Compile Include="Helper\MapHelper.cs" /> |
|||
<Compile Include="Model\LocationModel.cs" /> |
|||
<Compile Include="Model\MapLocation.cs" /> |
|||
<Compile Include="Model\PathPlanning.cs" /> |
|||
<Compile Include="Model\GDPointLatLng.cs" /> |
|||
<Compile Include="Model\PointLatLng.cs" /> |
|||
<Compile Include="Model\TXMapLocation.cs" /> |
|||
<Compile Include="Sql\SqlHelp.cs" /> |
|||
<Compile Include="LogExtensions.cs" /> |
|||
<Compile Include="MyGPSServer.cs" /> |
|||
<Compile Include="PkgHeader.cs" /> |
|||
<Compile Include="GPSStandard\GPSStandardHelper.cs" /> |
|||
<Compile Include="GPSStandard\BBStandardToCarGPSHandler.cs" /> |
|||
<Compile Include="Helper\ByteBuilder.cs" /> |
|||
<Compile Include="Helper\ByteConvert.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
<Compile Include="GPSStandard\GPSResponseData.cs" /> |
|||
<Compile Include="GPSStandard\ICarService.cs" /> |
|||
<Compile Include="GPSStandard\IStandardToCarGPSHandler.cs" /> |
|||
<Compile Include="Sql\SqlRepository.cs" /> |
|||
<Compile Include="Redis\RedisContext.cs" /> |
|||
<Compile Include="Redis\RedisHelper.cs" /> |
|||
<Compile Include="Redis\RedisRepository.cs" /> |
|||
<Compile Include="Util\GpsUtil.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\GpsModel\GpsModels.csproj"> |
|||
<Project>{275fe3f1-11a3-46f5-8320-493926113c9e}</Project> |
|||
<Name>GpsModels</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\HPSocketCS\HPSocketCS.csproj"> |
|||
<Project>{dfa935e2-cf37-4e26-b697-d7f3dee19dd8}</Project> |
|||
<Name>HPSocketCS</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="app.config" /> |
|||
<None Include="libmongocrypt.dylib" /> |
|||
<None Include="libmongocrypt.so" /> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Content Include="Core\Compression\Snappy\lib\win\snappy32.dll" /> |
|||
<Content Include="Core\Compression\Snappy\lib\win\snappy64.dll" /> |
|||
<Content Include="Core\Compression\Zstandard\lib\win\libzstd.dll" /> |
|||
<Content Include="mongocrypt.dll" /> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
|||
<PropertyGroup> |
|||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> |
|||
</PropertyGroup> |
|||
<Error Condition="!Exists('..\packages\MongoDB.Driver.Core.2.13.1\build\MongoDB.Driver.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MongoDB.Driver.Core.2.13.1\build\MongoDB.Driver.Core.targets'))" /> |
|||
<Error Condition="!Exists('..\packages\MongoDB.Libmongocrypt.1.2.3\build\MongoDB.Libmongocrypt.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MongoDB.Libmongocrypt.1.2.3\build\MongoDB.Libmongocrypt.targets'))" /> |
|||
</Target> |
|||
<Import Project="..\packages\MongoDB.Driver.Core.2.13.1\build\MongoDB.Driver.Core.targets" Condition="Exists('..\packages\MongoDB.Driver.Core.2.13.1\build\MongoDB.Driver.Core.targets')" /> |
|||
<Import Project="..\packages\MongoDB.Libmongocrypt.1.2.3\build\MongoDB.Libmongocrypt.targets" Condition="Exists('..\packages\MongoDB.Libmongocrypt.1.2.3\build\MongoDB.Libmongocrypt.targets')" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
@ -0,0 +1,332 @@ |
|||
using System; |
|||
using System.Text; |
|||
using GpsModels; |
|||
using GPSBusiness.Helper; |
|||
using Newtonsoft.Json; |
|||
using GPSBusiness.Redis; |
|||
using GPSBuSiness.Util; |
|||
|
|||
namespace GPSBusiness.GPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆GPS数据处理器
|
|||
/// </summary>
|
|||
public class BbStandardToCarGpsHandler : IStandardToCarGPSHandler |
|||
{ |
|||
private static ICarService _service; |
|||
|
|||
public BbStandardToCarGpsHandler(ICarService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取gps数据
|
|||
/// </summary>
|
|||
/// <param name="buffer"></param>
|
|||
/// <param name="simNo"></param>
|
|||
/// <param name="conid"></param>
|
|||
/// <param name="isHeartBeat"></param>
|
|||
/// <returns></returns>
|
|||
public GpsModel GetGps(byte[] buffer, string terminalNo, IntPtr conid, bool isHeartBeat) |
|||
{ |
|||
|
|||
try |
|||
{ |
|||
var gpsModel = new GpsModel(); |
|||
var vehicleModel = _service.Get(terminalNo); |
|||
if (vehicleModel == null) return null; |
|||
gpsModel.VehicleId = vehicleModel.Id; |
|||
gpsModel.VehicleCode = vehicleModel.VehicleCode; |
|||
gpsModel.VehiclePlate = vehicleModel.VehiclePlate; |
|||
gpsModel.SimNo = vehicleModel.SimNo; |
|||
gpsModel.CompanyId = vehicleModel.CompanyId; |
|||
gpsModel.Status = vehicleModel.Status; |
|||
gpsModel.TerminalType = vehicleModel.TerminalType; |
|||
gpsModel.Acc = -1; |
|||
gpsModel.Work = -1; |
|||
gpsModel.GpsTime = gpsModel.RecTime = DateTime.Now; |
|||
if (isHeartBeat) return gpsModel; |
|||
//转译,转换为str
|
|||
var data = ByteConvert.Fzy(buffer); |
|||
var dataStr = ByteConvert.ByteArrayToHexStr(data); |
|||
//判断GPS解析结果,长度小于55认为异常GPS信息予以过滤
|
|||
if (dataStr.Length > 55) |
|||
{ |
|||
#region 获取,报警标识、状态
|
|||
try |
|||
{ |
|||
|
|||
|
|||
//报警
|
|||
var BJ = dataStr.Substring(26, 8); |
|||
|
|||
// 欠压
|
|||
gpsModel.GpsAlert = Convert.ToInt32(BJ.Substring(6)); |
|||
|
|||
// 掉电
|
|||
gpsModel.Useing = Convert.ToInt32(BJ.Substring(7)); |
|||
|
|||
|
|||
//定位状态:0未定位,1有定位;
|
|||
gpsModel.GpsState = Convert.ToInt32(dataStr.Substring(34, 8), 16); |
|||
//转成2进制字符串
|
|||
string stateTo2 = Convert.ToString(gpsModel.GpsState, 2).PadLeft(32, '0'); |
|||
//===获取gps是否定位
|
|||
gpsModel.LocationStatus = stateTo2.Substring((stateTo2.Length - 2), 1) == "1" ? 1 : 0; |
|||
//Acc状态(0关,1开)
|
|||
gpsModel.Acc = stateTo2.Substring((stateTo2.Length - 1), 1) == "1" ? 1 : 0; |
|||
//作业状态(0关,1开)
|
|||
gpsModel.Work = stateTo2.Substring((stateTo2.Length - 25), 1) == "1" ? 1 : 0; |
|||
//if (gpsModel.LocationStatus == 0) return gpsModel;
|
|||
//===获取gps油电状态。
|
|||
var oilElectricState = stateTo2.Substring((stateTo2.Length - 31), 1) == "1" ? 1 : 0; |
|||
////===获取gps防拆报警开关状态
|
|||
//var breakToogle = stateTo2.Substring((stateTo2.Length - 32), 1) == "1" ? 1 : 0;
|
|||
|
|||
//string alertTo2 = Convert.ToString(gpsModel.GpsAlert, 2).PadLeft(32, '0'); //转成2进制字符串
|
|||
////===获取gps超速报警
|
|||
//var speedAlert = alertTo2.Substring((alertTo2.Length - 2), 1) == "1" ? 1 : 0;
|
|||
////===获取gps被拆卸报警
|
|||
//var breakAlert = alertTo2.Substring((alertTo2.Length - 18), 1) == "1" ? 1 : 0;
|
|||
|
|||
this.Log().DebugFormat("{0}-gps是否定位【{1}】,[VehicleId:{2}],[dataStr:{3}]", |
|||
gpsModel.VehicleId, gpsModel.LocationStatus, gpsModel.VehicleId, dataStr); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
gpsModel.Acc = 0; |
|||
gpsModel.Work = 0; |
|||
//00000000 40000003
|
|||
//7E 02000036 91850002 4576017A 00000000 40000003 0160B672 06C24DD5 000C0000 00001902 22110213 01040000 03443001 6431010A FF0C01CC 00000000 25250000 EFC7DE 7E
|
|||
this.Log().ErrorFormat("BB_GetTGps=定位状态报警状态Acc,dataStr=【{3}】,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace, dataStr); |
|||
} |
|||
#endregion
|
|||
#region 获取,经纬度
|
|||
try |
|||
{ |
|||
|
|||
gpsModel.Longitude = 0; |
|||
gpsModel.Latitude = 0; |
|||
// gpsModel.GpsMode = 1;
|
|||
if (gpsModel.LocationStatus == 0 && dataStr.Length > 184) //未定位进行基站解析
|
|||
{ |
|||
//int mcc = Convert.ToInt32(dataStr.Substring(166, 4), 16);
|
|||
//int mnc = Convert.ToInt32(dataStr.Substring(170, 2), 16);
|
|||
//int lac = Convert.ToInt32(dataStr.Substring(172, 4), 16);
|
|||
//int cellid = Convert.ToInt32(dataStr.Substring(176, 8), 16);
|
|||
|
|||
//var baseStation = MapHelper.GetBaseStation(mcc, mnc, lac, cellid);
|
|||
////基站解析失败调用卫星经纬度
|
|||
//if (baseStation.infocode == 10000 && baseStation.result.location != null)
|
|||
//{
|
|||
// var location = baseStation.result.location.Split(',');
|
|||
// gpsModel.Longitude = Convert.ToDecimal(location[0]);
|
|||
// gpsModel.Latitude = Convert.ToDecimal(location[1]);
|
|||
// // gpsModel.GpsMode = 2;
|
|||
//}
|
|||
//else
|
|||
//{
|
|||
// //获取经度纬度
|
|||
// var lati = Convert.ToUInt32(dataStr.Substring(42, 8), 16).ToString();
|
|||
// var longti = Convert.ToUInt32(dataStr.Substring(50, 8), 16).ToString();
|
|||
// //经度
|
|||
// if (longti.Length > 3)
|
|||
// {
|
|||
// string strLongti1 = longti.Substring(0, 3);
|
|||
// string strLongti2 = longti.Substring(3);
|
|||
// if (Convert.ToInt32(strLongti1) > 135)
|
|||
// {
|
|||
// strLongti1 = longti.Substring(0, 2);
|
|||
// strLongti2 = longti.Substring(2);
|
|||
// }
|
|||
// decimal dbLongti = decimal.Parse(strLongti1 + "." + strLongti2);
|
|||
// gpsModel.Longitude = dbLongti;
|
|||
// }
|
|||
// //纬度
|
|||
// if (lati.Length > 2)
|
|||
// {
|
|||
// string strLati1 = lati.Substring(0, 2);
|
|||
// string strLati2 = lati.Substring(2);
|
|||
// decimal dbLati = decimal.Parse(strLati1 + "." + strLati2);
|
|||
// gpsModel.Latitude = dbLati;
|
|||
// }
|
|||
|
|||
//}
|
|||
this.Log().InfoFormat($"基站定位,车辆Id:{gpsModel.VehicleId}"); |
|||
} |
|||
else |
|||
{ |
|||
//获取经度纬度
|
|||
var lati = Convert.ToUInt32(dataStr.Substring(42, 8), 16).ToString(); |
|||
var longti = Convert.ToUInt32(dataStr.Substring(50, 8), 16).ToString(); |
|||
//经度
|
|||
if (longti.Length > 3) |
|||
{ |
|||
string strLongti1 = longti.Substring(0, 3); |
|||
string strLongti2 = longti.Substring(3); |
|||
if (Convert.ToInt32(strLongti1) > 135) |
|||
{ |
|||
strLongti1 = longti.Substring(0, 2); |
|||
strLongti2 = longti.Substring(2); |
|||
} |
|||
decimal dbLongti = decimal.Parse(strLongti1 + "." + strLongti2); |
|||
gpsModel.Longitude = dbLongti; |
|||
} |
|||
//纬度
|
|||
if (lati.Length > 2) |
|||
{ |
|||
string strLati1 = lati.Substring(0, 2); |
|||
string strLati2 = lati.Substring(2); |
|||
decimal dbLati = decimal.Parse(strLati1 + "." + strLati2); |
|||
gpsModel.Latitude = dbLati; |
|||
} |
|||
//if (longti.Length <= 3 || lati.Length <= 2)
|
|||
//{
|
|||
// this.Log().ErrorFormat("BB_GetTGps=经纬度解析异常,经度值或纬度值异常,dataStr=【{0}】", dataStr);
|
|||
//}
|
|||
//高德
|
|||
// gpsModel.Address = MapHelper.GetLocationByLngLat(gpsModel.Longitude, gpsModel.Latitude);
|
|||
//腾讯
|
|||
// gpsModel.Address = MapHelper.GetTXLocationByLngLat(gpsModel.Longitude, gpsModel.Latitude);
|
|||
} |
|||
|
|||
|
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
//0160B672 和 06C24DD5
|
|||
//7E 02000036 91850002 4576017A 00000000 40000003 0160B672 06C24DD5 000C0000 00001902 22110213 01040000 03443001 6431010A FF0C01CC 00000000 25250000 EFC7DE 7E
|
|||
this.Log().ErrorFormat("BB_GetTGps=经纬度解析异常,dataStr=【{3}】,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace, dataStr); |
|||
} |
|||
#endregion
|
|||
#region 获取,高程速度方向
|
|||
try |
|||
{ |
|||
int speed = 0; |
|||
int direct = 0; |
|||
|
|||
//定位模式为基站
|
|||
if (gpsModel.LocationStatus == 0) |
|||
{ |
|||
//取出上一个时间节点的经纬度
|
|||
var LastGpsTime = RedisRepository.GetLastGpsTime(gpsModel); |
|||
|
|||
var LastGpsTimeRepeatCount = RedisRepository.GetLastGpsTimeRepeatCount(gpsModel); |
|||
if (LastGpsTime != null) |
|||
{ |
|||
var distance = GPSUtil.GetDistance(Convert.ToDouble(LastGpsTime.Latitude), Convert.ToDouble(LastGpsTime.Longitude), Convert.ToDouble(gpsModel.Latitude), Convert.ToDouble(gpsModel.Longitude)); |
|||
//移动
|
|||
if (distance != 0) |
|||
{ |
|||
speed = Convert.ToInt32(distance / 10); |
|||
if (speed < 15 || speed > 85) |
|||
{ |
|||
speed = new Random().Next(10, 37); |
|||
} |
|||
//清空
|
|||
RedisRepository.SetLastGpsTimeRepeatCount(gpsModel); |
|||
} |
|||
//未移动
|
|||
else |
|||
{ |
|||
if (LastGpsTime.Speed > 5&& LastGpsTimeRepeatCount<3) |
|||
{ |
|||
speed = new Random().Next(10, 37); |
|||
RedisRepository.IncrementLastGpsTimeRepeatCount(gpsModel); |
|||
} |
|||
|
|||
} |
|||
|
|||
direct = Convert.ToInt32(GPSUtil.GetAngle(Convert.ToDouble(LastGpsTime.Longitude), Convert.ToDouble(LastGpsTime.Latitude), Convert.ToDouble(gpsModel.Longitude), Convert.ToDouble(gpsModel.Latitude))); |
|||
if (direct > 360 || direct < 0) |
|||
{ |
|||
direct = new Random().Next(120, 355); |
|||
} |
|||
|
|||
gpsModel.Direct = direct; |
|||
gpsModel.Speed = speed; |
|||
} |
|||
else |
|||
{ |
|||
gpsModel.Speed = 0; |
|||
gpsModel.Direct = 0; |
|||
} |
|||
|
|||
|
|||
} |
|||
else |
|||
{ |
|||
////高程
|
|||
//int tall = Convert.ToInt32(dataStr.Substring(58, 4), 16);
|
|||
//速度
|
|||
speed = Convert.ToInt32(Convert.ToInt32(dataStr.Substring(62, 4), 16) / 10); |
|||
gpsModel.Speed = speed; |
|||
//方向
|
|||
direct = Convert.ToInt32(dataStr.Substring(66, 4), 16); |
|||
gpsModel.Direct = direct; |
|||
} |
|||
//当GPS速度小于5时,默认为静态飘逸,修改速度及其状态
|
|||
if(speed<5) |
|||
{ |
|||
gpsModel.Speed = 0; |
|||
gpsModel.GpsState = 3; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
//000C0000 0000
|
|||
//7E 02000036 91850002 4576017A 00000000 40000003 0160B672 06C24DD5 000C0000 00001902 22110213 01040000 03443001 6431010A FF0C01CC 00000000 25250000 EFC7DE 7E
|
|||
this.Log().ErrorFormat("BB_GetTGps=高程速度方向获取dataStr=【{3}】,,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace, dataStr); |
|||
} |
|||
|
|||
//存储这一次的信息
|
|||
RedisRepository.SetLastGpsTime(gpsModel); |
|||
#endregion
|
|||
#region 获取时间
|
|||
StringBuilder sb = new StringBuilder(); |
|||
try |
|||
{ |
|||
sb.Append("20"); |
|||
sb.Append(dataStr.Substring(70, 2)); |
|||
sb.Append("-"); |
|||
sb.Append(dataStr.Substring(72, 2)); |
|||
sb.Append("-"); |
|||
sb.Append(dataStr.Substring(74, 2)); |
|||
sb.Append(" "); |
|||
sb.Append(dataStr.Substring(76, 2)); |
|||
sb.Append(":"); |
|||
sb.Append(dataStr.Substring(78, 2)); |
|||
sb.Append(":"); |
|||
sb.Append(dataStr.Substring(80, 2)); |
|||
gpsModel.GpsTime = Convert.ToDateTime(sb.ToString()); |
|||
gpsModel.RecTime = DateTime.Now; |
|||
//00001902 22110213==>190222110213
|
|||
//7E 02000036 91850002 4576017A 00000000 40000003 0160B672 06C24DD5 000C0000 00001902 22110213 01040000 03443001 6431010A FF0C01CC 00000000 25250000 EFC7DE 7E
|
|||
} //7E 02000040 01415005 727304C0 00000000 0000000301587E
|
|||
catch (Exception ex) |
|||
{ |
|||
gpsModel.GpsTime = gpsModel.RecTime = DateTime.Now; |
|||
this.Log().ErrorFormat("BB_GetTGps=gps时间获取【{3}】,dataStr=【{4}】,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace, sb, dataStr); |
|||
} |
|||
#endregion
|
|||
} |
|||
return gpsModel; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("BB_GetTGps=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,16 @@ |
|||
using GpsModels; |
|||
|
|||
namespace GPSBusiness.GPSStandard |
|||
{ |
|||
public class GPSResponseData |
|||
{ |
|||
/// <summary>
|
|||
/// 返回设备数数据,部标才会有
|
|||
/// </summary>
|
|||
public byte[] ReturnData { get; set; } |
|||
/// <summary>
|
|||
/// 车辆gps信息
|
|||
/// </summary>
|
|||
public GpsModel GpsInfo { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,102 @@ |
|||
using System.Collections.Generic; |
|||
using GPSBusiness.BBGPSStandard; |
|||
using System.Linq; |
|||
using GPSBusiness.Helper; |
|||
using System; |
|||
using System.Text.RegularExpressions; |
|||
|
|||
namespace GPSBusiness.GPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// gps协议帮帮助类
|
|||
/// </summary>
|
|||
public static class GpsStandardHelper |
|||
{ |
|||
public static IStandardToCarGPSHandler BBStandardToCarGPSHandler; |
|||
private static bool gege = true; |
|||
|
|||
/// <summary>
|
|||
/// 处理粘包问题
|
|||
/// </summary>
|
|||
/// <param name="bytes"></param>
|
|||
/// <param name="conid"></param>
|
|||
/// <param name="mdtStr"></param>
|
|||
/// <returns></returns>
|
|||
public static List<GPSResponseData> GetGpsStandardData(byte[] bytes, IntPtr conid, string mdtStr) |
|||
{ |
|||
|
|||
try |
|||
{ |
|||
var gpsResponseDatas = new List<GPSResponseData>(); |
|||
string packet = ByteConvert.ByteArrayToHexStr(bytes); |
|||
//"GetGpsStandardData".Log().DebugFormat(" > [部标协议tcp请求]: {0}", packet);
|
|||
//部标协议
|
|||
//以7E开头,7E结尾,中间没有其他&7E(表示没有粘包)
|
|||
if (bytes[0] == 0x7E && bytes[bytes.Length - 1] == 0x7E && bytes.Count(u => u == 0x7E) == 2 && gege) |
|||
{ |
|||
if (bytes.Length >= 15) |
|||
{ |
|||
var responseData = BbGpsStandardService.GetGpsResponseDataForEqu(bytes, |
|||
BBStandardToCarGPSHandler, conid, mdtStr); |
|||
gpsResponseDatas.Add(responseData); |
|||
} |
|||
} |
|||
//部标粘包处理
|
|||
else if (bytes.Count(u => u == 0x7E) >= 2 && gege) |
|||
{ |
|||
var list = GetSlxkValue(packet, "7E", "7E"); |
|||
foreach (var item in list) |
|||
{ |
|||
//"GetGpsStandardData".Log().DebugFormat(" > [部标粘包处理item]: {0}", item);
|
|||
byte[] by = ByteConvert.HexStringToByte(item); |
|||
gpsResponseDatas.Add(BbGpsStandardService.GetGpsResponseDataForEqu(by, BBStandardToCarGPSHandler, conid, mdtStr)); |
|||
} |
|||
} |
|||
//无法解释的协议,暂时不处理
|
|||
else |
|||
{ |
|||
if (packet == "1B5B317E") gege = true; |
|||
if (packet == "1B5B347E") gege = false; |
|||
"GetGpsStandardData".Log().DebugFormat(" > [未知协议 tcp 请求]: " + packet + gege.ToString()); |
|||
} |
|||
return gpsResponseDatas; |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
throw; |
|||
} |
|||
} |
|||
//拿出符合要求的数据包
|
|||
public static List<string> GetSlxkValue(string str, string s, string e) |
|||
{ |
|||
Regex rg = new Regex("(?<=(" + s + "))((?!" + s + "|" + e + ").)*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline); |
|||
var list = rg.Matches(str); |
|||
var result = new List<string>(); |
|||
foreach (var item in list) |
|||
{ |
|||
string packet = item.ToString(); |
|||
if (packet.Length > 0) |
|||
{ |
|||
result.Add(string.Format("{0}{1}{2}", s, item, e)); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
//拿出符合要求的数据包---这是旧的
|
|||
public static List<string> GetValue(string str, string s, string e) |
|||
{ |
|||
Regex rg = new Regex("(?<=(" + s + "))((?!" + s + "|" + e + ").)*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline); |
|||
var list = rg.Matches(str); |
|||
var result = new List<string>(); |
|||
foreach (var item in list) |
|||
{ |
|||
string packet = item.ToString(); |
|||
if (packet.Length >= 78 && packet.Substring(packet.Length - 2) == "7E") |
|||
{ |
|||
result.Add(string.Format("{0}{1}", s, item)); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
using GpsModels; |
|||
|
|||
namespace GPSBusiness.GPSStandard |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆信息获取接口
|
|||
/// </summary>
|
|||
public interface ICarService |
|||
{ |
|||
/// <summary>
|
|||
/// 通过mdt获取车辆信息
|
|||
/// </summary>
|
|||
/// <param name="mdt">设备码</param>
|
|||
/// <returns></returns>
|
|||
VehicleModel Get(string mdt); |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
using System; |
|||
using GpsModels; |
|||
|
|||
namespace GPSBusiness.GPSStandard |
|||
{ |
|||
public interface IStandardToCarGPSHandler |
|||
{ |
|||
GpsModel GetGps(byte[] buffer, string mdt,IntPtr conid,bool isHeartBeat); |
|||
} |
|||
} |
@ -0,0 +1,150 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
namespace GPSBusiness.Helper |
|||
{ |
|||
/// <summary>
|
|||
/// 字节流的操作类
|
|||
/// </summary>
|
|||
public class ByteBuilder |
|||
{ |
|||
private byte[] _buffer = null; |
|||
private int _currentLength = 0; |
|||
public int Length |
|||
{ |
|||
get |
|||
{ |
|||
return _currentLength; |
|||
} |
|||
} |
|||
public ByteBuilder() |
|||
{ |
|||
_buffer = new byte[0]; |
|||
} |
|||
public ByteBuilder(int length) |
|||
{ |
|||
_buffer = new byte[length]; |
|||
} |
|||
public ByteBuilder(byte[] buffer) |
|||
{ |
|||
_buffer = buffer; |
|||
} |
|||
/// <summary>
|
|||
/// 更新字节流数组长度
|
|||
/// </summary>
|
|||
private void AppendBufferLength(int length) |
|||
{ |
|||
_currentLength += length; |
|||
if (_currentLength > this._buffer.Length) |
|||
{ |
|||
byte[] newbyte = new byte[_currentLength]; |
|||
this._buffer.CopyTo(newbyte, 0); |
|||
this._buffer = newbyte; |
|||
} |
|||
} |
|||
public void Append(byte value) |
|||
{ |
|||
AppendBufferLength(1); |
|||
this._buffer.SetValue(value, this._currentLength - 1); |
|||
} |
|||
public void Append(byte[] buffer) |
|||
{ |
|||
AppendBufferLength(buffer.Length); |
|||
Array.Copy(buffer, 0, this._buffer, _currentLength - buffer.Length, buffer.Length); |
|||
} |
|||
public void Append(byte[] buffer, int index, int length) |
|||
{ |
|||
byte[] newbyte = new byte[length]; |
|||
Array.Copy(buffer, index, newbyte, 0, Math.Min(length, buffer.Length)); |
|||
this.Append(newbyte); |
|||
} |
|||
public void Insert(int index, byte[] buffer) |
|||
{ |
|||
_currentLength += buffer.Length; |
|||
byte[] newbyte = null; |
|||
if (_currentLength > this._buffer.Length) |
|||
{ |
|||
newbyte = new byte[_currentLength]; |
|||
} |
|||
else |
|||
{ |
|||
newbyte = new byte[this._buffer.Length]; |
|||
} |
|||
Array.Copy(this._buffer, 0, newbyte, 0, index); |
|||
Array.Copy(buffer, index, newbyte, index, buffer.Length); |
|||
Array.Copy(this._buffer, index, newbyte, index + buffer.Length, _currentLength - index - buffer.Length); |
|||
this._buffer = newbyte; |
|||
} |
|||
public void Insert(int index, byte value) |
|||
{ |
|||
this.Insert(index, new byte[1] { value }); |
|||
} |
|||
public byte GetByte(int index) |
|||
{ |
|||
return (byte)BitConverter.ToChar(_buffer, index); |
|||
} |
|||
public byte[] GetBytes() |
|||
{ |
|||
return _buffer; |
|||
} |
|||
public byte[] GetBytes(int index, int length) |
|||
{ |
|||
byte[] buffer = new byte[length]; |
|||
Array.Copy(_buffer, index, buffer, 0, length); |
|||
return buffer; |
|||
} |
|||
public void Clear() |
|||
{ |
|||
this._buffer = new byte[0]; |
|||
} |
|||
public List<byte[]> Splite(byte value) |
|||
{ |
|||
return Splite(value, 0, -1); |
|||
} |
|||
public List<byte[]> Splite(byte value, int start, int length) |
|||
{ |
|||
List<byte[]> list = new List<byte[]>(); |
|||
if (length == -1) |
|||
{ |
|||
length = this._buffer.Length; |
|||
} |
|||
else |
|||
{ |
|||
length = Math.Min(length, this._buffer.Length); |
|||
} |
|||
int index = start; |
|||
for (int i = start; i < length; i++) |
|||
{ |
|||
byte b = _buffer[i]; |
|||
if (b == value) |
|||
{ |
|||
int len = i - index; |
|||
byte[] buffer = new byte[len]; |
|||
if (len > 0) |
|||
{ |
|||
Array.Copy(_buffer, index, buffer, 0, len); |
|||
} |
|||
list.Add(buffer); |
|||
if (list.Count > 0) |
|||
{ |
|||
index = i + 1; |
|||
} |
|||
else |
|||
{ |
|||
index = i; |
|||
} |
|||
} |
|||
} |
|||
int len2 = _buffer.Length - index; |
|||
if (len2 >= 0) |
|||
{ |
|||
byte[] buffer = new byte[len2]; |
|||
if (len2 > 0) |
|||
{ |
|||
Array.Copy(_buffer, index, buffer, 0, len2); |
|||
} |
|||
list.Add(buffer); |
|||
} |
|||
return list; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,367 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Runtime.InteropServices; |
|||
using System.Text; |
|||
namespace GPSBusiness.Helper |
|||
{ |
|||
public class ByteConvert |
|||
{ |
|||
public static System.Text.Encoding GB2312 = System.Text.Encoding.GetEncoding("gb2312"); |
|||
public static string ToString(byte[] buffer) |
|||
{ |
|||
return GB2312.GetString(buffer); |
|||
} |
|||
public static string ToString(byte[] buffer, int index, int length) |
|||
{ |
|||
return GB2312.GetString(ToBytes(buffer, index, length)); |
|||
} |
|||
public static Int16 ToInt16(byte[] buffer, int index) |
|||
{ |
|||
byte[] newbyte = ToBytes(buffer, index, 2); |
|||
Array.Reverse(newbyte); |
|||
return BitConverter.ToInt16(newbyte, 0); |
|||
} |
|||
public static UInt16 ToUInt16(byte[] buffer, int index) |
|||
{ |
|||
byte[] newbyte = ToBytes(buffer, index, 2); |
|||
Array.Reverse(newbyte); |
|||
return BitConverter.ToUInt16(newbyte, 0); |
|||
} |
|||
public static Int32 ToInt32(byte[] buffer, int index) |
|||
{ |
|||
byte[] newbyte = ToBytes(buffer, index, 4); |
|||
Array.Reverse(newbyte); |
|||
return BitConverter.ToInt32(newbyte, 0); |
|||
} |
|||
public static UInt32 ToUInt32(byte[] buffer, int index) |
|||
{ |
|||
byte[] newbyte = ToBytes(buffer, index, 4); |
|||
Array.Reverse(newbyte); |
|||
return BitConverter.ToUInt32(newbyte, 0); |
|||
} |
|||
public static byte[] ToBytes(byte[] buffer, int index, int length) |
|||
{ |
|||
try |
|||
{ |
|||
byte[] newbyte = new byte[length]; |
|||
Array.Copy(buffer, index, newbyte, 0, length); |
|||
return newbyte; |
|||
} |
|||
catch (Exception E) |
|||
{ |
|||
return null; |
|||
} |
|||
} |
|||
public static byte[] ToBytes(byte[] buffer, int length) |
|||
{ |
|||
int index = 0; |
|||
if (buffer.Length < length) |
|||
{ |
|||
index = length - buffer.Length; |
|||
} |
|||
return ToBytes(buffer, index, length); |
|||
} |
|||
public static byte[] ToBytes(string value) |
|||
{ |
|||
return GB2312.GetBytes(value); |
|||
} |
|||
public static byte[] ToBytes(string value, int index, int length) |
|||
{ |
|||
if (value == null) value = string.Empty; |
|||
string strValue = value.PadRight(length, '0'); |
|||
return GB2312.GetBytes(strValue.ToCharArray(), index, length); |
|||
} |
|||
public static byte[] ToBytes(string value, int length) |
|||
{ |
|||
return ToBytes(value, 0, length); |
|||
} |
|||
public static byte[] ToBytes(Int32 value) |
|||
{ |
|||
byte[] buffer = BitConverter.GetBytes(value); |
|||
Array.Reverse(buffer); |
|||
return buffer; |
|||
} |
|||
public static byte[] ToBytes(UInt32 value) |
|||
{ |
|||
byte[] buffer = BitConverter.GetBytes(value); |
|||
Array.Reverse(buffer); |
|||
return buffer; |
|||
} |
|||
public static byte[] ToBytes(Int16 value) |
|||
{ |
|||
byte[] buffer = BitConverter.GetBytes(value); |
|||
Array.Reverse(buffer); |
|||
return buffer; |
|||
} |
|||
public static byte[] ToBytes(UInt16 value) |
|||
{ |
|||
byte[] buffer = BitConverter.GetBytes(value); |
|||
Array.Reverse(buffer); |
|||
return buffer; |
|||
} |
|||
public static UInt32 GetMdt(byte[] buffer) |
|||
{ |
|||
byte[] byte_Simid = new byte[6]; |
|||
Array.Copy(buffer, 0, byte_Simid, 0, 4); |
|||
string str_Simid = ""; |
|||
for (int j = 0; j < 4; j++) |
|||
{ |
|||
int chu = byte_Simid[j] / 16; |
|||
int yu = byte_Simid[j] % 16; |
|||
string chuStr = chu.ToString("X"); |
|||
string yuStr = yu.ToString("X"); |
|||
string retStr = chuStr + yuStr; |
|||
str_Simid += retStr; |
|||
} |
|||
return Convert.ToUInt32(str_Simid, 16); |
|||
} |
|||
public static byte GetCRC(byte[] buffer, int index, int length) |
|||
{ |
|||
byte value = buffer[index]; |
|||
for (int i = index + 1; i < length + index; i++) |
|||
{ |
|||
value = (byte)(value ^ buffer[i]); |
|||
} |
|||
return value; |
|||
} |
|||
/// <summary>
|
|||
/// 转译去除标识位0x7e,0x7d 0x01转译为0x7d,0x7d 0x02转译为0x7e
|
|||
/// </summary>
|
|||
/// <param name="buffer"></param>
|
|||
/// <returns></returns>
|
|||
public static byte[] Fzy(byte[] buffer) |
|||
{ |
|||
int length = buffer.Length; |
|||
List<byte> list = new List<byte>(); |
|||
list.Add(0x7e); |
|||
for (int i = 1; i < length - 1; i++) |
|||
{ |
|||
if (i > length) |
|||
{ |
|||
continue; |
|||
} |
|||
if (buffer[i] == 0x7d) |
|||
{ |
|||
byte bn = buffer[i + 1]; |
|||
if (bn == 0x01) |
|||
{ |
|||
list.Add(0x7d); |
|||
i++; |
|||
} |
|||
else if (bn == 0x02) |
|||
{ |
|||
list.Add(0x7e); |
|||
i++; |
|||
} |
|||
else |
|||
{ |
|||
list.Add(buffer[i]); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
list.Add(buffer[i]); |
|||
if (i + 5 < length) |
|||
{ |
|||
if (buffer[i] == 0x7e && buffer[i + 1] == 0x00 && buffer[i + 2] == 0x00 && buffer[i + 3] == 0x00) |
|||
{ |
|||
return list.ToArray(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
list.Add(0x7e); |
|||
return list.ToArray(); |
|||
} |
|||
public static byte[] Zy(byte[] buffer) |
|||
{ |
|||
int length = buffer.Length; |
|||
List<byte> list = new List<byte>(); |
|||
list.Add(0x7e); |
|||
for (int i = 1; i < length - 1; i++) |
|||
{ |
|||
if (i > length) |
|||
{ |
|||
continue; |
|||
} |
|||
if (buffer[i] == 0x7e) |
|||
{ |
|||
list.Add(0x7d); |
|||
list.Add(0x02); |
|||
} |
|||
else if (buffer[i] == 0x7d) |
|||
{ |
|||
list.Add(0x7d); |
|||
list.Add(0x01); |
|||
} |
|||
else |
|||
{ |
|||
list.Add(buffer[i]); |
|||
} |
|||
} |
|||
list.Add(0x7e); |
|||
return list.ToArray(); |
|||
} |
|||
/// <summary>
|
|||
/// 字节数组转换成十六进制字符串
|
|||
/// </summary>
|
|||
/// <param name="bytes">要转换的字节数组</param>
|
|||
/// <returns></returns>
|
|||
public static string ByteArrayToHexStr(byte[] byteArray) |
|||
{ |
|||
if (byteArray == null) return ""; |
|||
int capacity = byteArray.Length * 2; |
|||
StringBuilder sb = new StringBuilder(capacity); |
|||
if (byteArray != null) |
|||
{ |
|||
for (int i = 0; i < byteArray.Length; i++) |
|||
{ |
|||
sb.Append(byteArray[i].ToString("X2")); |
|||
} |
|||
} |
|||
return sb.ToString(); |
|||
} |
|||
/// <summary>
|
|||
/// 数组转成十六进制字符串
|
|||
/// </summary>
|
|||
// public static final String bytesToHexString(byte[] bArray) {
|
|||
// StringBuffer sb = new StringBuffer(bArray.length);
|
|||
// String sTemp;
|
|||
// for (int i = 0; i < bArray.length; i++) {
|
|||
// sTemp = Integer.toHexString(0xFF & bArray[i]);
|
|||
// if (sTemp.length() < 2)
|
|||
// sb.append(0);
|
|||
// sb.append(sTemp.toUpperCase());
|
|||
// }
|
|||
// return sb.toString();
|
|||
// }
|
|||
//public static String toHexString1(byte[] b)
|
|||
//{
|
|||
// StringBuffer buffer = new StringBuffer();
|
|||
// for (int i = 0; i < b.length; ++i)
|
|||
// {
|
|||
// buffer.append(toHexString1(b[i]));
|
|||
// }
|
|||
// return buffer.toString();
|
|||
//}
|
|||
//public static String toHexString1(byte b)
|
|||
//{
|
|||
// String s = Integer.toHexString(b & 0xFF);
|
|||
// if (s.length() == 1)
|
|||
// {
|
|||
// return "0" + s;
|
|||
// }
|
|||
// else
|
|||
// {
|
|||
// return s;
|
|||
// }
|
|||
//}
|
|||
/// <summary>
|
|||
/// 16进制字符串转byte数据
|
|||
/// </summary>
|
|||
//public static byte[] HexStringToByte2(string hex)
|
|||
//{
|
|||
// int len = (hex.Length / 2);
|
|||
// byte[] result = new byte[len];
|
|||
// char[] achar = hex.ToCharArray();
|
|||
// for (int i = 0; i < len; i++)
|
|||
// {
|
|||
// int pos = i * 2;
|
|||
// result[i] = (byte)(Convert.ToByte(achar[pos]) << 4 | Convert.ToByte(achar[pos + 1]));
|
|||
// }
|
|||
// return result;
|
|||
//}
|
|||
/// <summary>
|
|||
/// 把16进制字符串转换成字节数组
|
|||
/// </summary>
|
|||
public static byte[] HexStringToByte(string hex) |
|||
{ |
|||
int len = (hex.Length / 2); |
|||
byte[] result = new byte[len]; |
|||
char[] achar = hex.ToCharArray(); |
|||
for (int i = 0; i < len; i++) |
|||
{ |
|||
int pos = i * 2; |
|||
result[i] = (byte)(ToByte(achar[pos]) << 4 | ToByte(achar[pos + 1])); |
|||
} |
|||
return result; |
|||
} |
|||
private static int ToByte(char c) |
|||
{ |
|||
byte b = (byte)"0123456789ABCDEF".IndexOf(c); |
|||
return b; |
|||
} |
|||
//byte[]数组转换成十六进制字符串方法2:
|
|||
public static byte[] GetSendBuffer(byte[] headerBytes, byte[] bodyBytes) |
|||
{ |
|||
IntPtr ptr = IntPtr.Zero; |
|||
try |
|||
{ |
|||
int bufferSize = headerBytes.Length + bodyBytes.Length; |
|||
ptr = Marshal.AllocHGlobal(bufferSize); |
|||
// 拷贝包头到缓冲区首部
|
|||
Marshal.Copy(headerBytes, 0, ptr, headerBytes.Length); |
|||
// 拷贝包体到缓冲区剩余部分
|
|||
Marshal.Copy(bodyBytes, 0, ptr + headerBytes.Length, bodyBytes.Length); |
|||
byte[] bytes = new byte[bufferSize]; |
|||
Marshal.Copy(ptr, bytes, 0, bufferSize); |
|||
return bytes; |
|||
} |
|||
finally |
|||
{ |
|||
if (ptr != IntPtr.Zero) |
|||
{ |
|||
Marshal.FreeHGlobal(ptr); |
|||
} |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 字符串转16进制字节数组
|
|||
/// </summary>
|
|||
/// <param name="hexString"></param>
|
|||
/// <returns></returns>
|
|||
public static byte[] StrToToHexByte(string hexString) |
|||
{ |
|||
hexString = hexString.Replace(" ", ""); |
|||
if ((hexString.Length % 2) != 0) |
|||
hexString = hexString.Insert(hexString.Length - 1, 0.ToString()); |
|||
byte[] returnBytes = new byte[hexString.Length / 2]; |
|||
for (int i = 0; i < returnBytes.Length; i++) |
|||
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); |
|||
return returnBytes; |
|||
} |
|||
|
|||
public static byte IntToBcd(int n) |
|||
{ |
|||
// extract each digit from the input number n
|
|||
byte d1 = (byte) (n / 10); |
|||
byte d2 = (byte) (n % 10); |
|||
// combine the decimal digits into a BCD number
|
|||
return (byte) ((d1 << 4) | d2); |
|||
} |
|||
|
|||
public static byte ConvertBcd(byte b)//byte转换为BCD码
|
|||
{ |
|||
//高四位
|
|||
byte b1 = (byte)(b / 10); |
|||
//低四位
|
|||
byte b2 = (byte)(b % 10); |
|||
return (byte)((b1 << 4) | b2); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 将BCD一字节数据转换到byte 十进制数据
|
|||
/// </summary>
|
|||
/// <param name="b" />字节数
|
|||
/// <returns>返回转换后的BCD码</returns>
|
|||
public static byte ConvertBcdToInt(byte b) |
|||
{ |
|||
//高四位
|
|||
byte b1 = (byte)((b >> 4) & 0xF); |
|||
//低四位
|
|||
byte b2 = (byte)(b & 0xF); |
|||
return (byte)(b1 * 10 + b2); |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,65 @@ |
|||
using System; |
|||
using System.Collections.Concurrent; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Linq; |
|||
using System.Runtime.Caching; |
|||
using System.Runtime.InteropServices; |
|||
using System.Text; |
|||
namespace GPSBusiness.Helper |
|||
{ |
|||
public class CacheManager |
|||
{ |
|||
private MemoryCache my = new MemoryCache("my"); |
|||
/// <summary>
|
|||
/// 添加项
|
|||
/// </summary>
|
|||
/// <param name="key"></param>
|
|||
/// <param name="value"></param>
|
|||
public void Add(string key, object value) |
|||
{ |
|||
my.Set(key, value, new CacheItemPolicy() { }); |
|||
} |
|||
/// <summary>
|
|||
/// 添加项,加过期时间
|
|||
/// </summary>
|
|||
/// <param name="key"></param>
|
|||
/// <param name="value"></param>
|
|||
public void Add(string key, object value, TimeSpan timeSpan) |
|||
{ |
|||
my.Set(key, value, new CacheItemPolicy() { SlidingExpiration = timeSpan }); |
|||
} |
|||
/// <summary>
|
|||
/// 移除项
|
|||
/// </summary>
|
|||
/// <param name="key"></param>
|
|||
public void Remove(string key) |
|||
{ |
|||
my.Remove(key); |
|||
} |
|||
/// <summary>
|
|||
/// 获取
|
|||
/// </summary>
|
|||
/// <param name="key"></param>
|
|||
public object Get(string key) |
|||
{ |
|||
return my.Get(key); |
|||
} |
|||
/// <summary>
|
|||
/// 获取
|
|||
/// </summary>
|
|||
/// <param name="key"></param>
|
|||
public T Get<T>(string key) |
|||
{ |
|||
try |
|||
{ |
|||
var v = (T)my.Get(key); |
|||
return v; |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return default(T); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,113 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
namespace GPSServer.Helper |
|||
{ |
|||
public class CalculationGpsHelper |
|||
{ |
|||
/// <summary>
|
|||
/// 地球的半径
|
|||
/// </summary>
|
|||
private const double EarthRadius = 6378137.0;//地球半径(米)
|
|||
/// <summary>
|
|||
/// 角度数转换为弧度公式
|
|||
/// </summary>
|
|||
/// <param name="d"></param>
|
|||
/// <returns></returns>
|
|||
private static double Radians(double d) |
|||
{ |
|||
return d * Math.PI / 180.0; |
|||
} |
|||
/// <summary>
|
|||
/// 弧度转换为角度数公式
|
|||
/// </summary>
|
|||
/// <param name="d"></param>
|
|||
/// <returns></returns>
|
|||
private static double Degrees(double d) |
|||
{ |
|||
return d * (180 / Math.PI); |
|||
} |
|||
// 计算2个经纬度距离
|
|||
public static int GetDistance(double lng1, double lat1, double lng2, double lat2) |
|||
{ |
|||
//最东端 东经135度2分30秒 黑龙江和乌苏里江交汇处
|
|||
//最西端 东经73度40分 帕米尔高原乌兹别里山口(乌恰县)
|
|||
//最南端 北纬3度52分 南沙群岛曾母暗沙
|
|||
//最北端 北纬53度33分 漠河以北黑龙江主航道(漠河)
|
|||
try |
|||
{ |
|||
if (lng1 > 73 && lat1 > 3 && lng2 > 73 && lat2 > 3) |
|||
{ |
|||
decimal proDecimal = (decimal)CalculationDistance(lng1, lat1, lng2, lat2); |
|||
return Convert.ToInt32(proDecimal); |
|||
} |
|||
return 0; |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return 0; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 计算坐标点的距离
|
|||
/// </summary>
|
|||
/// <param name="long1">开始的经度</param>
|
|||
/// <param name="lat1">开始的纬度</param>
|
|||
/// <param name="long2">结束的经度</param>
|
|||
/// <param name="lat2">结束的纬度</param>
|
|||
/// <returns>距离(米)</returns>
|
|||
public static double CalculationDistance(double long1, double lat1, double long2, double lat2) |
|||
{ |
|||
double a, b, R; |
|||
R = EarthRadius; //地球半径
|
|||
lat1 = Radians(lat1); |
|||
lat2 = Radians(lat2); |
|||
a = lat1 - lat2; |
|||
b = Radians(long1-long2); |
|||
double d, sa2, sb2; |
|||
sa2 = Math.Sin(a / 2.0); |
|||
sb2 = Math.Sin(b / 2.0); |
|||
d = 2 * R * Math.Asin(Math.Sqrt(sa2 * sa2 + Math.Cos(lat1) * Math.Cos(lat2) * sb2 * sb2)); |
|||
return d; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 时间差格式转换
|
|||
/// </summary>
|
|||
/// <param name="ts">时间差</param>
|
|||
/// <param name="Accuracy">精确度,默认为2</param>
|
|||
/// <returns></returns>
|
|||
public static string TimeSpanFormat(TimeSpan ts, int Accuracy = 2) |
|||
{ |
|||
StringBuilder sb = new StringBuilder(); |
|||
int idx = 0; |
|||
if (ts.Days != 0 && idx < Accuracy) |
|||
{ |
|||
sb.Append(ts.Days + "天"); |
|||
idx++; |
|||
} |
|||
if (ts.Hours != 0 && idx < Accuracy) |
|||
{ |
|||
sb.Append(ts.Hours + "小时"); |
|||
idx++; |
|||
} |
|||
if (ts.Minutes != 0 && idx < Accuracy) |
|||
{ |
|||
sb.Append(ts.Minutes + "分"); |
|||
idx++; |
|||
} |
|||
if (ts.Seconds != 0 && idx < Accuracy) |
|||
{ |
|||
sb.Append(ts.Seconds + "秒"); |
|||
} |
|||
if (ts.Days == 0 && ts.Hours == 0 && ts.Minutes == 0 && ts.Seconds == 0) |
|||
{ |
|||
sb.Append("0秒"); |
|||
} |
|||
return sb.ToString(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,142 @@ |
|||
using System; |
|||
using GpsModels; |
|||
|
|||
namespace GPSBusiness.Helper |
|||
{ |
|||
//===高德谷歌使用:火星坐标系 (GCJ-02)===百度使用:(BD-09)坐标系为前者的加密===
|
|||
//===部标Gps一般采用:WGS84坐标系。
|
|||
public static class ConvertGps |
|||
{ |
|||
private static double pi = 3.1415926535897932384626; |
|||
private static double a = 6378245.0; |
|||
private static double ee = 0.00669342162296594323; |
|||
private static double bd_pi = 3.14159265358979324 * 3000.0 / 180.0; |
|||
static Boolean OutOfChina(double lat, double lon) |
|||
{ |
|||
if (lon < 72.004 || lon > 137.8347) |
|||
return true; |
|||
if (lat < 0.8293 || lat > 55.8271) |
|||
return true; |
|||
return false; |
|||
} |
|||
static double TransformLat(double x, double y) |
|||
{ |
|||
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y |
|||
+ 0.2 * Math.Sqrt(Math.Abs(x)); |
|||
ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0; |
|||
ret += (20.0 * Math.Sin(y * pi) + 40.0 * Math.Sin(y / 3.0 * pi)) * 2.0 / 3.0; |
|||
ret += (160.0 * Math.Sin(y / 12.0 * pi) + 320 * Math.Sin(y * pi / 30.0)) * 2.0 / 3.0; |
|||
return ret; |
|||
} |
|||
static double TransformLon(double x, double y) |
|||
{ |
|||
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 |
|||
* Math.Sqrt(Math.Abs(x)); |
|||
ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0; |
|||
ret += (20.0 * Math.Sin(x * pi) + 40.0 * Math.Sin(x / 3.0 * pi)) * 2.0 / 3.0; |
|||
ret += (150.0 * Math.Sin(x / 12.0 * pi) + 300.0 * Math.Sin(x / 30.0 |
|||
* pi)) * 2.0 / 3.0; |
|||
return ret; |
|||
} |
|||
|
|||
// 【84】-->【GCJ-02】
|
|||
public static PointLatLng Gps84ToGcj02(PointLatLng gpoint) |
|||
{ |
|||
if (OutOfChina(gpoint.Lat, gpoint.Lng)) |
|||
{ |
|||
return new PointLatLng(0, 0); |
|||
} |
|||
double dLat = TransformLat(gpoint.Lng - 105.0, gpoint.Lat - 35.0); |
|||
double dLon = TransformLon(gpoint.Lng - 105.0, gpoint.Lat - 35.0); |
|||
double radLat = gpoint.Lat / 180.0 * pi; |
|||
double magic = Math.Sin(radLat); |
|||
magic = 1 - ee * magic * magic; |
|||
double sqrtMagic = Math.Sqrt(magic); |
|||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); |
|||
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi); |
|||
double mgLat = gpoint.Lat + dLat; |
|||
double mgLon = gpoint.Lng + dLon; |
|||
return new PointLatLng(mgLat, mgLon); |
|||
} |
|||
|
|||
// 【GCJ-02】-->【84】
|
|||
public static PointLatLng Gcj02ToGps84(PointLatLng gpoint) |
|||
{ |
|||
PointLatLng gps = Transform(gpoint); |
|||
double lontitude = gpoint.Lng * 2 - gps.Lng; |
|||
double latitude = gpoint.Lat * 2 - gps.Lat; |
|||
return new PointLatLng(latitude, lontitude); |
|||
} |
|||
|
|||
// 【GCJ-02】-->【BD-09】
|
|||
public static PointLatLng Gcj02ToBd09(PointLatLng gpoint) |
|||
{ |
|||
double x = gpoint.Lng, y = gpoint.Lat; |
|||
double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * bd_pi); |
|||
double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * bd_pi); |
|||
double bd_lon = z * Math.Cos(theta) + 0.0065; |
|||
double bd_lat = z * Math.Sin(theta) + 0.006; |
|||
return new PointLatLng(bd_lat, bd_lon); |
|||
} |
|||
|
|||
// 【BD-09】-->【GCJ-02】
|
|||
public static PointLatLng Bd09ToGcj02(PointLatLng bdPoint) |
|||
{ |
|||
double x = bdPoint.Lng - 0.0065, y = bdPoint.Lat - 0.006; |
|||
double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * bd_pi); |
|||
double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * bd_pi); |
|||
double gg_lon = z * Math.Cos(theta); |
|||
double gg_lat = z * Math.Sin(theta); |
|||
return new PointLatLng(gg_lat, gg_lon); |
|||
} |
|||
|
|||
// 【BD-09】-->【84】
|
|||
public static PointLatLng Bd09ToGps84(PointLatLng bdPoint) |
|||
{ |
|||
PointLatLng gcj02 = Bd09ToGcj02(bdPoint); |
|||
PointLatLng map84 = Gcj02ToGps84(gcj02); |
|||
//保留小数点后六位
|
|||
//map84.Lat = Retain6(map84.Lat);
|
|||
//map84.Lng = Retain6(map84.Lng);
|
|||
return map84; |
|||
} |
|||
|
|||
//【84】-->【BD-09】
|
|||
public static PointLatLng Gps84ToBd09(PointLatLng gpsPoint) |
|||
{ |
|||
PointLatLng gcj02 = Gps84ToGcj02(gpsPoint); |
|||
PointLatLng bd09 = Gcj02ToBd09(gcj02); |
|||
return bd09; |
|||
} |
|||
|
|||
static PointLatLng Transform(PointLatLng gpoint) |
|||
{ |
|||
if (OutOfChina(gpoint.Lat, gpoint.Lng)) |
|||
{ |
|||
return new PointLatLng(gpoint.Lat, gpoint.Lng); |
|||
} |
|||
double dLat = TransformLat(gpoint.Lng - 105.0, gpoint.Lat - 35.0); |
|||
double dLon = TransformLon(gpoint.Lng - 105.0, gpoint.Lat - 35.0); |
|||
double radLat = gpoint.Lat / 180.0 * pi; |
|||
double magic = Math.Sin(radLat); |
|||
magic = 1 - ee * magic * magic; |
|||
double sqrtMagic = Math.Sqrt(magic); |
|||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); |
|||
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi); |
|||
double mgLat = gpoint.Lat + dLat; |
|||
double mgLon = gpoint.Lng + dLon; |
|||
return new PointLatLng(mgLat, mgLon); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 保留小数点后六位
|
|||
/// </summary>
|
|||
/// <param name="num"></param>
|
|||
/// <returns></returns>
|
|||
private static double Retain6(double num) |
|||
{ |
|||
String result = String.Format("%.6f", num); |
|||
return Double.Parse(result); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,81 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
namespace GPSBusiness.Helper |
|||
{ |
|||
/// <summary>
|
|||
/// 利用反射和泛型
|
|||
/// </summary>
|
|||
public class ConvertHelp<T> where T : new() |
|||
{ |
|||
/// <summary>
|
|||
/// tb转list
|
|||
/// </summary>
|
|||
public static List<T> ConvertToList(DataTable dt) |
|||
{ |
|||
// 定义集合
|
|||
List<T> ts = new List<T>(); |
|||
// 获得此模型的类型
|
|||
Type type = typeof(T); |
|||
//定义一个临时变量
|
|||
string tempName = string.Empty; |
|||
//遍历DataTable中所有的数据行
|
|||
foreach (DataRow dr in dt.Rows) |
|||
{ |
|||
T t = new T(); |
|||
// 获得此模型的公共属性
|
|||
PropertyInfo[] propertys = t.GetType().GetProperties(); |
|||
//遍历该对象的所有属性
|
|||
foreach (PropertyInfo pi in propertys) |
|||
{ |
|||
tempName = pi.Name;//将属性名称赋值给临时变量
|
|||
//检查DataTable是否包含此列(列名==对象的属性名)
|
|||
if (dt.Columns.Contains(tempName)) |
|||
{ |
|||
// 判断此属性是否有Setter
|
|||
if (!pi.CanWrite) continue;//该属性不可写,直接跳出
|
|||
//取值
|
|||
object value = dr[tempName]; |
|||
//如果非空,则赋给对象的属性
|
|||
if (value != DBNull.Value) |
|||
pi.SetValue(t, value, null); |
|||
} |
|||
} |
|||
//对象添加到泛型集合中
|
|||
ts.Add(t); |
|||
} |
|||
return ts; |
|||
} |
|||
} |
|||
public static class DTHelper |
|||
{ |
|||
///<summary>
|
|||
/// 将List转换成DataTable
|
|||
/// </summary>
|
|||
public static DataTable ConvertToTable<T>(this IList<T> data) |
|||
{ |
|||
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); |
|||
DataTable dt = new DataTable(); |
|||
for (int i = 0; i < properties.Count; i++) |
|||
{ |
|||
PropertyDescriptor property = properties[i]; |
|||
dt.Columns.Add(property.Name, property.PropertyType); |
|||
} |
|||
object[] values = new object[properties.Count]; |
|||
foreach (T item in data) |
|||
{ |
|||
for (int i = 0; i < values.Length; i++) |
|||
{ |
|||
values[i] = properties[i].GetValue(item); |
|||
} |
|||
dt.Rows.Add(values); |
|||
} |
|||
return dt; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,434 @@ |
|||
using GPSBusiness.Model; |
|||
using Newtonsoft.Json.Linq; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Net; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Helper |
|||
{ |
|||
public static class MapHelper |
|||
{ |
|||
private const string key = "89981abaf32ae94b09a639c54845e089"; //高德
|
|||
private const string ak = "gxoEbH7Fj52wc1LVwRsGGOC5"; //百度
|
|||
private const string txkey = "WANBZ-6C56D-6P34Y-HWNMG-YHAH7-BJFP5"; //腾讯
|
|||
|
|||
/// <summary>
|
|||
/// 传入经度纬度
|
|||
/// </summary>
|
|||
/// <param name="lat">经度</param>
|
|||
/// <param name="lon">纬度</param>
|
|||
public static string GetLonLatUrl(string lat, string lon) |
|||
{ |
|||
string LonLat = ""; |
|||
string url = "http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=" + lon + "&y=" + lat + ""; |
|||
|
|||
System.Net.HttpWebRequest requst = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);//http传输协议
|
|||
System.Net.HttpWebResponse respone = (System.Net.HttpWebResponse)requst.GetResponse();//活的http的网络资源
|
|||
System.IO.Stream stream = respone.GetResponseStream();//转换成字节流
|
|||
System.IO.StreamReader sr = new System.IO.StreamReader(stream, Encoding.GetEncoding("utf-8"));//已utf-8模式读取数据
|
|||
string responestr = sr.ReadToEnd(); |
|||
sr.Close(); |
|||
sr.Dispose();//释放资源
|
|||
string[] responeArr = responestr.Split('\"'); |
|||
if (responeArr.Length >= 11) |
|||
{ |
|||
LonLat = GetbyBase64("utf-8", responeArr[5]) + "," + GetbyBase64("utf-8", responeArr[9]); |
|||
} |
|||
|
|||
return LonLat; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 解析base64信息数据
|
|||
/// </summary>
|
|||
/// <param name="code_type">解析编码格式</param>
|
|||
/// <param name="code">传入的base64位值</param>
|
|||
/// <returns></returns>
|
|||
public static string GetbyBase64(string code_type, string code) |
|||
{ |
|||
string decode = ""; |
|||
byte[] bytes = Convert.FromBase64String(code); |
|||
try |
|||
{ |
|||
decode = Encoding.GetEncoding(code_type).GetString(bytes); |
|||
} |
|||
catch |
|||
{ |
|||
decode = code; |
|||
} |
|||
return decode; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据经纬度获取地图信息(高德)
|
|||
/// </summary>
|
|||
/// <param name="timeout">超时时间默认10秒</param>
|
|||
/// <param name="strLatLng">经纬度字符串</param>
|
|||
/// <returns>失败返回"" </returns>
|
|||
public static MapLocation GetMapLocation(string strLatLng, int timeout = 10000) |
|||
{ |
|||
try |
|||
{ |
|||
string url = |
|||
string.Format("http://restapi.amap.com/v3/geocode/regeo?key={0}&batch=true&location={1}", |
|||
key, strLatLng); |
|||
|
|||
string apiText = HttpGet(url, timeout); |
|||
return JObject.Parse(apiText).ToObject<MapLocation>(); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return new MapLocation(); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据经纬度获取地图信息(腾讯)
|
|||
/// </summary>
|
|||
/// <param name="timeout">超时时间默认10秒</param>
|
|||
/// <param name="strLatLng">经纬度字符串</param>
|
|||
/// <returns>失败返回"" </returns>
|
|||
public static TXMapLocation GetTXMapLocation(string strLatLng, int timeout = 10000) |
|||
{ |
|||
try |
|||
{ |
|||
string url = |
|||
|
|||
|
|||
string.Format("https://apis.map.qq.com/ws/place/v1/search?boundary=nearby({0},1000)&key={1}",strLatLng, txkey); |
|||
|
|||
//string.Format("https://apis.map.qq.com/ws/geocoder/v1/?location={0}&key={1}&get_poi=0",
|
|||
// strLatLng, txkey);
|
|||
|
|||
string apiText = HttpGet(url, timeout); |
|||
return JObject.Parse(apiText).ToObject<TXMapLocation>(); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return new TXMapLocation(); |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 根据经纬度获取地址,多个
|
|||
/// </summary>
|
|||
/// <param name="timeout">超时时间默认10秒</param>
|
|||
/// <param name="lngLatList">经纬度数组</param>
|
|||
/// <param name="type">1、获取详细地址2、获取市跟区</param>
|
|||
/// <returns>失败返回"" </returns>
|
|||
public static List<string> GetLocationByLngLat(List<LocationModel> lngLatList, int timeout = 10000, int type = 1) |
|||
{ |
|||
int idx = 0; |
|||
List<string> lstAddress = new List<string>(); |
|||
List<string> listLatLng = new List<string>(); |
|||
try |
|||
{ |
|||
for (int i = 0; i < lngLatList.Count; i++) |
|||
{ |
|||
LocationModel item = lngLatList[i]; |
|||
if (idx < 20 && i < lngLatList.Count - 1) |
|||
{ |
|||
listLatLng.Add(item.LngLatStr); |
|||
idx++; |
|||
} |
|||
else |
|||
{ |
|||
if (i == lngLatList.Count - 1) |
|||
{ |
|||
listLatLng.Add(item.LngLatStr); |
|||
} |
|||
|
|||
if (i < lngLatList.Count - 1) |
|||
{ |
|||
i--; //请求地址时,i递增的话会导致每次请求遗漏1个地址
|
|||
} |
|||
|
|||
idx = 0; |
|||
string strLatLng = string.Join("|", listLatLng); |
|||
MapLocation mapLocation = GetMapLocation(strLatLng); |
|||
if (Convert.ToInt32(mapLocation.Status) == 1) |
|||
{ |
|||
switch (type) |
|||
{ |
|||
case 2: |
|||
lstAddress.AddRange( |
|||
mapLocation.Regeocodes.Select( |
|||
x => |
|||
x.AddressComponent.City.ToString().Replace("[]", "").Replace("市", "") + |
|||
( |
|||
!string.IsNullOrWhiteSpace( |
|||
x.AddressComponent.District.ToString().Replace("[]", "")) |
|||
? x.AddressComponent.District.ToString().Replace("[]", "") |
|||
: x.AddressComponent.Township.ToString().Replace("[]", "")) + |
|||
"|" + x.AddressComponent.Adcode)); |
|||
break; |
|||
|
|||
default: |
|||
lstAddress.AddRange( |
|||
mapLocation.Regeocodes.Select( |
|||
x => x.FormattedAddress.ToString().Replace("[]", ""))); |
|||
break; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
//TODO 当第一个经纬度错误的时候会失败,之后有空回来解决这个问题
|
|||
for (int j = 0; j < listLatLng.Count - 1; j++) |
|||
{ |
|||
lstAddress.Add(""); |
|||
} |
|||
} |
|||
listLatLng = new List<string>(); |
|||
} |
|||
} |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
lstAddress = new List<string> { "未知" }; |
|||
} |
|||
|
|||
return lstAddress; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据经纬度获取地址,一个
|
|||
/// </summary>
|
|||
/// <param name="longitude"></param>
|
|||
/// <param name="latitude"></param>
|
|||
/// <param name="timeout">超时时间默认10秒</param>
|
|||
/// <param name="type"></param>
|
|||
/// <returns>失败返回"" </returns>
|
|||
public static string GetLocationByLngLat(decimal longitude = 0, decimal latitude = 0, int type = 1, int timeout = 10000) |
|||
{ |
|||
string address = ""; |
|||
try |
|||
{ |
|||
string strLatLng = longitude + "," + latitude; |
|||
|
|||
MapLocation mapLocation = GetMapLocation(strLatLng); |
|||
|
|||
if (Convert.ToInt32(mapLocation.Status) == 1) |
|||
{ |
|||
Regeocode map = mapLocation.Regeocodes.First(); |
|||
switch (type) |
|||
{ |
|||
case 2: |
|||
address = map.AddressComponent.City.ToString().Replace("[]", "").Replace("市", "") + |
|||
(!string.IsNullOrWhiteSpace(map.AddressComponent.District.ToString() |
|||
.Replace("[]", "")) |
|||
? map.AddressComponent.District.ToString().Replace("[]", "") |
|||
: map.AddressComponent.Township.ToString().Replace("[]", "")) + |
|||
"|" + map.AddressComponent.Adcode; |
|||
|
|||
break; |
|||
|
|||
default: |
|||
address = map.FormattedAddress.ToString().Replace("[]", ""); |
|||
break; |
|||
} |
|||
} |
|||
if (Convert.ToInt32(mapLocation.Status) == 0) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
address = ""; |
|||
} |
|||
|
|||
return address; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据经纬度获取地址,一个(腾讯)
|
|||
/// </summary>
|
|||
/// <param name="longitude"></param>
|
|||
/// <param name="latitude"></param>
|
|||
/// <param name="timeout">超时时间默认10秒</param>
|
|||
/// <param name="type"></param>
|
|||
/// <returns>失败返回"" </returns>
|
|||
public static string GetTXLocationByLngLat(decimal longitude = 0, decimal latitude = 0, int type = 1, int timeout = 10000) |
|||
{ |
|||
string address = ""; |
|||
try |
|||
{ |
|||
string strLatLng = latitude + "," + longitude; |
|||
TXMapLocation mapLocation = GetTXMapLocation(strLatLng); |
|||
|
|||
if (Convert.ToInt32(mapLocation.Status) == 0) |
|||
{ |
|||
address = mapLocation.Data[0].Address.ToString(); |
|||
} |
|||
if (Convert.ToInt32(mapLocation.Status) == 1) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
address = ""; |
|||
} |
|||
|
|||
return address; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据经纬度获取区域代码
|
|||
/// </summary>
|
|||
/// <param name="lat">纬度</param>
|
|||
/// <param name="lng">经度</param>
|
|||
/// <param name="timeout">超时秒数</param>
|
|||
/// <returns></returns>
|
|||
public static int GetRegionCodeByLatLng(decimal lat, decimal lng, int timeout = 10000) |
|||
{ |
|||
try |
|||
{ |
|||
int regionCode = 0; |
|||
string strLatLng = lat + "," + lng; |
|||
string url = |
|||
string.Format( |
|||
"http://api.map.baidu.com/geocoder/v2/?location={0}&latest_admin=1&output=json&pois=1&ak={1}", |
|||
strLatLng, ak); |
|||
string apiText = HttpGet(url, timeout); |
|||
JObject jsonObj = JObject.Parse(apiText); |
|||
if ((int)(jsonObj["status"]) == 0)//成功返回0
|
|||
{ |
|||
regionCode = Convert.ToInt32(jsonObj["result"]["addressComponent"]["adcode"]); |
|||
} |
|||
return regionCode; |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取路径规划路线
|
|||
/// </summary>
|
|||
/// <param name="startLongitude">起点经度</param>
|
|||
/// <param name="startLatitude">起点纬度</param>
|
|||
/// <param name="endLongitude">终点经度</param>
|
|||
/// <param name="endLatitude">终点纬度</param>
|
|||
/// <param name="timeout">超时时间默认10秒</param>
|
|||
/// <returns>失败返回"" </returns>
|
|||
public static List<PointLatLng> GetRouteList(decimal startLongitude, decimal startLatitude, decimal endLongitude, decimal endLatitude, int timeout = 10000) |
|||
{ |
|||
try |
|||
{ |
|||
string origin = startLongitude + "," + startLatitude; |
|||
|
|||
string destination = endLongitude + "," + endLatitude; |
|||
|
|||
PathPlanning pathPlanning = GetPathPlanning(origin, destination); |
|||
|
|||
List<PointLatLng> list = new List<PointLatLng>(); |
|||
|
|||
if (Convert.ToInt32(pathPlanning.Status) == 1) |
|||
{ |
|||
Model.Path path = pathPlanning.Routes.Paths.FirstOrDefault(); |
|||
if (path != null) |
|||
{ |
|||
string[] lineList = string.Join(";", path.Steps.Select(x => x.Polyline)).Split(';'); |
|||
|
|||
list.AddRange( |
|||
lineList.Select( |
|||
x => |
|||
new PointLatLng |
|||
(Convert.ToDouble(x.Split(',')[1]), Convert.ToDouble(x.Split(',')[0])))); |
|||
} |
|||
return list; |
|||
} |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return new List<PointLatLng>(); |
|||
} |
|||
|
|||
return new List<PointLatLng>(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据起点终点经纬度获取路径规划(步行)(高德)
|
|||
/// </summary>
|
|||
/// <param name="destination">终点经纬度</param>
|
|||
/// <param name="timeout">超时时间默认10秒</param>
|
|||
/// <param name="origin">起点经纬度</param>
|
|||
/// <returns>失败返回"" </returns>
|
|||
public static PathPlanning GetPathPlanning(string origin, string destination, int timeout = 10000) |
|||
{ |
|||
try |
|||
{ |
|||
string url = |
|||
string.Format("https://restapi.amap.com/v3/direction/walking?key={0}&origin={1}&destination={2}", |
|||
key, origin, destination); |
|||
|
|||
string apiText = HttpGet(url, timeout); |
|||
return JObject.Parse(apiText).ToObject<PathPlanning>(); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return new PathPlanning(); |
|||
} |
|||
} |
|||
|
|||
public static string HttpGet(string url, int timeout) |
|||
{ |
|||
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; |
|||
req.ContentType = "multipart/form-data"; |
|||
req.Accept = "*/*"; |
|||
req.UserAgent = ""; |
|||
req.Timeout = timeout; |
|||
req.Method = "GET"; |
|||
req.KeepAlive = true; |
|||
HttpWebResponse response = req.GetResponse() as HttpWebResponse; |
|||
string apiText = ""; |
|||
using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) |
|||
{ |
|||
apiText = sr.ReadToEnd(); |
|||
} |
|||
return apiText; |
|||
} |
|||
|
|||
|
|||
|
|||
public static GDPointLatLng Gps84ToGD(double lat,double lng, int timeout = 10000) |
|||
{ |
|||
try |
|||
{ |
|||
string url = |
|||
string.Format("https://restapi.amap.com/v3/assistant/coordinate/convert?key=82c0ac5c67dc9b13a3bb5b8fd4813996&locations={0}&coordsys=gps", |
|||
lng + "," + lat); |
|||
string apiText = HttpGet(url,timeout); |
|||
return JObject.Parse(apiText).ToObject<GDPointLatLng>(); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return new GDPointLatLng() ; |
|||
} |
|||
} |
|||
|
|||
public static GpsModels.BaseStationModel GetBaseStation(int mcc, int mnc, long lac, long cellid) |
|||
{ |
|||
try |
|||
{ |
|||
string url = |
|||
string.Format("http://apilocate.amap.com/position?accesstype=0&cdma=0&bts={0},{1},{2},{3},50&output=json&key={4}", |
|||
mcc, mnc, lac, cellid, key); |
|||
string apiText = HttpGet(url, 10000); |
|||
return JObject.Parse(apiText).ToObject<GpsModels.BaseStationModel>(); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return new GpsModels.BaseStationModel(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,54 @@ |
|||
// ==============================================================================
|
|||
//
|
|||
// RealDimensions Software, LLC - Copyright © 2012 - Present - Released under the Apache 2.0 License
|
|||
//
|
|||
// Copyright 2007-2008 The Apache Software Foundation.
|
|||
//
|
|||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|||
// this file except in compliance with the License. You may obtain a copy of the
|
|||
// License at
|
|||
//
|
|||
// http://www.apache.org/licenses/LICENSE-2.0
|
|||
//
|
|||
// Unless required by applicable law or agreed to in writing, software distributed
|
|||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|||
// specific language governing permissions and limitations under the License.
|
|||
// ==============================================================================
|
|||
using System.Collections.Concurrent; |
|||
using System.ComponentModel; |
|||
using log4net; |
|||
using log4net.Core; |
|||
namespace GPSBusiness |
|||
{ |
|||
/// <summary>
|
|||
/// Extensions to help make logging awesome - this should be installed into the root namespace of your application
|
|||
/// </summary>
|
|||
public static class LogExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the logger for <see cref="T"/>.
|
|||
/// </summary>
|
|||
/// <typeparam name="T"></typeparam>
|
|||
/// <param name="type">The type to get the logger for.</param>
|
|||
/// <returns>Instance of a logger for the object.</returns>
|
|||
public static ILog Log<T>(this T type) |
|||
{ |
|||
//string objectName = typeof(T).FullName;
|
|||
return LogManager.GetLogger(typeof(T)); |
|||
} |
|||
/// <summary>
|
|||
/// Gets the logger for the specified object name.
|
|||
/// </summary>
|
|||
/// <param name="objectName">Either use the fully qualified object name or the short. If used with Log<T>() you must use the fully qualified object name"/></param>
|
|||
/// <returns>Instance of a logger for the object.</returns>
|
|||
//public static ILog Log(this string objectName)
|
|||
//{
|
|||
// return _dictionary.GetOrAdd(objectName, LoggingExtensions.Logging.Log.GetLoggerFor);
|
|||
//}
|
|||
public static ILog Log(this string objectName) |
|||
{ |
|||
return LogManager.GetLogger(objectName); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Model |
|||
{ |
|||
public class GDPointLatLng |
|||
{ |
|||
public string status { get; set; } |
|||
public string info { get; set; } |
|||
public string infocode { get; set; } |
|||
public string locations { get; set; } = "0,0"; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Model |
|||
{ |
|||
public class LocationModel |
|||
{ |
|||
public LocationModel() |
|||
{ |
|||
} |
|||
|
|||
public LocationModel(decimal longitude, decimal latitude) |
|||
{ |
|||
Latitude = latitude; |
|||
Longitude = longitude; |
|||
} |
|||
|
|||
public decimal Latitude { get; set; } |
|||
public decimal Longitude { get; set; } |
|||
|
|||
public string LngLatStr => Longitude + "," + Latitude; |
|||
} |
|||
} |
@ -0,0 +1,84 @@ |
|||
using Newtonsoft.Json; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Model |
|||
{ |
|||
public class MapLocation |
|||
{ |
|||
[JsonProperty("status")] |
|||
public object Status { get; set; } |
|||
|
|||
[JsonProperty("info")] |
|||
public object Info { get; set; } |
|||
|
|||
[JsonProperty("infocode")] |
|||
public object Infocode { get; set; } |
|||
|
|||
[JsonProperty("regeocodes")] |
|||
public List<Regeocode> Regeocodes { get; set; } |
|||
|
|||
[JsonProperty("regeocode")] |
|||
public Regeocode Regeocode { get; set; } |
|||
} |
|||
|
|||
public class Regeocode |
|||
{ |
|||
[JsonProperty("formatted_address")] |
|||
public object FormattedAddress { get; set; } |
|||
|
|||
[JsonProperty("addressComponent")] |
|||
public AddressComponent AddressComponent { get; set; } |
|||
} |
|||
|
|||
public class AddressComponent |
|||
{ |
|||
[JsonProperty("country")] |
|||
public object Country { get; set; } |
|||
|
|||
[JsonProperty("province")] |
|||
public object Province { get; set; } |
|||
|
|||
[JsonProperty("city")] |
|||
public object City { get; set; } |
|||
|
|||
[JsonProperty("citycode")] |
|||
public object Citycode { get; set; } |
|||
|
|||
[JsonProperty("district")] |
|||
public object District { get; set; } |
|||
|
|||
[JsonProperty("adcode")] |
|||
public object Adcode { get; set; } |
|||
|
|||
[JsonProperty("township")] |
|||
public object Township { get; set; } |
|||
|
|||
[JsonProperty("townCode")] |
|||
public object TownCode { get; set; } |
|||
|
|||
[JsonProperty("streetNumber")] |
|||
public StreetNumber StreetNumber { get; set; } |
|||
} |
|||
|
|||
public class StreetNumber |
|||
{ |
|||
[JsonProperty("street")] |
|||
public object Street { get; set; } |
|||
|
|||
[JsonProperty("number")] |
|||
public object Number { get; set; } |
|||
|
|||
[JsonProperty("location")] |
|||
public object Location { get; set; } |
|||
|
|||
[JsonProperty("direction")] |
|||
public object Direction { get; set; } |
|||
|
|||
[JsonProperty("distance")] |
|||
public object Distance { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,124 @@ |
|||
using Newtonsoft.Json; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Model |
|||
{ |
|||
/// <summary>
|
|||
/// 路径规划实体
|
|||
/// </summary>
|
|||
public class PathPlanning |
|||
{ |
|||
/// <summary>
|
|||
/// 返回状态
|
|||
/// 值为0或1 1:成功;0:失败
|
|||
/// </summary>
|
|||
[JsonProperty("status")] |
|||
public object Status { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 返回的状态信息
|
|||
/// status为0时,info返回错误原;否则返回“OK”。详情参阅info状态表
|
|||
/// </summary>
|
|||
[JsonProperty("info")] |
|||
public object Info { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 返回结果总数目
|
|||
/// </summary>
|
|||
[JsonProperty("count")] |
|||
public object Count { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 路线信息列表
|
|||
/// </summary>
|
|||
[JsonProperty("route")] |
|||
public Route Routes { get; set; } |
|||
} |
|||
|
|||
public class Route |
|||
{ |
|||
/// <summary>
|
|||
/// 起点坐标
|
|||
/// </summary>
|
|||
[JsonProperty("origin")] |
|||
public object Origin { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 终点坐标
|
|||
/// </summary>
|
|||
[JsonProperty("destination")] |
|||
public object Destination { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 步行方案
|
|||
/// </summary>
|
|||
[JsonProperty("paths")] |
|||
public List<Path> Paths { get; set; } |
|||
} |
|||
|
|||
public class Path |
|||
{ |
|||
/// <summary>
|
|||
/// 起点和终点的步行距离
|
|||
/// 单位:米
|
|||
/// </summary>
|
|||
[JsonProperty("distance")] |
|||
public object Distance { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 步行时间预计
|
|||
/// 单位:秒
|
|||
/// </summary>
|
|||
[JsonProperty("duration")] |
|||
public object Duration { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 返回步行结果列表
|
|||
/// </summary>
|
|||
[JsonProperty("steps")] |
|||
public List<Step> Steps { get; set; } |
|||
} |
|||
|
|||
public class Step |
|||
{ |
|||
/// <summary>
|
|||
/// 每段步行方案
|
|||
/// </summary>
|
|||
[JsonProperty("instruction")] |
|||
public object Instruction { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 方向
|
|||
/// </summary>
|
|||
[JsonProperty("orientation")] |
|||
public object Orientation { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 道路名称
|
|||
/// </summary>
|
|||
[JsonProperty("road")] |
|||
public object Road { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 此路段距离
|
|||
/// </summary>
|
|||
[JsonProperty("distance")] |
|||
public object Distance { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 此路段预计步行时间
|
|||
/// </summary>
|
|||
[JsonProperty("duration")] |
|||
public object Duration { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 此路段坐标点
|
|||
/// </summary>
|
|||
[JsonProperty("polyline")] |
|||
public object Polyline { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Model |
|||
{ |
|||
public class PointLatLng |
|||
{ |
|||
public PointLatLng() |
|||
{ |
|||
} |
|||
|
|||
public PointLatLng(double lat, double lng) |
|||
{ |
|||
Lat = lat; |
|||
Lng = lng; |
|||
} |
|||
|
|||
public double Lat { get; set; } |
|||
public double Lng { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,129 @@ |
|||
using Newtonsoft.Json; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GPSBusiness.Model |
|||
{ |
|||
public class TXMapLocation |
|||
{ |
|||
/// <summary>
|
|||
/// 状态码,0为正常,其它为异常
|
|||
/// </summary>
|
|||
[JsonProperty("status")] |
|||
public int Status { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 状态说明
|
|||
/// </summary>
|
|||
[JsonProperty("message")] |
|||
public string Message { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 本次请求的唯一标识
|
|||
/// </summary>
|
|||
[JsonProperty("request_id")] |
|||
public string Request_Id { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 解析结果
|
|||
/// </summary>
|
|||
[JsonProperty("data")] |
|||
public List<Data> Data { get; set; } |
|||
} |
|||
|
|||
public class Data |
|||
{ |
|||
|
|||
/// <summary>
|
|||
/// 以行政区划+道路+门牌号等信息组成的标准格式化地址
|
|||
/// </summary>
|
|||
[JsonProperty("id")] |
|||
public string Id { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 以行政区划+道路+门牌号等信息组成的标准格式化地址
|
|||
/// </summary>
|
|||
[JsonProperty("address")] |
|||
public string Address { get; set; } |
|||
|
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 以行政区划+道路+门牌号等信息组成的标准格式化地址
|
|||
/// </summary>
|
|||
[JsonProperty("category")] |
|||
public string category { get; set; } |
|||
|
|||
///// <summary>
|
|||
///// 结合知名地点形成的描述性地址,更具人性化特点
|
|||
///// </summary>
|
|||
//[JsonProperty("formatted_addresses")]
|
|||
//public Formatted_Addresses Formatted_Addresses { get; set; }
|
|||
|
|||
///// <summary>
|
|||
///// 地址部件,address不满足需求时可自行拼接
|
|||
///// </summary>
|
|||
//[JsonProperty("address_component")]
|
|||
//public Address_Component Address_Component { get; set; }
|
|||
} |
|||
|
|||
public class Formatted_Addresses |
|||
{ |
|||
/// <summary>
|
|||
/// 地址描述
|
|||
/// </summary>
|
|||
[JsonProperty("recommend")] |
|||
public string Recommend { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 粗略位置描述
|
|||
/// </summary>
|
|||
[JsonProperty("rough")] |
|||
public string Rough { get; set; } |
|||
} |
|||
|
|||
|
|||
public class Address_Component |
|||
{ |
|||
/// <summary>
|
|||
/// 国家
|
|||
/// </summary>
|
|||
[JsonProperty(" nation")] |
|||
public string Nation { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 省
|
|||
/// </summary>
|
|||
[JsonProperty("province")] |
|||
public string Province { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 市
|
|||
/// </summary>
|
|||
[JsonProperty("city")] |
|||
public string City { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 区,可能为空字串
|
|||
/// </summary>
|
|||
[JsonProperty("district")] |
|||
public string District { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 街道,可能为空字串
|
|||
/// </summary>
|
|||
[JsonProperty("street")] |
|||
public string Street { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 门牌,可能为空字串
|
|||
/// </summary>
|
|||
[JsonProperty("street_number")] |
|||
public string Street_Number { get; set; } |
|||
} |
|||
|
|||
} |
@ -0,0 +1,203 @@ |
|||
using GpsModels; |
|||
using log4net; |
|||
using System; |
|||
using System.Data; |
|||
using System.Data.SqlClient; |
|||
using GPSBusiness.Sql; |
|||
using GPSServer.Helper; |
|||
|
|||
namespace GPSBusiness |
|||
{ |
|||
public class MyGpsServer |
|||
{ |
|||
public static ILog Log = LogManager.GetLogger(""); |
|||
|
|||
//请查看Mongo的GpsRealTImeRepository
|
|||
///// <summary>
|
|||
///// 更新Gps实时数据
|
|||
///// </summary>
|
|||
//public static void UpdateGpsRealTime(GpsModel model)
|
|||
//{
|
|||
// try
|
|||
// {
|
|||
// Log.InfoFormat(
|
|||
// "UpdateGpsRealTime:VehicleId={0},GpsTime={1},RecTime={2},Longitude={3},Latitude={4},Direct={5},Speed={6},Acc={7},ModifiedTime={8}",
|
|||
// model.VehicleId, model.GpsTime, model.RecTime, model.Longitude, model.Latitude, model.Direct, model.Speed, model.Acc, DateTime.Now);
|
|||
// string sql = @"UpdateGpsRealTime";
|
|||
// SqlParameter[] parameters =
|
|||
// {
|
|||
// new SqlParameter("@VehicleId", SqlDbType.Int),
|
|||
// new SqlParameter("@GpsTime", SqlDbType.DateTime),
|
|||
// new SqlParameter("@RecTime",SqlDbType.DateTime),
|
|||
// new SqlParameter("@Longitude", SqlDbType.Decimal, 18),
|
|||
// new SqlParameter("@Latitude", SqlDbType.Decimal, 18),
|
|||
// new SqlParameter("@Direct", SqlDbType.Int),
|
|||
// new SqlParameter("@Speed", SqlDbType.Int),
|
|||
// new SqlParameter("@Acc", SqlDbType.Int),
|
|||
// new SqlParameter("@Address",SqlDbType.VarChar, 200),
|
|||
// new SqlParameter("@ModifiedTime", SqlDbType.DateTime),
|
|||
// };
|
|||
// parameters[0].Value = model.VehicleId;
|
|||
// parameters[1].Value = model.GpsTime;
|
|||
// parameters[2].Value = model.RecTime;
|
|||
// parameters[3].Value = model.Longitude;
|
|||
// parameters[4].Value = model.Latitude;
|
|||
// parameters[5].Value = model.Direct;
|
|||
// parameters[6].Value = model.Speed;
|
|||
// parameters[7].Value = model.Acc;
|
|||
// parameters[8].Value = model.Address ?? "";
|
|||
// parameters[9].Value = DateTime.Now;
|
|||
// SqlHelp.ExecSPCommand(sql, parameters);
|
|||
// }
|
|||
// catch (Exception ex)
|
|||
// {
|
|||
// Log.ErrorFormat("UpdateGpsRealTime=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}",
|
|||
// ex.Message, ex.InnerException, ex.StackTrace);
|
|||
// }
|
|||
//}
|
|||
|
|||
///// <summary>
|
|||
///// 更新车辆gps状态:
|
|||
///// </summary>
|
|||
//public static void UpdateGpsRealTimeGpsState(VehicleModel vehicle, int gpsState, string durationTime, string AccDurationTime)
|
|||
//{
|
|||
// try
|
|||
// {
|
|||
// Log.InfoFormat(
|
|||
// "UpdateGpsRealTimeGpsState:VehicleId={0},GpsState={1},DurationTime={2},AccDurationTime={3}",
|
|||
// vehicle.VehicleId, gpsState, durationTime, AccDurationTime);
|
|||
// string sql = @"UpdateGpsRealTimeState";
|
|||
// SqlParameter[] parameters =
|
|||
// {
|
|||
// new SqlParameter("@VehicleId", SqlDbType.Int),
|
|||
// new SqlParameter("@GpsState", SqlDbType.Int),
|
|||
// new SqlParameter("@DurationTime",SqlDbType.VarChar, 20),
|
|||
// new SqlParameter("@AccDurationTime",SqlDbType.VarChar, 20),
|
|||
// new SqlParameter("@ModifiedTime", SqlDbType.DateTime),
|
|||
// };
|
|||
// parameters[0].Value = vehicle.VehicleId;
|
|||
// parameters[1].Value = gpsState;
|
|||
// parameters[2].Value = durationTime;
|
|||
// parameters[3].Value = AccDurationTime;
|
|||
// parameters[4].Value = DateTime.Now;
|
|||
// SqlHelp.ExecSPCommand(sql, parameters);
|
|||
// }
|
|||
// catch (Exception ex)
|
|||
// {
|
|||
// Log.ErrorFormat(
|
|||
// "UpdateGpsRealTimeGpsState=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}",
|
|||
// ex.Message, ex.InnerException, ex.StackTrace);
|
|||
// }
|
|||
//}
|
|||
|
|||
///// <summary>
|
|||
///// 更新车辆gps状态,沃瑞特在线车辆。此更新,只在沃瑞特心跳时进行更新。
|
|||
///// </summary>
|
|||
//public static void UpdateGpsRealTimeGpsStateWrt(GpsModel gpsModel)
|
|||
//{
|
|||
// try
|
|||
// {
|
|||
// var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|||
// Log.InfoFormat(
|
|||
// "UpdateGpsRealTimeGpsStateWrt:VehicleId={0},GpsState={1},GpsTime、RecTime、ModifiedTime={2},DurationTime={3},AccDurationTime={5}",
|
|||
// gpsModel.VehicleId, gpsModel.GpsState, time, gpsModel.DurationTime, gpsModel.AccDurationTime);
|
|||
// string sql = @"UpdateGpsRealTimeStateWrt";
|
|||
// SqlParameter[] parameters =
|
|||
// {
|
|||
// new SqlParameter("@VehicleId", SqlDbType.Int),
|
|||
// new SqlParameter("@GpsState", SqlDbType.Int),
|
|||
// new SqlParameter("@GpsTime",SqlDbType.DateTime),
|
|||
// new SqlParameter("@RecTime",SqlDbType.DateTime),
|
|||
// new SqlParameter("@DurationTime",SqlDbType.VarChar, 20),
|
|||
// new SqlParameter("@AccDurationTime",SqlDbType.VarChar, 20),
|
|||
// new SqlParameter("@ModifiedTime", SqlDbType.DateTime),
|
|||
// };
|
|||
// parameters[0].Value = gpsModel.VehicleId;
|
|||
// parameters[1].Value = gpsModel.GpsState;
|
|||
// parameters[2].Value = time;
|
|||
// parameters[3].Value = time;
|
|||
// parameters[4].Value = gpsModel.DurationTime ?? "";
|
|||
// parameters[5].Value = gpsModel.AccDurationTime ?? "";
|
|||
// parameters[6].Value = time;
|
|||
// SqlHelp.ExecSPCommand(sql, parameters);
|
|||
// }
|
|||
// catch (Exception ex)
|
|||
// {
|
|||
// Log.ErrorFormat(
|
|||
// "UpdateGpsRealTimeGpsStateWrt=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}",
|
|||
// ex.Message, ex.InnerException, ex.StackTrace);
|
|||
// }
|
|||
//}
|
|||
|
|||
/// <summary>
|
|||
/// 更新订单状态:
|
|||
/// </summary>
|
|||
public static void UpdateOrderState(long orderId, int state, DateTime time) |
|||
{ |
|||
try |
|||
{ |
|||
Log.InfoFormat("UpdateOrderState:Id={0},State={1},Time={2:yyyy-MM-dd HH:mm:ss}", |
|||
orderId, state, time); |
|||
string sql = @"UpdateOrderState"; |
|||
SqlParameter[] parameters = |
|||
{ |
|||
new SqlParameter("@Id", SqlDbType.Int), |
|||
new SqlParameter("@State", SqlDbType.Int), |
|||
new SqlParameter("@Time",SqlDbType.DateTime), |
|||
}; |
|||
parameters[0].Value = orderId; |
|||
parameters[1].Value = state; |
|||
parameters[2].Value = time; |
|||
SqlHelp.ExecSPCommand(sql, parameters); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.ErrorFormat( |
|||
"UpdateOrderState=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
|
|||
///// <summary>
|
|||
///// 新增Acc持续时长记录
|
|||
///// </summary>
|
|||
//public static void AddGpsCarAccDuration(int carId, int companyId, string code, string vehicleName, int AccState, DateTime beginTime, DateTime endTime)
|
|||
//{
|
|||
// try
|
|||
// {
|
|||
// Log.InfoFormat("AddGpsCarAccDuration:VehicleId={0},CompanyId={1}",
|
|||
// carId, companyId);
|
|||
// var time = endTime - beginTime;
|
|||
// var AccDurationTime = CalculationGpsHelper.TimeSpanFormat(time);
|
|||
// string sql = @"AddGpsCarAccDuration";
|
|||
// SqlParameter[] parameters =
|
|||
// {
|
|||
// new SqlParameter("@VehicleId", SqlDbType.Int),
|
|||
// new SqlParameter("@CompanyId", SqlDbType.Int),
|
|||
// new SqlParameter("@Code",SqlDbType.VarChar, 20),
|
|||
// new SqlParameter("@VehicleName",SqlDbType.VarChar, 20),
|
|||
// new SqlParameter("@AccState",SqlDbType.Int),
|
|||
// new SqlParameter("@AccDurationTime",SqlDbType.VarChar, 20),
|
|||
// new SqlParameter("@TimeBegin",SqlDbType.DateTime),
|
|||
// new SqlParameter("@TimeEnd",SqlDbType.DateTime),
|
|||
// };
|
|||
// parameters[0].Value = carId;
|
|||
// parameters[1].Value = companyId;
|
|||
// parameters[2].Value = code;
|
|||
// parameters[3].Value = vehicleName;
|
|||
// parameters[4].Value = AccState;
|
|||
// parameters[5].Value = AccDurationTime;
|
|||
// parameters[6].Value = beginTime;
|
|||
// parameters[7].Value = endTime;
|
|||
// SqlHelp.ExecSPCommand(sql, parameters);
|
|||
|
|||
// }
|
|||
// catch (Exception ex)
|
|||
// {
|
|||
// Log.ErrorFormat(
|
|||
// "AddGpsCarAccDuration=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}",
|
|||
// ex.Message, ex.InnerException, ex.StackTrace);
|
|||
// }
|
|||
//}
|
|||
} |
|||
} |
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using System.Runtime.InteropServices; |
|||
namespace GPSBusiness |
|||
{ |
|||
[StructLayout(LayoutKind.Sequential)] |
|||
public class ClientInfo |
|||
{ |
|||
public IntPtr ConnId { get; set; } |
|||
public string IpAddress { get; set; } |
|||
public ushort Port { get; set; } |
|||
public PkgInfo PkgInfo { get; set; } |
|||
} |
|||
[StructLayout(LayoutKind.Sequential)] |
|||
public class PkgHeader |
|||
{ |
|||
public int Id; |
|||
public int BodySize; |
|||
} |
|||
[StructLayout(LayoutKind.Sequential)] |
|||
public class PkgInfo |
|||
{ |
|||
public bool IsHeader; |
|||
public int Length; |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
// 有关程序集的常规信息通过以下
|
|||
// 特性集控制。更改这些特性值可修改
|
|||
// 与程序集关联的信息。
|
|||
[assembly: AssemblyTitle("GPSBusiness")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("Microsoft")] |
|||
[assembly: AssemblyProduct("GPSBusiness")] |
|||
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
|||
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
|
|||
// 则将该类型上的 ComVisible 特性设置为 true。
|
|||
[assembly: ComVisible(false)] |
|||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
|||
[assembly: Guid("7ba5987d-4a46-4fdc-9522-fab54964d80f")] |
|||
// 程序集的版本信息由下面四个值组成:
|
|||
//
|
|||
// 主版本
|
|||
// 次版本
|
|||
// 生成号
|
|||
// 修订号
|
|||
//
|
|||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
|||
// 方法是按如下所示使用“*”:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "./log4net.config", ConfigFileExtension = "config", Watch = true)] |
@ -0,0 +1,34 @@ |
|||
namespace GPSBusiness.Redis |
|||
{ |
|||
public class RedisContext |
|||
{ |
|||
private static RedisHelper _server; |
|||
|
|||
public static RedisHelper Server |
|||
{ |
|||
get |
|||
{ |
|||
if (_server == null) |
|||
{ |
|||
return _server = new RedisHelper(); |
|||
} |
|||
return _server; |
|||
} |
|||
} |
|||
//private static RedisHelper _datasServer;
|
|||
|
|||
//public static RedisHelper DatasServer
|
|||
//{
|
|||
// get
|
|||
// {
|
|||
// if (_datasServer == null)
|
|||
// {
|
|||
// var connectionString = ConfigurationManager.ConnectionStrings["RedisConnectionString"].ConnectionString;
|
|||
// var redisAnalysisDb = int.Parse(ConfigurationManager.AppSettings["RedisAnalysisDb"]);
|
|||
// return _datasServer = new RedisHelper(connectionString, redisAnalysisDb);
|
|||
// }
|
|||
// return _datasServer;
|
|||
// }
|
|||
//}
|
|||
} |
|||
} |
@ -0,0 +1,254 @@ |
|||
using System; |
|||
using System.Configuration; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Newtonsoft.Json; |
|||
using StackExchange.Redis; |
|||
|
|||
namespace GPSBusiness.Redis |
|||
{ |
|||
/// <summary>
|
|||
/// Redis 操作类
|
|||
/// </summary>
|
|||
public class RedisHelper : IDisposable |
|||
{ |
|||
/// <summary>
|
|||
/// 连接字符串
|
|||
/// </summary>
|
|||
private static readonly string ConnectionString = ConfigurationManager.AppSettings["RedisConnectionString"]; |
|||
private static readonly int RedisAnalysisDb = int.Parse(ConfigurationManager.AppSettings["RedisAnalysisDb"]); |
|||
|
|||
/// <summary>
|
|||
/// 锁
|
|||
/// </summary>
|
|||
private readonly object _lock = new object(); |
|||
/// <summary>
|
|||
/// 连接对象
|
|||
/// </summary>
|
|||
private volatile IConnectionMultiplexer _connection; |
|||
/// <summary>
|
|||
/// 数据库
|
|||
/// </summary>
|
|||
private readonly IDatabase _db; |
|||
public RedisHelper() |
|||
{ |
|||
_connection = |
|||
ConnectionMultiplexer.Connect(string.Format( |
|||
"{0},allowAdmin=true,syncTimeout=60000,connectTimeout=30000", ConnectionString)); |
|||
_db = GetDatabase(RedisAnalysisDb); |
|||
} |
|||
public RedisHelper(string connectStr,int dataDb) |
|||
{ |
|||
_connection = |
|||
ConnectionMultiplexer.Connect(string.Format( |
|||
"{0},allowAdmin=true,syncTimeout=60000,connectTimeout=60000", connectStr)); |
|||
_db = GetDatabase(dataDb); |
|||
} |
|||
/// <summary>
|
|||
/// 获取连接
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
protected IConnectionMultiplexer GetConnection() |
|||
{ |
|||
if (_connection != null && _connection.IsConnected) |
|||
{ |
|||
return _connection; |
|||
} |
|||
lock (_lock) |
|||
{ |
|||
if (_connection != null && _connection.IsConnected) |
|||
{ |
|||
return _connection; |
|||
} |
|||
|
|||
if (_connection != null) |
|||
{ |
|||
_connection.Dispose(); |
|||
} |
|||
_connection = ConnectionMultiplexer.Connect(ConnectionString); |
|||
} |
|||
|
|||
return _connection; |
|||
} |
|||
/// <summary>
|
|||
/// 获取数据库
|
|||
/// </summary>
|
|||
/// <param name="db"></param>
|
|||
/// <returns></returns>
|
|||
public IDatabase GetDatabase(int? db = null) |
|||
{ |
|||
return GetConnection().GetDatabase(db ?? -1); |
|||
} |
|||
/// <summary>
|
|||
/// 设置
|
|||
/// </summary>
|
|||
/// <param name="key">键</param>
|
|||
/// <param name="data">值</param>
|
|||
/// <param name="cacheTime">时间-分钟</param>
|
|||
public virtual void SetOfBytes(string key, object data, int cacheTime) |
|||
{ |
|||
if (data == null) |
|||
{ |
|||
return; |
|||
} |
|||
var entryBytes = SerializeToBytes(data); |
|||
TimeSpan? expiresIn = null; |
|||
if(cacheTime != -1) |
|||
expiresIn = TimeSpan.FromMinutes(cacheTime); |
|||
|
|||
_db.StringSet(key, entryBytes, expiresIn); |
|||
} |
|||
/// <summary>
|
|||
/// 设置
|
|||
/// </summary>
|
|||
/// <param name="key">键</param>
|
|||
/// <param name="data">值</param>
|
|||
/// <param name="cacheTime">时间-分钟</param>
|
|||
public virtual void SetOfJson(string key, object data, int cacheTime) |
|||
{ |
|||
if (data == null) return; |
|||
var serializedValue = SerializeToJson(data); |
|||
TimeSpan? expiresIn = null; |
|||
if(cacheTime != -1) |
|||
expiresIn = TimeSpan.FromMinutes(cacheTime); |
|||
|
|||
_db.StringSet(key, serializedValue, expiresIn); |
|||
} |
|||
/// <summary>
|
|||
/// 根据键获取值
|
|||
/// </summary>
|
|||
/// <typeparam name="T"></typeparam>
|
|||
/// <param name="key"></param>
|
|||
/// <returns></returns>
|
|||
public virtual T GetFromBytes<T>(string key) |
|||
{ |
|||
var rValue = _db.StringGet(key); |
|||
if (!rValue.HasValue) |
|||
{ |
|||
return default(T); |
|||
} |
|||
|
|||
var result = DeserializeBytes<T>(rValue); |
|||
|
|||
return result; |
|||
} |
|||
/// <summary>
|
|||
/// 根据键获取值
|
|||
/// </summary>
|
|||
/// <typeparam name="T"></typeparam>
|
|||
/// <param name="key"></param>
|
|||
/// <returns></returns>
|
|||
public virtual T GetFromJson<T>(string key) |
|||
{ |
|||
var rValue = _db.StringGet(key); |
|||
if (!rValue.HasValue) |
|||
{ |
|||
return default(T); |
|||
} |
|||
|
|||
var result = DeserializeJson<T>(rValue); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根据键获取值
|
|||
/// </summary>
|
|||
/// <typeparam name="T"></typeparam>
|
|||
/// <param name="key"></param>
|
|||
/// <returns></returns>
|
|||
public virtual async Task<T> GetFromJsonAsync<T>(string key) |
|||
{ |
|||
var rValue =await _db.StringGetAsync(key); |
|||
if (!rValue.HasValue) |
|||
{ |
|||
return default(T); |
|||
} |
|||
|
|||
var result = DeserializeJson<T>(rValue); |
|||
|
|||
return result; |
|||
} |
|||
/// <summary>
|
|||
/// 序列化
|
|||
/// </summary>
|
|||
/// <param name="data"></param>
|
|||
/// <returns>byte[]</returns>
|
|||
private byte[] SerializeToBytes(object data) |
|||
{ |
|||
var json = JsonConvert.SerializeObject(data); |
|||
return Encoding.UTF8.GetBytes(json); |
|||
} |
|||
/// <summary>
|
|||
/// 序列化
|
|||
/// </summary>
|
|||
/// <param name="data"></param>
|
|||
/// <returns>byte[]</returns>
|
|||
private string SerializeToJson(object data) |
|||
{ |
|||
return JsonConvert.SerializeObject(data); |
|||
} |
|||
/// <summary>
|
|||
/// 反序列化
|
|||
/// </summary>
|
|||
/// <typeparam name="T"></typeparam>
|
|||
/// <param name="serializedObject"></param>
|
|||
/// <returns></returns>
|
|||
protected virtual T DeserializeBytes<T>(byte[] serializedObject) |
|||
{ |
|||
if (serializedObject == null) |
|||
{ |
|||
return default(T); |
|||
} |
|||
var json = Encoding.UTF8.GetString(serializedObject); |
|||
return JsonConvert.DeserializeObject<T>(json); |
|||
} |
|||
/// <summary>
|
|||
/// 反序列化
|
|||
/// </summary>
|
|||
/// <typeparam name="T"></typeparam>
|
|||
/// <param name="serializedObject"></param>
|
|||
/// <returns></returns>
|
|||
protected virtual T DeserializeJson<T>(string serializedObject) |
|||
{ |
|||
if (serializedObject == null) |
|||
{ |
|||
return default(T); |
|||
} |
|||
return JsonConvert.DeserializeObject<T>(serializedObject); |
|||
} |
|||
/// <summary>
|
|||
/// 判断是否已经设置
|
|||
/// </summary>
|
|||
/// <param name="key"></param>
|
|||
/// <returns></returns>
|
|||
public virtual bool IsSet(string key) |
|||
{ |
|||
return _db.KeyExists(key); |
|||
} |
|||
/// <summary>
|
|||
/// 根据key删除
|
|||
/// </summary>
|
|||
/// <param name="key"></param>
|
|||
/// <returns></returns>
|
|||
public virtual bool Remove(string key) |
|||
{ |
|||
return _db.KeyDelete(key); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 自增
|
|||
/// </summary>
|
|||
/// <param name="key"></param>
|
|||
/// <returns></returns>
|
|||
public virtual long StringIncrement(string key) |
|||
{ |
|||
return _db.StringIncrement(key); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,244 @@ |
|||
using System; |
|||
using GPSBusiness.Enum; |
|||
using GpsModels; |
|||
using log4net; |
|||
|
|||
namespace GPSBusiness.Redis |
|||
{ |
|||
public static class RedisRepository |
|||
{ |
|||
public static ILog Log = LogManager.GetLogger(""); |
|||
|
|||
#region 车辆最后存在速度的GPS时间
|
|||
/// <summary>
|
|||
/// 更新车辆最后存在速度的GPS时间
|
|||
/// </summary>
|
|||
public static void SetLastHaveSpeed(GpsModel model) |
|||
{ |
|||
if (model.CompanyId == 0) return; |
|||
if (model.VehicleId == 0) return; |
|||
var cmpId = model.CompanyId; |
|||
var key = "LastHaveSpeed" + "_" + cmpId + "_" + model.VehicleId; |
|||
try |
|||
{ |
|||
RedisContext.Server.SetOfJson(key, model, -1); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
var aa = 0; |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取车辆最后存在速度的GPS时间
|
|||
/// </summary>
|
|||
public static GpsModel GetLastHaveSpeed(GpsModel model) |
|||
{ |
|||
try |
|||
{ |
|||
if (model.CompanyId == 0) return null; |
|||
if (model.VehicleId == 0) return null; |
|||
var cmpId = model.CompanyId; |
|||
var key = "LastHaveSpeed" + "_" + cmpId + "_" + model.VehicleId; |
|||
return RedisContext.Server.GetFromJson<GpsModel>(key); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.ErrorFormat("GetLastHaveSpeed=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", ex.Message, ex.InnerException, ex.StackTrace); |
|||
throw; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 是否已设置车辆最后存在速度的GPS时间
|
|||
/// </summary>
|
|||
public static bool IsSetLastHaveSpeed(GpsModel model) |
|||
{ |
|||
if (model.CompanyId == 0) return false; |
|||
if (model.VehicleId == 0) return false; |
|||
var cmpId = model.CompanyId; |
|||
var key = "LastHaveSpeed" + "_" + cmpId + "_" + model.VehicleId; |
|||
return RedisContext.Server.IsSet(key); |
|||
} |
|||
#endregion
|
|||
|
|||
#region 车辆Acc/作业状态第一次开启的时间
|
|||
/// <summary>
|
|||
/// 更新Acc/作业状态第一次开启的时间
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <param name="type">1Acc,2Work</param>
|
|||
public static void SetFirstStatus(GpsModel model,int type) |
|||
{ |
|||
if (model.CompanyId == 0) return; |
|||
if (model.VehicleId == 0) return; |
|||
var cmpId = model.CompanyId; |
|||
var key = (type == (int)StatusEnum.Acc ? RedisPrefixEnum.FirstAcc : RedisPrefixEnum.FirstWork) + cmpId + "_" + model.VehicleId; |
|||
RedisContext.Server.SetOfJson(key, model, -1); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取Acc/作业状态第一次开启的时间
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <param name="type">1Acc,2Work</param>
|
|||
public static GpsModel GetFirstStatus(GpsModel model, int type) |
|||
{ |
|||
try |
|||
{ |
|||
if (model.CompanyId == 0) return null; |
|||
if (model.VehicleId == 0) return null; |
|||
var cmpId = model.CompanyId; |
|||
var key = (type == (int)StatusEnum.Acc ? RedisPrefixEnum.FirstAcc : RedisPrefixEnum.FirstWork) + cmpId + "_" + model.VehicleId; |
|||
return RedisContext.Server.GetFromJson<GpsModel>(key); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.ErrorFormat("GetLastHaveSpeed=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", ex.Message, ex.InnerException, ex.StackTrace); |
|||
throw; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 是否已设置Acc/作业状态第一次开启的时间
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <param name="type">1Acc,2Work</param>
|
|||
public static bool IsSetFirstStatus(GpsModel model, int type) |
|||
{ |
|||
if (model.CompanyId == 0) return false; |
|||
if (model.VehicleId == 0) return false; |
|||
var cmpId = model.CompanyId; |
|||
var key = (type == 1 ? RedisPrefixEnum.FirstAcc : RedisPrefixEnum.FirstWork) + cmpId + "_" + model.VehicleId; |
|||
return RedisContext.Server.IsSet(key); |
|||
} |
|||
#endregion
|
|||
|
|||
//#region 车辆最后GPS时间
|
|||
///// <summary>
|
|||
///// 更新车辆最后GPS时间
|
|||
///// </summary>
|
|||
//public static void SetLastGpsTime(GpsModel model)
|
|||
//{
|
|||
// if (model.CompanyId == 0) return;
|
|||
// if (model.VehicleId == 0) return;
|
|||
// var cmpId = 500000 + model.CompanyId;
|
|||
// var key = "LastGpsTime" + "_" + cmpId + "_" + model.VehicleId;
|
|||
// RedisContext.Server.SetOfJson(key, model, -1);
|
|||
//}
|
|||
|
|||
///// <summary>
|
|||
///// 获取车辆最后GPS时间
|
|||
///// </summary>
|
|||
//public static GpsModel GetLastGpsTime(GpsModel model)
|
|||
//{
|
|||
// try
|
|||
// {
|
|||
// if (model.CompanyId == 0) return null;
|
|||
// if (model.VehicleId == 0) return null;
|
|||
// var cmpId = 500000 + model.CompanyId;
|
|||
// var key = "LastGpsTime" + "_" + cmpId + "_" + model.VehicleId;
|
|||
// return RedisContext.Server.GetFromJson<GpsModel>(key);
|
|||
// }
|
|||
// catch (Exception ex)
|
|||
// {
|
|||
// Log.ErrorFormat("GetLastGpsTime=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", ex.Message, ex.InnerException, ex.StackTrace);
|
|||
// throw;
|
|||
// }
|
|||
//}
|
|||
///// <summary>
|
|||
///// 是否已设置车辆最后GPS时间
|
|||
///// </summary>
|
|||
//public static bool IsSetLastGpsTime(GpsModel model)
|
|||
//{
|
|||
// if (model.CompanyId == 0) return false;
|
|||
// if (model.VehicleId == 0) return false;
|
|||
// var cmpId = 500000 + model.CompanyId;
|
|||
// var key = "LastGpsTime" + "_" + cmpId + "_" + model.VehicleId;
|
|||
// return RedisContext.Server.IsSet(key);
|
|||
//}
|
|||
//#endregion
|
|||
|
|||
#region
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 更新车辆最后GPS时间
|
|||
/// </summary>
|
|||
public static void SetLastGpsTime(GpsModel model) |
|||
{ |
|||
if (model.VehicleId == 0) return; |
|||
var key = "LastGpsTime" + "_" + model.VehicleId; |
|||
RedisContext.Server.SetOfJson(key, model,1); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取车辆最后GPS时间
|
|||
/// </summary>
|
|||
public static GpsModel GetLastGpsTime(GpsModel model) |
|||
{ |
|||
try |
|||
{ |
|||
if (model.VehicleId == 0) return null; |
|||
var key = "LastGpsTime" + "_" + model.VehicleId; |
|||
return RedisContext.Server.GetFromJson<GpsModel>(key); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.ErrorFormat("GetLastGpsTime=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", ex.Message, ex.InnerException, ex.StackTrace); |
|||
throw; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 是否已设置车辆最后GPS时间
|
|||
/// </summary>
|
|||
public static bool IsSetLastGpsTime(GpsModel model) |
|||
{ |
|||
if (model.VehicleId == 0) return false; |
|||
var key = "LastGpsTime"+ "_" + model.VehicleId; |
|||
return RedisContext.Server.IsSet(key); |
|||
} |
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 自增车辆最后GPS时间
|
|||
/// </summary>
|
|||
public static long IncrementLastGpsTimeRepeatCount(GpsModel model) |
|||
{ |
|||
if (model.VehicleId == 0) return 0; |
|||
var key = "LastGpsTimeRepeatCount" + "_" + model.VehicleId; |
|||
return RedisContext.Server.StringIncrement(key); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新车辆最后GPS时间
|
|||
/// </summary>
|
|||
public static void SetLastGpsTimeRepeatCount(GpsModel model) |
|||
{ |
|||
if (model.VehicleId == 0) return; |
|||
var key = "LastGpsTimeRepeatCount" + "_" + model.VehicleId; |
|||
RedisContext.Server.SetOfJson(key,0,-1); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取车辆最后GPS时间
|
|||
/// </summary>
|
|||
public static long GetLastGpsTimeRepeatCount(GpsModel model) |
|||
{ |
|||
try |
|||
{ |
|||
if (model.VehicleId == 0) return 0; |
|||
var key = "LastGpsTimeRepeatCount" + "_" + model.VehicleId; |
|||
return RedisContext.Server.GetFromJson<long>(key); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.ErrorFormat("GetLastGpsTime=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", ex.Message, ex.InnerException, ex.StackTrace); |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
} |
|||
#endregion
|
|||
} |
|||
|
@ -0,0 +1,282 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Data.SqlClient; |
|||
using System.Linq; |
|||
using System.Configuration; |
|||
using log4net; |
|||
using System.ComponentModel; |
|||
using MySql.Data.MySqlClient; |
|||
|
|||
namespace GPSBusiness.Sql |
|||
{ |
|||
public class SqlHelp |
|||
{ |
|||
//"Data Source=数据库地址;Initial Catalog=数据库名称;Persist Security Info=True;User ID=帐号;Password=密码";
|
|||
public static string ConnectionString = ConfigurationManager.ConnectionStrings["ZNYCProjectGps"].ToString(); |
|||
//根据sql语句返回一个DataSet
|
|||
#region GetDataSet
|
|||
public static DataSet GetDataSet(string sql) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.Text, sql); |
|||
MySqlDataAdapter sda = new MySqlDataAdapter(); |
|||
sda.SelectCommand = sqlcom; |
|||
DataSet ds = new DataSet(); |
|||
sda.Fill(ds); |
|||
sqlcom.Parameters.Clear(); |
|||
return ds; |
|||
} |
|||
} |
|||
#endregion
|
|||
//根据sql语句返回一个MySqlDataAdapter
|
|||
#region ExecMySqlDataAdapter
|
|||
public static MySqlDataReader ExecMySqlDataAdapter(string sql) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
MySqlConnection conn = new MySqlConnection(ConnectionString); |
|||
try |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.Text, sql); |
|||
MySqlDataReader sdr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection); |
|||
sqlcom.Parameters.Clear(); |
|||
return sdr; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
conn.Close(); |
|||
throw ex; |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行sql语句,返回影响行数
|
|||
#region ExecCommand
|
|||
public static int ExecCommand(string sql) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.Text, sql); |
|||
int rtn = sqlcom.ExecuteNonQuery(); |
|||
sqlcom.Parameters.Clear(); |
|||
return rtn; |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行SQL语句,无返回值
|
|||
#region ExecNon
|
|||
public static void ExecNon(string sql) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.Text, sql); |
|||
sqlcom.ExecuteNonQuery(); |
|||
sqlcom.Parameters.Clear(); |
|||
} |
|||
} |
|||
#endregion
|
|||
//根据sql语句返回查询结果的第一行
|
|||
#region ExecuteScalar
|
|||
public static object ExecuteScalar(string sql) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.Text, sql); |
|||
object rtn = sqlcom.ExecuteScalar(); |
|||
sqlcom.Parameters.Clear(); |
|||
return rtn; |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行存储过程无返回值,SQL语句含有参数
|
|||
#region ExecSPCommand
|
|||
public static void ExecSPCommand(string sql, System.Data.IDataParameter[] paramers) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.StoredProcedure, sql); |
|||
foreach (System.Data.IDataParameter paramer in paramers) |
|||
{ |
|||
sqlcom.Parameters.Add(paramer); |
|||
} |
|||
sqlcom.ExecuteNonQuery(); |
|||
sqlcom.Parameters.Clear(); |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行存储过程无返回值,SQL语句不含有参数
|
|||
#region ExecSPCommand2
|
|||
public static void ExecSPCommand2(string sql) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.StoredProcedure, sql); |
|||
sqlcom.ExecuteNonQuery(); |
|||
sqlcom.Parameters.Clear(); |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行存储过程,返回MySqlDataAdapter,SQL语句含有参数
|
|||
#region ExecSPMySqlDataAdapter
|
|||
public static MySqlDataReader ExecSPMySqlDataAdapter(string sql, System.Data.IDataParameter[] paramers) |
|||
{ |
|||
MySqlConnection conn = new MySqlConnection(ConnectionString); |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
try |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.StoredProcedure, sql); |
|||
foreach (System.Data.IDataParameter paramer in paramers) |
|||
{ |
|||
sqlcom.Parameters.Add(paramer); |
|||
} |
|||
|
|||
MySqlDataReader sdr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection); |
|||
sqlcom.Parameters.Clear(); |
|||
return sdr; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
conn.Close(); |
|||
throw ex; |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行存储过程,SQL语句含有参数
|
|||
#region ExecSPSqlExecuteNonQuery
|
|||
public static int ExecSPSqlExecuteNonQuery(string sql, System.Data.IDataParameter[] paramers) |
|||
{ |
|||
MySqlConnection conn = new MySqlConnection(ConnectionString); |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
try |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.StoredProcedure, sql); |
|||
foreach (System.Data.IDataParameter paramer in paramers) |
|||
{ |
|||
sqlcom.Parameters.Add(paramer); |
|||
} |
|||
sqlcom.ExecuteNonQuery(); |
|||
return Convert.ToInt32(sqlcom.Parameters["@Id"].Value); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
conn.Close(); |
|||
throw ex; |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行存储过程,返回MySqlDataAdapter,SQL语句不含有参数
|
|||
#region ExecSPMySqlDataAdapter2
|
|||
public static MySqlDataReader ExecSPMySqlDataAdapter2(string sql) |
|||
{ |
|||
MySqlConnection conn = new MySqlConnection(ConnectionString); |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
try |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.StoredProcedure, sql); |
|||
MySqlDataReader sdr = sqlcom.ExecuteReader(CommandBehavior.CloseConnection); |
|||
sqlcom.Parameters.Clear(); |
|||
return sdr; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
conn.Close(); |
|||
throw ex; |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行存储过程返回DataSet类型,SQL语句含有参数
|
|||
#region ExecSPDataSet
|
|||
public static DataSet ExecSPDataSet(string sql, System.Data.IDataParameter[] paramers) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.StoredProcedure, sql); |
|||
foreach (System.Data.IDataParameter paramer in paramers) |
|||
{ |
|||
sqlcom.Parameters.Add(paramer); |
|||
} |
|||
MySqlDataAdapter sda = new MySqlDataAdapter(); |
|||
sda.SelectCommand = sqlcom; |
|||
DataSet ds = new DataSet(); |
|||
sda.Fill(ds); |
|||
sqlcom.Parameters.Clear(); |
|||
return ds; |
|||
} |
|||
} |
|||
#endregion
|
|||
//执行存储过程返回DataSet类型,SQL语句不含有参数
|
|||
#region ExecSPDataSet2
|
|||
public static DataSet ExecSPDataSet2(string sql) |
|||
{ |
|||
MySqlCommand sqlcom = new MySqlCommand(); |
|||
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) |
|||
{ |
|||
PrepareCommand(sqlcom, conn, CommandType.StoredProcedure, sql); |
|||
MySqlDataAdapter sda = new MySqlDataAdapter |
|||
{ |
|||
SelectCommand = sqlcom |
|||
}; |
|||
DataSet ds = new DataSet(); |
|||
sda.Fill(ds); |
|||
sqlcom.Parameters.Clear(); |
|||
return ds; |
|||
} |
|||
} |
|||
#endregion
|
|||
//
|
|||
// 执行存储过程返回DataSet类型,SQL语句含有参数
|
|||
#region PrepareCommand
|
|||
/// <summary>
|
|||
/// 执行存储过程返回DataSet类型,SQL语句含有参数
|
|||
/// </summary>
|
|||
/// <param name="cmd"></param>
|
|||
/// <param name="conn"></param>
|
|||
/// <param name="cmdType"></param>
|
|||
/// <param name="cmdText"></param>
|
|||
private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, CommandType cmdType, string cmdText) |
|||
{ |
|||
if (conn.State != ConnectionState.Open) |
|||
conn.Open(); |
|||
cmd.Connection = conn; |
|||
cmd.CommandText = cmdText; |
|||
cmd.CommandType = cmdType; |
|||
} |
|||
#endregion
|
|||
// 批量入库
|
|||
public static bool BulkInsert<T>(string tableName, IList<T> list) |
|||
{ |
|||
using (var bulkCopy = new SqlBulkCopy(ConnectionString)) |
|||
{ |
|||
bulkCopy.BatchSize = list.Count; |
|||
bulkCopy.DestinationTableName = tableName; |
|||
var table = new DataTable(); |
|||
var props = TypeDescriptor.GetProperties(typeof(T), new Attribute[] { }) |
|||
.Cast<PropertyDescriptor>() |
|||
.ToArray(); |
|||
foreach (var propertyInfo in props) |
|||
{ |
|||
bulkCopy.ColumnMappings.Add(propertyInfo.Name, propertyInfo.Name); |
|||
table.Columns.Add(propertyInfo.Name, Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType); |
|||
} |
|||
var values = new object[props.Length]; |
|||
foreach (var item in list) |
|||
{ |
|||
for (var i = 0; i < values.Length; i++) |
|||
{ |
|||
values[i] = props[i].GetValue(item); |
|||
} |
|||
table.Rows.Add(values); |
|||
} |
|||
bulkCopy.WriteToServer(table); |
|||
} |
|||
return true; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,139 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Data.SqlClient; |
|||
using GpsModels; |
|||
using GPSBusiness.GPSStandard; |
|||
using log4net; |
|||
using MySql.Data.MySqlClient; |
|||
|
|||
namespace GPSBusiness.Sql |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆信息获取接口
|
|||
/// </summary>
|
|||
public class SqlRepository : ICarService |
|||
{ |
|||
/// <summary>
|
|||
/// 开启了gps分析的公司:其实是根据gps分析订单状态:已出发,已到达,作业中
|
|||
/// </summary>
|
|||
public static List<CompanyModel> Companys; |
|||
/// <summary>
|
|||
/// 开启gps的所有车辆。
|
|||
/// </summary>
|
|||
public static List<VehicleModel> Cars; |
|||
/// <summary>
|
|||
/// 任务中(1,2,3,6,7)的订单,状态:(0未指派、1已指派、2已接单、3已出发、4已完成、5已删除、6已到达、7作业中、8已作废、9已撤销)
|
|||
/// </summary>
|
|||
public static List<OrderModel> Orders; |
|||
//public static Stopwatch Watch = new Stopwatch();
|
|||
public static ILog Log = LogManager.GetLogger(""); |
|||
|
|||
/// <summary>
|
|||
/// 通过协议卡号获取车辆信息
|
|||
/// </summary>
|
|||
/// <param name="simNo">卡号</param>
|
|||
/// <returns></returns>
|
|||
public VehicleModel Get(string terminalNo) |
|||
{ |
|||
var car = Cars.Find(x => x.TerminalNo == terminalNo); |
|||
return car; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 加载所有车辆信息
|
|||
/// </summary>
|
|||
public void Init() |
|||
{ |
|||
try |
|||
{ |
|||
Cars = new List<VehicleModel>(); |
|||
string sql = "SELECT Id,CompanyId,VehicleCode,VehiclePlate,SimNo,TerminalNo,TerminalType,IsActivate,IsGps,Acc,Work,GpsTime from dc_vehicle "; |
|||
var dt = SqlHelp.GetDataSet(sql).Tables[0]; |
|||
for (int i = 0; i < dt.Rows.Count; i++) |
|||
{ |
|||
var model = new VehicleModel |
|||
{ |
|||
Id = Convert.ToInt64(dt.Rows[i]["Id"]), |
|||
CompanyId = Convert.ToInt64(dt.Rows[i]["CompanyId"]), |
|||
VehicleCode = Convert.ToString(dt.Rows[i]["VehicleCode"]), |
|||
VehiclePlate = Convert.ToString(dt.Rows[i]["VehiclePlate"]), |
|||
SimNo = dt.Rows[i]["SimNo"].ToString(), |
|||
TerminalNo = dt.Rows[i]["TerminalNo"].ToString(), |
|||
TerminalType = Convert.ToInt32(dt.Rows[i]["TerminalType"]), |
|||
}; |
|||
Cars.Add(model); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.ErrorFormat("Init=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 加载所有公司信息,IsAnalyses为1的才会加载这些公司。
|
|||
/// </summary>
|
|||
public void InitCompany() |
|||
{ |
|||
try |
|||
{ |
|||
Companys = new List<CompanyModel>(); |
|||
string sql = "SELECT Id, CompanyName, Longitude, Latitude from dc_company"; |
|||
var dt = SqlHelp.GetDataSet(sql).Tables[0]; |
|||
for (int i = 0; i < dt.Rows.Count; i++) |
|||
{ |
|||
var model = new CompanyModel |
|||
{ |
|||
Id = Convert.ToInt64(dt.Rows[i]["Id"]), |
|||
CompanyName = Convert.ToString(dt.Rows[i]["CompanyName"]), |
|||
Longitude = Convert.ToDouble(dt.Rows[i]["Longitude"]), |
|||
Latitude = Convert.ToDouble(dt.Rows[i]["Latitude"]), |
|||
}; |
|||
Companys.Add(model); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.ErrorFormat("Init=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 加载所有车辆订单信息
|
|||
/// </summary>
|
|||
public void InitOrders() |
|||
{ |
|||
try |
|||
{ |
|||
Orders = new List<OrderModel>(); |
|||
string sql = "SELECT Id, Status, VehicleId, Longitude,Latitude,ArriveDate from dc_order"; |
|||
var dt = SqlHelp.GetDataSet(sql).Tables[0]; |
|||
for (var i = 0; i < dt.Rows.Count; i++) |
|||
{ |
|||
var model = new OrderModel |
|||
{ |
|||
Id = Convert.ToInt64(dt.Rows[i]["Id"]), |
|||
State = Convert.ToInt32(dt.Rows[i]["Status"]), |
|||
VehicleId = Convert.ToInt64(dt.Rows[i]["VehicleId"]), |
|||
Longitude = Convert.ToInt32(dt.Rows[i]["Longitude"]), |
|||
Latitude = Convert.ToInt32(dt.Rows[i]["Latitude"]), |
|||
ArriveTime = Convert.ToDateTime(dt.Rows[i]["ArriveDate"]) |
|||
}; |
|||
//订单状态
|
|||
Orders.Add(model); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.ErrorFormat("InitCarOrders=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
|
|||
public bool ExistThisStateOrder(long orderId,int state) |
|||
{ |
|||
var sql = string.Format("select Id from tc.[Order] where Id={0} and [State]={1}", orderId, state); |
|||
var result = SqlHelp.ExecuteScalar(sql); |
|||
var id = Convert.ToInt32(result); |
|||
return id != 0; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,190 @@ |
|||
using System; |
|||
|
|||
namespace GPSBuSiness.Util |
|||
{ |
|||
|
|||
public static class GPSUtil |
|||
{ |
|||
|
|||
public static double pi = 3.1415926535897932384626; |
|||
public static double x_pi = 3.14159265358979324 * 3000.0 / 180.0; |
|||
public static double a = 6378245.0; |
|||
public static double ee = 0.00669342162296594323; |
|||
private static double EARTH_RADIUS = 6378.137; |
|||
private static double rad(double d) |
|||
{ |
|||
return d * Math.PI / 180.0; |
|||
} |
|||
public static double transformLat(double x, double y) |
|||
{ |
|||
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y |
|||
+ 0.2 * Math.Sqrt(Math.Abs(x)); |
|||
ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0; |
|||
ret += (20.0 * Math.Sin(y * pi) + 40.0 * Math.Sin(y / 3.0 * pi)) * 2.0 / 3.0; |
|||
ret += (160.0 * Math.Sin(y / 12.0 * pi) + 320 * Math.Sin(y * pi / 30.0)) * 2.0 / 3.0; |
|||
return ret; |
|||
} |
|||
|
|||
public static double transformLon(double x, double y) |
|||
{ |
|||
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 |
|||
* Math.Sqrt(Math.Abs(x)); |
|||
ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0; |
|||
ret += (20.0 * Math.Sin(x * pi) + 40.0 * Math.Sin(x / 3.0 * pi)) * 2.0 / 3.0; |
|||
ret += (150.0 * Math.Sin(x / 12.0 * pi) + 300.0 * Math.Sin(x / 30.0 |
|||
* pi)) * 2.0 / 3.0; |
|||
return ret; |
|||
} |
|||
|
|||
public static Boolean outOfChina(double lat, double lon) |
|||
{ |
|||
if (lon < 72.004 || lon > 137.8347) |
|||
return true; |
|||
if (lat < 0.8293 || lat > 55.8271) |
|||
return true; |
|||
return false; |
|||
} |
|||
/** |
|||
* 84 to 火星坐标系 (GCJ-02) World Geodetic System ==> Mars Geodetic System |
|||
* |
|||
* @param lat |
|||
* @param lon |
|||
* @return |
|||
*/ |
|||
public static double[] gps84_To_Gcj02(double lat, double lon) |
|||
{ |
|||
if (outOfChina(lat, lon)) |
|||
{ |
|||
return new double[] { lat, lon }; |
|||
} |
|||
double dLat = transformLat(lon - 105.0, lat - 35.0); |
|||
double dLon = transformLon(lon - 105.0, lat - 35.0); |
|||
double radLat = lat / 180.0 * pi; |
|||
double magic = Math.Sin(radLat); |
|||
magic = 1 - ee * magic * magic; |
|||
double SqrtMagic = Math.Sqrt(magic); |
|||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi); |
|||
dLon = (dLon * 180.0) / (a / SqrtMagic * Math.Cos(radLat) * pi); |
|||
double mgLat = lat + dLat; |
|||
double mgLon = lon + dLon; |
|||
return new double[] { mgLat, mgLon }; |
|||
} |
|||
|
|||
/** |
|||
* * 火星坐标系 (GCJ-02) to 84 * * @param lon * @param lat * @return |
|||
* */ |
|||
public static double[] gcj02_To_Gps84(double lat, double lon) |
|||
{ |
|||
double[] gps = gps84_To_Gcj02(lat, lon); |
|||
double lontitude = lon * 2 - gps[1]; |
|||
double latitude = lat * 2 - gps[0]; |
|||
return new double[] { latitude, lontitude }; |
|||
} |
|||
/** |
|||
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 将 GCJ-02 坐标转换成 BD-09 坐标 |
|||
* |
|||
* @param lat |
|||
* @param lon |
|||
*/ |
|||
public static double[] gcj02_To_Bd09(double lat, double lon) |
|||
{ |
|||
double x = lon, y = lat; |
|||
double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * x_pi); |
|||
double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * x_pi); |
|||
double tempLon = z * Math.Cos(theta) + 0.0065; |
|||
double tempLat = z * Math.Sin(theta) + 0.006; |
|||
double[] gps = { tempLat, tempLon }; |
|||
return gps; |
|||
} |
|||
|
|||
/** |
|||
* * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 * * 将 BD-09 坐标转换成GCJ-02 坐标 * * @param |
|||
* bd_lat * @param bd_lon * @return |
|||
*/ |
|||
public static double[] bd09_To_Gcj02(double lat, double lon) |
|||
{ |
|||
double x = lon - 0.0065, y = lat - 0.006; |
|||
double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * x_pi); |
|||
double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * x_pi); |
|||
double tempLon = z * Math.Cos(theta); |
|||
double tempLat = z * Math.Sin(theta); |
|||
double[] gps = { tempLat, tempLon }; |
|||
return gps; |
|||
} |
|||
|
|||
/**将gps84转为bd09 |
|||
* @param lat |
|||
* @param lon |
|||
* @return |
|||
*/ |
|||
public static double[] gps84_To_bd09(double lat, double lon) |
|||
{ |
|||
double[] gcj02 = gps84_To_Gcj02(lat, lon); |
|||
double[] bd09 = gcj02_To_Bd09(gcj02[0], gcj02[1]); |
|||
return bd09; |
|||
} |
|||
public static double[] bd09_To_gps84(double lat, double lon) |
|||
{ |
|||
double[] gcj02 = bd09_To_Gcj02(lat, lon); |
|||
double[] gps84 = gcj02_To_Gps84(gcj02[0], gcj02[1]); |
|||
//保留小数点后六位
|
|||
gps84[0] = retain6(gps84[0]); |
|||
gps84[1] = retain6(gps84[1]); |
|||
return gps84; |
|||
} |
|||
|
|||
/**保留小数点后六位 |
|||
* @param num |
|||
* @return |
|||
*/ |
|||
private static double retain6(double num) |
|||
{ |
|||
String result = String.Format("%.6f", num); |
|||
return double.Parse(result); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 计算两个经纬度之间的距离 |
|||
* @param lat1 |
|||
* @param lng1 |
|||
* @param lat2 |
|||
* @param lng2 |
|||
* @return |
|||
*/ |
|||
public static double GetDistance(double lat1, double lng1, double lat2, double lng2) |
|||
{ |
|||
double radLat1 = rad(lat1); |
|||
double radLat2 = rad(lat2); |
|||
double a = radLat1 - radLat2; |
|||
double b = rad(lng1) - rad(lng2); |
|||
double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) + |
|||
Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2))); |
|||
s = s * EARTH_RADIUS; |
|||
s = Math.Round(s * 1000); |
|||
return s; |
|||
} |
|||
|
|||
/** |
|||
*算角度 |
|||
* @param lat_a 纬度1 |
|||
* @param lng_a 经度1 |
|||
* @param lat_b 纬度2 |
|||
* @param lng_b 经度2 |
|||
* @return |
|||
*/ |
|||
public static double GetAngle(double lng_a, double lat_a, double lng_b, double lat_b) |
|||
{ |
|||
|
|||
double y = Math.Sin(lng_b - lng_a) * Math.Cos(lat_b); |
|||
double x = Math.Cos(lat_a) * Math.Sin(lat_b) - Math.Sin(lat_a) * Math.Cos(lat_b) * Math.Cos(lng_b - lng_a); |
|||
double brng = Math.Atan2(y, x); |
|||
if (brng < 0) |
|||
brng = brng + 360; |
|||
return brng; |
|||
|
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<configuration> |
|||
<system.data> |
|||
<DbProviderFactories> |
|||
<remove invariant="MySql.Data.MySqlClient"/> |
|||
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/> |
|||
</DbProviderFactories> |
|||
</system.data> |
|||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,24 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="DnsClient" version="1.4.0" targetFramework="net472" /> |
|||
<package id="log4net" version="1.2.10" targetFramework="net40" /> |
|||
<package id="MongoDB.Bson" version="2.13.1" targetFramework="net472" /> |
|||
<package id="MongoDB.Driver" version="2.13.1" targetFramework="net472" /> |
|||
<package id="MongoDB.Driver.Core" version="2.13.1" targetFramework="net472" /> |
|||
<package id="MongoDB.Libmongocrypt" version="1.2.3" targetFramework="net472" /> |
|||
<package id="MySql.Data" version="6.7.9" targetFramework="net45" /> |
|||
<package id="SharpCompress" version="0.23.0" targetFramework="net472" /> |
|||
<package id="System.Buffers" version="4.5.1" targetFramework="net472" /> |
|||
<package id="System.IO" version="4.3.0" targetFramework="net472" /> |
|||
<package id="System.Net.Http" version="4.3.4" targetFramework="net472" /> |
|||
<package id="System.Runtime" version="4.3.0" targetFramework="net472" /> |
|||
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" /> |
|||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net472" /> |
|||
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net472" /> |
|||
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net472" /> |
|||
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net472" /> |
|||
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net472" /> |
|||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" /> |
|||
<package id="this.Log" version="0.0.3.0" targetFramework="net40" /> |
|||
<package id="this.Log-log4net" version="0.0.3.0" targetFramework="net40" /> |
|||
</packages> |
@ -0,0 +1,139 @@ |
|||
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00 |
|||
# Visual Studio Version 16 |
|||
VisualStudioVersion = 16.0.31205.134 |
|||
MinimumVisualStudioVersion = 10.0.40219.1 |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GPSServer", "GPSServer\GPSServer.csproj", "{75D60900-0E40-4BA4-8656-E956BBE7895A}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HPSocketCS", "HPSocketCS\HPSocketCS.csproj", "{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GPSBusiness", "GPSBusiness\GPSBusiness.csproj", "{5699F908-5B5C-4228-9EB7-6113B2B3992D}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Toogps.Mongo", "Toogps.Mongo\Toogps.Mongo.csproj", "{92893153-C7F1-42DF-8002-B7AE94829DB6}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Toogps.Mongo.Repository", "Toogps.PGProject.Repository.Mongo\Toogps.Mongo.Repository.csproj", "{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GpsModels", "GpsModel\GpsModels.csproj", "{275FE3F1-11A3-46F5-8320-493926113C9E}" |
|||
EndProject |
|||
Global |
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|||
CD_ROM|Any CPU = CD_ROM|Any CPU |
|||
CD_ROM|x64 = CD_ROM|x64 |
|||
Debug|Any CPU = Debug|Any CPU |
|||
Debug|x64 = Debug|x64 |
|||
DVD-5|Any CPU = DVD-5|Any CPU |
|||
DVD-5|x64 = DVD-5|x64 |
|||
Release|Any CPU = Release|Any CPU |
|||
Release|x64 = Release|x64 |
|||
SingleImage|Any CPU = SingleImage|Any CPU |
|||
SingleImage|x64 = SingleImage|x64 |
|||
EndGlobalSection |
|||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.CD_ROM|Any CPU.Build.0 = Release|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.CD_ROM|x64.ActiveCfg = Release|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.Debug|x64.ActiveCfg = Debug|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.Debug|x64.Build.0 = Debug|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.DVD-5|Any CPU.Build.0 = Debug|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.DVD-5|x64.ActiveCfg = Debug|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.Release|x64.ActiveCfg = Release|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.SingleImage|Any CPU.Build.0 = Release|Any CPU |
|||
{75D60900-0E40-4BA4-8656-E956BBE7895A}.SingleImage|x64.ActiveCfg = Release|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.CD_ROM|Any CPU.Build.0 = Release|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.CD_ROM|x64.ActiveCfg = Release|x64 |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.CD_ROM|x64.Build.0 = Release|x64 |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|x64.ActiveCfg = Debug|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Debug|x64.Build.0 = Debug|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.DVD-5|Any CPU.Build.0 = Debug|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.DVD-5|x64.ActiveCfg = Debug|x64 |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.DVD-5|x64.Build.0 = Debug|x64 |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|x64.ActiveCfg = Release|x64 |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.Release|x64.Build.0 = Release|x64 |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.SingleImage|Any CPU.Build.0 = Release|Any CPU |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.SingleImage|x64.ActiveCfg = Release|x64 |
|||
{DFA935E2-CF37-4E26-B697-D7F3DEE19DD8}.SingleImage|x64.Build.0 = Release|x64 |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.CD_ROM|Any CPU.Build.0 = Release|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.CD_ROM|x64.ActiveCfg = Release|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.Debug|x64.ActiveCfg = Debug|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.Debug|x64.Build.0 = Debug|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.DVD-5|Any CPU.Build.0 = Debug|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.DVD-5|x64.ActiveCfg = Debug|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.Release|x64.ActiveCfg = Release|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.SingleImage|Any CPU.Build.0 = Release|Any CPU |
|||
{5699F908-5B5C-4228-9EB7-6113B2B3992D}.SingleImage|x64.ActiveCfg = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.CD_ROM|Any CPU.Build.0 = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.CD_ROM|x64.ActiveCfg = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.Debug|x64.ActiveCfg = Debug|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.Debug|x64.Build.0 = Debug|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.DVD-5|Any CPU.Build.0 = Debug|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.DVD-5|x64.ActiveCfg = Debug|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.Release|x64.ActiveCfg = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.SingleImage|Any CPU.Build.0 = Release|Any CPU |
|||
{92893153-C7F1-42DF-8002-B7AE94829DB6}.SingleImage|x64.ActiveCfg = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.CD_ROM|Any CPU.Build.0 = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.CD_ROM|x64.ActiveCfg = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.Debug|x64.ActiveCfg = Debug|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.Debug|x64.Build.0 = Debug|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.DVD-5|Any CPU.Build.0 = Debug|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.DVD-5|x64.ActiveCfg = Debug|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.Release|x64.ActiveCfg = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.SingleImage|Any CPU.Build.0 = Release|Any CPU |
|||
{AA9C8C9B-D724-48CB-9E6E-400B456ADA5A}.SingleImage|x64.ActiveCfg = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.CD_ROM|Any CPU.Build.0 = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.CD_ROM|x64.ActiveCfg = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.Debug|x64.ActiveCfg = Debug|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.Debug|x64.Build.0 = Debug|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.DVD-5|Any CPU.Build.0 = Debug|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.DVD-5|x64.ActiveCfg = Debug|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.Release|x64.ActiveCfg = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.SingleImage|Any CPU.Build.0 = Release|Any CPU |
|||
{275FE3F1-11A3-46F5-8320-493926113C9E}.SingleImage|x64.ActiveCfg = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(SolutionProperties) = preSolution |
|||
HideSolutionNode = FALSE |
|||
EndGlobalSection |
|||
GlobalSection(ExtensibilityGlobals) = postSolution |
|||
SolutionGuid = {4DC58900-600F-4ADE-9873-1DC6E7F3873B} |
|||
EndGlobalSection |
|||
EndGlobal |
@ -0,0 +1,173 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{75D60900-0E40-4BA4-8656-E956BBE7895A}</ProjectGuid> |
|||
<OutputType>WinExe</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>GPSServer</RootNamespace> |
|||
<AssemblyName>GPSServer</AssemblyName> |
|||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<TargetFrameworkProfile /> |
|||
<IsWebBootstrapper>false</IsWebBootstrapper> |
|||
<PublishUrl>D:\Release\GPServer\</PublishUrl> |
|||
<Install>true</Install> |
|||
<InstallFrom>Disk</InstallFrom> |
|||
<UpdateEnabled>false</UpdateEnabled> |
|||
<UpdateMode>Foreground</UpdateMode> |
|||
<UpdateInterval>7</UpdateInterval> |
|||
<UpdateIntervalUnits>Days</UpdateIntervalUnits> |
|||
<UpdatePeriodically>false</UpdatePeriodically> |
|||
<UpdateRequired>false</UpdateRequired> |
|||
<MapFileExtensions>true</MapFileExtensions> |
|||
<UpdateUrl>http://localhost/GPSServer/</UpdateUrl> |
|||
<ApplicationRevision>13</ApplicationRevision> |
|||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> |
|||
<UseApplicationTrust>false</UseApplicationTrust> |
|||
<PublishWizardCompleted>true</PublishWizardCompleted> |
|||
<BootstrapperEnabled>true</BootstrapperEnabled> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<PlatformTarget>x64</PlatformTarget> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>..\bin\x64\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<Prefer32Bit>false</Prefer32Bit> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<PlatformTarget>AnyCPU</PlatformTarget> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<Prefer32Bit>false</Prefer32Bit> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<ApplicationIcon> |
|||
</ApplicationIcon> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<ManifestCertificateThumbprint>CD000D386F7A0036FBB1B94BFA06BF3A6E3146D8</ManifestCertificateThumbprint> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<ManifestKeyFile>GPSServer_TemporaryKey.pfx</ManifestKeyFile> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<GenerateManifests>true</GenerateManifests> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<SignManifests>false</SignManifests> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="log4net"> |
|||
<HintPath>..\lib\log4net.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="Newtonsoft.Json"> |
|||
<HintPath>..\lib\Newtonsoft.Json.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Configuration" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Data.DataSetExtensions" /> |
|||
<Reference Include="Microsoft.CSharp" /> |
|||
<Reference Include="System.Data" /> |
|||
<Reference Include="System.Deployment" /> |
|||
<Reference Include="System.Drawing" /> |
|||
<Reference Include="System.Windows.Forms" /> |
|||
<Reference Include="System.Xml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="Helper\MApplication.cs" /> |
|||
<Compile Include="Main.cs"> |
|||
<SubType>Form</SubType> |
|||
</Compile> |
|||
<Compile Include="Main.Designer.cs"> |
|||
<DependentUpon>Main.cs</DependentUpon> |
|||
</Compile> |
|||
<Compile Include="Program.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
<EmbeddedResource Include="Main.resx"> |
|||
<DependentUpon>Main.cs</DependentUpon> |
|||
</EmbeddedResource> |
|||
<EmbeddedResource Include="Properties\Resources.resx"> |
|||
<Generator>ResXFileCodeGenerator</Generator> |
|||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> |
|||
<SubType>Designer</SubType> |
|||
</EmbeddedResource> |
|||
<Compile Include="Properties\Resources.Designer.cs"> |
|||
<AutoGen>True</AutoGen> |
|||
<DependentUpon>Resources.resx</DependentUpon> |
|||
<DesignTime>True</DesignTime> |
|||
</Compile> |
|||
<None Include="app.config"> |
|||
<SubType>Designer</SubType> |
|||
</None> |
|||
<Content Include="log4net.config"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
<SubType>Designer</SubType> |
|||
</Content> |
|||
<None Include="GPSServer_TemporaryKey.pfx" /> |
|||
<None Include="Properties\Settings.settings"> |
|||
<Generator>SettingsSingleFileGenerator</Generator> |
|||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> |
|||
</None> |
|||
<Compile Include="Properties\Settings.Designer.cs"> |
|||
<AutoGen>True</AutoGen> |
|||
<DependentUpon>Settings.settings</DependentUpon> |
|||
<DesignTimeSharedInput>True</DesignTimeSharedInput> |
|||
</Compile> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\GPSBusiness\GPSBusiness.csproj"> |
|||
<Project>{5699f908-5b5c-4228-9eb7-6113b2b3992d}</Project> |
|||
<Name>GPSBusiness</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\GpsModel\GpsModels.csproj"> |
|||
<Project>{275fe3f1-11a3-46f5-8320-493926113c9e}</Project> |
|||
<Name>GpsModels</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\HPSocketCS\HPSocketCS.csproj"> |
|||
<Project>{dfa935e2-cf37-4e26-b697-d7f3dee19dd8}</Project> |
|||
<Name>HPSocketCS</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Toogps.PGProject.Repository.Mongo\Toogps.Mongo.Repository.csproj"> |
|||
<Project>{aa9c8c9b-d724-48cb-9e6e-400b456ada5a}</Project> |
|||
<Name>Toogps.Mongo.Repository</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<BootstrapperPackage Include=".NETFramework,Version=v4.5"> |
|||
<Visible>False</Visible> |
|||
<ProductName>Microsoft .NET Framework 4.5 %28x86 和 x64%29</ProductName> |
|||
<Install>true</Install> |
|||
</BootstrapperPackage> |
|||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> |
|||
<Visible>False</Visible> |
|||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> |
|||
<Install>false</Install> |
|||
</BootstrapperPackage> |
|||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> |
|||
<Visible>False</Visible> |
|||
<ProductName>.NET Framework 3.5 SP1</ProductName> |
|||
<Install>false</Install> |
|||
</BootstrapperPackage> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
@ -0,0 +1,19 @@ |
|||
using System.Collections.Concurrent; |
|||
using GpsModels; |
|||
|
|||
namespace GPSServer.Helper |
|||
{ |
|||
public class MApplication |
|||
{ |
|||
/// <summary>
|
|||
/// 待处理到RealTime的数据-列队线程安全的列队字典
|
|||
/// </summary>
|
|||
public static ConcurrentDictionary<long, ConcurrentQueue<GpsModel>> ConcurrentQueues = new ConcurrentDictionary<long, ConcurrentQueue<GpsModel>>(); |
|||
|
|||
/// <summary>
|
|||
/// 待持久化gps数据的列队字典(car)
|
|||
/// </summary>
|
|||
public static ConcurrentDictionary<long, ConcurrentQueue<GpsModel>> CarConcurrentQueues = new ConcurrentDictionary<long, ConcurrentQueue<GpsModel>>(); |
|||
|
|||
} |
|||
} |
@ -0,0 +1,246 @@ |
|||
namespace GPSServer |
|||
{ |
|||
partial class Main |
|||
{ |
|||
/// <summary>
|
|||
/// Required designer variable.
|
|||
/// </summary>
|
|||
private System.ComponentModel.IContainer components = null; |
|||
/// <summary>
|
|||
/// Clean up any resources being used.
|
|||
/// </summary>
|
|||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|||
protected override void Dispose(bool disposing) |
|||
{ |
|||
if (disposing && (components != null)) |
|||
{ |
|||
components.Dispose(); |
|||
} |
|||
base.Dispose(disposing); |
|||
} |
|||
#region Windows Form Designer generated code
|
|||
/// <summary>
|
|||
/// Required method for Designer support - do not modify
|
|||
/// the contents of this method with the code editor.
|
|||
/// </summary>
|
|||
private void InitializeComponent() |
|||
{ |
|||
this.components = new System.ComponentModel.Container(); |
|||
this.label1 = new System.Windows.Forms.Label(); |
|||
this.label2 = new System.Windows.Forms.Label(); |
|||
this.label3 = new System.Windows.Forms.Label(); |
|||
this.label4 = new System.Windows.Forms.Label(); |
|||
this.label5 = new System.Windows.Forms.Label(); |
|||
this.btnStart = new System.Windows.Forms.Button(); |
|||
this.btnStop = new System.Windows.Forms.Button(); |
|||
this.txtResIpAddress = new System.Windows.Forms.TextBox(); |
|||
this.txtResPort = new System.Windows.Forms.TextBox(); |
|||
this.timer1 = new System.Windows.Forms.Timer(this.components); |
|||
this.timer2 = new System.Windows.Forms.Timer(this.components); |
|||
this.timer3 = new System.Windows.Forms.Timer(this.components); |
|||
this.timer4 = new System.Windows.Forms.Timer(this.components); |
|||
this.lbCJH = new System.Windows.Forms.Label(); |
|||
this.lbDL = new System.Windows.Forms.Label(); |
|||
this.lbZD = new System.Windows.Forms.Label(); |
|||
this.label6 = new System.Windows.Forms.Label(); |
|||
this.label7 = new System.Windows.Forms.Label(); |
|||
this.SuspendLayout(); |
|||
//
|
|||
// label1
|
|||
//
|
|||
this.label1.AutoSize = true; |
|||
this.label1.Location = new System.Drawing.Point(57, 35); |
|||
this.label1.Name = "label1"; |
|||
this.label1.Size = new System.Drawing.Size(41, 12); |
|||
this.label1.TabIndex = 0; |
|||
this.label1.Text = "监听IP"; |
|||
//
|
|||
// label2
|
|||
//
|
|||
this.label2.AutoSize = true; |
|||
this.label2.Location = new System.Drawing.Point(57, 98); |
|||
this.label2.Name = "label2"; |
|||
this.label2.Size = new System.Drawing.Size(77, 12); |
|||
this.label2.TabIndex = 1; |
|||
this.label2.Text = "终端连接数:"; |
|||
//
|
|||
// label3
|
|||
//
|
|||
this.label3.AutoSize = true; |
|||
this.label3.Location = new System.Drawing.Point(55, 135); |
|||
this.label3.Name = "label3"; |
|||
this.label3.Size = new System.Drawing.Size(113, 12); |
|||
this.label3.TabIndex = 2; |
|||
this.label3.Text = "实时队列中的数据:"; |
|||
//
|
|||
// label4
|
|||
//
|
|||
this.label4.AutoSize = true; |
|||
this.label4.Location = new System.Drawing.Point(57, 176); |
|||
this.label4.Name = "label4"; |
|||
this.label4.Size = new System.Drawing.Size(101, 12); |
|||
this.label4.TabIndex = 3; |
|||
this.label4.Text = "持久化队列数据:"; |
|||
//
|
|||
// label5
|
|||
//
|
|||
this.label5.AutoSize = true; |
|||
this.label5.Location = new System.Drawing.Point(301, 35); |
|||
this.label5.Name = "label5"; |
|||
this.label5.Size = new System.Drawing.Size(41, 12); |
|||
this.label5.TabIndex = 4; |
|||
this.label5.Text = "端口:"; |
|||
//
|
|||
// btnStart
|
|||
//
|
|||
this.btnStart.Location = new System.Drawing.Point(120, 276); |
|||
this.btnStart.Name = "btnStart"; |
|||
this.btnStart.Size = new System.Drawing.Size(75, 23); |
|||
this.btnStart.TabIndex = 6; |
|||
this.btnStart.Text = "Start"; |
|||
this.btnStart.UseVisualStyleBackColor = true; |
|||
this.btnStart.Click += new System.EventHandler(this.btnStart_Click); |
|||
//
|
|||
// btnStop
|
|||
//
|
|||
this.btnStop.Location = new System.Drawing.Point(255, 276); |
|||
this.btnStop.Name = "btnStop"; |
|||
this.btnStop.Size = new System.Drawing.Size(75, 23); |
|||
this.btnStop.TabIndex = 7; |
|||
this.btnStop.Text = "Stop"; |
|||
this.btnStop.UseVisualStyleBackColor = true; |
|||
this.btnStop.Click += new System.EventHandler(this.btnStop_Click); |
|||
//
|
|||
// txtResIpAddress
|
|||
//
|
|||
this.txtResIpAddress.Location = new System.Drawing.Point(104, 32); |
|||
this.txtResIpAddress.Name = "txtResIpAddress"; |
|||
this.txtResIpAddress.Size = new System.Drawing.Size(174, 21); |
|||
this.txtResIpAddress.TabIndex = 8; |
|||
this.txtResIpAddress.Text = "0.0.0.0"; |
|||
//
|
|||
// txtResPort
|
|||
//
|
|||
this.txtResPort.Location = new System.Drawing.Point(348, 32); |
|||
this.txtResPort.Name = "txtResPort"; |
|||
this.txtResPort.Size = new System.Drawing.Size(54, 21); |
|||
this.txtResPort.TabIndex = 9; |
|||
this.txtResPort.Text = "9668"; |
|||
|
|||
//
|
|||
// timer1
|
|||
//
|
|||
this.timer1.Enabled = true; |
|||
this.timer1.Interval = 300000; |
|||
this.timer1.Tick += new System.EventHandler(this.timer1_Tick); |
|||
//
|
|||
// timer2
|
|||
//
|
|||
this.timer2.Enabled = true; |
|||
this.timer2.Interval = 1000; |
|||
this.timer2.Tick += new System.EventHandler(this.timer2_Tick); |
|||
//
|
|||
// timer3
|
|||
//
|
|||
this.timer3.Enabled = true; |
|||
this.timer3.Interval = 1000; |
|||
this.timer3.Tick += new System.EventHandler(this.timer3_Tick); |
|||
//
|
|||
// timer4
|
|||
//
|
|||
this.timer4.Enabled = true; |
|||
this.timer4.Interval = 3000; |
|||
this.timer4.Tick += new System.EventHandler(this.timer4_Tick); |
|||
//
|
|||
// lbCJH
|
|||
//
|
|||
this.lbCJH.AutoSize = true; |
|||
this.lbCJH.Location = new System.Drawing.Point(193, 176); |
|||
this.lbCJH.Name = "lbCJH"; |
|||
this.lbCJH.Size = new System.Drawing.Size(11, 12); |
|||
this.lbCJH.TabIndex = 12; |
|||
this.lbCJH.Text = "0"; |
|||
//
|
|||
// lbDL
|
|||
//
|
|||
this.lbDL.AutoSize = true; |
|||
this.lbDL.Location = new System.Drawing.Point(193, 135); |
|||
this.lbDL.Name = "lbDL"; |
|||
this.lbDL.Size = new System.Drawing.Size(11, 12); |
|||
this.lbDL.TabIndex = 11; |
|||
this.lbDL.Text = "0"; |
|||
//
|
|||
// lbZD
|
|||
//
|
|||
this.lbZD.AutoSize = true; |
|||
this.lbZD.Location = new System.Drawing.Point(193, 98); |
|||
this.lbZD.Name = "lbZD"; |
|||
this.lbZD.Size = new System.Drawing.Size(11, 12); |
|||
this.lbZD.TabIndex = 10; |
|||
this.lbZD.Text = "0"; |
|||
//
|
|||
// label6
|
|||
//
|
|||
this.label6.AutoSize = true; |
|||
this.label6.Location = new System.Drawing.Point(57, 213); |
|||
this.label6.Name = "label6"; |
|||
this.label6.Size = new System.Drawing.Size(113, 12); |
|||
this.label6.TabIndex = 13; |
|||
this.label6.Text = "完成持久化的数据:"; |
|||
//
|
|||
// label7
|
|||
//
|
|||
this.label7.AutoSize = true; |
|||
this.label7.Location = new System.Drawing.Point(193, 213); |
|||
this.label7.Name = "label7"; |
|||
this.label7.Size = new System.Drawing.Size(11, 12); |
|||
this.label7.TabIndex = 14; |
|||
this.label7.Text = "0"; |
|||
//
|
|||
// Main
|
|||
//
|
|||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); |
|||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
|||
this.ClientSize = new System.Drawing.Size(478, 334); |
|||
this.Controls.Add(this.label7); |
|||
this.Controls.Add(this.label6); |
|||
this.Controls.Add(this.lbCJH); |
|||
this.Controls.Add(this.lbDL); |
|||
this.Controls.Add(this.lbZD); |
|||
this.Controls.Add(this.txtResPort); |
|||
this.Controls.Add(this.txtResIpAddress); |
|||
this.Controls.Add(this.btnStop); |
|||
this.Controls.Add(this.btnStart); |
|||
this.Controls.Add(this.label5); |
|||
this.Controls.Add(this.label4); |
|||
this.Controls.Add(this.label3); |
|||
this.Controls.Add(this.label2); |
|||
this.Controls.Add(this.label1); |
|||
this.Name = "Main"; |
|||
this.Text = "GPS服务程序"; |
|||
this.Load += new System.EventHandler(this.Main_Load); |
|||
this.ResumeLayout(false); |
|||
this.PerformLayout(); |
|||
|
|||
} |
|||
#endregion
|
|||
private System.Windows.Forms.Label label1; |
|||
private System.Windows.Forms.Label label2; |
|||
private System.Windows.Forms.Label label3; |
|||
private System.Windows.Forms.Label label4; |
|||
private System.Windows.Forms.Label label5; |
|||
private System.Windows.Forms.Button btnStart; |
|||
private System.Windows.Forms.Button btnStop; |
|||
private System.Windows.Forms.TextBox txtResIpAddress; |
|||
private System.Windows.Forms.TextBox txtResPort; |
|||
private System.Windows.Forms.Timer timer1; |
|||
private System.Windows.Forms.Timer timer2; |
|||
private System.Windows.Forms.Timer timer3; |
|||
private System.Windows.Forms.Timer timer4; |
|||
private System.Windows.Forms.Label lbCJH; |
|||
private System.Windows.Forms.Label lbDL; |
|||
private System.Windows.Forms.Label lbZD; |
|||
private System.Windows.Forms.Label label6; |
|||
private System.Windows.Forms.Label label7; |
|||
} |
|||
} |
@ -0,0 +1,789 @@ |
|||
using GpsModels; |
|||
using GPSBusiness; |
|||
using GPSBusiness.GPSStandard; |
|||
using GPSServer.Helper; |
|||
using HPSocketCS; |
|||
using Newtonsoft.Json; |
|||
using System; |
|||
using System.Collections.Concurrent; |
|||
using System.Collections.Generic; |
|||
using System.Configuration; |
|||
using System.Linq; |
|||
using System.Runtime.InteropServices; |
|||
using System.Threading; |
|||
using System.Windows.Forms; |
|||
using GPSBusiness.BBGPSStandard; |
|||
using GPSBusiness.Enum; |
|||
using GPSBusiness.Helper; |
|||
using GPSBusiness.Redis; |
|||
using GPSBusiness.Sql; |
|||
using Toogps.Mongo.Repository; |
|||
using GPSBusiness.Model; |
|||
using GPSBuSiness.Util; |
|||
|
|||
namespace GPSServer |
|||
{ |
|||
public partial class Main : Form |
|||
{ |
|||
#region 显示消息
|
|||
|
|||
private delegate void ShowMsg(string msg); |
|||
|
|||
private ShowMsg _addMsgLabel; |
|||
private ShowMsg _addMsgLabel1; |
|||
private ShowMsg _addMsgLabel2; |
|||
private ShowMsg _addMsgLabel3; |
|||
|
|||
// 显示消息:终端连接数
|
|||
void AddMsg(string msg) |
|||
{ |
|||
if (this.lbZD.InvokeRequired) |
|||
{ |
|||
this.lbZD.Invoke(_addMsgLabel, msg); |
|||
} |
|||
else |
|||
{ |
|||
this.lbZD.Text = msg; |
|||
} |
|||
} |
|||
|
|||
// 显示消息:实时队列中的数据
|
|||
void AddMsg1(string msg) |
|||
{ |
|||
if (this.lbDL.InvokeRequired) |
|||
{ |
|||
this.lbDL.Invoke(_addMsgLabel1, msg); |
|||
} |
|||
else |
|||
{ |
|||
this.lbDL.Text = msg; |
|||
} |
|||
} |
|||
|
|||
// 显示消息:持久化队列数据
|
|||
void AddMsg2(string msg) |
|||
{ |
|||
if (this.lbCJH.InvokeRequired) |
|||
{ |
|||
this.lbCJH.Invoke(_addMsgLabel2, msg); |
|||
} |
|||
else |
|||
{ |
|||
this.lbCJH.Text = msg; |
|||
} |
|||
} |
|||
|
|||
// 显示消息:完成持久化的数据
|
|||
void AddMsg3(string msg) |
|||
{ |
|||
if (this.label7.InvokeRequired) |
|||
{ |
|||
this.label7.Invoke(_addMsgLabel3, msg); |
|||
} |
|||
else |
|||
{ |
|||
this.label7.Text = msg; |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
/// <summary>
|
|||
/// 应用状态
|
|||
/// </summary>
|
|||
private AppState _appState = AppState.Stoped; |
|||
/// <summary>
|
|||
/// gps设备tcp服务
|
|||
/// </summary>
|
|||
private readonly TcpServer _gpsEquServer = new TcpServer(); |
|||
public static SqlRepository CarService = new SqlRepository(); |
|||
private static int _persistenceGpsNo = 0; |
|||
private static int _persistenceCarGpsNo = 0; |
|||
private static long _savePsNo = 0; |
|||
|
|||
/// <summary>
|
|||
/// 出发厂区半径
|
|||
/// </summary>
|
|||
private static int _setOutRadius; |
|||
|
|||
/// <summary>
|
|||
/// 到达工地半径
|
|||
/// </summary>
|
|||
private static int _arriveRadius; |
|||
|
|||
public Main() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void Main_Load(object sender, EventArgs e) |
|||
{ |
|||
this.Log().Info("程序启动"); |
|||
_setOutRadius = int.Parse(ConfigurationManager.AppSettings["SetOutRadius"]); |
|||
_arriveRadius = int.Parse(ConfigurationManager.AppSettings["ArriveRadius"]); |
|||
_addMsgLabel += AddMsg; |
|||
_addMsgLabel1 += AddMsg1; |
|||
_addMsgLabel2 += AddMsg2; |
|||
_addMsgLabel3 += AddMsg3; |
|||
GpsStandardHelper.BBStandardToCarGPSHandler = new BbStandardToCarGpsHandler(CarService); |
|||
_gpsEquServer.OnPrepareListen += new TcpServerEvent.OnPrepareListenEventHandler(OnGpsEquServerPrepareListen); |
|||
_gpsEquServer.OnAccept += new TcpServerEvent.OnAcceptEventHandler(OnGpsEquServerAccept); |
|||
_gpsEquServer.OnSend += new TcpServerEvent.OnSendEventHandler(OnGPSEquServerSend); |
|||
_gpsEquServer.OnClose += new TcpServerEvent.OnCloseEventHandler(OnGpsEquServerClose); |
|||
_gpsEquServer.OnError += new TcpServerEvent.OnErrorEventHandler(OnGpsEquServerError); |
|||
_gpsEquServer.OnReceive += new TcpServerEvent.OnReceiveEventHandler(OnGpsEquServerReceive); |
|||
_gpsEquServer.OnShutdown += new TcpServerEvent.OnShutdownEventHandler(OnGpsEquServerShutdown); |
|||
|
|||
CarService.Init(); |
|||
CarService.InitCompany(); |
|||
CarService.InitOrders(); |
|||
SetAppState(AppState.Stoped); |
|||
// var list = CarGpsRepository.MongoGetListDemo();
|
|||
} |
|||
|
|||
#region GPSEquService Handle
|
|||
|
|||
private HandleResult OnGpsEquServerPrepareListen(IntPtr soListen) |
|||
{ |
|||
return HandleResult.Ok; |
|||
} |
|||
|
|||
private HandleResult OnGpsEquServerAccept(IntPtr connId, IntPtr pClient) |
|||
{ |
|||
AddMsg(_gpsEquServer.ConnectionCount.ToString()); |
|||
return HandleResult.Ok; |
|||
} |
|||
|
|||
private HandleResult OnGPSEquServerSend(IntPtr connId, IntPtr pData, int length) |
|||
{ |
|||
return HandleResult.Ok; |
|||
} |
|||
|
|||
private HandleResult OnGpsEquServerClose(IntPtr connId) |
|||
{ |
|||
AddMsg((_gpsEquServer.ConnectionCount - 1).ToString()); |
|||
return HandleResult.Ok; |
|||
} |
|||
|
|||
private HandleResult OnGpsEquServerError(IntPtr connId, SocketOperation enOperation, int errorCode) |
|||
{ |
|||
return OnGpsEquServerClose(connId); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 接收设备发来的数据
|
|||
/// </summary>
|
|||
/// <param name="intPtr"></param>
|
|||
/// <param name="pData"></param>
|
|||
/// <param name="length"></param>
|
|||
/// <returns></returns>
|
|||
private HandleResult OnGpsEquServerReceive(IntPtr intPtr, IntPtr pData, int length) |
|||
{ |
|||
|
|||
|
|||
try |
|||
{ |
|||
byte[] bytes = new byte[length]; |
|||
string mdtStr = ""; |
|||
Marshal.Copy(pData, bytes, 0, length); |
|||
var gpsResponseDatas = GpsStandardHelper.GetGpsStandardData(bytes, intPtr, mdtStr); |
|||
foreach (var gpsResponseData in gpsResponseDatas) |
|||
{ |
|||
if (gpsResponseData.GpsInfo != null) |
|||
{ |
|||
var gpsModel = gpsResponseData.GpsInfo; |
|||
if (gpsModel == null) continue; |
|||
if (gpsModel.Acc == -1 )//沃瑞特心跳或者博实结未定位
|
|||
{ |
|||
gpsModel.GpsState = GpsStateEnum.Motionless.ToInt(); //默认静止
|
|||
gpsModel.DurationTime = ""; |
|||
gpsModel.AccDurationTime = ""; |
|||
#region 先处理沃瑞特心跳在线实时的时间===沃瑞特gps心跳时间间隔:2分钟一次。
|
|||
var haveSpeedModel = RedisRepository.GetLastHaveSpeed(gpsModel); |
|||
if (haveSpeedModel != null) |
|||
{ |
|||
var time2 = DateTime.Now - haveSpeedModel.GpsTime; |
|||
gpsModel.DurationTime = CalculationGpsHelper.TimeSpanFormat(time2); |
|||
if (time2.TotalSeconds < 31) |
|||
{ |
|||
gpsModel.GpsState = GpsStateEnum.Moving.ToInt(); |
|||
gpsModel.Speed = haveSpeedModel.Speed; |
|||
gpsModel.DurationTime = ""; |
|||
} |
|||
} |
|||
|
|||
FirstStatusCacheService(gpsModel, (int)StatusEnum.Acc); |
|||
|
|||
//分析Acc持续时长
|
|||
var firstAccModel = RedisRepository.GetFirstStatus(gpsModel, (int)StatusEnum.Acc); |
|||
if (firstAccModel != null) |
|||
{ |
|||
if (firstAccModel.Acc != -1) |
|||
{ |
|||
var time3 = DateTime.Now - firstAccModel.GpsTime; |
|||
if (time3.TotalMilliseconds > 0) |
|||
gpsModel.AccDurationTime = CalculationGpsHelper.TimeSpanFormat(time3); |
|||
} |
|||
} |
|||
|
|||
FirstStatusCacheService(gpsModel, (int)StatusEnum.Work); |
|||
|
|||
//分析作业持续时长
|
|||
var firstWorkModel = RedisRepository.GetFirstStatus(gpsModel, (int)StatusEnum.Work); |
|||
if (firstWorkModel != null) |
|||
{ |
|||
if (firstWorkModel.Work != -1) |
|||
{ |
|||
var time3 = DateTime.Now - firstWorkModel.GpsTime; |
|||
if (time3.TotalMilliseconds > 0) |
|||
gpsModel.WorkDurationTime = CalculationGpsHelper.TimeSpanFormat(time3); |
|||
} |
|||
} |
|||
|
|||
|
|||
"bytes".Log().DebugFormat("GpsRealTimeRepository"); |
|||
|
|||
|
|||
|
|||
//MyGpsServer.UpdateGpsRealTimeGpsStateWrt(gpsModel);
|
|||
GpsRealTimeRepository.UpdateGpsRealTimeGpsStateWrt(gpsModel); |
|||
#endregion
|
|||
} |
|||
else//有gps数据信息,则加入到队列。
|
|||
{ |
|||
//加入队列
|
|||
ConcurrentQueue<GpsModel> concurrentQueues; |
|||
if (MApplication.ConcurrentQueues.TryGetValue(1, out concurrentQueues) == false) |
|||
{ |
|||
//三次失败就不再尝试了
|
|||
concurrentQueues = new ConcurrentQueue<GpsModel>(); |
|||
if (MApplication.ConcurrentQueues.TryAdd(1, concurrentQueues) == false) |
|||
{ |
|||
if (MApplication.ConcurrentQueues.TryAdd(1, concurrentQueues) == false) |
|||
{ |
|||
if (MApplication.ConcurrentQueues.TryAdd(1, concurrentQueues) == false) |
|||
{ |
|||
this.Log().Error("TryAdd(model.SiteId, ConcurrentQueues) false"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
//转成高德地图坐标点
|
|||
//var tgGps =
|
|||
// MapHelper.Gps84ToGD((double)gpsModel.Latitude,
|
|||
// (double)gpsModel.Longitude);
|
|||
|
|||
|
|||
//基站定位不做多余解析
|
|||
if (gpsModel.LocationStatus != 0) |
|||
{ |
|||
var gdGps = GPSUtil.gps84_To_Gcj02((double)gpsModel.Latitude, |
|||
(double)gpsModel.Longitude); |
|||
if (gdGps.Length > 0) |
|||
{ |
|||
gpsModel.Latitude = Convert.ToDecimal(gdGps[0]); |
|||
gpsModel.Longitude = Convert.ToDecimal(gdGps[1]); |
|||
} |
|||
} |
|||
gpsModel.Address = MapHelper.GetLocationByLngLat(gpsModel.Longitude, gpsModel.Latitude); |
|||
|
|||
// this.Log().InfoFormat("GPS数据对比,tgGps={0},gdGps={1},gdGps={2}", JsonConvert.SerializeObject(tgGps),gdGps[0], gdGps[1]);
|
|||
|
|||
|
|||
|
|||
|
|||
this.Log().InfoFormat(gpsModel.Address); |
|||
concurrentQueues.Enqueue(gpsModel); |
|||
_persistenceGpsNo++; |
|||
this.Log().InfoFormat("添加一条Gps位置信息到队列,共{0}条,model={1}", _persistenceGpsNo, |
|||
JsonConvert.SerializeObject(gpsModel)); |
|||
} |
|||
} |
|||
//应答数据不为null,应答设备联接
|
|||
if (gpsResponseData.ReturnData != null) |
|||
{ |
|||
_gpsEquServer.Send(intPtr, gpsResponseData.ReturnData, gpsResponseData.ReturnData.Length); |
|||
} |
|||
} |
|||
AddMsg1(_persistenceGpsNo.ToString()); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("OnGPSEquServerReceive=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
return HandleResult.Ok; |
|||
} |
|||
|
|||
private HandleResult OnGpsEquServerShutdown() |
|||
{ |
|||
AddMsg((_gpsEquServer.ConnectionCount - 1).ToString()); |
|||
return HandleResult.Ok; |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
private void btnStart_Click(object sender, EventArgs e) |
|||
{ |
|||
SetAppState(AppState.Starting); |
|||
StartGpsEquServer(); |
|||
} |
|||
|
|||
private void StartGpsEquServer() |
|||
{ |
|||
try |
|||
{ |
|||
_gpsEquServer.IpAddress = this.txtResIpAddress.Text.Trim(); |
|||
_gpsEquServer.Port = ushort.Parse(this.txtResPort.Text.Trim()); |
|||
// 启动接收服务
|
|||
if (_gpsEquServer.Start()) |
|||
{ |
|||
this.Text = string.Format("{2} - ({0}:{1})", this.txtResIpAddress.Text, this.txtResPort.Text, |
|||
"GPS服务程序"); |
|||
SetAppState(AppState.Started); |
|||
} |
|||
else |
|||
{ |
|||
SetAppState(AppState.Stoped); |
|||
throw new Exception(string.Format("$ receive Server Start Error -> {0}({1})", |
|||
_gpsEquServer.ErrorMessage, |
|||
_gpsEquServer.ErrorCode)); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("StartGpsEquServer=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
|
|||
// 设置程序状态
|
|||
private void SetAppState(AppState state) |
|||
{ |
|||
_appState = state; |
|||
this.btnStart.Enabled = (_appState == AppState.Stoped); |
|||
this.btnStop.Enabled = (_appState == AppState.Started); |
|||
this.txtResIpAddress.Enabled = (_appState == AppState.Stoped); |
|||
this.txtResPort.Enabled = (_appState == AppState.Stoped); |
|||
} |
|||
|
|||
private void btnStop_Click(object sender, EventArgs e) |
|||
{ |
|||
try |
|||
{ |
|||
SetAppState(AppState.Stoping); |
|||
// 停止服务
|
|||
if (_gpsEquServer.Stop()) |
|||
{ |
|||
this.Text = "GPS服务程序"; |
|||
SetAppState(AppState.Stoped); |
|||
} |
|||
else |
|||
{ |
|||
this.Log().Error(string.Format("btnStop_Click Error -> {0}({1})", |
|||
_gpsEquServer.ErrorMessage, _gpsEquServer.ErrorCode)); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("btnStop_Click=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
|
|||
// 更新车辆、公司、订单信息
|
|||
private void timer1_Tick(object sender, EventArgs e) |
|||
{ |
|||
if (_appState != AppState.Started) return; |
|||
CarService.Init(); |
|||
CarService.InitCompany(); |
|||
CarService.InitOrders(); |
|||
} |
|||
|
|||
// 定时器:PersistenceGpsRealTime
|
|||
private void timer2_Tick(object sender, EventArgs e) |
|||
{ |
|||
if (_appState != AppState.Started) return; |
|||
PersistenceGpsRealTime(); |
|||
} |
|||
|
|||
//更新车辆实时位置,更新Redis相关的Gps信息:1、车辆最后GPS时间。2、最后存在速度的GPS时间。3、Acc第一次开启的时间
|
|||
private void PersistenceGpsRealTime() |
|||
{ |
|||
try |
|||
{ |
|||
foreach (var concurrentQueue in MApplication.ConcurrentQueues) |
|||
{ |
|||
try |
|||
{ |
|||
if (concurrentQueue.Value.Count == 0) continue; |
|||
var models = new List<GpsModel>(); |
|||
for (var i = 0; i < Convert.ToInt32(_gpsEquServer.ConnectionCount); ) |
|||
{ |
|||
GpsModel model; |
|||
if (concurrentQueue.Value.TryDequeue(out model)) |
|||
{ |
|||
models.Add(model); |
|||
i++; |
|||
_persistenceGpsNo--; |
|||
} |
|||
else |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (models.Count == 0) continue; |
|||
foreach (var item in models) |
|||
{ |
|||
var gpsModel = item; |
|||
//=======================更新车辆实时==位置==========================
|
|||
//MyGpsServer.UpdateGpsRealTime(gpsModel);
|
|||
//当有GPS数据时再更新主表
|
|||
if (gpsModel.Latitude > 0 && gpsModel.Longitude > 0) |
|||
{ |
|||
GpsRealTimeRepository.UpdateGpsRealTime(gpsModel); |
|||
} |
|||
else |
|||
{ |
|||
this.Log().ErrorFormat("gpsModel.Latitude=0:{2}", |
|||
gpsModel.VehicleId); |
|||
} |
|||
//=======================更新车辆实时==位置==========================
|
|||
//有速度的最后定位时间 到Redis
|
|||
LastHaveSpeedCacheService(gpsModel); |
|||
//更新Acc 到Redis
|
|||
FirstStatusCacheService(gpsModel, (int)StatusEnum.Acc); |
|||
//更新Work 到Redis
|
|||
FirstStatusCacheService(gpsModel, (int)StatusEnum.Work); |
|||
//=======================更新车辆实时==状态==========================
|
|||
AnalysesGpsState(gpsModel);//TODO:逻辑检查,判断上两句存储在Redis的数据,是否会符合业务逻辑。是否会影响
|
|||
//=======================更新车辆实时==状态==========================
|
|||
|
|||
//入列到待持久化队列中
|
|||
ConcurrentQueue<GpsModel> carConcurrentQueues; |
|||
if (MApplication.CarConcurrentQueues.TryGetValue(gpsModel.VehicleId, out carConcurrentQueues) == false) |
|||
{ |
|||
//三次失败就不再尝试了
|
|||
carConcurrentQueues = new ConcurrentQueue<GpsModel>(); |
|||
if (MApplication.CarConcurrentQueues.TryAdd(gpsModel.VehicleId, carConcurrentQueues) == false) |
|||
{ |
|||
if (MApplication.CarConcurrentQueues.TryAdd(gpsModel.VehicleId, carConcurrentQueues) == false) |
|||
{ |
|||
if (MApplication.CarConcurrentQueues.TryAdd(gpsModel.VehicleId, carConcurrentQueues) == false) |
|||
{ |
|||
this.Log().Error("TryAdd(model.VehicleId, ConcurrentQueues) false"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
carConcurrentQueues.Enqueue(gpsModel); |
|||
_persistenceCarGpsNo++; |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("PersistenceGpsRealTime=concurrentQueue.Key={3}=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace, concurrentQueue.Key); |
|||
} |
|||
} |
|||
AddMsg1(_persistenceGpsNo.ToString()); |
|||
AddMsg2(_persistenceCarGpsNo.ToString()); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("timer2_Tick=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
|
|||
// 定时器:持久化gps数据到轨迹表。
|
|||
private void timer3_Tick(object sender, EventArgs e) |
|||
{ |
|||
if (_appState != AppState.Started) return; |
|||
PersistenceCarGps(); |
|||
} |
|||
|
|||
// 定时器:分析Gps离线后关闭车辆Acc开关。
|
|||
private void timer4_Tick(object sender, EventArgs e) |
|||
{ |
|||
if (_appState != AppState.Started) return; |
|||
UpdateGpsRealTimeAccState(); |
|||
} |
|||
/// <summary>
|
|||
/// 离线时关闭车辆的Acc状态
|
|||
/// </summary>
|
|||
public void UpdateGpsRealTimeAccState() |
|||
{ |
|||
try |
|||
{ |
|||
var list = GpsRealTimeRepository.GetOffLineGpsRealTime(); |
|||
if(!list.Any()) return; |
|||
|
|||
var offLineList = list.ConvertAll(x => new GpsModel |
|||
{ |
|||
Acc = 0, |
|||
Work = 0, |
|||
// VehicleId =x.VehicleId,
|
|||
// SimNo = x.SimNo,
|
|||
// CompanyId = x.CompanyId ,
|
|||
// Longitude = x.Longitude,
|
|||
// Latitude = x.Latitude,
|
|||
// Speed = x.Speed,
|
|||
// Direct = x.Direct,
|
|||
GpsState = 0, |
|||
//GpsTime = x.GpsTime,
|
|||
// RecTime = x.RecTime,
|
|||
//Address = x.Address,
|
|||
DurationTime = "", |
|||
AccDurationTime = "", |
|||
WorkDurationTime = "", |
|||
}); |
|||
offLineList.ForEach(x => |
|||
{ |
|||
FirstStatusCacheService(x,(int)StatusEnum.Acc); |
|||
FirstStatusCacheService(x, (int)StatusEnum.Work); |
|||
GpsRealTimeRepository.UpdateGpsRealTimeGpsStateWrt(x); |
|||
}); |
|||
this.Log().InfoFormat("更改Acc状态,更新车辆{0}辆", offLineList.Count); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("UpdateGpsRealTimeAccState=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
|
|||
// 持久化gps数据到轨迹表。
|
|||
private void PersistenceCarGps() |
|||
{ |
|||
|
|||
|
|||
this.Log().Debug("PersistenceCarGps"); |
|||
try |
|||
{ |
|||
foreach (var concurrentQueue in MApplication.CarConcurrentQueues) |
|||
{ |
|||
try |
|||
{ |
|||
if (concurrentQueue.Value.Count == 0) continue; |
|||
var models = new List<GpsModel>(); |
|||
while (true) |
|||
{ |
|||
GpsModel model; |
|||
if (concurrentQueue.Value.TryDequeue(out model)) |
|||
{ |
|||
models.Add(model); |
|||
_persistenceCarGpsNo--; |
|||
} |
|||
else |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
string tableName = "Car_" + concurrentQueue.Key + "_" + DateTime.Now.ToString("yyyyMM"); |
|||
//string tableName = "CarGps_" + concurrentQueue.Key + "_test2_" + DateTime.Now.ToString("yyyyMM");
|
|||
//测试
|
|||
//插入数据到mongodb中。
|
|||
CarGpsRepository.InsertCarGpsList(models, tableName); |
|||
_savePsNo += models.Count; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("PersistenceCarGps持久化gps数据到Car表异常=concurrentQueue.Key={3}=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace, concurrentQueue.Key); |
|||
} |
|||
} |
|||
AddMsg2(_persistenceCarGpsNo.ToString()); |
|||
AddMsg3(_savePsNo.ToString()); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Log().ErrorFormat("PersistenceCarGps=报错=,ex.Message={0},ex.InnerException={1},ex.StackTrace={2}", |
|||
ex.Message, ex.InnerException, ex.StackTrace); |
|||
} |
|||
} |
|||
|
|||
//分析车辆任务状态
|
|||
//分析车辆状态:0:离线,1:移动[在线],2:短停[在线],3:长停[在线]
|
|||
//分析车辆长停短停离线持续时间。
|
|||
//分析订单状态是否【已出发】【已到达】【作业中】,有开启gps分析才会分析这个。订单状态:0未指派、1已指派、2已接单、3已出发、4已完成、5已删除、6已到达、7作业中、8已作废、9已撤销
|
|||
private void AnalysesGpsState(GpsModel lastModel) |
|||
{ |
|||
var car = SqlRepository.Cars.FirstOrDefault(s => s.Id == lastModel.VehicleId); |
|||
if(car == null) return; |
|||
var gpsState = GpsStateEnum.OffLine.ToInt(); //Gps时间>15min则表示离线
|
|||
var durationTime = ""; //gps持续时长
|
|||
//int Acc = 0; //Acc状态
|
|||
var AccDurationTime = ""; //Acc持续时长
|
|||
var workDurationTime = ""; //Acc持续时长
|
|||
var time = DateTime.Now - lastModel.GpsTime; |
|||
durationTime = CalculationGpsHelper.TimeSpanFormat(time);//持续时长,长停短停的。//默认为离线持续时长
|
|||
AccDurationTime = durationTime; //默认跟gps时长一致。
|
|||
if (time.TotalMinutes <= 15)//表示在线
|
|||
{ |
|||
gpsState = GpsStateEnum.Motionless.ToInt();//静止
|
|||
if (lastModel.Speed > 0) |
|||
{ |
|||
gpsState = GpsStateEnum.Moving.ToInt();//移动
|
|||
durationTime = ""; |
|||
} |
|||
else |
|||
{ |
|||
var haveSpeedModel = RedisRepository.GetLastHaveSpeed(lastModel); |
|||
if (haveSpeedModel != null) |
|||
{ |
|||
var time2 = DateTime.Now - haveSpeedModel.GpsTime; |
|||
durationTime = CalculationGpsHelper.TimeSpanFormat(time2); |
|||
} |
|||
} |
|||
//分析Acc持续时长
|
|||
var firstAccModel = RedisRepository.GetFirstStatus(lastModel, (int) StatusEnum.Acc); |
|||
if (firstAccModel != null) |
|||
{ |
|||
var time3 = DateTime.Now - firstAccModel.GpsTime; |
|||
AccDurationTime = CalculationGpsHelper.TimeSpanFormat(time3); |
|||
} |
|||
//分析作业持续时长
|
|||
var firstWorkModel = RedisRepository.GetFirstStatus(lastModel, (int)StatusEnum.Work); |
|||
if (firstWorkModel != null) |
|||
{ |
|||
var time3 = DateTime.Now - firstWorkModel.GpsTime; |
|||
workDurationTime = CalculationGpsHelper.TimeSpanFormat(time3); |
|||
} |
|||
} |
|||
//=======================更新车辆实时状态==========================
|
|||
//MyGpsServer.UpdateGpsRealTimeGpsState(car, gpsState, durationTime, AccDurationTime);
|
|||
GpsRealTimeRepository.UpdateGpsRealTimeGpsState(car, gpsState, durationTime, AccDurationTime, |
|||
workDurationTime); |
|||
//=======================更新车辆实时状态==========================
|
|||
|
|||
//========分析订单状态(公司已开启订单分析),更改订单的State:已出发,已到达,作业中=================
|
|||
//找到此车辆所属公司
|
|||
var company = SqlRepository.Companys.Find(s => s.Id == 99999); |
|||
if (company != null) |
|||
{ |
|||
//找到此车辆所有订单
|
|||
var ods = SqlRepository.Orders.FindAll(s => s.VehicleId == car.Id); |
|||
if (ods.Any()) |
|||
{ |
|||
foreach (var odModel in ods) |
|||
{ |
|||
//分析:已出发//已接单的才能进行此分析。
|
|||
var flag1 = odModel.State == ViOrderStateEnum.Accepted.ToInt(); |
|||
var flag3 = odModel.State == ViOrderStateEnum.SetOut.ToInt(); |
|||
if (flag1) |
|||
{ |
|||
var distance = CalculationGpsHelper.GetDistance((double)lastModel.Longitude, (double)lastModel.Latitude, |
|||
company.Longitude, company.Latitude); |
|||
if (distance > _setOutRadius && !ods.Exists(s => s.Id != odModel.Id && s.State != 1)) |
|||
{ |
|||
if (CarService.ExistThisStateOrder(odModel.Id, ViOrderStateEnum.SetOut.ToInt())) |
|||
MyGpsServer.UpdateOrderState(odModel.Id, ViOrderStateEnum.SetOut.ToInt(), DateTime.Now); |
|||
} |
|||
} |
|||
//分析:已到达//已接单或已出发才能进行此分析。
|
|||
if (flag1 || flag3) |
|||
{ |
|||
var distance2 = CalculationGpsHelper.GetDistance((double)lastModel.Longitude, (double)lastModel.Latitude, |
|||
(double)odModel.Longitude, (double)odModel.Latitude); |
|||
if (distance2 < _arriveRadius) |
|||
{ |
|||
if (CarService.ExistThisStateOrder(odModel.Id, ViOrderStateEnum.Arrive.ToInt())) |
|||
MyGpsServer.UpdateOrderState(odModel.Id, ViOrderStateEnum.Arrive.ToInt(), DateTime.Now); |
|||
} |
|||
} |
|||
var flag5 = odModel.State == ViOrderStateEnum.Arrive.ToInt(); |
|||
//分析:作业中//已到达且到达时间大于5分钟,则为工作中
|
|||
if (flag5 && odModel.ArriveTime.Year > 1900) |
|||
{ |
|||
var ts = DateTime.Now - odModel.ArriveTime; |
|||
if (ts.Minutes > 5) |
|||
{ |
|||
if (CarService.ExistThisStateOrder(odModel.Id, ViOrderStateEnum.Working.ToInt())) |
|||
MyGpsServer.UpdateOrderState(odModel.Id, ViOrderStateEnum.Working.ToInt(), DateTime.Now); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 车辆最后存在速度的GPS时间
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <returns></returns>
|
|||
public void LastHaveSpeedCacheService(GpsModel model) |
|||
{ |
|||
if (RedisRepository.IsSetLastHaveSpeed(model) && model.Speed <= 0) return; |
|||
RedisRepository.SetLastHaveSpeed(model); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 车辆Acc/作业状态第一次开启的时间
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <param name="type">1Acc,2Work</param>
|
|||
/// <returns></returns>
|
|||
public void FirstStatusCacheService(GpsModel model,int type) |
|||
{ |
|||
if (type == (int)StatusEnum.Acc && model.Acc == -1) return; |
|||
if (type == (int)StatusEnum.Work && model.Work == -1) return; |
|||
|
|||
if (!RedisRepository.IsSetFirstStatus(model, type)) |
|||
{ |
|||
RedisRepository.SetFirstStatus(model, type); |
|||
} |
|||
else |
|||
{ |
|||
|
|||
var redisModel = RedisRepository.GetFirstStatus(model, type); |
|||
switch (type) |
|||
{ |
|||
case (int) StatusEnum.Acc: |
|||
{ |
|||
if (redisModel == null || redisModel.Acc == model.Acc) return; |
|||
break; |
|||
} |
|||
|
|||
case (int)StatusEnum.Work: |
|||
{ |
|||
if (redisModel == null || redisModel.Work == model.Work) return; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
RedisRepository.SetFirstStatus(model, type); |
|||
|
|||
var entity = new GpsCarStatusDurationModel |
|||
{ |
|||
VehicleId = model.VehicleId, |
|||
CompanyId = model.CompanyId, |
|||
Code = model.VehicleCode, |
|||
VehicleName = model.VehiclePlate, |
|||
State = type == (int) StatusEnum.Acc ? model.Acc : model.Work, |
|||
DurationTime = CalculationGpsHelper.TimeSpanFormat(model.GpsTime - redisModel.GpsTime), |
|||
TimeBegin = redisModel.GpsTime, |
|||
TimeEnd = model.GpsTime, |
|||
CreatedTime = DateTime.Now, |
|||
ModifiedTime = DateTime.Now, |
|||
Type = type |
|||
}; |
|||
|
|||
//Acc变更,则保存Acc持续时长
|
|||
GpsRealTimeRepository.AddGpsCarStatusDuration(entity); |
|||
|
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
public enum AppState |
|||
{ |
|||
Starting, Started, Stoping, Stoped, Error |
|||
} |
|||
} |
@ -0,0 +1,132 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<root> |
|||
<!-- |
|||
Microsoft ResX Schema |
|||
|
|||
Version 2.0 |
|||
|
|||
The primary goals of this format is to allow a simple XML format |
|||
that is mostly human readable. The generation and parsing of the |
|||
various data types are done through the TypeConverter classes |
|||
associated with the data types. |
|||
|
|||
Example: |
|||
|
|||
... ado.net/XML headers & schema ... |
|||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
|||
<resheader name="version">2.0</resheader> |
|||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
|||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
|||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
|||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
|||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
|||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
|||
</data> |
|||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
|||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
|||
<comment>This is a comment</comment> |
|||
</data> |
|||
|
|||
There are any number of "resheader" rows that contain simple |
|||
name/value pairs. |
|||
|
|||
Each data row contains a name, and value. The row also contains a |
|||
type or mimetype. Type corresponds to a .NET class that support |
|||
text/value conversion through the TypeConverter architecture. |
|||
Classes that don't support this are serialized and stored with the |
|||
mimetype set. |
|||
|
|||
The mimetype is used for serialized objects, and tells the |
|||
ResXResourceReader how to depersist the object. This is currently not |
|||
extensible. For a given mimetype the value must be set Accordingly: |
|||
|
|||
Note - application/x-microsoft.net.object.binary.base64 is the format |
|||
that the ResXResourceWriter will generate, however the reader can |
|||
read any of the formats listed below. |
|||
|
|||
mimetype: application/x-microsoft.net.object.binary.base64 |
|||
value : The object must be serialized with |
|||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
|||
: and then encoded with base64 encoding. |
|||
|
|||
mimetype: application/x-microsoft.net.object.soap.base64 |
|||
value : The object must be serialized with |
|||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
|||
: and then encoded with base64 encoding. |
|||
|
|||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
|||
value : The object must be serialized into a byte array |
|||
: using a System.ComponentModel.TypeConverter |
|||
: and then encoded with base64 encoding. |
|||
--> |
|||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
|||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
|||
<xsd:element name="root" msdata:IsDataSet="true"> |
|||
<xsd:complexType> |
|||
<xsd:choice maxOccurs="unbounded"> |
|||
<xsd:element name="metadata"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
|||
<xsd:attribute name="type" type="xsd:string" /> |
|||
<xsd:attribute name="mimetype" type="xsd:string" /> |
|||
<xsd:attribute ref="xml:space" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="assembly"> |
|||
<xsd:complexType> |
|||
<xsd:attribute name="alias" type="xsd:string" /> |
|||
<xsd:attribute name="name" type="xsd:string" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="data"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
|||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
|||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
|||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
|||
<xsd:attribute ref="xml:space" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="resheader"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
</xsd:choice> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
</xsd:schema> |
|||
<resheader name="resmimetype"> |
|||
<value>text/microsoft-resx</value> |
|||
</resheader> |
|||
<resheader name="version"> |
|||
<value>2.0</value> |
|||
</resheader> |
|||
<resheader name="reader"> |
|||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
|||
</resheader> |
|||
<resheader name="writer"> |
|||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
|||
</resheader> |
|||
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
|||
<value>104, 17</value> |
|||
</metadata> |
|||
<metadata name="timer2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
|||
<value>191, 17</value> |
|||
</metadata> |
|||
<metadata name="timer3.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
|||
<value>278, 17</value> |
|||
</metadata> |
|||
<metadata name="timer4.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
|||
<value>17, 17</value> |
|||
</metadata> |
|||
</root> |
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using System.IO; |
|||
using System.Windows.Forms; |
|||
namespace GPSServer |
|||
{ |
|||
static class Program |
|||
{ |
|||
// public static SqlCarService carService = new SqlCarService();
|
|||
/// <summary>
|
|||
/// 应用程序的主入口点。
|
|||
/// </summary>
|
|||
[STAThread] |
|||
static void Main() |
|||
{ |
|||
var configName = System.AppDomain.CurrentDomain.BaseDirectory + @"log4net.config"; |
|||
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(configName)); |
|||
Application.EnableVisualStyles(); |
|||
Application.SetCompatibleTextRenderingDefault(false); |
|||
Application.Run(new Main()); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
// 有关程序集的常规信息通过以下
|
|||
// 特性集控制。更改这些特性值可修改
|
|||
// 与程序集关联的信息。
|
|||
[assembly: AssemblyTitle("GPSServer")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("China")] |
|||
[assembly: AssemblyProduct("GPSServer")] |
|||
[assembly: AssemblyCopyright("Copyright © China 2017")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
|||
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
|
|||
// 则将该类型上的 ComVisible 特性设置为 true。
|
|||
[assembly: ComVisible(false)] |
|||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
|||
[assembly: Guid("c3cddb9d-fbc0-451f-bf46-5bf0b5ab5010")] |
|||
// 程序集的版本信息由下面四个值组成:
|
|||
//
|
|||
// 主版本
|
|||
// 次版本
|
|||
// 生成号
|
|||
// 修订号
|
|||
//
|
|||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
|||
// 方法是按如下所示使用“*”:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "./log4net.config", ConfigFileExtension = "config", Watch = true)] |
@ -0,0 +1,63 @@ |
|||
//------------------------------------------------------------------------------
|
|||
// <auto-generated>
|
|||
// 此代码由工具生成。
|
|||
// 运行时版本:4.0.30319.42000
|
|||
//
|
|||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
|||
// 重新生成代码,这些更改将会丢失。
|
|||
// </auto-generated>
|
|||
//------------------------------------------------------------------------------
|
|||
|
|||
namespace GPSServer.Properties { |
|||
using System; |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
|||
/// </summary>
|
|||
// 此类是由 StronglyTypedResourceBuilder
|
|||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
|||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
|||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
|||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] |
|||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
|||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
|||
internal class Resources { |
|||
|
|||
private static global::System.Resources.ResourceManager resourceMan; |
|||
|
|||
private static global::System.Globalization.CultureInfo resourceCulture; |
|||
|
|||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
|||
internal Resources() { |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 返回此类使用的缓存的 ResourceManager 实例。
|
|||
/// </summary>
|
|||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] |
|||
internal static global::System.Resources.ResourceManager ResourceManager { |
|||
get { |
|||
if (object.ReferenceEquals(resourceMan, null)) { |
|||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GPSServer.Properties.Resources", typeof(Resources).Assembly); |
|||
resourceMan = temp; |
|||
} |
|||
return resourceMan; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 重写当前线程的 CurrentUICulture 属性,对
|
|||
/// 使用此强类型资源类的所有资源查找执行重写。
|
|||
/// </summary>
|
|||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] |
|||
internal static global::System.Globalization.CultureInfo Culture { |
|||
get { |
|||
return resourceCulture; |
|||
} |
|||
set { |
|||
resourceCulture = value; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,106 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<root> |
|||
<!-- |
|||
Microsoft ResX Schema |
|||
Version 2.0 |
|||
The primary goals of this format is to allow a simple XML format |
|||
that is mostly human readable. The generation and parsing of the |
|||
various data types are done through the TypeConverter classes |
|||
associated with the data types. |
|||
Example: |
|||
... ado.net/XML headers & schema ... |
|||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
|||
<resheader name="version">2.0</resheader> |
|||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
|||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
|||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
|||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
|||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
|||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
|||
</data> |
|||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
|||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
|||
<comment>This is a comment</comment> |
|||
</data> |
|||
There are any number of "resheader" rows that contain simple |
|||
name/value pairs. |
|||
Each data row contains a name, and value. The row also contains a |
|||
type or mimetype. Type corresponds to a .NET class that support |
|||
text/value conversion through the TypeConverter architecture. |
|||
Classes that don't support this are serialized and stored with the |
|||
mimetype set. |
|||
The mimetype is used for serialized objects, and tells the |
|||
ResXResourceReader how to depersist the object. This is currently not |
|||
extensible. For a given mimetype the value must be set Accordingly: |
|||
Note - application/x-microsoft.net.object.binary.base64 is the format |
|||
that the ResXResourceWriter will generate, however the reader can |
|||
read any of the formats listed below. |
|||
mimetype: application/x-microsoft.net.object.binary.base64 |
|||
value : The object must be serialized with |
|||
: System.Serialization.Formatters.Binary.BinaryFormatter |
|||
: and then encoded with base64 encoding. |
|||
mimetype: application/x-microsoft.net.object.soap.base64 |
|||
value : The object must be serialized with |
|||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
|||
: and then encoded with base64 encoding. |
|||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
|||
value : The object must be serialized into a byte array |
|||
: using a System.ComponentModel.TypeConverter |
|||
: and then encoded with base64 encoding. |
|||
--> |
|||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
|||
<xsd:element name="root" msdata:IsDataSet="true"> |
|||
<xsd:complexType> |
|||
<xsd:choice maxOccurs="unbounded"> |
|||
<xsd:element name="metadata"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" /> |
|||
<xsd:attribute name="type" type="xsd:string" /> |
|||
<xsd:attribute name="mimetype" type="xsd:string" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="assembly"> |
|||
<xsd:complexType> |
|||
<xsd:attribute name="alias" type="xsd:string" /> |
|||
<xsd:attribute name="name" type="xsd:string" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="data"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
|||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> |
|||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
|||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="resheader"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
</xsd:choice> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
</xsd:schema> |
|||
<resheader name="resmimetype"> |
|||
<value>text/microsoft-resx</value> |
|||
</resheader> |
|||
<resheader name="version"> |
|||
<value>2.0</value> |
|||
</resheader> |
|||
<resheader name="reader"> |
|||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
|||
</resheader> |
|||
<resheader name="writer"> |
|||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
|||
</resheader> |
|||
</root> |
@ -0,0 +1,26 @@ |
|||
//------------------------------------------------------------------------------
|
|||
// <auto-generated>
|
|||
// 此代码由工具生成。
|
|||
// 运行时版本:4.0.30319.42000
|
|||
//
|
|||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
|||
// 重新生成代码,这些更改将会丢失。
|
|||
// </auto-generated>
|
|||
//------------------------------------------------------------------------------
|
|||
|
|||
namespace GPSServer.Properties { |
|||
|
|||
|
|||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
|||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] |
|||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { |
|||
|
|||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); |
|||
|
|||
public static Settings Default { |
|||
get { |
|||
return defaultInstance; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
<?xml version='1.0' encoding='utf-8'?> |
|||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)"> |
|||
<Profiles> |
|||
<Profile Name="(Default)" /> |
|||
</Profiles> |
|||
<Settings /> |
|||
</SettingsFile> |
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0"?> |
|||
<configuration> |
|||
<connectionStrings> |
|||
<!--<add name="ZNYCProjectGps" connectionString="Server=172.16.0.6; Port=3306; Database=znyc_dispatching; Uid=znyc; Pwd=UhcAoRR5A3hnt^%U; Charset=utf8mb4" providerName="System.Data.SqlClient"/>--> |
|||
<add name="ZNYCProjectGps" connectionString=" Server=42.194.147.251; Port=43306; Database=znyc_dispatching; Uid=guest; Pwd=4Y2e2WtekfDYWfT8; Charset=utf8mb4" providerName="System.Data.SqlClient"/> |
|||
</connectionStrings> |
|||
<appSettings> |
|||
<!--<add key="MongodbServers" value="mongodb://172.16.0.16:27017"/>--> |
|||
<add key="MongodbServers" value="mongodb://42.194.147.251:27018"/> |
|||
<add key="MongoDBName" value="ZNYCGPS"/> |
|||
<!--Redis中存储token的Db,0开始,生产--> |
|||
<!--<add key="RedisConnectionString" value="172.16.0.17:6379,defaultDatabase=6"/>--> |
|||
<add key="RedisConnectionString" value="42.194.147.251:6379,password=vtgA9HXFQQYA9g8Z"/> |
|||
<add key="RedisAnalysisDb" value="1"/> |
|||
<!--百度经纬度转换--> |
|||
<add key="BaiduApiUrl" value="http://api.map.baidu.com"/> |
|||
<add key="BaiduAk" value="9NbBNl5UeGI7Fa3ym7CqTa7t9iUqEtNL"/> |
|||
<!--出厂区公司半径--> |
|||
<add key="SetOutRadius" value="500"/> |
|||
<!--到达工地半径--> |
|||
<add key="ArriveRadius" value="500"/> |
|||
<!--线上生产--> |
|||
<add key="GpsRealTimeTableName" value="GpsRealTime"/> |
|||
<!--线上生产--> |
|||
<add key="GpsCarStatusDurationTableName" value="GpsCarStatusDuration"/> |
|||
</appSettings> |
|||
<startup> |
|||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/> |
|||
</startup> |
|||
</configuration> |
@ -0,0 +1,106 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<configuration> |
|||
<configSections> |
|||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> |
|||
</configSections> |
|||
|
|||
<log4net> |
|||
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender" > |
|||
<!--日志路径--> |
|||
<param name= "File" value= "C:\LogFile\GPSServer9999\info"/> |
|||
<!--是否是向文件中追加日志--> |
|||
<param name= "AppendToFile" value= "true"/> |
|||
<!--log保留天数--> |
|||
<param name= "MaxSizeRollBackups" value= "10"/> |
|||
<!--日志文件名是否是固定不变的--> |
|||
<param name= "StaticLogFileName" value= "false"/> |
|||
<!--日志文件名格式为:2008-08-31.log--> |
|||
<param name= "DatePattern" value= "yyyy-MM-dd".log""/> |
|||
<!--日志根据日期滚动%n%d-%type:%method:%m--> |
|||
<param name= "RollingStyle" value= "Date"/> |
|||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/> |
|||
<layout type="log4net.Layout.PatternLayout"> |
|||
<param name="ConversionPattern" value="%n%d-%m" /> |
|||
</layout> |
|||
<filter type="log4net.Filter.LevelRangeFilter"> |
|||
<param name="LevelMin" value="Info" /> |
|||
<param name="LevelMax" value="Info" /> |
|||
</filter> |
|||
</appender> |
|||
<appender name="ErrorLogFileAppender" type="log4net.Appender.RollingFileAppender" > |
|||
<!--日志路径--> |
|||
<param name= "File" value= "C:\LogFile\GPSServer9999\error"/> |
|||
<!--是否是向文件中追加日志--> |
|||
<param name= "AppendToFile" value= "true"/> |
|||
<!--log保留天数--> |
|||
<param name= "MaxSizeRollBackups" value= "10"/> |
|||
<!--日志文件名是否是固定不变的--> |
|||
<param name= "StaticLogFileName" value= "false"/> |
|||
<!--日志文件名格式为:2008-08-31.log--> |
|||
<param name= "DatePattern" value= "yyyy-MM-dd".log""/> |
|||
<!--日志根据日期滚动--> |
|||
<param name= "RollingStyle" value= "Date"/> |
|||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/> |
|||
<layout type="log4net.Layout.PatternLayout"> |
|||
<param name="ConversionPattern" value="%n%d-%m" /> |
|||
</layout> |
|||
<filter type="log4net.Filter.LevelRangeFilter"> |
|||
<param name="LevelMin" value="Error" /> |
|||
<param name="LevelMax" value="Error" /> |
|||
</filter> |
|||
</appender> |
|||
<appender name="DebugLogFileAppender" type="log4net.Appender.RollingFileAppender" > |
|||
<!--日志路径--> |
|||
<param name= "File" value= "C:\LogFile\GPSServer9999\Debug"/> |
|||
<!--是否是向文件中追加日志--> |
|||
<param name= "AppendToFile" value= "true"/> |
|||
<!--log保留天数--> |
|||
<param name= "MaxSizeRollBackups" value= "10"/> |
|||
<!--日志文件名是否是固定不变的--> |
|||
<param name= "StaticLogFileName" value= "false"/> |
|||
<!--日志文件名格式为:2008-08-31.log--> |
|||
<param name= "DatePattern" value= "yyyy-MM-dd".log""/> |
|||
<!--日志根据日期滚动--> |
|||
<param name= "RollingStyle" value= "Date"/> |
|||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/> |
|||
<layout type="log4net.Layout.PatternLayout"> |
|||
<param name="ConversionPattern" value="%n%d-%m" /> |
|||
</layout> |
|||
<filter type="log4net.Filter.LevelRangeFilter"> |
|||
<param name="LevelMin" value="Debug" /> |
|||
<param name="LevelMax" value="Debug" /> |
|||
</filter> |
|||
</appender> |
|||
<appender name="WarnLogFileAppender" type="log4net.Appender.RollingFileAppender" > |
|||
<!--日志路径--> |
|||
<param name= "File" value= "C:\LogFile\GPSServer9999\Warn"/> |
|||
<!--是否是向文件中追加日志--> |
|||
<param name= "AppendToFile" value= "true"/> |
|||
<!--log保留天数--> |
|||
<param name= "MaxSizeRollBackups" value= "10"/> |
|||
<!--日志文件名是否是固定不变的--> |
|||
<param name= "StaticLogFileName" value= "false"/> |
|||
<!--日志文件名格式为:2008-08-31.log--> |
|||
<param name= "DatePattern" value= "yyyy-MM-dd".log""/> |
|||
<!--日志根据日期滚动--> |
|||
<param name= "RollingStyle" value= "Date"/> |
|||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/> |
|||
<layout type="log4net.Layout.PatternLayout"> |
|||
<param name="ConversionPattern" value="%n%d-%m" /> |
|||
</layout> |
|||
<filter type="log4net.Filter.LevelRangeFilter"> |
|||
<param name="LevelMin" value="Warn" /> |
|||
<param name="LevelMax" value="Warn" /> |
|||
</filter> |
|||
</appender> |
|||
<root> |
|||
<!--(高) OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL (低) --> |
|||
<level value="ALL" /> |
|||
<appender-ref ref="ColoredConsoleAppender"/> |
|||
<appender-ref ref="RollingLogFileAppender"/> |
|||
<appender-ref ref="ErrorLogFileAppender"/> |
|||
<appender-ref ref="DebugLogFileAppender"/> |
|||
<appender-ref ref="WarnLogFileAppender"/> |
|||
</root> |
|||
</log4net> |
|||
</configuration> |
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace GpsModels |
|||
{ |
|||
public class BaseStationModel |
|||
{ |
|||
public int infocode { get; set; } |
|||
|
|||
public Result result { get; set; } |
|||
|
|||
} |
|||
|
|||
public class Result |
|||
{ |
|||
public string location { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,74 @@ |
|||
using System; |
|||
|
|||
namespace GpsModels |
|||
{ |
|||
public class CarGpsModel |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆id
|
|||
/// </summary>
|
|||
public long VehicleId { get; set; } |
|||
/// <summary>
|
|||
/// 车辆id
|
|||
/// </summary>
|
|||
public long CompanyId { get; set; } |
|||
/// <summary>
|
|||
/// 通讯SIM卡号
|
|||
/// </summary>
|
|||
public string SimNo { get; set; } |
|||
/// <summary>
|
|||
/// 车牌号
|
|||
/// </summary>
|
|||
public string VehiclePlate { get; set; } |
|||
/// <summary>
|
|||
/// 车辆编号
|
|||
/// </summary>
|
|||
public string VehicleCode { get; set; } |
|||
/// <summary>
|
|||
/// 经度
|
|||
/// </summary>
|
|||
public decimal Longitude { get; set; } |
|||
/// <summary>
|
|||
/// 纬度
|
|||
/// </summary>
|
|||
public decimal Latitude { get; set; } |
|||
/// <summary>
|
|||
/// 速度
|
|||
/// </summary>
|
|||
public int Speed { get; set; } |
|||
/// <summary>
|
|||
/// 方向
|
|||
/// </summary>
|
|||
public int Direct { get; set; } |
|||
/// <summary>
|
|||
/// 位置基本信息状态位,后期派工易用来做车辆的gps状态:GPS在线情况(0:离线,1:移动[在线],2:短停[在线],3:长停[在线])
|
|||
/// </summary>
|
|||
public int GpsState { get; set; } |
|||
/// <summary>
|
|||
/// Gps数据产生时间
|
|||
/// </summary>
|
|||
public DateTime GpsTime { get; set; } |
|||
/// <summary>
|
|||
/// Gps数据接收时间
|
|||
/// </summary>
|
|||
public DateTime RecTime { get; set; } |
|||
/// <summary>
|
|||
/// Acc状态(震动,判断是否点火)
|
|||
/// </summary>
|
|||
public int Acc { get; set; } |
|||
/// <summary>
|
|||
/// 作业状态(通电判断是否作业)
|
|||
/// </summary>
|
|||
public int Work { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 地址
|
|||
/// </summary>
|
|||
public string Address { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gps信号模式 1 GPS,2 基站
|
|||
/// </summary>
|
|||
public int GpsMode { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
namespace GpsModels |
|||
{ |
|||
public class CompanyModel |
|||
{ |
|||
public long Id { get; set; } |
|||
public string CompanyName { get; set; } |
|||
public double Longitude { get; set; } |
|||
public double Latitude { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
namespace GpsModels |
|||
{ |
|||
|
|||
public static class EnumExtension |
|||
{ |
|||
public static int ToInt(this ViOrderStateEnum sucEnum) |
|||
{ |
|||
return (int)sucEnum; |
|||
} |
|||
public static int ToInt(this GpsStateEnum sucEnum) |
|||
{ |
|||
return (int)sucEnum; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Bson.Serialization.Attributes; |
|||
|
|||
namespace GpsModels |
|||
{ |
|||
[BsonIgnoreExtraElements] |
|||
public class GpsCarStatusDurationModel |
|||
{ |
|||
public long VehicleId { get; set; } |
|||
public long CompanyId { get; set; } |
|||
public string Code { get; set; } |
|||
public string VehicleName { get; set; } |
|||
public int State { get; set; } |
|||
public string DurationTime { get; set; } |
|||
/// <summary>
|
|||
/// 状态 1Acc 2作业状态
|
|||
/// </summary>
|
|||
public int Type { get; set; } |
|||
[BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)] |
|||
public DateTime TimeBegin { get; set; } |
|||
[BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)] |
|||
public DateTime TimeEnd { get; set; } |
|||
public string Record { get; set; } |
|||
[BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)] |
|||
public DateTime ModifiedTime { get; set; } |
|||
[BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)] |
|||
public DateTime CreatedTime { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
namespace GpsModels |
|||
{ |
|||
public class GpsModel:CarGpsModel |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆启用状态0:启用,1启用。-->车辆在地图的状态,后面分析GpsState:(0:休-停用中;1:闲-可执行;2:忙-任务中)。
|
|||
/// </summary>
|
|||
public int Status { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 司机联系人
|
|||
/// </summary>
|
|||
public string ContactPerson { get; set; } |
|||
/// <summary>
|
|||
/// 司机联系电话
|
|||
/// </summary>
|
|||
public string ContactPhone { get; set; } |
|||
/// <summary>
|
|||
/// 文本地址
|
|||
/// </summary>
|
|||
public string Address { get; set; } |
|||
/// <summary>
|
|||
/// 停留时长,这个后期再查询时,根据与gps当前时间进行比较。
|
|||
/// </summary>
|
|||
public string DurationTime { get; set; } |
|||
/// <summary>
|
|||
/// Acc持续时长,开启或关闭的持续时长
|
|||
/// </summary>
|
|||
public string AccDurationTime { get; set; } |
|||
/// <summary>
|
|||
/// 作业持续时长,开启或关闭的持续时长
|
|||
/// </summary>
|
|||
public string WorkDurationTime { get; set; } |
|||
/// <summary>
|
|||
/// --欠压
|
|||
/// </summary>
|
|||
public int GpsAlert { get; set; } |
|||
/// <summary>
|
|||
/// 掉电
|
|||
/// </summary>
|
|||
public int Useing { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// gps品牌
|
|||
/// 1 博实结KM02-2线
|
|||
/// 2 速联星空-点烟器
|
|||
/// 3 博实结KM02-4线
|
|||
/// 4 沃瑞特C12
|
|||
/// </summary>
|
|||
public int TerminalType { get; set; } |
|||
/// <summary>
|
|||
/// 定位状态 0未定位,1已定位
|
|||
/// </summary>
|
|||
public int LocationStatus{ get; set; } |
|||
} |
|||
} |
@ -0,0 +1,74 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{275FE3F1-11A3-46F5-8320-493926113C9E}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>GpsModels</RootNamespace> |
|||
<AssemblyName>GpsModels</AssemblyName> |
|||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<TargetFrameworkProfile /> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="MongoDB.Bson"> |
|||
<HintPath>..\lib\MongoDB.Bson.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="MongoDB.Driver"> |
|||
<HintPath>..\lib\MongoDB.Driver.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="MongoDB.Driver.Core"> |
|||
<HintPath>..\lib\MongoDB.Driver.Core.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Data.DataSetExtensions" /> |
|||
<Reference Include="Microsoft.CSharp" /> |
|||
<Reference Include="System.Data" /> |
|||
<Reference Include="System.Xml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="BaseStationModel.cs" /> |
|||
<Compile Include="CarGpsModel.cs" /> |
|||
<Compile Include="CompanyModel.cs" /> |
|||
<Compile Include="GpsCarAccDurationModel.cs" /> |
|||
<Compile Include="GpsModel.cs" /> |
|||
<Compile Include="GpsRealTimeModel.cs" /> |
|||
<Compile Include="OrderModel.cs" /> |
|||
<Compile Include="PointLatLng.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
<Compile Include="EnumExtension.cs" /> |
|||
<Compile Include="VehicleModel.cs" /> |
|||
<Compile Include="GpsStateEnum.cs" /> |
|||
<Compile Include="ViOrderStateEnum.cs" /> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
@ -0,0 +1,131 @@ |
|||
using System; |
|||
using MongoDB.Bson.Serialization.Attributes; |
|||
namespace GpsModels |
|||
{ |
|||
[BsonIgnoreExtraElements] |
|||
public class GpsRealTimeModel |
|||
{ |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public long VehicleId { get; set; } |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public string VehicleCode { get; set; } |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public string VehiclePlate { get; set; } |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public long VehicleDriver { get; set; } |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public string DriverPhone { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public int Status { get; set; } |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public int GpsState { get; set; } |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
[BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)] |
|||
public DateTime GpsTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
[BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)] |
|||
public DateTime RecTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public decimal Longitude { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public decimal Latitude { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public int Direct { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public int Speed { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public string DurationTime { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public int Acc { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public string AccDurationTime { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public int Work { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public string WorkDurationTime { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public string Address { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public string SimNo { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public long CompanyId { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
[BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)] |
|||
public DateTime ModifiedTime { get; set; } |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
[BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)] |
|||
public DateTime CreatedTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gps信号模式 1 GPS,2 基站
|
|||
/// </summary>
|
|||
public int GpsMode { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 欠压
|
|||
/// </summary>
|
|||
public int GpsAlert { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 掉电
|
|||
/// </summary>
|
|||
public int Useing { get; set; } |
|||
|
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
using System.ComponentModel; |
|||
|
|||
namespace GpsModels |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆定位状态,地图监控列表显示:移动,静止,离线。
|
|||
/// </summary>
|
|||
public enum GpsStateEnum |
|||
{ |
|||
/// <summary>
|
|||
/// 0离线
|
|||
/// </summary>
|
|||
[Description("离线")] |
|||
OffLine = 0, |
|||
/// <summary>
|
|||
/// 1移动
|
|||
/// </summary>
|
|||
[Description("移动")] |
|||
Moving = 1, |
|||
|
|||
/// <summary>
|
|||
/// 2静止
|
|||
/// </summary>
|
|||
[Description("静止")] |
|||
Motionless = 2, |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
using System; |
|||
|
|||
namespace GpsModels |
|||
{ |
|||
public class OrderModel |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆id
|
|||
/// </summary>
|
|||
public long Id { get; set; } |
|||
/// <summary>
|
|||
/// 订单状态:(0未指派、1已指派、2已接单、3已出发、4已完成、5已删除、6已到达、7作业中、8已作废、9已撤销)
|
|||
/// </summary>
|
|||
public int State { get; set; } |
|||
/// <summary>
|
|||
/// 执行车辆id
|
|||
/// </summary>
|
|||
public long VehicleId { get; set; } |
|||
/// <summary>
|
|||
/// 工地经度
|
|||
/// </summary>
|
|||
public decimal Longitude { get; set; } |
|||
/// <summary>
|
|||
/// 工地纬度
|
|||
/// </summary>
|
|||
public decimal Latitude { get; set; } |
|||
/// <summary>
|
|||
/// 到达时间
|
|||
/// </summary>
|
|||
public DateTime ArriveTime { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
namespace GpsModels |
|||
{ |
|||
public class PointLatLng |
|||
{ |
|||
public PointLatLng(double lat, double lng) |
|||
{ |
|||
Lat = lat; |
|||
Lng = lng; |
|||
} |
|||
public double Lat { get; set; } |
|||
public double Lng { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// 有关程序集的常规信息通过以下
|
|||
// 特性集控制。更改这些特性值可修改
|
|||
// 与程序集关联的信息。
|
|||
[assembly: AssemblyTitle("GpsModel")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("Microsoft")] |
|||
[assembly: AssemblyProduct("GpsModel")] |
|||
[assembly: AssemblyCopyright("Copyright © Microsoft 2018")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
|||
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
|||
// 则将该类型上的 ComVisible 特性设置为 true。
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
|||
[assembly: Guid("28fd03bd-9d6e-4639-ae10-6f79642fba8f")] |
|||
|
|||
// 程序集的版本信息由下面四个值组成:
|
|||
//
|
|||
// 主版本
|
|||
// 次版本
|
|||
// 生成号
|
|||
// 修订号
|
|||
//
|
|||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
|||
// 方法是按如下所示使用“*”:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
@ -0,0 +1,47 @@ |
|||
namespace GpsModels |
|||
{ |
|||
public class VehicleModel |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆id
|
|||
/// </summary>
|
|||
public long Id { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 公司ID
|
|||
/// </summary>
|
|||
public long CompanyId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 车辆编号
|
|||
/// </summary>
|
|||
public string VehicleCode { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 车牌号
|
|||
/// </summary>
|
|||
public string VehiclePlate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 车辆启用状态0:停用,1:启用。-->车辆在地图的状态,后面分析GpsState:(0:休-停用中;1:闲-可执行;2:忙-任务中)。
|
|||
/// </summary>
|
|||
public int Status { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 通讯SIM卡号
|
|||
/// </summary>
|
|||
public string SimNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// gps品牌
|
|||
/// 1 博实结
|
|||
/// 2 深圳
|
|||
/// </summary>
|
|||
public int TerminalType { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 设备号
|
|||
/// </summary>
|
|||
public string TerminalNo { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
using System.ComponentModel; |
|||
|
|||
namespace GpsModels |
|||
{ |
|||
/// <summary>
|
|||
/// 车辆派工订单状态
|
|||
/// </summary>
|
|||
public enum ViOrderStateEnum |
|||
{ |
|||
// 订单状态(0未指派、1已指派、2已接单、3已出发、4已完成、5已删除、6已到达、7作业中、8已作废、9已撤销)
|
|||
/// <summary>
|
|||
/// 未指派0
|
|||
/// </summary>
|
|||
[Description("未指派")] |
|||
UnAssign = 0, |
|||
|
|||
/// <summary>
|
|||
/// 1已指派
|
|||
/// </summary>
|
|||
[Description("已指派")] |
|||
Assigned = 1, |
|||
|
|||
/// <summary>
|
|||
/// 2已接单
|
|||
/// </summary>
|
|||
[Description("已接单")] |
|||
Accepted = 2, |
|||
|
|||
/// <summary>
|
|||
/// 3已出发
|
|||
/// </summary>
|
|||
[Description("已出发")] |
|||
SetOut = 3, |
|||
|
|||
/// <summary>
|
|||
/// 4已完成
|
|||
/// </summary>
|
|||
[Description("已完成")] |
|||
Finished = 4, |
|||
|
|||
/// <summary>
|
|||
/// 5已删除
|
|||
/// </summary>
|
|||
[Description("已删除")] |
|||
Delete = 5, |
|||
|
|||
/// <summary>
|
|||
/// 6已到达
|
|||
/// </summary>
|
|||
[Description("已到达")] |
|||
Arrive = 6, |
|||
|
|||
/// <summary>
|
|||
/// 7作业中
|
|||
/// </summary>
|
|||
[Description("作业中")] |
|||
Working = 7, |
|||
|
|||
/// <summary>
|
|||
/// 8已作废
|
|||
/// </summary>
|
|||
[Description("已作废")] |
|||
Abandon = 8, |
|||
/// <summary>
|
|||
/// 9已撤销
|
|||
/// </summary>
|
|||
[Description("已撤销")] |
|||
Cancled = 9 |
|||
} |
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue