asg_backend/asg_form/Controllers/auditAndFilingController.cs

312 lines
14 KiB
C#
Raw Normal View History

2024-11-11 15:55:25 +08:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
2024-11-11 16:44:05 +08:00
using Manganese.Array;
2024-11-11 21:54:32 +08:00
using Microsoft.EntityFrameworkCore;
2024-11-12 21:57:32 +08:00
using AsmResolver.DotNet.Resources;
using SharpCompress.Archives;
using System.Management;
2025-01-22 11:40:30 +08:00
using Flandre.Core.Common;
using Flandre.Core.Messaging.Segments;
using Flandre.Core.Messaging;
using System.Threading.Tasks;
2024-11-11 15:55:25 +08:00
namespace asg_form.Controllers {
public class FileDB
{
public string proj_name { get; set; }
public string proj_no { get; set; }
2024-11-11 16:44:05 +08:00
public string? budget_use { get; set; }
public string? budget_name { get; set; }
2024-11-11 15:55:25 +08:00
public string biz_type { get; set; }
2024-11-11 16:44:05 +08:00
public int? budget_id { get; set; }
2024-11-11 15:55:25 +08:00
public string start_time { get; set; }
public decimal budget_money { get; set; }
2024-11-11 21:54:32 +08:00
public int? start_person_id { get; set; }
public string? start_person { get; set; }
2024-11-11 15:55:25 +08:00
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; }
2024-11-24 21:47:49 +08:00
public int? relative_id { get; set; }
public int node_index { get; set; }
public string flow_config { get; set; }
2024-11-11 15:55:25 +08:00
}
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; }
2024-11-11 21:54:32 +08:00
public int? startPersonId { get; set; }
public string? startPerson { get; set; }
2024-11-11 15:55:25 +08:00
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; }
2024-11-24 21:47:49 +08:00
public int? relativeId { get; set; }
public int nodeIndex { get; set; }
public string flowConfig { get; set; }
2024-11-11 15:55:25 +08:00
}
2025-01-27 20:32:23 +08:00
2024-11-11 15:55:25 +08:00
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;
2024-11-11 16:44:05 +08:00
au.start_person_id = auditinfo.startPersonId;
2024-11-24 21:47:49 +08:00
au.start_person = auditinfo.startPerson;
2024-11-24 22:39:50 +08:00
au.node_index = auditinfo.nodeIndex;
au.flow_config = auditinfo.flowConfig;
if(!query.Any(n => n.relative_id == auditinfo.relativeId))
2024-11-24 21:47:49 +08:00
{
2024-11-24 22:39:50 +08:00
au.relative_id = auditinfo.relativeId;
2024-12-02 21:39:10 +08:00
}
2024-12-03 09:31:56 +08:00
if (auditinfo.relativeId != null)
{
try
{
var query2 = await sub.T_Comform.FirstOrDefaultAsync(n => n.id == auditinfo.relativeId);
2025-01-22 11:40:30 +08:00
if (query2 != null && auditinfo.nowAuthPerson != "archive") query2.status = "5";
2024-12-03 09:31:56 +08:00
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
2024-11-11 15:55:25 +08:00
sub.SaveChanges();
2025-01-22 11:40:30 +08:00
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();
2025-02-16 17:43:59 +08:00
try
{
2025-02-16 22:44:44 +08:00
//await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, qqgroup, null, message, qqgroup);
2025-02-16 17:43:59 +08:00
return Ok(new { code = 200, message = "成功修改" });
}
catch
{
2025-02-16 22:23:54 +08:00
return Ok(new error_mb { code = 500, message = "机器人错误" });
2025-02-16 17:43:59 +08:00
}
2024-11-11 15:55:25 +08:00
}
else
{
var newAudit = new FileDB
{
id = auditinfo.Id,
proj_no = auditinfo.projNo,
proj_name = auditinfo.projName,
budget_use = auditinfo.budgetUse,
2024-11-12 21:57:32 +08:00
status = auditinfo.status,
2024-11-11 15:55:25 +08:00
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,
2024-11-11 16:44:05 +08:00
reason = auditinfo.reason,
start_person_id = auditinfo.startPersonId,
2024-11-11 21:54:32 +08:00
start_person = auditinfo.startPerson,
2024-11-24 22:39:50 +08:00
relative_id = auditinfo.relativeId,
node_index = auditinfo.nodeIndex,
flow_config = auditinfo.flowConfig,
2024-11-11 15:55:25 +08:00
};
2024-12-11 20:49:07 +08:00
if (auditinfo.relativeId != null)
{
try
{
var query2 = await sub.T_Comform.FirstOrDefaultAsync(n => n.id == auditinfo.relativeId);
2025-01-22 11:40:30 +08:00
if (query2 != null && auditinfo.nowAuthPerson != "archive") query2.status = "5";
2024-12-11 20:49:07 +08:00
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
2024-11-11 15:55:25 +08:00
sub.T_Audit.Add(newAudit);
sub.SaveChanges();
2025-01-22 11:40:30 +08:00
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();
2025-02-16 17:43:59 +08:00
try
{
2025-02-16 22:44:44 +08:00
//await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, qqgroup, null, message, qqgroup);
2025-02-16 17:43:59 +08:00
return Ok(new { code = 200, message = "成功新增" });
}
catch
{
2025-02-16 22:23:54 +08:00
return Ok(new error_mb { code = 500, message = "机器人错误" });
2025-02-16 17:43:59 +08:00
}
2024-11-11 15:55:25 +08:00
}
}
}
/// <summary>
/// 查询审批
/// </summary>
[Route("api/v1/admin/AuditFind")]
[HttpGet]
[Authorize]
2024-11-24 22:31:33 +08:00
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)
2024-11-11 15:55:25 +08:00
{
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
2024-11-11 21:54:32 +08:00
.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
{
2024-11-11 15:55:25 +08:00
if (archive == "1")
{
2024-11-11 21:54:32 +08:00
var rows = await query
2024-11-11 15:55:25 +08:00
.Skip((page - 1) * limit)
.Take(limit)
2024-11-11 21:54:32 +08:00
.ToListAsync();
int total = await query.CountAsync();
2024-11-11 15:55:25 +08:00
var data = new
{
2024-11-11 16:44:05 +08:00
rows,
total,
2024-11-11 15:55:25 +08:00
};
2024-11-11 21:54:32 +08:00
return Ok(new { code = 200, message = "", data , archive });
2024-11-11 15:55:25 +08:00
}
else
{
2024-11-11 21:54:32 +08:00
var rows =await query
.Where(n => n.now_auth_person_id ==(int)user.Id )
2024-11-11 15:55:25 +08:00
.Skip((page - 1) * limit)
.Take(limit)
2024-11-11 21:54:32 +08:00
.ToListAsync();
int total = await query.Where(n => n.now_auth_person_id == (int)user.Id).CountAsync();
2024-11-11 15:55:25 +08:00
var data = new
{
2024-11-11 16:44:05 +08:00
rows,
total,
2024-11-11 15:55:25 +08:00
};
2024-11-11 21:54:32 +08:00
return Ok(new { code = 200, message = "", data , archive });
2024-11-11 15:55:25 +08:00
}
2024-11-11 16:44:05 +08:00
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
2024-11-11 15:55:25 +08:00
}
}
2024-11-12 21:57:32 +08:00
/// <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";
2024-12-02 16:21:08 +08:00
if(query.relative_id != null)
{
try
{
var query2 = await sub.T_Comform.FirstOrDefaultAsync(n => n.id == query.relative_id);
2024-12-21 21:57:24 +08:00
if (query2 != null) query2.status = "3";
2024-12-02 16:21:08 +08:00
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
2024-11-12 21:57:32 +08:00
await sub.SaveChangesAsync();
return Ok(new error_mb { code = 200, message = "对应的status已经更改" });
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", ex });
}
}
}
2024-11-11 15:55:25 +08:00
}
}