using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Uninpho.DBOperation.Model;
namespace Uninpho.DBOperation.Operation
{
public class DMControl
{
///
/// 获取曲线信息管理数据
///
public static object GetUnionTable()
{
SqlSugarClient db = Config.GetPgClient();
List ignoreColumn = new List() { "remark", "xuhao" };
//List ignoreColumn = new List() { "xingbie", "jgjlc", "xlm", "remark", "xuhao" };
List DaoChaMeta = MetaDataCtrl.GetMetaData("t_daocha_account");
List JHFXMeta = MetaDataCtrl.GetMetaData("t_jihefenxi_account");
List LGLMeta = MetaDataCtrl.GetMetaData("t_lunguili_account");
//StringBuilder sql = new StringBuilder();
//sql.Append(" select c.*,ab.* from( ;");
//List dcList = new List();
//DaoChaMeta.ForEach( i => dcList.Add("dc."+i.name));
//List jhfxList = new List();
//JHFXMeta.ForEach(i => dcList.Add("jhfx." + i.name));
List lglList = new List();
LGLMeta.ForEach(i =>
{
if (!ignoreColumn.Contains(i.name))
{
//if (i.name == "id")
if (i.name == "id" || i.name == "xlm" || i.name == "jgjlc" || i.name == "xingbie")
{
lglList.Add(string.Format("lgl.{0} as lgl_{0}", i.name));
}
else
{
lglList.Add("lgl." + i.name);
}
}
}
);
List jhfxList = new List();
JHFXMeta.ForEach(i =>
{
//if (i.name == "id")
if (i.name == "id" || i.name == "xlm" || i.name == "jgjlc" || i.name == "xingbie")
{
jhfxList.Add(string.Format("jhfx.{0} as jhfx_{0}", i.name));
}
else
{
jhfxList.Add("jhfx." + i.name);
}
}
);
List dcList = new List();
DaoChaMeta.ForEach(i =>
{
if (!ignoreColumn.Contains(i.name))
{
//if (i.name == "id")
//{
// dcList.Add(string.Format("dc.{0} as dc_{0}", i.name));
//}
//else
//{
dcList.Add("dc." + i.name);
//}
}
}
);
string sql = @" select {dcColumns},ab.* from(
select {lglColumns}, {jhfxColumns} from t_lunguili_account lgl, t_jihefenxi_account jhfx
where
lgl.xlm = jhfx.xlm and
lgl.xingbie = jhfx.xingbie and
lgl.jgjlc = jhfx.jgjlc)
as
ab,t_daocha_account dc
where
ab.jhfx_xlm = dc.xlm and
ab.jhfx_xingbie = dc.xingbie and
ab.jhfx_jgjlc = dc.jgjlc";
string sql2 = @"select * from (select {jhfxColumns},{dcColumns}
from public.t_jihefenxi_account jhfx ,public.t_daocha_account dc
where dc.xlm = jhfx.xlm and dc.xingbie = jhfx.xingbie and dc.jgjlc = jhfx.jgjlc) as newtab
where newtab.jhfx_id not in
(select ab.id from(
select jhfx.id,jhfx.xlm,jhfx.xingbie,jhfx.jgjlc
from t_lunguili_account lgl, t_jihefenxi_account jhfx
where lgl.xlm = jhfx.xlm and lgl.xingbie = jhfx.xingbie and lgl.jgjlc = jhfx.jgjlc)
as ab,t_daocha_account dc
where ab.xlm = dc.xlm and ab.xingbie = dc.xingbie and ab.jgjlc = dc.jgjlc)";
string sql3 = @"select * from (select {lglColumns},{dcColumns}
from public.t_lunguili_account lgl ,public.t_daocha_account dc
where dc.xlm = lgl.xlm and dc.xingbie = lgl.xingbie and dc.jgjlc = lgl.jgjlc) as newtab
where newtab.lgl_id not in
(select ab.id from(
select lgl.id,lgl.xlm,lgl.xingbie,lgl.jgjlc
from t_lunguili_account lgl, t_jihefenxi_account jhfx
where lgl.xlm = jhfx.xlm and lgl.xingbie = jhfx.xingbie and lgl.jgjlc = jhfx.jgjlc)
as ab,t_daocha_account dc
where ab.xlm = dc.xlm and ab.xingbie = dc.xingbie and ab.jgjlc = dc.jgjlc)";
//string sql2 = @"select {jhfxColumns},{dcColumns} from public.t_jihefenxi_account jhfx ,public.t_daocha_account dc
// where
// dc.xlm = jhfx.xlm and
// dc.xingbie = jhfx.xingbie and
// dc.jgjlc = jhfx.jgjlc";
//string sql3 = @"select {lglColumns},{dcColumns} from public.t_lunguili_account lgl ,public.t_daocha_account dc
// where
// dc.xlm = lgl.xlm and
// dc.xingbie = lgl.xingbie and
// dc.jgjlc = lgl.jgjlc";
sql = sql.Replace("{lglColumns}", string.Join(",", lglList)).Replace("{dcColumns}", string.Join(",", dcList)).Replace("{jhfxColumns}", string.Join(",", jhfxList));
sql2 = sql2.Replace("{dcColumns}", string.Join(",", dcList)).Replace("{jhfxColumns}", string.Join(",", jhfxList));
sql3 = sql3.Replace("{lglColumns}", string.Join(",", lglList)).Replace("{dcColumns}", string.Join(",", dcList));
//var list = db.Queryable().AS("datamanage").Where("id=@id", new { id = 1 }).ToList();
//var list2 = db.Queryable("o").AS("order")
// .AddJoinInfo("OrderDetail", "i", "o.id=i.OrderId")
// .Where("id=@id", new { id = 1 })
// .Select("o.*").ToList();
var listqx = db.SqlQueryable(sql).ToList();
var listqx1 = db.SqlQueryable(sql2).ToList();
var listqx2 = db.SqlQueryable(sql3).ToList();
var fristUnion = listqx.Union(listqx1).Distinct().ToList();
var secondUnion = fristUnion.Union(listqx2).Distinct().ToList();
return secondUnion;
//if (listqx1.Count > listqx2.Count)
//{
// #region MyRegion
// // List indexs = new List();
// // for (int i = 0; i < listqx1.Count; i++)
// // {
// // for (int j = 0; j < listqx.Count; j++)
// // {
// // bool issame = true;
// // foreach (KeyValuePair col in listqx1[i])
// // {
// // string aa = col.Key;//属性
// // string bb;
// // if (col.Value.ToString() == null)
// // {
// // bb = "asdvbasghjdsadguhjasgdhjas";
// // }
// // else
// // {
// // bb = col.Value.ToString();//值
// // }
// // foreach (KeyValuePair cola in listqx[j])
// // {
// // string aaa = cola.Key;//属性
// // string bba;
// // if (col.Value.ToString() == null)
// // {
// // bba = "a34567235473625462345672346";
// // }
// // else
// // {
// // bba = cola.Value.ToString();//值
// // }
// // if (aa == aaa && bb == bba)
// // {
// // issame = true;
// // }
// // }
// // if (issame)
// // {
// // break;
// // }
// // }
// // if (issame)
// // {
// // indexs.Add(i);
// // break;
// // }
// // }
// // }
// // for (int i = indexs.Count; i >= 0; i--)
// // {
// // listqx1.RemoveAt(indexs[i]);
// // }
// #endregion
// return listqx.Union(listqx1).Distinct().ToList();
//}
//else if (listqx1.Count < listqx2.Count)
//{
// return listqx.Union(listqx2).Distinct().ToList();
//}
//else
//{
// return listqx;
//}
}
///
/// 获取轮轨力波形数据
///
/// 映射文件名
///
public static List GetLGL_BXData(string yswjm)
{
SqlSugarClient db = Config.GetPgClient();
string strSQL = string.Format("select * from t_lunguili_boxing where yswjm = '{0}'", yswjm);
//by expression
return db.SqlQueryable(strSQL).ToList();
}
public static List GetLGL_BXDataByIDS(string ids)
{
string[] idList = ids.Split(',');
if (idList.Length == 2)
{
SqlSugarClient db = Config.GetPgClient();
int startId = Convert.ToInt32(idList[0]);
int endId = Convert.ToInt32(idList[1]);
string strSQL = string.Format("select * from t_lunguili_boxing where id BETWEEN {0} and {1}", startId, endId);
//by expression
return db.SqlQueryable(strSQL).ToList();
}
else
{
return null;
}
}
///
/// 获取几何分析波形数据
///
///
///
public static List GetJHFX_BXDataByIDS(string ids)
{
string[] idList = ids.Split(',');
if (idList.Length == 2)
{
SqlSugarClient db = Config.GetPgClient();
int startId = Convert.ToInt32(idList[0]);
int endId = Convert.ToInt32(idList[1]);
string strSQL = string.Format("select * from t_jihefenxi_boxing where id BETWEEN {0} and {1}", startId, endId);
//by expression
return db.SqlQueryable(strSQL).ToList();
}
else
{
return null;
}
}
///
/// 获取几何分析波形数据
///
/// 映射文件名
///
public static List GetJHFX_BXData(string yswjm)
{
SqlSugarClient db = Config.GetPgClient();
string strSQL = string.Format("select * from t_jihefenxi_boxing where yswjm = '{0}'", yswjm);
//by expression
return db.SqlQueryable(strSQL).ToList();
}
}
}