Ejemplo 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);
        }
Ejemplo n.º 2
0
        public Message Add(IoT_SetUploadCycle info, List <IoT_UploadCycleMeter> meterList)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                //添加设置上传周期参数任务到通讯队列
                string result = new SetMeterParameter().SetUploadCycle(info, meterList);
                if (result != "")
                {
                    throw new Exception(result);
                }

                Table <IoT_SetUploadCycle> tbl = dd.GetTable <IoT_SetUploadCycle>();

                // 调用新增方法
                tbl.InsertOnSubmit(info);
                // 更新操作
                dd.SubmitChanges();
                // 更新操作
                Table <IoT_UploadCycleMeter> tbl_meter = dd.GetTable <IoT_UploadCycleMeter>();
                foreach (IoT_UploadCycleMeter meter in meterList)
                {
                    IoT_Meter tempMeter = MeterManageService.QueryMeter(meter.MeterNo);
                    meter.MeterID = tempMeter.ID;
                    meter.ID      = info.ID;
                    meter.Context = info.Context;
                    meter.State   = '0';//申请
                    info.TaskID   = meter.TaskID;
                    tbl_meter.InsertOnSubmit(meter);
                }
                // 更新操作
                dd.SubmitChanges();

                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_SetUploadCycle>(info)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增设置上传周期失败!" + e.Message
                };
            }
            return(m);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 批量添加用户
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public Message BatchAddUserMeter(IoT_User info, IoT_Meter meter)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                var count = dd.GetTable <IoT_Meter>().Where(p => p.CompanyID == meter.CompanyID && p.MeterNo == meter.MeterNo).Count();
                if (count > 0)
                {
                    m = new Message()
                    {
                        Result     = false,
                        TxtMessage = "表号不能重复!"
                    };
                    return(m);
                }


                Table <IoT_User> tbl = dd.GetTable <IoT_User>();
                info.UserID = GetUserID();
                if (info.UserID == "-1")
                {
                    m = new Message()
                    {
                        Result     = false,
                        TxtMessage = "新增用户失败!" + "获取用户id错误"
                    };
                    return(m);
                }
                // 调用新增方法
                tbl.InsertOnSubmit(info);
                // 更新操作
                dd.SubmitChanges();

                meter.UserID = info.UserID;
                MeterManageService meterService = new MeterManageService();
                m = meterService.Add(meter);
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增用户失败!" + e.Message
                };
            }
            return(m);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 执行点火操作,更新表点火状态,并更新表信息为点火指定参数同时提交点火任务给通信层
        /// </summary>
        /// <param name="meters"></param>
        /// <returns></returns>
        public string Do(List <IoT_Meter> meters)
        {
            MeterManageService _mms = new MeterManageService();
            DianhuoDA          dhDA = new DianhuoDA();
            TaskManageDA       tmd  = new TaskManageDA();

            foreach (IoT_Meter m in meters)
            {
                if (m.MeterState.ToString() == "5")
                {
                    IoT_Meter _oldMeter = MeterManageService.QueryMeter(m.MeterNo);
                    if (_oldMeter == null)
                    {
                        return(string.Format("点火失败,表{0}信息不存在!", m.MeterNo));
                    }

                    if (_oldMeter.MeterState == '0')
                    {
                        return(string.Format("表{0}已点火完成,不能重复操作。", m.MeterNo));
                    }
                    Meter _meter = tmd.QueryMeter(m.MeterNo.Trim());
                    tmd.UpdateMeter(m);
                    IoT_SetAlarm alarmPar = new IoT_SetAlarm();
                    alarmPar.SwitchTag = "000000000       ";
                    alarmPar.Par1      = 30;
                    alarmPar.Par2      = 10;
                    alarmPar.Par3      = 30;
                    alarmPar.Par4      = "";
                    alarmPar.Par5      = 10;
                    alarmPar.Par6      = 30;
                    alarmPar.Par7      = 30;
                    alarmPar.Par8      = 30;
                    alarmPar.Par9      = "00";
                    new SetAlarmService().UpdateMeterAlarmPar(m.MeterNo.Trim(), alarmPar);

                    //点火状态,需要修改表的通讯密钥
                    Message msg = _mms.Edit(m);
                    if (msg.Result == false)
                    {
                        return(string.Format("点火失败,原因:登记表{0}点火信息失败,原因:{1}", m.MeterNo, msg.TxtMessage));
                    }
                    string result = dhDA.SubmitDianHuoASK(_oldMeter);
                    new UserManageService().UpadteUserStatus("2", m.UserID);//用户表状态置为 撤销点火
                    if (result != "")
                    {
                        _mms.Edit(_oldMeter);
                    }
                }
            }
            return("");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 任务执行完成
        /// </summary>
        /// <param name="task"></param>
        public string TaskCompletes(Task task, decimal ljGas = 0)
        {
            string result = "";

            lock (_readlock)
            {
                //任务完成,设置表状态点火完成
                try
                {
                    //根据任务类型,处理《任务类型,点火任务(DH),换表登记(HB)、开阀(KF)、关阀(GF)、充值(CZ)、调整价格(TJ)等  》
                    switch (task.TaskType)
                    {
                    case TaskType.TaskType_点火:
                        MeterManageService mms = new MeterManageService();
                        IoT_Meter          m   = new DianHuoService().QueryMeter(task.MeterMac);
                        m.MeterState  = '0';
                        m.TotalAmount = ljGas;
                        CY.IotM.Common.Message msg = mms.Edit(m);
                        //更新mongo层Meter对象计价参数
                        new UserManageService().UpadteUserStatus("3", m.UserID);    //用户表状态置为 正常使用
                        if (msg.Result == false)
                        {
                            throw new Exception(msg.TxtMessage);
                        }
                        break;

                    case TaskType.TaskType_换表登记:
                        //在此实现换表完成代码
                        new HuanBiaoService().ChangeMeterFinished(task.TaskID, TaskState.Finished);
                        break;

                    case TaskType.TaskType_开阀:
                    case TaskType.TaskType_关阀:
                        ValveControlService valveControl = new ValveControlService();
                        valveControl.ValveControlFinished(task.TaskID, task.TaskType, TaskState.Finished);
                        break;

                    case TaskType.TaskType_充值:
                        //充值完成
                        TopUpService tps   = new TopUpService();
                        string       topup = tps.TopupFinished(task.TaskID, task.TaskState, "");
                        if (topup != "")
                        {
                            throw new Exception($"表号:{task.MeterMac} 充值完成,但更新mongo内存数据失败,原因:{topup}");
                        }
                        break;

                    case TaskType.TaskType_调整价格:
                        //表具已接受调价指令
                        new PricingManageService().UpdatePricingTaskState(task.TaskID, TaskState.Finished);
                        break;

                    case TaskType.TaskType_校准:
                        //系统自动发送和完成,无需做其他处理
                        new M_SetParameterService().XZFinished(task.TaskID);
                        break;

                    case TaskType.TaskType_设置报警参数:
                        new SetAlarmService().UpdateAlarmMeterState(task.TaskID, ((byte)TaskState.Finished).ToString());
                        break;

                    case TaskType.TaskType_设置结算日期:
                        //修改结算日期完成
                        new SettlementService().SettlementDaySetFinished(task.TaskID, TaskState.Finished);
                        break;

                    case TaskType.TaskType_设置上传周期:
                        //
                        new SetUploadCycleService().UpdateUploadCycleState(task.TaskID, TaskState.Finished);
                        break;

                    case TaskType.TaskType_发布广告:
                        if (task.TaskState != TaskState.Waitting)
                        {
                            new AdInfoService().ADPublishFinished(task);
                        }

                        break;
                        //case TaskType.TaskType_编辑广告配置:
                        //    new AdInfoService().UpdateTaskStatus(task.TaskID, TaskState.Finished);

                        //    break;
                    }

                    new CY.IoTM.MongoDataHelper.TaskManageDA().TaskCompile(task);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Log.getInstance().Write(MsgType.Error, "TaskCompletes 任务完成状态更新失败,原因:" + e.Message);
                    Log.getInstance().Write(new OneMeterDataLogMsg(task.MeterMac, e.Message));
                }

                return(result);
            }
        }
Ejemplo n.º 6
0
        public string Topup(string meterNo, decimal money, TopUpType topUpType, string oper, string orgCode, IoT_MeterTopUp info)
        {
            IoT_Meter _meter = MeterManageService.QueryMeter(meterNo);
            Meter     _m     = new TaskManageService().GetMeter(meterNo.Trim());

            if (_m == null)
            {
                return(string.Format("表:{0}不存在,充值失败。", meterNo));
            }
            if (_meter == null)
            {
                return(string.Format("表:{0}不存在,充值失败。", meterNo));
            }
            string taskID;//充值任务ID,通讯任务层提供

            if (_m.LastTopUpSer == 0)
            {
                _m.LastTopUpSer++;
            }

            //写充值记录到数据库
            IoT_MeterTopUp _topUp = new IoT_MeterTopUp();

            _topUp.CompanyID  = _meter.CompanyID;
            _topUp.UserID     = _meter.UserID;
            _topUp.MeterID    = _meter.ID;
            _topUp.MeterNo    = _meter.MeterNo;
            _topUp.TopUpType  = Convert.ToChar(((byte)topUpType).ToString());
            _topUp.Amount     = (decimal)money;
            _topUp.Oper       = oper;
            _topUp.OrgCode    = orgCode;
            _topUp.Ser        = _m.LastTopUpSer;
            _topUp.State      = '0';
            _topUp.IsPrint    = false;
            _topUp.TopUpDate  = DateTime.UtcNow.AddHours(8);
            _topUp.PayType    = info.PayType;
            _topUp.SFOperID   = info.SFOperID;
            _topUp.SFOperName = info.SFOperName;
            //任务提交层(mongo)
            M_MeterTopUpService _mtus = new M_MeterTopUpService();
            string result             = _mtus.TopUp(_topUp, out taskID);

            if (result != "")
            {
                return(string.Format("表:{0}不存在,充值失败,原因:{1}", meterNo, result));
            }
            _topUp.TaskID  = taskID;
            _topUp.Context = "";

            new TaskManageDA().UpdateMeter(_m);
            result = InsertTopUp(_topUp);
            Message message = new Message();

            if (result == "")
            {
                message.Result     = true;
                message.TxtMessage = JsonConvert.SerializeObject(_topUp);
            }
            else
            {
                message.Result     = false;
                message.TxtMessage = result;
            }
            return(JsonConvert.SerializeObject(message));;
        }
Ejemplo n.º 7
0
 public IoT_Meter QueryMeter(string meterNo)
 {
     return(MeterManageService.QueryMeter(meterNo));
 }
Ejemplo n.º 8
0
        public Message Add(IoT_Pricing info, List <IoT_PricingMeter> meterList)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                //获取价格信息
                IoT_PricePar priceInfo = dd.GetTable <IoT_PricePar>().Where(p =>
                                                                            p.CompanyID == info.CompanyID && p.ID == int.Parse(info.PriceType)).SingleOrDefault();

                info.Price1 = priceInfo.Price1 == null ? 0 : priceInfo.Price1;
                info.Gas1   = priceInfo.Gas1 == null ? 0 : priceInfo.Gas1;
                info.Price2 = priceInfo.Price2 == null ? 0 : priceInfo.Price2;
                info.Gas2   = priceInfo.Gas2 == null ? 0 : priceInfo.Gas2;
                info.Price3 = priceInfo.Price3 == null ? 0 : priceInfo.Price3;
                info.Gas3   = priceInfo.Gas3 == null ? 0 : priceInfo.Gas3;
                info.Price4 = priceInfo.Price4 == null ? 0 : priceInfo.Price4;
                info.Gas4   = priceInfo.Gas4 == null ? 0 : priceInfo.Gas4;
                info.Price5 = priceInfo.Price5 == null ? 0 : priceInfo.Price5;

                info.IsUsed         = priceInfo.IsUsed == null ? false : priceInfo.IsUsed;
                info.Ladder         = priceInfo.Ladder == null ? 3 : priceInfo.Ladder;
                info.SettlementType = priceInfo.SettlementType;
                info.MeterType      = "01";

                //设置调价计划参数和条件任务
                string result = new SetMeterParameter().SetPricingPlan(info, meterList);
                if (result != "")
                {
                    throw new Exception(result);
                }


                Table <IoT_Pricing> tbl = dd.GetTable <IoT_Pricing>();
                // 调用新增方法
                tbl.InsertOnSubmit(info);
                // 更新操作
                dd.SubmitChanges();

                Table <IoT_PricingMeter> tbl_meter = dd.GetTable <IoT_PricingMeter>();
                foreach (IoT_PricingMeter meter in meterList)
                {
                    IoT_Meter tempMeter = MeterManageService.QueryMeter(meter.MeterNo);
                    meter.MeterID = tempMeter.ID;
                    meter.ID      = info.ID;
                    meter.Context = info.Context;
                    meter.State   = '0';//申请
                    tbl_meter.InsertOnSubmit(meter);
                }
                // 更新操作
                dd.SubmitChanges();

                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_Pricing>(info)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增调价计划失败!" + e.Message
                };
            }
            return(m);
        }