From 59a42ae48f9bb7bd04a2360a290daa726603c27f Mon Sep 17 00:00:00 2001
From: "454313500@qq.com" <454313500@qq.com>
Date: Sat, 20 Mar 2021 14:12:24 +0800
Subject: [PATCH] v1.0.0
---
CC.Yi.API/CC.Yi.API.csproj | 22 +++++
.../Controllers/WeatherForecastController.cs | 47 ++++++++++
.../Migrations/20210319112041_yi1.Designer.cs | 40 ++++++++
CC.Yi.API/Migrations/20210319112041_yi1.cs | 29 ++++++
.../Migrations/DataContextModelSnapshot.cs | 38 ++++++++
CC.Yi.API/Program.cs | 26 +++++
CC.Yi.API/Properties/launchSettings.json | 31 ++++++
CC.Yi.API/Startup.cs | 74 +++++++++++++++
CC.Yi.API/WeatherForecast.cs | 15 +++
CC.Yi.API/appsettings.Development.json | 9 ++
CC.Yi.API/appsettings.json | 12 +++
CC.Yi.BLL/BaseBll.cs | 87 +++++++++++++++++
CC.Yi.BLL/CC.Yi.BLL.csproj | 32 +++++++
CC.Yi.BLL/T4BLL.cs | 19 ++++
CC.Yi.BLL/T4BLL.tt | 37 ++++++++
CC.Yi.Common/CC.Yi.Common.csproj | 11 +++
CC.Yi.Common/JsonFactory.cs | 12 +++
CC.Yi.DAL/BaseDal.cs | 86 +++++++++++++++++
CC.Yi.DAL/CC.Yi.DAL.csproj | 31 ++++++
CC.Yi.DAL/DbContentFactory.cs | 50 ++++++++++
CC.Yi.DAL/T4DAL.cs | 15 +++
CC.Yi.DAL/T4DAL.tt | 33 +++++++
CC.Yi.DALFactory/CC.Yi.DALFactory.csproj | 40 ++++++++
CC.Yi.DALFactory/DbSession.cs | 21 +++++
CC.Yi.DALFactory/DbSessionFactory.cs | 35 +++++++
CC.Yi.DALFactory/StaticDalFactory.cs | 24 +++++
CC.Yi.DALFactory/T4DbSession.cs | 18 ++++
CC.Yi.DALFactory/T4DbSession.tt | 36 +++++++
CC.Yi.DALFactory/T4StaticDalFactory.cs | 25 +++++
CC.Yi.DALFactory/T4StaticDalFactory.tt | 43 +++++++++
CC.Yi.IBLL/CC.Yi.IBLL.csproj | 31 ++++++
CC.Yi.IBLL/IBaseBll.cs | 29 ++++++
CC.Yi.IBLL/T4IBLL.cs | 11 +++
CC.Yi.IBLL/T4IBLL.tt | 29 ++++++
CC.Yi.IDAL/CC.Yi.IDAL.csproj | 31 ++++++
CC.Yi.IDAL/IBaseDal.cs | 50 ++++++++++
CC.Yi.IDAL/IDbSession.cs | 18 ++++
CC.Yi.IDAL/T4IDAL.cs | 11 +++
CC.Yi.IDAL/T4IDAL.tt | 29 ++++++
CC.Yi.Model/CC.Yi.Model.csproj | 42 +++++++++
CC.Yi.Model/DataContext.cs | 13 +++
CC.Yi.Model/T4DataContext.cs | 12 +++
CC.Yi.Model/T4DataContext.tt | 30 ++++++
CC.Yi.Model/student.cs | 16 ++++
CC.Yi.ViewModel/CC.Yi.ViewModel.csproj | 8 ++
CC.Yi.ViewModel/Program.cs | 12 +++
CC.Yi.sln | 94 +++++++++++++++++++
T4Model/T4Model.txt | 1 +
48 files changed, 1465 insertions(+)
create mode 100644 CC.Yi.API/CC.Yi.API.csproj
create mode 100644 CC.Yi.API/Controllers/WeatherForecastController.cs
create mode 100644 CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs
create mode 100644 CC.Yi.API/Migrations/20210319112041_yi1.cs
create mode 100644 CC.Yi.API/Migrations/DataContextModelSnapshot.cs
create mode 100644 CC.Yi.API/Program.cs
create mode 100644 CC.Yi.API/Properties/launchSettings.json
create mode 100644 CC.Yi.API/Startup.cs
create mode 100644 CC.Yi.API/WeatherForecast.cs
create mode 100644 CC.Yi.API/appsettings.Development.json
create mode 100644 CC.Yi.API/appsettings.json
create mode 100644 CC.Yi.BLL/BaseBll.cs
create mode 100644 CC.Yi.BLL/CC.Yi.BLL.csproj
create mode 100644 CC.Yi.BLL/T4BLL.cs
create mode 100644 CC.Yi.BLL/T4BLL.tt
create mode 100644 CC.Yi.Common/CC.Yi.Common.csproj
create mode 100644 CC.Yi.Common/JsonFactory.cs
create mode 100644 CC.Yi.DAL/BaseDal.cs
create mode 100644 CC.Yi.DAL/CC.Yi.DAL.csproj
create mode 100644 CC.Yi.DAL/DbContentFactory.cs
create mode 100644 CC.Yi.DAL/T4DAL.cs
create mode 100644 CC.Yi.DAL/T4DAL.tt
create mode 100644 CC.Yi.DALFactory/CC.Yi.DALFactory.csproj
create mode 100644 CC.Yi.DALFactory/DbSession.cs
create mode 100644 CC.Yi.DALFactory/DbSessionFactory.cs
create mode 100644 CC.Yi.DALFactory/StaticDalFactory.cs
create mode 100644 CC.Yi.DALFactory/T4DbSession.cs
create mode 100644 CC.Yi.DALFactory/T4DbSession.tt
create mode 100644 CC.Yi.DALFactory/T4StaticDalFactory.cs
create mode 100644 CC.Yi.DALFactory/T4StaticDalFactory.tt
create mode 100644 CC.Yi.IBLL/CC.Yi.IBLL.csproj
create mode 100644 CC.Yi.IBLL/IBaseBll.cs
create mode 100644 CC.Yi.IBLL/T4IBLL.cs
create mode 100644 CC.Yi.IBLL/T4IBLL.tt
create mode 100644 CC.Yi.IDAL/CC.Yi.IDAL.csproj
create mode 100644 CC.Yi.IDAL/IBaseDal.cs
create mode 100644 CC.Yi.IDAL/IDbSession.cs
create mode 100644 CC.Yi.IDAL/T4IDAL.cs
create mode 100644 CC.Yi.IDAL/T4IDAL.tt
create mode 100644 CC.Yi.Model/CC.Yi.Model.csproj
create mode 100644 CC.Yi.Model/DataContext.cs
create mode 100644 CC.Yi.Model/T4DataContext.cs
create mode 100644 CC.Yi.Model/T4DataContext.tt
create mode 100644 CC.Yi.Model/student.cs
create mode 100644 CC.Yi.ViewModel/CC.Yi.ViewModel.csproj
create mode 100644 CC.Yi.ViewModel/Program.cs
create mode 100644 CC.Yi.sln
create mode 100644 T4Model/T4Model.txt
diff --git a/CC.Yi.API/CC.Yi.API.csproj b/CC.Yi.API/CC.Yi.API.csproj
new file mode 100644
index 00000000..4e2559a2
--- /dev/null
+++ b/CC.Yi.API/CC.Yi.API.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net5.0
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CC.Yi.API/Controllers/WeatherForecastController.cs b/CC.Yi.API/Controllers/WeatherForecastController.cs
new file mode 100644
index 00000000..6ba2ecff
--- /dev/null
+++ b/CC.Yi.API/Controllers/WeatherForecastController.cs
@@ -0,0 +1,47 @@
+using CC.Yi.IBLL;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace CC.Yi.API.Controllers
+{
+ [ApiController]
+ [Route("[controller]/[action]")]
+ public class WeatherForecastController : ControllerBase
+ {
+ private static readonly string[] Summaries = new[]
+ {
+ "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+ };
+
+ private readonly ILogger _logger;
+ private IstudentBll _studentBll;
+ public WeatherForecastController(ILogger logger, IstudentBll studentBll)
+ {
+ _studentBll = studentBll;
+ _logger = logger;
+ }
+
+ [HttpGet]
+ public IEnumerable Get()
+ {
+ var rng = new Random();
+ return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+ {
+ Date = DateTime.Now.AddDays(index),
+ TemperatureC = rng.Next(-20, 55),
+ Summary = Summaries[rng.Next(Summaries.Length)]
+ })
+ .ToArray();
+ }
+ [HttpGet]
+ public IActionResult Test()
+ {
+ var data= _studentBll.GetEntities(n => n.id >= 0).ToList();
+ return Content(Common.JsonFactory.JsonToString(data));
+ }
+ }
+}
diff --git a/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs b/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs
new file mode 100644
index 00000000..fa669c28
--- /dev/null
+++ b/CC.Yi.API/Migrations/20210319112041_yi1.Designer.cs
@@ -0,0 +1,40 @@
+//
+using CC.Yi.Model;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+namespace CC.Yi.API.Migrations
+{
+ [DbContext(typeof(DataContext))]
+ [Migration("20210319112041_yi1")]
+ partial class yi1
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("ProductVersion", "5.0.4")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("CC.Yi.Model.student", b =>
+ {
+ b.Property("id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("name")
+ .HasColumnType("int");
+
+ b.HasKey("id");
+
+ b.ToTable("student");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CC.Yi.API/Migrations/20210319112041_yi1.cs b/CC.Yi.API/Migrations/20210319112041_yi1.cs
new file mode 100644
index 00000000..03299091
--- /dev/null
+++ b/CC.Yi.API/Migrations/20210319112041_yi1.cs
@@ -0,0 +1,29 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace CC.Yi.API.Migrations
+{
+ public partial class yi1 : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "student",
+ columns: table => new
+ {
+ id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ name = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_student", x => x.id);
+ });
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "student");
+ }
+ }
+}
diff --git a/CC.Yi.API/Migrations/DataContextModelSnapshot.cs b/CC.Yi.API/Migrations/DataContextModelSnapshot.cs
new file mode 100644
index 00000000..d2ae13a7
--- /dev/null
+++ b/CC.Yi.API/Migrations/DataContextModelSnapshot.cs
@@ -0,0 +1,38 @@
+//
+using CC.Yi.Model;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+namespace CC.Yi.API.Migrations
+{
+ [DbContext(typeof(DataContext))]
+ partial class DataContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("ProductVersion", "5.0.4")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("CC.Yi.Model.student", b =>
+ {
+ b.Property("id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("name")
+ .HasColumnType("int");
+
+ b.HasKey("id");
+
+ b.ToTable("student");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CC.Yi.API/Program.cs b/CC.Yi.API/Program.cs
new file mode 100644
index 00000000..5457af7a
--- /dev/null
+++ b/CC.Yi.API/Program.cs
@@ -0,0 +1,26 @@
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace CC.Yi.API
+{
+ public class Program
+ {
+ public static void Main(string[] args)
+ {
+ CreateHostBuilder(args).Build().Run();
+ }
+
+ public static IHostBuilder CreateHostBuilder(string[] args) =>
+ Host.CreateDefaultBuilder(args)
+ .ConfigureWebHostDefaults(webBuilder =>
+ {
+ webBuilder.UseStartup();
+ });
+ }
+}
diff --git a/CC.Yi.API/Properties/launchSettings.json b/CC.Yi.API/Properties/launchSettings.json
new file mode 100644
index 00000000..9942be97
--- /dev/null
+++ b/CC.Yi.API/Properties/launchSettings.json
@@ -0,0 +1,31 @@
+{
+ "$schema": "http://json.schemastore.org/launchsettings.json",
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:55197",
+ "sslPort": 44334
+ }
+ },
+ "profiles": {
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "CC.Yi.API": {
+ "commandName": "Project",
+ "dotnetRunMessages": "true",
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "applicationUrl": "https://localhost:5001;http://localhost:5000",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/CC.Yi.API/Startup.cs b/CC.Yi.API/Startup.cs
new file mode 100644
index 00000000..fe9446c4
--- /dev/null
+++ b/CC.Yi.API/Startup.cs
@@ -0,0 +1,74 @@
+
+using CC.Yi.BLL;
+using CC.Yi.DAL;
+using CC.Yi.IBLL;
+using CC.Yi.IDAL;
+using CC.Yi.Model;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.HttpsPolicy;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using Microsoft.OpenApi.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace CC.Yi.API
+{
+ public partial class Startup
+ {
+ public Startup(IConfiguration configuration)
+ {
+ Configuration = configuration;
+ }
+
+ public IConfiguration Configuration { get; }
+
+ // This method gets called by the runtime. Use this method to add services to the container.
+ public void ConfigureServices(IServiceCollection services)
+ {
+
+ services.AddControllers();
+ services.AddSwaggerGen(c =>
+ {
+ c.SwaggerDoc("v1", new OpenApiInfo { Title = "CC.Yi.API", Version = "v1" });
+ });
+ string connection = Configuration["ConnectionStringBySQL"];
+ string connection2 = Configuration["ConnectionStringByMySQL"];
+ services.AddDbContext(options =>
+ {
+ options.UseSqlServer(connection, b => b.MigrationsAssembly("CC.Yi.API"));//ݿ
+ });
+ services.AddScoped(typeof(IBaseDal<>), typeof(BaseDal<>));
+ services.AddScoped(typeof(IstudentBll), typeof(studentBll));
+ }
+
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+ if (env.IsDevelopment())
+ {
+ app.UseDeveloperExceptionPage();
+ app.UseSwagger();
+ app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CC.Yi.API v1"));
+ }
+
+ app.UseHttpsRedirection();
+
+ app.UseRouting();
+
+ app.UseAuthorization();
+
+ app.UseEndpoints(endpoints =>
+ {
+ endpoints.MapControllers();
+ });
+ }
+ }
+}
diff --git a/CC.Yi.API/WeatherForecast.cs b/CC.Yi.API/WeatherForecast.cs
new file mode 100644
index 00000000..9a3c14cf
--- /dev/null
+++ b/CC.Yi.API/WeatherForecast.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace CC.Yi.API
+{
+ public class WeatherForecast
+ {
+ public DateTime Date { get; set; }
+
+ public int TemperatureC { get; set; }
+
+ public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+ public string Summary { get; set; }
+ }
+}
diff --git a/CC.Yi.API/appsettings.Development.json b/CC.Yi.API/appsettings.Development.json
new file mode 100644
index 00000000..8983e0fc
--- /dev/null
+++ b/CC.Yi.API/appsettings.Development.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ }
+}
diff --git a/CC.Yi.API/appsettings.json b/CC.Yi.API/appsettings.json
new file mode 100644
index 00000000..8fcd04df
--- /dev/null
+++ b/CC.Yi.API/appsettings.json
@@ -0,0 +1,12 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ },
+ "AllowedHosts": "*",
+ "ConnectionStringBySQL": "server=.;Database=cctest;UId=sa;PWD=Qz52013142020.",
+ "ConnectionStringByMySQL": "Data Source=49.235.212.122;Database=GraduationProject;User ID=root;Password=Qz52013142020.;pooling=true;port=3306;sslmode=none;CharSet=utf8;"
+}
diff --git a/CC.Yi.BLL/BaseBll.cs b/CC.Yi.BLL/BaseBll.cs
new file mode 100644
index 00000000..6ebbd6f4
--- /dev/null
+++ b/CC.Yi.BLL/BaseBll.cs
@@ -0,0 +1,87 @@
+using CC.Yi.DALFactory;
+using CC.Yi.IBLL;
+using CC.Yi.IDAL;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+
+namespace CC.Yi.BLL
+{
+ public class BaseBll : IBaseBll where T : class, new()
+ {
+ public IBaseDal CurrentDal;
+ public BaseBll(IBaseDal cd)
+ {
+ CurrentDal = cd;
+ }
+ //public abstract void SetCurrentDal();
+ //public BaseBll()//基类的构造方法
+ //{
+ // SetCurrentDal();//该方法由子类去实现
+ //}
+
+ public IQueryable GetEntities(Expression> whereLambda)
+ {
+ return CurrentDal.GetEntities(whereLambda);
+ }
+
+ public int GetCount(Expression> whereLambda) //统计数量
+ {
+ return CurrentDal.GetCount(whereLambda);
+ }
+
+ public IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda) //分组
+ {
+ return CurrentDal.GetGroup(whereLambda, groupByLambda);
+
+ }
+
+
+ public IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc)
+ {
+ return CurrentDal.GetPageEntities(pageSize, pageIndex, out total, whereLambda, orderByLambda, isAsc);
+ }
+
+ public T Add(T entity)
+ {
+ CurrentDal.Add(entity);
+ DbSession.SaveChanges();
+ return entity;
+ }
+
+ public bool Update(T entity)
+ {
+ CurrentDal.Update(entity);
+ return DbSession.SaveChanges() > 0;
+ }
+
+ public bool Delete(T entity)
+ {
+ CurrentDal.Delete(entity);
+ return DbSession.SaveChanges() > 0;
+ }
+ public IDbSession DbSession
+ {
+ get
+ {
+ return DbSessionFactory.GetCurrentDbSession();
+ }
+ }
+ public bool Delete(int id)
+ {
+ CurrentDal.Detete(id);
+ return DbSession.SaveChanges() > 0;
+ }
+
+ public int DeleteList(List ids)
+ {
+ foreach (var id in ids)
+ {
+ CurrentDal.Detete(id);
+ }
+ return DbSession.SaveChanges();//这里把SaveChanges方法提到了循环体外,自然就与数据库交互一次
+ }
+
+ }
+}
diff --git a/CC.Yi.BLL/CC.Yi.BLL.csproj b/CC.Yi.BLL/CC.Yi.BLL.csproj
new file mode 100644
index 00000000..ce6c0299
--- /dev/null
+++ b/CC.Yi.BLL/CC.Yi.BLL.csproj
@@ -0,0 +1,32 @@
+
+
+
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
+
+ TextTemplatingFileGenerator
+ T4BLL.cs
+
+
+
+
+
+
+
+
+
+ True
+ True
+ T4BLL.tt
+
+
+
+
diff --git a/CC.Yi.BLL/T4BLL.cs b/CC.Yi.BLL/T4BLL.cs
new file mode 100644
index 00000000..da68edd2
--- /dev/null
+++ b/CC.Yi.BLL/T4BLL.cs
@@ -0,0 +1,19 @@
+
+using CC.Yi.IBLL;
+using CC.Yi.IDAL;
+using CC.Yi.Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace CC.Yi.BLL
+{
+ public partial class studentBll : BaseBll, IstudentBll
+ {
+ public studentBll(IBaseDal cd):base(cd)
+ {
+ CurrentDal = cd;
+ }
+ }
+}
\ No newline at end of file
diff --git a/CC.Yi.BLL/T4BLL.tt b/CC.Yi.BLL/T4BLL.tt
new file mode 100644
index 00000000..dcda0135
--- /dev/null
+++ b/CC.Yi.BLL/T4BLL.tt
@@ -0,0 +1,37 @@
+<#@ template debug="false" hostspecific="true" language="C#" #>
+<#@ assembly name="System.Core" #>
+<#@ import namespace="System.Linq" #>
+<#@ import namespace="System.Text" #>
+<#@ import namespace="System.Collections.Generic" #>
+<#@ import namespace="System.IO" #>
+<#@ output extension=".cs" #>
+<#
+ string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
+ string txt;
+ StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
+ txt=sr.ReadToEnd();
+ sr.Close();
+ string[] ModelData= txt.Split(',');
+ #>
+
+using CC.Yi.IBLL;
+using CC.Yi.IDAL;
+using CC.Yi.Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace CC.Yi.BLL
+{
+<# foreach(string k in ModelData){
+ #>
+ public partial class <#=k #>Bll : BaseBll<<#=k #>>, I<#=k #>Bll
+ {
+ public <#=k #>Bll(IBaseDal<<#=k #>> cd):base(cd)
+ {
+ CurrentDal = cd;
+ }
+ }
+<# } #>
+}
\ No newline at end of file
diff --git a/CC.Yi.Common/CC.Yi.Common.csproj b/CC.Yi.Common/CC.Yi.Common.csproj
new file mode 100644
index 00000000..a20524d3
--- /dev/null
+++ b/CC.Yi.Common/CC.Yi.Common.csproj
@@ -0,0 +1,11 @@
+
+
+
+ netcoreapp3.1
+
+
+
+
+
+
+
diff --git a/CC.Yi.Common/JsonFactory.cs b/CC.Yi.Common/JsonFactory.cs
new file mode 100644
index 00000000..f51b56c4
--- /dev/null
+++ b/CC.Yi.Common/JsonFactory.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace CC.Yi.Common
+{
+ public static class JsonFactory
+ {
+ public static string JsonToString(object q)
+ {
+ return Newtonsoft.Json.JsonConvert.SerializeObject(q);
+ }
+ }
+}
diff --git a/CC.Yi.DAL/BaseDal.cs b/CC.Yi.DAL/BaseDal.cs
new file mode 100644
index 00000000..fc85f109
--- /dev/null
+++ b/CC.Yi.DAL/BaseDal.cs
@@ -0,0 +1,86 @@
+using CC.Yi.IDAL;
+using CC.Yi.Model;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Linq;
+using System.Linq.Expressions;
+
+namespace CC.Yi.DAL
+{
+ public class BaseDal : IBaseDal where T : class, new()
+ {
+ public DataContext Db;
+ public BaseDal(DataContext _Db)
+ {
+ Db = _Db;
+ }
+ public IQueryable GetEntities(Expression> whereLambda)
+ {
+ return Db.Set().Where(whereLambda).AsQueryable();
+ }
+
+ public int GetCount(Expression> whereLambda) //统计数量
+ {
+ return Db.Set().Where(whereLambda).Count();
+ }
+
+ public IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda) //分组
+ {
+ return Db.Set().Where(whereLambda).GroupBy(groupByLambda).AsQueryable();
+
+ }
+
+
+
+ public IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc)
+ {
+ total = Db.Set().Where(whereLambda).Count();
+ if (isAsc)
+ {
+ var pageData = Db.Set().Where(whereLambda)
+ .OrderBy(orderByLambda)
+ .Skip(pageSize * (pageIndex - 1))
+ .Take(pageSize).AsQueryable();
+ return pageData;
+ }
+ else
+ {
+ var pageData = Db.Set().Where(whereLambda)
+ .OrderByDescending(orderByLambda)
+ .Skip(pageSize * (pageIndex - 1))
+ .Take(pageSize).AsQueryable();
+ return pageData;
+ }
+ }
+
+ public T Add(T entity)
+ {
+ Db.Set().Add(entity);
+ //Db.SaveChanges();
+ return entity;
+ }
+
+ public bool Update(T entity)
+ {
+ //所有字段均修改
+ Db.Entry(entity).State = EntityState.Modified;
+ //return Db.SaveChanges() > 0;
+ return true;
+ }
+
+
+ public bool Delete(T entity)
+ {
+ Db.Entry(entity).State = EntityState.Deleted;
+ //return Db.SaveChanges() > 0;
+ return true;
+ }
+ public bool Detete(int id)
+ {
+ var entity = Db.Set().Find(id);//根据id找到实体
+ Db.Set().Remove(entity);//由于这里先Find找到了实体,所以这里可以用Remove标记该实体要移除(删除)。如果不是先Find到实体就需要用System.Data.Entity.EntityState.Deleted
+ return true;
+ }
+
+ }
+}
diff --git a/CC.Yi.DAL/CC.Yi.DAL.csproj b/CC.Yi.DAL/CC.Yi.DAL.csproj
new file mode 100644
index 00000000..ac766382
--- /dev/null
+++ b/CC.Yi.DAL/CC.Yi.DAL.csproj
@@ -0,0 +1,31 @@
+
+
+
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
+ TextTemplatingFileGenerator
+ T4DAL.cs
+
+
+
+
+
+
+
+
+
+ True
+ True
+ T4DAL.tt
+
+
+
+
diff --git a/CC.Yi.DAL/DbContentFactory.cs b/CC.Yi.DAL/DbContentFactory.cs
new file mode 100644
index 00000000..a89b3cb8
--- /dev/null
+++ b/CC.Yi.DAL/DbContentFactory.cs
@@ -0,0 +1,50 @@
+using CC.Yi.Model;
+using Microsoft.EntityFrameworkCore;
+using System.Collections.Concurrent;
+using System.Threading;
+
+
+namespace CC.Yi.DAL
+{
+ public class DbContentFactory
+ {
+ private static DataContext Webcontext;
+
+ public DbContentFactory(DataContext webContext)
+ {
+ Webcontext = webContext;
+ }
+
+ //public static void Initialize(DataContext webContext)
+ //{
+ // Webcontext = webContext;
+ //}
+ public static DataContext GetCurrentDbContent()
+ {
+ ////return new DataModelContainer();
+ ////一次请求共用一个上下文实例
+ ////每一次http请求都会开启一个新的线程,保证在一个线程中,DbContext是唯一的
+ ////CallContext:是线程内部唯一的数据槽(一块内存空间/容器),相当于一个键值对数据容器,通过key获取value了,需要引入System.Runtime.Remoting.Messaging;命名空间
+ //DbContext db = CallContext.GetData("DbContext") as DbContext;
+ ////从 CallContext 中检索具有指定key“DbContext”的对象,并强转为DbContext
+ //if (db == null)//线程在数据槽里面没有此上下文
+ //{
+ // db = Webcontext;
+ // CallContext.SetData("DbContext", db);//放到数据槽中去,DbContext是key,db是value
+ //}
+ //return db;
+ return Webcontext;
+ }
+
+ //private static class CallContext
+ //{
+ // static ConcurrentDictionary> state = new ConcurrentDictionary>();
+
+ // public static void SetData(string name, object data) =>
+ // state.GetOrAdd(name, _ => new AsyncLocal