65 lines
2.5 KiB
C#
65 lines
2.5 KiB
C#
using Competition.Common.Util;
|
|
using CompetitionAPI.api.back;
|
|
using CompetitionAPI.api.unity;
|
|
using CompetitionAPI.Util;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Text;
|
|
|
|
namespace CompetitionAPI.Controllers.unity.study
|
|
{
|
|
[Route("unity/[controller]")]
|
|
[ApiController]
|
|
public class GetStudyListController : Controller
|
|
{
|
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
|
|
|
Competition.Mysql.BLL.pow_study study_bll = new Competition.Mysql.BLL.pow_study();
|
|
|
|
public GetStudyListController(IWebHostEnvironment webHostEnvironment)
|
|
{
|
|
_webHostEnvironment = webHostEnvironment;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取我的学习列表接口
|
|
/// </summary>
|
|
/// <param name="req">请求参数</param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpPost]
|
|
[APIFilter]
|
|
public JsonResult Index([FromForm] GetStudyListRequest req)
|
|
{
|
|
try
|
|
{
|
|
var query = new StringBuilder(" T1.Status='已发布' ");
|
|
var total_query = new StringBuilder(" T1.Status='已发布' ");
|
|
if (!string.IsNullOrEmpty(req.StudyName))
|
|
{
|
|
query.AppendFormat(" and T1.StudyName like '%{0}%' ", req.StudyName);
|
|
total_query.AppendFormat(" and T1.StudyName like '%{0}%' ", req.StudyName);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.StudyClassId))
|
|
{
|
|
query.AppendFormat(" and T1.StudyClassId='{0}' ", req.StudyClassId);
|
|
total_query.AppendFormat(" and T1.StudyClassId='{0}' ", req.StudyClassId);
|
|
}
|
|
|
|
var offset = (req.PageIndex - 1) * req.PageSize;
|
|
query.AppendFormat(" order by T1.CreateTime desc LIMIT {0} OFFSET {1} ", req.PageSize, offset);
|
|
var total = study_bll.GetUserRecordCount(total_query.ToString(), req.UserId);
|
|
var list = study_bll.GetUserList(query.ToString(), req.UserId);
|
|
return Json(Tool.GetJsonWithCode(APICode.Success, new { total = total, list = list }));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
}
|
|
}
|