123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- package com.ruoyi.app.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.ruoyi.app.domain.*;
- import com.ruoyi.app.domain.vo.AppFamilyVo;
- import com.ruoyi.app.domain.vo.AppMemberVo;
- import com.ruoyi.app.service.*;
- import com.ruoyi.common.constant.HttpStatus;
- import com.ruoyi.common.core.page.PageDomain;
- import com.ruoyi.common.core.page.TableDataInfo;
- import com.ruoyi.common.core.page.TableSupport;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.utils.sql.SqlUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ruoyi.app.mapper.TbMyPublishMapper;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- /**
- * 我的近况(发表)
- *
- * @author Administrator
- * @date 2020-10-02
- */
- @Service
- public class TbMyPublishServiceImpl extends ServiceImpl<TbMyPublishMapper, TbMyPublish> implements ITbMyPublishService {
- @Autowired
- private ITbMyPublishService publishService;
- @Autowired
- private ITbPublishImgService imgService;
- @Autowired
- private ITbPublishThumbsService thumbsService;
- @Autowired
- private ITbPublishCommentService commentService;
- @Autowired
- private ITbAppUserService userService;
- @Autowired
- private ITbMyFriendsService friendsService;
- protected void startPage() {
- PageDomain pageDomain = TableSupport.buildPageRequest();
- Integer pageNum = pageDomain.getPageNum() == null ? 1 : pageDomain.getPageNum();
- Integer pageSize = pageDomain.getPageSize() == null ? 10 : pageDomain.getPageSize();
- if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize))
- {
- String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
- PageHelper.startPage(pageNum, pageSize, orderBy);
- }
- }
- /**
- * 响应请求分页数据
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected TableDataInfo getDataTable(List<?> list) {
- TableDataInfo rspData = new TableDataInfo();
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- return rspData;
- }
- /**
- * 我的近况列表
- * @param tbMyPublish
- * @return
- */
- @Override
- public List<TbMyPublish> pageList(TbMyPublish tbMyPublish) {
- LambdaQueryWrapper<TbMyPublish> lqw = new LambdaQueryWrapper<TbMyPublish>();
- if (tbMyPublish.getAppUserId() != null){
- lqw.eq(TbMyPublish::getAppUserId ,tbMyPublish.getAppUserId());
- }
- if (StringUtils.isNotBlank(tbMyPublish.getContents())){
- lqw.like(TbMyPublish::getContents ,tbMyPublish.getContents());
- }
- if (StringUtils.isNotBlank(tbMyPublish.getMessage())){
- lqw.eq(TbMyPublish::getMessage ,tbMyPublish.getMessage());
- }
- if (StringUtils.isNotBlank(tbMyPublish.getDeleted())){
- lqw.eq(TbMyPublish::getDeleted ,tbMyPublish.getDeleted());
- }
- if (StringUtils.isNotBlank(tbMyPublish.getBeginTime()) &&
- StringUtils.isNotBlank(tbMyPublish.getEndTime())) {
- lqw.between(TbMyPublish::getCreateTime, tbMyPublish.getBeginTime(), tbMyPublish.getEndTime());
- }
- startPage();
- List<TbMyPublish> list = baseMapper.pageList(lqw);
- if (list.size() <= 0) {
- return new ArrayList<>();
- }
- List<Long> ids = new ArrayList<>();
- list.forEach(item -> {
- ids.add(item.getId());
- });
- // 族友圈中放入图片列表 点赞列表 评论列表
- List<TbPublishImg> imgList = imgService.list(new LambdaQueryWrapper<TbPublishImg>()
- .in(TbPublishImg::getPublishId, ids)
- );
- list.forEach(item -> {
- // 加入图片列表
- List<TbPublishImg> imgs = new ArrayList<>();
- imgList.forEach(img -> {
- if (img.getPublishId().equals(item.getId())) {
- imgs.add(img);
- }
- });
- item.setImgList(imgs);
- });
- return list;
- }
- @Autowired
- private ITbFamilyService familyService;
- /**
- * 我的近况详情(登录人只能看好友和族友的点赞、评论)
- * @param id
- * @return
- */
- @Override
- public TbMyPublish getPublish(Long id, Long appUserId) {
- TbMyPublish publish = this.getById(id);
- if (publish != null) {
- // 只能看好友和族友的点赞、评论
- List<Long> fids = getMyFrientIds(appUserId);
- // 图片列表
- List<TbPublishImg> publishImgs = imgService.list(new LambdaQueryWrapper<TbPublishImg>()
- .in(TbPublishImg::getPublishId, id)
- );
- // 点赞列表
- List<TbPublishThumbs> thumbsList = thumbsService.selectList(new LambdaQueryWrapper<TbPublishThumbs>()
- .in(TbPublishThumbs::getPublishId, id)
- .in(fids.size() > 0,TbPublishThumbs::getAppUserId, fids)
- );
- // 评论列表
- List<TbPublishComment> commentList = commentService.selectList(new LambdaQueryWrapper<TbPublishComment>()
- .in(TbPublishComment::getPublishId, id)
- .in(fids.size() > 0,TbPublishComment::getAppUserId, fids)
- );
- //点赞数
- int thumbs = this.getThumbs(id);
- //评论数
- int comments = this.getComments(id);
- TbAppUser userPublish = userService.getById(publish.getAppUserId());
- if (userPublish != null) {
- publish.setNickName(userPublish.getNickName());
- publish.setAvatar(userPublish.getAvatar());
- }
- // 如果是留念人发表
- if (publish.getMessageUserId() != null) {
- TbAppUser user = userService.getById(publish.getMessageUserId());
- if (user != null) {
- publish.setMessageUser(user.getNickName());
- publish.setMessageUserAvatar(user.getAvatar());
- }
- }
- publish.setImgList(publishImgs);
- publish.setCommentList(commentList);
- publish.setThumbsList(thumbsList);
- publish.setThumbs(thumbs);
- publish.setComments(comments);
- }
- return publish;
- }
- /**
- * 会员的所有近况详情
- * @param id
- * @return
- */
- @Override
- public TbMyPublish getPublish(Long id) {
- TbMyPublish publish = this.getById(id);
- if (publish != null) {
- Long familyId = null;
- TbFamilyMember member = memberService.getOne(new LambdaQueryWrapper<TbFamilyMember>()
- .eq(TbFamilyMember::getAppUserId,publish.getAppUserId())
- .last("limit 1")
- );
- if (member != null) {
- TbFamily family = familyService.myFamily(member.getId());
- if (family != null) {
- familyId = family.getId();
- }
- }
- // 图片列表
- List<TbPublishImg> publishImgs = imgService.list(new LambdaQueryWrapper<TbPublishImg>()
- .in(TbPublishImg::getPublishId, id)
- );
- // 点赞列表
- List<TbPublishThumbs> thumbsList = thumbsService.selectList(new LambdaQueryWrapper<TbPublishThumbs>()
- .in(TbPublishThumbs::getPublishId, id)
- );
- // 评论列表
- List<TbPublishComment> commentList = commentService.selectList(new LambdaQueryWrapper<TbPublishComment>()
- .in(TbPublishComment::getPublishId, id)
- );
- //点赞数
- int thumbs = this.getThumbs(id);
- //评论数
- int comments = this.getComments(id);
- TbAppUser userPublish = userService.getById(publish.getAppUserId());
- if (userPublish != null) {
- publish.setNickName(userPublish.getNickName());
- publish.setAvatar(userPublish.getAvatar());
- }
- // 如果是留念人发表
- if (publish.getMessageUserId() != null) {
- TbAppUser user = userService.getById(publish.getMessageUserId());
- if (user != null) {
- publish.setMessageUser(user.getNickName());
- publish.setMessageUserAvatar(user.getAvatar());
- }
- }
- publish.setImgList(publishImgs);
- publish.setCommentList(commentList);
- publish.setThumbsList(thumbsList);
- publish.setThumbs(thumbs);
- publish.setComments(comments);
- }
- return publish;
- }
- @Override
- public boolean delPublish(List<Long> ids){
- List<TbMyPublish> publishList = baseMapper.selectList(new LambdaQueryWrapper<TbMyPublish>()
- .in(TbMyPublish::getId, ids)
- );
- if (publishList.size() > 0) {
- publishList.forEach(item -> {
- item.setDeleted("Y");
- });
- return publishService.updateBatchById(publishList);
- }
- return false;
- }
- /**
- * 获取点赞数
- * @param publishId 近况id
- * @return
- */
- @Override
- public int getThumbs(Long publishId) {
- int count = thumbsService.count(new LambdaQueryWrapper<TbPublishThumbs>()
- .eq(TbPublishThumbs::getPublishId, publishId)
- );
- return count;
- }
- /**
- * 获取评论数
- * @param publishId 近况id
- * @return
- */
- @Override
- public int getComments(Long publishId) {
- int count = commentService.count(new LambdaQueryWrapper<TbPublishComment>()
- .eq(TbPublishComment::getPublishId, publishId)
- );
- return count;
- }
- /**
- * 获取评论
- * @param publishId
- * @return
- */
- @Override
- public List<TbPublishComment> listComment(Long publishId){
- List<TbPublishComment> comments = commentService.list(new LambdaQueryWrapper<TbPublishComment>()
- .eq(TbPublishComment::getPublishId, publishId)
- );
- if (comments.size() > 0) {
- List<Long> ids = new ArrayList<>();
- comments.forEach(item -> {
- ids.add(item.getAppUserId());
- });
- List<TbAppUser> userList = userService.list(new LambdaQueryWrapper<TbAppUser>()
- .in(TbAppUser::getId,ids)
- );
- if (userList.size() > 0) {
- comments.forEach(item -> {
- userList.forEach(user -> {
- if (item.getAppUserId().equals(user.getId())) {
- item.setAppUserUrl(user.getAvatar());
- item.setAppUser(user.getNickName());
- }
- });
- });
- }
- }
- return comments;
- }
- /**
- * 删除一条评论
- * @param id
- * @return
- */
- @Override
- public boolean delComment(Long id) {
- return commentService.removeById(id);
- }
- @Autowired
- private ITbFamilyMemberService memberService;
- /**
- * 族友圈列表
- */
- @Override
- public List<TbMyPublish> selectPublish(Long appUserId, Long familyId) {
- startPage();
- List<TbMyPublish> list = baseMapper.selectPublish(appUserId);
- if (list.size() <= 0) {
- return new ArrayList<>();
- }
- List<Long> ids = new ArrayList<>();
- list.forEach(item -> {
- ids.add(item.getId());
- });
- // 只能看好友和族友的点赞、评论
- List<Long> fids = getMyFrientIds(appUserId);
- // 族友圈中放入图片列表 点赞列表 评论列表
- List<TbPublishImg> imgList = imgService.list(new LambdaQueryWrapper<TbPublishImg>()
- .in(TbPublishImg::getPublishId, ids)
- );
- List<TbPublishThumbs> thumbsList = thumbsService.selectList(new LambdaQueryWrapper<TbPublishThumbs>()
- .in(TbPublishThumbs::getPublishId, ids)
- .in(fids.size() > 0,TbPublishThumbs::getAppUserId, fids)
- );
- List<TbPublishComment> commentList = commentService.selectList(new LambdaQueryWrapper<TbPublishComment>()
- .in(TbPublishComment::getPublishId, ids)
- .in(fids.size() > 0,TbPublishComment::getAppUserId, fids)
- );
- list.forEach(item -> {
- // 加入图片列表
- List<TbPublishImg> imgs = new ArrayList<>();
- imgList.forEach(img -> {
- if (img.getPublishId().equals(item.getId())) {
- imgs.add(img);
- }
- });
- item.setImgList(imgs);
- // 加入点赞列表
- List<TbPublishThumbs> thumbs = new ArrayList<>();
- thumbsList.forEach(thumb -> {
- if (thumb.getPublishId().equals(item.getId())){
- thumbs.add(thumb);
- }
- });
- item.setThumbsList(thumbs);
- // 加入评论列表
- List<TbPublishComment> comments = new ArrayList<>();
- commentList.forEach(comment -> {
- if (comment.getPublishId().equals(item.getId())){
- comments.add(comment);
- }
- });
- item.setCommentList(comments);
- });
- return list;
- }
- /**
- * 获取好友、族友的id
- * @param appUserId
- * @return
- */
- @Override
- public List<Long> getMyFrientIds(Long appUserId){
- List<Long> fids = new ArrayList<>();
- // 自己
- fids.add(appUserId);
- if (appUserId != null) {
- // 好友列表
- TbMyFriends tbMyFriends = new TbMyFriends();
- tbMyFriends.setAppUserId(appUserId);
- tbMyFriends.setStatus("2");
- List<TbMyFriends> friendsList = friendsService.pageList(tbMyFriends);
- if (friendsList.size() > 0) {
- friendsList.forEach(item -> {
- fids.add(item.getAppUserId());
- });
- }
- }
- List<Long> familyIds = new ArrayList<>();
- // 获取登录人所在的家族id
- TbFamilyMember member = memberService.getOne(new LambdaQueryWrapper<TbFamilyMember>()
- .eq(TbFamilyMember::getAppUserId,appUserId)
- .last("limit 1")
- );
- if (member != null) {
- List<AppFamilyVo> familyVoList = familyService.selectByMemberId(member.getId());
- if (familyVoList.size() > 0) {
- familyVoList.forEach(item -> {
- familyIds.add(item.getId());
- });
- // 族友列表
- List<AppMemberVo> memberList = memberService.myMemberList(new LambdaQueryWrapper<AppMemberVo>()
- .in(AppMemberVo::getFamilyId, familyIds)
- .eq(AppMemberVo::getStatus, "2")
- );
- if (memberList.size() > 0) {
- memberList.forEach(item -> {
- fids.add(item.getUserId());
- });
- }
- }
- }
- return fids;
- }
- }
|