| | |
| | | package com.xinquan.meditation.controller.client; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xinquan.common.core.domain.R; |
| | | import com.xinquan.common.core.utils.page.CollUtils; |
| | | import com.xinquan.common.core.utils.page.PageDTO; |
| | | import com.xinquan.common.security.utils.SecurityUtils; |
| | | import com.xinquan.course.api.domain.Course; |
| | | import com.xinquan.meditation.api.domain.Meditation; |
| | | import com.xinquan.meditation.domain.MeditationHall; |
| | | import com.xinquan.meditation.domain.vo.ClientMeditationQuestionVO; |
| | | import com.xinquan.meditation.service.MeditationHallService; |
| | | import com.xinquan.meditation.service.MeditationService; |
| | | import com.xinquan.meditation.api.domain.dto.MeditationDTO; |
| | | import com.xinquan.meditation.api.domain.dto.UserAnswerDTO; |
| | | import com.xinquan.meditation.domain.*; |
| | | import com.xinquan.meditation.service.*; |
| | | import com.xinquan.system.api.domain.AppUser; |
| | | import com.xinquan.system.api.domain.MeditationQuestion; |
| | | import com.xinquan.system.api.domain.NoticeRecord; |
| | | import com.xinquan.system.api.domain.Tag; |
| | | import com.xinquan.user.api.feign.RemoteAppUserService; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RequestMapping("/client/meditation/meditation") |
| | | public class ClientMeditationController { |
| | | |
| | | private final MeditationService meditationService; |
| | | private final MeditationHallService meditationHallService; |
| | | @Autowired |
| | | private MeditationService meditationService; |
| | | @Autowired |
| | | private MeditationHallService meditationHallService; |
| | | @Autowired |
| | | private MeditationUserFavoriteService meditationUserFavoriteService; |
| | | @Autowired |
| | | private MeditationTagService meditationTagService; |
| | | @Autowired |
| | | private MeditationMusicService meditationMusicService; |
| | | @Autowired |
| | | private MeditationCategoryService meditationCategoryService; |
| | | @Autowired |
| | | private MeditationQuestionService meditationQuestionService; |
| | | |
| | | @Resource |
| | | private RemoteAppUserService remoteAppUserService; |
| | | |
| | | /** |
| | | * 远程调用 通过疗愈名字查询疗愈ids |
| | | * @return |
| | | */ |
| | | @PostMapping("/getMeditationIdsByName/{name}") |
| | | public R<List<Long>> getMeditationIdsByName(@PathVariable("name") String name) { |
| | | List<Long> collect = meditationService.lambdaQuery().like(Meditation::getMeditationTitle, name) |
| | | .list().stream().map(Meditation::getId) |
| | | .collect(Collectors.toList()); |
| | | return R.ok(collect); |
| | | } |
| | | @GetMapping("/getMeditationById/{pageCurr}/{pageSize}") |
| | | public R<Page<Meditation>> getMeditationById(@PathVariable("pageCurr") Integer pageCurr,@PathVariable("pageSize") Integer pageSize) |
| | | { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId == 0)return R.tokenError("登录失效"); |
| | | List<Long> collect = meditationUserFavoriteService |
| | | .lambdaQuery() |
| | | .eq(MeditationUserFavorite::getAppUserId, userId).list().stream() |
| | | .map(MeditationUserFavorite::getId).collect(Collectors.toList()); |
| | | Page<Meditation> page = meditationService |
| | | .lambdaQuery() |
| | | .in(Meditation::getId, collect) |
| | | .page(new Page<>(pageCurr, pageSize)); |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(page); |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | @GetMapping("/getMeditationById/{id}") |
| | | public R<Meditation> getMeditationById(@PathVariable("id") Long id) |
| | | { |
| | | Meditation byId = meditationService.getById(id); |
| | | MeditationCategory byId1 = meditationCategoryService.getById(byId.getCateId()); |
| | | byId.setCategoryName(byId1.getCategoryName()); |
| | | return R.ok(byId); |
| | | } |
| | | /** |
| | | * 获取冥想馆列表 |
| | | */ |
| | |
| | | MeditationHall byId = meditationHallService.getById(id); |
| | | return R.ok(byId); |
| | | } |
| | | @PostMapping("/meditationManagementList") |
| | | @ApiOperation(value = "冥想音频列表-分页", tags = {"管理后台-冥想音频管理"}) |
| | | public R<PageDTO<Meditation>> meditationManagementList(@RequestBody MeditationDTO dto) { |
| | | List<Long> longs = new ArrayList<>(); |
| | | if (!dto.getTagName().isEmpty()){ |
| | | List<Tag> data = remoteAppUserService.queryTag(dto.getTagName()).getData(); |
| | | if (data.isEmpty()){ |
| | | longs.add(-1L); |
| | | }else{ |
| | | longs.addAll(data.stream().map(Tag::getId).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | List<Long> collect = meditationTagService.lambdaQuery().in(MeditationTag::getTagId) |
| | | .list().stream().map(MeditationTag::getMeditationId) |
| | | .collect(Collectors.toList()); |
| | | if (collect.isEmpty()){ |
| | | collect.add(-1L); |
| | | } |
| | | LambdaQueryWrapper<Meditation> courseLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | courseLambdaQueryWrapper.eq(dto.getSanskrit()!=null,Meditation::getSanskrit, dto.getSanskrit()); |
| | | courseLambdaQueryWrapper.in(Meditation::getId, collect); |
| | | courseLambdaQueryWrapper.eq(dto.getChargeType()!=null,Meditation::getChargeType, dto.getChargeType()); |
| | | courseLambdaQueryWrapper.eq(dto.getCateId()!=null,Meditation::getCateId, dto.getCateId()); |
| | | courseLambdaQueryWrapper.eq(dto.getMeditationTitle()!=null&& !dto.getMeditationTitle().isEmpty(),Meditation::getMeditationTitle, dto.getMeditationTitle()); |
| | | courseLambdaQueryWrapper.orderByDesc(Meditation::getSortNum); |
| | | Page<Meditation> page = meditationService.page(new Page<>(dto.getPageCurr(), dto.getPageSize()), courseLambdaQueryWrapper); |
| | | if (CollUtils.isEmpty(page.getRecords())) { |
| | | return R.ok(PageDTO.empty(page)); |
| | | } |
| | | for (Meditation record : page.getRecords()) { |
| | | record.setUid(record.getId()+""); |
| | | MeditationCategory byId = meditationCategoryService.getById(record.getCateId()); |
| | | if (byId!=null){ |
| | | record.setCategoryName(byId.getCategoryName()); |
| | | } |
| | | } |
| | | return R.ok(PageDTO.of(page, Meditation.class)); |
| | | } |
| | | |
| | | @PostMapping("/addMeditation") |
| | | @ApiOperation(value = "新增冥想音频管理", notes = "管理后台-冥想音频管理") |
| | | public R addMeditation(@RequestBody Meditation homeBackgroundMusic) { |
| | | homeBackgroundMusic.setCreateBy(SecurityUtils.getUsername()); |
| | | homeBackgroundMusic.setCreateTime(LocalDateTime.now()); |
| | | meditationService.save(homeBackgroundMusic); |
| | | if (!homeBackgroundMusic.getTagIds().isEmpty()){ |
| | | String[] split = homeBackgroundMusic.getTagIds().split(","); |
| | | List<MeditationTag> meditationTags = new ArrayList<>(); |
| | | for (int i = 0; i < split.length; i++) { |
| | | MeditationTag meditationTag = new MeditationTag(); |
| | | meditationTag.setMeditationId(homeBackgroundMusic.getId()); |
| | | meditationTag.setTagId(Long.valueOf(split[i])); |
| | | meditationTags.add(meditationTag); |
| | | } |
| | | meditationTagService.saveBatch(meditationTags); |
| | | } |
| | | if (!homeBackgroundMusic.getMusicUrls().isEmpty()){ |
| | | String[] split = homeBackgroundMusic.getMusicUrls().split(","); |
| | | List<MeditationMusic> meditationTags = new ArrayList<>(); |
| | | for (int i = 0; i < split.length; i++) { |
| | | MeditationMusic meditationTag = new MeditationMusic(); |
| | | meditationTag.setMeditationId(homeBackgroundMusic.getId()); |
| | | meditationTag.setMusicUrl(split[i]); |
| | | meditationTag.setMusicSecond(Integer.valueOf(homeBackgroundMusic.getMusicSecond().split(",")[i])); |
| | | meditationTags.add(meditationTag); |
| | | } |
| | | meditationMusicService.saveBatch(meditationTags); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @GetMapping("/detailMeditation") |
| | | @ApiOperation(value = "查看详情冥想音频管理", notes = "管理后台-冥想音频管理") |
| | | public R<Meditation> detailMeditation(String uid) { |
| | | Meditation byId = meditationService.getById(uid); |
| | | List<Long> collect = meditationTagService.list(new LambdaQueryWrapper<MeditationTag>() |
| | | .eq(MeditationTag::getMeditationId, uid)) |
| | | .stream().map(MeditationTag::getTagId) |
| | | .collect(Collectors.toList()); |
| | | List<String> collect1 = meditationMusicService.list(new LambdaQueryWrapper<MeditationMusic>() |
| | | .eq(MeditationMusic::getMeditationId, uid)) |
| | | .stream().map(MeditationMusic::getMusicUrl) |
| | | .collect(Collectors.toList()); |
| | | byId.setMusicList(collect1); |
| | | byId.setTagList(collect); |
| | | MeditationCategory byId1 = meditationCategoryService.getById(byId.getCateId()); |
| | | if (byId1!=null){ |
| | | byId.setCategoryName(byId1.getCategoryName()); |
| | | } |
| | | return R.ok(byId); |
| | | } |
| | | @PostMapping("/userAnswer") |
| | | @ApiOperation(value = "查看详情冥想音频-用户提问-分页", notes = "管理后台-冥想音频管理") |
| | | public R<PageDTO<MeditationQuestion>> userAnswer(@RequestBody UserAnswerDTO dto) { |
| | | LambdaQueryWrapper<MeditationQuestion> courseLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | if (StringUtils.hasLength(dto.getUserName())){ |
| | | List<Long> data = remoteAppUserService.getAppUserByName(dto.getUserName()).getData(); |
| | | if (data.isEmpty()){ |
| | | data.add(-1L); |
| | | } |
| | | courseLambdaQueryWrapper.in(MeditationQuestion::getAppUserId, data); |
| | | } |
| | | courseLambdaQueryWrapper.eq(dto.getShow_flag()!=null,MeditationQuestion::getShowFlag, dto.getShow_flag()); |
| | | courseLambdaQueryWrapper.like(dto.getContent()!=null&& (!dto.getContent().isEmpty()),MeditationQuestion::getContent, dto.getContent()); |
| | | courseLambdaQueryWrapper.eq(dto.getUid()!=null,MeditationQuestion::getMeditationId, dto.getUid()); |
| | | courseLambdaQueryWrapper.orderByDesc(MeditationQuestion::getCreateTime); |
| | | Page<MeditationQuestion> page = meditationQuestionService.page(new Page<>(dto.getPageCurr(), dto.getPageSize()), courseLambdaQueryWrapper); |
| | | if (CollUtils.isEmpty(page.getRecords())) { |
| | | return R.ok(PageDTO.empty(page)); |
| | | } |
| | | for (MeditationQuestion record : page.getRecords()) { |
| | | record.setUid(record.getId() + ""); |
| | | AppUser data = remoteAppUserService.getAppUserById(record.getAppUserId() + "").getData(); |
| | | if (data!=null){ |
| | | record.setUserName(data.getNickname()); |
| | | record.setAvatar(data.getAvatar()); |
| | | record.setCellPhone(data.getCellPhone()); |
| | | } |
| | | } |
| | | return R.ok(PageDTO.of(page, MeditationQuestion.class)); |
| | | } |
| | | @GetMapping("/updateUserAnswerState") |
| | | @ApiOperation(value = "查看详情冥想音频-用户提问-修改显示状态", notes = "管理后台-冥想音频管理") |
| | | public R updateUserAnswerState(String uid) { |
| | | MeditationQuestion byId = meditationQuestionService.getById(uid); |
| | | if (byId.getShowFlag() == 1){ |
| | | byId.setShowFlag(2); |
| | | }else { |
| | | byId.setShowFlag(1); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @GetMapping("/detailUserAnswer") |
| | | @ApiOperation(value = "查看详情冥想音频-用户提问", notes = "管理后台-冥想音频管理") |
| | | public R<MeditationQuestion> detailUserAnswer(String uid) { |
| | | MeditationQuestion byId = meditationQuestionService.getById(uid); |
| | | AppUser data = remoteAppUserService.getAppUserById(byId.getAppUserId().toString()).getData(); |
| | | byId.setUserName(data.getNickname()); |
| | | byId.setAvatar(data.getAvatar()); |
| | | byId.setCellPhone(data.getCellPhone()); |
| | | return R.ok(byId); |
| | | } |
| | | @GetMapping("/updateUserAnswer") |
| | | @ApiOperation(value = "查看详情冥想音频-用户提问-编辑", notes = "管理后台-冥想音频管理") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "uid", value = "uid", dataType = "String", required = true), |
| | | @ApiImplicitParam(name = "content", value = "回复内容", dataType = "String", required = false), |
| | | @ApiImplicitParam(name = "showFlag", value = "是否显示1是2否", dataType = "Integer", required = true), |
| | | }) |
| | | public R<MeditationQuestion> updateUserAnswer(String uid,String content,Integer showFlag) { |
| | | MeditationQuestion byId = meditationQuestionService.getById(uid); |
| | | if (StringUtils.hasLength(content)){ |
| | | // 给用户发一条消息 只有第一次回复发送 |
| | | if (StringUtils.hasLength(byId.getReplyContent())){ |
| | | NoticeRecord noticeRecord = new NoticeRecord(); |
| | | noticeRecord.setAppUserId(byId.getAppUserId()); |
| | | noticeRecord.setMeditationQuestionId(byId.getId()); |
| | | noticeRecord.setReadStatus(1); |
| | | noticeRecord.setNoticeType(2); |
| | | noticeRecord.setTitle("回复消息"); |
| | | noticeRecord.setContent(content); |
| | | noticeRecord.setCreateBy(SecurityUtils.getUsername()); |
| | | noticeRecord.setCreateTime(LocalDateTime.now()); |
| | | remoteAppUserService.addNoticeReplay(noticeRecord); |
| | | } |
| | | } |
| | | LambdaUpdateWrapper<MeditationQuestion> meditationQuestionLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); |
| | | meditationQuestionLambdaUpdateWrapper.set(MeditationQuestion::getReplyContent, content); |
| | | meditationQuestionLambdaUpdateWrapper.set(StringUtils.hasLength(content),MeditationQuestion::getReplyTime, LocalDateTime.now()); |
| | | meditationQuestionLambdaUpdateWrapper.set(MeditationQuestion::getShowFlag, showFlag); |
| | | meditationQuestionService.update(meditationQuestionLambdaUpdateWrapper); |
| | | return R.ok(byId); |
| | | } |
| | | @GetMapping("/updateState") |
| | | @ApiOperation(value = "修改冥想音频上下架状态", notes = "管理后台-冥想音频管理") |
| | | public R updateState(String uid) { |
| | | Meditation byId = meditationService.getById(uid); |
| | | if (byId.getListingStatus() == 1){ |
| | | byId.setListingStatus(2); |
| | | }else { |
| | | byId.setListingStatus(1); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @PostMapping("/updateMeditation") |
| | | @ApiOperation(value = "修改冥想音频管理", notes = "管理后台-冥想音频管理") |
| | | public R updateMeditation(@RequestBody Meditation homeBackgroundMusic) { |
| | | homeBackgroundMusic.setUpdateBy(SecurityUtils.getUsername()); |
| | | homeBackgroundMusic.setUpdateTime(LocalDateTime.now()); |
| | | meditationService.updateById(homeBackgroundMusic); |
| | | meditationTagService.remove(new LambdaQueryWrapper<MeditationTag>() |
| | | .eq(MeditationTag::getMeditationId,homeBackgroundMusic.getId())); |
| | | meditationMusicService.remove(new LambdaQueryWrapper<MeditationMusic>() |
| | | .eq(MeditationMusic::getMeditationId,homeBackgroundMusic.getId())); |
| | | if (!homeBackgroundMusic.getTagIds().isEmpty()){ |
| | | meditationTagService.remove(new LambdaQueryWrapper<MeditationTag>().eq(MeditationTag::getMeditationId,homeBackgroundMusic.getId())); |
| | | String[] split = homeBackgroundMusic.getTagIds().split(","); |
| | | List<MeditationTag> meditationTags = new ArrayList<>(); |
| | | for (int i = 0; i < split.length; i++) { |
| | | MeditationTag meditationTag = new MeditationTag(); |
| | | meditationTag.setMeditationId(homeBackgroundMusic.getId()); |
| | | meditationTag.setTagId(Long.valueOf(split[i])); |
| | | meditationTags.add(meditationTag); |
| | | } |
| | | meditationTagService.saveBatch(meditationTags); |
| | | } |
| | | if (!homeBackgroundMusic.getMusicUrls().isEmpty()){ |
| | | meditationMusicService.remove(new LambdaQueryWrapper<MeditationMusic>().eq(MeditationMusic::getMeditationId,homeBackgroundMusic.getId())); |
| | | String[] split = homeBackgroundMusic.getMusicUrls().split(","); |
| | | List<MeditationMusic> meditationTags = new ArrayList<>(); |
| | | for (int i = 0; i < split.length; i++) { |
| | | MeditationMusic meditationTag = new MeditationMusic(); |
| | | meditationTag.setMeditationId(homeBackgroundMusic.getId()); |
| | | meditationTag.setMusicUrl(split[i]); |
| | | meditationTag.setMusicSecond(Integer.valueOf(homeBackgroundMusic.getMusicSecond().split(",")[i])); |
| | | meditationTags.add(meditationTag); |
| | | } |
| | | meditationMusicService.saveBatch(meditationTags); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @PostMapping("/deleteMeditation") |
| | | @ApiOperation(value = "批量删除", notes = "管理后台-冥想音频管理") |
| | | public R deleteMeditation(String ids) { |
| | | return R.ok(meditationService.removeBatchByIds(Arrays.asList(ids.split(",")))); |
| | | } |
| | | } |
| | | |