Example #1
0
        /// <summary>
        /// 清零操作
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public Dictionary <string, object> QingLing(Dictionary <string, object> list)
        {
            Dictionary <string, object> r = new Dictionary <string, object>();

            try
            {
                Newtonsoft.Json.Linq.JArray arry = (Newtonsoft.Json.Linq.JArray)list["data"];
                if (arry.Count > 0)
                {
                    List <Dictionary <string, object> > listEle = new List <Dictionary <string, object> >();
                    foreach (var item in arry)
                    {
                        Dictionary <string, object> eleDic = new Dictionary <string, object>();
                        eleDic.Add("opr_id", item["opr_id"]?.ToString());
                        eleDic.Add("address", item["address"]?.ToString()); //map.put("address", "201908290001");
                        eleDic.Add("cid", item["cid"]?.ToString());         //map.put("cid", "201908290001");
                        eleDic.Add("time_out", 0);
                        eleDic.Add("must_online", true);
                        eleDic.Add("retry_time", 1);
                        listEle.Add(eleDic);
                    }
                    var builder = new ConfigurationBuilder()
                                  .SetBasePath(Directory.GetCurrentDirectory())
                                  .AddJsonFile("appsettings.json");
                    Configuration = builder.Build();
                    string EleApiIP = Configuration.GetSection("Ele").GetSection("qingling").Value;
                    string authCode = Configuration.GetSection("Ele").GetSection("authCode").Value;
                    string nonce    = Configuration.GetSection("Ele").GetSection("nonce").Value;
                    TQApi  tqApi    = new TQApi(
                        authCode,
                        nonce,
                        EleApiIP,
                        ""
                        );  // SyncMode.enable
                    string res = tqApi.readElecMeter(listEle);
                    Dictionary <string, string> dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(res);
                    string status = dict["status"];
                    if ("SUCCESS".Equals(status))
                    {
                        string response_content = dict["response_content"];
                        List <Dictionary <string, string> > items = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(response_content);
                        if (items.Count > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            for (int i = 0; i < items.Count; i++)
                            {
                                Dictionary <string, string> item = items[i];
                                for (int k = 0; k < listEle.Count; k++) //最上面的查询sql list
                                {
                                    Dictionary <string, object> item2 = listEle[k];
                                    if (item["opr_id"].ToString() == item2["opr_id"].ToString())
                                    {
                                        if (item["status"].ToString() == "SUCCESS")
                                        {
                                            sb.Append("update wy_ele_recharge set QingLingMsg='',");
                                            sb.Append("QingLing=1 where opr_id='" + item2["opr_id"] + "' and address='" + item2["address"] + "' ; ");
                                        }
                                        else
                                        {
                                            sb.Append("update wy_ele_recharge set  ");
                                            sb.Append("QingLing=0,QingLingMsg='" + item["error_msg"].ToString() + "'  where opr_id='" + item2["opr_id"] + "' and address='" + item2["address"] + "' ; ");
                                        }
                                        break;
                                    }
                                }
                            }
                            string result = db.update(sb.ToString());
                            if (result == "")
                            {
                                r["message"] = "操作成功!";
                                r["code"]    = 2000;
                                return(r);
                            }
                            else
                            {
                                r["message"] = result;
                                r["code"]    = -1;
                                return(r);
                            }
                        }
                    }
                    else
                    {
                        r["code"]    = -1;
                        r["message"] = res;
                    }
                    return(r);
                }
                else
                {
                    r["message"] = " 请选择数据";
                    r["code"]    = -1;
                }
            }
            catch (Exception e)
            {
                r["message"] = e.Message;
                r["code"]    = -1;
            }
            return(r);
        }
Example #2
0
        /// <summary>
        /// 批量读取电能
        /// </summary>
        public void ReadActiveEnergyBatch()
        {
            try
            {
                string    sqlQuery = "SELECT ELE_NUMBER,CID FROM wy_houseinfo a where a.FWSX<>0 ";
                DataTable dt       = SqlHelper.ExexuteDataTalbe(sqlQuery);
                if (dt != null && dt.Rows.Count > 0)
                {
                    // 设置sdk的底层http传输日志显示级别
                    // LogSetter.setHttp2Debug();
                    // LogSetter.setHttp2Error();

                    // 设置sdk日志显示级别
                    // LogSetter.setSdk2Debug();
                    // LogSetter.setSdk2Error();
                    //"http://192.168.1.10:8080/notify"

                    TQApi tqApi = new TQApi(
                        ConfigCom.authCode,
                        ConfigCom.nonce,
                        ConfigCom.EleIP + ConfigCom.ActiveEnergy,
                        SyncMode.enable);
                    java.util.List list = new java.util.ArrayList();
                    foreach (DataRow row in dt.Rows)
                    {
                        java.util.Map map = new java.util.HashMap();
                        map.put("opr_id", CommonUtil.generateOperateId());
                        map.put("address", row["ELE_NUMBER"]?.ToString()); //map.put("address", "201908290001");
                        map.put("cid", row["CID"]?.ToString());            //map.put("cid", "201908290001");
                        map.put("time_out", tqApi.getTimeOut());
                        map.put("must_online", true);
                        map.put("retry_time", tqApi.getRetryTimes());
                        map.put("type", ReadElecMeterType.PositiveActiveEnergy.getType());//正向总电 能 33
                        list.add(map);
                    }
                    TQResponse tqresponse = tqApi.readElecMeter(list);
                    string     stats      = tqresponse.getStatus();
                    if (stats == "SUCCESS")
                    {
                        string dateNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        //每天只留一条,先删除,在insert
                        string sqlDelete = " delete from wy_ele_Energy where datediff(day,CreateDate,'" + dateNow + "')=0 and Ustatus is not null";
                        int    exctR     = SqlHelper.ExcuteNonQuery(sqlDelete);
                        if (exctR > 0)
                        {
                            log.Info("readActiveEnergyBatch()Delete成功!");
                        }
                        else
                        {
                            log.Info("readActiveEnergyBatch()delete失败!");
                        }
                        java.util.List listRes       = tqresponse.getResponseContent();
                        int            total         = 0; //如果超过998条要分批插入
                        int            count         = 0; //几次 998条insert
                        string         sqlInsertHead = "insert into wy_ele_Energy(address,cid,opr_id,CreateDate,Cstatus,CMessage)values ";
                        string         sqlInsert     = sqlInsertHead;
                        for (int i = 0; i < listRes.size(); i++)
                        {
                            total = i;
                            java.util.HashMap mp = (java.util.HashMap)listRes.get(i);//string opr_id=mp.get("opr_id").ToString();
                            if (mp.get("status").ToString() == "SUCCESS")
                            {
                                sqlInsert += "(";
                                for (int k = 0; k < list.size(); k++)
                                {
                                    java.util.HashMap mpl = (java.util.HashMap)list.get(k);
                                    if (mpl.get("opr_id").ToString() == mp.get("opr_id").ToString())
                                    {
                                        sqlInsert += "'" + mpl.get("address").ToString() + "',";
                                        sqlInsert += "'" + mpl.get("cid").ToString() + "',";
                                        sqlInsert += "'" + mpl.get("opr_id").ToString() + "',";
                                        sqlInsert += "'" + dateNow + "',1,null),";
                                        total++;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                sqlInsert += "(";
                                for (int k = 0; k < list.size(); k++)
                                {
                                    java.util.HashMap mpl = (java.util.HashMap)list.get(k);
                                    if (mpl.get("opr_id").ToString() == mp.get("opr_id").ToString())
                                    {
                                        sqlInsert += "'" + mpl.get("address").ToString() + "',";
                                        sqlInsert += "'" + mpl.get("cid").ToString() + "',";
                                        sqlInsert += "'" + mpl.get("opr_id").ToString() + "',";
                                        sqlInsert += "'" + dateNow + "',0,'" + mp.get("error_msg").ToString() + "'),";
                                        total++;
                                        break;
                                    }
                                }
                            }
                            if (total == 998)//查过一千条insert 分批执行。
                            {
                                count++;
                                total     = 0;
                                sqlInsert = sqlInsert.Substring(0, sqlInsert.Length - 1);
                                int exct = SqlHelper.ExcuteNonQuery(sqlInsert);
                                if (exct > 0)
                                {
                                    log.Info("readActiveEnergyBatch()insert第" + count + "几次成功!");
                                }
                                else
                                {
                                    log.Info("readActiveEnergyBatch()insert第" + count + "几次时失败!");
                                }
                                sqlInsert = sqlInsertHead;
                            }
                        }
                        if (count == 0 || (count > 0 && count * 998 < listRes.size()))
                        {
                            sqlInsert = sqlInsert.Substring(0, sqlInsert.Length - 1);
                            int exct = SqlHelper.ExcuteNonQuery(sqlInsert);
                            if (exct > 0)
                            {
                                log.Info("readActiveEnergyBatch()insert第" + count + "几次成功!");
                            }
                            else
                            {
                                log.Info("readActiveEnergyBatch()insert第" + count + "几次时失败!");
                            }
                        }
                    }
                    else
                    {
                        log.Error("readActiveEnergyBatch()=>tqresponse 返回不是success,是:" + stats + ",errorMsg:" + tqresponse.getErrorMsg());
                    }
                    #region res说明

                    /*
                     * {
                     * TQResponse {
                     * status = 'SUCCESS', errorMsg = 'null', responseContent = [{
                     * opr_id = 1 c05fa34 - fc65 - 41 b2 - 9 c96 - b35f5351db69,
                     * status = SUCCESS ,error_msg
                     * }], timestamp = 1585114838, sign = 'ed6c8381d3b448f505516a4f999ecc0f'
                     * }
                     * }
                     * [{
                     * "opr_id": "e3dfb115-2f07-46eb-a36f-0b6442bb1d1e",
                     * "resolve_time": "2020-03-27 17:14:02",
                     * "status": "SUCCESS",
                     * "data": [{
                     * "type": 3,
                     * "value": ["0.00", "0.00", "0.00", "0.00", "0.00"],
                     * "dsp": "总 : 0.00 kWh 尖 : 0.00 kWh 峰 : 0.00 kWh 平 : 0.00 kWh 谷 : 0.00 kWh"
                     * }]
                     * }]
                     */
                    #endregion
                }
            }
            catch (Exception ex)
            {
                log.Error("批量读取电能接口readActiveEnergyBatch()出错:" + ex.Message.ToString());
            }
        }
Example #3
0
        /// 清零操作
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public Dictionary <string, object> KaiHu(Dictionary <string, object> list)
        {
            Dictionary <string, object> r = new Dictionary <string, object>();

            try
            {
                Newtonsoft.Json.Linq.JArray arry = (Newtonsoft.Json.Linq.JArray)list["data"];
                if (arry.Count > 0)
                {
                    List <Dictionary <string, object> > listEle = new List <Dictionary <string, object> >();
                    foreach (var item in arry)
                    {
                        Dictionary <string, object> eleDic = new Dictionary <string, object>();
                        eleDic.Add("opr_id", item["opr_id"]?.ToString());
                        eleDic.Add("address", item["address"]?.ToString()); //map.put("address", "201908290001");
                        eleDic.Add("cid", item["cid"]?.ToString());         //map.put("cid", "201908290001");
                        eleDic.Add("time_out", 0);
                        eleDic.Add("must_online", true);
                        eleDic.Add("retry_time", 1);
                        Dictionary <string, object> dicAccount = new Dictionary <string, object>();
                        dicAccount.Add("account_id", "1234");
                        dicAccount.Add("count", "2");
                        dicAccount.Add("money", "1");
                        //ElecMeterAccount elecMeterAccount = new ElecMeterAccount("1234", "2", row["Cost"].ToString());
                        // map.put("params", elecMeterAccount.getAccount());
                        eleDic.Add("params", dicAccount);
                        listEle.Add(eleDic);
                    }
                    var builder = new ConfigurationBuilder()
                                  .SetBasePath(Directory.GetCurrentDirectory())
                                  .AddJsonFile("appsettings.json");
                    Configuration = builder.Build();
                    string EleApiIP = Configuration.GetSection("Ele").GetSection("kaihu").Value;
                    string authCode = Configuration.GetSection("Ele").GetSection("authCode").Value;
                    string nonce    = Configuration.GetSection("Ele").GetSection("nonce").Value;
                    TQApi  tqApi    = new TQApi(
                        authCode,
                        nonce,
                        EleApiIP,
                        ""
                        );  // SyncMode.enable
                    string res = tqApi.readElecMeter(listEle);


                    Dictionary <string, string> dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(res);
                    string status = dict["status"];
                    if ("SUCCESS".Equals(status))
                    {
                        JObject jObject = Tools.JsonDeSerilize(res) as JObject;
                        if (jObject != null)
                        {
                            res = jObject.Serilize2Json();
                            JToken token = null;
                            if (jObject.TryGetValue("response_content", out token) && token is JValue)
                            {
                                JArray items = Tools.JsonDeSerilize(((JValue)token).Value.ToString()) as JArray;
                                if (items != null && items.Count > 0)
                                {
                                    StringBuilder sb = new StringBuilder();
                                    for (int i = 0; i < items.Count; i++)
                                    {
                                        var item = items[i];
                                        for (int k = 0; k < listEle.Count; k++) //最上面的查询sql list
                                        {
                                            Dictionary <string, object> item2 = listEle[k];
                                            if (item["opr_id"].ToString() == item2["opr_id"].ToString())
                                            {
                                                if (item["status"].ToString() == "SUCCESS")
                                                {
                                                    sb.Append("update wy_ele_recharge set KaiHuMsg='',");
                                                    sb.Append("KaiHu=1 where opr_id='" + item2["opr_id"] + "' and address='" + item2["address"] + "' ; ");
                                                }
                                                else
                                                {
                                                    sb.Append("update wy_ele_recharge set  ");
                                                    sb.Append("KaiHu=0,KaiHuMsg='" + item["err_msg"].ToString() + "'  where opr_id='" + item2["opr_id"] + "' and address='" + item2["address"] + "' ; ");
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    string result = db.update(sb.ToString());
                                    if (result == "")
                                    {
                                        r["message"] = "操作成功!";
                                        r["code"]    = 2000;
                                        return(r);
                                    }
                                    else
                                    {
                                        r["message"] = result;
                                        r["code"]    = -1;
                                        return(r);
                                    }
                                }
                            }

                            #region MyRegion


                            //}
                            //if (items.Count > 0)
                            //{
                            //    StringBuilder sb = new StringBuilder();
                            //    for (int i = 0; i < items.Count; i++)
                            //    {
                            //        Dictionary<string, string> item = items[i];
                            //        for (int k = 0; k < listEle.Count; k++) //最上面的查询sql list
                            //        {
                            //            Dictionary<string, object> item2 = listEle[k];
                            //            if (item["opr_id"].ToString() == item2["opr_id"].ToString())
                            //            {
                            //                if (item["status"].ToString() == "SUCCESS")
                            //                {
                            //                    sb.Append("update wy_ele_recharge set ");
                            //                    sb.Append("KaiHu=1 where opr_id='" + item2["opr_id"] + "' and address='" + item2["address"] + "' ; ");
                            //                }
                            //                else
                            //                {
                            //                    sb.Append("update wy_ele_recharge set  ");
                            //                    sb.Append("KaiHu=0,KaiHuMsg='" + item["error_msg"].ToString() + "'  where opr_id='" + item2["opr_id"] + "' and address='" + item2["address"] + "' ; ");
                            //                }
                            //                break;
                            //            }
                            //        }

                            //    }
                            //    string result = db.update(sb.ToString());
                            //    if (result == "")
                            //    {
                            //        r["message"] = "操作成功!";
                            //        r["code"] = 2000;
                            //        return r;
                            //    }
                            //    else
                            //    {
                            //        r["message"] = result;
                            //        r["code"] = -1;
                            //        return r;
                            //    }
                            //}
                            #endregion
                        }
                        else
                        {
                            r["code"]    = -1;
                            r["message"] = res;
                        }
                        return(r);
                    }
                    else
                    {
                        r["message"] = " 请选择数据";
                        r["code"]    = -1;
                    }
                }
            }
            catch (Exception e)
            {
                r["message"] = e.Message;
                r["code"]    = -1;
            }
            return(r);
        }