PushDataCopy.cs 23 KB

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