public ReturnValueInfo UpdateRecord(SourceConsumeRecord_scr_Info infoObject)
 {
     throw new NotImplementedException();
 }
Beispiel #2
0
        public override List<ConsumeRecord_csr_Info> GetAllProfileRecords()
        {
            List<ConsumeRecord_csr_Info> listReturn = null;
            try
            {
                IConsumeMachineBL MacBLL = MasterBLLFactory.GetBLL<IConsumeMachineBL>(MasterBLLFactory.ConsumeMachine);
                ConsumeMachineMaster_cmm_Info machineInfo = MacBLL.SearchRecords(new ConsumeMachineMaster_cmm_Info() { cmm_iMacNo = base.MacNo, cmm_cIPAddr = base.IP.ToString() }).FirstOrDefault();
                if (machineInfo == null)
                {
                    return listReturn;
                }

                bool isPingSucc = Common.General.Ping(base.IP.ToString());
                List<PosRecord> listRecord = this._Device.ER_GetAllRecord();
                if (listRecord != null && isPingSucc)
                {
                    if (listRecord.Count > 0)
                    {
                        //转换数据,保存到数据库
                        #region 转换原始数据

                        List<SourceConsumeRecord_scr_Info> listDBRecord = new List<SourceConsumeRecord_scr_Info>();
                        foreach (PosRecord payItem in listRecord)
                        {
                            try
                            {
                                SourceConsumeRecord_scr_Info sRecord = new SourceConsumeRecord_scr_Info();
                                sRecord.scr_cAdd = "sys";
                                sRecord.scr_cCardNo = payItem.CardNo;
                                sRecord.scr_cRecordID = Guid.NewGuid();
                                sRecord.scr_dAddDate = DateTime.Now;
                                sRecord.scr_dRecordTime = payItem.RecordTime;
                                sRecord.scr_fBalance = payItem.Balance;
                                sRecord.scr_fConsume = payItem.Consume;
                                sRecord.scr_iMacNo = base.MacNo;
                                listDBRecord.Add(sRecord);
                            }
                            catch (Exception exItem)
                            {
                                throw exItem;
                            }
                        }

                        #endregion

                        ISourceConsumeRecordBL BLL = MasterBLLFactory.GetBLL<ISourceConsumeRecordBL>(MasterBLLFactory.SourceConsumeRecord);
                        ReturnValueInfo rvInfo = BLL.BatchInsertRecord(listDBRecord);

                        if (rvInfo.boolValue && !rvInfo.isError)
                        {
                            machineInfo.cmm_lLastAccessRes = true;

                            this.RemoveAllConsumptionRecords();
                            listReturn = rvInfo.ValueObject as List<ConsumeRecord_csr_Info>;
                        }
                        else
                        {
                            machineInfo.cmm_lLastAccessRes = false;
                        }
                    }
                    else
                    {
                        machineInfo.cmm_lLastAccessRes = true;
                        listReturn = new List<ConsumeRecord_csr_Info>();
                    }
                }
                else
                {
                    machineInfo.cmm_lLastAccessRes = false;
                }

                machineInfo.cmm_dLastAccessTime = DateTime.Now;
                machineInfo.cmm_cLast = "sys";
                machineInfo.cmm_dLastDate = DateTime.Now;
                MacBLL.Save(machineInfo, Common.DefineConstantValue.EditStateEnum.OE_Update);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return listReturn;
        }
        /// <summary>
        /// 收集定餐消费数据
        /// </summary>
        /// <param name="MacObjInfo">机器主档信息</param>
        ReturnValueInfo SetMealRecordCollection(Object MacObjInfo)
        {
            ReturnValueInfo rvInfoMain = new ReturnValueInfo();
            try
            {
                ConsumeMachineMaster_cmm_Info MacInfo = MacObjInfo as ConsumeMachineMaster_cmm_Info;
                if (MacInfo != null)
                {
                    string strMacDetail = "机号:" + MacInfo.cmm_iMacNo + "-" + MacInfo.cmm_cIPAddr + ":" + MacInfo.cmm_iPort.ToString() + "-" + MacInfo.cmm_cDesc;
                    try
                    {
                        int iMacNo = MacInfo.cmm_iMacNo;
                        int iPort = MacInfo.cmm_iPort;
                        IPAddress ipAddr = IPAddress.Parse(MacInfo.cmm_cIPAddr);
                        bool resPing = Common.General.Ping(ipAddr.ToString());

                        //更新设备访问信息
                        MacInfo.cmm_lLastAccessRes = false;
                        MacInfo.cmm_dLastAccessTime = DateTime.Now;
                        MacInfo.cmm_cLast = this._ServiceName;
                        MacInfo.cmm_dLastDate = DateTime.Now;

                        if (resPing)
                        {
                            #region 可以ping通,则表示可以进行收数操作

                            AbstractPayDevice device = PaymentDeviceFactory.CreateDevice(PaymentDeviceFactory.EastRiverDevice);
                            ReturnValueInfo rvInfoConn = device.Conn(ipAddr, iPort, iMacNo);
                            if (rvInfoConn.boolValue && !rvInfoConn.isError)
                            {
                                #region 设备连接成功

                                List<PosRecord> listSourceRecord = device.GetAllConsumptionRecords();
                                if (listSourceRecord != null)
                                {
                                    if (listSourceRecord.Count > 0)
                                    {
                                        #region 收到的消费数据数量不为零

                                        try
                                        {
                                            //转换数据,保存到数据库
                                            #region 转换原始数据

                                            List<SourceConsumeRecord_scr_Info> listDBRecord = new List<SourceConsumeRecord_scr_Info>();

                                            foreach (PosRecord payItem in listSourceRecord)
                                            {
                                                try
                                                {
                                                    SourceConsumeRecord_scr_Info sRecord = new SourceConsumeRecord_scr_Info();
                                                    sRecord.scr_cAdd = this._ServiceName;
                                                    sRecord.scr_cCardNo = payItem.CardNo;
                                                    sRecord.scr_cRecordID = Guid.NewGuid();
                                                    sRecord.scr_dAddDate = DateTime.Now;
                                                    sRecord.scr_dRecordTime = payItem.RecordTime;
                                                    sRecord.scr_fBalance = payItem.Balance;
                                                    sRecord.scr_fConsume = payItem.Consume;
                                                    sRecord.scr_iMacNo = MacInfo.cmm_iMacNo;
                                                    listDBRecord.Add(sRecord);
                                                }
                                                catch (Exception exItem)
                                                {
                                                    this._LocalLogger.WriteLog(exItem.Message + "-" + DateTime.Now.ToString(), string.Empty, SystemLog.SystemLog.LogType.Error);
                                                    throw exItem;
                                                }
                                            }

                                            #endregion

                                            //插入消费数据(插入原始消费数据表,消费数据表
                                            ReturnValueInfo rvInfoInsert = this._ISourceConsumeRecordBL.BatchInsertRecord(listDBRecord);
                                            if (!rvInfoInsert.isError)
                                            {
                                                List<ConsumeRecord_csr_Info> listReturn = rvInfoConn.ValueObject as List<ConsumeRecord_csr_Info>;
                                                if (listReturn != null)
                                                {
                                                    this._LocalLogger.WriteLog("返回成功保存记录数量:" + listReturn.Count.ToString() + "条。" + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Trace);
                                                }
                                                else
                                                {
                                                    this._LocalLogger.WriteLog("返回成功保存记录发生异常。" + rvInfoConn.messageText + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Error);
                                                    rvInfoMain.isError = true;
                                                }

                                                MacInfo.cmm_lLastAccessRes = true;
                                                MacInfo.cmm_dLastAccessTime = DateTime.Now;

                                                //删除所有消费数据
                                                #region 消费机清数
                                                ReturnValueInfo rvInfoClear = device.RemoveAllConsumptionRecords();
                                                if (!rvInfoClear.boolValue || rvInfoClear.isError)
                                                {
                                                    this._LocalLogger.WriteLog("删除设备数据失败。" + rvInfoConn.messageText + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Error);
                                                    rvInfoMain.isError = true;
                                                }
                                                #endregion
                                            }
                                            else
                                            {
                                                this._LocalLogger.WriteLog("保存消费数据失败。" + rvInfoConn.messageText + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Error);
                                                rvInfoMain.isError = true;
                                            }
                                        }
                                        catch (Exception exList)
                                        {
                                            //有错误数据产生,停止收集数据
                                            this._LocalLogger.WriteLog(exList.Message, strMacDetail, SystemLog.SystemLog.LogType.Error);
                                            rvInfoMain.isError = true;
                                        }

                                        #endregion
                                    }
                                    else if (listSourceRecord.Count == 0)
                                    {
                                        rvInfoMain.isError = false;
                                        rvInfoMain.boolValue = true;
                                        this._LocalLogger.WriteLog("消费机:" + MacInfo.cmm_iMacNo + "号,没有收集到消费数据。" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Warning);
                                        MacInfo.cmm_lLastAccessRes = true;
                                        MacInfo.cmm_dLastAccessTime = DateTime.Now;
                                    }

                                    //Modify by Donald @ 12-24,获取数据操作完毕后清除黑名单
                                    rvInfoConn = device.RemoveAllBlacklist();
                                    if (rvInfoConn.boolValue && !rvInfoConn.isError)
                                    {
                                        //this._LocalLogger.WriteLog("删除设备黑名单成功。" + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Trace);
                                        rvInfoMain.isError = false;
                                    }
                                    else
                                    {
                                        this._LocalLogger.WriteLog("删除设备黑名单失败。" + rvInfoConn.messageText + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Error);
                                        rvInfoMain.isError = true;
                                    }
                                }
                                else
                                {
                                    this._LocalLogger.WriteLog("获取设备数据失败。" + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Error);
                                    rvInfoMain.isError = true;
                                }

                                #endregion
                            }
                            else
                            {
                                this._LocalLogger.WriteLog("设备无法连接。" + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Error);
                                rvInfoMain.isError = true;
                            }

                            ReturnValueInfo rvInfoDisConn = device.DisConn();
                            if (!rvInfoDisConn.boolValue || rvInfoDisConn.isError)
                            {
                                this._LocalLogger.WriteLog("设备断开失败。" + rvInfoConn.messageText + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Warning);
                            }

                            #endregion
                        }
                        else
                        {
                            this._LocalLogger.WriteLog("设备无法访问(PING)。" + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Warning);
                            rvInfoMain.isError = true;
                        }

                        //更新对应消费机的状态
                        ReturnValueInfo rvInfoState = this._IConsumeMachineBL.Save(MacInfo, Common.DefineConstantValue.EditStateEnum.OE_Update);
                        if (rvInfoState.isError)
                        {
                            this._LocalLogger.WriteLog("设备状态更新失败。" + "-" + DateTime.Now.ToString() + rvInfoState.messageText, strMacDetail, SystemLog.SystemLog.LogType.Error);
                            rvInfoMain.isError = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        this._LocalLogger.WriteLog(ex.Message + "-" + DateTime.Now.ToString(), strMacDetail, SystemLog.SystemLog.LogType.Error);
                        rvInfoMain.isError = true;
                    }
                }
                else
                {
                    this._LocalLogger.WriteLog("消费机转换实体失败。" + "-" + DateTime.Now.ToString(), string.Empty, SystemLog.SystemLog.LogType.Error);
                    rvInfoMain.isError = true;
                }
            }
            catch (Exception exMain)
            {
                this._LocalLogger.WriteLog(exMain.Message + "-" + DateTime.Now.ToString(), string.Empty, SystemLog.SystemLog.LogType.Error);
                rvInfoMain.messageText = exMain.Message;
                rvInfoMain.isError = true;
            }
            return rvInfoMain;
        }