完成基础员工界面
This commit is contained in:
parent
1d944be6eb
commit
a07d786d1d
65
src/StaffManagement/Controllers/Api/PersonController.cs
Normal file
65
src/StaffManagement/Controllers/Api/PersonController.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
16
src/StaffManagement/Controllers/Web/PersonController.cs
Normal file
16
src/StaffManagement/Controllers/Web/PersonController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
32
src/StaffManagement/Database/DbInit.cs
Normal file
32
src/StaffManagement/Database/DbInit.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using StaffManagement.Database.Tables;
|
||||
|
||||
namespace StaffManagement.Database
|
||||
{
|
||||
|
@ -12,5 +13,10 @@ namespace StaffManagement.Database
|
|||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public SMDbContext(DbContextOptions options) : base(options) { }
|
||||
|
||||
/// <summary>
|
||||
/// 员工基本信息表
|
||||
/// </summary>
|
||||
public DbSet<Person> People { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
21
src/StaffManagement/Database/StaticData/GenderDefinition.cs
Normal file
21
src/StaffManagement/Database/StaticData/GenderDefinition.cs
Normal 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,
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
55
src/StaffManagement/Database/Tables/Person.cs
Normal file
55
src/StaffManagement/Database/Tables/Person.cs
Normal 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;
|
||||
}
|
||||
}
|
7
src/StaffManagement/Models/PersonModel.cs
Normal file
7
src/StaffManagement/Models/PersonModel.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace StaffManagement.Models
|
||||
{
|
||||
public class PersonFilter
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
|
@ -21,9 +21,4 @@
|
|||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\Api\" />
|
||||
<Folder Include="Database\Tables\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -28,9 +28,9 @@ namespace StaffManagement
|
|||
//注册Json序列化
|
||||
services.AddMsJsonProvider();
|
||||
//注册数据库
|
||||
var dbStr = this.Configuration.GetValue<string>("Database:dbConnStr");
|
||||
services.AddDbContext<SMDbContext>(option => {
|
||||
//option.UseSqlServer(this.Configuration.GetValue<string>("Database:connStr"));
|
||||
option.UseMySql(this.Configuration.GetValue<string>("Database:dbConnStr"));
|
||||
option.UseMySql(dbStr);
|
||||
});
|
||||
//注册Redis
|
||||
var rop = this.Configuration.GetSection("Redis").Get<RedisCacheOptions>();
|
||||
|
@ -46,11 +46,10 @@ namespace StaffManagement
|
|||
|
||||
//注册Swagger
|
||||
services.AddSwaggerGen(c => {
|
||||
var option = this.Configuration.GetSection("SwaggerDoc");
|
||||
c.SwaggerDoc("V1",new OpenApiInfo {
|
||||
Title = option.GetValue<string>("Title"),
|
||||
Version = option.GetValue<string>("Version"),
|
||||
Description = option.GetValue<string>("Description"),
|
||||
Title = "员工管理API接口",// option.GetValue<string>("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<ApiExceptionFilterAttribute>();
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
|
64
src/StaffManagement/Views/Person/Index.cshtml
Normal file
64
src/StaffManagement/Views/Person/Index.cshtml
Normal 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>
|
|
@ -34,7 +34,7 @@
|
|||
<a class="nav-link text-dark" fajax="#main" asp-controller="Home" asp-action="Building">街道管理</a>
|
||||
</li>
|
||||
<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 class="nav-item">
|
||||
<a class="nav-link text-dark" fajax="#main" asp-controller="Home" asp-action="Building">合同管理</a>
|
||||
|
@ -63,9 +63,9 @@
|
|||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.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/vue/vue.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@RenderSection("Scripts",required: false)
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -8,19 +8,10 @@
|
|||
},
|
||||
"AllowedHosts": "*",
|
||||
"Database": {
|
||||
"dbConnStr": "Server=localhost;Port=3306;Database=FAuth;Uid=falcon;Pwd=falcon;"
|
||||
"dbConnStr": "Server=localhost;Port=3306;Database=StaffManagement;Uid=falcon;Pwd=falcon;"
|
||||
},
|
||||
"Redis": {
|
||||
"InstanceName": "",
|
||||
"Configuration": "127.0.0.1:7001,password=123654"
|
||||
},
|
||||
"SwaggerDoc": {
|
||||
"Title": "员工管理API接口",
|
||||
"Version": "1.0",
|
||||
"Description": "统一采用API接口设计,查看下面详细接口规范。",
|
||||
"Contact": {
|
||||
"Name": "技术支持(点击链接,发布工单)",
|
||||
"Url": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
||||
// Write your JavaScript code.
|
||||
//根据生日和当前时间获取年龄
|
||||
Vue.filter('getAge', function (value) {
|
||||
var now = new Date();
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user