using BPA.KitChen.GroupMeal.SqlSugar;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.GroupMeal.Application.Service.TestService
{
    [ApiDescriptionSettings("测试", Tag = "测试", SplitCamelCase = false)]
    [AllowAnonymous]
    public class TestService: IDynamicApiController, ITransient, ITestService
    {
        /// <summary>
        /// CodeFirst
        /// </summary>
        /// <param name="tableNames"></param>
        public  void CodeFirst()
        {
            try
            {
                var types = Assembly.Load("BPA.KitChen.GroupMeal.Core").GetTypes()
                    .Where(x => x.Namespace != null
                                && x.GetCustomAttribute<SugarTable>() != null
                                && x.Namespace.Contains("BPA.KitChen.GroupMeal.Core.Entity"))
                    .ToArray();
              SqlSugarDb.Db.CodeFirst.InitTables(types);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

           
        }
    }
}
