完成基础员工界面

This commit is contained in:
falcon 2020-11-05 15:13:59 +08:00
parent 1d944be6eb
commit a07d786d1d
15 changed files with 399 additions and 31 deletions

View File

@ -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
{
/// <summary>
/// 员工操作接口
/// </summary>
public class PersonController:ApiControllerBase<PersonController>
{
public PersonController(ILogger<PersonController> logger,IServiceProvider service) : base(logger,service) {
}
/// <summary>
/// 获取员工列表
/// </summary>
/// <returns>员工数据列表</returns>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<Person>),200)]
public IEnumerable<Person> 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();
}
/// <summary>
/// 增加新人员信息
/// </summary>
/// <param name="p">人员信息</param>
/// <returns>保存后的信息</returns>
[HttpPost]
[ProducesResponseType(typeof(Person),200)]
public Person AddNewPerson(Person p) {
this.Db.Entry(p).State = EntityState.Added;
this.Db.SaveChanges();
return p;
}
/// <summary>
/// 删除人员信息
/// </summary>
/// <param name="id">人员编号</param>
/// <returns>是否成功</returns>
[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;
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace StaffManagement.Controllers.Web
{
public class PersonController:WebControllerBase<PersonController>
{
public PersonController(ILogger<PersonController> logger,IServiceProvider service) : base(logger,service) {
}
public IActionResult Index() {
return PartialView();
}
}
}

View File

@ -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
{
/// <summary>
/// 初始化数据库
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public static IApplicationBuilder SMDbInit(this IApplicationBuilder app) {
app.ApplicationServices.GetService<SMDbContext>().Init();
return app;
}
/// <summary>
/// 初始化数据库
/// </summary>
/// <param name="db">数据库上下文</param>
/// <returns></returns>
public static SMDbContext Init(this SMDbContext db) {
db.Database.EnsureCreated();
return db;
}
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StaffManagement.Database.Tables;
namespace StaffManagement.Database namespace StaffManagement.Database
{ {
@ -12,5 +13,10 @@ namespace StaffManagement.Database
/// </summary> /// </summary>
/// <param name="options"></param> /// <param name="options"></param>
public SMDbContext(DbContextOptions options) : base(options) { } public SMDbContext(DbContextOptions options) : base(options) { }
/// <summary>
/// 员工基本信息表
/// </summary>
public DbSet<Person> People { get; set; }
} }
} }

View File

@ -0,0 +1,29 @@
namespace StaffManagement.Database.StaticData
{
/// <summary>
/// 性别定义
/// </summary>
public enum EducationDefinition
{
/// <summary>
/// 未知、未提供
/// </summary>
Unknown = 0,
/// <summary>
/// 文盲
/// </summary>
Illiterate = 1,
/// <summary>
/// 小学
/// </summary>
primary = 2,
/// <summary>
/// 中学
/// </summary>
middle = 3,
/// <summary>
/// 大学
/// </summary>
University = 4
}
}

View File

@ -0,0 +1,21 @@
namespace StaffManagement.Database.StaticData
{
/// <summary>
/// 性别定义
/// </summary>
public enum GenderDefinition
{
/// <summary>
/// 未知、未提供
/// </summary>
Unknown = 0,
/// <summary>
/// 男
/// </summary>
Male = 1,
/// <summary>
/// 女
/// </summary>
Female = 2,
}
}

View File

@ -0,0 +1,29 @@
namespace StaffManagement.Database.StaticData
{
/// <summary>
/// 婚姻状态
/// </summary>
public enum MarriageDefinition
{
/// <summary>
/// 未知、未提供
/// </summary>
Unknown = 0,
/// <summary>
/// 未婚
/// </summary>
Unmarried = 1,
/// <summary>
/// 已婚
/// </summary>
Married = 2,
/// <summary>
/// 离异
/// </summary>
Divorced = 3,
/// <summary>
/// 丧偶
/// </summary>
Widowed = 4
}
}

View File

@ -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
{
/// <summary>
/// 人员基本信息
/// </summary>
[Table("Person")]
public class Person
{
[Key]
public int Id { get; set; }
/// <summary>
/// 姓名
/// </summary>
[MaxLength(10)]
public string Name { get; set; } = null;
/// <summary>
/// 身份证号码
/// </summary>
[MaxLength(20)]
public string CardNo { get; set; } = "";
/// <summary>
/// 性别
/// </summary>
public GenderDefinition Gender { get; set; } = GenderDefinition.Unknown;
/// <summary>
/// 出生日期
/// </summary>
public DateTimeOffset Birthday { get; set; } = DateTimeOffset.MinValue;
/// <summary>
/// 电话号码
/// </summary>
[MaxLength(200)]
public string PhoneNo { get; set; } = "";
/// <summary>
/// 婚史
/// </summary>
public MarriageDefinition Marriage { get; set; } = MarriageDefinition.Unknown;
/// <summary>
/// 学历
/// </summary>
public EducationDefinition Education { get; set; } = EducationDefinition.Unknown;
/// <summary>
/// 记录状态
/// </summary>
public int Status { get; set; } = 0;
}
}

View File

@ -0,0 +1,7 @@
namespace StaffManagement.Models
{
public class PersonFilter
{
public string Name { get; set; }
}
}

View File

@ -20,10 +20,5 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.5" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.5" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Controllers\Api\" />
<Folder Include="Database\Tables\" />
</ItemGroup>
</Project> </Project>

View File

@ -28,9 +28,9 @@ namespace StaffManagement
//注册Json序列化 //注册Json序列化
services.AddMsJsonProvider(); services.AddMsJsonProvider();
//注册数据库 //注册数据库
var dbStr = this.Configuration.GetValue<string>("Database:dbConnStr");
services.AddDbContext<SMDbContext>(option => { services.AddDbContext<SMDbContext>(option => {
//option.UseSqlServer(this.Configuration.GetValue<string>("Database:connStr")); option.UseMySql(dbStr);
option.UseMySql(this.Configuration.GetValue<string>("Database:dbConnStr"));
}); });
//注册Redis //注册Redis
var rop = this.Configuration.GetSection("Redis").Get<RedisCacheOptions>(); var rop = this.Configuration.GetSection("Redis").Get<RedisCacheOptions>();
@ -46,11 +46,10 @@ namespace StaffManagement
//注册Swagger //注册Swagger
services.AddSwaggerGen(c => { services.AddSwaggerGen(c => {
var option = this.Configuration.GetSection("SwaggerDoc");
c.SwaggerDoc("V1",new OpenApiInfo { c.SwaggerDoc("V1",new OpenApiInfo {
Title = option.GetValue<string>("Title"), Title = "员工管理API接口",// option.GetValue<string>("Title"),
Version = option.GetValue<string>("Version"), Version = "1.0",
Description = option.GetValue<string>("Description"), Description = "统一采用API接口设计查看下面详细接口规范。",
}); });
var basePath = AppContext.BaseDirectory; var basePath = AppContext.BaseDirectory;
c.IncludeXmlComments(Path.Combine(basePath,"StaffManagement.xml"),true); c.IncludeXmlComments(Path.Combine(basePath,"StaffManagement.xml"),true);
@ -60,25 +59,25 @@ namespace StaffManagement
services.AddScoped<ApiExceptionFilterAttribute>(); services.AddScoped<ApiExceptionFilterAttribute>();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app,IWebHostEnvironment env,SMDbContext db) {
public void Configure(IApplicationBuilder app,IWebHostEnvironment env) {
if(env.IsDevelopment()) { if(env.IsDevelopment()) {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} else { } else {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
} }
app.UseStaticFiles(); app.UseStaticFiles();
db.Init();
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => { app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/V1/swagger.json","接口文档"); c.SwaggerEndpoint("/swagger/V1/swagger.json","接口文档");
//c.RoutePrefix = ""; c.RoutePrefix = "api";
c.DocumentTitle = "一站式医疗救助接口文档"; c.DocumentTitle = "一站式医疗救助接口文档";
c.InjectStylesheet("/css/swagger.css"); c.InjectStylesheet("/css/swagger.css");
c.InjectJavascript("/lib/jquery/dist/jquery.min.js"); c.InjectJavascript("/lib/jquery/dist/jquery.min.js");
c.InjectJavascript("/js/swagger.js"); c.InjectJavascript("/js/swagger.js");
}); });
app.UseRouting(); app.UseRouting();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -0,0 +1,64 @@
<div id="vuefrom">
<fieldset>
<legend>员工查询</legend>
<form fajax="#list">
<label>姓名<input type="text" id="name" v-model="filter.Name" /></label>
<button type="button" v-on:click="search">查询</button>
</form>
</fieldset>
<div id="list" v-if="list.length > 0">
<table class="table">
<thead>
<tr>
<td>编号</td>
<td>姓名</td>
<td>身份证号码</td>
<td>性别</td>
<td>生日</td>
<td>年龄</td>
<td>电话</td>
<td>婚史</td>
<td>教育</td>
</tr>
</thead>
<tbody>
<tr v-for="i in list">
<td>{{i.Id}}</td>
<td>{{i.Name}}</td>
<td>{{i.CardNo}}</td>
<td>{{i.Gender | cgGender}}</td>
<td>{{i.Birthday | dateFormat}}</td>
<td>{{i.Birthday | getAge}}</td>
<td>{{i.PhoneNo}}</td>
<td>{{i.Marriage | cgMarriage}}</td>
<td>{{i.Education | cgEducation}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#vuefrom",
data: {
filter: {
Name: "",
},
list: {
}
},
created() {
},
methods: {
search() {
$.getJSON("/api/Person/GetPeople", vm.filter, function (d) {
vm.list = d;
});
}
},
computed: {
}
});
</script>

View File

@ -34,7 +34,7 @@
<a class="nav-link text-dark" fajax="#main" asp-controller="Home" asp-action="Building">街道管理</a> <a class="nav-link text-dark" fajax="#main" asp-controller="Home" asp-action="Building">街道管理</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" fajax="#main" asp-controller="Home" asp-action="Building">员工管理</a> <a class="nav-link text-dark" fajax="#main" asp-controller="Person" asp-action="Index">员工管理</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" fajax="#main" asp-controller="Home" asp-action="Building">合同管理</a> <a class="nav-link text-dark" fajax="#main" asp-controller="Home" asp-action="Building">合同管理</a>
@ -63,9 +63,9 @@
</footer> </footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script> <script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/lib/jquery.unobtrusive-ajax/jquery.unobtrusive-ajax.min.js"></script> <script src="~/lib/jquery.unobtrusive-ajax/jquery.unobtrusive-ajax.min.js"></script>
<script src="~/lib/vue/vue.min.js"></script> <script src="~/lib/vue/vue.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@RenderSection("Scripts",required: false) @RenderSection("Scripts",required: false)
</body> </body>
</html> </html>

View File

@ -8,19 +8,10 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"Database": { "Database": {
"dbConnStr": "Server=localhost;Port=3306;Database=FAuth;Uid=falcon;Pwd=falcon;" "dbConnStr": "Server=localhost;Port=3306;Database=StaffManagement;Uid=falcon;Pwd=falcon;"
}, },
"Redis": { "Redis": {
"InstanceName": "", "InstanceName": "",
"Configuration": "127.0.0.1:7001,password=123654" "Configuration": "127.0.0.1:7001,password=123654"
},
"SwaggerDoc": {
"Title": "员工管理API接口",
"Version": "1.0",
"Description": "统一采用API接口设计查看下面详细接口规范。",
"Contact": {
"Name": "技术支持(点击链接,发布工单)",
"Url": ""
}
} }
} }

View File

@ -1,4 +1,63 @@
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification //根据生日和当前时间获取年龄
// for details on configuring this project to bundle and minify static web assets. Vue.filter('getAge', function (value) {
var now = new Date();
// Write your JavaScript code. var nowYear = now.getFullYear();
var bd = new Date(value);
var by = bd.getFullYear();
return nowYear - by;
});
//生成时间年月日格式
Vue.filter('dateFormat', function (value) {
var bd = new Date(value);
var by = bd.getFullYear();
var bm = bd.getMonth();
var bd = bd.getDay();
return by + "年" + bm + "月" + bd + "日";
});
//转换婚姻代码为文字
Vue.filter('cgMarriage', function (value) {
switch (value) {
case 0:
return "未知、未提供";
case 1:
return "未婚";
case 2:
return "已婚";
case 3:
return "离异";
case 4:
return "丧偶";
default:
return value;
}
});
//转换性别代码为文字
Vue.filter('cgGender', function (value) {
switch (value) {
case 0:
return "未知、未提供";
case 1:
return "男";
case 2:
return "女";
default:
return value;
}
});
//转换学历代码到文字
Vue.filter('cgEducation', function (value) {
switch (value) {
case 0:
return "未知、未提供";
case 1:
return "文盲";
case 2:
return "女小学";
case 3:
return "中学";
case 4:
return "大学";
default:
return value;
}
});