Exemplo n.º 1
0
        /// <summary>
        /// 根据表号读取表对象(mongo)
        /// </summary>
        /// <param name="mac"></param>
        /// <returns></returns>
        public Meter GetMeter(string mac)
        {
            Meter meter = new CY.IoTM.MongoDataHelper.TaskManageDA().QueryMeter(mac);

            if (meter == null)
            {
                IoT_Meter iot_meter = new MeterManageService().GetMeterByNo(mac);
                if (iot_meter != null)
                {
                    new CY.IoTM.MongoDataHelper.TaskManageDA().InsertMeter(iot_meter);
                    meter = new CY.IoTM.MongoDataHelper.TaskManageDA().QueryMeter(mac);
                }
            }
            short  ver    = meter.LastTopUpSer;
            Random rd     = new Random();
            int    newVer = rd.Next(0, 255);

            while (ver == newVer)
            {
                rd     = new Random();
                newVer = rd.Next(0, 255);
            }
            meter.LastTopUpSer = (byte)newVer;
            return(meter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 撤销点火请求
        /// </summary>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string UnDoDianHuo(IoT_Meter meter)
        {
            Meter _m = new TaskManageDA().QueryMeter(meter.MeterNo.Trim());

            if (_m.MeterState == "0")
            {
                return(string.Format("表{0}点火已完成,不能撤销。", meter.MeterNo.Trim()));
            }
            if (_m.MeterState == "1" || _m.MeterState == "2" || _m.MeterState == "4")
            {
                return(string.Format("表{0}不是点火状态,不能撤销。", meter.MeterNo.Trim()));
            }
            _m.MeterState = "4";
            List <CY.IoTM.Common.Business.Task> list = new TaskManageDA().GetTaskList(meter.MeterNo.Trim());

            foreach (CY.IoTM.Common.Business.Task task in list)
            {
                foreach (Command cmd in task.CommandList)
                {
                    if (cmd.CommandState == CommandState.Waitting)
                    {
                        cmd.CommandState = CommandState.Undo;
                        CommandDA.Update(cmd);
                    }
                }
                task.TaskState = TaskState.Undo;
                new TaskManageDA().TaskCompile(task);
            }
            return(new MeterDA().UpdateMeter(_m));;
        }
Exemplo n.º 3
0
 /// <summary>
 /// 指令完成
 /// </summary>
 /// <param name="command"></param>
 /// <param name="task"></param>
 public void CommandCompletes(Command command, Task task)
 {
     lock (_readlock)
     {
         //A014 写新密钥
         if (command.Identification.ToUpper() == "A014")
         {
             //更新通讯密钥完成
             Meter meter = new CY.IoTM.MongoDataHelper.TaskManageDA().QueryMeter(task.MeterMac);
             if (!meter.IsDianHuo)
             {
                 meter.IsDianHuo = true;
                 new CY.IoTM.MongoDataHelper.TaskManageDA().UpdateMeter(meter);
             }
         }
         //更新mongodb任务状态
         new CY.IoTM.MongoDataHelper.TaskManageDA().CommandCompile(command);
     }
 }
Exemplo n.º 4
0
        public string TopUpFinished(string taskID, decimal money)
        {
            try
            {
                MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
                QueryDocument        query = new QueryDocument();
                query.Add("TaskID", taskID);
                MongoCursor <Task> mongoCursor = mongo.Query(CollectionNameDefine.TaskCollectionName, query);
                var dataList = mongoCursor.ToList();
                if (dataList == null || dataList.Count == 0)
                {
                    return("没有找到TaskID:【" + taskID + "】的任务。");
                }
                string    result = "";
                TaskState state  = TaskState.Finished;

                Task task = dataList[0];
                task.Finished  = QuShi.getDate();
                task.TaskState = state;

                TaskManageDA tm = new TaskManageDA();
                result = tm.TaskCompile(task);
                if (result != "")
                {
                    return(result);
                }
                if (state == TaskState.Finished)
                {
                    Meter _meter = tm.QueryMeter(task.MeterMac);
                    _meter.TotalTopUp           += money;
                    _meter.LastSettlementAmount += money;
                    _meter.CurrentBalance       += money;
                    result = tm.UpdateMeter(_meter);
                }
                return(result);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Exemplo n.º 5
0
        public string XZFinished(string taskID)
        {
            string         result = "";
            List <Command> list   = CommandDA.QueryCommandList(taskID);

            foreach (Command cmd in list)
            {
                if (cmd.CommandState == CommandState.Waitting)
                {
                    cmd.CommandState = CommandState.Finished;
                    result          += CommandDA.Update(cmd);
                }
            }
            TaskManageDA taskMDa = new TaskManageDA();
            Task         task    = taskMDa.QueryTask(taskID);

            if (task.TaskState == TaskState.Waitting)
            {
                task.TaskState = TaskState.Finished;
                result        += taskMDa.TaskCompile(task);
            }

            return(result);
        }
Exemplo n.º 6
0
 public static string ValveControlFinished(string taskID, TaskState state)
 {
     try
     {
         MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
         QueryDocument        query = new QueryDocument();
         query.Add("TaskID", taskID);
         MongoCursor <Task> mongoCursor = mongo.Query(CollectionNameDefine.TaskCollectionName, query);
         var dataList = mongoCursor.ToList();
         if (dataList == null || dataList.Count == 0)
         {
             return("没有找到TaskID:【" + taskID + "】的任务。");
         }
         string result = "";
         Task   task   = dataList[0];
         task.Finished  = QuShi.getDate();
         task.TaskState = state;
         TaskManageDA tm = new TaskManageDA();
         result = tm.TaskCompile(task);
         if (result != "")
         {
             return(result);
         }
         Meter _meter = tm.QueryMeter(task.MeterMac);
         if (state == TaskState.Finished)
         {
             _meter.ValveState = task.TaskType == TaskType.TaskType_开阀 ? "0" : "1";
             result            = tm.UpdateMeter(_meter);
         }
         return(result);
     }
     catch (Exception e)
     {
         return(e.Message);
     }
 }