NewsServiceImpl.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.fdkankan.manage.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.fdkankan.common.constant.CommonStatus;
  6. import com.fdkankan.common.constant.TbStatus;
  7. import com.fdkankan.common.response.PageInfo;
  8. import com.fdkankan.common.response.ResultData;
  9. import com.fdkankan.manage.entity.News;
  10. import com.fdkankan.manage.mapper.INewsMapper;
  11. import com.fdkankan.manage.service.INewsService;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import com.fdkankan.manage.vo.BaseParamVO;
  14. import com.fdkankan.manage.vo.NewsDisplayParamVO;
  15. import com.fdkankan.manage.vo.NewsPublicParamVO;
  16. import com.fdkankan.manage.vo.NewsPutTopParamVO;
  17. import com.fdkankan.manage.vo.PageNewsParamVO;
  18. import com.fdkankan.manage.vo.PageNewsVO;
  19. import com.fdkankan.manage.vo.SaveNewsParamVO;
  20. import com.fdkankan.manage.vo.UpdateNewsParamVO;
  21. import java.util.Calendar;
  22. import org.springframework.stereotype.Service;
  23. /**
  24. * <p>
  25. * 服务实现类
  26. * </p>
  27. *
  28. * @author
  29. * @since 2022-06-06
  30. */
  31. @Service
  32. public class NewsServiceImpl extends ServiceImpl<INewsMapper, News> implements INewsService {
  33. @Override
  34. public PageInfo pageNews(PageNewsParamVO param) {
  35. Page<PageNewsVO> pageNewsVOPage =
  36. this.baseMapper.pageNews(new Page<>(param.getPageNum(), param.getPageSize()), param);
  37. return PageInfo.PageInfo(pageNewsVOPage);
  38. }
  39. @Override
  40. public ResultData display(Long userId, NewsDisplayParamVO param) {
  41. this.update(new LambdaUpdateWrapper<News>()
  42. .set(News::getDisplay, param.getDisplay())
  43. .set(News::getUpdateTime, Calendar.getInstance().getTime())
  44. .set(News::getUpdaterId, userId)
  45. .eq(News::getId, param.getId()));
  46. return ResultData.ok();
  47. }
  48. @Override
  49. public ResultData putTop(Long userId, NewsPutTopParamVO param) {
  50. LambdaUpdateWrapper<News> updateWrapper = new LambdaUpdateWrapper<News>()
  51. .set(News::getIsTop, param.getIsTop())
  52. .set(News::getUpdateTime, Calendar.getInstance().getTime())
  53. .set(News::getUpdaterId, userId)
  54. .eq(News::getId, param.getId());
  55. if(CommonStatus.YES.code() == param.getIsTop().byteValue()){
  56. updateWrapper.set(News::getTopTime, Calendar.getInstance().getTime());
  57. }
  58. this.update(updateWrapper);
  59. return ResultData.ok();
  60. }
  61. @Override
  62. public ResultData publicNews(Long userId, NewsPublicParamVO param) {
  63. LambdaUpdateWrapper<News> updateWrapper = new LambdaUpdateWrapper<News>()
  64. .set(News::getIsPublic, param.getIsPublic())
  65. .set(News::getUpdateTime, Calendar.getInstance().getTime())
  66. .set(News::getUpdaterId, userId)
  67. .eq(News::getId, param.getId());
  68. if(CommonStatus.YES.code() == param.getIsPublic().byteValue()){
  69. updateWrapper.set(News::getPublicTime, Calendar.getInstance().getTime());
  70. }
  71. this.update(updateWrapper);
  72. return ResultData.ok();
  73. }
  74. @Override
  75. public ResultData delete(Long userId, BaseParamVO param) {
  76. this.update(new LambdaUpdateWrapper<News>()
  77. .set(News::getTbStatus, TbStatus.DELETE.code())
  78. .set(News::getUpdateTime, Calendar.getInstance().getTime())
  79. .set(News::getUpdaterId, userId)
  80. .eq(News::getId, param.getId()));
  81. return ResultData.ok();
  82. }
  83. @Override
  84. public News getNewsDetail(BaseParamVO param) {
  85. return this.getById(param.getId());
  86. }
  87. @Override
  88. public ResultData addNews(Long userId, SaveNewsParamVO param) {
  89. News news = BeanUtil.copyProperties(param, News.class);
  90. news.setCreaterId(userId);
  91. news.setPublicTime(Calendar.getInstance().getTime());
  92. this.save(news);
  93. return ResultData.ok();
  94. }
  95. @Override
  96. public ResultData updateNews(Long userId, UpdateNewsParamVO param) {
  97. News news = BeanUtil.copyProperties(param, News.class);
  98. news.setUpdateTime(Calendar.getInstance().getTime());
  99. news.setUpdaterId(userId);
  100. this.updateById(news);
  101. return ResultData.ok();
  102. }
  103. }