PushData.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. using System;
  2. using System.Web;
  3. using System.Web.SessionState;
  4. using System.Data;
  5. using System.Collections;
  6. using Curtain.DataAccess;
  7. using DK.XuWei.WebMes;
  8. using Newtonsoft.Json.Linq;
  9. using Newtonsoft.Json;
  10. using System.Collections.Generic;
  11. public static class PushData
  12. {
  13. //private static string _url = "http://edge.cosmoplat.com:30152/company/device/access";// 测试
  14. private static string _url = "http://edge.cosmoplat.com:30032/company/device/access";// 生产
  15. /// <summary>
  16. /// 烘干区
  17. /// </summary>
  18. public static void export02()
  19. {
  20. try {
  21. using (IDataAccess conn = DataAccess.Create())
  22. {
  23. DataTable dtDevice = conn.ExecuteDatatable(@"
  24. SELECT
  25. 'HGQ' || p.PLC_ID AS deviceCode,
  26. '烘干区' || P.PLC_NAME AS name
  27. FROM
  28. T_XT_PLC_V V
  29. INNER JOIN T_XT_PLC P ON P.PLC_ID = V.PLC_ID
  30. WHERE
  31. V.CREATETIME >= date'2021-07-01'
  32. AND V.CREATETIME < sysdate + 1
  33. GROUP BY
  34. p.PLC_ID,
  35. P.PLC_NAME
  36. ORDER BY
  37. P.PLC_NAME"
  38. );
  39. string str = "";
  40. for (int m = 7; m < 12; m++) {
  41. for (int i = 0; i < DateTime.DaysInMonth(2021, m); i++) {
  42. if (m == 7) ;
  43. DataTable dtDeviceData = conn.ExecuteDatatable(@"
  44. SELECT
  45. 'HGQ' || p.PLC_ID AS deviceCode,
  46. '烘干区' || P.PLC_NAME AS name,
  47. TO_CHAR(V.CREATETIME,'YYYY-MM-DD') as time,
  48. SUM(nvl( V.V100, 0 )) AS FNTEMPERATURE_房内温度,
  49. SUM(nvl( V.V104, 0 )) AS SDTEMPERATURE_设定温度,
  50. SUM(nvl( V.V108, 0 )) AS FNHUMIDITY_房内湿度,
  51. SUM(nvl( V.V112, 0 )) AS SDHUMIDITY_设定湿度,
  52. SUM(nvl( V.V120, 0 )) AS RSSTEMPERATURE_燃烧室温度,
  53. SUM(nvl( V.V124, 0 )) AS YRTEMPERATURE_余热温度
  54. FROM
  55. T_XT_PLC_V V
  56. INNER JOIN T_XT_PLC P ON P.PLC_ID = V.PLC_ID
  57. WHERE
  58. V.CREATETIME >= date'2021-07-01' + {I}
  59. AND V.CREATETIME < date'2021-07-01' + 1 + {I}
  60. GROUP BY
  61. p.PLC_ID,P.PLC_NAME,TO_CHAR(V.CREATETIME,'YYYY-MM-DD')
  62. ORDER BY
  63. p.PLC_ID,TO_CHAR(V.CREATETIME,'YYYY-MM-DD')".Replace("{I}",i + "")
  64. );
  65. if (dtDevice.Rows.Count == 0 || dtDeviceData.Rows.Count == 0)
  66. {
  67. return;
  68. }
  69. // 拼接主体
  70. JObject data = new JObject();
  71. data.Add(new JProperty("industryName", "广东区域"));
  72. data.Add(new JProperty("companyName", "佛山恒洁卫浴有限公司"));
  73. data.Add(new JProperty("productName", "烘干区"));
  74. data.Add(new JProperty("productCode", "FSHJHGQ"));
  75. data.Add(new JProperty("protocol", "HTTP"));
  76. data.Add(new JProperty("classfy", "陶瓷生产设备"));
  77. data.Add(new JProperty("lever", "低端"));
  78. data.Add(new JProperty("dimension", "工业品"));
  79. // 拼接device
  80. JArray arrDevice = new JArray();
  81. JObject device = null;
  82. foreach (DataRow row in dtDevice.Rows)
  83. {
  84. device = new JObject();
  85. device.Add(new JProperty("name", row["name"]));
  86. device.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
  87. device.Add(new JProperty("province", "广东省"));
  88. device.Add(new JProperty("city", "佛山市"));
  89. device.Add(new JProperty("address", "三水区乐平镇中油大道 3 号"));
  90. device.Add(new JProperty("worth", "0"));
  91. device.Add(new JProperty("latitude", "0"));
  92. device.Add(new JProperty("longitude", "0"));
  93. device.Add(new JProperty("manufacture", "2021-10-13"));
  94. arrDevice.Add(device);
  95. }
  96. data.Add("device", arrDevice);
  97. // 拼接deviceData
  98. JArray arrDeviceData = new JArray();
  99. JObject deviceData = null;
  100. string[] colNames;
  101. // 时间戳
  102. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  103. string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  104. foreach (DataRow row in dtDeviceData.Rows)
  105. {
  106. foreach (DataColumn col in dtDeviceData.Columns)
  107. {
  108. if (col.ColumnName.Equals("DEVICECODE") || col.ColumnName.Equals("NAME"))
  109. {
  110. continue;
  111. }
  112. colNames = col.ColumnName.Split('_');
  113. deviceData = new JObject();
  114. deviceData.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
  115. deviceData.Add(new JProperty("name", colNames[1]));
  116. deviceData.Add(new JProperty("mark", colNames[0]));
  117. deviceData.Add(new JProperty("value", row[col].ToString()));
  118. deviceData.Add(new JProperty("timestamp", timestamp));
  119. arrDeviceData.Add(deviceData);
  120. }
  121. }
  122. data.Add("deviceData", arrDeviceData);
  123. //上报数据
  124. string message = JsonClient.Post(_url, data.ToString());
  125. }
  126. }
  127. }
  128. Curtain.Log.Logger.Debug("烘干区数据上报成功!");
  129. }
  130. catch (Exception ex) {
  131. Curtain.Log.Logger.Error(ex);
  132. }
  133. }
  134. /// <summary>
  135. /// 施釉房
  136. /// </summary>
  137. public static void export03()
  138. {
  139. try {
  140. using (IDataAccess conn = DataAccess.Create())
  141. {
  142. DataTable dtDevice = conn.ExecuteDatatable(@"
  143. SELECT
  144. 'SYF' || REPLACE ( GD.GLAZINGROOM, '#', '' ) AS deviceCode,
  145. '施釉房' || GD.GLAZINGROOM AS name
  146. FROM
  147. TP_PM_PRODUCTIONDATA P
  148. INNER JOIN TP_PM_GROUTINGDAILYDETAIL GD ON GD.GROUTINGDAILYDETAILID = P.GROUTINGDAILYDETAILID
  149. INNER JOIN TP_PM_GOODSGLAZING G ON P.GROUTINGDAILYDETAILID = G.GROUTINGDAILYDETAILID
  150. WHERE
  151. P.PROCEDUREID = 98
  152. AND P.CREATETIME >= date'2021-07-01'
  153. AND P.CREATETIME < sysdate + 1
  154. GROUP BY
  155. GD.GLAZINGROOM
  156. ORDER BY
  157. GD.GLAZINGROOM"
  158. );
  159. DataTable dtDeviceData = conn.ExecuteDatatable(@"
  160. SELECT
  161. t.deviceCode,
  162. t.name,
  163. t.TEMP_釉温,
  164. t.PRESSURE_釉压
  165. FROM
  166. (
  167. SELECT
  168. 'SYF' || REPLACE ( GD.GLAZINGROOM, '#', '' ) AS deviceCode,
  169. '施釉房' || GD.GLAZINGROOM AS name,
  170. G.G_TEMP AS TEMP_釉温,
  171. G.G_PRESSURE AS PRESSURE_釉压,
  172. rank ( ) over ( PARTITION BY GD.GLAZINGROOM ORDER BY P.GROUTINGDAILYDETAILID DESC ) AS rk
  173. FROM
  174. TP_PM_PRODUCTIONDATA P
  175. INNER JOIN TP_PM_GROUTINGDAILYDETAIL GD ON GD.GROUTINGDAILYDETAILID = P.GROUTINGDAILYDETAILID
  176. INNER JOIN TP_PM_GOODSGLAZING G ON P.GROUTINGDAILYDETAILID = G.GROUTINGDAILYDETAILID
  177. WHERE
  178. P.PROCEDUREID = 98
  179. AND P.CREATETIME >= date'2021-07-01'
  180. AND P.CREATETIME < sysdate + 1
  181. ) t
  182. WHERE
  183. t.rk <= 1
  184. ORDER BY
  185. t.name"
  186. );
  187. if (dtDevice.Rows.Count == 0 || dtDeviceData.Rows.Count == 0)
  188. {
  189. return;
  190. }
  191. // 拼接主体
  192. JObject data = new JObject();
  193. data.Add(new JProperty("industryName", "广东区域"));
  194. data.Add(new JProperty("companyName", "佛山恒洁卫浴有限公司"));
  195. data.Add(new JProperty("productName", "施釉房"));
  196. data.Add(new JProperty("productCode", "FSHJSYF"));
  197. data.Add(new JProperty("protocol", "HTTP"));
  198. data.Add(new JProperty("classfy", "陶瓷生产设备"));
  199. data.Add(new JProperty("lever", "低端"));
  200. data.Add(new JProperty("dimension", "工业品"));
  201. // 拼接device
  202. JArray arrDevice = new JArray();
  203. JObject device = null;
  204. foreach (DataRow row in dtDevice.Rows)
  205. {
  206. device = new JObject();
  207. device.Add(new JProperty("name", row["name"]));
  208. device.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
  209. device.Add(new JProperty("province", "广东省"));
  210. device.Add(new JProperty("city", "佛山市"));
  211. device.Add(new JProperty("address", "三水区乐平镇中油大道 3 号"));
  212. device.Add(new JProperty("worth", "0"));
  213. device.Add(new JProperty("latitude", "0"));
  214. device.Add(new JProperty("longitude", "0"));
  215. device.Add(new JProperty("manufacture", "2021-10-13"));
  216. arrDevice.Add(device);
  217. }
  218. data.Add("device", arrDevice);
  219. // 拼接deviceData
  220. JArray arrDeviceData = new JArray();
  221. JObject deviceData = null;
  222. string[] colNames;
  223. // 时间戳
  224. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  225. string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  226. foreach (DataRow row in dtDeviceData.Rows)
  227. {
  228. foreach (DataColumn col in dtDeviceData.Columns)
  229. {
  230. if (col.ColumnName.Equals("DEVICECODE") || col.ColumnName.Equals("NAME"))
  231. {
  232. continue;
  233. }
  234. colNames = col.ColumnName.Split('_');
  235. deviceData = new JObject();
  236. deviceData.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
  237. deviceData.Add(new JProperty("name", colNames[1]));
  238. deviceData.Add(new JProperty("mark", colNames[0]));
  239. deviceData.Add(new JProperty("value", row[col].ToString()));
  240. deviceData.Add(new JProperty("timestamp", timestamp));
  241. arrDeviceData.Add(deviceData);
  242. }
  243. }
  244. data.Add("deviceData", arrDeviceData);
  245. //上报数据
  246. string message = JsonClient.Post(_url, data.ToString());
  247. }
  248. Curtain.Log.Logger.Debug("施釉房数据上报成功!");
  249. }
  250. catch (Exception ex)
  251. {
  252. Curtain.Log.Logger.Error(ex);
  253. }
  254. }
  255. /// <summary>
  256. /// 成品测漏
  257. /// </summary>
  258. public static void export04()
  259. {
  260. try {
  261. using (IDataAccess conn = DataAccess.Create())
  262. {
  263. DataTable dtDevice = conn.ExecuteDatatable(@"
  264. SELECT
  265. 'CPCL' || W.WORKSTATIONID AS deviceCode,
  266. '成品测漏' || W.WORKSTATIONNAME AS name
  267. FROM
  268. TP_PM_GOODSLEAK L
  269. INNER JOIN TP_MST_WORKSTATION W ON W.WORKSTATIONID = L.WS_ID
  270. WHERE
  271. L.LEAKTYPE = 1
  272. AND L.CREATETIME >= date'2021-07-01'
  273. AND L.CREATETIME < sysdate + 1
  274. GROUP BY
  275. W.WORKSTATIONID,
  276. W.WORKSTATIONNAME
  277. ORDER BY
  278. W.WORKSTATIONNAME"
  279. );
  280. DataTable dtDeviceData = conn.ExecuteDatatable(@"
  281. SELECT
  282. t.deviceCode,
  283. t.name,
  284. t.TESTRESULT_测试结果,
  285. t.LEAKAGE_泄漏量
  286. FROM
  287. (
  288. SELECT
  289. 'CPCL' || W.WORKSTATIONID AS deviceCode,
  290. '成品测漏' || W.WORKSTATIONNAME AS name,
  291. DECODE( L.IS_GOOD, 0, '不合格', 1, '合格', '' ) AS TESTRESULT_测试结果,
  292. L.LEAKAGE AS LEAKAGE_泄漏量,
  293. rank ( ) over ( PARTITION BY W.WORKSTATIONNAME ORDER BY L.CREATETIME DESC ) AS rk
  294. FROM
  295. TP_PM_GOODSLEAK L
  296. INNER JOIN TP_MST_WORKSTATION W ON W.WORKSTATIONID = L.WS_ID
  297. WHERE
  298. L.LEAKTYPE = 1
  299. AND L.CREATETIME >= date'2021-07-01'
  300. AND L.CREATETIME < sysdate + 1
  301. ) t
  302. WHERE
  303. t.rk <= 1
  304. ORDER BY
  305. t.name"
  306. );
  307. if (dtDevice.Rows.Count == 0 || dtDeviceData.Rows.Count == 0)
  308. {
  309. return;
  310. }
  311. // 拼接主体
  312. JObject data = new JObject();
  313. data.Add(new JProperty("industryName", "广东区域"));
  314. data.Add(new JProperty("companyName", "佛山恒洁卫浴有限公司"));
  315. data.Add(new JProperty("productName", "成品测漏"));
  316. data.Add(new JProperty("productCode", "FSHJCPCL"));
  317. data.Add(new JProperty("protocol", "HTTP"));
  318. data.Add(new JProperty("classfy", "陶瓷生产设备"));
  319. data.Add(new JProperty("lever", "低端"));
  320. data.Add(new JProperty("dimension", "工业品"));
  321. // 拼接device
  322. JArray arrDevice = new JArray();
  323. JObject device = null;
  324. foreach (DataRow row in dtDevice.Rows)
  325. {
  326. device = new JObject();
  327. device.Add(new JProperty("name", row["name"]));
  328. device.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
  329. device.Add(new JProperty("province", "广东省"));
  330. device.Add(new JProperty("city", "佛山市"));
  331. device.Add(new JProperty("address", "三水区乐平镇中油大道 3 号"));
  332. device.Add(new JProperty("worth", "0"));
  333. device.Add(new JProperty("latitude", "0"));
  334. device.Add(new JProperty("longitude", "0"));
  335. device.Add(new JProperty("manufacture", "2021-10-13"));
  336. arrDevice.Add(device);
  337. }
  338. data.Add("device", arrDevice);
  339. // 拼接deviceData
  340. JArray arrDeviceData = new JArray();
  341. JObject deviceData = null;
  342. string[] colNames;
  343. // 时间戳
  344. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  345. string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  346. foreach (DataRow row in dtDeviceData.Rows)
  347. {
  348. foreach (DataColumn col in dtDeviceData.Columns)
  349. {
  350. if (col.ColumnName.Equals("DEVICECODE") || col.ColumnName.Equals("NAME"))
  351. {
  352. continue;
  353. }
  354. colNames = col.ColumnName.Split('_');
  355. deviceData = new JObject();
  356. deviceData.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
  357. deviceData.Add(new JProperty("name", colNames[1]));
  358. deviceData.Add(new JProperty("mark", colNames[0]));
  359. deviceData.Add(new JProperty("value", row[col].ToString()));
  360. deviceData.Add(new JProperty("timestamp", timestamp));
  361. arrDeviceData.Add(deviceData);
  362. }
  363. }
  364. data.Add("deviceData", arrDeviceData);
  365. //上报数据
  366. string message = JsonClient.Post(_url, data.ToString());
  367. }
  368. Curtain.Log.Logger.Debug("成品侧漏数据上报成功!");
  369. }
  370. catch (Exception ex)
  371. {
  372. Curtain.Log.Logger.Error(ex);
  373. }
  374. }
  375. /// <summary>
  376. /// 试用结果
  377. /// </summary>
  378. public static void export05()
  379. {
  380. try {
  381. using (IDataAccess conn = DataAccess.Create())
  382. {
  383. DataTable dtDevice = conn.ExecuteDatatable(@"
  384. SELECT
  385. 'SYJG' || W.WORKSTATIONID AS deviceCode,
  386. '试用结果' || W.WORKSTATIONNAME AS name
  387. FROM
  388. TP_PM_GOODSLEAK L
  389. INNER JOIN TP_MST_WORKSTATION W ON W.WORKSTATIONID = L.WS_ID
  390. WHERE
  391. L.LEAKTYPE = 2
  392. AND L.CREATETIME >= date'2021-07-01'
  393. AND L.CREATETIME < sysdate + 1
  394. GROUP BY
  395. W.WORKSTATIONID,
  396. W.WORKSTATIONNAME
  397. ORDER BY
  398. W.WORKSTATIONNAME"
  399. );
  400. DataTable dtDeviceData = conn.ExecuteDatatable(@"
  401. SELECT
  402. t.deviceCode,
  403. t.name,
  404. t.TESTRESULT_测试结果
  405. FROM
  406. (
  407. SELECT
  408. 'SYJG' || W.WORKSTATIONID AS deviceCode,
  409. '试用结果' || W.WORKSTATIONNAME AS name,
  410. DECODE( L.IS_GOOD, 0, '不合格', 1, '合格', '' ) AS TESTRESULT_测试结果,
  411. rank ( ) over ( PARTITION BY W.WORKSTATIONNAME ORDER BY L.CREATETIME DESC ) AS rk
  412. FROM
  413. TP_PM_GOODSLEAK L
  414. INNER JOIN TP_MST_WORKSTATION W ON W.WORKSTATIONID = L.WS_ID
  415. WHERE
  416. L.LEAKTYPE = 2
  417. AND L.CREATETIME >= date'2021-07-01'
  418. AND L.CREATETIME < sysdate + 1
  419. ) t
  420. WHERE
  421. t.rk <= 1
  422. ORDER BY
  423. t.name"
  424. );
  425. if (dtDevice.Rows.Count == 0 || dtDeviceData.Rows.Count == 0)
  426. {
  427. return;
  428. }
  429. // 拼接主体
  430. JObject data = new JObject();
  431. data.Add(new JProperty("industryName", "广东区域"));
  432. data.Add(new JProperty("companyName", "佛山恒洁卫浴有限公司"));
  433. data.Add(new JProperty("productName", "试用结果"));
  434. data.Add(new JProperty("productCode", "FSHJCPCL"));
  435. data.Add(new JProperty("protocol", "HTTP"));
  436. data.Add(new JProperty("classfy", "陶瓷生产设备"));
  437. data.Add(new JProperty("lever", "低端"));
  438. data.Add(new JProperty("dimension", "工业品"));
  439. // 拼接device
  440. JArray arrDevice = new JArray();
  441. JObject device = null;
  442. foreach (DataRow row in dtDevice.Rows)
  443. {
  444. device = new JObject();
  445. device.Add(new JProperty("name", row["name"]));
  446. device.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
  447. device.Add(new JProperty("province", "广东省"));
  448. device.Add(new JProperty("city", "佛山市"));
  449. device.Add(new JProperty("address", "三水区乐平镇中油大道 3 号"));
  450. device.Add(new JProperty("worth", "0"));
  451. device.Add(new JProperty("latitude", "0"));
  452. device.Add(new JProperty("longitude", "0"));
  453. device.Add(new JProperty("manufacture", "2021-10-13"));
  454. arrDevice.Add(device);
  455. }
  456. data.Add("device", arrDevice);
  457. // 拼接deviceData
  458. JArray arrDeviceData = new JArray();
  459. JObject deviceData = null;
  460. string[] colNames;
  461. // 时间戳
  462. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  463. string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  464. foreach (DataRow row in dtDeviceData.Rows)
  465. {
  466. foreach (DataColumn col in dtDeviceData.Columns)
  467. {
  468. if (col.ColumnName.Equals("DEVICECODE") || col.ColumnName.Equals("NAME"))
  469. {
  470. continue;
  471. }
  472. colNames = col.ColumnName.Split('_');
  473. deviceData = new JObject();
  474. deviceData.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
  475. deviceData.Add(new JProperty("name", colNames[1]));
  476. deviceData.Add(new JProperty("mark", colNames[0]));
  477. deviceData.Add(new JProperty("value", row[col].ToString()));
  478. deviceData.Add(new JProperty("timestamp", timestamp));
  479. arrDeviceData.Add(deviceData);
  480. }
  481. }
  482. data.Add("deviceData", arrDeviceData);
  483. //上报数据
  484. string message = JsonClient.Post(_url, data.ToString());
  485. }
  486. Curtain.Log.Logger.Debug("试用数据上报成功!");
  487. }
  488. catch (Exception ex)
  489. {
  490. Curtain.Log.Logger.Error(ex);
  491. }
  492. }
  493. /// <summary>
  494. /// 获取在用电能设备
  495. /// </summary>
  496. public static void getDeviceId()
  497. {
  498. try {
  499. using (IDataAccess conn = DataAccess.Create())
  500. {
  501. string data00 = @"
  502. DELETE FROM TP_DEV_DEVICEONUSING
  503. ";
  504. int result00 = conn.ExecuteNonQuery(data00);
  505. string data0 = @"{
  506. ""appid"": ""ETP001018"",
  507. ""token"": ""6d06bb6d2173a4fdcfd098eba8a6605c""
  508. }
  509. ";
  510. string url = "http://htemp.cn/opi/devices";// 生产
  511. string message = JsonClient.Post(url, data0.ToString());
  512. //Dictionary<string, object> ret = JsonHelper.JsonToDictionaryso(message + "");
  513. //JsonConvert.DeserializeObject<Dictionary<string, object>>(message);
  514. JObject ja = (JObject)JsonConvert.DeserializeObject(message); //反序列化为数组
  515. string code = ja["code"].ToString();
  516. string msg = ja["msg"].ToString();
  517. string timestamp = ja["timestamp"].ToString();
  518. string data = ja["data"].ToString();
  519. JArray ja2 = (JArray)JsonConvert.DeserializeObject(data); //反序列化为数组
  520. string name = ja2[0]["name"].ToString();
  521. string item = ja2[0]["item"].ToString();
  522. JArray ja3 = (JArray)JsonConvert.DeserializeObject(item); //反序列化为数组
  523. string device = ja3[0]["device"].ToString();
  524. string maters = ja3[0]["maters"].ToString();
  525. for (int i = 0 + 1; i < ja3.Count; i++)
  526. {
  527. device += "," + ja3[i]["device"].ToString();
  528. maters += "," + ja3[i]["maters"].ToString();
  529. }
  530. string str = "[" + maters.Replace("[", "").Replace("]", "") + "]";
  531. JArray ja4 = (JArray)JsonConvert.DeserializeObject(str); //反序列化为数组
  532. List<int> list1 = new List<int>();
  533. list1.Add(Convert.ToInt32(ja4[0]["id"].ToString()));
  534. List<int> list2 = new List<int>();
  535. list2.Add(Convert.ToInt32(ja4[0]["position"].ToString()));
  536. List<string> list3 = new List<string>();
  537. list3.Add(ja4[0]["component_no"].ToString());
  538. for (int i = 0 + 1; i < ja4.Count; i++)
  539. {
  540. list1.Add(Convert.ToInt32(ja4[i]["id"].ToString()));
  541. list2.Add(Convert.ToInt32(ja4[i]["position"].ToString()));
  542. list3.Add(ja4[i]["component_no"].ToString());
  543. }
  544. int result = 0;
  545. foreach (int i in list1)
  546. {
  547. //context.Response.Write(i + "___");
  548. string data2 = @"
  549. INSERT INTO TP_DEV_DEVICEONUSING(ID,CREATETIME) VALUES({ID},SYSDATE)
  550. ".Replace("{ID}", i + "");
  551. result += conn.ExecuteNonQuery(data2);
  552. }
  553. }
  554. Curtain.Log.Logger.Debug("在用电能设备获取成功!");
  555. }
  556. catch (Exception ex)
  557. {
  558. Curtain.Log.Logger.Error(ex);
  559. }
  560. }
  561. /// <summary>
  562. /// 获取设备电量
  563. /// </summary>
  564. public static void getDeviceElectronicCharge()
  565. {
  566. try
  567. {
  568. using (IDataAccess conn = DataAccess.Create())
  569. {
  570. string data00 = @"
  571. DELETE
  572. FROM
  573. TP_DEV_DEVICEELECTRICCHARGE
  574. WHERE TRUNC(DEVICEDATE,'DD') = TRUNC(SYSDATE,'DD')
  575. ";
  576. DataTable dt00 = conn.ExecuteDatatable(data00);
  577. string data0 = @"
  578. SELECT
  579. ID
  580. FROM
  581. TP_DEV_DEVICEONUSING
  582. ";
  583. DataTable dt = conn.ExecuteDatatable(data0);
  584. string str = "";
  585. int result = 0;
  586. for (int n = 0; n < dt.Rows.Count; n++)
  587. {
  588. int num = Convert.ToInt32(dt.Rows[n]["ID"] + "");
  589. string data2 = @"{
  590. ""appid"": ""ETP001018"",
  591. ""token"": ""6d06bb6d2173a4fdcfd098eba8a6605c"",
  592. ""meter_id"": {ID}
  593. }
  594. ".Replace("{ID}", num + "");
  595. string url = "http://htemp.cn/opi/energy";// 生产
  596. string message = JsonClient.Post(url, data2.ToString());
  597. Curtain.Log.Logger.Info(message);
  598. JObject ja = new JObject();
  599. ja = (JObject)JsonConvert.DeserializeObject(message); //反序列化为数组
  600. string code = ja["code"].ToString();
  601. string msg = ja["msg"].ToString();
  602. string timestamp = ja["timestamp"].ToString();
  603. string data = ja["data"].ToString();
  604. JArray ja2 = new JArray();
  605. ja2 = (JArray)JsonConvert.DeserializeObject("[" + data + "]"); //反序列化为数组
  606. string meter_id = ja2[0]["meter_id"].ToString();
  607. string item = ja2[0]["item"].ToString();
  608. //JArray ja3 = (JArray)JsonConvert.DeserializeObject(item); //反序列化为数组
  609. //string device = ja3[0]["device"].ToString();
  610. //string maters = ja3[0]["maters"].ToString();
  611. //for (int i = 0 + 1; i < ja3.Count; i++)
  612. //{
  613. // device += "," + ja3[i]["device"].ToString();
  614. // maters += "," + ja3[i]["maters"].ToString();
  615. //}
  616. str = "[" + item.Replace("[", "").Replace("]", "") + "]";
  617. JArray ja4 = new JArray();
  618. ja4 = (JArray)JsonConvert.DeserializeObject(str); //反序列化为数组
  619. string date = "_";
  620. double epi = 0;
  621. double etp = 0;
  622. double eta = 0;
  623. double etv = 0;
  624. for (int m = 0; m < ja4.Count; m++)
  625. {
  626. if (ja4[m].ToString().IndexOf("date") > 0)
  627. {
  628. date = ja4[m]["date"].ToString();
  629. }
  630. if (ja4[m].ToString().IndexOf("epi") > 0)
  631. {
  632. epi = Convert.ToDouble(ja4[m]["epi"].ToString());
  633. }
  634. if (ja4[m].ToString().IndexOf("etp") > 0)
  635. {
  636. etp = Convert.ToDouble(ja4[m]["etp"].ToString());
  637. }
  638. if (ja4[m].ToString().IndexOf("eta") > 0)
  639. {
  640. eta = Convert.ToDouble(ja4[m]["eta"].ToString());
  641. }
  642. if (ja4[m].ToString().IndexOf("etv") > 0)
  643. {
  644. etv = Convert.ToDouble(ja4[m]["etv"].ToString());
  645. }
  646. string data3 = @"
  647. INSERT INTO TP_DEV_DEVICEELECTRICCHARGE(APPID,TOKEN,METER_ID,DEVICEDATE,EPI,ETP,ETA,ETV,CREATETIME)
  648. VALUES('ETP001018','6d06bb6d2173a4fdcfd098eba8a6605c',{ID},TO_DATE('{DATE}', 'YYYY-MM-DD HH24-MI-SS'),{EPI},{ETP},{ETA},{ETV},SYSDATE)
  649. ".Replace("{ID}", num + "").Replace("{DATE}", date).Replace("{EPI}", epi + "").Replace("{ETP}", etp + "").Replace("{ETA}", eta + "").Replace("{ETV}", etv + "");
  650. result += conn.ExecuteNonQuery(data3);
  651. }
  652. }
  653. }
  654. Curtain.Log.Logger.Debug("电能数据获取成功!" );
  655. }
  656. catch(Exception ex)
  657. {
  658. Curtain.Log.Logger.Error(ex);
  659. }
  660. }
  661. }