using Edu.Model.Entity.Bonus;
using Edu.Model.ViewModel.Bonus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Edu.Repository.Bonus
{
    /// <summary>
    /// 员工人头奖励日志仓储层
    /// </summary>
    public class RB_Personnel_BonusLogRepository:BaseRepository<RB_Personnel_BonusLog>
    {
        /// <summary>
        /// 获取员工人头奖励日志分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Personnel_BonusLog_Extend> GetPersonnelBonusLogListRepository(RB_Personnel_BonusLog_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.* 
FROM RB_Personnel_BonusLog AS A
WHERE 1=1
");
            if (query != null)
            {
                if (query.BonusId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Personnel_BonusLog_Extend.BonusId), query.BonusId);
                }
                if (!string.IsNullOrEmpty(query.QBonusIds))
                {
                    builder.AppendFormat(" AND A.{0} IN({1}) ", nameof(RB_Personnel_BonusLog_Extend.BonusId), query.QBonusIds);
                }
                if (query.LogType > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Personnel_BonusLog_Extend.LogType), query.LogType);
                }
                if (query.OrderId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Personnel_BonusLog_Extend.OrderId), query.OrderId);
                }

            }
            return Get<RB_Personnel_BonusLog_Extend>( builder.ToString()).ToList();
        }

        /// <summary>
        /// 新增日志
        /// </summary>
        /// <param name="BonusId"></param>
        /// <param name="LogType"></param>
        /// <param name="OrderId"></param>
        /// <param name="LogContent"></param>
        /// <returns></returns>
        public bool AddPersonnelBonusLogRepository(int BonusId,int LogType,int OrderId,string LogContent)
        {
            var newModel = new RB_Personnel_BonusLog()
            {
                BonusId = BonusId,
                LogType = LogType,
                OrderId = OrderId,
                LogContent = LogContent,
                CreateTime=DateTime.Now,
            };
            var newId = base.Insert(newModel);
            return newId > 0;
        }
    }
}