|
|
|
|
using IOT.Show.Common;
|
|
|
|
|
using IOT.Show.Model;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace IOT.Show.SqlBase
|
|
|
|
|
{
|
|
|
|
|
public class SqlSugarBase
|
|
|
|
|
{
|
|
|
|
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
|
|
|
|
{
|
|
|
|
|
ConnectionString = "server=10.113.254.16;uid=sa;pwd=klltdb@3391123;database=XJEMSRefactor",
|
|
|
|
|
//ConnectionString = ConfigurationManager.AppSettings["ConnectionString"],
|
|
|
|
|
DbType = SqlSugar.DbType.SqlServer,//设置数据库类型
|
|
|
|
|
IsAutoCloseConnection = true,//自动释放数据务,如果存在事务,在事务结束后释放
|
|
|
|
|
InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public List<T_Led_Info> getLedInfo()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var sqlStr = "select * from T_Led_Info where title not like 'ML%'";
|
|
|
|
|
LogHelper.Info("语句:" + sqlStr);
|
|
|
|
|
var info = db.Ado.SqlQuery<T_Led_Info>(sqlStr);
|
|
|
|
|
LogHelper.Info("获取Led信息成功:"+info.Count+"条Led信息");
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error("获取Led信息失败:"+ex.Message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataTable getLedData(string unitname)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
/*var sqlStr = "select a.monitorName,a.ip,a.title,b.tempreture,b.humidity,b.illuminance from ( \n" +
|
|
|
|
|
"select t1.title,t1.ip,t2.collectDeviceId,t3.monitorId,t3.correctValue,t3.monitorName,MAX(t4.collectTime) as collectTime from T_Led_Info t1 \n" +
|
|
|
|
|
"left join T_CollectDeviceInfo t2 on t1.title = t2.settingAddress \n" +
|
|
|
|
|
"left join T_Monitor t3 on t2.collectDeviceId = t3.collectDeviceId and t1.collectFlag = t3.sensorMeterTypeId \n" +
|
|
|
|
|
"left join T_W_TempertureData t4 on t4.monitorId = t3.monitorId \n" +
|
|
|
|
|
"where t1.title = '"+ unitname + "' and t3.secondType = 0 \n" +
|
|
|
|
|
"group by t1.title,t2.collectDeviceId,t3.monitorId,t3.monitorName,t1.ip,t3.correctValue \n" +
|
|
|
|
|
") a \n" +
|
|
|
|
|
"left join T_W_TempertureData b on a.monitorId = b.monitorId and a.collectTime = b.collectTime \n" +
|
|
|
|
|
"Order by a.correctValue";*/
|
|
|
|
|
var sqlStr = "select a.monitorName,a.ip,a.title,b.tempreture,b.humidity,b.illuminance from ( \n"+
|
|
|
|
|
"select t1.title,t2.ledId,t1.ip,t2.monitorId,t2.monitorOrder,t3.monitorName,MAX(t4.collectTime) as collectTime from T_Led_Info t1 \n"+
|
|
|
|
|
"left join T_Led_MonitorUnit t2 on t1.ledId = t2.ledId \n"+
|
|
|
|
|
"left join T_Monitor t3 on t2.monitorId = t3.monitorId \n"+
|
|
|
|
|
"left join T_W_TempertureData t4 on t4.monitorId = t3.monitorId \n"+
|
|
|
|
|
"where t1.title = '"+ unitname + "' \n"+
|
|
|
|
|
"group by t1.title,t2.ledId,t1.ip,t2.monitorId,t3.monitorName,t2.monitorOrder \n"+
|
|
|
|
|
") as a \n"+
|
|
|
|
|
"left join T_W_TempertureData b on b.collectTime = a.collectTime and a.monitorId = b.monitorId \n"+
|
|
|
|
|
"order by a.monitorOrder";
|
|
|
|
|
LogHelper.Info("语句:"+sqlStr);
|
|
|
|
|
var info = db.Ado.SqlQuery<T_Led_Data>(sqlStr);
|
|
|
|
|
|
|
|
|
|
LogHelper.Info("获取Led数据成功:获取到"+info.Count+"条数据");
|
|
|
|
|
return ListToTable(info);
|
|
|
|
|
}catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Error("获取Led数据失败:"+ex.Message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataTable ListToTable(IList info)
|
|
|
|
|
{
|
|
|
|
|
DataTable dt = new DataTable();
|
|
|
|
|
if (info.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
PropertyInfo[] propertys = info[0].GetType().GetProperties();
|
|
|
|
|
|
|
|
|
|
foreach (PropertyInfo pi in propertys)
|
|
|
|
|
{
|
|
|
|
|
dt.Columns.Add(pi.Name);
|
|
|
|
|
}
|
|
|
|
|
foreach (object t in info)
|
|
|
|
|
{
|
|
|
|
|
ArrayList tempList = new ArrayList();
|
|
|
|
|
foreach (PropertyInfo pi in propertys)
|
|
|
|
|
{
|
|
|
|
|
object obj = pi.GetValue(t, null);
|
|
|
|
|
tempList.Add(obj);
|
|
|
|
|
}
|
|
|
|
|
object[] array = tempList.ToArray();
|
|
|
|
|
dt.LoadDataRow(array, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return dt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|