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 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 id) { return lectureMapper.batchDeleteByPrimaryKey(id); } @SuppressWarnings("unchecked") @Override public Pagination listLecture(String uid, String username, String name, String startLectureTime, String endLectureTime, Integer pageNo, Integer pageSize) { Map 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) findPage("findLectureListByPage", "findLectureCount", params, pageNo, pageSize); } @Override public Integer countDynamicNum() { return lectureMapper.countDynamicNum(); } @Override public Integer countHotNum() { return lectureMapper.countHotNum(); } @Override public List listHot() { return lectureMapper.listHot(); } @Override @Cacheable(value = "LectureDynamicListCache", key = "'LectureDynamicList:'+#lectureDynamicListCacheKey") public List 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 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 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 loadMore(Integer pageSize, Integer pageNo) { Map params = new HashMap(); params.put("pageSize", pageSize); params.put("pageNo", pageNo); return lectureMapper.findMoreLectureList(params); } }