Commit 33e75dd2 authored by 刘基明's avatar 刘基明

HomePageController

parent 198af5af
package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class FollowQo {
......
package com.tanpu.community.api.beans.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@Data
public class HomePageReq {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "头像url")
@NotEmpty(message = "头像不能为空")
private String headImg;
@ApiModelProperty(value = "昵称")
@NotEmpty(message = "用户昵称不能为空")
private String nickName;
@ApiModelProperty(value = "个人简介")
@NotEmpty(message = "个人简介不能为空")
private String introduction;
@ApiModelProperty(value = "性别")
private Integer sex;
@ApiModelProperty(value = "地址")
private String location;
}
package com.tanpu.community.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import redis.clients.jedis.JedisPoolConfig;
import java.lang.reflect.Method;
import java.time.Duration;
@Configuration
@EnableCaching
......@@ -38,49 +28,49 @@ public class RedisConfig {
@Value("${spring.redis.max-idle}")
private int maxIdle;
@Bean
public JedisPoolConfig jedisPoolConfig() {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
// maximum connection
jedisPoolConfig.setMaxTotal(maxActive);
// Maximum wait time when no connection is available in the pool
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
// Maximum number of idle connections
jedisPoolConfig.setMinIdle(maxIdle);
// Other properties can be added by yourself
return jedisPoolConfig;
}
@Bean
public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {
JedisClientConfiguration jedisClientConfiguration = JedisClientConfiguration.builder().usePooling()
.poolConfig(jedisPoolConfig).and().readTimeout(Duration.ofMillis(timeout)).build();
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port);
redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
return new JedisConnectionFactory(redisStandaloneConfiguration, jedisClientConfiguration);
}
@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory(jedisPoolConfig()));
return template;
}
/**
* cache
*/
@Bean
public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() {
return (builder) -> RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory(jedisPoolConfig()))
.withCacheConfiguration("tempCache",
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(10)))
.withCacheConfiguration("longCache",
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(7)));
}
// @Bean
// public JedisPoolConfig jedisPoolConfig() {
// JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
// // maximum connection
// jedisPoolConfig.setMaxTotal(maxActive);
// // Maximum wait time when no connection is available in the pool
// jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
// // Maximum number of idle connections
// jedisPoolConfig.setMinIdle(maxIdle);
// // Other properties can be added by yourself
// return jedisPoolConfig;
// }
//
// @Bean
// public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {
// JedisClientConfiguration jedisClientConfiguration = JedisClientConfiguration.builder().usePooling()
// .poolConfig(jedisPoolConfig).and().readTimeout(Duration.ofMillis(timeout)).build();
// RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
// redisStandaloneConfiguration.setHostName(host);
// redisStandaloneConfiguration.setPort(port);
// redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
// return new JedisConnectionFactory(redisStandaloneConfiguration, jedisClientConfiguration);
// }
//
// @Bean
// public RedisTemplate<String, Object> redisTemplate() {
// RedisTemplate<String, Object> template = new RedisTemplate<>();
// template.setConnectionFactory(jedisConnectionFactory(jedisPoolConfig()));
//
// return template;
// }
//
// /**
// * cache
// */
// @Bean
// public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() {
// return (builder) -> RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory(jedisPoolConfig()))
// .withCacheConfiguration("tempCache",
// RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(10)))
// .withCacheConfiguration("longCache",
// RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(7)));
// }
@Bean("communityKeyGenerator")
public KeyGenerator keyGenerator() {
......
package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.beans.TopicDataAnalysDTO;
import com.tanpu.community.api.beans.req.topic.TopicConcealReq;
import com.tanpu.community.api.beans.req.topic.TopicModifyMountReq;
import com.tanpu.community.api.beans.req.topic.TopicTopReq;
import com.tanpu.community.manager.TopicManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@Slf4j
@RequestMapping(value = "/api/admin")
public class AdminController {
@Autowired
private TopicManager topicManager;
@Autowired
private UserHolder userHolder;
@GetMapping(value = "/admin/queryTopicDetailList")
@ApiOperation("查询所有的话题详情")
@ResponseBody
public CommonResp<List<TopicBriefInfoDTO>> getAllTopicList(){
List<TopicBriefInfoDTO> allTopic = topicManager.getAllTopicBriefInfo();
return CommonResp.success(allTopic);
}
@PostMapping(value="/admin/insertTopic")
@ApiOperation("新增话题")
@ResponseBody
public CommonResp<Void> addTopic(@RequestParam String topicTitle){
String userId = userHolder.getUserId();
topicManager.insertTopic(topicTitle,userId);
return CommonResp.success();
}
@ApiOperation("单个话题详细数据")
@PostMapping("/topic/detailData")
@ResponseBody
public CommonResp<TopicDTO> selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
TopicDTO topicDTO=topicManager.getDetail(topicId);
return CommonResp.success(topicDTO);
}
@PostMapping(value = "/topic/setTop")
@ApiOperation("顶置/取消顶置话题")
@ResponseBody
public CommonResp<Void> setTopTopic(@RequestBody TopicTopReq req) throws MissingServletRequestParameterException {
topicManager.setTopTopic(req.getTopicId(),req.isTop());
return CommonResp.success();
}
@PostMapping(value = "/topic/setConceal")
@ApiOperation("隐藏/显示话题")
@ResponseBody
public CommonResp<Void> setConceal(@RequestBody TopicConcealReq req) throws MissingServletRequestParameterException {
topicManager.setTopicConceal(req.getTopicId(),req.isConceal());
return CommonResp.success();
}
@PostMapping(value = "/topic/modifyViewNum")
@ApiOperation("话题浏览数调整(后台管理)")
@ResponseBody
public CommonResp<Void> modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException {
topicManager.modifyViewAmount(req.getTopicId(),req.getModifyMount());
return CommonResp.success();
}
@PostMapping(value = "/topic/dataAnalyse")
@ApiOperation("话题数据分析")
@ResponseBody
public CommonResp<TopicDataAnalysDTO> dataAnalyse(@RequestParam String topicId) throws MissingServletRequestParameterException {
TopicDataAnalysDTO result =topicManager.queryDataAnalysis(topicId);
return CommonResp.success(result);
}
}
package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.req.HomePageReq;
import com.tanpu.community.api.beans.req.homepage.AddIdolReq;
import com.tanpu.community.manager.HomePageManager;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@Slf4j
@RequestMapping(value = "/api/homepage")
public class HomePageController {
@Autowired
private HomePageManager homePageManager;
@PostMapping(value = "/queryMyFans")
@PostMapping(value = "/editUserInfo")
@ApiModelProperty("编辑个人资料")
@ResponseBody
public CommonResp<String> editUserInfo(@Validated @RequestBody HomePageReq req){
String userId="liujm";
homePageManager.editUserInfo(req,userId);
return CommonResp.success("修改成功");
}
@GetMapping(value = "/queryMyFans")
@ApiOperation("查询自己的粉丝")
@ResponseBody
public CommonResp queryMyFans() {
public CommonResp<List<FollowQo>> queryMyFans() {
String userId = "123";
return CommonResp.success(homePageManager.queryFansByIdolId(userId));
List<FollowQo> data = homePageManager.queryFansByIdolId(userId);
homePageManager.judgeFollowed(data,userId);
return CommonResp.success(data);
}
@PostMapping(value = "/queryUserFans")
@GetMapping(value = "/queryFansByUserId")
@ApiOperation("查询他人的粉丝")
@ResponseBody
public CommonResp queryFans(@RequestParam String userId) {
return CommonResp.success(homePageManager.queryFansByIdolId(userId));
public CommonResp<List<FollowQo>> queryFans(@RequestParam String targetUser) {
String userId="123";
List<FollowQo> data = homePageManager.queryFansByIdolId(targetUser);
homePageManager.judgeFollowed(data,userId);
return CommonResp.success(data);
}
@PostMapping(value = "/queryMyIdols")
@GetMapping(value = "/queryMyIdols")
@ApiOperation("查询自己的关注")
@ResponseBody
public CommonResp queryMyIdols() {
public CommonResp<List<FollowQo>> queryMyIdols() {
String userId = "123";
return CommonResp.success(homePageManager.queryIdolsByFollowerId(userId));
List<FollowQo> data = homePageManager.queryIdolsByFollowerId(userId);
homePageManager.judgeFollowed(data,userId);
return CommonResp.success(data);
}
@PostMapping(value = "/queryUserIdols")
@GetMapping(value = "/queryIdolsByUserId")
@ApiOperation("查询他人的关注")
@ResponseBody
public CommonResp queryIdols(@RequestParam String userId) {
return CommonResp.success(homePageManager.queryIdolsByFollowerId(userId));
public CommonResp queryIdols(@RequestParam String targetUser) {
String userId="123";
List<FollowQo> data = homePageManager.queryIdolsByFollowerId(targetUser);
homePageManager.judgeFollowed(data,userId);
return CommonResp.success(data);
}
@PostMapping(value = "/addIdol")
......@@ -57,7 +84,7 @@ public class HomePageController {
return CommonResp.success();
}
@PostMapping(value = "/query/likeTheme")
@PostMapping(value = "/query/queryMyLike")
@ApiOperation("我的点赞")
@ResponseBody
public CommonResp likeList(){
......
......@@ -38,66 +38,7 @@ public class TopicController {
return CommonResp.success(allTopic);
}
@GetMapping(value = "/admin/queryTopicDetailList")
@ApiOperation("查询所有的话题详情")
@ResponseBody
public CommonResp<List<TopicBriefInfoDTO>> getAllTopicList(){
List<TopicBriefInfoDTO> allTopic = topicManager.getAllTopicBriefInfo();
return CommonResp.success(allTopic);
}
@PostMapping(value="/admin/insertTopic")
@ApiOperation("新增话题")
@ResponseBody
public CommonResp addTopic(@RequestParam String topicTitle){
String userId = userHolder.getUserId();
topicManager.insertTopic(topicTitle,userId);
return CommonResp.success();
}
@ApiOperation("单个话题数据总览")
@PostMapping("/admin/selectOne")
@ResponseBody
public CommonResp selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
TopicDTO topicDTO=topicManager.getDetail(topicId);
return CommonResp.success(topicDTO);
}
@PostMapping(value = "/admin/setTop")
@ApiOperation("顶置/取消顶置话题")
@ResponseBody
public CommonResp setTopTopic(@RequestBody TopicTopReq req) throws MissingServletRequestParameterException {
topicManager.setTopTopic(req.getTopicId(),req.isTop());
return CommonResp.success();
}
@PostMapping(value = "/admin/setConceal")
@ApiOperation("隐藏/显示话题")
@ResponseBody
public CommonResp setConceal(@RequestBody TopicConcealReq req) throws MissingServletRequestParameterException {
topicManager.setTopicConceal(req.getTopicId(),req.isConceal());
return CommonResp.success();
}
@PostMapping(value = "/admin/modifyViewNum")
@ApiOperation("话题浏览数调整(后台管理)")
@ResponseBody
public CommonResp modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException {
topicManager.modifyViewAmount(req.getTopicId(),req.getModifyMount());
return CommonResp.success();
}
@PostMapping(value = "/admin/dataAnalys")
@ApiOperation("话题数据分析(后台管理)")
@ResponseBody
public CommonResp<TopicDataAnalysDTO> dataAnalys(@RequestParam String topicId) throws MissingServletRequestParameterException {
TopicDataAnalysDTO result =topicManager.queryDataAnalysis(topicId);
return CommonResp.success(result);
}
......
package com.tanpu.community.manager;
import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.req.HomePageReq;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.service.FansRelService;
import com.tanpu.community.service.HomePageService;
......@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service
......@@ -21,18 +23,50 @@ public class HomePageManager {
@Resource
private HomePageService homePageService;
public void editUserInfo(HomePageReq req,String userId) {
HomePageEntity entity = HomePageEntity.builder()
.userId(userId)
.nickName(req.getNickName())
.headImg(req.getHeadImg())
.introduction(req.getIntroduction())
.sex(req.getSex())
.location(req.getLocation())
.build();
if(homePageService.selectByUserId(userId) == null){
homePageService.insert(entity);
}else {
homePageService.update(entity);
}
return;
}
//获取用户的关注列表
public List<FollowQo> queryIdolsByFollowerId(String followerId) {
List<String> idolIds = fansRelService.queryFansByFollowerId(followerId);
List<HomePageEntity> list = homePageService.selectListByUserIds(idolIds);
return list.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList());
}
//获取用户的粉丝列表
public List<FollowQo> queryFansByIdolId(String idolId) {
List<String> fanIds = fansRelService.queryFansByIdolId(idolId);
List<HomePageEntity> list = homePageService.selectListByUserIds(fanIds);
return list.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList());
}
//判断返回列表中的用户是否被当前用户关注
public List<FollowQo> judgeFollowed(List<FollowQo> followQos,String followerId){
Set<String> idolSet = fansRelService.queryFansByFollowerId(followerId).stream().collect(Collectors.toSet());
return followQos.stream().map(o->{
if (idolSet.contains(o.getUserId())){
o.setFollowed(true);
}
return o;
}).collect(Collectors.toList());
}
public void addIdol(String idolId, String followerId) {
fansRelService.addFans(idolId, followerId);
}
......
......@@ -211,7 +211,7 @@ public class ThemeManager {
}else {
themeQO.setFollow(false);
}
HomePageEntity userEntity = homePageService.selectByUser(userId);
HomePageEntity userEntity = homePageService.selectByUserId(userId);
themeQO.setUserImg(userEntity.getHeadImg());
themeQO.setNickName(userEntity.getNickName());
......
......@@ -3,7 +3,6 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.dao.entity.community.FansRelEntity;
import com.tanpu.community.dao.mapper.community.FansRelMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;
......@@ -24,9 +23,10 @@ public class FansRelService {
.stream().map(FansRelEntity::getIdolId).collect(Collectors.toList());
}
@Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator")
// @Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator")
public List<String> queryFansByIdolId(String idolId) {
return fansRelMapper.selectList(new LambdaQueryWrapper<FansRelEntity>().eq(FansRelEntity::getIdolId, idolId))
return fansRelMapper.selectList(new LambdaQueryWrapper<FansRelEntity>()
.eq(FansRelEntity::getIdolId, idolId))
.stream().map(FansRelEntity::getFollowerId).collect(Collectors.toList());
}
......
......@@ -3,9 +3,11 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.dao.mapper.community.HomePageMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
@Service
......@@ -16,13 +18,26 @@ public class HomePageService {
private HomePageMapper homePageMapper;
public HomePageEntity selectByUser(String userId){
public HomePageEntity selectByUserId(String userId){
return homePageMapper.selectOne(new LambdaQueryWrapper<HomePageEntity>()
.in(HomePageEntity::getId,userId));
.eq(HomePageEntity::getUserId,userId));
}
public List<HomePageEntity> selectListByUserIds(List<String> userIds){
if (CollectionUtils.isEmpty(userIds)){
return Collections.emptyList();
}
return homePageMapper.selectList(new LambdaQueryWrapper<HomePageEntity>()
.in(HomePageEntity::getId,userIds));
.in(HomePageEntity::getUserId,userIds));
}
public void update(HomePageEntity entity) {
homePageMapper.updateById(entity);
}
public void insert(HomePageEntity entity) {
homePageMapper.insert(entity);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment