Files
T-DAS/Epost.BLL/AddressstorageBLL.cs

379 lines
11 KiB
C#
Raw Normal View History

2023-01-13 15:30:20 +08:00
using Epost.DAL;
using Epost.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Epost.Model.AddressCheckModel;
namespace Epost.BLL
{
public class AddressstorageBLL
{
AddressstorageDAL dal = new AddressstorageDAL();
#region
public DataTable getBlock(string address, string type, string controlip)
{
return dal.getBlock(address, type, controlip);
}
#endregion
#region
public DataTable getLocationList(string address, string controlIP)
{
return dal.getLocationList(address, controlIP);
}
#endregion
#region
public DataTable getArea(string address, string controlIP)
{
return dal.getArea(address, controlIP);
}
#endregion
#region
public DataTable getAddressList(string location)
{
return dal.getAddressList(location);
}
#endregion
#region
public DataTable getOrderAddress(string location)
{
return dal.getOrderAddress(location);
}
#endregion
#region Ip地址
public DataTable getIP(string carid)
{
return dal.getIP(carid);
}
#endregion
#region
public DataTable getAddressListByway(string location, string block, string area, string way)
{
return dal.getAddressListByway(location, block, area, way);
}
#endregion
#region
public DataTable getAddressByBlock(string block)
{
return dal.getAddressByBlock(block);
}
#endregion
#region
public DataTable getAddressByBlock(string block, string area)
{
return dal.getAddressByBlock(block, area);
}
#endregion
#region
public DataTable GetBoxAddress(string block,string area,int type)
{
return dal.GetBoxAddress(block,area,type);
}
#endregion
#region
public DataTable getAddresslist(string block, string area,string type)
{
return dal.getAddresslist(block, area,type);
}
#endregion
#region
public DataTable GetScanList()
{
return dal.GetScanList();
}
#endregion
#region
public DataTable GetLightList()
{
return dal.GetLightList();
}
#endregion
#region
public DataTable GetScanListByArea(string block, string area)
{
return dal.GetScanListByArea(block, area);
}
#endregion
#region
public DataTable GetlightListByArea(string block, string area)
{
return dal.GetlightListByArea(block, area);
}
#endregion
#region
public DataTable getControlList()
{
return dal.getControlList();
}
#endregion
#region
public DataTable getLabelList(string controlid)
{
return dal.getLabelList(controlid);
}
#endregion
#region
public DataTable getAddressList()
{
return dal.getAddressList();
}
#endregion
#region
public DataTable GetBlockList()
{
return dal.GetBlockList();
}
#endregion
#region
public List<AddressstorageModel> getDeviceList(string controlid)
{
DataTable dt = dal.getLabelList(controlid);
return Common.ModelConvertHelper<AddressstorageModel>.ConvertToList(dt);
}
#endregion
#region
public DataTable GetAreaListDT()
{
return dal.GetAreaList();
}
#endregion
#region
public List<AddressstorageModel> GetAreaList(string block = "")
{
return dal.GetAreaList(block);
}
#endregion
#region
public DataTable GetWayList()
{
return dal.GetWayList();
}
#endregion
//#region
///// <summary>
///// 分页获取数据列表
///// </summary>
//public List<Model.AddressstorageModel> GetCityListByPage(string strWhere, string orderby, int pageSize, int pageIndex, out int recordCount)
//{
// int startIndex = 0;
// int endIndex = 0;
// if (pageIndex <= 0)
// pageIndex = 1;
// //计算查询的开始行数与结束行数
// startIndex = (pageIndex - 1) * pageSize + 1;
// endIndex = pageIndex * pageSize;
// return dal.GetCityListByPage(strWhere, orderby, startIndex, endIndex, out recordCount);
//}
//#endregion
#region
/// <summary>
/// 分页获取数据列表
/// </summary>
public List<Model.AddressstorageModel> GetCityListByPage(string strWhere, string orderby, int pageSize, int pageIndex, out int recordCount)
{
int startIndex = 0;
int endIndex = 0;
if (pageIndex <= 0)
pageIndex = 1;
//计算查询的开始行数与结束行数
startIndex = (pageIndex - 1) * pageSize + 1;
endIndex = pageIndex * pageSize;
return dal.GetLocationListByPage(strWhere, orderby, startIndex, endIndex, out recordCount);
}
#endregion
//获取地址的检测的设备信息
public static Dictionary<bool, Dictionary<string, List<Detail>>> listcheck = new Dictionary<bool, Dictionary<string, List<Detail>>>();
public static List<Detail> list = new List<Detail>();
Dictionary<string, List<Detail>> lists2 = new Dictionary<string, List<Detail>>();
ErrorLogBLL errorLog = new ErrorLogBLL();
#region
public static int Check()
{
while (listcheck.Count == 0)
{
ErrorLogBLL errorLogc = new ErrorLogBLL();
//errorLogc.SaveSysytemError("调用接口一直等待", "程序一直在检测接口的数据,一直没有发过来");
Thread.Sleep(10);
}
return listcheck.Count;
}
#endregion
#region
public bool AddOrder(List<Detail> model)
{
string s = "1";
list.Clear();
lists2.Clear();
listcheck.Clear();
try
{
for (int i = 0; i < model.Count; i++)
{
if (string.IsNullOrEmpty(model[i].Address) || string.IsNullOrEmpty(model[i].ControlIP))
{
s = "2";
}
else
{
s = "3";
}
}
if (s == "3")
{
list.AddRange(model);
//将list排序
//控制器Ip
var details = (from d in list
group d by d.ControlIP
into g
orderby g.Key
where g.Count() > 0
select new
{
g.Key,
}
).ToList();
//根据ip查询所有的地址
string address_error = "";
foreach (var a in details)
{
List<Detail> dtlist = list.FindAll(m => m.ControlIP == a.Key.ToString());
List<Detail> su = dtlist.OrderBy(f => Convert.ToInt32(f.Address)).ToList();
lists2.Add(a.Key.ToString(), su);
address_error += a.Key.ToString() + "(IP):";
for (int i = 0; i < su.Count; i++)
{
address_error += su[i].Address.ToString() + ",";
}
address_error += "|";
}
//如何判断接口被调用
listcheck.Add(true, lists2);
//将调用接口成功返回的错误的地址和ip打包放置到数据库中去
errorLog.SaveOperateError("调用接口成功", "返回的地址错误信息:" + address_error);
return true;
}
else
{
listcheck.Add(true, lists2);
errorLog.SaveOperateError("调用接口成功", "无错误返回");
return true;
}
}
catch (Exception ex)
{
errorLog.SaveSysytemError("调用接口失败", ex.ToString());
return false;
}
}
#endregion
#region state
public DataTable GetErrorState(string address,string ip)
{
return dal.getErrorState(address,ip);
}
#endregion
#region state的值为3
public bool UpdateErrorState(string address, string ip)
{
return dal.UpdateErrorState(address, ip);
}
#endregion
#region state的值为1
public bool UpdateState()
{
return dal.UpdateState();
}
#endregion
#region
public DataTable GetALLList(string strwhere)
{
return dal.GetALLList(strwhere);
}
#endregion
#region
/// <summary>
/// 分页获取数据列表
/// </summary>
public List<Model.AddressstorageModel> GetAddrListByPage(string strWhere, string orderby, int pageSize, int pageIndex, out int recordCount)
{
int startIndex = 0;
int endIndex = 0;
if (pageIndex <= 0)
pageIndex = 1;
//计算查询的开始行数与结束行数
startIndex = (pageIndex - 1) * pageSize + 1;
endIndex = pageIndex * pageSize;
return dal.GetAddressListByByPage(strWhere, orderby, startIndex, endIndex, out recordCount);
}
#endregion
}
}