44323
2024-04-23 16b704d18a875d1fb63827aaa507790ba2bef5be
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package com.stylefeng.guns.modular.code.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.stylefeng.guns.modular.system.dto.FindCommentQuery;
import com.stylefeng.guns.modular.system.dto.FindQuery;
import com.stylefeng.guns.modular.system.dto.FindReportQuery;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.RedisUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.util.UUIDUtil;
import com.stylefeng.guns.modular.system.vo.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author 无关风月
 * @Date 2024/2/6 18:25
 */
@RestController
@RequestMapping("")
public class FindController {
    @Autowired
    private IAppUserService appUserService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private IProtocolService protocolService;
    @Autowired
    private IPageService pageService;
    @Autowired
    private IFindService findService;
    @Autowired
    private IFindCommentService findCommentService;
    @Autowired
    private IFindReportService reportService;
    @Autowired
    private IMessageService messageService;
 
    @ResponseBody
    @PostMapping("/base/find/selectReport")
    @ApiOperation(value = "举报列表查询", tags = {"发现管理"})
    public ResultUtil<PageInfo<FindReportVO>> selectReport(FindReportQuery req) {
        List<FindReportVO> res= reportService.selectReport(req);
//        PageHelper.startPage(req.getPageNum(),req.getPageSize());
        PageInfo<FindReportVO> info=new PageInfo<>(res);
        return ResultUtil.success(info);
    }
    @ResponseBody
    @PostMapping("/base/find/reportDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "举报id"),
    })
    @ApiOperation(value = "举报详情", tags = {"发现管理"})
    public ResultUtil<FindReportDetailVO> handle(Integer id) {
        FindReportDetailVO findReportDetailVO = new FindReportDetailVO();
        FindReport findReport = reportService.selectById(id);
        Integer findId = findReport.getFindId();
        Find find = findService.selectById(findId);
        // 说明是举报评论
        if (findReport.getCommentId()!=null){
            String content = findCommentService.selectById(findReport.getCommentId()).getContent();
            findReportDetailVO.setContent(content);
        }else{
            findReportDetailVO.setContent(find.getContent());
        }
        Integer userId = find.getUserId();
        AppUser appUser = appUserService.selectById(userId);
        findReportDetailVO.setImage(find.getImg());
        findReportDetailVO.setVideo(find.getVideo());
        findReportDetailVO.setUserName(appUser.getName());
        findReportDetailVO.setPhone(appUser.getPhone());
        findReportDetailVO.setInsertTime(find.getInsertTime());
        findReportDetailVO.setLikeCount(find.getLikeCount());
        findReportDetailVO.setTitle(find.getTitle());
        findReportDetailVO.setState(findReport.getState());
        findReportDetailVO.setReportContent(findReport.getContent());
        return ResultUtil.success(findReportDetailVO);
    }
    
    @ResponseBody
    @PostMapping("/base/find/handle")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "举报id"),
            @ApiImplicitParam(name = "state", value = "状态2=忽略 3-下架")
    })
    @ApiOperation(value = "处理举报", tags = {"发现管理"})
    public ResultUtil handle(Integer id,Integer state) {
        FindReport findReport = reportService.selectById(id);
            findReport.setState(state);
            if (state==3){
                // 下架动态
                if (findReport.getCommentId()!=null){
                    // 下架评论
                    FindComment findComment = findCommentService.selectById(findReport.getCommentId());
                    findComment.setIsShow(0);
                    findCommentService.updateById(findComment);
                    Message message = new Message();
                    message.setUserId(findComment.getUserId());
                    message.setType(1);
                    message.setContent("你的评论\""+findComment.getContent()+"\""+"已被下架");
                    message.setInsertTime(new Date());
                    messageService.insert(message);
                }else{
                    // 下架动态
                    Find find = findService.selectById(findReport.getFindId());
                    find.setState(2);
                    findService.updateById(find);
                    Message message = new Message();
                    message.setUserId(find.getUserId());
                    message.setType(1);
                    message.setContent("你的动态\""+find.getTitle()+"\""+"已被下架");
                    message.setInsertTime(new Date());
                    messageService.insert(message);
                }
            }
        reportService.updateById(findReport);
        return ResultUtil.success();
    }
    @ResponseBody
    @PostMapping("/base/find/selectFind")
    @ApiOperation(value = "发现列表查询", tags = {"发现管理"})
    public ResultUtil<PageInfo<FindVO>> findList(FindQuery req) {
        List<FindVO> res = findService.selectFind(req);
        for (FindVO re : res) {
            int findId = findCommentService.selectList(new EntityWrapper<FindComment>()
                    .eq("findId", re.getId())).size();
            re.setComment(findId);
        }
//        PageHelper.startPage(req.getPageNum(),req.getPageSize());
        PageInfo<FindVO> info=new PageInfo<>(res);
        return ResultUtil.success(info);
    }
    @ResponseBody
    @PostMapping("/base/find/selectFindComment")
    @ApiOperation(value = "动态详情-查看评论", tags = {"发现管理"})
    public ResultUtil<PageInfo<CommentVO>> selectFindComment(FindCommentQuery req) {
        List<CommentVO> res = findCommentService.selectFindComment(req);
//        PageHelper.startPage(req.getPageNum(),req.getPageSize());
        PageInfo<CommentVO> info=new PageInfo<>(res);
        return ResultUtil.success(info);
    }
    @ResponseBody
    @PostMapping("/base/find/shield")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论id"),
            @ApiImplicitParam(name = "isShow", value = "是否展示 0否1是")
    })
    @ApiOperation(value = "屏蔽/展示评论", tags = {"发现管理"})
    public ResultUtil shield(Integer id,Integer isShow) {
        FindComment findComment = findCommentService.selectById(id);
        findComment.setIsShow(isShow);
        findCommentService.updateById(findComment);
        return ResultUtil.success();
    }
    @ResponseBody
    @PostMapping("/base/find/findDetail")
    @ApiOperation(value = "动态详情", tags = {"发现管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
            @ApiImplicitParam(name = "id", value = "动态id")
    })
    public ResultUtil<FindVO> findDetail(Integer id) {
        Find find1 = findService.selectById(id);
        FindVO findVO = new FindVO();
        findVO.setId(find1.getId());
        findVO.setUserId(find1.getUserId());
        findVO.setInsertTime(find1.getInsertTime());
        findVO.setLikeCount(find1.getLikeCount());
        findVO.setTitle(find1.getTitle());
        findVO.setContent(find1.getContent());
        findVO.setImg(find1.getImg());
        findVO.setVideo(find1.getVideo());
        findVO.setIsTop(find1.getIsTop());
        findVO.setIsDelete(find1.getIsDelete());
        findVO.setPhone(appUserService.selectById(find1.getUserId()).getPhone());
        // 计算每个动态的评论数量
        int size = findCommentService.selectList(new EntityWrapper<FindComment>()
                .eq("findId", find1.getId())
                .eq("isShow", 1)).size();
        findVO.setComment(size);
        AppUser appUser = appUserService.selectById(find1.getUserId());
        findVO.setHeadImg(appUser.getHeadImg());
        findVO.setUserName(appUser.getName());
        findVO.setClockIn(appUser.getClockIn());
//        // 查询一级评论
//        List<CommentVO> one = findCommentService.getCommentOne(id);
//        for (CommentVO comment : one) {
//            // 查询这条评论下面的子评论
//            List<CommentVO> two = findCommentService.getCommentTwo(comment.getId());
//            comment.setCommentList(two);
//        }
//        findVO.setCommentList(one);
        return ResultUtil.success(findVO);
    }
    @ResponseBody
    @PostMapping("/base/find/updateState")
    @ApiOperation(value = "上架/下架/删除/置顶/修改点赞数", tags = {"发现管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "动态id", required = true),
            @ApiImplicitParam(name = "type", value = "类型 1 = 上架 2 = 下架 3=删除 4=是否置顶(0否1是) 5=修改点赞数", required = true),
            @ApiImplicitParam(name = "temp", value = "当type为4时该字段是否置顶填0否或者1是 type=5该字段填点赞数 type=123该字段不填")
    })
    public ResultUtil Like(Integer id,Integer type,Integer temp) {
        Find find = findService.selectById(id);
        if (type == 2){
            // 还需要发送一条消息给用户
            Message message = new Message();
            message.setUserId(find.getUserId());
            message.setType(1);
            message.setContent("您的动态\""+find.getTitle()+"\"已被下架");
            message.setInsertTime(new Date());
            message.setIsRead(0);
            messageService.insert(message);
        }
        if (type==1||type==2){
            find.setState(type);
        }
        if (type == 3){
            find.setIsDelete(1);
        }
        if (type==4){
            find.setIsTop(temp);
        }
        if (type==5){
            find.setLikeCount(temp);
        }
        findService.updateById(find);
        return ResultUtil.success();
    }
 
}