You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
898 lines
46 KiB
898 lines
46 KiB
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Serialization;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.XSSF.UserModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using TeacherExt.Entities;
|
|
using TeacherExt.Models;
|
|
|
|
namespace TeacherExt.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("[controller]/[action]")]
|
|
public class HomeController : BaseController
|
|
{
|
|
private readonly IHostEnvironment _env;
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
private readonly IConfiguration _config;
|
|
private readonly AesHelper _helper;
|
|
private readonly IRepository<DictionaryItem> _directoryRepo;
|
|
private readonly IRepository<Person> _personRepo;
|
|
private readonly IRepository<PersonLogin> _loginRepo;
|
|
private readonly IRepository<Organization> _organizationRepo;
|
|
private readonly IRepository<CheckLog> _checkLogRepo;
|
|
|
|
public HomeController(IHostEnvironment env,
|
|
ILogger<HomeController> logger,
|
|
IConfiguration config,
|
|
AesHelper helper,
|
|
IRepository<DictionaryItem> directoryRepo,
|
|
IRepository<Person> personRepo,
|
|
IRepository<Organization> organizationRepo,
|
|
IRepository<PersonLogin> loginRepo,
|
|
IRepository<CheckLog> checkLogRepo
|
|
)
|
|
{
|
|
this._env = env;
|
|
this._logger = logger;
|
|
this._config = config;
|
|
this._helper = helper;
|
|
this._directoryRepo = directoryRepo;
|
|
this._personRepo = personRepo;
|
|
this._organizationRepo = organizationRepo;
|
|
this._loginRepo = loginRepo;
|
|
this._checkLogRepo = checkLogRepo;
|
|
}
|
|
|
|
/*
|
|
* select distinct t1.person_id,t1.person_name,t1.xb_name as sex ,
|
|
t1.bureau_id,t2.org_name as bureau_name,ifnull(f_get_decrypt(t1.tel),'')
|
|
as tel , ifnull(f_get_decrypt(t1.identity_num),'') as idcard ,
|
|
ifnull(nation,1) as nation,ifnull(nationality,1) as nationality,
|
|
t1.org_id,t6.org_name,placeofbirth,t7.role_id,t1.identity_id,t1.political_status from t_base_person t1
|
|
left join t_base_organization t2 on t1.bureau_id=t2.org_id and t1.b_use=1
|
|
left join t_base_person_title t3 on t1.person_id=t3.person_id and t3.b_use=1
|
|
left join t_base_person_record t4 on t1.person_id=t4.person_id and
|
|
t4.b_use=1 and t4.record_type=1
|
|
left join t_base_person_rewards t5 on t1.person_id=t5.person_id and
|
|
t5.b_use=1 and t5.rewards_type=1
|
|
left join t_base_organization t6 on t1.org_id=t6.org_id
|
|
left join t_sys_person_role t7 on t7.b_use=1 and t7.role_id=420 and t7.identity_id=5 and t7.person_id=t1.person_id
|
|
where t1.b_use=1 and t1.district_id = 302705 order by t1.bureau_id, t1.create_time asc limit 0, 20
|
|
*/
|
|
|
|
[HttpGet]
|
|
[Route("/")]
|
|
public IActionResult Index(QueryTeacherModel model)
|
|
{
|
|
var bureau_id = this._config.GetValue<int>("bureau", 302705);
|
|
var personQuery = this.CreatePersonQuery(model)
|
|
.OrderBy(o => o.OrganId)
|
|
.ThenBy(o => o.CreateAt);
|
|
var query = from person in personQuery
|
|
join organ in this._organizationRepo.ReadOnlyTable() on person.BureauId equals organ.OrganId
|
|
join department in this._organizationRepo.ReadOnlyTable() on person.OrganId equals department.OrganId
|
|
join login in this._loginRepo.ReadOnlyTable() on person.Id equals login.PersonId
|
|
orderby person.OrganId ascending, person.CreateAt ascending
|
|
select new TeacherListItem
|
|
{
|
|
RequestEditStatus = person.RequestEditStatus,
|
|
CheckStatus = person.CheckStatus,
|
|
person_name = person.RealName,
|
|
login_name = login.LoginName,
|
|
sex = person.Sex,
|
|
nation = person.Nation,
|
|
placeofbirth = person.NativePlace,
|
|
person_id = person.Id,
|
|
org_name = organ.Name,
|
|
department_name = department.Name
|
|
};
|
|
var count = query.Count();
|
|
var list = query
|
|
.Skip(model.PageSize * (model.PageNumber - 1))
|
|
.Take(model.PageSize)
|
|
.ToList();
|
|
var nations = this.GetNation();
|
|
foreach (var item in list)
|
|
{
|
|
item.nation_name = nations.GetText(item.nation);
|
|
}
|
|
model.TotalRow = count;
|
|
model.List.AddRange(list);
|
|
if (!model.HeaderSelectList.Any())
|
|
{
|
|
model.HeaderSelectList = typeof(EditTeacherModel).GetProperties()
|
|
.Select(o => o.GetCustomAttribute<ExcelHeaderAttribute>())
|
|
.Where(o => o != null)
|
|
.Select(o => new SelectListItem
|
|
{
|
|
Value = o.Header,
|
|
Text = o.Headers.Last().Key.Replace("\r\n", ""),
|
|
Selected = Request.Method.ToLower() == "get" ? true : model.Headers.Any(h => h == o.Header)
|
|
})
|
|
.ToList();
|
|
}
|
|
var organs = this._organizationRepo.ReadOnlyTable().Where(o => o.AreaId == bureau_id && o.IsUsed).ToList();
|
|
var bureau = organs.FirstOrDefault(o => o.Name == "城中区教育局");
|
|
bureau.Children = organs.Where(o => o.Name != "城中区教育局").ToList();
|
|
model.Organs.Add(bureau);
|
|
ViewData.SelectList(o => model.RequestEditStatus, () => this.GetRequestEditStatus(model.RequestEditStatus));
|
|
ViewData.SelectList(o => model.CheckStatus, () => this.GetCheckStatus(model.CheckStatus));
|
|
return Result(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("/")]
|
|
public IActionResult Index(QueryTeacherModel model, bool isPost)
|
|
{
|
|
var result = this.Index(model);
|
|
return result;
|
|
}
|
|
|
|
private void ModelToEntity(EditTeacherModel model, Person entity)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(entity.IdNumber))
|
|
{
|
|
entity.IdNumber = this._helper.Encrypt(entity.IdNumber);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(entity.PhoneNumber))
|
|
{
|
|
entity.PhoneNumber = this._helper.Encrypt(entity.PhoneNumber);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Update(int id, string access_token)
|
|
{
|
|
var person = this._personRepo.ReadOnlyTable().Where(o => o.Id == id).FirstOrDefault();
|
|
var organ = this._organizationRepo.ReadOnlyTable().Where(o => o.Id == person.OrganId).FirstOrDefault();
|
|
var model = person.To<EditTeacherModel>();
|
|
model.OrganName = organ.Name;
|
|
this.EntityToModel(person, model);
|
|
this.ToEditModel(person, model);
|
|
model.LoginName = this._loginRepo.ReadOnlyTable().Where(o => o.PersonId == model.Id).Select(o => o.LoginName).FirstOrDefault();
|
|
if (!string.IsNullOrEmpty(access_token))
|
|
{
|
|
var httpContext = this.Request.HttpContext;
|
|
var token = access_token;
|
|
var cookieOptions = new CookieOptions
|
|
{
|
|
HttpOnly = true
|
|
};
|
|
var cookieName = httpContext.GetJwtCookieName();
|
|
httpContext.Response.Cookies.Delete(cookieName);
|
|
httpContext.Response.Cookies.Append(cookieName, token, cookieOptions);
|
|
}
|
|
return Result<EditTeacherModel>(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Update([FromForm] EditTeacherModel model)
|
|
{
|
|
var self = this.HttpContext.Request.Query.ContainsKey("self") || (this.HttpContext.Request.Method == "POST" && this.HttpContext.Request.Form.ContainsKey("self"));
|
|
ValidEditModel(model);
|
|
var entity = this._personRepo.Table().Where(o => o.Id == model.Id).FirstOrDefault();
|
|
this.ValidModelStatus(entity, model);
|
|
var login = this._loginRepo.ReadOnlyTable().Where(o => o.PersonId == model.Id).FirstOrDefault();
|
|
if (ModelState.IsValid)
|
|
{
|
|
if (entity.CheckStatus != model.CheckStatus)
|
|
{
|
|
var updateRealName = this._loginRepo.ReadOnlyTable()
|
|
.Where(o => o.LoginName == User.Identity.Name)
|
|
.Select(o => o.RealName)
|
|
.FirstOrDefault();
|
|
this._checkLogRepo.Add(new CheckLog
|
|
{
|
|
PersonId = entity.Id,
|
|
UpdateRealName = updateRealName,
|
|
UpdateBy = User.Identity.Name,
|
|
UpdateAt = DateTime.Now,
|
|
LoginName = login.LoginName,
|
|
RealName = login.RealName,
|
|
FromStatus = entity.CheckStatus,
|
|
ToStatus = model.CheckStatus
|
|
});
|
|
}
|
|
this.UpdateInternal(entity, model);
|
|
//entity.From(model);
|
|
//this.ModelToEntity(model, entity);
|
|
this._personRepo.SaveChanges();
|
|
if (this.IsJsonRequest())
|
|
{
|
|
return this.NoContent();
|
|
}
|
|
}
|
|
this.EntityToModel(entity, model);
|
|
this.ToEditModel(entity, model);
|
|
model.LoginName = login.LoginName;
|
|
return Result<EditTeacherModel>(model);
|
|
}
|
|
|
|
private void UpdateInternal(Person entity, EditTeacherModel model)
|
|
{
|
|
var self = this.HttpContext.Request.Query.ContainsKey("self") || (this.HttpContext.Request.Method == "POST" && this.HttpContext.Request.Form.ContainsKey("self"));
|
|
if (self)
|
|
{
|
|
if (entity.CheckStatus == model.CheckStatus)
|
|
{
|
|
if (model.CheckStatus == "未提交" || model.CheckStatus == "审核失败")
|
|
{
|
|
entity.From(model);
|
|
this.ModelToEntity(model, entity);
|
|
}
|
|
else
|
|
{
|
|
if (entity.RequestEditStatus != model.RequestEditStatus)
|
|
{
|
|
entity.RequestEditStatus = model.RequestEditStatus;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (entity.CheckStatus == "未提交" || entity.CheckStatus == "审核失败")
|
|
{
|
|
if (model.CheckStatus == "待审核")
|
|
{
|
|
entity.From(model);
|
|
this.ModelToEntity(model, entity);
|
|
}
|
|
}
|
|
else if (entity.CheckStatus == "待审核")
|
|
{
|
|
if (model.CheckStatus == "未提交")
|
|
{
|
|
entity.CheckStatus = model.CheckStatus;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (User.IsInRole("城中区教育局管理员"))
|
|
{
|
|
if (model.CheckStatus == "审核失败" && model.RequestEditStatus == "未申请")
|
|
{
|
|
entity.Comment = model.Comment;
|
|
entity.CheckStatus = model.CheckStatus;
|
|
entity.RequestEditStatus = model.RequestEditStatus;
|
|
entity.FromWhere(model, (s, t) => s.Name.EndsWith("Checked"));
|
|
}
|
|
}
|
|
else if (User.IsInRole("学校管理员"))
|
|
{
|
|
if (model.CheckStatus == "审核成功" || model.CheckStatus == "审核失败")
|
|
{
|
|
entity.Comment = model.Comment;
|
|
entity.CheckStatus = model.CheckStatus;
|
|
entity.RequestEditStatus = model.RequestEditStatus;
|
|
entity.FromWhere(model, (s, t) => s.Name.EndsWith("Checked"));
|
|
}
|
|
if (entity.RequestEditStatus != model.RequestEditStatus)
|
|
{
|
|
entity.CheckStatus = model.CheckStatus;
|
|
entity.RequestEditStatus = model.RequestEditStatus;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ValidModelStatus(Person entity, EditTeacherModel model)
|
|
{
|
|
var self = this.HttpContext.Request.Query.ContainsKey("self") || (this.HttpContext.Request.Method == "POST" && this.HttpContext.Request.Form.ContainsKey("self"));
|
|
if (self)
|
|
{
|
|
if (entity.CheckStatus != model.CheckStatus)
|
|
{
|
|
if (model.CheckStatus == "待审核")
|
|
{
|
|
if (entity.CheckStatus != "未提交" && entity.CheckStatus != "审核失败")
|
|
{
|
|
ModelState.AddModelError(nameof(model.CheckStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.CheckStatus}]状态");
|
|
}
|
|
}
|
|
if (model.CheckStatus == "未提交")
|
|
{
|
|
if (entity.CheckStatus != "待审核")
|
|
{
|
|
ModelState.AddModelError(nameof(model.CheckStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.CheckStatus}]状态");
|
|
}
|
|
}
|
|
}
|
|
if (entity.RequestEditStatus != model.RequestEditStatus)
|
|
{
|
|
if (entity.CheckStatus == "未提交" || entity.CheckStatus == "审核失败")
|
|
{
|
|
ModelState.AddModelError(nameof(model.RequestEditStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.RequestEditStatus}]状态");
|
|
}
|
|
}
|
|
if (model.LoginName != User.Identity.Name)
|
|
{
|
|
ModelState.AddModelError(nameof(model.RealName), $"当前用户不是[{model.RealName}]无法修改登录名其的个人信息");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (User.IsInRole("城中区教育局管理员"))
|
|
{
|
|
if (model.CheckStatus == "审核失败")
|
|
{
|
|
if (entity.CheckStatus != "审核成功")
|
|
{
|
|
ModelState.AddModelError(nameof(model.CheckStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.CheckStatus}]状态");
|
|
}
|
|
}
|
|
}
|
|
else if (User.IsInRole("学校管理员"))
|
|
{
|
|
if(model.CheckStatus=="审核成功")
|
|
{
|
|
var valid = false;
|
|
valid = valid || (entity.CheckStatus == "待审核" && model.RequestEditStatus == "未申请");
|
|
valid = valid || (entity.CheckStatus == "审核成功"&&model.CheckStatus=="审核成功"&&entity.RequestEditStatus=="已申请" && model.RequestEditStatus == "未申请");
|
|
valid = valid || (entity.CheckStatus == "审核成功" && model.CheckStatus == "未提交" && entity.RequestEditStatus == "已申请" && model.RequestEditStatus == "未申请");
|
|
if (!valid)
|
|
{
|
|
ModelState.AddModelError(nameof(model.CheckStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.CheckStatus}]状态");
|
|
}
|
|
}
|
|
else if(model.CheckStatus=="审核失败")
|
|
{
|
|
var valid = false;
|
|
valid = valid || (entity.CheckStatus == "待审核" && model.RequestEditStatus == "未申请");
|
|
if (!valid)
|
|
{
|
|
ModelState.AddModelError(nameof(model.CheckStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.CheckStatus}]状态");
|
|
}
|
|
}
|
|
if (entity.RequestEditStatus != model.RequestEditStatus)
|
|
{
|
|
if (entity.CheckStatus != "审核成功")
|
|
{
|
|
ModelState.AddModelError(nameof(model.RequestEditStatus), $"无法从[{entity.RequestEditStatus}]状态修改为[{model.RequestEditStatus}]状态");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(entity.CheckStatus!=model.CheckStatus)
|
|
{
|
|
if (model.CheckStatus == "审核成功" || model.CheckStatus == "审核失败")
|
|
{
|
|
if (entity.CheckStatus != "待审核")
|
|
{
|
|
ModelState.AddModelError(nameof(model.CheckStatus), $"无法从[{entity.CheckStatus}]状态修改为[{model.CheckStatus}]状态");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void EntityToModel(Person entity, EditTeacherModel model)
|
|
{
|
|
if (entity != null)
|
|
{
|
|
if (!string.IsNullOrEmpty(entity.PhoneNumber))
|
|
{
|
|
model.PhoneNumber = _helper.Decrypt(entity.PhoneNumber);
|
|
}
|
|
if (!string.IsNullOrEmpty(entity.IdNumber))
|
|
{
|
|
model.IdNumber = _helper.Decrypt(entity.IdNumber);
|
|
try
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(model.IdNumber))
|
|
{
|
|
if (model.IdNumber.Length == 15 || model.IdNumber.Length == 18)
|
|
{
|
|
var value = model.IdNumber.Length == 15 ? $"19{model.IdNumber.Substring(6, 6)}" : model.IdNumber.Substring(6, 8);
|
|
var birthday = DateTime.ParseExact(value, "yyyyMMdd", CultureInfo.InvariantCulture);
|
|
model.Age = DateTime.Now.Year - birthday.Year;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
}
|
|
}
|
|
if (entity.WorkingTime.HasValue)
|
|
{
|
|
model.JobAgeYear = DateTime.Now.Year - model.WorkingTime.Value.Year;
|
|
model.JobAgeMonth = model.JobAgeYear * 12 + Math.Abs((model.WorkingTime.Value.Month - DateTime.Now.Month));
|
|
}
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult History([FromQuery] QueryHistoryModel model)
|
|
{
|
|
var query = this._checkLogRepo.ReadOnlyTable()
|
|
.Where(o => o.PersonId == model.Id)
|
|
.OrderByDescending(o => o.UpdateAt);
|
|
model.TotalRow = query.Count();
|
|
var list = query.Skip(model.PageSize * (model.PageNumber - 1))
|
|
.OrderByDescending(o => o.UpdateAt)
|
|
.Take(model.PageSize)
|
|
.ToList();
|
|
model.List.AddRange(list);
|
|
return Result(model);
|
|
}
|
|
|
|
/// <summary>
|
|
/// https://github.com/nissl-lab/npoi/wiki/How-to-use-NPOI-on-Linux
|
|
/// apt-get install libgdiplus libc6-dev
|
|
/// cd /usr/lib
|
|
/// ln -s libgdiplus.so gdiplus.dll
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public FileResult Export([FromForm] QueryTeacherModel model)
|
|
{
|
|
var template = Path.Combine(this._env.ContentRootPath, "wwwroot", "teacher.xlsx");
|
|
using var fs = System.IO.File.OpenRead(template);
|
|
var wk = new XSSFWorkbook(fs);
|
|
var sheet = wk.GetSheetAt(0);
|
|
this.ExportInternal(sheet, model);
|
|
using var ms = new MemoryStream();
|
|
wk.Write(ms);
|
|
return File(ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"在编教师信息管理表_{DateTime.Now.ToString("yyyy_MM-dd_HH_mm_ss")}.xlsx");
|
|
}
|
|
|
|
private void ValidEditModel(EditTeacherModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
if (model.IsJobAsMaxTitle.HasValue)
|
|
{
|
|
if (model.IsJobAsMaxTitle.Value)
|
|
{//最高职称聘任
|
|
if (ModelState.ContainsKey(nameof(model.JobAsNotMaxTitleReason)))
|
|
{
|
|
ModelState.Remove(nameof(model.JobAsNotMaxTitleReason));
|
|
}
|
|
if (ModelState.ContainsKey(nameof(model.NotMaxTitle)))
|
|
{
|
|
ModelState.Remove(nameof(model.NotMaxTitle));
|
|
}
|
|
if (ModelState.ContainsKey(nameof(model.NotMaxTitleStart)))
|
|
{
|
|
ModelState.Remove(nameof(model.NotMaxTitleStart));
|
|
}
|
|
if (ModelState.ContainsKey(nameof(model.JobAsNotMaxTitleDate)))
|
|
{
|
|
ModelState.Remove(nameof(model.JobAsNotMaxTitleDate));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (ModelState.ContainsKey(nameof(model.JobAsMaxTitleDate)))
|
|
{
|
|
ModelState.Remove(nameof(model.JobAsMaxTitleDate));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(model.EducationGrade) && ModelState.ContainsKey(nameof(model.EducationGradeDate)))
|
|
{//不享受待遇
|
|
ModelState.Remove(nameof(model.EducationGradeDate));
|
|
}
|
|
if (model.HasPosition.HasValue)
|
|
{
|
|
if (model.HasPosition.Value)
|
|
{//在编在岗
|
|
if (ModelState.ContainsKey(nameof(model.NotOnPostReason)))
|
|
{
|
|
ModelState.Remove(nameof(model.NotOnPostReason));
|
|
}
|
|
if (ModelState.ContainsKey(nameof(model.NotOnPostReasonDate)))
|
|
{
|
|
ModelState.Remove(nameof(model.NotOnPostReasonDate));
|
|
}
|
|
if (model.IsMiddleLevel.HasValue)
|
|
{
|
|
if (model.IsMiddleLevel.Value)
|
|
{//中层
|
|
if (ModelState.ContainsKey(nameof(model.FrontTeacher)))
|
|
{
|
|
ModelState.Remove(nameof(model.FrontTeacher));
|
|
}
|
|
}
|
|
else
|
|
{//一线教师
|
|
if (ModelState.ContainsKey(nameof(model.Position)))
|
|
{
|
|
ModelState.Remove(nameof(model.Position));
|
|
}
|
|
if (ModelState.ContainsKey(nameof(model.PositionStart)))
|
|
{
|
|
ModelState.Remove(nameof(model.PositionStart));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{//在编不在岗
|
|
if (ModelState.ContainsKey(nameof(model.Position)))
|
|
{
|
|
ModelState.Remove(nameof(model.Position));
|
|
}
|
|
if (ModelState.ContainsKey(nameof(model.PositionStart)))
|
|
{
|
|
ModelState.Remove(nameof(model.PositionStart));
|
|
}
|
|
if (ModelState.ContainsKey(nameof(model.FrontTeacher)))
|
|
{
|
|
ModelState.Remove(nameof(model.FrontTeacher));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ToEditModel(Person entity, EditTeacherModel model)
|
|
{
|
|
// value is int
|
|
ViewData.SelectList(o => model.Sex, () => this.GetSex(model.Sex));
|
|
ViewData.SelectList(o => model.Position, () => this.GetPosition(model.Position));
|
|
//
|
|
ViewData.SelectList(o => model.Nation, () => this.GetNation(model.Nation));
|
|
ViewData.SelectList(o => model.Politics, () => this.GetPolitics(model.Politics));
|
|
ViewData.SelectList(o => model.MaxTitle, () => this.GetTitle(model.MaxTitle));
|
|
ViewData.SelectList(o => model.NotMaxTitle, () => this.GetTitle(model.MaxTitle));
|
|
ViewData.SelectList(o => model.Nationality, () => this.GetNationality(model.Nationality));
|
|
ViewData.SelectList(o => model.UserType, () => this.GetUserType(model.UserType));
|
|
ViewData.SelectList(o => model.PostType, () => this.GetPostType(model.PostType));
|
|
ViewData.SelectList(o => model.MaritalStatus, () => this.GetMaritalStatus(model.MaritalStatus));
|
|
ViewData.SelectList(o => model.MaxDegree, () => this.GetDegree(model.MaxDegree));
|
|
ViewData.SelectList(o => model.FirstEducation, () => this.GetEducation(model.FirstEducation));
|
|
ViewData.SelectList(o => model.MaxEducation, () => this.GetEducation(model.MaxEducation));
|
|
ViewData.SelectList(o => model.FullTimeSchoolEducation, () => this.GetEducation(model.FullTimeSchoolEducation));
|
|
ViewData.SelectList(o => model.JobTimeSchoolEducation, () => this.GetEducation(model.JobTimeSchoolEducation));
|
|
//
|
|
ViewData.SelectList(o => model.PostGrade, () => this.GetPostGrade(model.PostGrade));
|
|
ViewData.SelectList(o => model.MainTeachPeriod, () => this.GetTeachPeriod(model.MainTeachPeriod));
|
|
ViewData.SelectList(o => model.MainTeachSubject, () => this.GetTeachSubject(model.MainTeachSubject));
|
|
ViewData.SelectList(o => model.OtherTeachPeriod, () => this.GetTeachPeriod(model.OtherTeachPeriod));
|
|
ViewData.SelectList(o => model.OtherTeachSubject, () => this.GetTeachSubject(model.OtherTeachSubject));
|
|
//
|
|
ViewData.SelectList(o => model.RequestEditStatus, () => this.GetRequestEditStatus(model.RequestEditStatus));
|
|
ViewData.SelectList(o => model.CheckStatus, () => this.GetCheckStatus(model.CheckStatus));
|
|
ViewData.SelectList(o => model.EducationGrade, () => this.GetEducationGrade(model.EducationGrade));
|
|
ViewData.SelectList(o => model.FullTimeSchoolType, () => this.GetFullTimeSchoolType(model.FullTimeSchoolType));
|
|
ViewData.SelectList(o => model.JobTimeSchoolType, () => this.GetFullTimeSchoolType(model.JobTimeSchoolType));
|
|
ViewData.SelectList(o => model.MainTeachGrade, () => this.GetTeachGrade(model.MainTeachGrade));
|
|
ViewData.SelectList(o => model.FrontTeacher, () => this.GetFrontTeacher(model.FrontTeacher));
|
|
ViewData.SelectList(o => model.NotOnPostReason, () => this.GetNotOnPostReason(model.NotOnPostReason));
|
|
ViewData.SelectList(o => model.TeacherCardType, () => this.GetTeacherCardType(model.TeacherCardType));
|
|
ViewData.SelectList(o => model.TeacherCardLangLevel, () => this.GetLangLevel(model.TeacherCardLangLevel));
|
|
ViewData.SelectList(o => model.CurrentAddressArea, () => this.GetAddressArea(model.CurrentAddressArea));
|
|
}
|
|
|
|
private void ExportInternal(ISheet sheet, QueryTeacherModel model)
|
|
{
|
|
var personQuery = this.CreatePersonQuery(model);
|
|
var organQuery = this._organizationRepo.ReadOnlyTable();
|
|
var query = from person in personQuery
|
|
join organ in organQuery on person.OrganId equals organ.OrganId
|
|
orderby person.AreaId, person.CreateAt
|
|
select new { organ.Name, person = person };
|
|
//
|
|
var nations = this.GetNation();
|
|
var titles = this.GetTitle();
|
|
var politics = this.GetPolitics();
|
|
var postTypes = this.GetPostType();
|
|
var degrees = this.GetDegree();
|
|
var educations = this.GetEducation();
|
|
var positions = this.GetPosition();
|
|
//
|
|
|
|
var style = NPOIHelper.CreateStyle(sheet, fontName: "宋体", fontSize: 11);
|
|
|
|
var headers = NPOIHelper.CreateHader(sheet, typeof(EditTeacherModel), model.Headers);
|
|
var list = query
|
|
.ToList()
|
|
.Select(o =>
|
|
{
|
|
var model = o.person.To<EditTeacherModel>();
|
|
this.EntityToModel(o.person, model);
|
|
model.OrganName = o.Name;
|
|
return model;
|
|
})
|
|
.ToList();
|
|
var rowIndex = 0;
|
|
var colIndex = -1;
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
var teacher = list[i];
|
|
var rowNumber = i + 1;
|
|
rowIndex = i + 4;
|
|
colIndex = -1;
|
|
var row = sheet.CreateRow(rowIndex);
|
|
teacher.DisplayOrder = rowNumber;
|
|
|
|
row.Export("A", headers, () => teacher.DisplayOrder)?.SetCell(++colIndex, style, teacher.DisplayOrder);
|
|
row.Export("B", headers, () => teacher.OrganName)?.SetCell(++colIndex, style, teacher.OrganName);
|
|
row.Export("C", headers, () => teacher.RealName)?.SetCell(++colIndex, style, teacher.RealName);
|
|
row.Export("D", headers, () => teacher.Sex)?.SetCell(++colIndex, style, teacher.Sex);
|
|
row.Export("E", headers, () => teacher.Birthday)?.SetCell(++colIndex, style, teacher.Birthday);
|
|
row.Export("F", headers, () => teacher.Age)?.SetCell(++colIndex, style, teacher.Age);
|
|
row.Export("G", headers, () => teacher.Nation)?.SetCell(++colIndex, style, nations.GetText(teacher.Nation));
|
|
row.Export("H", headers, () => teacher.NativePlace)?.SetCell(++colIndex, style, teacher.NativePlace);
|
|
row.Export("I", headers, () => teacher.PhoneNumber)?.SetCell(++colIndex, style, teacher.PhoneNumber);
|
|
row.Export("J", headers, () => teacher.IdNumber)?.SetCell(++colIndex, style, teacher.IdNumber);
|
|
row.Export("K", headers, () => teacher.WorkingTime)?.SetCell(++colIndex, style, teacher.WorkingTime);
|
|
row.Export("L", headers, () => teacher.TeachDate)?.SetCell(++colIndex, style, teacher.TeachDate.HasValue);
|
|
row.Export("M", headers, () => teacher.CurrentJobStart)?.SetCell(++colIndex, style, teacher.CurrentJobStart);
|
|
row.Export("N", headers, () => teacher.JobAgeYear)?.SetCell(++colIndex, style, teacher.JobAgeYear, teacher.WorkingTime.HasValue);
|
|
row.Export("O", headers, () => teacher.JobAgeMonth)?.SetCell(++colIndex, style, teacher.JobAgeMonth, teacher.WorkingTime.HasValue);
|
|
row.Export("P", headers, () => teacher.Politics)?.SetCell(++colIndex, style, politics.GetText(teacher.Politics));
|
|
row.Export("Q", headers, () => teacher.JoinPartyDate)?.SetCell(++colIndex, style, teacher.JoinPartyDate);
|
|
row.Export("R", headers, () => teacher.MaxTitle)?.SetCell(++colIndex, style, titles.GetText(teacher.MaxTitle));
|
|
row.Export("S", headers, () => teacher.MaxTitleStart)?.SetCell(++colIndex, style, teacher.MaxTitleStart);
|
|
row.Export("T", headers, () => teacher.JobAsMaxTitleDate)?.SetCell(++colIndex, style, teacher.JobAsMaxTitleDate, teacher.IsJobAsMaxTitle.HasValue && teacher.IsJobAsMaxTitle.Value);
|
|
row.Export("U", headers, () => teacher.JobAsNotMaxTitleReason)?.SetCell(++colIndex, style, teacher.JobAsNotMaxTitleReason, teacher.IsJobAsMaxTitle.HasValue && !teacher.IsJobAsMaxTitle.Value);
|
|
row.Export("V", headers, () => teacher.NotMaxTitle)?.SetCell(++colIndex, style, titles.GetText(teacher.NotMaxTitle), teacher.IsJobAsMaxTitle.HasValue && !teacher.IsJobAsMaxTitle.Value);
|
|
row.Export("W", headers, () => teacher.NotMaxTitleStart)?.SetCell(++colIndex, style, teacher.NotMaxTitleStart, teacher.IsJobAsMaxTitle.HasValue && !teacher.IsJobAsMaxTitle.Value);
|
|
row.Export("X", headers, () => teacher.JobAsNotMaxTitleDate)?.SetCell(++colIndex, style, teacher.JobAsNotMaxTitleDate, teacher.IsJobAsMaxTitle.HasValue && !teacher.IsJobAsMaxTitle.Value);
|
|
row.Export("Y", headers, () => teacher.PostType)?.SetCell(++colIndex, style, postTypes.GetText(teacher.PostType));
|
|
row.Export("Z", headers, () => teacher.PostGrade)?.SetCell(++colIndex, style, teacher.PostGrade);
|
|
|
|
row.Export("AA", headers, () => teacher.CurrentPostGradeStart)?.SetCell(++colIndex, style, teacher.CurrentPostGradeStart);
|
|
row.Export("AB", headers, () => teacher.EducationGrade)?.SetCell(++colIndex, style, educations.GetText(teacher.EducationGrade));
|
|
row.Export("AC", headers, () => teacher.EducationGradeDate)?.SetCell(++colIndex, style, teacher.EducationGradeDate, !string.IsNullOrEmpty(teacher.EducationGrade));
|
|
row.Export("AD", headers, () => teacher.FullTimeSchool)?.SetCell(++colIndex, style, teacher.FullTimeSchool);
|
|
row.Export("AE", headers, () => teacher.FullTimeSchoolType)?.SetCell(++colIndex, style, teacher.FullTimeSchoolType);
|
|
row.Export("AF", headers, () => teacher.FullTimeSchoolMajor)?.SetCell(++colIndex, style, teacher.FullTimeSchoolMajor);
|
|
row.Export("AG", headers, () => teacher.FullTimeSchoolEducation)?.SetCell(++colIndex, style, teacher.FullTimeSchoolEducation);
|
|
row.Export("AH", headers, () => teacher.FullTimeSchoolEducationDate)?.SetCell(++colIndex, style, teacher.FullTimeSchoolEducationDate);
|
|
row.Export("AI", headers, () => teacher.JobTimeSchool)?.SetCell(++colIndex, style, teacher.JobTimeSchool);
|
|
row.Export("AJ", headers, () => teacher.JobTimeSchoolType)?.SetCell(++colIndex, style, teacher.JobTimeSchoolType);
|
|
row.Export("AK", headers, () => teacher.JobTimeSchoolMajor)?.SetCell(++colIndex, style, teacher.JobTimeSchoolMajor);
|
|
row.Export("AL", headers, () => teacher.JobTimeSchoolEducation)?.SetCell(++colIndex, style, educations.GetText(teacher.JobTimeSchoolEducation));
|
|
row.Export("AM", headers, () => teacher.JobTimeSchoolEducationDate)?.SetCell(++colIndex, style, teacher.JobTimeSchoolEducationDate);
|
|
row.Export("AN", headers, () => teacher.MaxEducation)?.SetCell(++colIndex, style, educations.GetText(teacher.MaxEducation));
|
|
row.Export("AO", headers, () => teacher.MaxDegree)?.SetCell(++colIndex, style, degrees.GetText(teacher.MaxDegree));
|
|
row.Export("AP", headers, () => teacher.IsClassTeacher)?.SetCell(++colIndex, style, teacher.IsClassTeacher ? "是" : "否");
|
|
row.Export("AQ", headers, () => teacher.MainTeachPeriod)?.SetCell(++colIndex, style, teacher.MainTeachPeriod);
|
|
row.Export("AR", headers, () => teacher.MainTeachSubject)?.SetCell(++colIndex, style, teacher.MainTeachSubject);
|
|
row.Export("AS", headers, () => teacher.MainTeachGrade)?.SetCell(++colIndex, style, teacher.MainTeachGrade);
|
|
row.Export("AT", headers, () => teacher.OtherTeachPeriod)?.SetCell(++colIndex, style, teacher.OtherTeachPeriod);
|
|
row.Export("AU", headers, () => teacher.OtherTeachSubject)?.SetCell(++colIndex, style, teacher.OtherTeachSubject);
|
|
row.Export("AV", headers, () => teacher.Position)?.SetCell(++colIndex, style, positions.GetText(teacher.Position), teacher.HasPosition.HasValue && teacher.HasPosition.Value && teacher.IsMiddleLevel.HasValue && teacher.IsMiddleLevel.Value);
|
|
row.Export("AW", headers, () => teacher.PositionStart)?.SetCell(++colIndex, style, teacher.PositionStart, teacher.HasPosition.HasValue && teacher.HasPosition.Value && teacher.IsMiddleLevel.HasValue && teacher.IsMiddleLevel.Value);
|
|
row.Export("AX", headers, () => teacher.FrontTeacher)?.SetCell(++colIndex, style, teacher.FrontTeacher, teacher.HasPosition.HasValue && teacher.HasPosition.Value && teacher.IsMiddleLevel.HasValue && !teacher.IsMiddleLevel.Value);
|
|
row.Export("AY", headers, () => teacher.NotOnPostReason)?.SetCell(++colIndex, style, teacher.NotOnPostReason, teacher.HasPosition.HasValue && !teacher.HasPosition.Value);
|
|
row.Export("AZ", headers, () => teacher.NotOnPostReasonDate)?.SetCell(++colIndex, style, teacher.NotOnPostReasonDate, teacher.HasPosition.HasValue && !teacher.HasPosition.Value);
|
|
|
|
row.Export("BA", headers, () => teacher.TeacherCardType)?.SetCell(++colIndex, style, teacher.TeacherCardType);
|
|
row.Export("BB", headers, () => teacher.TeacherCardSubject)?.SetCell(++colIndex, style, teacher.TeacherCardSubject);
|
|
row.Export("BC", headers, () => teacher.TeacherCardLangLevel)?.SetCell(++colIndex, style, teacher.TeacherCardLangLevel);
|
|
row.Export("BD", headers, () => teacher.CurrentAddressArea)?.SetCell(++colIndex, style, teacher.CurrentAddressArea);
|
|
row.Export("BE", headers, () => teacher.AddressDetails)?.SetCell(++colIndex, style, teacher.AddressDetails);
|
|
row.Export("BF", headers, () => teacher.Comment)?.SetCell(++colIndex, style, "");
|
|
}
|
|
NPOIHelper.SetColWidth(3, sheet);
|
|
}
|
|
|
|
private IQueryable<Person> CreatePersonQuery(QueryTeacherModel model)
|
|
{
|
|
var bureau_id = this._config.GetValue<int>("bureau", 302705);
|
|
if (!model.bureau_id.HasValue)
|
|
{
|
|
if (User.IsInRole("城中区教育局管理员"))
|
|
{
|
|
model.bureau_id = bureau_id;
|
|
}
|
|
else
|
|
{
|
|
model.bureau_id = Convert.ToInt32(User.Claims.Where(o => o.Type == "OrganId").Select(o => o.Value).FirstOrDefault());
|
|
}
|
|
}
|
|
var name = model.person_name?.Trim();
|
|
var personQuery = this._personRepo.ReadOnlyTable()
|
|
.Where(o => o.IsUsed)
|
|
.Where(o => o.AreaId == bureau_id);
|
|
if (model.bureau_id.Value != bureau_id)
|
|
{
|
|
personQuery = personQuery.Where(o => o.BureauId == model.bureau_id);
|
|
}
|
|
|
|
if (!User.IsInRole("城中区教育局管理员") && !User.IsInRole("学校管理员"))
|
|
{
|
|
var personId = Convert.ToInt32(User.Claims.Where(o => o.Type == "PersonId").Select(o => o.Value).FirstOrDefault());
|
|
personQuery = personQuery.Where(o => o.Id == personId);
|
|
}
|
|
personQuery = personQuery
|
|
.WhereIf(!string.IsNullOrEmpty(name), o => o.RealName.Contains(name))
|
|
.WhereIf(!string.IsNullOrEmpty(model.RequestEditStatus), o => o.RequestEditStatus == model.RequestEditStatus)
|
|
.WhereIf(!string.IsNullOrEmpty(model.CheckStatus), o => o.CheckStatus == model.CheckStatus);
|
|
return personQuery;
|
|
}
|
|
|
|
private SelectList GetRequestEditStatus(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("RequestEditStatus", selected);
|
|
}
|
|
|
|
private SelectList GetCheckStatus(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("CheckStatus", selected);
|
|
}
|
|
|
|
private SelectList GetUserType(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("PERSON_STATUS", selected);
|
|
}
|
|
|
|
private SelectList GetSex(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("SEX2", selected);
|
|
}
|
|
|
|
private SelectList GetNation(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("ETHNIC_GROUP", selected);
|
|
}
|
|
|
|
private SelectList GetPolitics(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("POLITICALSTATUS", selected);
|
|
}
|
|
|
|
private SelectList GetTitle(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("PROFESSIONAL_TITLE", selected);
|
|
}
|
|
|
|
private SelectList GetNationality(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("NATIONALITY", selected);
|
|
}
|
|
|
|
private SelectList GetPostType(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("POST_CATEGORY", selected);
|
|
}
|
|
|
|
private SelectList GetMaritalStatus(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("MARITAL_STATUS", selected);
|
|
}
|
|
|
|
private SelectList GetPostGrade(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("POSTGRADE2", selected);
|
|
}
|
|
|
|
private SelectList GetEducationGrade(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("EducationGrade", selected);
|
|
}
|
|
|
|
private SelectList GetFullTimeSchoolType(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("SchoolType", selected);
|
|
}
|
|
|
|
private SelectList GetEducation(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("Education", selected);
|
|
}
|
|
|
|
private SelectList GetDegree(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("DEGREE", selected);
|
|
}
|
|
|
|
private SelectList GetTeachPeriod(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("TeachPeriod", selected);
|
|
}
|
|
|
|
private SelectList GetTeachSubject(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("ZYSY_MNSJ_XK2", selected);
|
|
}
|
|
|
|
private SelectList GetTeachGrade(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("TeachGrade", selected);
|
|
}
|
|
|
|
private SelectList GetPosition(object selected = null)
|
|
{
|
|
return this.GetSelectListFromDirectory("ADMINISTRATIVE_POST", selected);
|
|
}
|
|
|
|
private SelectList GetFrontTeacher(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("NoramlPost2", selected);
|
|
}
|
|
|
|
private SelectList GetNotOnPostReason(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("NotOnPostReason", selected);
|
|
}
|
|
|
|
private SelectList GetTeacherCardType(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("TeacherCardType", selected);
|
|
}
|
|
|
|
private SelectList GetLangLevel(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("LangLevel", selected);
|
|
}
|
|
|
|
private SelectList GetAddressArea(string selected)
|
|
{
|
|
return this.GetSelectListFromDirectory("AddressArea", selected);
|
|
}
|
|
|
|
private SelectList GetSelectListFromDirectory(string category, object selected)
|
|
{
|
|
var list = this._directoryRepo.ReadOnlyTable()
|
|
.Where(o => o.IsUsed)
|
|
.Where(o => o.Category == category)
|
|
.OrderBy(o => o.Order)
|
|
.Select(o => new SelectListItem { Text = o.Remark, Value = o.Code })
|
|
.ToList();
|
|
return new SelectList(list, nameof(SelectListItem.Value), nameof(SelectListItem.Text), selected);
|
|
}
|
|
|
|
private List<DictionaryItem> GetItems(string category)
|
|
{
|
|
return this._directoryRepo.ReadOnlyTable()
|
|
.Where(o => o.IsUsed)
|
|
.Where(o => o.Category == category)
|
|
.ToList();
|
|
}
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
protected IActionResult Success()
|
|
{
|
|
if (this.IsJsonRequest())
|
|
{
|
|
return this.NoContent();
|
|
}
|
|
return RedirectTo();
|
|
}
|
|
|
|
private IActionResult Result<T>(T model)
|
|
{
|
|
if (this.IsJsonRequest())
|
|
{
|
|
return Json(new
|
|
{
|
|
schema = this.GetJsonSchema<T>(),
|
|
model,
|
|
errors = ModelState.Where(o => o.Value.ValidationState == ModelValidationState.Invalid),
|
|
data = ViewData
|
|
}, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
|
}
|
|
return View(model);
|
|
}
|
|
}
|
|
} |