Beispiel #1
0
        /// <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);
        }
Beispiel #2
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);
        }
Beispiel #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));;
        }