| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xinquan.common.core.domain.R; |
| | | import com.xinquan.common.core.utils.DateUtils; |
| | | import com.xinquan.common.core.utils.page.BeanUtils; |
| | | import com.xinquan.common.core.utils.page.CollUtils; |
| | | import com.xinquan.common.core.utils.page.PageDTO; |
| | | import com.xinquan.common.core.web.domain.BaseModel; |
| | | import com.xinquan.common.security.service.TokenService; |
| | | import com.xinquan.common.security.utils.SecurityUtils; |
| | | import com.xinquan.course.api.domain.Course; |
| | | import com.xinquan.course.api.feign.RemoteCourseService; |
| | | import com.xinquan.meditation.api.domain.Meditation; |
| | | import com.xinquan.meditation.api.domain.MeditationQuestion; |
| | | import com.xinquan.meditation.api.feign.RemoteMeditationService; |
| | | import com.xinquan.system.api.domain.AppUser; |
| | | import com.xinquan.system.api.domain.NoticeRecord; |
| | | import com.xinquan.meditation.api.domain.vo.NoticeDetailVO; |
| | | import com.xinquan.system.api.model.LoginUser; |
| | | import com.xinquan.user.service.AppUserService; |
| | | import com.xinquan.user.service.NoticeRecordService; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | |
| | | /** |
| | |
| | | private AppUserService appUserService; |
| | | @Resource |
| | | private RemoteMeditationService remoteMeditationService; |
| | | @Resource |
| | | private RemoteCourseService remoteCourseService; |
| | | @GetMapping("/addNotice/{id}/{courseId}/{userId}/{price}") |
| | | public R addNotice(@PathVariable("id")String id,@PathVariable("courseId")String courseId |
| | | ,@PathVariable("userId")String userId,@PathVariable("price")String price) { |
| | | NoticeRecord noticeRecord = new NoticeRecord(); |
| | | noticeRecord.setAppUserId(Long.valueOf(id)); |
| | | noticeRecord.setCourseId(Long.valueOf(courseId)); |
| | | noticeRecord.setReadStatus(1); |
| | | noticeRecord.setNoticeType(1); |
| | | noticeRecord.setTitle("你收到一个来自好友的赠送课程"); |
| | | Course data = remoteCourseService.getCourseById(Long.valueOf(courseId)).getData(); |
| | | if (data!=null){ |
| | | noticeRecord.setContent("课程名称:"+data.getCourseTitle()+"。"+"课程价值:¥"+price+"。"+"赠送好友:" |
| | | +appUserService.getById(Long.valueOf(userId)).getNickname()+";"+"快去个人中心/已购课程查看吧!"); |
| | | } |
| | | noticeRecord.setUserId(Long.valueOf(userId)); |
| | | noticeRecordService.save(noticeRecord); |
| | | return R.ok(); |
| | | } |
| | | @PostMapping("/noticeList") |
| | | @ApiOperation(value = "系统消息列表",tags = "系统消息") |
| | | @ApiImplicitParams({ |
| | |
| | | @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer") |
| | | }) |
| | | public R<PageDTO<NoticeRecord>> noticeList(Integer pageCurr, Integer pageSize) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId==0)return R.tokenError("登录失效"); |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser==null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | if(userId ==null || userId == 0)return R.tokenError("登录失效"); |
| | | Page<NoticeRecord> page = noticeRecordService.lambdaQuery() |
| | | .eq(NoticeRecord::getAppUserId, userId) |
| | | .orderByDesc(BaseModel::getCreateTime) |
| | |
| | | @PostMapping("/noticeDetail") |
| | | @ApiOperation(value = "系统消息列表-查看详情",tags = "系统消息") |
| | | public R<NoticeDetailVO> wallet(Long id) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId == 0)return R.tokenError("登录失效"); |
| | | |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser==null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | NoticeRecord noticeRecord = noticeRecordService.getById(id); |
| | | // 设置为已读 |
| | | noticeRecord.setReadStatus(2); |
| | | noticeRecordService.updateById(noticeRecord); |
| | | NoticeDetailVO noticeDetailVO = new NoticeDetailVO(); |
| | | BeanUtils.copyProperties(noticeRecord,noticeDetailVO); |
| | | LocalDateTime createTime = noticeRecord.getCreateTime(); |
| | | // 定义日期时间格式 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); |
| | | |
| | | // 将 LocalDateTime 转换为字符串 |
| | | String formattedDateTime = createTime.format(formatter); |
| | | // 将其转化为yyyy-MM-dd HH:mm格式 |
| | | noticeDetailVO.setTime(formattedDateTime); |
| | | noticeDetailVO.setPublishTime(noticeRecord.getCreateTime()); |
| | | if (noticeRecord!=null && noticeRecord.getMeditationQuestionId()!=null){ |
| | | // 远程调用 根据冥想提问id 查询数据 |
| | | noticeDetailVO.setMeditationQuestionId(noticeRecord.getMeditationQuestionId()); |
| | | // NoticeDetailVO data = remoteMeditationService.noticeDetail(noticeDetailVO).getData(); |
| | | Meditation data = remoteMeditationService.getMeditationById(noticeRecord.getMeditationId()).getData(); |
| | | MeditationQuestion data1 = remoteMeditationService.getMeditationQuestion(noticeRecord.getMeditationQuestionId() + "").getData(); |
| | | if (data!=null){ |
| | | noticeDetailVO.setMeditationTitle(data.getMeditationTitle()); |
| | | noticeDetailVO.setReplyContent(noticeRecord.getContent()); |
| | | noticeDetailVO.setCoverDescription(data.getDetailDescription()); |
| | | noticeDetailVO.setIconUrl(data.getCoverUrl()); |
| | | } |
| | | if (data1!=null){ |
| | | noticeDetailVO.setNoticeType(noticeRecord.getNoticeType()); |
| | | noticeDetailVO.setContent(data1.getContent()); |
| | | noticeDetailVO.setReplyContent(data1.getReplyContent()); |
| | | noticeDetailVO.setPublishTime(data1.getCreateTime()); |
| | | } |
| | | AppUser byId = appUserService.getById(userId); |
| | | noticeDetailVO.setNickname(byId.getNickname()); |
| | | noticeDetailVO.setAvatar(byId.getAvatar()); |
| | |
| | | } |
| | | return R.ok(noticeDetailVO); |
| | | } |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | @PostMapping("/queryNotice") |
| | | @ApiOperation(value = "是否有未读消息 true是 false否",tags = "系统消息") |
| | | public R<Boolean> queryNotice() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId == 0)return R.tokenError("登录失效"); |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser==null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | int size = noticeRecordService.lambdaQuery() |
| | | .eq(NoticeRecord::getAppUserId, userId) |
| | | .eq(NoticeRecord::getReadStatus, 1).list().size(); |