feat: 🎸 新增课程评论
This commit is contained in:
parent
6cc473fead
commit
ce36c26dff
@ -13,6 +13,8 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.query.QueryRuleEnum;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.config.shiro.IgnoreAuth;
|
||||
import org.jeecg.modules.aiol.dto.CommentWithUserInfo;
|
||||
@ -29,6 +31,7 @@ import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -39,7 +42,10 @@ import com.alibaba.fastjson.JSON;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 评论
|
||||
* @Author: jeecg-boot
|
||||
@ -71,7 +77,6 @@ public class AiolCommentController extends JeecgController<AiolComment, IAiolCom
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
|
||||
|
||||
QueryWrapper<AiolComment> queryWrapper = QueryGenerator.initQueryWrapper(aiolComment, req.getParameterMap());
|
||||
Page<AiolComment> page = new Page<AiolComment>(pageNo, pageSize);
|
||||
IPage<AiolComment> pageList = aiolCommentService.page(page, queryWrapper);
|
||||
@ -191,8 +196,10 @@ public class AiolCommentController extends JeecgController<AiolComment, IAiolCom
|
||||
|
||||
// @GetMapping("/activity/{activityId}/list")
|
||||
// @Operation(summary = "查询活动评论列表", description = "根据活动ID查询活动评论列表,包含用户信息")
|
||||
// public Result<List<CommentWithUserInfo>> queryActivityCommentList(@PathVariable("activityId") String activityId) {
|
||||
// List<CommentWithUserInfo> list = commentBizService.getCommentList("activity", activityId);
|
||||
// public Result<List<CommentWithUserInfo>>
|
||||
// queryActivityCommentList(@PathVariable("activityId") String activityId) {
|
||||
// List<CommentWithUserInfo> list = commentBizService.getCommentList("activity",
|
||||
// activityId);
|
||||
// return Result.OK(list);
|
||||
// }
|
||||
|
||||
@ -201,7 +208,58 @@ public class AiolCommentController extends JeecgController<AiolComment, IAiolCom
|
||||
// public Result<List<CommentWithUserInfo>> queryCommentList(
|
||||
// @PathVariable("targetType") String targetType,
|
||||
// @PathVariable("targetId") String targetId) {
|
||||
// List<CommentWithUserInfo> list = commentBizService.getCommentList(targetType, targetId);
|
||||
// List<CommentWithUserInfo> list = commentBizService.getCommentList(targetType,
|
||||
// targetId);
|
||||
// return Result.OK(list);
|
||||
// }
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseApi;
|
||||
|
||||
/**
|
||||
* 新增课程评论
|
||||
*
|
||||
* @param courseId 课程ID
|
||||
* @param aiolComment 评论信息
|
||||
* @param request HTTP请求对象
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "评论-新增课程评论")
|
||||
@Operation(summary = "新增课程评论", description = "新增课程评论,target_type默认为course,user_id通过token自动获取")
|
||||
@PostMapping(value = "/course/{courseId}/add")
|
||||
public Result<String> addCourseComment(
|
||||
@PathVariable("courseId") String courseId,
|
||||
@RequestBody AiolComment aiolComment,
|
||||
HttpServletRequest request) {
|
||||
|
||||
try {
|
||||
// 1. 获取当前登录用户信息
|
||||
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
|
||||
String username = JwtUtil.getUsername(token);
|
||||
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
||||
|
||||
if (sysUser == null) {
|
||||
return Result.error("用户未登录或登录已过期");
|
||||
}
|
||||
|
||||
// 2. 设置评论基本信息
|
||||
aiolComment.setTargetType("course"); // 默认设置为course
|
||||
aiolComment.setTargetId(courseId); // 设置课程ID
|
||||
aiolComment.setUserId(sysUser.getId()); // 设置用户ID
|
||||
aiolComment.setCreateBy(sysUser.getId()); // 设置创建人
|
||||
aiolComment.setCreateTime(new Date()); // 设置创建时间
|
||||
|
||||
// 3. 保存评论
|
||||
aiolCommentService.save(aiolComment);
|
||||
|
||||
log.info("用户 {} 成功添加课程评论,课程ID: {}, 评论ID: {}",
|
||||
username, courseId, aiolComment.getId());
|
||||
|
||||
return Result.OK("评论添加成功!");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("添加课程评论失败: courseId={}, error={}", courseId, e.getMessage(), e);
|
||||
return Result.error("评论添加失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user