/// <summary>
        /// 更新设置结算日任务状态
        /// </summary>
        /// <param name="taskID"></param>
        /// <param name="state">状态:0 申请 1 完成 2 撤销  3 失败</param>
        /// <returns></returns>
        public string SettlementDaySetFinished(string taskID, TaskState state)
        {
            string result     = "";
            string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                TaskManageService tms = new TaskManageService();

                IoT_SettlementDayMeter dbinfo = dd.GetTable <IoT_SettlementDayMeter>().Where(p =>
                                                                                             p.TaskID == taskID).SingleOrDefault();
                dbinfo.State        = Convert.ToChar(((byte)state).ToString());
                dbinfo.FinishedDate = DateTime.Now;
                IoT_SetSettlementDay uploadCycle = dd.GetTable <IoT_SetSettlementDay>().Where(p => p.ID == dbinfo.ID).SingleOrDefault();

                Meter meter = tms.GetMeter(dbinfo.MeterNo.Trim());
                if (meter != null)
                {
                    meter.SettlementDay   = (int)uploadCycle.SettlementDay;
                    meter.SettlementMonth = (int)uploadCycle.SettlementMonth;
                    meter.SetNextSettlementDateTime();
                    result = new TaskManageDA().UpdateMeter(meter);
                }
                int iCount = dd.GetTable <IoT_SettlementDayMeter>().Where(p =>
                                                                          p.TaskID == taskID && p.State.ToString() == "0").Count();
                if (iCount == 1)
                {
                    uploadCycle.State = Convert.ToChar(((byte)state).ToString());
                }
                if (result != "")
                {
                    throw new Exception(result);
                }
                // 更新操作
                dd.SubmitChanges();

                if (state == TaskState.Undo)
                {
                    //撤销操作需要更新任务队列数据
                    new M_SetParameterService().UnSetParameter(taskID);
                }
                if (state == TaskState.Finished)
                {
                    IoT_Meter meterInfo = dd.GetTable <IoT_Meter>().Where(p => p.MeterNo == dbinfo.MeterNo).SingleOrDefault();
                    meterInfo.SettlementDay   = (int)uploadCycle.SettlementDay;
                    meterInfo.SettlementMonth = (int)uploadCycle.SettlementMonth;
                    // 更新操作
                    dd.SubmitChanges();
                }
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
Exemple #2
0
        public string Initi(string mac, MeterLink link, byte control, byte[] data, IotProtocolType protocolType = IotProtocolType.RanQiBiao)
        {
            if (this._meterLink != null)
            {
                return("IsExit");
            }

            this._meterLink = link;
            this._meterLink.OnConnectClosed += _meterLink_OnConnectClosed;
            try
            {
                //读取当前表的信息并初始化
                //Stopwatch sw = new Stopwatch();
                //sw.Start();
                meter = tms.GetMeter(mac);

                this._meterLink.OnReviced += _meterLink_OnReviced;

                //应答并上报数据
                ReportData(mac, control, data, protocolType);

                if (meter == null)
                {
                    return("");
                }
                //读取当前表任务
                List <Task> taskList = tms.GetTaskList(mac);

                //Log.getInstance().Write(MsgType.Information, string.Format("处理MAC上报数据:{0} Time:{1}", mac, sw.ElapsedMilliseconds / 1000.00));
                //Log.getInstance().Write(new OneMeterDataLogMsg(mac, string.Format("处理MAC上报数据:{0} Time:{1}; 时间:{2}", mac, sw.ElapsedMilliseconds / 1000.00, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"))));


                this._reportWatch.Start();
                //创建并启动任务执行线程
                this._taskThread = new Thread(new ParameterizedThreadStart(DoTask));
                this._reportWatch.Restart();
                this._taskThread.Start(taskList);
            }
            catch (Exception e)
            {
                Log.getInstance().Write(MsgType.Error, "创建IoTMetre对象失败,原因:" + e.Message);
                Log.getInstance().Write(new OneMeterDataLogMsg(this.MAC, "创建IoTMetre对象失败,原因:" + e.Message + e.ToString()));
                Log.getInstance().Write(e, MsgType.Error);
                return("创建IoTMetre对象失败,原因:" + e.Message);
            }
            return("");
        }
Exemple #3
0
        /// <summary>
        /// 换标登记动作
        /// </summary>
        /// <param name="taskID"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public Message Dengji(IoT_ChangeMeter info)
        {
            Message     m;
            string      configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            DataContext dd         = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                //查看该申请单的状态是否是"换表登记"或者"换表完成"状态,如果是该状态则填写换表登记失败
                IoT_ChangeMeter dbinfo = dd.GetTable <IoT_ChangeMeter>().Where(p =>
                                                                               p.CompanyID == info.CompanyID && p.ID == info.ID).SingleOrDefault();
                //判断当前的申请单的状态
                if (dbinfo.State == '2')//换表登记状态下提示
                {
                    return(new Message()
                    {
                        Result = false,
                        TxtMessage = "不能重复提交换表登记!"
                    });
                }
                else if (dbinfo.State == '3')//换表完成状态下提示
                {
                    return(new Message()
                    {
                        Result = false,
                        TxtMessage = "该用户已换表成功,若需要换表请重新填写申请单!"
                    });
                }
                Table <IoT_MeterHistory> tbHistory   = dd.GetTable <IoT_MeterHistory>();
                Table <IoT_Meter>        tbMeter     = dd.GetTable <IoT_Meter>();
                IoT_Meter        Meter_Model         = tbMeter.Where(u => u.MeterNo == info.OldMeterNo && u.UserID == info.UserID).FirstOrDefault();
                List <IoT_Meter> lstMeter_ModelExect = tbMeter.Where(u => u.MeterNo == info.NewMeterNo).ToList();
                //判断是否存在表具讯息
                if (Meter_Model == null)
                {
                    return(new Message()
                    {
                        Result = false,
                        TxtMessage = "换表登记失败,该用户暂无表具信息!"
                    });
                }
                //判断新表号是否已经存在
                if (lstMeter_ModelExect.Count > 0)
                {
                    return(new Message()
                    {
                        Result = false,
                        TxtMessage = "表号:" + info.NewMeterNo + "已存在,请更换表号"
                    });
                }
                IoT_MeterHistory History_Model = new IoT_MeterHistory()
                {//历史数据实体对象
                    ID              = Meter_Model.ID,
                    MeterNo         = Meter_Model.MeterNo,
                    MeterType       = Meter_Model.MeterType,
                    CompanyID       = Meter_Model.CompanyID,
                    UserID          = Meter_Model.UserID,
                    TotalAmount     = Meter_Model.TotalAmount,
                    TotalTopUp      = Meter_Model.TotalTopUp,
                    Direction       = Meter_Model.Direction,
                    InstallDate     = Meter_Model.InstallDate,
                    Price1          = Meter_Model.Price1,
                    Gas1            = Meter_Model.Gas1,
                    Price2          = Meter_Model.Price2,
                    Gas2            = Meter_Model.Gas2,
                    Price3          = Meter_Model.Price3,
                    Gas3            = Meter_Model.Gas3,
                    Price4          = Meter_Model.Price4,
                    Gas4            = Meter_Model.Gas4,
                    Price5          = Meter_Model.Price5,
                    IsUsed          = Meter_Model.IsUsed,
                    Ladder          = Meter_Model.Ladder,
                    SettlementType  = Meter_Model.SettlementType,
                    SettlementDay   = Meter_Model.SettlementDay,
                    ValveState      = Meter_Model.ValveState,
                    MeterState      = Meter_Model.MeterState,
                    ReadDate        = Meter_Model.ReadDate,
                    RemainingAmount = Meter_Model.RemainingAmount,
                    LastTotal       = Meter_Model.LastTotal,
                    PriceCheck      = Meter_Model.PriceCheck,
                    MKeyVer         = Meter_Model.MKeyVer,
                    MKey            = Meter_Model.MKey,
                    EnableMeterDate = Meter_Model.EnableMeterDate,
                    EnableMeterOper = Meter_Model.EnableMeterOper,
                    UploadCycle     = Meter_Model.UploadCycle,
                    SettlementMonth = Meter_Model.SettlementMonth
                };
                IoT_Meter Meter_Add = new IoT_Meter()
                {//表实体对象
                    MeterNo         = info.NewMeterNo,
                    MeterType       = Meter_Model.MeterType,
                    CompanyID       = info.CompanyID,
                    UserID          = info.UserID,
                    TotalAmount     = info.ChangeUseSum,       //新表表底
                    TotalTopUp      = Meter_Model.TotalTopUp,  //需要更新
                    Direction       = Meter_Model.Direction,
                    InstallDate     = Meter_Model.InstallDate, //需要更新
                    Price1          = Meter_Model.Price1,
                    Gas1            = Meter_Model.Gas1,
                    Price2          = Meter_Model.Price2,
                    Gas2            = Meter_Model.Gas2,
                    Price3          = Meter_Model.Price3,
                    Gas3            = Meter_Model.Gas3,
                    Price4          = Meter_Model.Price4,
                    Gas4            = Meter_Model.Gas4,
                    Price5          = Meter_Model.Price5,
                    IsUsed          = Meter_Model.IsUsed,
                    Ladder          = Meter_Model.Ladder,
                    SettlementType  = Meter_Model.SettlementType,
                    SettlementDay   = Meter_Model.SettlementDay,
                    ValveState      = Meter_Model.ValveState,
                    MeterState      = Meter_Model.MeterState,
                    ReadDate        = Meter_Model.ReadDate,
                    RemainingAmount = Meter_Model.RemainingAmount, //需要更新
                    LastTotal       = Meter_Model.LastTotal,       //需要更新
                    PriceCheck      = Meter_Model.PriceCheck,      //需要更新
                    MKeyVer         = Meter_Model.MKeyVer,
                    MKey            = Meter_Model.MKey,
                    EnableMeterDate = Meter_Model.EnableMeterDate, //需要更新
                    EnableMeterOper = Meter_Model.EnableMeterOper, //需要更新
                    UploadCycle     = Meter_Model.UploadCycle,
                    SettlementMonth = Meter_Model.SettlementMonth
                };
                //实现数据操作
                dbinfo.State           = info.State;
                dbinfo.ChangeUseSum    = info.ChangeUseSum;
                dbinfo.OldGasSum       = info.OldGasSum;
                dbinfo.ChangeGasSum    = info.ChangeGasSum;
                dbinfo.RemainingAmount = info.RemainingAmount;
                dbinfo.NewMeterNo      = info.NewMeterNo;
                dbinfo.TaskID          = Guid.NewGuid().ToString();
                tbMeter.DeleteOnSubmit(Meter_Model);     //删除表
                tbMeter.InsertOnSubmit(Meter_Add);       //新增表
                tbHistory.InsertOnSubmit(History_Model); //新增历史表

                dd.SubmitChanges();

                //获取meterId
                Meter_Add = tbMeter.Where(u => u.MeterNo == info.NewMeterNo && u.UserID == info.UserID).FirstOrDefault();
                //此处调用接口
                if (Meter_Add.MeterType == "01")
                {
                    TaskManageService tms = new TaskManageService();
                    //查原表数据
                    Meter _m = tms.GetMeter(info.OldMeterNo.Trim());
                    //_m.TotalAmount = (decimal)info.OldGasSum;
                    //金额表
                    //1、换表结算
                    decimal LastSettlementGas = _m.LastTotal;//原表上次结算时的表底数
                    //换表用气量 = 换表时表底 - 上次结算表底
                    dbinfo.ChangeUseSum = info.ChangeGasSum - LastSettlementGas;

                    _m = new Settlement().CalculateGasFee(_m, (decimal)info.ChangeGasSum, "", true);

                    Meter_Add.TotalTopUp      = _m.CurrentBalance; //新表上总金额(就是换表的余额)
                    Meter_Add.RemainingAmount = _m.CurrentBalance; //新表上剩余金额(就是换表的余额)
                    Meter_Add.LastTotal       = Meter_Add.TotalAmount;

                    //添加mongo队列表对象
                    string str = new TaskManageDA().ChangeMeterInsert(Meter_Add, _m.CurrentLadder, _m.CurrentPrice, (decimal)dbinfo.ChangeUseSum);
                    if (str != "")
                    {
                        throw new Exception(str);
                    }
                    //2、登记换表操作任务(登记操作指令)
                    str = new M_HuanBiaoService().SubmitASK(dbinfo.TaskID, Meter_Add, (decimal)dbinfo.ChangeUseSum);
                    if (str != "")
                    {
                        throw new Exception(str);
                    }
                }
                else
                {
                    //气量表
                }
                // 更新操作
                dd.SubmitChanges();

                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_ChangeMeter>(info)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "换表登记失败!" + e.Message
                };
            }
            return(m);
        }