This commit is contained in:
张良(004796)
2024-01-02 17:01:28 +08:00
parent cf724410f3
commit 2c68510a02
17 changed files with 73 additions and 24 deletions

View File

@@ -15,4 +15,5 @@ public interface CitysService extends IService<Citys> {
Map<Long,String> all();
String getByCityId(Integer cityId);
}

View File

@@ -31,7 +31,7 @@ public class AnchorServiceImpl extends ServiceImpl<AnchorMapper, Anchor> impleme
@Override
public Page<AnchorListVo> pageApp(PageQuery pageQuery, AnchorListQuery query) {
if(query.getType() != null && query.getType() != 3){
query.setCity(null);
query.setCityId(null);
}
return baseMapper.pageApp(pageQuery.build(),query);
}

View File

@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -29,9 +30,16 @@ public class CitysServiceImpl extends ServiceImpl<CitysMapper, Citys> implements
@Autowired
private StringRedisTemplate redisTemplate;
@PostConstruct
public void init() {
List<Citys> list = this.list();
Map<Long, String> map = list.stream().collect(Collectors.toMap(Citys::getId, Citys::getName));
redisTemplate.opsForHash().putAll(RedisConstant.CITY_CACHE_REDIS, map);
}
@Override
public Map<Long, String> all() {
String value = redisTemplate.opsForValue().get(RedisConstant.CITY_CACHE_REDIS);
String value = redisTemplate.opsForValue().get(RedisConstant.CITY_CACHE_ALL_REDIS);
if(value != null){
return JSON.parseObject(value, new TypeReference<LinkedHashMap<Long, String>>(){});
}
@@ -40,4 +48,21 @@ public class CitysServiceImpl extends ServiceImpl<CitysMapper, Citys> implements
redisTemplate.opsForValue().set(RedisConstant.CITY_CACHE_REDIS,JSON.toJSONString(map),30, TimeUnit.DAYS);
return map;
}
@Override
public String getByCityId(Integer cityId){
if(cityId == null || cityId == 0){
return null;
}
Object val = redisTemplate.opsForHash().get(RedisConstant.CITY_CACHE_REDIS, cityId);
if(val != null){
return String.valueOf(val);
}
Citys city = this.getById(cityId);
if(city == null){
return null;
}
redisTemplate.opsForHash().put(RedisConstant.CITY_CACHE_REDIS, cityId, city.getName());
return city.getName();
}
}

View File

@@ -88,6 +88,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
}
}
vo.setCity(user.getCity());
vo.setCityId(user.getCityId());
vo.setFansNum(userFollowService.getFansNumByUserId(userId));
vo.setStar(userFollowService.checkStar(currentUserId, userId));
vo.setAlbumList(userAlbumService.getUserAlbum(userId, user.getIsAnchor()));