From a07d786d1df865e2b6bf66b81149e2ae1ded5467 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Thu, 5 Nov 2020 15:13:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=9F=BA=E7=A1=80=E5=91=98?= =?UTF-8?q?=E5=B7=A5=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/PersonController.cs | 65 ++++++++++++++++++ .../Controllers/Web/PersonController.cs | 16 +++++ src/StaffManagement/Database/DbInit.cs | 32 +++++++++ src/StaffManagement/Database/SMDbContext.cs | 6 ++ .../StaticData/EducationDefinition.cs | 29 ++++++++ .../Database/StaticData/GenderDefinition.cs | 21 ++++++ .../Database/StaticData/MarriageDefinition.cs | 29 ++++++++ src/StaffManagement/Database/Tables/Person.cs | 55 +++++++++++++++ src/StaffManagement/Models/PersonModel.cs | 7 ++ src/StaffManagement/StaffManagement.csproj | 5 -- src/StaffManagement/Startup.cs | 19 +++--- src/StaffManagement/Views/Person/Index.cshtml | 64 ++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 4 +- src/StaffManagement/appsettings.json | 11 +-- src/StaffManagement/wwwroot/js/site.js | 67 +++++++++++++++++-- 15 files changed, 399 insertions(+), 31 deletions(-) create mode 100644 src/StaffManagement/Controllers/Api/PersonController.cs create mode 100644 src/StaffManagement/Controllers/Web/PersonController.cs create mode 100644 src/StaffManagement/Database/DbInit.cs create mode 100644 src/StaffManagement/Database/StaticData/EducationDefinition.cs create mode 100644 src/StaffManagement/Database/StaticData/GenderDefinition.cs create mode 100644 src/StaffManagement/Database/StaticData/MarriageDefinition.cs create mode 100644 src/StaffManagement/Database/Tables/Person.cs create mode 100644 src/StaffManagement/Models/PersonModel.cs create mode 100644 src/StaffManagement/Views/Person/Index.cshtml diff --git a/src/StaffManagement/Controllers/Api/PersonController.cs b/src/StaffManagement/Controllers/Api/PersonController.cs new file mode 100644 index 0000000..219c4a5 --- /dev/null +++ b/src/StaffManagement/Controllers/Api/PersonController.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Falcon.Extend; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using StaffManagement.Database.Tables; +using StaffManagement.Models; + +namespace StaffManagement.Controllers.Api +{ + /// + /// 员工操作接口 + /// + public class PersonController:ApiControllerBase + { + public PersonController(ILogger logger,IServiceProvider service) : base(logger,service) { + } + + /// + /// 获取员工列表 + /// + /// 员工数据列表 + [HttpGet] + [ProducesResponseType(typeof(IEnumerable),200)] + public IEnumerable GetPeople(PersonFilter filter) { + var qu = this.Db.People.AsQueryable(); + if(filter != null) { + if(filter.Name.IsNotNullOrEmpty()) { + var f = filter.Name; + qu = qu.Where(m => m.Name.Contains(f)); + } + } + return qu.ToList(); + } + /// + /// 增加新人员信息 + /// + /// 人员信息 + /// 保存后的信息 + [HttpPost] + [ProducesResponseType(typeof(Person),200)] + public Person AddNewPerson(Person p) { + this.Db.Entry(p).State = EntityState.Added; + this.Db.SaveChanges(); + return p; + } + /// + /// 删除人员信息 + /// + /// 人员编号 + /// 是否成功 + [HttpPost] + [ProducesResponseType(typeof(bool),200)] + public bool RemovePerson(int id) { + var p = new Person { Id = id }; + //this.Db.People.Attach(p); + this.Db.Entry(p).State = EntityState.Deleted; + this.Db.SaveChanges(); + return true; + } + } +} diff --git a/src/StaffManagement/Controllers/Web/PersonController.cs b/src/StaffManagement/Controllers/Web/PersonController.cs new file mode 100644 index 0000000..6ad8f6f --- /dev/null +++ b/src/StaffManagement/Controllers/Web/PersonController.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace StaffManagement.Controllers.Web +{ + public class PersonController:WebControllerBase + { + public PersonController(ILogger logger,IServiceProvider service) : base(logger,service) { + } + + public IActionResult Index() { + return PartialView(); + } + } +} diff --git a/src/StaffManagement/Database/DbInit.cs b/src/StaffManagement/Database/DbInit.cs new file mode 100644 index 0000000..77c9a92 --- /dev/null +++ b/src/StaffManagement/Database/DbInit.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; + +namespace StaffManagement.Database +{ + static public class DbInit + { + /// + /// 初始化数据库 + /// + /// + /// + public static IApplicationBuilder SMDbInit(this IApplicationBuilder app) { + app.ApplicationServices.GetService().Init(); + return app; + } + /// + /// 初始化数据库 + /// + /// 数据库上下文 + /// + public static SMDbContext Init(this SMDbContext db) { + db.Database.EnsureCreated(); + return db; + } + } +} diff --git a/src/StaffManagement/Database/SMDbContext.cs b/src/StaffManagement/Database/SMDbContext.cs index 77386eb..32b12cd 100644 --- a/src/StaffManagement/Database/SMDbContext.cs +++ b/src/StaffManagement/Database/SMDbContext.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using StaffManagement.Database.Tables; namespace StaffManagement.Database { @@ -12,5 +13,10 @@ namespace StaffManagement.Database /// /// public SMDbContext(DbContextOptions options) : base(options) { } + + /// + /// 员工基本信息表 + /// + public DbSet People { get; set; } } } diff --git a/src/StaffManagement/Database/StaticData/EducationDefinition.cs b/src/StaffManagement/Database/StaticData/EducationDefinition.cs new file mode 100644 index 0000000..89f3303 --- /dev/null +++ b/src/StaffManagement/Database/StaticData/EducationDefinition.cs @@ -0,0 +1,29 @@ +namespace StaffManagement.Database.StaticData +{ + /// + /// 性别定义 + /// + public enum EducationDefinition + { + /// + /// 未知、未提供 + /// + Unknown = 0, + /// + /// 文盲 + /// + Illiterate = 1, + /// + /// 小学 + /// + primary = 2, + /// + /// 中学 + /// + middle = 3, + /// + /// 大学 + /// + University = 4 + } +} diff --git a/src/StaffManagement/Database/StaticData/GenderDefinition.cs b/src/StaffManagement/Database/StaticData/GenderDefinition.cs new file mode 100644 index 0000000..4d813f5 --- /dev/null +++ b/src/StaffManagement/Database/StaticData/GenderDefinition.cs @@ -0,0 +1,21 @@ +namespace StaffManagement.Database.StaticData +{ + /// + /// 性别定义 + /// + public enum GenderDefinition + { + /// + /// 未知、未提供 + /// + Unknown = 0, + /// + /// 男 + /// + Male = 1, + /// + /// 女 + /// + Female = 2, + } +} diff --git a/src/StaffManagement/Database/StaticData/MarriageDefinition.cs b/src/StaffManagement/Database/StaticData/MarriageDefinition.cs new file mode 100644 index 0000000..739e786 --- /dev/null +++ b/src/StaffManagement/Database/StaticData/MarriageDefinition.cs @@ -0,0 +1,29 @@ +namespace StaffManagement.Database.StaticData +{ + /// + /// 婚姻状态 + /// + public enum MarriageDefinition + { + /// + /// 未知、未提供 + /// + Unknown = 0, + /// + /// 未婚 + /// + Unmarried = 1, + /// + /// 已婚 + /// + Married = 2, + /// + /// 离异 + /// + Divorced = 3, + /// + /// 丧偶 + /// + Widowed = 4 + } +} diff --git a/src/StaffManagement/Database/Tables/Person.cs b/src/StaffManagement/Database/Tables/Person.cs new file mode 100644 index 0000000..5bfc5c7 --- /dev/null +++ b/src/StaffManagement/Database/Tables/Person.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; +using StaffManagement.Database.StaticData; + +namespace StaffManagement.Database.Tables +{ + /// + /// 人员基本信息 + /// + [Table("Person")] + public class Person + { + [Key] + public int Id { get; set; } + /// + /// 姓名 + /// + [MaxLength(10)] + public string Name { get; set; } = null; + /// + /// 身份证号码 + /// + [MaxLength(20)] + public string CardNo { get; set; } = ""; + /// + /// 性别 + /// + public GenderDefinition Gender { get; set; } = GenderDefinition.Unknown; + /// + /// 出生日期 + /// + public DateTimeOffset Birthday { get; set; } = DateTimeOffset.MinValue; + /// + /// 电话号码 + /// + [MaxLength(200)] + public string PhoneNo { get; set; } = ""; + /// + /// 婚史 + /// + public MarriageDefinition Marriage { get; set; } = MarriageDefinition.Unknown; + /// + /// 学历 + /// + public EducationDefinition Education { get; set; } = EducationDefinition.Unknown; + /// + /// 记录状态 + /// + public int Status { get; set; } = 0; + } +} diff --git a/src/StaffManagement/Models/PersonModel.cs b/src/StaffManagement/Models/PersonModel.cs new file mode 100644 index 0000000..ded14fd --- /dev/null +++ b/src/StaffManagement/Models/PersonModel.cs @@ -0,0 +1,7 @@ +namespace StaffManagement.Models +{ + public class PersonFilter + { + public string Name { get; set; } + } +} diff --git a/src/StaffManagement/StaffManagement.csproj b/src/StaffManagement/StaffManagement.csproj index 8f8bf63..d0004e7 100644 --- a/src/StaffManagement/StaffManagement.csproj +++ b/src/StaffManagement/StaffManagement.csproj @@ -20,10 +20,5 @@ - - - - - diff --git a/src/StaffManagement/Startup.cs b/src/StaffManagement/Startup.cs index d984c2c..1829bed 100644 --- a/src/StaffManagement/Startup.cs +++ b/src/StaffManagement/Startup.cs @@ -28,9 +28,9 @@ namespace StaffManagement //עJsonл services.AddMsJsonProvider(); //עݿ + var dbStr = this.Configuration.GetValue("Database:dbConnStr"); services.AddDbContext(option => { - //option.UseSqlServer(this.Configuration.GetValue("Database:connStr")); - option.UseMySql(this.Configuration.GetValue("Database:dbConnStr")); + option.UseMySql(dbStr); }); //עRedis var rop = this.Configuration.GetSection("Redis").Get(); @@ -46,11 +46,10 @@ namespace StaffManagement //עSwagger services.AddSwaggerGen(c => { - var option = this.Configuration.GetSection("SwaggerDoc"); c.SwaggerDoc("V1",new OpenApiInfo { - Title = option.GetValue("Title"), - Version = option.GetValue("Version"), - Description = option.GetValue("Description"), + Title = "ԱAPIӿ",// option.GetValue("Title"), + Version = "1.0", + Description = "ͳһAPIӿƣ鿴ϸӿڹ淶", }); var basePath = AppContext.BaseDirectory; c.IncludeXmlComments(Path.Combine(basePath,"StaffManagement.xml"),true); @@ -60,25 +59,25 @@ namespace StaffManagement services.AddScoped(); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app,IWebHostEnvironment env) { + public void Configure(IApplicationBuilder app,IWebHostEnvironment env,SMDbContext db) { if(env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); - + db.Init(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/V1/swagger.json","ӿĵ"); - //c.RoutePrefix = ""; + c.RoutePrefix = "api"; c.DocumentTitle = "һվʽҽƾӿĵ"; c.InjectStylesheet("/css/swagger.css"); c.InjectJavascript("/lib/jquery/dist/jquery.min.js"); c.InjectJavascript("/js/swagger.js"); }); + app.UseRouting(); app.UseAuthorization(); diff --git a/src/StaffManagement/Views/Person/Index.cshtml b/src/StaffManagement/Views/Person/Index.cshtml new file mode 100644 index 0000000..2f07f77 --- /dev/null +++ b/src/StaffManagement/Views/Person/Index.cshtml @@ -0,0 +1,64 @@ +
+
+ 员工查询 +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
编号姓名身份证号码性别生日年龄电话婚史教育
{{i.Id}}{{i.Name}}{{i.CardNo}}{{i.Gender | cgGender}}{{i.Birthday | dateFormat}}{{i.Birthday | getAge}}{{i.PhoneNo}}{{i.Marriage | cgMarriage}}{{i.Education | cgEducation}}
+
+
+ + \ No newline at end of file diff --git a/src/StaffManagement/Views/Shared/_Layout.cshtml b/src/StaffManagement/Views/Shared/_Layout.cshtml index 17d5eea..3582a17 100644 --- a/src/StaffManagement/Views/Shared/_Layout.cshtml +++ b/src/StaffManagement/Views/Shared/_Layout.cshtml @@ -34,7 +34,7 @@ 街道管理