package cn.lili.controller.lmk; import cn.lili.group.Update; import cn.lili.group.Add; import cn.lili.modules.lmk.domain.form.ThumbsUpRecordForm; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.validation.annotation.Validated; import org.springframework.security.access.prepost.PreAuthorize; import lombok.RequiredArgsConstructor; import java.io.BufferedReader; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; import org.springframework.validation.annotation.Validated; import javax.servlet.http.HttpServletRequest; import javax.validation.constraints.NotEmpty; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import cn.lili.modules.lmk.service.VideoCommentService; import cn.lili.base.Result; import cn.lili.modules.lmk.domain.form.VideoCommentForm; import cn.lili.modules.lmk.domain.query.VideoCommentQuery; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; /** * 视频评论 前端控制器 * * @author xp * @since 2025-05-27 */ @Validated @RequiredArgsConstructor @Api(value = "视频评论", tags = "视频评论管理") @RestController @RequestMapping("/buyer/lmk/video-comment") public class VideoCommentController { private final VideoCommentService videoCommentService; // Jackson 实例(用于手动解析 JSON) private final ObjectMapper objectMapper = new ObjectMapper(); @PostMapping("/thumbs_up") @ApiOperation(value = "点赞评论", notes = "点赞评论") public Result thumbsUp(@RequestBody @Validated(Add.class) ThumbsUpRecordForm form) { return videoCommentService.thumbsUp(form); } @PostMapping("/cancel/thumbs_up") @ApiOperation(value = "取消点赞评论", notes = "取消点赞评论") public Result cancelThumbsUp(@RequestBody @Validated(Add.class) ThumbsUpRecordForm form) { return videoCommentService.cancelThumbsUp(form); } // @PostMapping("/comment") // @ApiOperation(value = "评论", notes = "评论") // public Result comment(@RequestBody @Validated(Add.class) VideoCommentForm form) { // System.out.println("打印出:" + form.getCommentContent()); // String content = EmojiParser.parseToAliases(form.getCommentContent()); // System.out.println("解析后:" + content); // return videoCommentService.comment(form); // } @PostMapping("/comment") @ApiOperation(value = "评论", notes = "评论") public Result comment(HttpServletRequest request)throws IOException { BufferedReader reader = request.getReader(); StringBuilder jsonStr = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { jsonStr.append(line); } String requestBody = jsonStr.toString(); System.out.println("后端接收的 JSON 字符串:" + requestBody); // 正常输出:{"commentContent":"我\uD83E\uDD26\u200D\u2642\uFE0F...",...} // 2. 手动解析 JSON 字符串(显式使用 UTF-8 编码) VideoCommentForm form = objectMapper.readValue( requestBody.getBytes(StandardCharsets.UTF_8), // 转为 UTF-8 字节数组 VideoCommentForm.class // 目标实体类 ); return videoCommentService.comment(form); } @GetMapping("/wx/page") @ApiOperation(value = "小程序分页", notes = "评论") public Result wxPage(VideoCommentQuery query) { return videoCommentService.wxPage(query); } @DeleteMapping("/{id}") @ApiOperation(value = "ID删除", notes = "ID删除") public Result removeById(@PathVariable("id") String id) { return videoCommentService.removeById(id); } @DeleteMapping("/batch") @ApiOperation(value = "批量删除", notes = "批量删除") public Result remove(@RequestBody @NotEmpty(message = "请选择数据") List ids) { return videoCommentService.remove(ids); } @GetMapping("/page") @ApiOperation(value = "分页", notes = "分页") public Result page(VideoCommentQuery query) { return videoCommentService.page(query); } @GetMapping("/{id}") @ApiOperation(value = "详情", notes = "详情") public Result detail(@PathVariable("id") String id) { return videoCommentService.detail(id); } @GetMapping("/list") @ApiOperation(value = "列表", notes = "列表") public Result list() { return videoCommentService.all(); } }