You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
5.5 KiB
139 lines
5.5 KiB
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;
|
|
}
|
|
}
|
|
}
|
|
|