using System;
using System.Collections.Generic;
using System.Text;
using System.IRepositories;
using System.Model;
using System.Common;
using SqlSugar;
using System.Threading.Tasks;
using System.Data;

namespace System.Repositories
{
    public class SysUser_GradeRepository : BaseRepository<T_SysUser_Grade>, ISysUser_GradeRepository
    {
        /// <summary>
        /// 获取某月员工绩效  发单总数  发单总金额   0 未发出 1未签收2签收3改代收4拒收
        /// </summary>
        /// <param name="userid">某员工</param>
        /// <param name="dtStart">时间所在月</param>
        ///  <param name="type">0团队 1部门</param>
        /// <returns></returns>
        public async Task<List<decimal>> GetALLNumber(int id, DateTime dtStart,int type)
        {
            List<decimal> intarry = new List<decimal>() { -1, -0.00M, -1, -0.00M, -1, -0.00M, -1, -0.00M, -1, -0.00M, -1, -0.00M };
            try
            {
                List<SugarParameter> sugarParameter = new List<SugarParameter>();
                sugarParameter.Add(new SugarParameter("@id", id));
                sugarParameter.Add(new SugarParameter("@F_Month", dtStart.ToString("yyyyMM")));
                string sql = "SELECT " +
                    "SUM(F_SendTotleNumber), " +
                    "SUM(F_TotleMoney), " +
                    "SUM(F_SignNumber), " +
                    "SUM(F_SignMoney), " +
                    "SUM(F_RefuseNumber), " +
                    "SUM(F_RefuseMoney), " +
                    "SUM(F_NoSignNumber), " +
                    "SUM(F_NoSignMoney), " +
                    "SUM(F_AfterNumber), " +
                    "SUM(F_AfterMoney), " +
                    "SUM(F_ErrorMoney), " +
                    "SUM(F_AlongMoney) ";
                   
                if (type == 0)
                {
                    sql += " FROM T_SysUser_Grade WHERE  F_TeamId= @id  AND  F_Month=@F_Month ";
                }
                else
                {
                    sql += " FROM T_SysUser_Grade WHERE  F_DeptId= @id  AND  F_Month=@F_Month ";
                }
                DataTable dt = await GetTableSugar(sql, sugarParameter);
                if (dt != null && dt.Rows.Count > 0)
                {
                    intarry.Clear();
                    intarry.Add(dt.Rows[0][0].ObjToInt());
                    intarry.Add(dt.Rows[0][1].ObjToDecimal());

                    intarry.Add(dt.Rows[0][2].ObjToInt());
                    intarry.Add(dt.Rows[0][3].ObjToDecimal());

                    intarry.Add(dt.Rows[0][4].ObjToInt());
                    intarry.Add(dt.Rows[0][5].ObjToDecimal());

                    intarry.Add(dt.Rows[0][6].ObjToInt());
                    intarry.Add(dt.Rows[0][7].ObjToDecimal());

                    intarry.Add(dt.Rows[0][8].ObjToInt());
                    intarry.Add(dt.Rows[0][9].ObjToDecimal());

                    intarry.Add(dt.Rows[0][10].ObjToDecimal());
                    intarry.Add(dt.Rows[0][11].ObjToDecimal());
                }
                return intarry;
            }
            catch { return intarry; }
        }       
    }

}
