| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- package com.goafanti.lecture.service.impl;
- import java.text.ParseException;
- import java.util.Calendar;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.cache.annotation.CacheEvict;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.stereotype.Service;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.dao.LectureMapper;
- import com.goafanti.common.enums.DeleteStatus;
- import com.goafanti.common.model.Lecture;
- import com.goafanti.common.utils.DateUtils;
- import com.goafanti.common.utils.LoggerUtils;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.lecture.bo.BigShotLectureListBo;
- import com.goafanti.lecture.bo.LectureListBo;
- import com.goafanti.lecture.service.LectureService;
- @Service
- public class LectureServiceImpl extends BaseMybatisDao<LectureMapper> implements LectureService {
- private static final Logger logger = LoggerFactory.getLogger(LectureServiceImpl.class);
- @Autowired
- private LectureMapper lectureMapper;
- @Override
- public void save(Lecture l, String lectureTimeFormattedDate, String endTimeFormattedDate) {
- l.setId(UUID.randomUUID().toString());
- try {
- l.setLectureTime(DateUtils.parseDate(lectureTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS));
- l.setEndTime(DateUtils.parseDate(endTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- }
- Calendar now = Calendar.getInstance();
- now.set(Calendar.MILLISECOND, 0);
- l.setCreateTime(now.getTime());
- l.setLastUpdateTime(l.getCreateTime());
- l.setDeletedSign(DeleteStatus.UNDELETE.getCode());
- lectureMapper.insert(l);
- }
- @Override
- public void update(Lecture l, String lectureTimeFormattedDate, String endTimeFormattedDate) {
- try {
- l.setLectureTime(DateUtils.parseDate(lectureTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS));
- l.setEndTime(DateUtils.parseDate(endTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- }
- Calendar now = Calendar.getInstance();
- now.set(Calendar.MILLISECOND, 0);
- l.setLastUpdateTime(now.getTime());
- lectureMapper.updateByPrimaryKeySelective(l);
- }
- @Override
- public int batchDeleteByPrimaryKey(List<String> id) {
- return lectureMapper.batchDeleteByPrimaryKey(id);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<LectureListBo> listLecture(String uid, String username, String name, String startLectureTime,
- String endLectureTime, Integer pageNo, Integer pageSize) {
- Map<String, Object> params = new HashMap<>();
- if (StringUtils.isNotBlank(uid)) {
- params.put("uid", uid);
- }
- if (StringUtils.isNotBlank(username)) {
- params.put("username", username);
- }
- if (StringUtils.isNotBlank(name)) {
- params.put("name", name);
- }
- try {
- params.put("startL", StringUtils.isBlank(startLectureTime) ? null
- : DateUtils.parseDate(startLectureTime, AFTConstants.YYYYMMDDHHMMSS));
- params.put("endL", StringUtils.isBlank(endLectureTime) ? null
- : DateUtils.parseDate(endLectureTime, AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- }
- if (pageNo == null || pageNo < 0) {
- pageNo = 1;
- }
- if (pageSize == null || pageSize < 0 || pageSize > 10) {
- pageSize = 10;
- }
- return (Pagination<LectureListBo>) findPage("findLectureListByPage", "findLectureCount", params, pageNo,
- pageSize);
- }
- @Override
- public Integer countDynamicNum() {
- return lectureMapper.countDynamicNum();
- }
- @Override
- public Integer countHotNum() {
- return lectureMapper.countHotNum();
- }
- @Override
- public List<LectureListBo> listHot() {
- return lectureMapper.listHot();
- }
- @Override
- @Cacheable(value = "LectureDynamicListCache", key = "'LectureDynamicList:'+#lectureDynamicListCacheKey")
- public List<LectureListBo> listDynamic(Integer lectureDynamicListCacheKey) {
- return lectureMapper.listDynamic();
- }
-
- @Override
- @CacheEvict(value = "LectureDynamicListCache", key = "'LectureDynamicList:'+#lectureDynamicListCacheKey")
- public void clearLectureDynamicList(Integer lectureDynamicListCacheKey) {
- LoggerUtils.debug(logger, "清除科技明星页面科技讲堂列表缓存:[%s]", lectureDynamicListCacheKey);
- }
- @Override
- @Cacheable(value = "BigShotLectureListCache", key = "'BigShotLectureList:'+#bigShotLectureCacheKey")
- public List<BigShotLectureListBo> listBigShotLecture(Integer bigShotLectureCacheKey) {
- return lectureMapper.listBigShotLecture();
- }
-
- @Override
- @CacheEvict(value = "BigShotLectureListCache", key = "'BigShotLectureList:'+#bigShotLectureCacheKey")
- public void clearBigShotLectureList(Integer bigShotLectureCacheKey) {
- LoggerUtils.debug(logger, "清除大咖说科技讲堂列表缓存:[%s]", bigShotLectureCacheKey);
- }
- @Override
- @Cacheable(value = "LectureListCache", key = "'LectureList:'+#lectureListCacheKey")
- public List<LectureListBo> findLectureList(Integer lectureListCacheKey) {
- return lectureMapper.findLectureList();
- }
-
- @Override
- @CacheEvict(value = "LectureListCache", key = "'LectureList:'+#lectureListCacheKey")
- public void clearLectureList(Integer lectureListCacheKey) {
- LoggerUtils.debug(logger, "清除科技讲堂列表缓存:[%s]", lectureListCacheKey);
- }
- @Override
- public List<LectureListBo> loadMore(Integer pageSize, Integer pageNo) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("pageSize", pageSize);
- params.put("pageNo", pageNo);
- return lectureMapper.findMoreLectureList(params);
-
- }
-
-
-
- }
|