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

namespace Edu.Repository.Log
{
    /// <summary>
    /// 用户信息改变日志仓储层
    /// </summary>
    public class RB_User_ChangeLogRepository : BaseRepository<RB_User_ChangeLog>
    {
        /// <summary>
        /// 获取用户信息改变日志列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_User_ChangeLog_ViewModel> GetUserChangeLogListRepository(RB_User_ChangeLog_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM RB_User_ChangeLog 
WHERE 1=1 
");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat($" AND {nameof(RB_User_ChangeLog_ViewModel.Group_Id)}={query.Group_Id} ");
                }
                if (query.School_Id > 0)
                {
                    builder.AppendFormat($" AND {nameof(RB_User_ChangeLog_ViewModel.School_Id)}={query.School_Id} ");
                }
                if (query.CreateBy > 0)
                {
                    builder.AppendFormat($" AND {nameof(RB_User_ChangeLog_ViewModel.CreateBy)}={query.CreateBy} ");
                }
            }
            return Get<RB_User_ChangeLog_ViewModel>(builder.ToString()).ToList();
        }
    }
}