CompetitionAPI_dotnet/CompetitionAPI/Controllers/unity/ClearDataController.cs

96 lines
3.5 KiB
C#

using Competition.Common.Util;
using CompetitionAPI.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Org.BouncyCastle.Ocsp;
using static NPOI.HSSF.Util.HSSFColor;
namespace CompetitionAPI.Controllers.unity
{
[Route("unity/[controller]")]
[ApiController]
public class ClearDataController : Controller
{
Competition.Mysql.BLL.pow_achievement achievement_bll = new Competition.Mysql.BLL.pow_achievement();
Competition.Mysql.BLL.pow_video video_bll = new Competition.Mysql.BLL.pow_video();
Competition.Mysql.BLL.pow_user_fault user_fault_bll = new Competition.Mysql.BLL.pow_user_fault();
private readonly IWebHostEnvironment _webHostEnvironment;
public ClearDataController(IWebHostEnvironment webHostEnvironment)
{
_webHostEnvironment = webHostEnvironment;
}
/// <summary>
/// 清除所有数据接口
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpGet]
public JsonResult Index()
{
try
{
var video_list = video_bll.GetModelList("");
var delete_list = user_fault_bll.GetModelList(" FaultDesc='出线电缆编号牌型号编写错误' ");
var row = achievement_bll.OperationDeleteData();
foreach (var item in video_list)
{
if (!string.IsNullOrEmpty(item.VideoPath))
{
string path = _webHostEnvironment.WebRootPath + item.VideoPath;
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
}
}
foreach (var item in delete_list)
{
string path1 = _webHostEnvironment.WebRootPath + item.SensitiveKnowledge;
if (System.IO.File.Exists(path1))
{
System.IO.File.Delete(path1);
}
string path2 = _webHostEnvironment.WebRootPath + item.Minhui;
if (System.IO.File.Exists(path2))
{
System.IO.File.Delete(path2);
}
string path3 = _webHostEnvironment.WebRootPath + item.SensitiveLine;
if (System.IO.File.Exists(path3))
{
System.IO.File.Delete(path3);
}
string path4 = _webHostEnvironment.WebRootPath + item.Allergy;
if (System.IO.File.Exists(path4))
{
System.IO.File.Delete(path4);
}
string path5 = _webHostEnvironment.WebRootPath + item.GracefulGraceful;
if (System.IO.File.Exists(path5))
{
System.IO.File.Delete(path5);
}
}
return Json(Tool.GetJsonWithCode(APICode.Success, "清除成功"));
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
}
}
}
}