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

namespace Edu.Repository.User
{
    /// <summary>
    /// 部门岗位关联表仓储层
    /// </summary>
    public class RB_Department_PostRepository : BaseRepository<RB_Department_Post>
    {
        /// <summary>
        /// 获取部门管理岗位列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Department_Post_ViewModel> GetDepartmentPostListRepository(RB_Department_Post_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*,IFNULL(B.PostName,'') AS PostName
FROM rb_department_post AS A LEFT JOIN rb_post AS B ON A.PostId=B.PostId
WHERE 1=1 
");
            if (query == null)
            {
                return new List<RB_Department_Post_ViewModel>();
            }
            else
            {
                if (query.Dept_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Department_Post_ViewModel.Dept_Id), query.Dept_Id);
                }
                if (!string.IsNullOrEmpty(query.QDeptIds))
                {
                    builder.AppendFormat(" AND {0} IN ({1}) ", nameof(RB_Department_Post_ViewModel.Dept_Id), query.QDeptIds);
                }
            }
            return Get<RB_Department_Post_ViewModel>(builder.ToString()).ToList();
        }
    }
}
