/// <summary>
        /// 设置调价计划
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string SetPricingPlan(PricingPlan info, IoT_PricingMeter meter)
        {
            string result = "";

            try
            {
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = meter.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_调整价格;    //
                //读取表信息
                info.MeterNo = meter.MeterNo.Trim();
                info.TaskID  = task.TaskID;

                //写任务
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                meter.TaskID = task.TaskID;

                //2.设置调价计划数据
                DataItem_A010 item_A010 = null;
                CT            ct        = new CT(info.MeterType == "00" ? MeterType.气量表 : MeterType.金额表,
                                                 (bool)info.IsUsedLadder, (JieSuanType)Convert.ToInt16(info.SettlementType.ToString()), ((int)info.Ladder) <= 0 ? 1 : (int)info.Ladder);

                item_A010           = new DataItem_A010(Convert.ToByte(new Random().Next(0, 255)), ct, DateTime.Now);
                item_A010.Price1    = (decimal)info.Price1;
                item_A010.Price2    = (decimal)info.Price2;
                item_A010.Price3    = (decimal)info.Price3;
                item_A010.Price4    = (decimal)info.Price4;
                item_A010.Price5    = (decimal)info.Price5;
                item_A010.UseGas1   = (decimal)info.Gas1;
                item_A010.UseGas2   = (decimal)info.Gas2;
                item_A010.UseGas3   = (decimal)info.Gas3;
                item_A010.UseGas4   = (decimal)info.Gas4;
                item_A010.StartDate = Convert.ToDateTime(info.UseDate);

                Command cmd = new Command();
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_A010.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.WriteData;//设置参数
                cmd.DataLength     = Convert.ToByte(item_A010.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A010.GetBytes());
                cmd.Order          = 1;
                CommandDA.Insert(cmd);


                new PricingPlanDA().NewPricingPlan(info);

                //注:该函数如何进行事务处理,保证所有数据更新都成功。
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 添加修正任务
        /// </summary>
        /// <param name="correctRecord"></param>
        /// <returns></returns>
        public string AddCorrentTask(CorrectRecord correctRecord, out Task returnTask)
        {
            string result = "";

            returnTask = null;
            try
            {
                //先删除未执行的任务
                DeleteUnRunTask(correctRecord.MeterNo.Trim());
                MongoDBHelper <Meter> mongo = new MongoDBHelper <Meter>();
                //1、记录修正信息
                result = mongo.Insert(CollectionNameDefine.MeterCorrectRecord, correctRecord);
                if (result != "")
                {
                    return(result);
                }
                //2、创建修正任务指令
                //创建一个任务
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = correctRecord.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_校准;      //点火任务(DH),换表登记(HB)、开阀(KF)、关阀(GF)、充值(CZ)、调整价格(TJ)
                //写任务
                result = mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                if (result != "")
                {
                    return(result);
                }

                Command cmd = new Command();
                //1.写校正指令
                byte          ser       = Convert.ToByte(new Random().Next(0, 255));
                DataItem_C102 item_C102 = new DataItem_C102(ser, correctRecord.TotalTopUp - correctRecord.SettlementBalance, correctRecord.SettlementBalance, correctRecord.LastSettlementDayLJGas);
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_C102.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.CYWriteData;//创源写操作
                cmd.DataLength     = Convert.ToByte(item_C102.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_C102.GetBytes());
                cmd.Order          = 1;
                //返回修正任务
                result     = CommandDA.Insert(cmd);
                returnTask = task;
                task.CommandList.Add(cmd);
                if (result != "")
                {
                    return(result);
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
            return("");
        }
Example #3
0
        public string TaskCompile(Task task)
        {
            MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
            var query = new QueryDocument();

            query.Add("_id", task._id);
            var update = new UpdateDocument();

            update.Add("TaskState", task.TaskState);
            update.Add("Finished", QuShi.getDate());
            update.Add("MeterMac", task.MeterMac);
            update.Add("TaskDate", task.TaskDate);
            update.Add("TaskID", task.TaskID);
            update.Add("TaskType", task.TaskType);
            update.Add("TaskSource", task.TaskSource == null ?"":task.TaskSource);
            //update.Add("CommandList", task.CommandList);
            return(mongo.Update(CollectionNameDefine.TaskCollectionName, query, update));
        }
        /// <summary>
        /// 设置报警参数任务
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string SetWariningParameter(IoT_SetAlarm info, IoT_AlarmMeter meter)
        {
            string result = "";

            try
            {
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = meter.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_设置报警参数;  //
                //写任务
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                meter.TaskID = task.TaskID;

                //3.设置报警参数
                DataItem_C103 item_C103 = new DataItem_C103(Convert.ToByte(new Random().Next(0, 255)), new WaringSwitchSign(info.SwitchTag));
                item_C103.长期未与服务器通讯报警时间 = Convert.ToByte(info.Par1);
                item_C103.燃气漏泄切断报警时间    = Convert.ToByte(info.Par2);
                item_C103.燃气流量过载切断报警时间  = Convert.ToByte(info.Par3);
                item_C103.异常大流量值        = MyDataConvert.TwoBCDStrToDecimal(info.Par4);
                item_C103.异常大流量切断报警时间   = Convert.ToByte(info.Par5);
                item_C103.异常微小流量切断报警时间  = Convert.ToByte(info.Par6);
                item_C103.持续流量切断报警时间    = Convert.ToByte(info.Par7);
                item_C103.长期未使用切断报警时间   = Convert.ToByte(info.Par8);
                //item_C103.长期未使用切断报警时间 = Convert.ToByte(info.Par7);

                Command cmd = new Command();
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_C103.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
                cmd.DataLength     = Convert.ToByte(item_C103.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_C103.GetBytes());
                cmd.Order          = 3;
                CommandDA.Insert(cmd);
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
        public static string Undo(string taskID)
        {
            //先读任务
            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 + "】的任务。");
                }

                Task task = dataList[0];
                if (task.TaskState != TaskState.Waitting)
                {
                    return(string.Format("任务TaskID:{0}状态为:{1},不能撤销.", taskID, task.TaskState));
                }
                task.TaskState = TaskState.Undo;
                List <Command> list = CommandDA.QueryCommandList(task.TaskID);
                if (list != null && list.Count == 0)
                {
                    return(string.Format("任务TaskID:{0}的指令已执行,不能撤销.", taskID));
                }
                foreach (Command cmd in list)
                {
                    cmd.CommandState = CommandState.Undo;
                    cmd.AnswerDate   = QuShi.getDate();
                    CommandDA.Update(cmd);
                }
                new TaskManageDA().TaskCompile(task);
                return("");
            }
            catch (Exception e)
            {
                //记录日志
                Console.WriteLine(e.Message);
                return(e.Message);
            }
        }
Example #6
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);
            }
        }
Example #7
0
        /// <summary>
        /// 创建充值任务
        /// </summary>
        /// <param name="topup">充值数据对象</param>
        /// <param name="taskID"></param>
        /// <returns></returns>
        public string TopUp(IoT_MeterTopUp topup, out string taskID)
        {
            //创建一个任务
            string result = "";
            MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
            Task task = new Task();

            task.MeterMac  = topup.MeterNo.Trim();
            task.TaskDate  = QuShi.getDate();
            task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
            task.TaskState = TaskState.Waitting;
            task.TaskType  = TaskType.TaskType_充值;      //点火任务(DH),换表登记(HB)、开阀(KF)、关阀(GF)、充值(CZ)、调整价格(TJ)
            //写任务
            result = mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
            taskID = task.TaskID;
            if (result != "")
            {
                return(result);
            }

            //创建命令
            Command       cmd       = new Command();
            byte          ser       = Convert.ToByte(topup.Ser);//new Random().Next(0, 255));
            DataItem_A013 item_A013 = new DataItem_A013(ser, ser, (decimal)topup.Amount);

            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_A013.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.WriteData;//写操作
            cmd.DataLength     = Convert.ToByte(item_A013.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A013.GetBytes());
            cmd.Order          = 1;
            result             = CommandDA.Insert(cmd);
            if (result != "")
            {
                return(result);
            }
            return("");
        }
        /// <summary>
        /// 设置结算日
        /// </summary>
        /// <param name="settlementDay"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string SetSettlementDay(IoT_SetSettlementDay settlementDay, IoT_SettlementDayMeter meter)
        {
            string result = "";

            try
            {
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = meter.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_设置结算日期;  //
                //写任务
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                meter.TaskID = task.TaskID;

                //2.设置上传周期
                int JSDay   = (int)settlementDay.SettlementDay;
                int JSMonth = (int)settlementDay.SettlementMonth;

                DataItem_A011 item_A011 = new DataItem_A011(Convert.ToByte(new Random().Next(0, 255)), JSDay, JSMonth);
                Command       cmd       = new Command();
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_A011.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.WriteData;//设置参数
                cmd.DataLength     = Convert.ToByte(item_A011.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A011.GetBytes());
                cmd.Order          = 1;
                CommandDA.Insert(cmd);
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
 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);
     }
 }
        /// <summary>
        /// 设置上传周期
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string SetUploadCycle(IoT_SetUploadCycle info, IoT_UploadCycleMeter meter)
        {
            string result = "";

            try
            {
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = meter.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_设置上传周期;  //
                //写任务
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                meter.TaskID = task.TaskID;

                /*上传周期模式:
                 * 00:以月为周期,在每个月的XX日YY时ZZ分上传数据;
                 * 01:以XX天为周期,在每XX天的YY时ZZ分上传数据,起点为每月的01日00时00分;
                 * 02:以YY时为周期,在每YY小时的ZZ分上传数据,起点为每天的00时00分;
                 * 03:以燃气表启动开始计时,以XX日YY时ZZ分上传数据
                 */
                ReportCycleType cycleType = ReportCycleType.时周期;

                if (info.ReportType == "00")
                {
                    cycleType = ReportCycleType.月周期;
                }
                else if (info.ReportType == "01")
                {
                    cycleType = ReportCycleType.天周期;
                }
                else if (info.ReportType == "02")
                {
                    cycleType = ReportCycleType.时周期;
                }
                else if (info.ReportType == "03")
                {
                    cycleType = ReportCycleType.周期采集;
                }

                /*周期参数,
                 * DD 天    范围:00-31
                 * HH 小时  范围:00-23
                 * MM 分钟  范围:00-59*/
                int DD = 1;
                int HH = 23;
                int MM = 59;
                try
                {
                    DD = Convert.ToInt32(info.Par.Substring(0, 2));
                    HH = Convert.ToInt32(info.Par.Substring(2, 2));
                    MM = Convert.ToInt32(info.Par.Substring(4, 2));
                }
                catch
                { }

                //2.设置上传周期
                DataItem_C105 item_C105 = new DataItem_C105(Convert.ToByte(new Random().Next(0, 255)), cycleType, DD, HH, MM);
                item_C105.type = (ReportCycleType)Convert.ToByte(info.ReportType);
                item_C105.XX   = Convert.ToUInt16(info.Par.Substring(0, 2));
                item_C105.YY   = Convert.ToUInt16(info.Par.Substring(2, 2));
                item_C105.ZZ   = Convert.ToUInt16(info.Par.Substring(4, 2));

                Command cmd = new Command();
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_C105.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
                cmd.DataLength     = Convert.ToByte(item_C105.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_C105.GetBytes());
                cmd.Order          = 2;
                CommandDA.Insert(cmd);
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
Example #11
0
        /// <summary>
        /// 换表申请指令
        /// </summary>
        /// <returns></returns>
        public string SubmitASK(string taskID, IoT_Meter meter, decimal LJGas)
        {
            /*数据标识DI,序号SER,当前累计用量(金额),当前剩余用量(气量/金额),本阶梯周期已使用累计用量(气量)*/

            //创建一个任务
            MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
            Task task = new Task();

            task.MeterMac  = meter.MeterNo.Trim();
            task.TaskDate  = QuShi.getDate();
            task.TaskID    = taskID;                 //用于和指令进行进行关联
            task.TaskState = TaskState.Waitting;
            task.TaskType  = TaskType.TaskType_换表登记; //点火任务(DH),换表登记(HB)、开阀(KF)、关阀(GF)、充值(CZ)、调整价格(TJ)
            //写任务
            mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);

            Command cmd = new Command();
            byte    ser = Convert.ToByte(new Random().Next(0, 255));

            cmd = new Command();
            //1.写密钥
            //DataItem_A014 item_A014 = new DataItem_A014(ser, (byte)meter.MKeyVer, meter.MKey);//
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_A014.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.WriteData;//写操作
            //cmd.DataLength = Convert.ToByte(item_A014.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_A014.GetBytes());
            //cmd.Order = 1;
            //CommandDA.Insert(cmd);

            ////2.设置上传周期
            //DataItem_C105 item_C105 = new DataItem_C105(Convert.ToByte(new Random().Next(0, 255)), ReportCycleType.天周期, 1, 23, 59);
            //cmd = new Command();
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C105.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(item_C105.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C105.GetBytes());
            //cmd.Order = 2;
            //CommandDA.Insert(cmd);

            ////3.设置报警参数
            //DataItem_C103 item_C103 = new DataItem_C103(Convert.ToByte(new Random().Next(0, 255)), new WaringSwitchSign() { 长期未使用切断报警 = true, 长期未与服务器通讯报警 = true });
            //cmd = new Command();
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C103.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(item_C103.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C103.GetBytes());
            //cmd.Order = 3;
            //CommandDA.Insert(cmd);

            //4.写价格表
            DataItem_A010 item_A010 = null;
            CT            ct        = new CT(meter.MeterType == "00" ? MeterType.气量表 : MeterType.金额表,
                                             (bool)meter.IsUsed, (JieSuanType)Convert.ToInt16(meter.SettlementType.ToString()), meter.Ladder == null ? 1 : (int)meter.Ladder);

            item_A010           = new DataItem_A010(Convert.ToByte(new Random().Next(0, 255)), ct, DateTime.Now);
            item_A010.Price1    = (decimal)meter.Price1;
            item_A010.Price2    = (decimal)meter.Price2;
            item_A010.Price3    = (decimal)meter.Price3;
            item_A010.Price4    = (decimal)meter.Price4;
            item_A010.Price5    = (decimal)meter.Price5;
            item_A010.UseGas1   = (decimal)meter.Gas1;
            item_A010.UseGas2   = (decimal)meter.Gas2;
            item_A010.UseGas3   = (decimal)meter.Gas3;
            item_A010.UseGas4   = (decimal)meter.Gas4;
            item_A010.StartDate = DateTime.Now;

            cmd                = new Command();
            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_A010.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.WriteData;//设置参数
            cmd.DataLength     = Convert.ToByte(item_A010.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A010.GetBytes());
            cmd.Order          = 4;
            CommandDA.Insert(cmd);

            //5.写结算日
            DataItem_A011 item_a011 = new DataItem_A011(Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(meter.SettlementDay));

            item_a011.JieSuanMonth = 1;//根据系统定义取值
            cmd                = new Command();
            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_a011.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.WriteData;//设置参数
            cmd.DataLength     = Convert.ToByte(item_a011.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_a011.GetBytes());

            cmd.Order = 5;
            CommandDA.Insert(cmd);
            //6.写换表指令
            DataItem_C107 item_C107 = new DataItem_C107(Convert.ToByte(new Random().Next(0, 255)), 0.0m, (decimal)meter.TotalTopUp, LJGas);

            cmd                = new Command();
            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_C107.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
            cmd.DataLength     = Convert.ToByte(item_C107.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_C107.GetBytes());
            cmd.Order          = 6;
            CommandDA.Insert(cmd);
            return("");
        }
Example #12
0
        /// <summary>
        /// 发布广告
        /// </summary>
        /// <param name="ap">广告发布信息</param>
        /// <param name="listMeter">广告用户列表</param>
        /// <param name="aDItems">广告内容列表</param>
        /// <param name="type">发布类型</param>
        /// <returns></returns>
        public string PublishAD(ADPublish ap, List <ADPublisMeter> listMeter, List <ADItem> aDItems, PublishType type)
        {
            //创建一个任务
            ser++;

            MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
            // DataItem_C109(byte ser, ADPublishOperatorCode operatorCode,byte fileCount,List<ADFile> fileList)
            //发布文件列表
            List <Common.Item.ADFile> fileList = new List <Common.Item.ADFile>();
            //操作码
            ADPublishOperatorCode operatorCode = type == PublishType.NewPublish ? ADPublishOperatorCode.ReDefineList : ADPublishOperatorCode.AddList;
            //文件条数
            byte fileCount = (byte)aDItems.Count;

            foreach (ADItem item in aDItems)
            {
                Common.Item.ADFile aDfile = new Common.Item.ADFile((int)item.OrderID, item.StoreName, (DateTime)item.BDate, (DateTime)item.EDate, (int)item.Length, (int)item.FileLength);
                fileList.Add(aDfile);
            }

            foreach (ADPublisMeter meter in listMeter)
            {
                Task task = new Task();
                task.MeterMac   = meter.MeterNo.Trim();
                task.TaskDate   = QuShi.getDate();
                task.TaskID     = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState  = TaskState.Waitting;
                task.TaskType   = TaskType.TaskType_发布广告;    //广告文件(GGF)
                task.TaskSource = string.Format("{0}|{1}|{2}", meter.AP_ID, meter.UserID, meter.CompanyID);
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);

                //meter.TaskID = task.TaskID;  //设置任务编号
                //准备指令
                Command       cmd       = new Command();
                DataItem_C109 item_c109 = new DataItem_C109(ser, operatorCode, fileCount, fileList);
                cmd.Identification = ((UInt16)item_c109.IdentityCode).ToString("X2");;
                cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
                byte[] tmp = item_c109.GetBytes();
                cmd.DataLength  = Convert.ToByte(tmp.Length);
                cmd.DataCommand = MyDataConvert.BytesToHexStr(tmp);  //指令内容
                cmd.Order       = (byte)1;

                cmd.TaskID = task.TaskID;

                CommandDA.Insert(cmd);
            }

            //Command cmd = new Command();
            //byte ser = Convert.ToByte(new Random().Next(0, 255));
            //byte fileid = (byte)adfile.id;//广告命令 只存储文件编号
            //byte[] contentAllBytes = new byte[1];
            //contentAllBytes[0] = fileid;
            ////1.文件发送
            //DataItem_C108 item_C108 = new DataItem_C108(ser, adfile.FileName, 1, 1, 1, 1, contentAllBytes);//
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C108.IdentityCode).ToString("X2"); ;
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(contentAllBytes.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C108.GetBytes()); ; //文件内容
            //cmd.Order = (byte)1;
            //CommandDA.Insert(cmd);


            //1.文件配置发送指令
            //cmd = new Command();
            //DataItem_C109 item_C109 = new DataItem_C109(Convert.ToByte(new Random().Next(0, 255)), adddfile.FileNO, adddfile.FileName, adddfile.DTStart, adddfile.DTEnd, adddfile.PollTime, adddfile.OpShowStatus, adddfile.OpDeleteStatus);//
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C109.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(item_C109.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C109.GetBytes());
            //cmd.Order = (byte)(2);
            //CommandDA.Insert(cmd);

            return("");//返回空表示成功
        }