initial version with inspection edition
This commit is contained in:
425
IronIntelContractorBusiness/MapView/AssetMapViewManagement.cs
Normal file
425
IronIntelContractorBusiness/MapView/AssetMapViewManagement.cs
Normal file
@ -0,0 +1,425 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Foresight.Data;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.MapView;
|
||||
using Foresight.Fleet.Services.JobSite;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class AssetMapViewManagement : MachineManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据Contractorid获取机器列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AssetViewItem[] GetAssets(string sessionid, string companyid, string useriid, string filtertext, int onroad, MachineAlertViewQueryParameter param, bool IncludeNoLocation)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
|
||||
MapViewAssetsQueryParam qp = new MapViewAssetsQueryParam();
|
||||
qp.FilterString = filtertext;
|
||||
qp.OnRoad = onroad;
|
||||
qp.IncludeNoLocation = IncludeNoLocation;
|
||||
qp.IncludeAssetGroups = true;
|
||||
qp.IncludeJobSites = true;
|
||||
if (param != null)
|
||||
{
|
||||
qp.ViewId = param.ViewID;
|
||||
qp.AlertViewQueryParam = param;
|
||||
}
|
||||
|
||||
var client = FleetServiceClientHelper.CreateClient<MapViewQueryClient>(companyid, sessionid);
|
||||
AssetMapViewPinItem[] assets = client.GetAssets(companyid, useriid, qp);
|
||||
List<AssetViewItem> result = new List<AssetViewItem>();
|
||||
foreach (var a in assets)
|
||||
{
|
||||
AssetViewItem avi = new AssetViewItem();
|
||||
Helper.CloneProperty(avi, a);
|
||||
result.Add(avi);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static AssetDetailViewItem GetAssetDetailItem(string sessionid, string companyid, long machineid, string datasource = null)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid);
|
||||
var asset = client.GetAssetDetailInfo(companyid, machineid);
|
||||
AssetDetailViewItem mi = new AssetDetailViewItem();
|
||||
mi.ID = asset.ID;
|
||||
mi.Name = asset.Name;
|
||||
mi.Name2 = asset.Name2;
|
||||
mi.VIN = asset.VIN;
|
||||
mi.MakeYear = asset.MakeYear;
|
||||
mi.Make = asset.MakeName;
|
||||
mi.Model = asset.ModelName;
|
||||
mi.AssetType = asset.TypeName;
|
||||
mi.GroupNames = asset.GroupNames;
|
||||
mi.IconUrl = asset.MapViewIconUrl;
|
||||
mi.AssetIconUrl = asset.AssetIconUrl;
|
||||
|
||||
if (asset.CurrentHours != null)
|
||||
{
|
||||
mi.EngineHours = asset.CurrentHours.Corrected;
|
||||
mi.EngineHoursDate = asset.CurrentHours.AsofTimeLocal;
|
||||
}
|
||||
|
||||
mi.Location = new LocationViewItem();
|
||||
var loc = asset.CurrentLocation;
|
||||
if (!string.IsNullOrWhiteSpace(datasource)
|
||||
&& (loc == null || string.Compare(datasource, loc.DataSource, true) != 0))
|
||||
{
|
||||
AssetLocationInfo[] locs = client.GetAssetCurrentLocation(companyid, machineid);
|
||||
var tempLoc = locs.FirstOrDefault(l => string.Compare(datasource, l.DataSource, true) != 0);
|
||||
if (tempLoc != null)
|
||||
{
|
||||
mi.Location.Latitude = tempLoc.Latitude;
|
||||
mi.Location.Longitude = tempLoc.Longitude;
|
||||
mi.Location.LocationTime = tempLoc.AsofTimeLocal;
|
||||
mi.Location.Speed = tempLoc.Speed;
|
||||
mi.Location.SpeedUnit = tempLoc.SpeedUnits;
|
||||
mi.Location.PostedSpeed = tempLoc.PostedSpeedLimit;
|
||||
mi.Location.PostedSpeedUnit = tempLoc.SpeedLimitUnits;
|
||||
mi.Location.Street = tempLoc.Street;
|
||||
}
|
||||
}
|
||||
else if (loc != null)
|
||||
{
|
||||
mi.Location.Latitude = loc.Latitude;
|
||||
mi.Location.Longitude = loc.Longitude;
|
||||
mi.Location.LocationTime = loc.AsofTimeLocal;
|
||||
mi.Location.Speed = loc.Speed;
|
||||
mi.Location.SpeedUnit = loc.SpeedUnits;
|
||||
mi.Location.PostedSpeed = loc.PostedSpeedLimit;
|
||||
mi.Location.PostedSpeedUnit = loc.SpeedLimitUnits;
|
||||
mi.Location.Street = loc.Street;
|
||||
}
|
||||
|
||||
if (asset.CurrentOdometer != null)
|
||||
{
|
||||
mi.Odometer = asset.CurrentOdometer.Corrected;
|
||||
mi.OdometerUOM = asset.CurrentOdometer.UOM;
|
||||
}
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
public static AssetGroupViewItem[] GetAssetGroups(string sessionid, string companyid, string useriid, string searchtext)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<MapViewQueryClient>(companyid, sessionid);
|
||||
AssetGroupInfo[] gs = client.GetAvailableAssetGroups(companyid, useriid, searchtext, false);
|
||||
|
||||
List<AssetGroupViewItem> list = new List<AssetGroupViewItem>();
|
||||
foreach (var g in gs)
|
||||
{
|
||||
AssetGroupViewItem ag = new AssetGroupViewItem();
|
||||
ag.ID = g.Id;
|
||||
ag.Name = g.Name;
|
||||
//ag.Assets = g.Assets;
|
||||
list.Add(ag);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static JobSiteViewItem[] GetJobsites(string sessionid, string companyid, string useriid, string searchtext)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<MapViewQueryClient>(companyid, sessionid);
|
||||
MapViewJobSiteInfo[] jss = client.GetAvailableJobSites(companyid, useriid, searchtext, false);
|
||||
|
||||
List<JobSiteViewItem> list = new List<JobSiteViewItem>();
|
||||
foreach (var js in jss)
|
||||
{
|
||||
JobSiteViewItem ajs = new JobSiteViewItem();
|
||||
ajs.ID = js.ID;
|
||||
ajs.Name = js.Name;
|
||||
ajs.Latitude = js.Latitude;
|
||||
ajs.Longitude = js.Longitude;
|
||||
ajs.Radius = js.Radius;
|
||||
ajs.Radius_UOM = js.RadiusUOM;
|
||||
//ajs.Assets = js.Assets;
|
||||
|
||||
System.Drawing.Color color = System.Drawing.Color.Orange;
|
||||
try
|
||||
{
|
||||
color = System.Drawing.ColorTranslator.FromHtml(js.Color);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
ajs.Color = new IIColor() { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B };
|
||||
if (js.Polygon != null)
|
||||
{
|
||||
List<PostionItem> temp = new List<PostionItem>();
|
||||
foreach (var p in js.Polygon)
|
||||
{
|
||||
temp.Add(new PostionItem(p.Latitude, p.Longtitude));
|
||||
}
|
||||
ajs.Polygon = temp.ToArray();
|
||||
}
|
||||
ajs.Notes = js.Notes;
|
||||
list.Add(ajs);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static Dictionary<string, List<MachineViewItem>> GetGroupAssets(string useriid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = @"if(select count(1) from USERMACHINEGROUPMAP where USERIID={0})=0
|
||||
select a.MACHINEID,a.GROUPID,b.VIN,b.MACHINENAME,b.MACHINENAME2 from MACHINEGROUPMAP a,MACHINES b where a.MACHINEID=b.MACHINEID and ISNULL(b.HIDE,0)=0
|
||||
else
|
||||
select a.MACHINEID,a.GROUPID,b.VIN,b.MACHINENAME,b.MACHINENAME2 from MACHINEGROUPMAP a,MACHINES b where a.MACHINEID=b.MACHINEID and ISNULL(b.HIDE,0)=0
|
||||
and b.MACHINEID in (select distinct MACHINEID from MACHINEGROUPMAP
|
||||
where GROUPID in (select GROUPID from USERMACHINEGROUPMAP where USERIID={0}))";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = null;
|
||||
dt = db.GetDataTableBySQL(SQL, useriid);
|
||||
|
||||
Dictionary<string, List<MachineViewItem>> result = new Dictionary<string, List<MachineViewItem>>(StringComparer.OrdinalIgnoreCase);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineViewItem mi = new MachineViewItem();
|
||||
mi.ID = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
mi.Name = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
mi.Name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
mi.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
string groupID = FIDbAccess.GetFieldString(dr["GROUPID"], string.Empty);
|
||||
if (!result.ContainsKey(groupID))
|
||||
result[groupID] = new List<MachineViewItem>();
|
||||
result[groupID].Add(mi);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void ConvertSpeedUnitToMile(LocationViewItem loc)
|
||||
{
|
||||
if (loc == null) return;
|
||||
if (loc.Speed >= 0 && loc.SpeedUnit.StartsWith("K", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loc.Speed = loc.Speed * 0.6213712;
|
||||
loc.SpeedUnit = "mi/h";
|
||||
}
|
||||
if (loc.PostedSpeed > 0 && loc.PostedSpeedUnit.StartsWith("K", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loc.PostedSpeed = loc.PostedSpeed * 0.6213712;
|
||||
loc.PostedSpeedUnit = "mi/h";
|
||||
}
|
||||
}
|
||||
|
||||
public static AssetLocationHistoryViewItem GetMachineLocationHistory(string sessionid, string machineid, DateTime startTime, DateTime endTime, string companyid, bool notShow00loc, string datasource)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
|
||||
var client = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid);
|
||||
AssetBasicInfo asset = client.GetAssetBasicInfoByID(companyid, Convert.ToInt64(machineid));
|
||||
AssetViewItem ai = new AssetViewItem();
|
||||
Helper.CloneProperty(ai, asset);
|
||||
|
||||
double timeOffset = SystemParams.GetHoursOffset();
|
||||
startTime = startTime.AddHours(-timeOffset);
|
||||
endTime = endTime.AddHours(-timeOffset);
|
||||
|
||||
AssetLocationInfo[] assetLocs = client.GetAssetBasicLocationHistory(companyid, long.Parse(machineid), startTime, endTime, datasource, "", !notShow00loc);
|
||||
|
||||
List<LocationViewItem> ls = new List<LocationViewItem>();
|
||||
foreach (AssetLocationInfo assetLoc in assetLocs)
|
||||
{
|
||||
LocationViewItem li = new LocationViewItem();
|
||||
li.Latitude = assetLoc.Latitude;
|
||||
li.Longitude = assetLoc.Longitude;
|
||||
li.LocationTime = assetLoc.AsofTime.AddHours(timeOffset);
|
||||
|
||||
li.Speed = assetLoc.Speed;
|
||||
li.SpeedUnit = assetLoc.SpeedUnits;
|
||||
li.PostedSpeed = assetLoc.PostedSpeedLimit;
|
||||
li.PostedSpeedUnit = assetLoc.SpeedLimitUnits;
|
||||
li.Street = assetLoc.Street;
|
||||
li.HarshDringEvent = assetLoc.HarshDringEvent;
|
||||
li.SpeedingBehavior = assetLoc.SpeedingBehavior;
|
||||
li.IconURL = GenerateLocationIconUrl(assetLoc);
|
||||
li.SmartWitnessVideoUrl = assetLoc.SmartWitnessVideoUrl;
|
||||
|
||||
ConvertSpeedUnitToMile(li);
|
||||
ls.Add(li);
|
||||
}
|
||||
AssetLocationHistoryViewItem al = new AssetLocationHistoryViewItem();
|
||||
al.Machine = ai;
|
||||
al.Locations = ls.ToArray();
|
||||
return al;
|
||||
}
|
||||
|
||||
private static string GenerateLocationIconUrl(AssetLocationInfo loc)
|
||||
{
|
||||
//http://iron.soft.rz/admin/machinetypeicon.ashx
|
||||
//http://iron.soft.rz/admin/machinemovingicon.ashx
|
||||
string path = SystemParams.MachineTypeMapViewIconUrl.ToLower().Replace("machinetypeicon.ashx", "machinemovingicon.ashx");
|
||||
const string PARAM = "?tp={0}&bkcolor={1}&heading={2}";
|
||||
int tp = (int)HarshDrivingEvents.HardAccelerationEvent;
|
||||
string color = "";
|
||||
switch (loc.HarshDringEvent)
|
||||
{
|
||||
case HarshDrivingEvents.None:
|
||||
break;
|
||||
case HarshDrivingEvents.HardAccelerationEvent:
|
||||
color = "#ff3f48cc";
|
||||
break;
|
||||
case HarshDrivingEvents.HardBrakeEvent:
|
||||
color = "#ff00a8f3";
|
||||
break;
|
||||
case HarshDrivingEvents.HardTurnEvent:
|
||||
color = "#fffff200";
|
||||
break;
|
||||
}
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (loc.SpeedingBehavior == SpeedingBehaviors.MinorSpeeding)
|
||||
color = "#ffff7f27";
|
||||
else if (loc.SpeedingBehavior == SpeedingBehaviors.SevereSpeeding)
|
||||
color = "#ffec1c24";
|
||||
}
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (loc.MoveStatus == AssetMoveStatus.InMotion)
|
||||
color = "#ff228B22";
|
||||
}
|
||||
|
||||
if (loc.Speed <= 0 && loc.MoveStatus == AssetMoveStatus.Unknown)
|
||||
loc.Heading = -1;
|
||||
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (loc.MoveStatus == AssetMoveStatus.StoppedOn)
|
||||
return path + "?legend=StoppedOn";
|
||||
else if (loc.MoveStatus == AssetMoveStatus.StoppedOff)
|
||||
return path + "?legend=StoppedOff";
|
||||
}
|
||||
color = HttpUtility.UrlEncode(color);
|
||||
path = path + string.Format(PARAM, tp, color, loc.Heading);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static MapAlertViewDefinitionItem[] GetMapAlertViews(string sessionid, string companyid, string selectedViewID)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
|
||||
var client = FleetServiceClientHelper.CreateClient<MapViewQueryClient>(companyid, sessionid);
|
||||
AlertViewMapItem[] views = client.GetAlertViewMapItems(companyid);
|
||||
|
||||
AlertViewMapItem viewInfo = null;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(selectedViewID))//获取View下使用的数据源信息
|
||||
viewInfo = client.GetAlertViewMapItem(companyid, selectedViewID);
|
||||
}
|
||||
catch { }
|
||||
|
||||
string path = SystemParams.MachineTypeMapViewIconUrl;
|
||||
List<MapAlertViewDefinitionItem> ls = new List<MapAlertViewDefinitionItem>();
|
||||
foreach (AlertViewMapItem ai in views)
|
||||
{
|
||||
MapAlertViewDefinitionItem mi = new MapAlertViewDefinitionItem();
|
||||
mi.ID = ai.ID;
|
||||
mi.Name = ai.Name;
|
||||
|
||||
if (viewInfo != null && viewInfo.ID.Equals(mi.ID, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
mi.Layers = new MapAlertLayerDefinitionItem[viewInfo.Layers.Count];
|
||||
for (int i = 0; i < viewInfo.Layers.Count; i++)
|
||||
{
|
||||
var layer = viewInfo.Layers[i];
|
||||
mi.Layers[i] = new MapAlertLayerDefinitionItem();
|
||||
mi.Layers[i].ID = layer.LayerId;
|
||||
mi.Layers[i].Title = layer.Title;
|
||||
mi.Layers[i].LegendUrl = layer.LegendUrl;
|
||||
|
||||
if (layer.Pivots != null && layer.Pivots.Count > 0)
|
||||
mi.Layers[i].Pivots = ConvertPivotsDefine(layer.Pivots);
|
||||
}
|
||||
//mi.Layers = mi.Layers.OrderBy((l) => l.AlertLayerType).ToArray();
|
||||
mi.LookupDataSources = ConvertLookupData(viewInfo.LookupDataSources);
|
||||
}
|
||||
ls.Add(mi);
|
||||
}
|
||||
return ls.OrderBy((mal) => mal.Name).ToArray();
|
||||
|
||||
}
|
||||
|
||||
private static List<LookupDataSourceDataItem> ConvertLookupData(List<LookupDataSourceData> data)
|
||||
{
|
||||
List<LookupDataSourceDataItem> result = new List<LookupDataSourceDataItem>();
|
||||
if (data != null)
|
||||
{
|
||||
foreach (LookupDataSourceData d in data)
|
||||
{
|
||||
LookupDataSourceDataItem item = new LookupDataSourceDataItem();
|
||||
item.ID = d.ID;
|
||||
item.Name = d.Name;
|
||||
item.Items.AddRange(d.Items);
|
||||
result.Add(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static AlertLayerPivotViewItem[] ConvertPivotsDefine(List<AlertLayerPivot> paramerters)
|
||||
{
|
||||
List<AlertLayerPivotViewItem> list = new List<AlertLayerPivotViewItem>();
|
||||
foreach (AlertLayerPivot pd in paramerters)
|
||||
{
|
||||
AlertLayerPivotViewItem pi = new AlertLayerPivotViewItem();
|
||||
Helper.CloneProperty(pi, pd);
|
||||
if (pi.DataType == DataTypes.Datetime)
|
||||
{
|
||||
try
|
||||
{
|
||||
pi.DefaultValue = DateTime.Parse(pi.DefaultValue).ToString("M/d/yyyy");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
list.Add(pi);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static long[] GetNoGroupAssets(string companyid)
|
||||
{
|
||||
const string SQL = @"select b.MACHINEID from MACHINES b where not exists(select 1 from MACHINEGROUPMAP a where a.MACHINEID=b.MACHINEID) and isnull(b.HIDE,0)=0";
|
||||
|
||||
string dbs = SystemParams.GetCompanyDbString(companyid);
|
||||
FISqlConnection db = new FISqlConnection(dbs);
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL);
|
||||
|
||||
List<long> result = new List<long>();
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new long[0];
|
||||
}
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
result.Add(FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0));
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
123
IronIntelContractorBusiness/MapView/AssetViewItems.cs
Normal file
123
IronIntelContractorBusiness/MapView/AssetViewItems.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using Foresight;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.MapView;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class AssetViewItem
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public string AssetType { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
public string AlertTips { get; set; }
|
||||
public List<string> AssetGroups { get; set; }
|
||||
public List<long> JobSites { get; set; }
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
//Name取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = Name2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = Name;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = ID.ToString();
|
||||
return name;
|
||||
}
|
||||
}//由于地图显示及排序的名称
|
||||
|
||||
}
|
||||
public class AssetDetailViewItem
|
||||
{
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public DateTime EngineHoursDate { get; set; }
|
||||
public string GroupNames { get; set; }
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string OdometerUOM { get; set; }
|
||||
public int MakeYear { get; set; }
|
||||
public string AssetType { get; set; }
|
||||
public string Model { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string Name { get; set; }
|
||||
public long ID { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
public string AssetIconUrl { get; set; }
|
||||
public LocationViewItem Location { get; set; }
|
||||
public string EngineHoursDateText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (EngineHoursDate != DateTime.MinValue)
|
||||
{
|
||||
return EngineHoursDate.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AssetLocationHistoryViewItem
|
||||
{
|
||||
public AssetViewItem Machine { get; set; }
|
||||
public LocationViewItem[] Locations { get; set; }
|
||||
}
|
||||
|
||||
public class AlertLayerPivotViewItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Caption { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DataTypes DataType { get; set; }
|
||||
public string DefaultValue { get; set; }
|
||||
public string ParameterValue { get; set; }
|
||||
public QueryParameterDisplayStyles DisplayStyle { get; set; }
|
||||
public string LookupDatasourceID { get; set; }
|
||||
public bool DisplayCaptionField { get; set; }
|
||||
public bool IsField { get; set; }
|
||||
public bool IsAllAllowed { get; set; }
|
||||
public bool MutipleSelect { get; set; }
|
||||
public bool IsCriteriaSQL { get; set; }
|
||||
}
|
||||
}
|
125
IronIntelContractorBusiness/MapView/JobManagement.cs
Normal file
125
IronIntelContractorBusiness/MapView/JobManagement.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Foresight.Data;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class JobManagement
|
||||
{
|
||||
public static JobSiteViewItem[] GetJobSite(string searchtext, int onroad, string companyid)
|
||||
{
|
||||
const string sql_1 = @"select JOBSITEID,JOBSITENAME,LATITUDE,LONGITUDE ,RADIUS,RADUIS_UOM,CONTRACTORID,COLOR,NOTES,STARTDATE,ENDDATE,POLYGON from JOBSITES where ENDDATE is null or ENDDATE>getdate() order by JOBSITENAME";
|
||||
const string sql_2 = @"select JOBSITEID,JOBSITENAME,LATITUDE,LONGITUDE ,RADIUS,RADUIS_UOM,CONTRACTORID,COLOR,NOTES,STARTDATE,ENDDATE,POLYGON from JOBSITES where (ENDDATE is null or ENDDATE>getdate()) and JOBSITENAME like {0} order by JOBSITENAME";
|
||||
|
||||
FISqlConnection db = SystemParams.GetCompanyDbConnection(companyid);
|
||||
if (db == null)
|
||||
{
|
||||
return new JobSiteViewItem[0];
|
||||
}
|
||||
DataTable dt = null;
|
||||
if (string.IsNullOrWhiteSpace(searchtext))
|
||||
{
|
||||
dt = db.GetDataTableBySQL(sql_1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = db.GetDataTableBySQL(sql_2, "%" + searchtext + "%");
|
||||
}
|
||||
List<JobSiteViewItem> list = new List<JobSiteViewItem>();
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
JobSiteViewItem js = new JobSiteViewItem();
|
||||
long JobSiteId = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.ID = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.Name = FIDbAccess.GetFieldString(dr["JOBSITENAME"], string.Empty);
|
||||
js.Latitude = FIDbAccess.GetFieldDouble(dr["LATITUDE"], 0);
|
||||
js.Longitude = FIDbAccess.GetFieldDouble(dr["LONGITUDE"], 0);
|
||||
js.Radius = FIDbAccess.GetFieldDouble(dr["RADIUS"], 0);
|
||||
js.Radius_UOM = FIDbAccess.GetFieldString(dr["RADUIS_UOM"], string.Empty);
|
||||
if (string.IsNullOrWhiteSpace(js.Radius_UOM))
|
||||
js.Radius_UOM = "Mile";
|
||||
js.ContractorID = FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty);
|
||||
js.ColorString = FIDbAccess.GetFieldString(dr["COLOR"], string.Empty);
|
||||
System.Drawing.Color color = System.Drawing.Color.Orange;
|
||||
try
|
||||
{
|
||||
color = System.Drawing.ColorTranslator.FromHtml(js.ColorString);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
js.Color = new IIColor() { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B };
|
||||
|
||||
js.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
js.StartDate = FIDbAccess.GetFieldDateTime(dr["STARTDATE"], DateTime.MinValue);
|
||||
js.EndDate = FIDbAccess.GetFieldDateTime(dr["ENDDATE"], DateTime.MinValue);
|
||||
string polygon = FIDbAccess.GetFieldString(dr["POLYGON"], string.Empty);
|
||||
js.Polygon = ConvertPolygonToPointItem(polygon);
|
||||
MachineViewItem[] msiary = GetJobSiteMachines(JobSiteId, onroad, db);
|
||||
if (msiary.Count() > 0)
|
||||
{
|
||||
js.Machines = msiary.OrderBy((m) => m.VIN).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
js.Machines = null;
|
||||
}
|
||||
list.Add(js);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static MachineViewItem[] GetJobSiteMachines(long jobsiteid, int onroad, FISqlConnection db = null)
|
||||
{
|
||||
const string sql_m = @"select a.MACHINEID,b.VIN,b.MACHINENAME,b.MACHINENAME2,ONROAD from JOBSITEMACHINES a,MACHINES b where a.MACHINEID=b.MACHINEID and ISNULL(b.HIDE,0)=0 and a.JOBSITEID={0}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = null;
|
||||
dt = db.GetDataTableBySQL(sql_m, jobsiteid);
|
||||
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MachineViewItem[0];
|
||||
}
|
||||
List<MachineViewItem> list = new List<MachineViewItem>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineViewItem mi = new MachineViewItem();
|
||||
mi.ID = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
mi.Name = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
mi.Name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
mi.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
mi.Onroad = FIDbAccess.GetFieldInt(dr["ONROAD"], 0);
|
||||
if (onroad < 0 || onroad == mi.Onroad)
|
||||
list.Add(mi);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static PostionItem[] ConvertPolygonToPointItem(string polygon)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(polygon))
|
||||
return null;
|
||||
|
||||
List<PostionItem> list = new List<PostionItem>();
|
||||
var polygons = polygon.Split(';');
|
||||
foreach (var py in polygons)
|
||||
{
|
||||
PostionItem pi = new PostionItem();
|
||||
var sap = py.Split(',');
|
||||
pi.Latitude = Convert.ToDouble(sap[0]);
|
||||
pi.Longitude = Convert.ToDouble(sap[1]);
|
||||
list.Add(pi);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
55
IronIntelContractorBusiness/MapView/LocationManagement.cs
Normal file
55
IronIntelContractorBusiness/MapView/LocationManagement.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Foresight.Fleet.Services.Customer;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class LocationManagement
|
||||
{
|
||||
public static CompanyLocationViewItem[] GetCompanyLocations(string companyid)
|
||||
{
|
||||
List<CompanyLocationViewItem> ls = new List<CompanyLocationViewItem>();
|
||||
if (string.IsNullOrWhiteSpace(companyid) || string.Compare(companyid, SystemParams.CompanyID, true) == 0)
|
||||
{
|
||||
GetCompanyLocations(SystemParams.CompanyID, ls);
|
||||
if (!SystemParams.IsDealer)
|
||||
{
|
||||
Services.Customers.CustomerInfo dealer = SystemParams.GetFirstDealerInfo();
|
||||
if (dealer != null)
|
||||
{
|
||||
GetCompanyLocations(dealer.ID, ls);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
private static void GetCompanyLocations(string companyid, List<CompanyLocationViewItem> ls)
|
||||
{
|
||||
CustomerLocation[] locations = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerLocations(companyid);
|
||||
|
||||
foreach (CustomerLocation loc in locations)
|
||||
{
|
||||
ls.Add(ConvertToViewItem(loc, companyid));
|
||||
}
|
||||
}
|
||||
|
||||
private static CompanyLocationViewItem ConvertToViewItem(CustomerLocation loc, string companyid)
|
||||
{
|
||||
CompanyLocationViewItem li = new CompanyLocationViewItem();
|
||||
li.CompanyID = companyid;
|
||||
li.ID = loc.ID;
|
||||
li.LocationName = loc.Name;
|
||||
li.Latitude = loc.Latitude;
|
||||
li.Longitude = loc.Longitude;
|
||||
li.Notes = loc.Notes;
|
||||
|
||||
return li;
|
||||
}
|
||||
}
|
||||
}
|
298
IronIntelContractorBusiness/MapView/MachineStateInfo.cs
Normal file
298
IronIntelContractorBusiness/MapView/MachineStateInfo.cs
Normal file
@ -0,0 +1,298 @@
|
||||
using Foresight;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using IronIntel.Services.Common;
|
||||
using IronIntel.Services.MapView;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class MachineViewItem
|
||||
{
|
||||
public string VIN { get; set; }
|
||||
public long ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
public string EmptyIconUrl { get; set; }//不包含机器图标
|
||||
public string MachineType { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
public int MakeYear { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public DateTime EngineHoursDate { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public string AlertTip { get; set; }
|
||||
public bool OnSite { get; set; }
|
||||
public string JobSiteName { get; set; }//当前所在的JobSiteName
|
||||
public double DistanceFromSite { get; set; }//机器与Jobsite之间的距离
|
||||
public bool WithinSite { get; set; }//机器是否在JobSite多边形范围内
|
||||
public LocationViewItem Location { get; set; }
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string OdometerUOM { get; set; }
|
||||
public int Onroad { get; set; }
|
||||
public string IconFileName { get; set; }
|
||||
public string MoveStatus { get; set; }
|
||||
public int Directionalheading { get; set; }
|
||||
public int MapAlertLayerPriority { get; set; }
|
||||
public Int64 GpsDeviceID { get; set; } //空 -1
|
||||
public string AssetGroupNames { get; set; }
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
//Name取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = Name2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = Name;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = ID.ToString();
|
||||
return name;
|
||||
}
|
||||
}//由于地图显示及排序的名称
|
||||
|
||||
public string EngineHoursDateText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (EngineHoursDate != DateTime.MinValue)
|
||||
{
|
||||
return EngineHoursDate.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class JobSiteViewItem
|
||||
{
|
||||
public Int64 ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string[] Types { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public double Radius { get; set; }
|
||||
public string Radius_UOM { get; set; }
|
||||
public string ContractorID { get; set; }
|
||||
public string ColorString { get; set; }
|
||||
public IIColor Color { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTime StartDate { get; set; }
|
||||
public DateTime EndDate { get; set; }
|
||||
public PostionItem[] Polygon { get; set; }
|
||||
public Int64 BaseOnMachineID { get; set; }
|
||||
public string Code { get; set; }
|
||||
public long[] Assets { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public string strStartDate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (StartDate == DateTime.MinValue)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return StartDate.ToShortDateString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string strEndDate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (EndDate == DateTime.MinValue)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return EndDate.ToShortDateString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MachineViewItem[] Machines { get; set; }
|
||||
}
|
||||
|
||||
public class AssetGroupViewItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public long[] Assets { get; set; }
|
||||
}
|
||||
|
||||
public class CompanyLocationViewItem
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string CompanyID { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public string LocationName { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
}
|
||||
|
||||
public class MapAlertViewDefinitionItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public MapAlertLayerDefinitionItem[] Layers { get; set; }
|
||||
public List<LookupDataSourceDataItem> LookupDataSources { get; set; }
|
||||
}
|
||||
|
||||
public class LookupDataSourceDataItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
|
||||
private List<KeyValuePair<string, string>> _Items = new List<KeyValuePair<string, string>>();
|
||||
public List<KeyValuePair<string, string>> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Items;
|
||||
}
|
||||
}
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class MapAlertLayerDefinitionItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string IconColor { get; set; }
|
||||
public string AlertLayerType { get; set; }//Primary/Secondary
|
||||
public string LegendUrl { get; set; }
|
||||
public DbQueryParameterItem[] CriteriaSQLParameters { get; set; }
|
||||
public DbQueryParameterItem[] AlertSQLParameters { get; set; }
|
||||
public AlertLayerPivotViewItem[] Pivots { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class DbQueryParameterItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Caption { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DataTypes DataType { get; set; }
|
||||
public string DefaultValue { get; set; }
|
||||
public string ParameterValue { get; set; }
|
||||
public QueryParameterDisplayStyles DisplayStyle { get; set; }
|
||||
public string LookupDatasourceID { get; set; }
|
||||
public bool DisplayCaptionField { get; set; }//当参数显示为dropdown时,指示显示Key或者text
|
||||
public bool IsField { get; set; }//表明该参数名是一个数据库参数或是结果集的字段,如果是结果集的字段,则该定义必须要与lookupdatasource关联。
|
||||
public bool IsAllAllowed { get; set; }
|
||||
public bool MutipleSelect { get; set; }
|
||||
}
|
||||
|
||||
public class QueryParameterSource
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class LocationViewItem
|
||||
{
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public DateTime LocationTime { get; set; }
|
||||
public string LocationTimeText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LocationTime != DateTime.MinValue)
|
||||
{
|
||||
return LocationTime.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public double Speed { get; set; } = -1;
|
||||
public string SpeedUnit { get; set; }
|
||||
public double PostedSpeed { get; set; } = -1;
|
||||
public string PostedSpeedUnit { get; set; }
|
||||
public string Street { get; set; } = string.Empty;
|
||||
public string IconURL { get; set; } = string.Empty;
|
||||
public List<KeyValuePair<string, string>> SmartWitnessVideoUrl { get; set; }
|
||||
public SpeedingBehaviors SpeedingBehavior { get; set; }
|
||||
public HarshDrivingEvents HarshDringEvent { get; set; }
|
||||
}
|
||||
|
||||
public class MachineLocationHistoryViewItem
|
||||
{
|
||||
public MachineViewItem Machine { get; set; }
|
||||
public LocationViewItem[] Locations { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class MachineTypeItem
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 供JobSite选中的Mahcine
|
||||
/// </summary>
|
||||
public class AvailableMachines
|
||||
{
|
||||
public MachineViewItem[] Assigned { get; set; }
|
||||
public MachineViewItem[] Unassigned { get; set; }
|
||||
}
|
||||
public struct PostionItem
|
||||
{
|
||||
public double Latitude;
|
||||
public double Longitude;
|
||||
|
||||
public PostionItem(double latitude, double longitude)
|
||||
{
|
||||
Latitude = latitude;
|
||||
Longitude = longitude;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShapeFileItem
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
}
|
1232
IronIntelContractorBusiness/MapView/MachinesMapViewerManagement.cs
Normal file
1232
IronIntelContractorBusiness/MapView/MachinesMapViewerManagement.cs
Normal file
File diff suppressed because it is too large
Load Diff
44
IronIntelContractorBusiness/MapView/MapViewer.cs
Normal file
44
IronIntelContractorBusiness/MapView/MapViewer.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services.MapView;
|
||||
using IronIntel.Services.Customers;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public static class MapViewer
|
||||
{
|
||||
public static KeyValuePair<string, string>[] GetContractors(string useriid)
|
||||
{
|
||||
Users.UserInfo userinfo = UserManagement.GetUserByIID(useriid);
|
||||
CustomerInfo[] cps = SystemParams.GetContractors();
|
||||
List<KeyValuePair<string, string>> ls = new List<KeyValuePair<string, string>>();
|
||||
if (userinfo.UserType == UserTypes.Admin || userinfo.UserType == UserTypes.SupperAdmin)
|
||||
{
|
||||
foreach (CustomerInfo cp in cps)
|
||||
{
|
||||
ls.Add(new KeyValuePair<string, string>(cp.ID, cp.Name));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] str = Acl.GetUserAvailableContractors(useriid);
|
||||
foreach (CustomerInfo cp in cps)
|
||||
{
|
||||
foreach (string s in str)
|
||||
{
|
||||
if (string.Compare(cp.ID, s, true) == 0)
|
||||
{
|
||||
ls.Add(new KeyValuePair<string, string>(cp.ID, cp.Name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user