Exemple #1
0
        // 批量下发命令
        private bool YdBatchControlOfSsr(string v0Fun, string dataValue, string pStr)
        {
            string msg = "";
            YdToGw gw  = new YdToGw(user.Ledger, user.Uid);
            V0Fun  fun = V0Fun.E;

            if (Enum.TryParse <V0Fun>(v0Fun, out fun) == false)
            {
                return(false);
            }
            //V0Fun fun = V0Fun.Ssr;
            try
            {
                foreach (string s in pStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    gw.YdToGwCmd(CommFunc.ConvertDBNullToInt32(s), fun, dataValue);
                }
                return(true);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                FileLog.WriteLog("获取状态列表错误 (GetYdBatchControlOfList)", ex.Message + ex.StackTrace);
            }
            return(false);
        }
Exemple #2
0
        // 批量下发命令
        public APIRst YdBatchControlOfSsr(string v0Fun, string dataValue, string pStr)
        {
            APIRst rst = new APIRst();
            YdToGw gw  = new YdToGw(user.Ledger, user.Uid);
            V0Fun  fun = V0Fun.E;

            if (Enum.TryParse <V0Fun>(v0Fun, out fun) == false)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "控制命令错误";
                return(rst);
            }
            //V0Fun fun = V0Fun.Ssr;
            try
            {
                foreach (string s in pStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    gw.YdToGwCmd(CommFunc.ConvertDBNullToInt32(s), fun, dataValue);
                }
                rst.data = "";
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("批量下发命令错误(YdBatchControlOfSsr)", ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Exemple #3
0
        private bool YdToGwCmd(int module_id, int fun_id, V0Fun funType, string dataValue, bool backgroup, int isRn = 0)
        {
            long          log_id = bll.YdToGwOfAddCmd(module_id, fun_id, funType.ToString(), dataValue, isRn);
            CommandVModel cmd    = bll.GetYdToGwOfSendCmd(log_id);

            return(this.SendCmd(cmd, backgroup));
        }
Exemple #4
0
        public APIRst SetYdParams(int module_id, int fun_id, string funType, string dataValue)
        {
            APIRst rst  = new APIRst();
            V0Fun  vfun = V0Fun.E;

            if (module_id == 0)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "设备不能为空";
                return(rst);
            }
            if (fun_id == 0 && string.IsNullOrEmpty(funType))
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "参数ID不能为空";
                return(rst);
            }
            if (string.IsNullOrEmpty(dataValue))
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "设置参数不能为空";
                return(rst);
            }
            if (!string.IsNullOrEmpty(funType) && Enum.TryParse(funType, false, out vfun) == false)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "设置参数类型错误";
                return(rst);
            }

            string msg  = "";
            bool   upDb = false;

            try
            {
                if (fun_id != 0)
                {
                    rst.rst = new YdToGw(user.Ledger, user.Uid).YdToGwCmdOfSingle(module_id, fun_id, dataValue, out upDb, out msg);
                }
                else
                {
                    rst.rst = new YdToGw(user.Ledger, user.Uid).YdToGwCmd(module_id, vfun, dataValue);
                }
                rst.data    = upDb;
                rst.err.msg = msg;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("电表设备参数设置错误 (SetYdParams)", ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Exemple #5
0
        /// <summary>
        /// 获取设备测试ID号
        /// </summary>
        /// <param name="module_id"></param>
        /// <param name="funType"></param>
        /// <returns></returns>
        public int GetYdToFun_id(int module_id, V0Fun funType)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Clear();
            strSql.Append("select b.Fun_id");
            strSql.Append(" from vp_mdinfo as a inner join v0_fun as b on a.Ledger=b.Ledger and a.Mm_id=b.Mm_id");
            strSql.Append(" where a.Ledger=@Ledger and a.Module_id=@Module_id and b.FunType=@FunType");
            object id = SQLHelper.ExecuteScalar(strSql.ToString(), new { Ledger = this.Ledger, Module_id = module_id, FunType = funType.ToString() });

            return(CommFunc.ConvertDBNullToInt32(id));
        }
Exemple #6
0
        /// <summary>
        /// 下发继电器状态
        /// </summary>
        /// <returns></returns>
        public APIRst YdMonitorOfIsRelay(string v0Fun, string dataValue, int module_id)
        {
            APIRst rst = new APIRst();
            YdToGw gw  = new YdToGw(user.Ledger, user.Uid);
            V0Fun  fun = V0Fun.E;

            if (Enum.TryParse <V0Fun>(v0Fun, out fun) == false)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "控制命令错误";
                return(rst);
            }
            try
            {
                //根据Module_id找到对应的表v0_fun中继电器状态,保存设置的继电器状态
                DataTable dt  = bll.GetMm_idBymodule_id(module_id);
                int       cnt = 0;
                if (dt.Rows.Count != 0)
                {
                    int mm_id  = CommFunc.ConvertDBNullToInt32(dt.Rows[0]["Mm_id"]);
                    int fun_id = CommFunc.ConvertDBNullToInt32(dt.Rows[0]["Fun_id"]);
                    cnt = bll.SaveIsRelayInfo(module_id, fun_id, dataValue);
                }
                else
                {
                    rst.rst      = false;
                    rst.err.code = (int)ResultCodeDefine.Error;
                    rst.err.msg  = "该功能不存在与这个类型的电表中。";
                    return(rst);
                }
                if (cnt == 0)
                {
                    rst.rst      = false;
                    rst.err.code = (int)ResultCodeDefine.Error;
                    rst.err.msg  = "更新继电器状态错误";
                    return(rst);
                }
                //向网关下发指令
                gw.YdToGwCmd(module_id, fun, dataValue);
                rst.data = "";
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取下发继电器状态错误 (YdMonitorOfIsRelay)", ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Exemple #7
0
        /// <summary>
        /// 保存映射
        /// </summary>
        /// <param name="Module_id"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public APIRst YdModuleOnMapInSave(int Module_id, DataModels data)
        {
            APIRst        rst     = new APIRst();
            StringBuilder tagName = new StringBuilder();

            try
            {
                int       cnt      = 0;
                YdToGw    gw       = new YdToGw(user.Ledger, user.Uid);
                DataTable dtSource = JsonHelper.ToDataTable(data.Data);
                foreach (DataRow dr in dtSource.Rows)
                {
                    int action = CommFunc.ConvertDBNullToInt32(dr["Action"]);
                    cnt = bll.YdModuleOnMapInSave(Module_id, dr);
                    if (action == 0)
                    {
                        if (!string.IsNullOrEmpty(tagName.ToString()))
                        {
                            tagName.Append(",");
                        }
                        tagName.Append(CommFunc.ConvertDBNullToString(dr["TagName"]));
                    }
                    else
                    {
                        if (cnt == 1)
                        {
                            V0Fun fun = V0Fun.E;
                            if (Enum.TryParse <V0Fun>(CommFunc.ConvertDBNullToString(dr["FunType"]), out fun) == true)
                            {
                                gw.BeginYdToGwCmd(Module_id, CommFunc.ConvertDBNullToInt32(dr["Fun_id"]), fun, CommFunc.ConvertDBNullToString(dr["DataValue"]));
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(tagName.ToString()))
                {
                    gw.BeginYdToGwConfig(tagName.ToString());
                }

                rst.data = cnt;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("映射保存错误(YdModuleOnMapInSave):" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Exemple #8
0
        /// <summary>
        /// 增加设备充值命令到数据库中
        /// </summary>
        /// <param name="module_id"></param>
        /// <param name="moduleAddr"></param>
        /// <param name="payVal"></param>
        /// <returns></returns>
        public long AddPayCommmand(int module_id, string moduleAddr, decimal payVal, V0Fun funType)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Clear();
            strSql.Append("insert into v2_command(");
            strSql.Append("CDate,Ledger,Co_id,Module_id,ModuleAddr,Fun_id,FunType,DataValue,Create_by,Create_dt,ErrCode)");
            strSql.Append("select now(),a.Ledger,a.Co_id,a.Module_id,a.ModuleAddr,ifnull(b.Fun_id,0),@FunType,@DataValue,@SysUid,now(),0");
            strSql.Append(" from vp_mdinfo as a left join v0_fun as b on a.Ledger=b.Ledger and a.Mm_id=b.Mm_id and b.FunType=@FunType");
            strSql.Append(" where a.Ledger=@Ledger and a.Module_id=@Module_id and a.ModuleAddr=@ModuleAddr;");
            strSql.Append("select last_insert_id();");
            object obj = SQLHelper.ExecuteScalar(strSql.ToString(), new { Ledger = this.Ledger, Module_id = module_id, ModuleAddr = moduleAddr, DataValue = Math.Abs(payVal).ToString(), FunType = funType.ToString(), SysUid = this.SysUid });

            return(CommFunc.ConvertDBNullToLong(obj));
        }
Exemple #9
0
 public int GetYdToFun_id(int module_id, V0Fun funType)
 {
     return(dal.GetYdToFun_id(module_id, funType));
 }
Exemple #10
0
 /// <summary>
 /// 增加设备充值命令到数据库中
 /// </summary>
 /// <param name="module_id"></param>
 /// <param name="moduleAddr"></param>
 /// <param name="payVal"></param>
 /// <returns></returns>
 public long AddPayCommmand(int module_id, string moduleAddr, decimal payVal, V0Fun funType)
 {
     return(dal.AddPayCommmand(module_id, moduleAddr, payVal, funType));
 }
Exemple #11
0
        /// <summary>
        ///  // 同步发送命令
        /// </summary>
        /// <param name="module_id"></param>
        /// <param name="funType"></param>
        /// <param name="dataValue"></param>
        /// <returns></returns>
        public bool YdToGwCmd(int module_id, V0Fun funType, string dataValue)
        {
            int fun_id = bll.GetYdToFun_id(module_id, funType);

            return(this.YdToGwCmd(module_id, fun_id, funType, dataValue, false));
        }
Exemple #12
0
 /// <summary>
 /// // 异步发送命令
 /// </summary>
 /// <param name="module_id"></param>
 /// <param name="fun_id"></param>
 /// <param name="funType"></param>
 /// <param name="dataValue"></param>
 /// <returns></returns>
 public bool BeginYdToGwCmd(int module_id, int fun_id, V0Fun funType, string dataValue, int isRn = 0)
 {
     return(this.YdToGwCmd(module_id, fun_id, funType, dataValue, true, isRn));
 }
Exemple #13
0
        public void Run()
        {
            DateTime? dtRun = null, dtTab = null;
            DataTable dtSi = null;

            while (true)
            {
                Thread.Sleep(1000);/*每一秒*/
                if (NCSys.IsRun == false)
                {
                    dtSi = null; dtTab = null;
                    continue;
                }
                DateTime Now = DateTime.Now;
                if (dtRun != null)
                { /*以分钟为一个单位执行*/
                    if (dtRun.Value.Minute == Now.Minute)
                    {
                        continue;
                    }
                }
                dtRun = DateTime.Now;
                //
                try
                {
                    if (NCSys.ResetSiTime == false || dtSi == null || dtTab == null || dtTab.Value.AddHours(1) < DateTime.Now)
                    {
                        dtSi              = bll.GetV1_si_ssr();
                        dtTab             = DateTime.Now;
                        NCSys.ResetSiTime = true;
                    }
                    foreach (DataRow dr in dtSi.Rows)
                    {
                        int    ledger     = CommFunc.ConvertDBNullToInt32(dr["Ledger"]);
                        int    si_id      = CommFunc.ConvertDBNullToInt32(dr["Si_id"]);
                        int    co_id      = CommFunc.ConvertDBNullToInt32(dr["Co_id"]);
                        int    module_id  = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                        string moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]);
                        string moduleType = CommFunc.ConvertDBNullToString(dr["ModuleType"]);
                        //
                        int    meter_id  = CommFunc.ConvertDBNullToInt32(dr["Meter_id"]);
                        string meterAddr = CommFunc.ConvertDBNullToString(dr["MeterAddr"]);
                        int    ssr       = IsRunSi(Now, dr);
                        //
                        if (ssr == 0)
                        {
                            continue;
                        }
                        bool isQf = false;

                        //if (moduleType.Equals("YD-ZB20-4PL2-SB"))
                        //{/*这款用于河北工业大学的SB设备,特殊定制化*/
                        //    isQf = bll.GetMeterQianFei(ledger,co_id, meter_id, meterAddr);/*是否欠费*/
                        //}
                        //else
                        //{
                        isQf = bll.GetModuleQianFei(ledger, co_id, module_id, moduleAddr);   /*是否欠费*/
                        //}


                        V0Fun  fun      = V0Fun.Ssr;
                        int    fun_id   = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]);
                        string funName  = "定时合闸";
                        int    nowSsr   = 0;
                        string descr    = "定时合闸";
                        string dataVale = "0";
                        if (ssr == 3355)
                        {
                            fun      = V0Fun.Ssr;
                            fun_id   = 0;
                            funName  = "定时拉闸";
                            nowSsr   = 1;
                            dataVale = "1";
                            descr    = "定时拉闸";
                        }
                        //////////////
                        SysPro pro;
                        NCSys.Pro.TryGetValue(ledger, out pro);
                        if (pro == null)
                        {
                            continue;
                        }
                        string key    = pro.ProjectKey + CommFunc.ConvertDBNullToString(dr["LpszDbVarName"]);
                        RstVar rstVar = MemcachedMgr.GetVal <RstVar>(key);
                        int    curSsr = -1;
                        if (rstVar != null)
                        {
                            curSsr = CommFunc.ConvertDBNullToInt32(rstVar.lpszVal);
                        }
                        //if (nowSsr == curSsr) continue;
                        ///////////////////////////////////////////////////////////////////////////////////////////
                        if (ssr == 9966)
                        {/*合闸*/
                            if (isQf == true)
                            {
                                continue;              /*欠费不合闸*/
                            }
                        }
                        if (nowSsr != curSsr)
                        {/*不一致执行命令*/
                            //CommandVModel cmd = bll.GetSsrInfo(ledger, module_id, dataVale);
                            CommandVModel cmd          = null;
                            int           transferType = bll.GetTransferType(ledger, module_id);
                            if (transferType == 4)
                            {
                                cmd = bll.GetSsrInfo(ledger, module_id, V0Fun.Ssr.ToString() + dataVale, dataVale);
                            }
                            else
                            {
                                cmd = bll.GetSsrInfo(ledger, module_id, V0Fun.Ssr.ToString(), dataVale);
                            }
                            if (cmd == null)
                            {
                                FileLog.Error("定时操作没有数据");
                                continue;
                            }
                            cmd.Fun_id    = fun_id;
                            cmd.FunType   = fun.ToString();
                            cmd.FunName   = funName;
                            cmd.DataValue = dataVale;
                            cmd.Descr     = descr;
                            cmd.IsUI      = true;
                            cmd.IsNDb     = true;
                            cmd.Create_by = Config.Uid;
                            if (cmd.TransferType == 4)
                            {
                                //string fs = cmd.FunType + cmd.DataValue;
                                //string tagName = "", dataValue = "";
                                //tagName = bll.GetSSrIOService(ledger, module_id, fs, out dataValue);
                                //if (!string.IsNullOrEmpty(tagName) && !string.IsNullOrEmpty(dataVale))
                                //{
                                //    cmd.LpszDbVarName = tagName;
                                //    cmd.DataValue = dataVale;
                                //}
                                DataProcess.IOService.Collection.CollectionHelper.WriteVar(cmd);
                            }
                            else
                            {
                                DataProcess.YdDrive.Collection.CollectionHelper.Instance(cmd);
                            }
                            FileLog.Debug("电表ID:" + cmd.Module_id + "地址:" + cmd.ModuleAddr + "动作:" + cmd.Descr);
                        }
                    }
                }
                catch (Exception ex)
                {
                    FileLog.Error("拉合闸策略错误:" + ex.Message + ex.StackTrace);
                }
            }
        }