DMControl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using Uninpho.DBOperation.Model;
  8. namespace Uninpho.DBOperation.Operation
  9. {
  10. public class DMControl
  11. {
  12. /// <summary>
  13. /// 获取曲线信息管理数据
  14. /// </summary>
  15. public static object GetUnionTable()
  16. {
  17. SqlSugarClient db = Config.GetPgClient();
  18. List<string> ignoreColumn = new List<string>() { "remark", "xuhao" };
  19. //List<string> ignoreColumn = new List<string>() { "xingbie", "jgjlc", "xlm", "remark", "xuhao" };
  20. List<T_metadata_account> DaoChaMeta = MetaDataCtrl.GetMetaData("t_daocha_account");
  21. List<T_metadata_account> JHFXMeta = MetaDataCtrl.GetMetaData("t_jihefenxi_account");
  22. List<T_metadata_account> LGLMeta = MetaDataCtrl.GetMetaData("t_lunguili_account");
  23. //StringBuilder sql = new StringBuilder();
  24. //sql.Append(" select c.*,ab.* from( ;");
  25. //List<string> dcList = new List<string>();
  26. //DaoChaMeta.ForEach( i => dcList.Add("dc."+i.name));
  27. //List<string> jhfxList = new List<string>();
  28. //JHFXMeta.ForEach(i => dcList.Add("jhfx." + i.name));
  29. List<string> lglList = new List<string>();
  30. LGLMeta.ForEach(i =>
  31. {
  32. if (!ignoreColumn.Contains(i.name))
  33. {
  34. //if (i.name == "id")
  35. if (i.name == "id" || i.name == "xlm" || i.name == "jgjlc" || i.name == "xingbie")
  36. {
  37. lglList.Add(string.Format("lgl.{0} as lgl_{0}", i.name));
  38. }
  39. else
  40. {
  41. lglList.Add("lgl." + i.name);
  42. }
  43. }
  44. }
  45. );
  46. List<string> jhfxList = new List<string>();
  47. JHFXMeta.ForEach(i =>
  48. {
  49. //if (i.name == "id")
  50. if (i.name == "id" || i.name == "xlm" || i.name == "jgjlc" || i.name == "xingbie")
  51. {
  52. jhfxList.Add(string.Format("jhfx.{0} as jhfx_{0}", i.name));
  53. }
  54. else
  55. {
  56. jhfxList.Add("jhfx." + i.name);
  57. }
  58. }
  59. );
  60. List<string> dcList = new List<string>();
  61. DaoChaMeta.ForEach(i =>
  62. {
  63. if (!ignoreColumn.Contains(i.name))
  64. {
  65. //if (i.name == "id")
  66. //{
  67. // dcList.Add(string.Format("dc.{0} as dc_{0}", i.name));
  68. //}
  69. //else
  70. //{
  71. dcList.Add("dc." + i.name);
  72. //}
  73. }
  74. }
  75. );
  76. string sql = @" select {dcColumns},ab.* from(
  77. select {lglColumns}, {jhfxColumns} from t_lunguili_account lgl, t_jihefenxi_account jhfx
  78. where
  79. lgl.xlm = jhfx.xlm and
  80. lgl.xingbie = jhfx.xingbie and
  81. lgl.jgjlc = jhfx.jgjlc)
  82. as
  83. ab,t_daocha_account dc
  84. where
  85. ab.jhfx_xlm = dc.xlm and
  86. ab.jhfx_xingbie = dc.xingbie and
  87. ab.jhfx_jgjlc = dc.jgjlc";
  88. string sql2 = @"select * from (select {jhfxColumns},{dcColumns}
  89. from public.t_jihefenxi_account jhfx ,public.t_daocha_account dc
  90. where dc.xlm = jhfx.xlm and dc.xingbie = jhfx.xingbie and dc.jgjlc = jhfx.jgjlc) as newtab
  91. where newtab.jhfx_id not in
  92. (select ab.id from(
  93. select jhfx.id,jhfx.xlm,jhfx.xingbie,jhfx.jgjlc
  94. from t_lunguili_account lgl, t_jihefenxi_account jhfx
  95. where lgl.xlm = jhfx.xlm and lgl.xingbie = jhfx.xingbie and lgl.jgjlc = jhfx.jgjlc)
  96. as ab,t_daocha_account dc
  97. where ab.xlm = dc.xlm and ab.xingbie = dc.xingbie and ab.jgjlc = dc.jgjlc)";
  98. string sql3 = @"select * from (select {lglColumns},{dcColumns}
  99. from public.t_lunguili_account lgl ,public.t_daocha_account dc
  100. where dc.xlm = lgl.xlm and dc.xingbie = lgl.xingbie and dc.jgjlc = lgl.jgjlc) as newtab
  101. where newtab.lgl_id not in
  102. (select ab.id from(
  103. select lgl.id,lgl.xlm,lgl.xingbie,lgl.jgjlc
  104. from t_lunguili_account lgl, t_jihefenxi_account jhfx
  105. where lgl.xlm = jhfx.xlm and lgl.xingbie = jhfx.xingbie and lgl.jgjlc = jhfx.jgjlc)
  106. as ab,t_daocha_account dc
  107. where ab.xlm = dc.xlm and ab.xingbie = dc.xingbie and ab.jgjlc = dc.jgjlc)";
  108. //string sql2 = @"select {jhfxColumns},{dcColumns} from public.t_jihefenxi_account jhfx ,public.t_daocha_account dc
  109. // where
  110. // dc.xlm = jhfx.xlm and
  111. // dc.xingbie = jhfx.xingbie and
  112. // dc.jgjlc = jhfx.jgjlc";
  113. //string sql3 = @"select {lglColumns},{dcColumns} from public.t_lunguili_account lgl ,public.t_daocha_account dc
  114. // where
  115. // dc.xlm = lgl.xlm and
  116. // dc.xingbie = lgl.xingbie and
  117. // dc.jgjlc = lgl.jgjlc";
  118. sql = sql.Replace("{lglColumns}", string.Join(",", lglList)).Replace("{dcColumns}", string.Join(",", dcList)).Replace("{jhfxColumns}", string.Join(",", jhfxList));
  119. sql2 = sql2.Replace("{dcColumns}", string.Join(",", dcList)).Replace("{jhfxColumns}", string.Join(",", jhfxList));
  120. sql3 = sql3.Replace("{lglColumns}", string.Join(",", lglList)).Replace("{dcColumns}", string.Join(",", dcList));
  121. //var list = db.Queryable<dynamic>().AS("datamanage").Where("id=@id", new { id = 1 }).ToList();
  122. //var list2 = db.Queryable<dynamic>("o").AS("order")
  123. // .AddJoinInfo("OrderDetail", "i", "o.id=i.OrderId")
  124. // .Where("id=@id", new { id = 1 })
  125. // .Select("o.*").ToList();
  126. var listqx = db.SqlQueryable<dynamic>(sql).ToList();
  127. var listqx1 = db.SqlQueryable<dynamic>(sql2).ToList();
  128. var listqx2 = db.SqlQueryable<dynamic>(sql3).ToList();
  129. var fristUnion = listqx.Union(listqx1).Distinct().ToList();
  130. var secondUnion = fristUnion.Union(listqx2).Distinct().ToList();
  131. return secondUnion;
  132. //if (listqx1.Count > listqx2.Count)
  133. //{
  134. // #region MyRegion
  135. // // List<int> indexs = new List<int>();
  136. // // for (int i = 0; i < listqx1.Count; i++)
  137. // // {
  138. // // for (int j = 0; j < listqx.Count; j++)
  139. // // {
  140. // // bool issame = true;
  141. // // foreach (KeyValuePair<string, object> col in listqx1[i])
  142. // // {
  143. // // string aa = col.Key;//属性
  144. // // string bb;
  145. // // if (col.Value.ToString() == null)
  146. // // {
  147. // // bb = "asdvbasghjdsadguhjasgdhjas";
  148. // // }
  149. // // else
  150. // // {
  151. // // bb = col.Value.ToString();//值
  152. // // }
  153. // // foreach (KeyValuePair<string, object> cola in listqx[j])
  154. // // {
  155. // // string aaa = cola.Key;//属性
  156. // // string bba;
  157. // // if (col.Value.ToString() == null)
  158. // // {
  159. // // bba = "a34567235473625462345672346";
  160. // // }
  161. // // else
  162. // // {
  163. // // bba = cola.Value.ToString();//值
  164. // // }
  165. // // if (aa == aaa && bb == bba)
  166. // // {
  167. // // issame = true;
  168. // // }
  169. // // }
  170. // // if (issame)
  171. // // {
  172. // // break;
  173. // // }
  174. // // }
  175. // // if (issame)
  176. // // {
  177. // // indexs.Add(i);
  178. // // break;
  179. // // }
  180. // // }
  181. // // }
  182. // // for (int i = indexs.Count; i >= 0; i--)
  183. // // {
  184. // // listqx1.RemoveAt(indexs[i]);
  185. // // }
  186. // #endregion
  187. // return listqx.Union(listqx1).Distinct().ToList();
  188. //}
  189. //else if (listqx1.Count < listqx2.Count)
  190. //{
  191. // return listqx.Union(listqx2).Distinct().ToList();
  192. //}
  193. //else
  194. //{
  195. // return listqx;
  196. //}
  197. }
  198. /// <summary>
  199. /// 获取轮轨力波形数据
  200. /// </summary>
  201. /// <param name="yswjm">映射文件名</param>
  202. /// <returns></returns>
  203. public static List<T_lunguili_boxing> GetLGL_BXData(string yswjm)
  204. {
  205. SqlSugarClient db = Config.GetPgClient();
  206. string strSQL = string.Format("select * from t_lunguili_boxing where yswjm = '{0}'", yswjm);
  207. //by expression
  208. return db.SqlQueryable<T_lunguili_boxing>(strSQL).ToList();
  209. }
  210. public static List<T_lunguili_boxing> GetLGL_BXDataByIDS(string ids)
  211. {
  212. string[] idList = ids.Split(',');
  213. if (idList.Length == 2)
  214. {
  215. SqlSugarClient db = Config.GetPgClient();
  216. int startId = Convert.ToInt32(idList[0]);
  217. int endId = Convert.ToInt32(idList[1]);
  218. string strSQL = string.Format("select * from t_lunguili_boxing where id BETWEEN {0} and {1}", startId, endId);
  219. //by expression
  220. return db.SqlQueryable<T_lunguili_boxing>(strSQL).ToList();
  221. }
  222. else
  223. {
  224. return null;
  225. }
  226. }
  227. /// <summary>
  228. /// 获取几何分析波形数据
  229. /// </summary>
  230. /// <param name="ids"></param>
  231. /// <returns></returns>
  232. public static List<T_jihefenxi_boxing> GetJHFX_BXDataByIDS(string ids)
  233. {
  234. string[] idList = ids.Split(',');
  235. if (idList.Length == 2)
  236. {
  237. SqlSugarClient db = Config.GetPgClient();
  238. int startId = Convert.ToInt32(idList[0]);
  239. int endId = Convert.ToInt32(idList[1]);
  240. string strSQL = string.Format("select * from t_jihefenxi_boxing where id BETWEEN {0} and {1}", startId, endId);
  241. //by expression
  242. return db.SqlQueryable<T_jihefenxi_boxing>(strSQL).ToList();
  243. }
  244. else
  245. {
  246. return null;
  247. }
  248. }
  249. /// <summary>
  250. /// 获取几何分析波形数据
  251. /// </summary>
  252. /// <param name="yswjm">映射文件名</param>
  253. /// <returns></returns>
  254. public static List<T_jihefenxi_boxing> GetJHFX_BXData(string yswjm)
  255. {
  256. SqlSugarClient db = Config.GetPgClient();
  257. string strSQL = string.Format("select * from t_jihefenxi_boxing where yswjm = '{0}'", yswjm);
  258. //by expression
  259. return db.SqlQueryable<T_jihefenxi_boxing>(strSQL).ToList();
  260. }
  261. }
  262. }