using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.User;
using Mall.Model.Extend.User;
using System.Linq;

namespace Mall.Repository.User
{
    /// <summary>
    /// 小程序用户中心配置仓储层
    /// </summary>
    public class RB_MiniProgram_UserCenterMenuRepository : RepositoryBase<RB_MiniProgram_UserCenterMenu>
    {
        /// <summary>
        /// 根据查询条件获取小程序用户中心菜单列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_MiniProgram_UserCenterMenu_Extend> GetMiniProgramUserCenterMenuListRepository(RB_MiniProgram_UserCenterMenu_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" SELECT * FROM RB_MiniProgram_UserCenterMenu WHERE 1=1 ");
            if (query != null)
            {
                if (query.MallBaseId > 0)
                {
                    builder.AppendFormat(" AND MallBaseId={0} ", query.MallBaseId);
                }
                if (query.DetailIds != null && !string.IsNullOrWhiteSpace(query.DetailIds))
                {
                    builder.AppendFormat(" AND DetailId IN({0}) ", query.DetailIds);
                }
            }
            return Get<RB_MiniProgram_UserCenterMenu_Extend>(builder.ToString()).ToList();
        }

        /// <summary>
        /// 删除小程序用户中心菜单
        /// </summary>
        /// <param name="DetailIds">详情编号</param>
        /// <param name="MallBaseId">商城编号</param>
        /// <returns></returns>
        public bool DeleteMiniProgramUserCenterMenuRepository(string DetailIds = "", int MallBaseId = 0)
        {
            bool flag = true;
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("DELETE FROM RB_MiniProgram_UserCenterMenu WHERE 1=1 ");
            if (!string.IsNullOrEmpty(DetailIds) || MallBaseId > 0)
            {
                if (!string.IsNullOrEmpty(DetailIds))
                {
                    builder.AppendFormat(" AND DetailId IN({0}) ", DetailIds);
                }
                if (MallBaseId > 0)
                {
                    builder.AppendFormat(" AND MallBaseId IN({0}) ", MallBaseId);
                }
                flag = base.Execute(builder.ToString()) > 0;
            }
            return flag;
        }
    }
}
