using Competition.Common.Util; using CompetitionAPI.api.back; using CompetitionAPI.Util; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace CompetitionAPI.Controllers.back.score { [Route("api/[controller]")] [ApiController] public class DeleteAchievementController : Controller { private readonly IWebHostEnvironment _webHostEnvironment; 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(); public DeleteAchievementController(IWebHostEnvironment webHostEnvironment) { _webHostEnvironment = webHostEnvironment; } /// /// 删除成绩接口 /// /// 请求参数 /// [Authorize] [HttpPost] [APIFilter] public JsonResult Index([FromBody] DeleteAchievementRequest req) { try { var count = req.Data.Count; if (count <= 0) { return Json(Tool.GetJsonWithCode(APICode.Fail, "数据不能为空")); } var video_list = video_bll.GetModelList(" AchievementId in ('" + string.Join("','", req.Data.Select(a => a.AchievementId).ToArray()) + "') "); var delete_list = new List(); foreach (var item in req.Data) { var user_fault_list = user_fault_bll.GetModelList(string.Format(" ExamId='{0}' and UserId='{1}' and FaultDesc='出线电缆编号牌型号编写错误' ", item.ExamId, item.UserId)); if (user_fault_list.Count > 0) { delete_list.AddRange(user_fault_list); } } var flag = false; //批量删除 if (achievement_bll.OperationDelAllData(req.Data) > 0) { flag = true; 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); } } } //存在被删除的记录 if (flag) { return Json(Tool.GetJsonWithCode(APICode.Success, "删除成功")); } else { return Json(Tool.GetJsonWithCode(APICode.Fail, "删除失败")); } } catch (Exception ex) { LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace); return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。")); } } } }