zxl
3 天以前 e636396c6c16f56931edc8b57b8efb6b9a165786
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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<String> 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();
    }
}