| | |
| | | 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.meditation.api.domain.Meditation; |
| | | 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.ClientMeditationEverydayVO; |
| | | import com.xinquan.meditation.domain.vo.ClientMeditationQuestionVO; |
| | | import com.xinquan.meditation.domain.vo.ClientMeditationVO; |
| | | import com.xinquan.meditation.service.HomeBackgroundMusicService; |
| | | import com.xinquan.meditation.service.MeditationCategoryService; |
| | | import com.xinquan.meditation.service.MeditationEverydayService; |
| | | import com.xinquan.meditation.service.MeditationQuestionService; |
| | | import com.xinquan.meditation.service.MeditationService; |
| | | import com.xinquan.meditation.service.*; |
| | | import com.xinquan.system.api.RemoteHotWordsService; |
| | | import com.xinquan.system.api.domain.AppUser; |
| | | 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.Optional; |
| | | 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> |
| | |
| | | private final MeditationService meditationService; |
| | | private final MeditationCategoryService meditationCategoryService; |
| | | private final MeditationEverydayService meditationEverydayService; |
| | | private final RemoteHotWordsService remoteHotWordsService; |
| | | @Resource |
| | | private RemoteHotWordsService remoteHotWordsService; |
| | | private final MeditationQuestionService meditationQuestionService; |
| | | |
| | | @PostMapping("/listHomeBackgroundMusic") |
| | | @ApiOperation(value = "背景音乐列表查询-分页", notes = "管理后台-首页背景音乐管理") |
| | | @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) { |
| | | PageDTO<HomeBackgroundMusic> pageDTO = PageDTO.empty(0L, 0L); |
| | | |
| | | // 查询 |
| | | Page<HomeBackgroundMusic> page = homeBackgroundMusicService.lambdaQuery() |
| | | .orderByDesc(HomeBackgroundMusic::getSortNum) |
| | | .page(new Page<>(pageCurr, pageSize)); |
| | | // 如果没有查到数据直接返回 |
| | | if (Optional.ofNullable(page.getRecords()).isPresent()) { |
| | | return R.ok(pageDTO); |
| | | if (page.getRecords().isEmpty()) { |
| | | return R.ok(PageDTO.empty(page)); |
| | | } |
| | | // 将实体类转换为VO |
| | | pageDTO = PageDTO.of(page, HomeBackgroundMusic.class); |
| | | for (HomeBackgroundMusic homeBackgroundMusic : pageDTO.getList()) { |
| | | for (HomeBackgroundMusic homeBackgroundMusic : page.getRecords()) { |
| | | homeBackgroundMusic.setUid(homeBackgroundMusic.getId() + ""); |
| | | } |
| | | return R.ok(pageDTO); |
| | | return R.ok(PageDTO.of(page, HomeBackgroundMusic.class)); |
| | | } |
| | | |
| | | @PostMapping("/addHomeBackgroundMusic") |
| | | @ApiOperation(value = "新增背景", notes = "管理后台-首页背景音乐管理") |
| | | @Log(title = "【首页背景音乐管理】新增", businessType = BusinessType.INSERT) |
| | | @ApiOperation(value = "新增背景", tags = "管理后台-首页背景音乐管理") |
| | | public R addHomeBackgroundMusic(@RequestBody HomeBackgroundMusic homeBackgroundMusic) { |
| | | return R.ok(homeBackgroundMusicService.save(homeBackgroundMusic)); |
| | | } |
| | | @GetMapping("/detailHomeBackgroundMusic") |
| | | @ApiOperation(value = "查看详情", notes = "管理后台-首页背景音乐管理") |
| | | public R detailHomeBackgroundMusic(String uid) { |
| | | @ApiOperation(value = "查看详情", tags = "管理后台-首页背景音乐管理") |
| | | public R<HomeBackgroundMusic> detailHomeBackgroundMusic(String uid) { |
| | | return R.ok(homeBackgroundMusicService.getById(uid)); |
| | | } |
| | | @PostMapping("/updateHomeBackgroundMusic") |
| | | @ApiOperation(value = "修改背景", notes = "管理后台-首页背景音乐管理") |
| | | @ApiOperation(value = "修改背景", tags = "管理后台-首页背景音乐管理") |
| | | @Log(title = "【首页背景音乐管理】修改", businessType = BusinessType.UPDATE) |
| | | public R updateHomeBackgroundMusic(@RequestBody HomeBackgroundMusic homeBackgroundMusic) { |
| | | return R.ok(homeBackgroundMusicService.updateById(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 = "批量删除", notes = "管理后台-首页背景音乐管理") |
| | | @ApiOperation(value = "批量删除", tags = "管理后台-首页背景音乐管理") |
| | | @Log(title = "【首页背景音乐管理】批量删除", businessType = BusinessType.DELETE) |
| | | |
| | | public R deleteHomeBackgroundMusic(String ids) { |
| | | return R.ok(homeBackgroundMusicService.removeBatchByIds(Arrays.asList(ids.split(",")))); |
| | | return R.ok(homeBackgroundMusicService.removeBatchByIds(Arrays.asList(ids.split(",")).stream().map(Long::valueOf).collect(Collectors.toList()))); |
| | | } |
| | | /** |
| | | * 获取首页背景音乐列表 |
| | |
| | | public R<List<ClientHomeBackgroundMusicVO>> getHomeBackgroundMusicList() { |
| | | return R.ok(homeBackgroundMusicService.getHomeBackgroundMusicList()); |
| | | } |
| | | @PostMapping("/saveUserHomeBackgroundMusic") |
| | | @ApiOperation(value = "保存用户首页背景音频设置", notes = "保存用户首页背景音频设置") |
| | | @Log(title = "【用户首页背景音频设置】修改", businessType = BusinessType.UPDATE) |
| | | |
| | | /** |
| | | * 保存用户首页背景音乐设置 |
| | | * |
| | | * @param id 首页背景音乐id |
| | | */ |
| | | @PostMapping("/savePersonalitySetting") |
| | | @ApiOperation(value = "保存用户首页背景音乐设置") |
| | | @ApiImplicitParam(name = "id", value = "首页背景音乐id", required = true) |
| | | public R<?> savePersonalitySetting(@RequestParam("id") Long id) { |
| | | homeBackgroundMusicService.savePersonalitySetting(id); |
| | | @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){ |
| | | // 游客登录模式 不要返回登录失效 返回空即可 |
| | | List<HomeBackgroundMusic> list = homeBackgroundMusicService.list(); |
| | | if (list.isEmpty()){ |
| | | return R.ok(new ClientHomeBackgroundMusicVO()); |
| | | } |
| | | ClientHomeBackgroundMusicVO clientHomeBackgroundMusicVO = new ClientHomeBackgroundMusicVO(); |
| | | BeanUtils.copyProperties(list.get(0), clientHomeBackgroundMusicVO); |
| | | return R.ok(clientHomeBackgroundMusicVO); |
| | | } |
| | | HomeBackgroundMusicUser homeBackgroundMusicUser = homeBackgroundMusicUserService.lambdaQuery() |
| | | .eq(HomeBackgroundMusicUser::getAppUserId, tokenService.getLoginUser().getAppUserId()) |
| | | .one(); |
| | | if (homeBackgroundMusicUser==null){ |
| | | List<HomeBackgroundMusic> list = homeBackgroundMusicService.list(); |
| | | if (list.isEmpty()){ |
| | | return R.ok(new ClientHomeBackgroundMusicVO()); |
| | | } |
| | | ClientHomeBackgroundMusicVO clientHomeBackgroundMusicVO = new ClientHomeBackgroundMusicVO(); |
| | | BeanUtils.copyProperties(list.get(0), clientHomeBackgroundMusicVO); |
| | | return R.ok(clientHomeBackgroundMusicVO); |
| | | } |
| | | HomeBackgroundMusic homeBackgroundMusic = homeBackgroundMusicService.lambdaQuery() |
| | | .eq(HomeBackgroundMusic::getId, homeBackgroundMusicUser.getHomeBackgroundMusicId()) |
| | | .one(); |
| | | if (homeBackgroundMusic==null){ |
| | | List<HomeBackgroundMusic> list = homeBackgroundMusicService.list(); |
| | | if (list.isEmpty()){ |
| | | return R.ok(new ClientHomeBackgroundMusicVO()); |
| | | } |
| | | ClientHomeBackgroundMusicVO clientHomeBackgroundMusicVO = new ClientHomeBackgroundMusicVO(); |
| | | BeanUtils.copyProperties(list.get(0), clientHomeBackgroundMusicVO); |
| | | return R.ok(clientHomeBackgroundMusicVO); |
| | | } |
| | | ClientHomeBackgroundMusicVO clientHomeBackgroundMusicVO = new ClientHomeBackgroundMusicVO(); |
| | | BeanUtils.copyProperties(homeBackgroundMusic, clientHomeBackgroundMusicVO); |
| | | return R.ok(clientHomeBackgroundMusicVO); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据类型获取冥想分类列表 |
| | |
| | | @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()); |
| | | } |
| | | |
| | |
| | | }) |
| | | public R<PageDTO<ClientMeditationVO>> search(@RequestParam String condition, |
| | | @RequestParam Integer pageCurr, @RequestParam Integer pageSize) { |
| | | |
| | | |
| | | return R.ok(meditationService.search(condition, pageCurr, pageSize)); |
| | | } |
| | | |
| | |
| | | @ApiOperation("获取冥想音频详情") |
| | | @ApiImplicitParam(name = "id", value = "冥想音频id", dataType = "Long", required = true) |
| | | public R<ClientMeditationDetailsVO> getMeditationDetails(@RequestParam("id") Long id) { |
| | | return R.ok(meditationService.getMeditationDetails(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)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @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(); |
| | | } |
| | |
| | | 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(); |
| | | } |
| | | /** |
| | | * 举报提问 |
| | | * |