LectureServiceImpl.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package com.goafanti.lecture.service.impl;
  2. import java.text.ParseException;
  3. import java.util.Calendar;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.UUID;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.cache.annotation.CacheEvict;
  13. import org.springframework.cache.annotation.Cacheable;
  14. import org.springframework.stereotype.Service;
  15. import com.goafanti.common.constant.AFTConstants;
  16. import com.goafanti.common.dao.LectureMapper;
  17. import com.goafanti.common.enums.DeleteStatus;
  18. import com.goafanti.common.model.Lecture;
  19. import com.goafanti.common.utils.DateUtils;
  20. import com.goafanti.common.utils.LoggerUtils;
  21. import com.goafanti.core.mybatis.BaseMybatisDao;
  22. import com.goafanti.core.mybatis.page.Pagination;
  23. import com.goafanti.lecture.bo.BigShotLectureListBo;
  24. import com.goafanti.lecture.bo.LectureListBo;
  25. import com.goafanti.lecture.service.LectureService;
  26. @Service
  27. public class LectureServiceImpl extends BaseMybatisDao<LectureMapper> implements LectureService {
  28. private static final Logger logger = LoggerFactory.getLogger(LectureServiceImpl.class);
  29. @Autowired
  30. private LectureMapper lectureMapper;
  31. @Override
  32. public void save(Lecture l, String lectureTimeFormattedDate, String endTimeFormattedDate) {
  33. l.setId(UUID.randomUUID().toString());
  34. try {
  35. l.setLectureTime(DateUtils.parseDate(lectureTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS));
  36. l.setEndTime(DateUtils.parseDate(endTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS));
  37. } catch (ParseException e) {
  38. }
  39. Calendar now = Calendar.getInstance();
  40. now.set(Calendar.MILLISECOND, 0);
  41. l.setCreateTime(now.getTime());
  42. l.setLastUpdateTime(l.getCreateTime());
  43. l.setDeletedSign(DeleteStatus.UNDELETE.getCode());
  44. lectureMapper.insert(l);
  45. }
  46. @Override
  47. public void update(Lecture l, String lectureTimeFormattedDate, String endTimeFormattedDate) {
  48. try {
  49. l.setLectureTime(DateUtils.parseDate(lectureTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS));
  50. l.setEndTime(DateUtils.parseDate(endTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS));
  51. } catch (ParseException e) {
  52. }
  53. Calendar now = Calendar.getInstance();
  54. now.set(Calendar.MILLISECOND, 0);
  55. l.setLastUpdateTime(now.getTime());
  56. lectureMapper.updateByPrimaryKeySelective(l);
  57. }
  58. @Override
  59. public int batchDeleteByPrimaryKey(List<String> id) {
  60. return lectureMapper.batchDeleteByPrimaryKey(id);
  61. }
  62. @SuppressWarnings("unchecked")
  63. @Override
  64. public Pagination<LectureListBo> listLecture(String uid, String username, String name, String startLectureTime,
  65. String endLectureTime, Integer pageNo, Integer pageSize) {
  66. Map<String, Object> params = new HashMap<>();
  67. if (StringUtils.isNotBlank(uid)) {
  68. params.put("uid", uid);
  69. }
  70. if (StringUtils.isNotBlank(username)) {
  71. params.put("username", username);
  72. }
  73. if (StringUtils.isNotBlank(name)) {
  74. params.put("name", name);
  75. }
  76. try {
  77. params.put("startL", StringUtils.isBlank(startLectureTime) ? null
  78. : DateUtils.parseDate(startLectureTime, AFTConstants.YYYYMMDDHHMMSS));
  79. params.put("endL", StringUtils.isBlank(endLectureTime) ? null
  80. : DateUtils.parseDate(endLectureTime, AFTConstants.YYYYMMDDHHMMSS));
  81. } catch (ParseException e) {
  82. }
  83. if (pageNo == null || pageNo < 0) {
  84. pageNo = 1;
  85. }
  86. if (pageSize == null || pageSize < 0 || pageSize > 10) {
  87. pageSize = 10;
  88. }
  89. return (Pagination<LectureListBo>) findPage("findLectureListByPage", "findLectureCount", params, pageNo,
  90. pageSize);
  91. }
  92. @Override
  93. public Integer countDynamicNum() {
  94. return lectureMapper.countDynamicNum();
  95. }
  96. @Override
  97. public Integer countHotNum() {
  98. return lectureMapper.countHotNum();
  99. }
  100. @Override
  101. public List<LectureListBo> listHot() {
  102. return lectureMapper.listHot();
  103. }
  104. @Override
  105. @Cacheable(value = "LectureDynamicListCache", key = "'LectureDynamicList:'+#lectureDynamicListCacheKey")
  106. public List<LectureListBo> listDynamic(Integer lectureDynamicListCacheKey) {
  107. return lectureMapper.listDynamic();
  108. }
  109. @Override
  110. @CacheEvict(value = "LectureDynamicListCache", key = "'LectureDynamicList:'+#lectureDynamicListCacheKey")
  111. public void clearLectureDynamicList(Integer lectureDynamicListCacheKey) {
  112. LoggerUtils.debug(logger, "清除科技明星页面科技讲堂列表缓存:[%s]", lectureDynamicListCacheKey);
  113. }
  114. @Override
  115. @Cacheable(value = "BigShotLectureListCache", key = "'BigShotLectureList:'+#bigShotLectureCacheKey")
  116. public List<BigShotLectureListBo> listBigShotLecture(Integer bigShotLectureCacheKey) {
  117. return lectureMapper.listBigShotLecture();
  118. }
  119. @Override
  120. @CacheEvict(value = "BigShotLectureListCache", key = "'BigShotLectureList:'+#bigShotLectureCacheKey")
  121. public void clearBigShotLectureList(Integer bigShotLectureCacheKey) {
  122. LoggerUtils.debug(logger, "清除大咖说科技讲堂列表缓存:[%s]", bigShotLectureCacheKey);
  123. }
  124. @Override
  125. @Cacheable(value = "LectureListCache", key = "'LectureList:'+#lectureListCacheKey")
  126. public List<LectureListBo> findLectureList(Integer lectureListCacheKey) {
  127. return lectureMapper.findLectureList();
  128. }
  129. @Override
  130. @CacheEvict(value = "LectureListCache", key = "'LectureList:'+#lectureListCacheKey")
  131. public void clearLectureList(Integer lectureListCacheKey) {
  132. LoggerUtils.debug(logger, "清除科技讲堂列表缓存:[%s]", lectureListCacheKey);
  133. }
  134. @Override
  135. public List<LectureListBo> loadMore(Integer pageSize, Integer pageNo) {
  136. Map<String, Object> params = new HashMap<String, Object>();
  137. params.put("pageSize", pageSize);
  138. params.put("pageNo", pageNo);
  139. return lectureMapper.findMoreLectureList(params);
  140. }
  141. }