Esempio n. 1
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);
        }
Esempio n. 2
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("");
        }
Esempio n. 3
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));;
        }
Esempio n. 4
0
 public IoT_Meter QueryMeter(string meterNo)
 {
     return(MeterManageService.QueryMeter(meterNo));
 }
Esempio n. 5
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);
        }