feat: 🎸 新增课程评论

This commit is contained in:
GoCo 2025-09-03 09:44:49 +08:00
parent 6cc473fead
commit ce36c26dff

View File

@ -13,6 +13,8 @@ import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum; 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.common.util.oConvertUtils;
import org.jeecg.config.shiro.IgnoreAuth; import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.aiol.dto.CommentWithUserInfo; 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.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -39,14 +42,17 @@ import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
/** import java.util.Date;
/**
* @Description: 评论 * @Description: 评论
* @Author: jeecg-boot * @Author: jeecg-boot
* @Date: 2025-08-31 * @Date: 2025-08-31
* @Version: V1.0 * @Version: V1.0
*/ */
@Tag(name="评论") @Tag(name = "评论")
@RestController @RestController
@RequestMapping("/aiol/aiolComment") @RequestMapping("/aiol/aiolComment")
@Slf4j @Slf4j
@ -63,29 +69,28 @@ public class AiolCommentController extends JeecgController<AiolComment, IAiolCom
* @param req * @param req
* @return * @return
*/ */
//@AutoLog(value = "评论-分页列表查询") // @AutoLog(value = "评论-分页列表查询")
@Operation(summary="评论-分页列表查询") @Operation(summary = "评论-分页列表查询")
@GetMapping(value = "/list") @GetMapping(value = "/list")
public Result<IPage<AiolComment>> queryPageList(AiolComment aiolComment, public Result<IPage<AiolComment>> queryPageList(AiolComment aiolComment,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) { HttpServletRequest req) {
QueryWrapper<AiolComment> queryWrapper = QueryGenerator.initQueryWrapper(aiolComment, req.getParameterMap());
QueryWrapper<AiolComment> queryWrapper = QueryGenerator.initQueryWrapper(aiolComment, req.getParameterMap());
Page<AiolComment> page = new Page<AiolComment>(pageNo, pageSize); Page<AiolComment> page = new Page<AiolComment>(pageNo, pageSize);
IPage<AiolComment> pageList = aiolCommentService.page(page, queryWrapper); IPage<AiolComment> pageList = aiolCommentService.page(page, queryWrapper);
return Result.OK(pageList); return Result.OK(pageList);
} }
/** /**
* 添加 * 添加
* *
* @param aiolComment * @param aiolComment
* @return * @return
*/ */
@AutoLog(value = "评论-添加") @AutoLog(value = "评论-添加")
@Operation(summary="评论-添加") @Operation(summary = "评论-添加")
@RequiresPermissions("aiol:aiol_comment:add") @RequiresPermissions("aiol:aiol_comment:add")
@PostMapping(value = "/add") @PostMapping(value = "/add")
public Result<String> add(@RequestBody AiolComment aiolComment) { public Result<String> add(@RequestBody AiolComment aiolComment) {
@ -95,46 +100,46 @@ public class AiolCommentController extends JeecgController<AiolComment, IAiolCom
} }
/** /**
* 编辑 * 编辑
* *
* @param aiolComment * @param aiolComment
* @return * @return
*/ */
@AutoLog(value = "评论-编辑") @AutoLog(value = "评论-编辑")
@Operation(summary="评论-编辑") @Operation(summary = "评论-编辑")
@RequiresPermissions("aiol:aiol_comment:edit") @RequiresPermissions("aiol:aiol_comment:edit")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) @RequestMapping(value = "/edit", method = { RequestMethod.PUT, RequestMethod.POST })
public Result<String> edit(@RequestBody AiolComment aiolComment) { public Result<String> edit(@RequestBody AiolComment aiolComment) {
aiolCommentService.updateById(aiolComment); aiolCommentService.updateById(aiolComment);
return Result.OK("编辑成功!"); return Result.OK("编辑成功!");
} }
/** /**
* 通过id删除 * 通过id删除
* *
* @param id * @param id
* @return * @return
*/ */
@AutoLog(value = "评论-通过id删除") @AutoLog(value = "评论-通过id删除")
@Operation(summary="评论-通过id删除") @Operation(summary = "评论-通过id删除")
@RequiresPermissions("aiol:aiol_comment:delete") @RequiresPermissions("aiol:aiol_comment:delete")
@DeleteMapping(value = "/delete") @DeleteMapping(value = "/delete")
public Result<String> delete(@RequestParam(name="id",required=true) String id) { public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
aiolCommentService.removeById(id); aiolCommentService.removeById(id);
return Result.OK("删除成功!"); return Result.OK("删除成功!");
} }
/** /**
* 批量删除 * 批量删除
* *
* @param ids * @param ids
* @return * @return
*/ */
@AutoLog(value = "评论-批量删除") @AutoLog(value = "评论-批量删除")
@Operation(summary="评论-批量删除") @Operation(summary = "评论-批量删除")
@RequiresPermissions("aiol:aiol_comment:deleteBatch") @RequiresPermissions("aiol:aiol_comment:deleteBatch")
@DeleteMapping(value = "/deleteBatch") @DeleteMapping(value = "/deleteBatch")
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) { public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
this.aiolCommentService.removeByIds(Arrays.asList(ids.split(","))); this.aiolCommentService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!"); return Result.OK("批量删除成功!");
} }
@ -145,63 +150,116 @@ public class AiolCommentController extends JeecgController<AiolComment, IAiolCom
* @param id * @param id
* @return * @return
*/ */
//@AutoLog(value = "评论-通过id查询") // @AutoLog(value = "评论-通过id查询")
@Operation(summary="评论-通过id查询") @Operation(summary = "评论-通过id查询")
@GetMapping(value = "/queryById") @GetMapping(value = "/queryById")
public Result<AiolComment> queryById(@RequestParam(name="id",required=true) String id) { public Result<AiolComment> queryById(@RequestParam(name = "id", required = true) String id) {
AiolComment aiolComment = aiolCommentService.getById(id); AiolComment aiolComment = aiolCommentService.getById(id);
if(aiolComment==null) { if (aiolComment == null) {
return Result.error("未找到对应数据"); return Result.error("未找到对应数据");
} }
return Result.OK(aiolComment); return Result.OK(aiolComment);
} }
/** /**
* 导出excel * 导出excel
* *
* @param request * @param request
* @param aiolComment * @param aiolComment
*/ */
@RequiresPermissions("aiol:aiol_comment:exportXls") @RequiresPermissions("aiol:aiol_comment:exportXls")
@RequestMapping(value = "/exportXls") @RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, AiolComment aiolComment) { public ModelAndView exportXls(HttpServletRequest request, AiolComment aiolComment) {
return super.exportXls(request, aiolComment, AiolComment.class, "评论"); return super.exportXls(request, aiolComment, AiolComment.class, "评论");
} }
/** /**
* 通过excel导入数据 * 通过excel导入数据
* *
* @param request * @param request
* @param response * @param response
* @return * @return
*/ */
@RequiresPermissions("aiol:aiol_comment:importExcel") @RequiresPermissions("aiol:aiol_comment:importExcel")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, AiolComment.class); return super.importExcel(request, response, AiolComment.class);
} }
@GetMapping("/course/{courseId}/list") @GetMapping("/course/{courseId}/list")
@Operation(summary = "查询课程评论列表", description = "根据课程ID查询课程评论列表包含用户信息") @Operation(summary = "查询课程评论列表", description = "根据课程ID查询课程评论列表包含用户信息")
@IgnoreAuth @IgnoreAuth
public Result<List<CommentWithUserInfo>> queryCourseCommentList(@PathVariable("courseId") String courseId) { public Result<List<CommentWithUserInfo>> queryCourseCommentList(@PathVariable("courseId") String courseId) {
List<CommentWithUserInfo> list = aiolCommentService.getCommentList("course", courseId); List<CommentWithUserInfo> list = aiolCommentService.getCommentList("course", courseId);
return Result.OK(list); return Result.OK(list);
} }
// @GetMapping("/activity/{activityId}/list") // @GetMapping("/activity/{activityId}/list")
// @Operation(summary = "查询活动评论列表", description = "根据活动ID查询活动评论列表包含用户信息") // @Operation(summary = "查询活动评论列表", description = "根据活动ID查询活动评论列表包含用户信息")
// public Result<List<CommentWithUserInfo>> queryActivityCommentList(@PathVariable("activityId") String activityId) { // public Result<List<CommentWithUserInfo>>
// List<CommentWithUserInfo> list = commentBizService.getCommentList("activity", activityId); // queryActivityCommentList(@PathVariable("activityId") String activityId) {
// return Result.OK(list); // List<CommentWithUserInfo> list = commentBizService.getCommentList("activity",
// } // activityId);
// return Result.OK(list);
// }
// @GetMapping("/{targetType}/{targetId}/list") // @GetMapping("/{targetType}/{targetId}/list")
// @Operation(summary = "查询通用评论列表", description = "根据目标类型和目标ID查询评论列表包含用户信息") // @Operation(summary = "查询通用评论列表", description = "根据目标类型和目标ID查询评论列表包含用户信息")
// public Result<List<CommentWithUserInfo>> queryCommentList( // public Result<List<CommentWithUserInfo>> queryCommentList(
// @PathVariable("targetType") String targetType, // @PathVariable("targetType") String targetType,
// @PathVariable("targetId") String targetId) { // @PathVariable("targetId") String targetId) {
// List<CommentWithUserInfo> list = commentBizService.getCommentList(targetType, targetId); // List<CommentWithUserInfo> list = commentBizService.getCommentList(targetType,
// return Result.OK(list); // 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默认为courseuser_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());
}
}
} }