无关风月
2025-02-08 bbc55de9bb0f6e5d3d8267c628d25780c19ebf36
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
package com.xinquan.meditation.controller.client;
 
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinquan.common.core.constant.SecurityConstants;
import com.xinquan.common.core.domain.R;
import com.xinquan.common.core.utils.page.BeanUtils;
import com.xinquan.common.core.utils.page.PageDTO;
import com.xinquan.common.log.annotation.Log;
import com.xinquan.common.log.enums.BusinessType;
import com.xinquan.common.security.service.TokenService;
import com.xinquan.meditation.domain.HomeBackgroundMusic;
import com.xinquan.meditation.domain.HomeBackgroundMusicUser;
import com.xinquan.meditation.domain.vo.ClientHomeBackgroundMusicVO;
import com.xinquan.meditation.domain.vo.ClientMeditationAndCateVO;
import com.xinquan.meditation.domain.vo.ClientMeditationCategoryVO;
import com.xinquan.meditation.domain.vo.ClientMeditationDetailsVO;
import com.xinquan.meditation.domain.vo.ClientMeditationEverydayVO;
import com.xinquan.meditation.domain.vo.ClientMeditationQuestionVO;
import com.xinquan.meditation.domain.vo.ClientMeditationVO;
import com.xinquan.meditation.service.*;
import com.xinquan.system.api.RemoteHotWordsService;
import com.xinquan.meditation.api.domain.MeditationQuestion;
import com.xinquan.system.api.model.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
/**
 * <p>
 * 首页相关接口
 * </p>
 *
 * @author mitao
 * @since 2024-08-21
 */
@Api(tags = {"用户端-首页相关接口"})
@RestController
@RequiredArgsConstructor
@RequestMapping("/client/meditation/home")
public class ClientHomeController {
 
    private final HomeBackgroundMusicService homeBackgroundMusicService;
    private final MeditationService meditationService;
    private final MeditationCategoryService meditationCategoryService;
    private final MeditationEverydayService meditationEverydayService;
    @Resource
    private  RemoteHotWordsService remoteHotWordsService;
    private final MeditationQuestionService meditationQuestionService;
    @Autowired
    private HomeBackgroundMusicUserService homeBackgroundMusicUserService;
    @Autowired
    private TokenService tokenService;
    // 新增需求 用户注册默认给一个背景音频设置
    @GetMapping("/addHomeBackgroundMusicDefault/{id}")
    public R addHomeBackgroundMusicDefault(@PathVariable("id") Long id) {
        List<HomeBackgroundMusic> list = homeBackgroundMusicService.list();
        if (!list.isEmpty()) {
            List<HomeBackgroundMusicUser> homeBackgroundMusicUserList = homeBackgroundMusicUserService.lambdaQuery().eq(HomeBackgroundMusicUser::getAppUserId, id).list();
            if (homeBackgroundMusicUserList.isEmpty()) {
                HomeBackgroundMusicUser homeBackgroundMusicUser = new HomeBackgroundMusicUser();
                homeBackgroundMusicUser.setAppUserId(id);
                homeBackgroundMusicUser.setHomeBackgroundMusicId(list.get(0).getId());
                homeBackgroundMusicUserService.save(homeBackgroundMusicUser);
            }
        }
        return R.ok();
    }
    @GetMapping("/listHomeBackgroundMusic")
    @ApiOperation(value = "背景音乐列表查询-分页", tags = "管理后台-首页背景音乐管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true)})
    public R<PageDTO<HomeBackgroundMusic>> listHomeBackgroundMusic(@RequestParam Integer pageCurr, @RequestParam Integer pageSize) {
 
        // 查询
        Page<HomeBackgroundMusic> page = homeBackgroundMusicService.lambdaQuery()
                .orderByDesc(HomeBackgroundMusic::getSortNum)
                .page(new Page<>(pageCurr, pageSize));
        // 如果没有查到数据直接返回
        if (page.getRecords().isEmpty()) {
            return R.ok(PageDTO.empty(page));
        }
        for (HomeBackgroundMusic homeBackgroundMusic : page.getRecords()) {
            homeBackgroundMusic.setUid(homeBackgroundMusic.getId() + "");
        }
        return R.ok(PageDTO.of(page, HomeBackgroundMusic.class));
    }
 
    @PostMapping("/addHomeBackgroundMusic")
    @Log(title = "【首页背景音乐管理】新增", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增背景", tags = "管理后台-首页背景音乐管理")
    public R addHomeBackgroundMusic(@RequestBody HomeBackgroundMusic homeBackgroundMusic) {
        return R.ok(homeBackgroundMusicService.save(homeBackgroundMusic));
    }
    @GetMapping("/detailHomeBackgroundMusic")
    @ApiOperation(value = "查看详情", tags = "管理后台-首页背景音乐管理")
    public R<HomeBackgroundMusic> detailHomeBackgroundMusic(String uid) {
        return R.ok(homeBackgroundMusicService.getById(uid));
    }
    @PostMapping("/updateHomeBackgroundMusic")
    @ApiOperation(value = "修改背景", tags = "管理后台-首页背景音乐管理")
    @Log(title = "【首页背景音乐管理】修改", businessType = BusinessType.UPDATE)
    public R updateHomeBackgroundMusic(@RequestBody HomeBackgroundMusic homeBackgroundMusic) {
        homeBackgroundMusicService.updateById(homeBackgroundMusic);
        LambdaUpdateWrapper<HomeBackgroundMusic> homeBackgroundMusicLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        if (homeBackgroundMusic.getBackUrl()==null){
            homeBackgroundMusicLambdaUpdateWrapper.set(HomeBackgroundMusic::getBackUrl,null);
            homeBackgroundMusicLambdaUpdateWrapper.set(HomeBackgroundMusic::getBackName,null);
        }
        return R.ok();
    }
    @PostMapping("/deleteHomeBackgroundMusic")
    @ApiOperation(value = "批量删除", tags = "管理后台-首页背景音乐管理")
    @Log(title = "【首页背景音乐管理】批量删除", businessType = BusinessType.DELETE)
 
    public R deleteHomeBackgroundMusic(String ids) {
        return R.ok(homeBackgroundMusicService.removeBatchByIds(Arrays.asList(ids.split(",")).stream().map(Long::valueOf).collect(Collectors.toList())));
    }
    /**
     * 获取首页背景音乐列表
     *
     * @return 背景音乐列表
     */
    @GetMapping("/getHomeBackgroundMusicList")
    @ApiOperation(value = "获取首页背景音乐列表", notes = "首页顶部默认展示该接口返回的列表中第一条数据的背景图片")
    public R<List<ClientHomeBackgroundMusicVO>> getHomeBackgroundMusicList() {
        return R.ok(homeBackgroundMusicService.getHomeBackgroundMusicList());
    }
    @PostMapping("/saveUserHomeBackgroundMusic")
    @ApiOperation(value = "保存用户首页背景音频设置", notes = "保存用户首页背景音频设置")
    @Log(title = "【用户首页背景音频设置】修改", businessType = BusinessType.UPDATE)
 
    @ApiImplicitParam(name = "id", value = "首页背景音频id", dataType = "Long", required = true)
    public R saveUserHomeBackgroundMusic(@RequestParam("id") Long id) {
        if (tokenService.getLoginUser()==null) {
            return R.tokenError("登录失效");
        }
        HomeBackgroundMusicUser one = homeBackgroundMusicUserService.lambdaQuery()
                .eq(HomeBackgroundMusicUser::getAppUserId, tokenService.getLoginUser().getAppUserId()).one();
        if (one!=null){
            one.setHomeBackgroundMusicId(id);
            homeBackgroundMusicUserService.updateById(one);
        }else{
            HomeBackgroundMusicUser homeBackgroundMusicUser = new HomeBackgroundMusicUser();
            homeBackgroundMusicUser.setAppUserId(tokenService.getLoginUser().getAppUserId());
            homeBackgroundMusicUser.setHomeBackgroundMusicId(id);
            homeBackgroundMusicUserService.save(homeBackgroundMusicUser);
        }
        return R.ok();
    }
    @GetMapping("/getHomeBackgroundMusicByUserId")
    @ApiOperation(value = "获取用户设置的首页背景音乐", notes = "获取用户设置的首页背景音乐")
    public R<ClientHomeBackgroundMusicVO> getHomeBackgroundMusicByUserId() {
        if (tokenService.getLoginUser()==null){
            // 游客登录模式 不要返回登录失效 返回空即可
            return R.ok(new ClientHomeBackgroundMusicVO());
        }
        HomeBackgroundMusicUser homeBackgroundMusicUser = homeBackgroundMusicUserService.lambdaQuery()
                .eq(HomeBackgroundMusicUser::getAppUserId, tokenService.getLoginUser().getAppUserId())
                .one();
        if (homeBackgroundMusicUser==null){
            return R.ok(new ClientHomeBackgroundMusicVO());
        }
        HomeBackgroundMusic homeBackgroundMusic = homeBackgroundMusicService.lambdaQuery()
                .eq(HomeBackgroundMusic::getId, homeBackgroundMusicUser.getHomeBackgroundMusicId())
                .one();
        if (homeBackgroundMusic==null)return R.ok(new ClientHomeBackgroundMusicVO());
        ClientHomeBackgroundMusicVO clientHomeBackgroundMusicVO = new ClientHomeBackgroundMusicVO();
        BeanUtils.copyProperties(homeBackgroundMusic, clientHomeBackgroundMusicVO);
        return R.ok(clientHomeBackgroundMusicVO);
    }
 
 
    /**
     * 根据类型获取冥想分类列表
     *
     * @param type 分类类型
     * @return 分类列表
     */
    @PostMapping("/getCategoryListByType")
    @ApiOperation("根据类型获取冥想音频分类列表")
    @ApiImplicitParam(name = "type", value = "类型 1=顶部4个 2=下面3个", required = true)
    public R<List<ClientMeditationCategoryVO>> getCategoryListByType(
            @RequestParam(value = "type") Integer type) {
        return R.ok(meditationCategoryService.getCategoryListByType(type));
    }
 
    /**
     * 获取冥想分类列表
     *
     * @return 冥想分类列表
     */
    @GetMapping("/getCategoryList")
    @ApiOperation("获取冥想音频分类列表")
    public R<List<ClientMeditationCategoryVO>> getCategoryList() {
        return R.ok(meditationCategoryService.getCategoryList());
    }
 
    /**
     * 查询每日冥想
     *
     * @return 每日冥想
     */
    @GetMapping("/getTodayMeditation")
    @ApiOperation("获取今日冥想")
    public R<ClientMeditationEverydayVO> getTodayMeditation() {
        return R.ok(meditationEverydayService.getTodayMeditation());
    }
 
    /**
     * 获取私人订制
     *
     * @return 冥想列表
     */
    @GetMapping("/getPersonalityPlan")
    @ApiOperation("获取私人订制")
    public R<List<ClientMeditationVO>> getPersonalityPlan() {
//        LoginUser loginUser = tokenService.getLoginUser();
//        if (loginUser==null){
//            return R.tokenError("登录失效");
//        }
//        Long userId = loginUser.getUserid();
        return R.ok(meditationService.getPersonalityPlan());
    }
 
    /**
     * 根据分类id获取冥想列表
     *
     * @param cateId 分类id
     * @return 冥想列表
     */
    @PostMapping("/getMeditationListByCateId")
    @ApiOperation("根据分类id获取冥想音频列表")
    @ApiImplicitParam(name = "cateId", value = "分类id", dataType = "Long", required = true)
    public R<List<ClientMeditationVO>> getMeditationListByCateId(
            @RequestParam("cateId") Long cateId) {
        return R.ok(meditationService.getMeditationListByCateId(cateId));
    }
 
    /**
     * 获取全部的冥想及分类列表
     *
     * @return 冥想及分类列表
     */
    @GetMapping("/getMeditationAndCateList")
    @ApiOperation(value = "获取全部的冥想音频及分类列表", notes = "用于首页列表展示")
    public R<List<ClientMeditationAndCateVO>> getMeditationAndCateList() {
        return R.ok(meditationService.getMeditationAndCateList());
    }
 
    /**
     * 根据分类id获取冥想列表-分页
     *
     * @param cateId   分类id
     * @param pageCurr 当前页码
     * @param pageSize 每页数量
     * @return 冥想列表
     */
    @PostMapping("/getMeditationPageByCateId")
    @ApiOperation(value = "根据分类id获取冥想音频列表-分页", notes = "查看更多")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cateId", value = "分类id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true)})
    public R<PageDTO<ClientMeditationVO>> getMeditationPageByCateId(@RequestParam Long cateId,
            @RequestParam Integer pageCurr, @RequestParam Integer pageSize) {
        return R.ok(meditationService.getMeditationPageByCateId(cateId, pageCurr, pageSize));
    }
 
    /**
     * 首页搜索首页
     *
     * @param condition 搜索条件
     * @param pageCurr  当前页码
     * @param pageSize  每页数量
     * @return 冥想列表
     */
    @PostMapping("/search")
    @ApiOperation("首页搜索冥想音频")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "condition", value = "查询条件", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true)
    })
    public R<PageDTO<ClientMeditationVO>> search(@RequestParam String condition,
            @RequestParam Integer                    pageCurr, @RequestParam Integer pageSize) {
 
 
        return R.ok(meditationService.search(condition, pageCurr, pageSize));
    }
 
    /**
     * 获取热词列表
     *
     * @return 热词列表
     */
    @GetMapping("/getHotWordList")
    @ApiOperation("获取热词列表")
    public R<List<String>> getHotWordList() {
        return R.ok(remoteHotWordsService.getHotWordList(SecurityConstants.INNER).getData());
    }
 
    /**
     * 获取冥想音频详情
     *
     * @param id 冥想音频id
     * @return 客户端冥想详情视图对象
     */
    @GetMapping("/getMeditationDetails")
    @ApiOperation("获取冥想音频详情")
    @ApiImplicitParam(name = "id", value = "冥想音频id", dataType = "Long", required = true)
    public R<ClientMeditationDetailsVO> getMeditationDetails(@RequestParam("id") Long id) {
 
        return meditationService.getMeditationDetails(id);
    }
    @GetMapping("/getMeditationDetailsShare")
    @ApiOperation(value = "获取冥想音频详情",tags = "H5分享")
    @ApiImplicitParam(name = "id", value = "冥想音频id", dataType = "Long", required = true)
    public R<ClientMeditationDetailsVO> getMeditationDetailsShare(Long id) {
        return R.ok(meditationService.getMeditationDetails1(id));
    }
 
    /**
     * 收藏/取消收藏
     *
     * @param id 冥想音频id
     */
    @PostMapping("/favorite")
    @ApiOperation(value = "收藏/取消收藏")
    @ApiImplicitParam(name = "id", value = "冥想音频id", dataType = "Long", required = true)
    public R<?> favorite(@RequestParam("id") Long id) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (loginUser==null){
            return R.tokenError("登录失效");
        }
        Long userId = loginUser.getUserid();
        meditationService.favorite(id);
        return R.ok();
    }
 
    /**
     * 获取冥想音频提问列表-分页
     *
     * @param id       冥想音频id
     * @param pageCurr 当前页码
     * @param pageSize 每页数量
     * @return 冥想音频提问分页列表
     */
    @GetMapping("/getMeditationQuestionPage")
    @ApiOperation(value = "获取冥想音频提问列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "冥想音频id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true)
    })
    public R<PageDTO<ClientMeditationQuestionVO>> getMeditationQuestionPage(
            @RequestParam("id") Long id, @RequestParam("pageCurr") Integer pageCurr,
            @RequestParam("pageSize") Integer pageSize) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (loginUser==null){
            return R.tokenError("登录失效");
        }
        Long userId = loginUser.getUserid();
        return R.ok(meditationService.getMeditationQuestionPage(id, pageCurr, pageSize));
    }
    @GetMapping("/getMeditationQuestionPageShare")
    @ApiOperation(value = "获取冥想音频提问列表-分页",tags = "H5分享")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "冥想音频id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true)
    })
    public R<PageDTO<ClientMeditationQuestionVO>> getMeditationQuestionPageShare(
            @RequestParam("id") Long id, @RequestParam("pageCurr") Integer pageCurr,
            @RequestParam("pageSize") Integer pageSize) {
        return R.ok(meditationService.getMeditationQuestionPageShare(id, pageCurr, pageSize));
    }
 
    @PostMapping("/addQuestion")
    @ApiOperation(value = "发布提问")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "meditationId", value = "冥想音频id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "content", value = "提问内容", dataType = "String", required = true),
    })
    public R addQuestion(Long meditationId,String content) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (loginUser==null){
            return R.tokenError("登录失效");
        }
        Long userId = loginUser.getUserid();
        MeditationQuestion meditationQuestion = new MeditationQuestion();
        meditationQuestion.setMeditationId(meditationId);
        meditationQuestion.setLikeCount(0);
        meditationQuestion.setFavorite(2);
        meditationQuestion.setContent(content);
        meditationQuestion.setPublishTime(LocalDateTime.now());
        meditationQuestion.setAppUserId(userId);
        meditationQuestion.setShowFlag(2);
        meditationQuestion.setReportStatus(1);
        meditationQuestionService.save(meditationQuestion);
        return R.ok();
    }
    /**
     * 举报提问
     *
     * @param id      提问id
     * @param content 举报内容
     */
    @PostMapping("/report")
    @ApiOperation("举报提问")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "提问id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "reason", value = "举报原因", dataType = "String", required = true)
    })
    public R<?> report(@RequestParam("id") Long id, @RequestParam("reason") String content) {
        meditationQuestionService.report(id, content);
        return R.ok();
    }
 
    /**
     * 点赞/取消点赞提问
     *
     * @param id 提问id
     */
    @PostMapping("/likeQuestion")
    @ApiOperation("点赞/取消点赞提问")
    @ApiImplicitParam(name = "id", value = "提问id", dataType = "Long", required = true)
    public R<?> likeQuestion(@RequestParam("id") Long id) {
        meditationQuestionService.likeQuestion(id);
        return R.ok();
    }
}