Beispiel #1
0
    /// <summary>
    /// 取个人任务
    /// </summary>
    private static void GetSelfTaskFromDB(string StaffId)
    {
        try
        {
            string    sql = "SELECT TOP " + SelfTasks.ToString() + " A.Task_Guid, A.Customer_Guid, B.ItemName FROM SDrmTasks A LEFT OUTER JOIN SDrmItems B ON A.Item_Id = B.Item_Id WHERE StartTime is null and A.Lock is null and A.Staff_Id='" + StaffId + "' and A.Finish_Id is null and (B.BeginTime <= GETDATE()) AND (B.EndTime >= GETDATE()) AND (B.TaskLocation = 0) AND (B.WorkStatusId = 0) AND (B.StatusId = 0)";
            MDataBase db  = new MDataBase(config.DBConn);
            Hashtable ht  = new Hashtable();
            if (_SelfTaskPool == null)
            {
                _SelfTaskPool = new Hashtable();
            }
            db.Open();
            DataTable dt;
            bool      blnReturnCode = db.GetDataTable(sql, out dt);
            if (blnReturnCode == true)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ht.Add(dr["Task_Guid"].ToString(), dr);
                }
            }
            db.Close();

            // 记录更新的记录
            if (_SelfTaskPool.ContainsKey(StaffId) == true)
            {
                _SelfTaskPool.Remove(StaffId);
            }
            _SelfTaskPool.Add(StaffId, ht);

            // 更新标记
            if (_SelfLastRefresh == null)
            {
                _SelfLastRefresh = new Hashtable();
            }
            if (_SelfLastRefresh.ContainsKey(StaffId) == true)
            {
                _SelfLastRefresh[StaffId] = ht.Count;
            }
            else
            {
                _SelfLastRefresh.Add(StaffId, ht.Count);
            }
        }
        catch { }
    }
Beispiel #2
0
    /// <summary>
    /// 取抢占任务
    /// 包括前期加锁未外呼的任务(即Lock=0,Finish_Id is null,LockTime为40分钟前的任务)
    /// </summary>
    /// <param name="StrategyId">单个组策略编码</param>
    private static void GetRobTaskFromDB(string StrategyId)
    {
        try
        {
            string    sql = "SELECT TOP " + RobTasks.ToString() + " A.Task_Guid, A.Customer_Guid, B.ItemName FROM SDrmTasks A LEFT OUTER JOIN SDrmItems B ON A.Item_Id = B.Item_Id WHERE A.Strategy_Id='" + StrategyId + "' and A.StartTime is null and A.Lock is null and A.Finish_Id is null and (B.BeginTime <= GETDATE()) AND (B.EndTime >= GETDATE()) AND (B.TaskLocation = 0) AND (B.WorkStatusId = 0) AND (B.StatusId = 0)";
            MDataBase db  = new MDataBase(config.DBConn);
            Hashtable ht  = new Hashtable();
            if (_RobTaskPool == null)
            {
                _RobTaskPool = new Hashtable();
            }
            db.Open();
            DataTable dt;
            bool      blnReturnCode = db.GetDataTable(sql, out dt);
            if (blnReturnCode == true)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ht.Add(dr["Task_Guid"].ToString(), dr);
                }

                // 如果抢占任务完成或快要完成,则取前期加锁未外呼的任务
                if (dt.Rows.Count < RobTasks / 2)
                {
                    //SELECT TOP 1 Task_Guid FROM SDrmTasks where " + strStrategyId + "  and Finish_Id is null and Lock=0 and LockTime<=DATEADD(mi,30,getdate()) order by StartTime
                    sql           = "SELECT TOP " + Convert.ToString(RobTasks - dt.Rows.Count) + " A.Task_Guid, A.Customer_Guid, B.ItemName FROM SDrmTasks A LEFT OUTER JOIN SDrmItems B ON A.Item_Id = B.Item_Id WHERE A.Strategy_Id='" + StrategyId + "' AND A.Finish_Id is null AND A.Lock = 0 AND A.LockTime<=DATEADD(mi,-45,getdate()) AND (B.BeginTime <= GETDATE()) AND (B.EndTime >= GETDATE()) AND (B.TaskLocation = 0) AND (B.WorkStatusId = 0) AND (B.StatusId = 0) order by A.LockTime";
                    blnReturnCode = db.GetDataTable(sql, out dt);
                    if (blnReturnCode == true)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            ht.Add(dr["Task_Guid"].ToString(), dr);
                        }
                    }
                }
            }
            db.Close();

            // 记录更新的记录
            if (_RobTaskPool.ContainsKey(StrategyId) == true)
            {
                _RobTaskPool.Remove(StrategyId);
            }
            _RobTaskPool.Add(StrategyId, ht);

            // 更新标记
            if (_RobLastRefresh == null)
            {
                _RobLastRefresh = new Hashtable();
            }
            if (_RobLastRefresh.ContainsKey(StrategyId) == true)
            {
                _RobLastRefresh[StrategyId] = ht.Count;
            }
            else
            {
                _RobLastRefresh.Add(StrategyId, ht.Count);
            }
        }
        catch { }
    }
Beispiel #3
0
    /// <summary>
    /// 取4小时内的预约任务
    /// </summary>
    private static void GetRespeakTaskFromDB()
    {
        try
        {
            DateTime  Now = DateTime.Now.AddHours(Convert.ToDouble(RespeakTime));
            string    sql = "SELECT A.Task_Guid, A.Customer_Guid, B.ItemName, A.Staff_Id, A.StartTime FROM SDrmTasks A LEFT OUTER JOIN SDrmItems B ON A.Item_Id = B.Item_Id WHERE A.StartTime is not null and A.StartTime<='" + Now.ToString("yyyy-MM-dd HH:mm:ss") + "' and A.Lock is null and A.Finish_Id is null and (B.BeginTime <= GETDATE()) AND (B.EndTime >= GETDATE()) AND (B.TaskLocation = 0) AND (B.WorkStatusId = 0) AND (B.StatusId = 0) order by A.StartTime";
            MDataBase db  = new MDataBase(config.DBConn);
            _RespeakTaskPool = new Hashtable();
            db.Open();
            DataTable dt;
            bool      blnReturnCode = db.GetDataTable(sql, out dt);
            if (blnReturnCode == true)
            {
                //foreach (DataRow dr in dt.Rows)
                //{
                //    Hashtable ht;
                //    if (_RespeakTaskPool.ContainsKey(dr["Staff_Id"].ToString()) == true)
                //    {
                //        ht = (Hashtable)_RespeakTaskPool[dr["Staff_Id"].ToString()];
                //        ht.Add(dr["StartTime"].ToString(), dr);
                //    }
                //    else
                //    {
                //        ht = new Hashtable();
                //        ht.Add(dr["StartTime"].ToString(), dr);
                //        _RespeakTaskPool.Add(dr["Staff_Id"].ToString(), ht);
                //    }
                //}

                foreach (DataRow dr in dt.Rows)
                {
                    Hashtable ht;
                    if (_RespeakTaskPool.ContainsKey(dr["Staff_Id"].ToString()) == true)
                    {
                        ht = (Hashtable)_RespeakTaskPool[dr["Staff_Id"].ToString()];
                        bool     blnOnce   = false;
                        DateTime StartTime = Convert.ToDateTime(dr["StartTime"]);
                        while (blnOnce == false)
                        {
                            if (ht.ContainsKey(StartTime) == true)
                            {
                                StartTime = StartTime.AddSeconds(1);
                            }
                            else
                            {
                                ht.Add(StartTime, dr);
                                blnOnce = true;
                            }
                        }
                    }
                    else
                    {
                        ht = new Hashtable();
                        ht.Add(dr["StartTime"].ToString(), dr);
                        _RespeakTaskPool.Add(dr["Staff_Id"].ToString(), ht);
                    }
                }
            }
            db.Close();

            _RespeakLastRefresh = DateTime.Now;
        }
        catch (Exception err)
        {
            //string tmp = err.Message;
            ErrorLog.LogInsert(err.Message, "App_Code/OBTask", "");
        }
    }
Beispiel #4
0
    /// <summary>
    /// 取外呼任务
    /// </summary>
    /// <param name="StaffId">单个职员编码</param>
    /// <param name="StrategyId">单个组策略编码</param>
    /// <returns></returns>
    public static DataTable GetOBTask(string StaffId, string StrategyId)
    {
        while (_GetTaskStatus != 0 || _GetTaskFromDBStatus != 0)
        {
            Thread.Sleep(100);
        }

        _GetTaskStatus = 1;
        DataTable dtReturn = null;
        string    sql;
        MDataBase db = new MDataBase(config.DBConn);

        db.Open();
        try
        {
            // 刷新所有外呼任务
            // 如果不需要刷新,则不刷新
            RefreshOBTask(StaffId, StrategyId);

            // 取预约任务
            if (_RespeakTaskPool.ContainsKey(StaffId) == true)
            {
                // 从_RespeakTaskPool取自已的最早的预约任务
                Hashtable ht      = (Hashtable)_RespeakTaskPool[StaffId];
                DateTime  nowTime = DateTime.Now;                       //当前时间
                DateTime  newTime = nowTime;                            //最小的预约时间
                DataRow   dr      = null;
                foreach (DictionaryEntry de in ht)
                {
                    if (Convert.ToDateTime(de.Key) < newTime)
                    {
                        // 小于最小的预约时间
                        newTime = Convert.ToDateTime(de.Key);
                        dr      = (DataRow)de.Value;
                    }
                }
                if (newTime != nowTime)
                {
                    DataTable dt;
                    dt = new DataTable();
                    DataColumn column = new DataColumn();
                    column.DataType   = typeof(string);
                    column.Caption    = "Task_Guid";
                    column.ColumnName = "Task_Guid";
                    dt.Columns.Add(column);
                    DataColumn column2 = new DataColumn();
                    column2.DataType   = typeof(string);
                    column2.Caption    = "Customer_Guid";
                    column2.ColumnName = "Customer_Guid";
                    dt.Columns.Add(column2);
                    DataColumn column3 = new DataColumn();
                    column3.DataType   = typeof(string);
                    column3.Caption    = "ItemName";
                    column3.ColumnName = "ItemName";
                    dt.Columns.Add(column3);

                    dt.ImportRow(dr);

                    dtReturn = dt;
                    sql      = "update SDrmTasks set Lock=0,LockTime=getDate(),ExecuteBy='" + StaffId + "' where Task_Guid='" + dt.Rows[0]["Task_Guid"].ToString() + "'";
                    int intCount = db.executeUpdate(sql);
                    if (intCount > 0)
                    {
                        string tmp = newTime.ToString();
                        ht.Remove(tmp);
                    }
                }
            }
            // 取个人任务
            if (dtReturn == null && _SelfTaskPool.ContainsKey(StaffId) == true)
            {
                // 从_SelfTaskPool取个人任务
                Hashtable ht = (Hashtable)_SelfTaskPool[StaffId];
                DataTable dt;
                GetOnce(db, StaffId, ht, out dt);
                dtReturn = dt;
            }
            // 取抢占任务
            if (dtReturn == null && (_RobTaskPool.ContainsKey(StrategyId) == true))
            {
                // 从_RobTaskPool取抢占任务
                Hashtable ht = (Hashtable)_RobTaskPool[StrategyId];
                DataTable dt;
                GetOnce(db, StaffId, ht, out dt);
                dtReturn = dt;
            }
        }
        catch (Exception err)
        {
            //err.Message;
        }
        db.Close();

        _GetTaskStatus = 0;
        return(dtReturn);
    }