asg_backend/asg_form/Controllers/auditAndFilingController.cs
2025-01-27 20:32:23 +08:00

297 lines
13 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using Manganese.Array;
using Microsoft.EntityFrameworkCore;
using AsmResolver.DotNet.Resources;
using SharpCompress.Archives;
using System.Management;
using Flandre.Core.Common;
using Flandre.Core.Messaging.Segments;
using Flandre.Core.Messaging;
using System.Threading.Tasks;
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 int? start_person_id { 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 int? relative_id { get; set; }
public int node_index { get; set; }
public string flow_config { 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 int? startPersonId { 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 int? relativeId { get; set; }
public int nodeIndex { get; set; }
public string flowConfig { get; set; }
}
[ApiController]
public class auditAndFilingController : ControllerBase
{
private readonly RoleManager<Role> roleManager;
private readonly UserManager<User> userManager;
public auditAndFilingController(
RoleManager<Role> roleManager, UserManager<User> userManager)
{
this.roleManager = roleManager;
this.userManager = userManager;
}
/// <summary>
/// 新增/修改审批
/// </summary>
/// <param name="auditinfo"></param>
/// <returns></returns>
[Route("api/v1/admin/AuditPost")]
[HttpPost]
[Authorize]
public async Task<ActionResult<object>> 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;
au.start_person_id = auditinfo.startPersonId;
au.start_person = auditinfo.startPerson;
au.node_index = auditinfo.nodeIndex;
au.flow_config = auditinfo.flowConfig;
if(!query.Any(n => n.relative_id == auditinfo.relativeId))
{
au.relative_id = auditinfo.relativeId;
}
if (auditinfo.relativeId != null)
{
try
{
var query2 = await sub.T_Comform.FirstOrDefaultAsync(n => n.id == auditinfo.relativeId);
if (query2 != null && auditinfo.nowAuthPerson != "archive") query2.status = "5";
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
sub.SaveChanges();
string mesg = $"ASG管理系统您有新的业务待办需要处理请及时上后台系统推进流程。";
string qqgroup = "925510646";
var atuserqq = auditinfo.nowAuthPersonId.ToString();
if (atuserqq == null) return Ok(new { code = 500, message = "服务器错误" });
var message = new MessageBuilder().Add(new AtSegment(atuserqq)).Text(mesg).Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, qqgroup, null, message, qqgroup);
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,
start_person_id = auditinfo.startPersonId,
start_person = auditinfo.startPerson,
relative_id = auditinfo.relativeId,
node_index = auditinfo.nodeIndex,
flow_config = auditinfo.flowConfig,
};
if (auditinfo.relativeId != null)
{
try
{
var query2 = await sub.T_Comform.FirstOrDefaultAsync(n => n.id == auditinfo.relativeId);
if (query2 != null && auditinfo.nowAuthPerson != "archive") query2.status = "5";
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
sub.T_Audit.Add(newAudit);
sub.SaveChanges();
string mesg = $"ASG管理系统您有新的业务待办需要处理请及时上后台系统推进流程。";
string qqgroup = "925510646";
var atuserqq = auditinfo.nowAuthPersonId.ToString();
if (atuserqq == null) return Ok(new { code = 500, message = "服务器错误" });
var message = new MessageBuilder().Add(new AtSegment(atuserqq)).Text(mesg).Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, qqgroup, null, message, qqgroup);
return Ok(new { code = 200, message = "成功新增" });
}
}
}
/// <summary>
/// 查询审批
/// </summary>
[Route("api/v1/admin/AuditFind")]
[HttpGet]
[Authorize]
public async Task<ActionResult<object>> 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)||projName==null) && (n.proj_no.Contains(projNo) || projNo == null) && (n.biz_type.Contains(bizType) || bizType == null) && (n.start_person.Contains(startPerson)|| startPerson == null) && (n.budget_use.Contains(budgetUse)|| budgetUse == null))
.AsQueryable();
try
{
if (archive == "1")
{
var rows = await query
.Skip((page - 1) * limit)
.Take(limit)
.ToListAsync();
int total = await query.CountAsync();
var data = new
{
rows,
total,
};
return Ok(new { code = 200, message = "", data , archive });
}
else
{
var rows =await query
.Where(n => n.now_auth_person_id ==(int)user.Id )
.Skip((page - 1) * limit)
.Take(limit)
.ToListAsync();
int total = await query.Where(n => n.now_auth_person_id == (int)user.Id).CountAsync();
var data = new
{
rows,
total,
};
return Ok(new { code = 200, message = "", data , archive });
}
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
}
/// <summary>
/// Id改status为4
/// </summary>
[Route("api/v1/admin/statusChange4")]
[HttpGet]
[Authorize]
public async Task<ActionResult<object>> statusChange4([FromQuery] string Id)
{
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.FirstOrDefault(n => n.id == Id);
try
{
if(query == null) return Ok(new error_mb { code = 404, message = "没有对应记录" });
query.status = "4";
if(query.relative_id != null)
{
try
{
var query2 = await sub.T_Comform.FirstOrDefaultAsync(n => n.id == query.relative_id);
if (query2 != null) query2.status = "3";
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
await sub.SaveChangesAsync();
return Ok(new error_mb { code = 200, message = "对应的status已经更改" });
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
}
}
}