新增微信接口以及一些问天
This commit is contained in:
@ -0,0 +1,326 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.UserAnswerTaskService;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
|
||||
|
||||
/// <summary>
|
||||
/// 小程序首页控制器
|
||||
/// </summary>
|
||||
public class UserAnswerTaskController : WeChatBaseController
|
||||
{
|
||||
private readonly IUserAnswerTaskService _userAnswerTaskService;
|
||||
private readonly ILogger<UserAnswerTaskController> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public UserAnswerTaskController(
|
||||
IUserAnswerTaskService userAnswerTaskService,
|
||||
ILogger<UserAnswerTaskController> logger)
|
||||
{
|
||||
_userAnswerTaskService = userAnswerTaskService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户的期刊学习进度列表
|
||||
/// </summary>
|
||||
/// <returns>按期刊分组的学习进度数据</returns>
|
||||
[HttpGet("progress")]
|
||||
public async Task<BaseResponse<List<JournalProgressOutput>>> GetProgressAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<List<JournalProgressOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.GetJournalProgressAsync(userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取学习进度失败,UserId: {UserId}", GetCurrentUserId());
|
||||
return BaseResponse<List<JournalProgressOutput>>.Fail("获取学习进度失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取目录列表(按一级目录分组,二级目录含完成状态)
|
||||
/// </summary>
|
||||
/// <param name="journalId">期刊Id</param>
|
||||
/// <returns>按一级目录分组的目录列表</returns>
|
||||
[HttpGet("catalog-list/{journalId:long}")]
|
||||
public async Task<BaseResponse<List<CatalogListOutput>>> GetCatalogListAsync([Required] long journalId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<List<CatalogListOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
if (journalId <= 0)
|
||||
{
|
||||
return BaseResponse<List<CatalogListOutput>>.Fail(ResultCode.PARAM_ERROR, "期刊Id不能为空");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.GetCatalogListAsync(journalId, userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取目录列表失败,JournalId: {JournalId}, UserId: {UserId}", journalId, GetCurrentUserId());
|
||||
return BaseResponse<List<CatalogListOutput>>.Fail("获取目录列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一级目录概览(含二级目录详情、页码范围、任务完成状态)
|
||||
/// </summary>
|
||||
/// <param name="catalogId">一级目录Id</param>
|
||||
/// <returns>一级目录概览数据</returns>
|
||||
[HttpGet("catalog-overview/{catalogId:long}")]
|
||||
public async Task<BaseResponse<CatalogOverviewOutput>> GetCatalogOverviewAsync([Required] long catalogId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<CatalogOverviewOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
if (catalogId <= 0)
|
||||
{
|
||||
return BaseResponse<CatalogOverviewOutput>.Fail(ResultCode.PARAM_ERROR, "目录Id不能为空");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.GetCatalogOverviewAsync(catalogId, userId);
|
||||
if (result == null)
|
||||
{
|
||||
return BaseResponse<CatalogOverviewOutput>.Fail("未找到该目录");
|
||||
}
|
||||
|
||||
return Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取目录概览失败,CatalogId: {CatalogId}, UserId: {UserId}", catalogId, GetCurrentUserId());
|
||||
return BaseResponse<CatalogOverviewOutput>.Fail("获取目录概览失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户答题任务列表
|
||||
/// </summary>
|
||||
/// <param name="catalogId">二级目录Id</param>
|
||||
/// <returns>答题任务列表</returns>
|
||||
[HttpGet("task-list/{catalogId:long}")]
|
||||
public async Task<BaseResponse<UserAnswerTaskListOutput>> GetTaskListAsync([Required] long catalogId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<UserAnswerTaskListOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
if (catalogId <= 0)
|
||||
{
|
||||
return BaseResponse<UserAnswerTaskListOutput>.Fail(ResultCode.PARAM_ERROR, "目录Id不能为空");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.GetUserAnswerTaskListAsync(catalogId, userId);
|
||||
if (result == null)
|
||||
{
|
||||
return BaseResponse<UserAnswerTaskListOutput>.Fail("未找到该目录");
|
||||
}
|
||||
|
||||
return Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取任务列表失败,CatalogId: {CatalogId}, UserId: {UserId}", catalogId, GetCurrentUserId());
|
||||
return BaseResponse<UserAnswerTaskListOutput>.Fail("获取任务列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取跨页题目详情
|
||||
/// </summary>
|
||||
/// <param name="journalPageTaskId">任务Id</param>
|
||||
/// <returns>跨页题目详情</returns>
|
||||
[HttpGet("cross-page-task/{journalPageTaskId:long}")]
|
||||
public async Task<BaseResponse<CrossPageTaskOutput>> GetCrossPageTaskAsync([Required] long journalPageTaskId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<CrossPageTaskOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
if (journalPageTaskId <= 0)
|
||||
{
|
||||
return BaseResponse<CrossPageTaskOutput>.Fail(ResultCode.PARAM_ERROR, "任务Id不能为空");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.GetCrossPageTaskAsync(journalPageTaskId, userId);
|
||||
if (result == null)
|
||||
{
|
||||
return BaseResponse<CrossPageTaskOutput>.Fail("未找到该任务");
|
||||
}
|
||||
|
||||
return Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取跨页题目失败,JournalPageTaskId: {JournalPageTaskId}, UserId: {UserId}", journalPageTaskId, GetCurrentUserId());
|
||||
return BaseResponse<CrossPageTaskOutput>.Fail("获取跨页题目失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 领取任务积分
|
||||
/// </summary>
|
||||
/// <param name="journalPageTaskId">任务Id</param>
|
||||
/// <returns>领取结果</returns>
|
||||
[HttpPost("claim-points/{journalPageTaskId:long}")]
|
||||
public async Task<BaseResponse<ClaimTaskPointsOutput>> ClaimTaskPointsAsync([Required] long journalPageTaskId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<ClaimTaskPointsOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
if (journalPageTaskId <= 0)
|
||||
{
|
||||
return BaseResponse<ClaimTaskPointsOutput>.Fail(ResultCode.PARAM_ERROR, "任务Id不能为空");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.ClaimTaskPointsAsync(journalPageTaskId, userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "领取任务积分业务异常,JournalPageTaskId: {JournalPageTaskId}, UserId: {UserId}", journalPageTaskId, GetCurrentUserId());
|
||||
return BaseResponse<ClaimTaskPointsOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "领取任务积分失败,JournalPageTaskId: {JournalPageTaskId}, UserId: {UserId}", journalPageTaskId, GetCurrentUserId());
|
||||
return BaseResponse<ClaimTaskPointsOutput>.Fail("领取任务积分失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量领取任务积分(一键领取)
|
||||
/// </summary>
|
||||
/// <param name="input">批量领取参数</param>
|
||||
/// <returns>批量领取结果</returns>
|
||||
[HttpPost("batch-claim-points")]
|
||||
public async Task<BaseResponse<BatchClaimPointsOutput>> BatchClaimPointsAsync([FromBody] BatchClaimPointsInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<BatchClaimPointsOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
if (input == null || input.GroupIds == null || input.GroupIds.Count == 0)
|
||||
{
|
||||
return BaseResponse<BatchClaimPointsOutput>.Fail(ResultCode.PARAM_ERROR, "任务分组Id列表不能为空");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.BatchClaimPointsAsync(input, userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "批量领取积分业务异常,UserId: {UserId}", GetCurrentUserId());
|
||||
return BaseResponse<BatchClaimPointsOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "批量领取积分失败,UserId: {UserId}", GetCurrentUserId());
|
||||
return BaseResponse<BatchClaimPointsOutput>.Fail("批量领取积分失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取杂志列表
|
||||
/// </summary>
|
||||
/// <param name="queryType">查询类型:Bound=已绑定,Unbound=未绑定(添加书籍用),默认是:Bound</param>
|
||||
/// <returns>杂志列表</returns>
|
||||
[HttpGet("journal-list")]
|
||||
public async Task<BaseResponse<List<JournalListOutput>>> GetJournalListAsync([FromQuery] string? queryType = "Bound")
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<List<JournalListOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.GetJournalListAsync(userId, queryType);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "查询杂志列表业务异常,UserId: {UserId}", GetCurrentUserId());
|
||||
return BaseResponse<List<JournalListOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "查询杂志列表失败,UserId: {UserId}", GetCurrentUserId());
|
||||
return BaseResponse<List<JournalListOutput>>.Fail("查询杂志列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增学生
|
||||
/// </summary>
|
||||
/// <param name="input">新增学生参数</param>
|
||||
/// <returns>新增学生结果</returns>
|
||||
[HttpPost("add-student")]
|
||||
public async Task<BaseResponse<bool>> AddStudentAsync([FromBody] AddStudentInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<bool>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _userAnswerTaskService.AddStudentAsync(input, userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "新增学生业务异常,UserId: {UserId}", GetCurrentUserId());
|
||||
return BaseResponse<bool>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "新增学生失败,UserId: {UserId}", GetCurrentUserId());
|
||||
return BaseResponse<bool>.Fail("新增学生失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<key id="22eabfbc-9d6d-4d02-a009-12a7eb9886c2" version="1">
|
||||
<creationDate>2026-06-24T08:30:52.1384894Z</creationDate>
|
||||
<activationDate>2026-06-24T08:30:52.1128731Z</activationDate>
|
||||
<expirationDate>2026-09-22T08:30:52.1128731Z</expirationDate>
|
||||
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
|
||||
<descriptor>
|
||||
<encryption algorithm="AES_256_CBC" />
|
||||
<validation algorithm="HMACSHA256" />
|
||||
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
|
||||
<!-- Warning: the key below is in an unencrypted form. -->
|
||||
<value>pejyMxgU0u9FWIYfhFHKOIK2tiEFlkbgD4WVeVom3GNwAP1/JRCwVGkaqaceJzwpzVBcNpwM2JrunPK/KQeAfQ==</value>
|
||||
</masterKey>
|
||||
</descriptor>
|
||||
</descriptor>
|
||||
</key>
|
||||
Reference in New Issue
Block a user