StarServiceImpl.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.goafanti.star.service.impl;
  2. import java.util.HashSet;
  3. import java.util.List;
  4. import java.util.Set;
  5. import java.util.UUID;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.cache.annotation.CacheEvict;
  10. import org.springframework.stereotype.Service;
  11. import com.goafanti.common.dao.StarMapper;
  12. import com.goafanti.common.enums.StarHotType;
  13. import com.goafanti.common.enums.StarType;
  14. import com.goafanti.common.model.Star;
  15. import com.goafanti.common.utils.LoggerUtils;
  16. import com.goafanti.star.bo.BigShotStarListBo;
  17. import com.goafanti.star.bo.HotStarListBo;
  18. import com.goafanti.star.service.StarService;
  19. @Service
  20. public class StarServiceImpl implements StarService {
  21. private static final Logger logger = LoggerFactory.getLogger(StarServiceImpl.class);
  22. @Autowired
  23. private StarMapper starMapper;
  24. @Override
  25. public List<HotStarListBo> listHotStar() {
  26. return starMapper.listHostStar();
  27. }
  28. @Override
  29. public List<HotStarListBo> listStarList() {
  30. return starMapper.listStarList();
  31. }
  32. @Override
  33. public void save(List<Star> startList, String[] hot) {
  34. starMapper.deleteAll();
  35. Set<String> set = new HashSet<>();
  36. for (Star s : startList) {
  37. s.setId(UUID.randomUUID().toString());
  38. s.setHot(StarHotType.UNHOT.getCode());
  39. for (String h : hot) {
  40. if (s.getUid().equals(h)) {
  41. s.setHot(StarHotType.HOT.getCode());
  42. } else {
  43. set.add(h);
  44. }
  45. }
  46. }
  47. Star star = null;
  48. for (String s : set) {
  49. star = new Star();
  50. star.setId(UUID.randomUUID().toString());
  51. star.setUid(s);
  52. star.setHot(StarHotType.HOT.getCode());
  53. star.setStar(StarType.UNSTAR.getCode());
  54. startList.add(star);
  55. }
  56. starMapper.insertBatch(startList);
  57. }
  58. @Override
  59. //@Cacheable(value = "BigShotStarListCache", key = "'BigShotStarList:'+#bigShotStarCacheKey")
  60. public List<BigShotStarListBo> listBigShotStar(Integer bigShotStarCacheKey) {
  61. return starMapper.listBigShotStar();
  62. }
  63. @Override
  64. @CacheEvict(value = "BigShotStarListCache", key = "'BigShotStarList:'+#bigShotStarCacheKey")
  65. public void clearBigShotStarList(Integer bigShotStarCacheKey) {
  66. LoggerUtils.debug(logger, "清除大咖说科技明星列表缓存:[%s]", bigShotStarCacheKey);
  67. }
  68. }