using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; namespace asg_form.Controllers { public class FileDB { public string proj_name { get; set; } public string proj_no { get; set; } public string budget_use { get; set; } public string budget_name { get; set; } public string biz_type { get; set; } public int budget_id { get; set; } public string start_time { get; set; } public decimal budget_money { get; set; } public string start_person { get; set; } public string now_auth_person { get; set; } public int now_auth_person_id { get; set; } public string id { get; set; } public string description { get; set; } public string reason { get; set; } public string supplementary_info { get; set; } public string status { get; set; } } public class FileFront { public string projName { get; set; } public string projNo { get; set; } public string budgetUse { get; set; } public string budgetName { get; set; } public string bizType { get; set; } public int budgetId { get; set; } public string startTime { get; set; } public decimal budgetMoney { get; set; } public string startPerson { get; set; } public string nowAuthPerson { get; set; } public int nowAuthPersonId { get; set; } public string Id { get; set; } public string description { get; set; } public string reason { get; set; } public string supplementaryInfo { get; set; } public string status { get; set; } } public class auditAndFilingController : ControllerBase { private readonly RoleManager roleManager; private readonly UserManager userManager; public auditAndFilingController( RoleManager roleManager, UserManager userManager) { this.roleManager = roleManager; this.userManager = userManager; } /// /// 新增/修改审批 /// /// /// [Route("api/v1/admin/AuditPost")] [HttpPost] [Authorize] public async Task> auditPost([FromBody] FileFront auditinfo) { if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) { return Ok(new error_mb { code = 401, message = "无权访问" }); } using (TestDbContext sub = new TestDbContext()) { var query = sub.T_Audit.AsQueryable(); if (query.Any(n => n.id == auditinfo.Id)) { var au = query.FirstOrDefault(n => n.id == auditinfo.Id); au.proj_no = auditinfo.projNo; au.proj_name = auditinfo.projName; au.budget_use = auditinfo.budgetUse; au.status = auditinfo.status; au.budget_name = auditinfo.budgetName; au.biz_type = auditinfo.bizType; au.budget_id = auditinfo.budgetId; au.start_time = auditinfo.startTime; au.budget_money = auditinfo.budgetMoney; au.now_auth_person = auditinfo.nowAuthPerson; au.now_auth_person_id = auditinfo.nowAuthPersonId; au.supplementary_info = auditinfo.supplementaryInfo; au.description = auditinfo.description; au.reason = auditinfo.reason; sub.SaveChanges(); return Ok(new { code = 200, message = "成功修改" }); } else { var newAudit = new FileDB { id = auditinfo.Id, proj_no = auditinfo.projNo, proj_name = auditinfo.projName, budget_use = auditinfo.budgetUse, status = auditinfo.status, budget_name = auditinfo.budgetName, biz_type = auditinfo.bizType, budget_id = auditinfo.budgetId, start_time = auditinfo.startTime, budget_money = auditinfo.budgetMoney, now_auth_person = auditinfo.nowAuthPerson, now_auth_person_id = auditinfo.nowAuthPersonId, supplementary_info = auditinfo.supplementaryInfo, description = auditinfo.description, reason = auditinfo.reason }; sub.T_Audit.Add(newAudit); sub.SaveChanges(); return Ok(new { code = 200, message = "成功新增" }); } } } /// /// 查询审批 /// [Route("api/v1/admin/AuditFind")] [HttpGet] [Authorize] public async Task> auditFind([FromQuery] string archive,string projName,string projNo,string bizType,string startPerson,string budgetUse, short page = 1, short limit = 10) { string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value; var user = await userManager.FindByIdAsync(userId); if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) { return Ok(new error_mb { code = 401, message = "无权访问" }); } using (TestDbContext sub = new TestDbContext()) { var query = sub.T_Audit .Where(n => n.proj_name.Contains(projName) || n.proj_no.Contains(projNo) || n.biz_type.Contains(bizType) || n.start_person.Contains(startPerson) || n.budget_use.Contains(budgetUse)); if (archive == "1") { var rows = query .Skip((page - 1) * limit) .Take(limit) .ToList(); int total = query.Count(); var data = new { rows = query, total = total, }; return Ok(new { code = 200, message = "", data }); } else { var rows = query .Where(n => n.now_auth_person_id == (int)(user.Id)) .Skip((page - 1) * limit) .Take(limit) .ToList(); int total = query.Count(); var data = new { rows = query, total = total, }; return Ok(new { code = 200, message = "", data }); } } } } }