| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722 |
- using System;
- using System.Web;
- using System.Web.SessionState;
- using System.Data;
- using System.Collections;
- using Curtain.DataAccess;
- using DK.XuWei.WebMes;
- using Newtonsoft.Json.Linq;
- using Newtonsoft.Json;
- using System.Collections.Generic;
- public static class PushDataCopy
- {
- //private static string _url = "http://edge.cosmoplat.com:30152/company/device/access";// 测试
- private static string _url = "http://edge.cosmoplat.com:30032/company/device/access";// 生产
- /// <summary>
- /// 烘干区
- /// </summary>
- public static void export02()
- {
- try {
- using (IDataAccess conn = DataAccess.Create())
- {
- DataTable dtDevice = conn.ExecuteDatatable(@"
- SELECT
- 'HGQ' || p.PLC_ID AS deviceCode,
- '烘干区' || P.PLC_NAME AS name
- FROM
- T_XT_PLC_V V
- INNER JOIN T_XT_PLC P ON P.PLC_ID = V.PLC_ID
- WHERE
- V.CREATETIME >= to_date( to_char( SYSDATE, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- AND V.CREATETIME < to_date( to_char( SYSDATE + 1 / 24, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- GROUP BY
- p.PLC_ID,
- P.PLC_NAME
- ORDER BY
- P.PLC_NAME"
- );
- DataTable dtDeviceData = conn.ExecuteDatatable(@"
- SELECT
- t.deviceCode,
- t.name,
- t.FNTEMPERATURE_房内温度,
- t.SDTEMPERATURE_设定温度,
- t.FNHUMIDITY_房内湿度,
- t.SDHUMIDITY_设定湿度,
- t.RSSTEMPERATURE_燃烧室温度,
- t.YRTEMPERATURE_余热温度
- FROM
- (
- SELECT
- 'HGQ' || p.PLC_ID AS deviceCode,
- '烘干区' || P.PLC_NAME AS name,
- nvl( V.V100, 0 ) AS FNTEMPERATURE_房内温度,
- nvl( V.V104, 0 ) AS SDTEMPERATURE_设定温度,
- nvl( V.V108, 0 ) AS FNHUMIDITY_房内湿度,
- nvl( V.V112, 0 ) AS SDHUMIDITY_设定湿度,
- nvl( V.V120, 0 ) AS RSSTEMPERATURE_燃烧室温度,
- nvl( V.V124, 0 ) AS YRTEMPERATURE_余热温度,
- rank ( ) over ( PARTITION BY P.PLC_ID ORDER BY V.VID DESC ) AS rk
- FROM
- T_XT_PLC_V V
- INNER JOIN T_XT_PLC P ON P.PLC_ID = V.PLC_ID
- WHERE
- V.CREATETIME >= to_date( to_char( SYSDATE, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- AND V.CREATETIME < to_date( to_char( SYSDATE + 1 / 24, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- ) t
- WHERE
- t.rk <= 1
- ORDER BY
- t.name"
- );
- if (dtDevice.Rows.Count == 0 || dtDeviceData.Rows.Count == 0)
- {
- return;
- }
- // 拼接主体
- JObject data = new JObject();
- data.Add(new JProperty("industryName", "广东区域"));
- data.Add(new JProperty("companyName", "佛山恒洁卫浴有限公司"));
- data.Add(new JProperty("productName", "烘干区"));
- data.Add(new JProperty("productCode", "FSHJHGQ"));
- data.Add(new JProperty("protocol", "HTTP"));
- data.Add(new JProperty("classfy", "陶瓷生产设备"));
- data.Add(new JProperty("lever", "低端"));
- data.Add(new JProperty("dimension", "工业品"));
- // 拼接device
- JArray arrDevice = new JArray();
- JObject device = null;
- foreach (DataRow row in dtDevice.Rows)
- {
- device = new JObject();
- device.Add(new JProperty("name", row["name"]));
- device.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
- device.Add(new JProperty("province", "广东省"));
- device.Add(new JProperty("city", "佛山市"));
- device.Add(new JProperty("address", "三水区乐平镇中油大道 3 号"));
- device.Add(new JProperty("worth", "0"));
- device.Add(new JProperty("latitude", "0"));
- device.Add(new JProperty("longitude", "0"));
- device.Add(new JProperty("manufacture", "2021-10-13"));
- arrDevice.Add(device);
- }
- data.Add("device", arrDevice);
- // 拼接deviceData
- JArray arrDeviceData = new JArray();
- JObject deviceData = null;
- string[] colNames;
- // 时间戳
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- foreach (DataRow row in dtDeviceData.Rows)
- {
- foreach (DataColumn col in dtDeviceData.Columns)
- {
- if (col.ColumnName.Equals("DEVICECODE") || col.ColumnName.Equals("NAME"))
- {
- continue;
- }
- colNames = col.ColumnName.Split('_');
- deviceData = new JObject();
- deviceData.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
- deviceData.Add(new JProperty("name", colNames[1]));
- deviceData.Add(new JProperty("mark", colNames[0]));
- deviceData.Add(new JProperty("value", row[col].ToString()));
- deviceData.Add(new JProperty("timestamp", timestamp));
- arrDeviceData.Add(deviceData);
- }
- }
- data.Add("deviceData", arrDeviceData);
- //上报数据
- string message = JsonClient.Post(_url, data.ToString());
- }
- Curtain.Log.Logger.Debug("烘干区数据上报成功!");
- }
- catch (Exception ex) {
- Curtain.Log.Logger.Error(ex);
- }
- }
- /// <summary>
- /// 施釉房
- /// </summary>
- public static void export03()
- {
- try {
- using (IDataAccess conn = DataAccess.Create())
- {
- DataTable dtDevice = conn.ExecuteDatatable(@"
- SELECT
- 'SYF' || REPLACE ( GD.GLAZINGROOM, '#', '' ) AS deviceCode,
- '施釉房' || GD.GLAZINGROOM AS name
- FROM
- TP_PM_PRODUCTIONDATA P
- INNER JOIN TP_PM_GROUTINGDAILYDETAIL GD ON GD.GROUTINGDAILYDETAILID = P.GROUTINGDAILYDETAILID
- INNER JOIN TP_PM_GOODSGLAZING G ON P.GROUTINGDAILYDETAILID = G.GROUTINGDAILYDETAILID
- WHERE
- P.PROCEDUREID = 98
- AND P.CREATETIME >= to_date( to_char( SYSDATE, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- AND P.CREATETIME < to_date( to_char( SYSDATE + 1 / 24, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- GROUP BY
- GD.GLAZINGROOM
- ORDER BY
- GD.GLAZINGROOM"
- );
- DataTable dtDeviceData = conn.ExecuteDatatable(@"
- SELECT
- t.deviceCode,
- t.name,
- t.TEMP_釉温,
- t.PRESSURE_釉压
- FROM
- (
- SELECT
- 'SYF' || REPLACE ( GD.GLAZINGROOM, '#', '' ) AS deviceCode,
- '施釉房' || GD.GLAZINGROOM AS name,
- G.G_TEMP AS TEMP_釉温,
- G.G_PRESSURE AS PRESSURE_釉压,
- rank ( ) over ( PARTITION BY GD.GLAZINGROOM ORDER BY P.GROUTINGDAILYDETAILID DESC ) AS rk
- FROM
- TP_PM_PRODUCTIONDATA P
- INNER JOIN TP_PM_GROUTINGDAILYDETAIL GD ON GD.GROUTINGDAILYDETAILID = P.GROUTINGDAILYDETAILID
- INNER JOIN TP_PM_GOODSGLAZING G ON P.GROUTINGDAILYDETAILID = G.GROUTINGDAILYDETAILID
- WHERE
- P.PROCEDUREID = 98
- AND P.CREATETIME >= to_date( to_char( SYSDATE, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- AND P.CREATETIME < to_date( to_char( SYSDATE + 1 / 24, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- ) t
- WHERE
- t.rk <= 1
- ORDER BY
- t.name"
- );
- if (dtDevice.Rows.Count == 0 || dtDeviceData.Rows.Count == 0)
- {
- return;
- }
- // 拼接主体
- JObject data = new JObject();
- data.Add(new JProperty("industryName", "广东区域"));
- data.Add(new JProperty("companyName", "佛山恒洁卫浴有限公司"));
- data.Add(new JProperty("productName", "施釉房"));
- data.Add(new JProperty("productCode", "FSHJSYF"));
- data.Add(new JProperty("protocol", "HTTP"));
- data.Add(new JProperty("classfy", "陶瓷生产设备"));
- data.Add(new JProperty("lever", "低端"));
- data.Add(new JProperty("dimension", "工业品"));
- // 拼接device
- JArray arrDevice = new JArray();
- JObject device = null;
- foreach (DataRow row in dtDevice.Rows)
- {
- device = new JObject();
- device.Add(new JProperty("name", row["name"]));
- device.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
- device.Add(new JProperty("province", "广东省"));
- device.Add(new JProperty("city", "佛山市"));
- device.Add(new JProperty("address", "三水区乐平镇中油大道 3 号"));
- device.Add(new JProperty("worth", "0"));
- device.Add(new JProperty("latitude", "0"));
- device.Add(new JProperty("longitude", "0"));
- device.Add(new JProperty("manufacture", "2021-10-13"));
- arrDevice.Add(device);
- }
- data.Add("device", arrDevice);
- // 拼接deviceData
- JArray arrDeviceData = new JArray();
- JObject deviceData = null;
- string[] colNames;
- // 时间戳
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- foreach (DataRow row in dtDeviceData.Rows)
- {
- foreach (DataColumn col in dtDeviceData.Columns)
- {
- if (col.ColumnName.Equals("DEVICECODE") || col.ColumnName.Equals("NAME"))
- {
- continue;
- }
- colNames = col.ColumnName.Split('_');
- deviceData = new JObject();
- deviceData.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
- deviceData.Add(new JProperty("name", colNames[1]));
- deviceData.Add(new JProperty("mark", colNames[0]));
- deviceData.Add(new JProperty("value", row[col].ToString()));
- deviceData.Add(new JProperty("timestamp", timestamp));
- arrDeviceData.Add(deviceData);
- }
- }
- data.Add("deviceData", arrDeviceData);
- //上报数据
- string message = JsonClient.Post(_url, data.ToString());
- }
- Curtain.Log.Logger.Debug("施釉房数据上报成功!");
- }
- catch (Exception ex)
- {
- Curtain.Log.Logger.Error(ex);
- }
- }
- /// <summary>
- /// 成品测漏
- /// </summary>
- public static void export04()
- {
- try {
- using (IDataAccess conn = DataAccess.Create())
- {
- DataTable dtDevice = conn.ExecuteDatatable(@"
- SELECT
- 'CPCL' || W.WORKSTATIONID AS deviceCode,
- '成品测漏' || W.WORKSTATIONNAME AS name
- FROM
- TP_PM_GOODSLEAK L
- INNER JOIN TP_MST_WORKSTATION W ON W.WORKSTATIONID = L.WS_ID
- WHERE
- L.LEAKTYPE = 1
- AND L.CREATETIME >= to_date( to_char( SYSDATE, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- AND L.CREATETIME < to_date( to_char( SYSDATE + 1 / 24, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- GROUP BY
- W.WORKSTATIONID,
- W.WORKSTATIONNAME
- ORDER BY
- W.WORKSTATIONNAME"
- );
- DataTable dtDeviceData = conn.ExecuteDatatable(@"
- SELECT
- t.deviceCode,
- t.name,
- t.TESTRESULT_测试结果,
- t.LEAKAGE_泄漏量
- FROM
- (
- SELECT
- 'CPCL' || W.WORKSTATIONID AS deviceCode,
- '成品测漏' || W.WORKSTATIONNAME AS name,
- DECODE( L.IS_GOOD, 0, '不合格', 1, '合格', '' ) AS TESTRESULT_测试结果,
- L.LEAKAGE AS LEAKAGE_泄漏量,
- rank ( ) over ( PARTITION BY W.WORKSTATIONNAME ORDER BY L.CREATETIME DESC ) AS rk
- FROM
- TP_PM_GOODSLEAK L
- INNER JOIN TP_MST_WORKSTATION W ON W.WORKSTATIONID = L.WS_ID
- WHERE
- L.LEAKTYPE = 1
- AND L.CREATETIME >= to_date( to_char( SYSDATE, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- AND L.CREATETIME < to_date( to_char( SYSDATE + 1 / 24, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- ) t
- WHERE
- t.rk <= 1
- ORDER BY
- t.name"
- );
- if (dtDevice.Rows.Count == 0 || dtDeviceData.Rows.Count == 0)
- {
- return;
- }
- // 拼接主体
- JObject data = new JObject();
- data.Add(new JProperty("industryName", "广东区域"));
- data.Add(new JProperty("companyName", "佛山恒洁卫浴有限公司"));
- data.Add(new JProperty("productName", "成品测漏"));
- data.Add(new JProperty("productCode", "FSHJCPCL"));
- data.Add(new JProperty("protocol", "HTTP"));
- data.Add(new JProperty("classfy", "陶瓷生产设备"));
- data.Add(new JProperty("lever", "低端"));
- data.Add(new JProperty("dimension", "工业品"));
- // 拼接device
- JArray arrDevice = new JArray();
- JObject device = null;
- foreach (DataRow row in dtDevice.Rows)
- {
- device = new JObject();
- device.Add(new JProperty("name", row["name"]));
- device.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
- device.Add(new JProperty("province", "广东省"));
- device.Add(new JProperty("city", "佛山市"));
- device.Add(new JProperty("address", "三水区乐平镇中油大道 3 号"));
- device.Add(new JProperty("worth", "0"));
- device.Add(new JProperty("latitude", "0"));
- device.Add(new JProperty("longitude", "0"));
- device.Add(new JProperty("manufacture", "2021-10-13"));
- arrDevice.Add(device);
- }
- data.Add("device", arrDevice);
- // 拼接deviceData
- JArray arrDeviceData = new JArray();
- JObject deviceData = null;
- string[] colNames;
- // 时间戳
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- foreach (DataRow row in dtDeviceData.Rows)
- {
- foreach (DataColumn col in dtDeviceData.Columns)
- {
- if (col.ColumnName.Equals("DEVICECODE") || col.ColumnName.Equals("NAME"))
- {
- continue;
- }
- colNames = col.ColumnName.Split('_');
- deviceData = new JObject();
- deviceData.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
- deviceData.Add(new JProperty("name", colNames[1]));
- deviceData.Add(new JProperty("mark", colNames[0]));
- deviceData.Add(new JProperty("value", row[col].ToString()));
- deviceData.Add(new JProperty("timestamp", timestamp));
- arrDeviceData.Add(deviceData);
- }
- }
- data.Add("deviceData", arrDeviceData);
- //上报数据
- string message = JsonClient.Post(_url, data.ToString());
- }
- Curtain.Log.Logger.Debug("成品侧漏数据上报成功!");
- }
- catch (Exception ex)
- {
- Curtain.Log.Logger.Error(ex);
- }
- }
- /// <summary>
- /// 试用结果
- /// </summary>
- public static void export05()
- {
- try {
- using (IDataAccess conn = DataAccess.Create())
- {
- DataTable dtDevice = conn.ExecuteDatatable(@"
- SELECT
- 'SYJG' || W.WORKSTATIONID AS deviceCode,
- '试用结果' || W.WORKSTATIONNAME AS name
- FROM
- TP_PM_GOODSLEAK L
- INNER JOIN TP_MST_WORKSTATION W ON W.WORKSTATIONID = L.WS_ID
- WHERE
- L.LEAKTYPE = 2
- AND L.CREATETIME >= to_date( to_char( SYSDATE, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- AND L.CREATETIME < to_date( to_char( SYSDATE + 1 / 24, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- GROUP BY
- W.WORKSTATIONID,
- W.WORKSTATIONNAME
- ORDER BY
- W.WORKSTATIONNAME"
- );
- DataTable dtDeviceData = conn.ExecuteDatatable(@"
- SELECT
- t.deviceCode,
- t.name,
- t.TESTRESULT_测试结果
- FROM
- (
- SELECT
- 'SYJG' || W.WORKSTATIONID AS deviceCode,
- '试用结果' || W.WORKSTATIONNAME AS name,
- DECODE( L.IS_GOOD, 0, '不合格', 1, '合格', '' ) AS TESTRESULT_测试结果,
- rank ( ) over ( PARTITION BY W.WORKSTATIONNAME ORDER BY L.CREATETIME DESC ) AS rk
- FROM
- TP_PM_GOODSLEAK L
- INNER JOIN TP_MST_WORKSTATION W ON W.WORKSTATIONID = L.WS_ID
- WHERE
- L.LEAKTYPE = 2
- AND L.CREATETIME >= to_date( to_char( SYSDATE, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- AND L.CREATETIME < to_date( to_char( SYSDATE + 1 / 24, 'yyyy-mm-dd hh' ), 'yyyy-mm-dd hh:mi:ss' )
- ) t
- WHERE
- t.rk <= 1
- ORDER BY
- t.name"
- );
- if (dtDevice.Rows.Count == 0 || dtDeviceData.Rows.Count == 0)
- {
- return;
- }
- // 拼接主体
- JObject data = new JObject();
- data.Add(new JProperty("industryName", "广东区域"));
- data.Add(new JProperty("companyName", "佛山恒洁卫浴有限公司"));
- data.Add(new JProperty("productName", "试用结果"));
- data.Add(new JProperty("productCode", "FSHJCPCL"));
- data.Add(new JProperty("protocol", "HTTP"));
- data.Add(new JProperty("classfy", "陶瓷生产设备"));
- data.Add(new JProperty("lever", "低端"));
- data.Add(new JProperty("dimension", "工业品"));
- // 拼接device
- JArray arrDevice = new JArray();
- JObject device = null;
- foreach (DataRow row in dtDevice.Rows)
- {
- device = new JObject();
- device.Add(new JProperty("name", row["name"]));
- device.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
- device.Add(new JProperty("province", "广东省"));
- device.Add(new JProperty("city", "佛山市"));
- device.Add(new JProperty("address", "三水区乐平镇中油大道 3 号"));
- device.Add(new JProperty("worth", "0"));
- device.Add(new JProperty("latitude", "0"));
- device.Add(new JProperty("longitude", "0"));
- device.Add(new JProperty("manufacture", "2021-10-13"));
- arrDevice.Add(device);
- }
- data.Add("device", arrDevice);
- // 拼接deviceData
- JArray arrDeviceData = new JArray();
- JObject deviceData = null;
- string[] colNames;
- // 时间戳
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- string timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- foreach (DataRow row in dtDeviceData.Rows)
- {
- foreach (DataColumn col in dtDeviceData.Columns)
- {
- if (col.ColumnName.Equals("DEVICECODE") || col.ColumnName.Equals("NAME"))
- {
- continue;
- }
- colNames = col.ColumnName.Split('_');
- deviceData = new JObject();
- deviceData.Add(new JProperty("deviceCode", "FSHJ" + row["deviceCode"]));
- deviceData.Add(new JProperty("name", colNames[1]));
- deviceData.Add(new JProperty("mark", colNames[0]));
- deviceData.Add(new JProperty("value", row[col].ToString()));
- deviceData.Add(new JProperty("timestamp", timestamp));
- arrDeviceData.Add(deviceData);
- }
- }
- data.Add("deviceData", arrDeviceData);
- //上报数据
- string message = JsonClient.Post(_url, data.ToString());
- }
- Curtain.Log.Logger.Debug("试用数据上报成功!");
- }
- catch (Exception ex)
- {
- Curtain.Log.Logger.Error(ex);
- }
- }
- /// <summary>
- /// 获取在用电能设备
- /// </summary>
- public static void getDeviceId()
- {
- try {
- using (IDataAccess conn = DataAccess.Create())
- {
- string data00 = @"
- DELETE FROM TP_DEV_DEVICEONUSING
- ";
- int result00 = conn.ExecuteNonQuery(data00);
- string data0 = @"{
- ""appid"": ""ETP001018"",
- ""token"": ""6d06bb6d2173a4fdcfd098eba8a6605c""
- }
- ";
- string url = "http://htemp.net/opi/devices";// 生产
- string message = JsonClient.Post(url, data0.ToString());
- //Dictionary<string, object> ret = JsonHelper.JsonToDictionaryso(message + "");
- //JsonConvert.DeserializeObject<Dictionary<string, object>>(message);
- JObject ja = (JObject)JsonConvert.DeserializeObject(message); //反序列化为数组
- string code = ja["code"].ToString();
- string msg = ja["msg"].ToString();
- string timestamp = ja["timestamp"].ToString();
- string data = ja["data"].ToString();
- JArray ja2 = (JArray)JsonConvert.DeserializeObject(data); //反序列化为数组
- string name = ja2[0]["name"].ToString();
- string item = ja2[0]["item"].ToString();
- JArray ja3 = (JArray)JsonConvert.DeserializeObject(item); //反序列化为数组
- string device = ja3[0]["device"].ToString();
- string maters = ja3[0]["maters"].ToString();
- for (int i = 0 + 1; i < ja3.Count; i++)
- {
- device += "," + ja3[i]["device"].ToString();
- maters += "," + ja3[i]["maters"].ToString();
- }
- string str = "[" + maters.Replace("[", "").Replace("]", "") + "]";
- JArray ja4 = (JArray)JsonConvert.DeserializeObject(str); //反序列化为数组
- List<int> list1 = new List<int>();
- list1.Add(Convert.ToInt32(ja4[0]["id"].ToString()));
- List<int> list2 = new List<int>();
- list2.Add(Convert.ToInt32(ja4[0]["position"].ToString()));
- List<string> list3 = new List<string>();
- list3.Add(ja4[0]["component_no"].ToString());
- for (int i = 0 + 1; i < ja4.Count; i++)
- {
- list1.Add(Convert.ToInt32(ja4[i]["id"].ToString()));
- list2.Add(Convert.ToInt32(ja4[i]["position"].ToString()));
- list3.Add(ja4[i]["component_no"].ToString());
- }
- int result = 0;
- foreach (int i in list1)
- {
- //context.Response.Write(i + "___");
- string data2 = @"
- INSERT INTO TP_DEV_DEVICEONUSING(ID,CREATETIME) VALUES({ID},SYSDATE)
- ".Replace("{ID}", i + "");
- result += conn.ExecuteNonQuery(data2);
- }
- }
- Curtain.Log.Logger.Debug("在用电能设备获取成功!");
- }
- catch (Exception ex)
- {
- Curtain.Log.Logger.Error(ex);
- }
- }
- /// <summary>
- /// 获取设备电量
- /// </summary>
- public static void getDeviceElectronicCharge()
- {
- try
- {
- using (IDataAccess conn = DataAccess.Create())
- {
- string data00 = @"
- DELETE
- FROM
- TP_DEV_DEVICEELECTRICCHARGE
- WHERE TRUNC(DEVICEDATE,'DD') = TRUNC(SYSDATE,'DD')
- ";
- DataTable dt00 = conn.ExecuteDatatable(data00);
- string data0 = @"
- SELECT
- ID
- FROM
- TP_DEV_DEVICEONUSING
- ";
- DataTable dt = conn.ExecuteDatatable(data0);
- string str = "";
- int result = 0;
- for (int n = 0; n < dt.Rows.Count; n++)
- {
- int num = Convert.ToInt32(dt.Rows[n]["ID"] + "");
- string data2 = @"{
- ""appid"": ""ETP001018"",
- ""token"": ""6d06bb6d2173a4fdcfd098eba8a6605c"",
- ""meter_id"": {ID}
- }
- ".Replace("{ID}", num + "");
- string url = "http://htemp.net/opi/energy";// 生产
- string message = JsonClient.Post(url, data2.ToString());
- JObject ja = new JObject();
- ja = (JObject)JsonConvert.DeserializeObject(message); //反序列化为数组
- string code = ja["code"].ToString();
- string msg = ja["msg"].ToString();
- string timestamp = ja["timestamp"].ToString();
- string data = ja["data"].ToString();
- JArray ja2 = new JArray();
- ja2 = (JArray)JsonConvert.DeserializeObject("[" + data + "]"); //反序列化为数组
- string meter_id = ja2[0]["meter_id"].ToString();
- string item = ja2[0]["item"].ToString();
- //JArray ja3 = (JArray)JsonConvert.DeserializeObject(item); //反序列化为数组
- //string device = ja3[0]["device"].ToString();
- //string maters = ja3[0]["maters"].ToString();
- //for (int i = 0 + 1; i < ja3.Count; i++)
- //{
- // device += "," + ja3[i]["device"].ToString();
- // maters += "," + ja3[i]["maters"].ToString();
- //}
- str = "[" + item.Replace("[", "").Replace("]", "") + "]";
- JArray ja4 = new JArray();
- ja4 = (JArray)JsonConvert.DeserializeObject(str); //反序列化为数组
- string date = "_";
- double epi = 0;
- double etp = 0;
- double eta = 0;
- double etv = 0;
-
- for (int m = 0; m < ja4.Count; m++)
- {
- if (ja4[m].ToString().IndexOf("date") > 0)
- {
- date = ja4[m]["date"].ToString();
- }
- if (ja4[m].ToString().IndexOf("epi") > 0)
- {
- epi = Convert.ToDouble(ja4[m]["epi"].ToString());
- }
- if (ja4[m].ToString().IndexOf("etp") > 0)
- {
- etp = Convert.ToDouble(ja4[m]["etp"].ToString());
- }
- if (ja4[m].ToString().IndexOf("eta") > 0)
- {
- eta = Convert.ToDouble(ja4[m]["eta"].ToString());
- }
- if (ja4[m].ToString().IndexOf("etv") > 0)
- {
- etv = Convert.ToDouble(ja4[m]["etv"].ToString());
- }
- string data3 = @"
- INSERT INTO TP_DEV_DEVICEELECTRICCHARGE(APPID,TOKEN,METER_ID,DEVICEDATE,EPI,ETP,ETA,ETV,CREATETIME)
- VALUES('ETP001018','6d06bb6d2173a4fdcfd098eba8a6605c',{ID},TO_DATE('{DATE}', 'YYYY-MM-DD HH24-MI-SS'),{EPI},{ETP},{ETA},{ETV},SYSDATE)
- ".Replace("{ID}", num + "").Replace("{DATE}", date).Replace("{EPI}", epi + "").Replace("{ETP}", etp + "").Replace("{ETA}", eta + "").Replace("{ETV}", etv + "");
- result += conn.ExecuteNonQuery(data3);
- }
- }
- }
- Curtain.Log.Logger.Debug("电能数据获取成功!");
- }
- catch(Exception ex)
- {
- Curtain.Log.Logger.Error(ex);
- }
- }
- }
|