TbMyPublishServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. package com.ruoyi.app.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.github.pagehelper.PageHelper;
  5. import com.github.pagehelper.PageInfo;
  6. import com.ruoyi.app.domain.*;
  7. import com.ruoyi.app.domain.vo.AppFamilyVo;
  8. import com.ruoyi.app.domain.vo.AppMemberVo;
  9. import com.ruoyi.app.service.*;
  10. import com.ruoyi.common.constant.HttpStatus;
  11. import com.ruoyi.common.core.page.PageDomain;
  12. import com.ruoyi.common.core.page.TableDataInfo;
  13. import com.ruoyi.common.core.page.TableSupport;
  14. import com.ruoyi.common.utils.StringUtils;
  15. import com.ruoyi.common.utils.sql.SqlUtil;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.scheduling.annotation.Async;
  18. import org.springframework.stereotype.Service;
  19. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  20. import com.ruoyi.app.mapper.TbMyPublishMapper;
  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.List;
  24. /**
  25. * 我的近况(发表)
  26. *
  27. * @author Administrator
  28. * @date 2020-10-02
  29. */
  30. @Service
  31. public class TbMyPublishServiceImpl extends ServiceImpl<TbMyPublishMapper, TbMyPublish> implements ITbMyPublishService {
  32. @Autowired
  33. private ITbMyPublishService publishService;
  34. @Autowired
  35. private ITbPublishImgService imgService;
  36. @Autowired
  37. private ITbPublishThumbsService thumbsService;
  38. @Autowired
  39. private ITbPublishCommentService commentService;
  40. @Autowired
  41. private ITbAppUserService userService;
  42. @Autowired
  43. private ITbMyFriendsService friendsService;
  44. protected void startPage() {
  45. PageDomain pageDomain = TableSupport.buildPageRequest();
  46. Integer pageNum = pageDomain.getPageNum() == null ? 1 : pageDomain.getPageNum();
  47. Integer pageSize = pageDomain.getPageSize() == null ? 10 : pageDomain.getPageSize();
  48. if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize))
  49. {
  50. String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
  51. PageHelper.startPage(pageNum, pageSize, orderBy);
  52. }
  53. }
  54. /**
  55. * 响应请求分页数据
  56. */
  57. @SuppressWarnings({ "rawtypes", "unchecked" })
  58. protected TableDataInfo getDataTable(List<?> list) {
  59. TableDataInfo rspData = new TableDataInfo();
  60. rspData.setCode(HttpStatus.SUCCESS);
  61. rspData.setMsg("查询成功");
  62. rspData.setRows(list);
  63. rspData.setTotal(new PageInfo(list).getTotal());
  64. return rspData;
  65. }
  66. /**
  67. * 我的近况列表
  68. * @param tbMyPublish
  69. * @return
  70. */
  71. @Override
  72. public List<TbMyPublish> pageList(TbMyPublish tbMyPublish) {
  73. LambdaQueryWrapper<TbMyPublish> lqw = new LambdaQueryWrapper<TbMyPublish>();
  74. if (tbMyPublish.getAppUserId() != null){
  75. lqw.eq(TbMyPublish::getAppUserId ,tbMyPublish.getAppUserId());
  76. }
  77. if (StringUtils.isNotBlank(tbMyPublish.getContents())){
  78. lqw.like(TbMyPublish::getContents ,tbMyPublish.getContents());
  79. }
  80. if (StringUtils.isNotBlank(tbMyPublish.getMessage())){
  81. lqw.eq(TbMyPublish::getMessage ,tbMyPublish.getMessage());
  82. }
  83. if (StringUtils.isNotBlank(tbMyPublish.getDeleted())){
  84. lqw.eq(TbMyPublish::getDeleted ,tbMyPublish.getDeleted());
  85. }
  86. if (StringUtils.isNotBlank(tbMyPublish.getBeginTime()) &&
  87. StringUtils.isNotBlank(tbMyPublish.getEndTime())) {
  88. lqw.between(TbMyPublish::getCreateTime, tbMyPublish.getBeginTime(), tbMyPublish.getEndTime());
  89. }
  90. startPage();
  91. List<TbMyPublish> list = baseMapper.pageList(lqw);
  92. if (list.size() <= 0) {
  93. return new ArrayList<>();
  94. }
  95. List<Long> ids = new ArrayList<>();
  96. list.forEach(item -> {
  97. ids.add(item.getId());
  98. });
  99. // 族友圈中放入图片列表 点赞列表 评论列表
  100. List<TbPublishImg> imgList = imgService.list(new LambdaQueryWrapper<TbPublishImg>()
  101. .in(TbPublishImg::getPublishId, ids)
  102. );
  103. list.forEach(item -> {
  104. // 加入图片列表
  105. List<TbPublishImg> imgs = new ArrayList<>();
  106. imgList.forEach(img -> {
  107. if (img.getPublishId().equals(item.getId())) {
  108. imgs.add(img);
  109. }
  110. });
  111. item.setImgList(imgs);
  112. });
  113. return list;
  114. }
  115. @Autowired
  116. private ITbFamilyService familyService;
  117. /**
  118. * 我的近况详情(登录人只能看好友和族友的点赞、评论)
  119. * @param id
  120. * @return
  121. */
  122. @Override
  123. public TbMyPublish getPublish(Long id, Long appUserId) {
  124. TbMyPublish publish = this.getById(id);
  125. if (publish != null) {
  126. // 只能看好友和族友的点赞、评论
  127. List<Long> fids = getMyFrientIds(appUserId);
  128. // 图片列表
  129. List<TbPublishImg> publishImgs = imgService.list(new LambdaQueryWrapper<TbPublishImg>()
  130. .in(TbPublishImg::getPublishId, id)
  131. );
  132. // 点赞列表
  133. List<TbPublishThumbs> thumbsList = thumbsService.selectList(new LambdaQueryWrapper<TbPublishThumbs>()
  134. .in(TbPublishThumbs::getPublishId, id)
  135. .in(fids.size() > 0,TbPublishThumbs::getAppUserId, fids)
  136. );
  137. // 评论列表
  138. List<TbPublishComment> commentList = commentService.selectList(new LambdaQueryWrapper<TbPublishComment>()
  139. .in(TbPublishComment::getPublishId, id)
  140. .in(fids.size() > 0,TbPublishComment::getAppUserId, fids)
  141. );
  142. //点赞数
  143. int thumbs = this.getThumbs(id);
  144. //评论数
  145. int comments = this.getComments(id);
  146. TbAppUser userPublish = userService.getById(publish.getAppUserId());
  147. if (userPublish != null) {
  148. publish.setNickName(userPublish.getNickName());
  149. publish.setAvatar(userPublish.getAvatar());
  150. }
  151. // 如果是留念人发表
  152. if (publish.getMessageUserId() != null) {
  153. TbAppUser user = userService.getById(publish.getMessageUserId());
  154. if (user != null) {
  155. publish.setMessageUser(user.getNickName());
  156. publish.setMessageUserAvatar(user.getAvatar());
  157. }
  158. }
  159. publish.setImgList(publishImgs);
  160. publish.setCommentList(commentList);
  161. publish.setThumbsList(thumbsList);
  162. publish.setThumbs(thumbs);
  163. publish.setComments(comments);
  164. }
  165. return publish;
  166. }
  167. /**
  168. * 会员的所有近况详情
  169. * @param id
  170. * @return
  171. */
  172. @Override
  173. public TbMyPublish getPublish(Long id) {
  174. TbMyPublish publish = this.getById(id);
  175. if (publish != null) {
  176. Long familyId = null;
  177. TbFamilyMember member = memberService.getOne(new LambdaQueryWrapper<TbFamilyMember>()
  178. .eq(TbFamilyMember::getAppUserId,publish.getAppUserId())
  179. .last("limit 1")
  180. );
  181. if (member != null) {
  182. TbFamily family = familyService.myFamily(member.getId());
  183. if (family != null) {
  184. familyId = family.getId();
  185. }
  186. }
  187. // 图片列表
  188. List<TbPublishImg> publishImgs = imgService.list(new LambdaQueryWrapper<TbPublishImg>()
  189. .in(TbPublishImg::getPublishId, id)
  190. );
  191. // 点赞列表
  192. List<TbPublishThumbs> thumbsList = thumbsService.selectList(new LambdaQueryWrapper<TbPublishThumbs>()
  193. .in(TbPublishThumbs::getPublishId, id)
  194. );
  195. // 评论列表
  196. List<TbPublishComment> commentList = commentService.selectList(new LambdaQueryWrapper<TbPublishComment>()
  197. .in(TbPublishComment::getPublishId, id)
  198. );
  199. //点赞数
  200. int thumbs = this.getThumbs(id);
  201. //评论数
  202. int comments = this.getComments(id);
  203. TbAppUser userPublish = userService.getById(publish.getAppUserId());
  204. if (userPublish != null) {
  205. publish.setNickName(userPublish.getNickName());
  206. publish.setAvatar(userPublish.getAvatar());
  207. }
  208. // 如果是留念人发表
  209. if (publish.getMessageUserId() != null) {
  210. TbAppUser user = userService.getById(publish.getMessageUserId());
  211. if (user != null) {
  212. publish.setMessageUser(user.getNickName());
  213. publish.setMessageUserAvatar(user.getAvatar());
  214. }
  215. }
  216. publish.setImgList(publishImgs);
  217. publish.setCommentList(commentList);
  218. publish.setThumbsList(thumbsList);
  219. publish.setThumbs(thumbs);
  220. publish.setComments(comments);
  221. }
  222. return publish;
  223. }
  224. @Override
  225. public boolean delPublish(List<Long> ids){
  226. List<TbMyPublish> publishList = baseMapper.selectList(new LambdaQueryWrapper<TbMyPublish>()
  227. .in(TbMyPublish::getId, ids)
  228. );
  229. if (publishList.size() > 0) {
  230. publishList.forEach(item -> {
  231. item.setDeleted("Y");
  232. });
  233. return publishService.updateBatchById(publishList);
  234. }
  235. return false;
  236. }
  237. /**
  238. * 获取点赞数
  239. * @param publishId 近况id
  240. * @return
  241. */
  242. @Override
  243. public int getThumbs(Long publishId) {
  244. int count = thumbsService.count(new LambdaQueryWrapper<TbPublishThumbs>()
  245. .eq(TbPublishThumbs::getPublishId, publishId)
  246. );
  247. return count;
  248. }
  249. /**
  250. * 获取评论数
  251. * @param publishId 近况id
  252. * @return
  253. */
  254. @Override
  255. public int getComments(Long publishId) {
  256. int count = commentService.count(new LambdaQueryWrapper<TbPublishComment>()
  257. .eq(TbPublishComment::getPublishId, publishId)
  258. );
  259. return count;
  260. }
  261. /**
  262. * 获取评论
  263. * @param publishId
  264. * @return
  265. */
  266. @Override
  267. public List<TbPublishComment> listComment(Long publishId){
  268. List<TbPublishComment> comments = commentService.list(new LambdaQueryWrapper<TbPublishComment>()
  269. .eq(TbPublishComment::getPublishId, publishId)
  270. );
  271. if (comments.size() > 0) {
  272. List<Long> ids = new ArrayList<>();
  273. comments.forEach(item -> {
  274. ids.add(item.getAppUserId());
  275. });
  276. List<TbAppUser> userList = userService.list(new LambdaQueryWrapper<TbAppUser>()
  277. .in(TbAppUser::getId,ids)
  278. );
  279. if (userList.size() > 0) {
  280. comments.forEach(item -> {
  281. userList.forEach(user -> {
  282. if (item.getAppUserId().equals(user.getId())) {
  283. item.setAppUserUrl(user.getAvatar());
  284. item.setAppUser(user.getNickName());
  285. }
  286. });
  287. });
  288. }
  289. }
  290. return comments;
  291. }
  292. /**
  293. * 删除一条评论
  294. * @param id
  295. * @return
  296. */
  297. @Override
  298. public boolean delComment(Long id) {
  299. return commentService.removeById(id);
  300. }
  301. @Autowired
  302. private ITbFamilyMemberService memberService;
  303. /**
  304. * 族友圈列表
  305. */
  306. @Override
  307. public List<TbMyPublish> selectPublish(Long appUserId, Long familyId) {
  308. startPage();
  309. List<TbMyPublish> list = baseMapper.selectPublish(appUserId);
  310. if (list.size() <= 0) {
  311. return new ArrayList<>();
  312. }
  313. List<Long> ids = new ArrayList<>();
  314. list.forEach(item -> {
  315. ids.add(item.getId());
  316. });
  317. // 只能看好友和族友的点赞、评论
  318. List<Long> fids = getMyFrientIds(appUserId);
  319. // 族友圈中放入图片列表 点赞列表 评论列表
  320. List<TbPublishImg> imgList = imgService.list(new LambdaQueryWrapper<TbPublishImg>()
  321. .in(TbPublishImg::getPublishId, ids)
  322. );
  323. List<TbPublishThumbs> thumbsList = thumbsService.selectList(new LambdaQueryWrapper<TbPublishThumbs>()
  324. .in(TbPublishThumbs::getPublishId, ids)
  325. .in(fids.size() > 0,TbPublishThumbs::getAppUserId, fids)
  326. );
  327. List<TbPublishComment> commentList = commentService.selectList(new LambdaQueryWrapper<TbPublishComment>()
  328. .in(TbPublishComment::getPublishId, ids)
  329. .in(fids.size() > 0,TbPublishComment::getAppUserId, fids)
  330. );
  331. list.forEach(item -> {
  332. // 加入图片列表
  333. List<TbPublishImg> imgs = new ArrayList<>();
  334. imgList.forEach(img -> {
  335. if (img.getPublishId().equals(item.getId())) {
  336. imgs.add(img);
  337. }
  338. });
  339. item.setImgList(imgs);
  340. // 加入点赞列表
  341. List<TbPublishThumbs> thumbs = new ArrayList<>();
  342. thumbsList.forEach(thumb -> {
  343. if (thumb.getPublishId().equals(item.getId())){
  344. thumbs.add(thumb);
  345. }
  346. });
  347. item.setThumbsList(thumbs);
  348. // 加入评论列表
  349. List<TbPublishComment> comments = new ArrayList<>();
  350. commentList.forEach(comment -> {
  351. if (comment.getPublishId().equals(item.getId())){
  352. comments.add(comment);
  353. }
  354. });
  355. item.setCommentList(comments);
  356. });
  357. return list;
  358. }
  359. /**
  360. * 获取好友、族友的id
  361. * @param appUserId
  362. * @return
  363. */
  364. @Override
  365. public List<Long> getMyFrientIds(Long appUserId){
  366. List<Long> fids = new ArrayList<>();
  367. // 自己
  368. fids.add(appUserId);
  369. if (appUserId != null) {
  370. // 好友列表
  371. TbMyFriends tbMyFriends = new TbMyFriends();
  372. tbMyFriends.setAppUserId(appUserId);
  373. tbMyFriends.setStatus("2");
  374. List<TbMyFriends> friendsList = friendsService.pageList(tbMyFriends);
  375. if (friendsList.size() > 0) {
  376. friendsList.forEach(item -> {
  377. fids.add(item.getAppUserId());
  378. });
  379. }
  380. }
  381. List<Long> familyIds = new ArrayList<>();
  382. // 获取登录人所在的家族id
  383. TbFamilyMember member = memberService.getOne(new LambdaQueryWrapper<TbFamilyMember>()
  384. .eq(TbFamilyMember::getAppUserId,appUserId)
  385. .last("limit 1")
  386. );
  387. if (member != null) {
  388. List<AppFamilyVo> familyVoList = familyService.selectByMemberId(member.getId());
  389. if (familyVoList.size() > 0) {
  390. familyVoList.forEach(item -> {
  391. familyIds.add(item.getId());
  392. });
  393. // 族友列表
  394. List<AppMemberVo> memberList = memberService.myMemberList(new LambdaQueryWrapper<AppMemberVo>()
  395. .in(AppMemberVo::getFamilyId, familyIds)
  396. .eq(AppMemberVo::getStatus, "2")
  397. );
  398. if (memberList.size() > 0) {
  399. memberList.forEach(item -> {
  400. fids.add(item.getUserId());
  401. });
  402. }
  403. }
  404. }
  405. return fids;
  406. }
  407. }