Commit 52f1b37f authored by 刘基明's avatar 刘基明

req和resp封装

parent 98e0f115
package com.tanpu.community.api;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.AlertReq;
import com.tanpu.community.api.beans.req.AlertReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
......
package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
public class FollowQo {
@ApiModelProperty(value = "id")
private String id;
@ApiModelProperty(value = "用户id")
private String userId;
@ApiModelProperty(value = "头像url")
private String headImg;
@ApiModelProperty(value = "昵称")
private String nickName;
@ApiModelProperty(value = "个人简介")
private String introduction;
@ApiModelProperty(value = "是否关注")
private boolean followed;
}
package com.tanpu.community.api.beans;
package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -7,7 +7,7 @@ import java.time.LocalDateTime;
import java.util.List;
@Data
public class ThemeDTO {
public class ThemeQo {
private static final long serialVersionUID = 1L;
......@@ -29,8 +29,8 @@ public class ThemeDTO {
@ApiModelProperty(value = "所属的话题")
private String topicId;
@ApiModelProperty(value = "用户名")
private String userName;
@ApiModelProperty(value = "昵称")
private String nickName;
@ApiModelProperty(value = "用户头像")
private String userImg;
......@@ -59,15 +59,9 @@ public class ThemeDTO {
@ApiModelProperty("附件")
private List<Object> attachment;
private String createBy;
private Object attachmentInfo;
private LocalDateTime createTime;
private String updateBy;
private LocalDateTime updateTime;
private Integer deleteTag;
private Object attachmentInfo;
}
package com.tanpu.community.api.beans;
package com.tanpu.community.api.beans.req;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
......
package com.tanpu.community.api.beans;
package com.tanpu.community.api.beans.req;
import io.swagger.annotations.ApiModel;
import lombok.Data;
......@@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty;
@ApiModel
@Data
public class CommentReq {
public class CreateCommentReq {
@NotEmpty(message = "主题id不能为空")
private String themeId;
......
package com.tanpu.community.api.beans.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Map;
@Data
public class CreateThemeReq {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题")
private Integer themeType;
@ApiModelProperty(value = "标题")
private String title;
@ApiModelProperty(value = "文本内容")
private String content;
@ApiModelProperty(value = "所属的话题")
private String topicId;
@ApiModelProperty(value = "被转发的主题")
private String formerThemeId;
@ApiModelProperty("附件")
private Map<String,String> attachment;
}
//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.RedisConnectionFactory;
//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
//public class RedisConfig {
//
// @Value("${spring.redis.host}")
// private String host;
// @Value("${spring.redis.port}")
// private int port;
// @Value("${spring.redis.password}")
// private String password;
// @Value("${spring.redis.timeout}")
// private int timeout;
// @Value("${spring.redis.max-active}")
// private int maxActive;
// @Value("${spring.redis.max-wait}")
// private long maxWaitMillis;
// @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("communityKeyGenerator")
// public KeyGenerator keyGenerator() {
// return new RedisConfig.CommunityKeyGenerator();
// }
//
// public static class CommunityKeyGenerator implements KeyGenerator {
// public Object generate(Object target, Method method, Object... params) {
// // todo prefix 加到common
// return "new_community_" + target.getClass().getSimpleName() + "_"
// + method.getName() + "_"
// + StringUtils.arrayToDelimitedString(params, "_");
// }
// }
//}
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
public class RedisConfig {
@Value("${spring.redis.host}")
private String host;
@Value("${spring.redis.port}")
private int port;
@Value("${spring.redis.password}")
private String password;
@Value("${spring.redis.timeout}")
private int timeout;
@Value("${spring.redis.max-active}")
private int maxActive;
@Value("${spring.redis.max-wait}")
private long maxWaitMillis;
@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("communityKeyGenerator")
public KeyGenerator keyGenerator() {
return new RedisConfig.CommunityKeyGenerator();
}
public static class CommunityKeyGenerator implements KeyGenerator {
public Object generate(Object target, Method method, Object... params) {
// todo prefix 加到common
return "new_community_" + target.getClass().getSimpleName() + "_"
+ method.getName() + "_"
+ StringUtils.arrayToDelimitedString(params, "_");
}
}
}
package com.tanpu.community.controller;
import com.tanpu.community.dao.entity.community.FansRelEntity;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.req.homepage.AddIdolReq;
import com.tanpu.community.manager.HomePageManager;
import com.tanpu.community.model.req.homepage.AddIdolReq;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@Slf4j
@RequestMapping(value = "/api/homepage")
public class HomePageController {
@Autowired
......@@ -21,28 +20,49 @@ public class HomePageController {
@PostMapping(value = "/queryMyFans")
@ApiOperation("查询自己的粉丝")
@ResponseBody
public String queryMyFans() {
public CommonResp queryMyFans() {
String userId = "123";
List<FansRelEntity> fans = homePageManager.queryFansByIdolId(userId);
System.out.println(fans.size());
return null;
return CommonResp.success(homePageManager.queryFansByIdolId(userId));
}
@PostMapping(value = "/queryMyFans")
@ApiOperation("查询他人的粉丝")
@ResponseBody
public CommonResp queryFans(@RequestParam String userId) {
return CommonResp.success(homePageManager.queryFansByIdolId(userId));
}
@PostMapping(value = "/queryMyFans")
@ApiOperation("查询自己的关注")
@ResponseBody
public CommonResp queryMyIdols() {
String userId = "123";
return CommonResp.success(homePageManager.queryIdolsByFollowerId(userId));
}
@PostMapping(value = "/queryUserFans")
@ApiOperation("查询他人的关注")
@ResponseBody
public CommonResp queryIdols(@RequestParam String userId) {
return CommonResp.success(homePageManager.queryIdolsByFollowerId(userId));
}
@PostMapping(value = "/addIdol")
@ApiOperation("关注他人")
@ResponseBody
public String addIdol(@RequestBody AddIdolReq req) {
public CommonResp addIdol(@RequestBody AddIdolReq req) {
String userId = "123";
homePageManager.addIdol(req.idolId, userId);
return "11";
return CommonResp.success();
}
@PostMapping(value = "/query/likeTheme")
@ApiOperation("我的点赞")
@ResponseBody
public String likeList(){
public CommonResp likeList(){
String userId="123";
return "success";
return CommonResp.success();
}
}
package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.service.RedisService;
import io.swagger.annotations.ApiOperation;
......@@ -14,8 +15,9 @@ public class MetricsController {
@ApiOperation("浏览量埋点")
@RequestMapping("/pv")
public void pageView(@RequestParam String themeId){
public CommonResp pageView(@RequestParam String themeId){
redisService.incr(RedisKeyConstant.THEME_VIEW_AMOUNT_ +themeId, 1L);
return CommonResp.success();
}
......
package com.tanpu.community.controller;
import com.tanpu.community.api.beans.CommentReq;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.req.CreateCommentReq;
import com.tanpu.community.api.beans.req.CreateThemeReq;
import com.tanpu.community.api.beans.ForwardThemeDTO;
import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.manager.ThemeManager;
import com.tanpu.community.service.FansRelService;
import io.swagger.annotations.ApiOperation;
......@@ -27,25 +29,24 @@ public class ThemeController {
@ApiOperation("新增主题")
@PostMapping(value = "/add")
@ResponseBody
public String insertTheme(@RequestBody ThemeDTO themeDTO){
public CommonResp insertTheme(@RequestBody CreateThemeReq req){
String userId="liujm";
themeDTO.setAuthorId(userId);
// themeManager.insert(ThemeConvert.convertToEntity(themeDTO));
return "success";
themeManager.createTheme(req,userId);
return CommonResp.success();
}
@ApiOperation("获取推荐的圈文")
@ApiOperation("圈子首页-推荐")
@RequestMapping(value = "/recmend_list")
@ResponseBody
public List<ThemeDTO> selectHotList(){
public List<ThemeQo> selectHotList(){
String userId="liujm";
return themeManager.selectHotThemes(userId);
}
@ApiOperation("获取关注的圈文")
@ApiOperation("圈子首页-关注")
@RequestMapping(value = "/interest_list")
@ResponseBody
public List<ThemeDTO> selectInterestList(){
public List<ThemeQo> selectInterestList(){
String userId="liujm012";
return themeManager.selectInterestThemes(userId);
}
......@@ -53,61 +54,61 @@ public class ThemeController {
@ApiOperation("评论")
@RequestMapping(value = "/comment")
@ResponseBody
public String commetOnTheme(@RequestBody CommentReq req){
public CommonResp commetOnTheme(@RequestBody CreateCommentReq req){
String userId="liujm";
themeManager.comment(req,userId);
return "success";
return CommonResp.success();
}
@ApiOperation("转发主题")
@RequestMapping(value = "/forward")
@ResponseBody
public String forwardTheme(ForwardThemeDTO forwardThemeDTO){
public CommonResp forwardTheme(ForwardThemeDTO forwardThemeDTO){
String userId="liujm";
themeManager.forward(forwardThemeDTO,userId);
return "success";
return CommonResp.success();
}
@ApiOperation("点赞主题")
@GetMapping(value = "/like")
@ResponseBody
public String likeOnTheme(@RequestParam String themeId){
public CommonResp likeOnTheme(@RequestParam String themeId){
String user="liujm";
themeManager.like(themeId,user);
return "success";
return CommonResp.success();
}
@ApiOperation("分享主题")
@GetMapping(value = "/share")
@ResponseBody
public String shareTheme(String themeId){
return "success";
public CommonResp shareTheme(String themeId){
return CommonResp.success();
}
@ApiOperation("收藏主题")
@RequestMapping(value = "/book")
@ResponseBody
public String bookTheme(String themeId){
public CommonResp bookTheme(String themeId){
String user="liujm";
// themeManager.book(themeId,user);
return "success";
return CommonResp.success();
}
@ApiOperation("举报主题")
@GetMapping(value = "/complaint")
@ResponseBody
public String complaintTheme(@RequestParam String themeId){
public CommonResp complaintTheme(@RequestParam String themeId){
return "功能暂未开放";
return CommonResp.failed("功能暂未开放");
}
@ApiOperation("屏蔽")
@RequestMapping(value = "/conceal")
@ResponseBody
public String concealTheme(String themeId){
public CommonResp concealTheme(String themeId){
String user="liujm";
// themeManager.blockContent(themeId,user);
return "success";
return CommonResp.success();
}
}
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.manager.TopicManager;
import com.tanpu.community.model.req.topic.TopicConcealReq;
import com.tanpu.community.model.req.topic.TopicModifyMountReq;
import com.tanpu.community.model.req.topic.TopicTopReq;
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 io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -24,75 +26,77 @@ public class TopicController {
@Autowired
private TopicManager topicManager;
@Autowired
private UserHolder userHolder;
@GetMapping(value = "/queryTopicInfoList")
@ApiOperation("APP全部话题页面,可搜索")
@ResponseBody
public List<TopicDTO> getTopicBriefInfoList(){
public CommonResp<List<TopicDTO>> getTopicBriefInfoList(){
List<TopicDTO> allTopic = topicManager.getAllTopicDetail();
return allTopic;
return CommonResp.success(allTopic);
}
@GetMapping(value = "/admin/queryTopicDetailList")
@ApiOperation("查询所有的话题详情")
@ResponseBody
public List<TopicBriefInfoDTO> getAllTopicList(){
public CommonResp<List<TopicBriefInfoDTO>> getAllTopicList(){
List<TopicBriefInfoDTO> allTopic = topicManager.getAllTopicBriefInfo();
return allTopic;
return CommonResp.success(allTopic);
}
@PostMapping(value="/admin/insertTopic")
@ApiOperation("新增话题")
@ResponseBody
public String addTopic(@RequestParam String topicTitle){
//TODO:获取登录用户信息
String userId = "liujm";
public CommonResp addTopic(@RequestParam String topicTitle){
String userId = userHolder.getUserId();
topicManager.insertTopic(topicTitle,userId);
return "success";
return CommonResp.success();
}
@ApiOperation("单个话题数据总览")
@PostMapping("/admin/selectOne")
@ResponseBody
public String selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
public CommonResp selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
TopicDTO topicDTO=topicManager.getDetail(topicId);
return "success";
return CommonResp.success(topicDTO);
}
@PostMapping(value = "/admin/setTop")
@ApiOperation("顶置/取消顶置话题")
@ResponseBody
public String setTopTopic(@RequestBody TopicTopReq req) throws MissingServletRequestParameterException {
public CommonResp setTopTopic(@RequestBody TopicTopReq req) throws MissingServletRequestParameterException {
topicManager.setTopTopic(req.getTopicId(),req.isTop());
return "success";
return CommonResp.success();
}
@PostMapping(value = "/admin/setConceal")
@ApiOperation("隐藏/显示话题")
@ResponseBody
public String setConceal(@RequestBody TopicConcealReq req) throws MissingServletRequestParameterException {
public CommonResp setConceal(@RequestBody TopicConcealReq req) throws MissingServletRequestParameterException {
topicManager.setTopicConceal(req.getTopicId(),req.isConceal());
return "success";
return CommonResp.success();
}
@PostMapping(value = "/admin/modifyViewNum")
@ApiOperation("话题浏览数调整")
@ApiOperation("话题浏览数调整(后台管理)")
@ResponseBody
public String modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException {
public CommonResp modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException {
topicManager.modifyViewAmount(req.getTopicId(),req.getModifyMount());
return "success";
return CommonResp.success();
}
@PostMapping(value = "/admin/dataAnalys")
@ApiOperation("话题数据分析")
@ApiOperation("话题数据分析(后台管理)")
@ResponseBody
public TopicDataAnalysDTO dataAnalys(@RequestParam String topicId) throws MissingServletRequestParameterException {
public CommonResp<TopicDataAnalysDTO> dataAnalys(@RequestParam String topicId) throws MissingServletRequestParameterException {
TopicDataAnalysDTO result =topicManager.queryDataAnalysis(topicId);
return result;
return CommonResp.success(result);
}
......
......@@ -22,7 +22,7 @@ public class CodeAutoGenerator {
String mysqlUserName = "tamp_admin";
String mysqlPassword = "@imeng123";
String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community";
String[] tables = new String[]{"collection"};
String[] tables = new String[]{"home_page"};
// String[] tables = new String[]{"visit_summary", "black_list","collection","comment","fans_rel","file_record","home_page","theme","topic"};
String basePackage = "com.tanpu.community";
String mapperPackage = "dao.mapper.community";
......
package com.tanpu.community.dao.entity.community;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
......@@ -12,8 +16,11 @@ import io.swagger.annotations.ApiModelProperty;
* </p>
*
* @author xudong
* @since 2021-06-10
* @since 2021-06-29
*/
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("home_page")
@ApiModel(value="HomePageEntity对象", description="个人主页")
public class HomePageEntity implements Serializable {
......@@ -35,6 +42,12 @@ public class HomePageEntity implements Serializable {
@ApiModelProperty(value = "个人简介")
private String introduction;
@ApiModelProperty(value = "性别")
private Integer sex;
@ApiModelProperty(value = "地址")
private String location;
private String createBy;
private LocalDateTime createTime;
......@@ -86,6 +99,22 @@ public class HomePageEntity implements Serializable {
this.introduction = introduction;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getCreateBy() {
return createBy;
}
......@@ -134,6 +163,8 @@ public class HomePageEntity implements Serializable {
", headImg=" + headImg +
", nickName=" + nickName +
", introduction=" + introduction +
", sex=" + sex +
", location=" + location +
", createBy=" + createBy +
", createTime=" + createTime +
", updateBy=" + updateBy +
......
package com.tanpu.community.manager;
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 com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.service.FansRelService;
import com.tanpu.community.service.HomePageService;
import com.tanpu.community.util.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class HomePageManager {
......@@ -16,16 +18,19 @@ public class HomePageManager {
@Autowired
private FansRelService fansRelService;
public List<FansRelEntity> queryFansByFollowerId(String followerId) {
return fansRelService.queryFansByFollowerId(followerId);
@Resource
private HomePageService homePageService;
// todo 组装粉丝的头像等信息
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<FansRelEntity> queryFansByIdolId(String idolId) {
return fansRelService.queryFansByIdolId(idolId);
// todo 组装粉丝的头像等信息
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 void addIdol(String idolId, String followerId) {
......
package com.tanpu.community.manager;
import com.tanpu.community.api.beans.CommentReq;
import com.tanpu.community.api.beans.req.CreateCommentReq;
import com.tanpu.community.api.beans.req.CreateThemeReq;
import com.tanpu.community.api.beans.ForwardThemeDTO;
import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.constants.BlockTypeEnum;
import com.tanpu.community.api.constants.CollectionTypeEnum;
import com.tanpu.community.api.constants.CommentTypeEnum;
......@@ -12,6 +13,7 @@ import com.tanpu.community.dao.entity.user.OrderFlowEntity;
import com.tanpu.community.service.*;
import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -20,7 +22,7 @@ import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@Service
......@@ -58,27 +60,40 @@ public class ThemeManager {
@Autowired
private ThemeAttachmentService themeAttachmentService;
@Autowired
private HomePageService homePageService;
public void createTheme(CreateThemeReq req, String userId) {
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req,themeEntity);
themeEntity.setAuthorId(userId);
themeService.insertTheme(themeEntity);
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req,themeEntity.getId());
themeAttachmentService.insertList(themeAttachments);
}
// 返回推荐主题文章
public List<ThemeDTO> selectHotThemes(String userId) {
public List<ThemeQo> selectHotThemes(String userId) {
// TODO:根据算法计算推荐主题
List<ThemeEntity> themeEntities = themeService.selectAll();
List<ThemeDTO> themeDTOS = ConvertUtil.themeEntitiesToDTOs(themeEntities);
for (ThemeDTO themeDTO : themeDTOS) {
fillDTOExtraInfo(themeDTO, userId);
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
for (ThemeQo themeQO : themeQos) {
fillDTOExtraInfo(themeQO, userId);
}
return themeDTOS;
return themeQos;
}
// 返回关注主题
public List<ThemeDTO> selectInterestThemes(String userId) {
List<String> fansList = fansRelService.queryFansByFollowerId(userId).stream().map(FansRelEntity::getIdolId).collect(Collectors.toList());
public List<ThemeQo> selectInterestThemes(String userId) {
List<String> fansList = fansRelService.queryFansByFollowerId(userId);
List<ThemeEntity> themeEntities = themeService.selectByFans(fansList);
List<ThemeDTO> themeDTOS = ConvertUtil.themeEntitiesToDTOs(themeEntities);
for (ThemeDTO themeDTO : themeDTOS) {
fillDTOExtraInfo(themeDTO, userId);
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
for (ThemeQo themeQO : themeQos) {
fillDTOExtraInfo(themeQO, userId);
}
return themeDTOS;
return themeQos;
}
private String calUpToNowTime(LocalDateTime start) {
......@@ -105,7 +120,7 @@ public class ThemeManager {
}
// 评论(对主题)
public void comment(CommentReq req, String userId) {
public void comment(CreateCommentReq req, String userId) {
CommentEntity commentEntity = CommentEntity.builder()
.targetId(req.getThemeId())
.authorId(userId)
......@@ -177,29 +192,29 @@ public class ThemeManager {
// }
// }
public void insert(ThemeEntity themeEntity) {
themeService.insertTheme(themeEntity);
}
//查询话题所需关联信息
private void fillDTOExtraInfo(ThemeDTO themeDTO,String userId) {
List<ThemeAttachmentEntity> attachments = themeAttachmentService.selectByThemeId(themeDTO.getId());
private void fillDTOExtraInfo(ThemeQo themeQO, String userId) {
List<ThemeAttachmentEntity> attachments = themeAttachmentService.selectByThemeId(themeQO.getId());
if (CollectionUtils.isEmpty(attachments)){
return;
}
List<Object> obs = attachments.stream().map(themeAttachmentEntity -> transferAttachment(themeAttachmentEntity, userId)).collect(Collectors.toList());
themeDTO.setAttachment(obs);
themeQO.setAttachment(obs);
//是否关注
themeDTO.setUpToNowTime(calUpToNowTime(themeDTO.getCreateTime()));
String authorId = themeDTO.getCreateBy();
Map<String, FansRelEntity> fansMap = fansRelService.queryFansByFollowerId(userId).stream().collect(Collectors.toMap(FansRelEntity::getIdolId, c -> c));
if (fansMap.containsKey(authorId)) {
themeDTO.setFollow(true);
themeQO.setUpToNowTime(calUpToNowTime(themeQO.getCreateTime()));
String authorId = themeQO.getAuthorId();
Set<String> fansSet = fansRelService.queryFansByFollowerId(userId).stream().collect(Collectors.toSet());
if (fansSet.contains(authorId)) {
themeQO.setFollow(true);
}else {
themeDTO.setFollow(false);
themeQO.setFollow(false);
}
//TODO 添加用户名、头像、认证、是否关注
HomePageEntity userEntity = homePageService.selectByUser(userId);
themeQO.setUserImg(userEntity.getHeadImg());
themeQO.setNickName(userEntity.getNickName());
}
public Object transferAttachment(ThemeAttachmentEntity themeAttachment,String userId){
......@@ -225,4 +240,5 @@ public class ThemeManager {
}
}
}
......@@ -35,18 +35,22 @@ public class TopicManager {
@Autowired
private CommentService commentService;
//新增话题
public void insertTopic(String topicTitle, String userId) {
topicService.addTopic(topicTitle, userId);
}
if (topicService.queryByTitile(topicTitle) == null){
topicService.addTopic(topicTitle, userId);
}
return;
}
//后台管理-话题列表
//话题详情列表
public List<TopicDTO> getAllTopicDetail() {
return ConvertUtil.topicEntitiesToDTOs(topicService.queryAll());
}
//APP-话题列表
//话题简介列表
public List<TopicBriefInfoDTO> getAllTopicBriefInfo() {
List<TopicEntity> allTopic = topicService.queryAll();
List<TopicBriefInfoDTO> topicDTOS = ConvertUtil.topicEntitiesToBriefDTOs(allTopic);
......@@ -96,6 +100,10 @@ public class TopicManager {
}
public void modifyViewAmount(String topicId, Long modifyMount) {
TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId);
}
topicService.modifyViewAmount(topicId, modifyMount);
if (modifyMount > 0) {
redisService.incr(RedisKeyConstant.TOPIC_TOTAL_VIEW_AMOUNT_ + topicId, modifyMount);
......
......@@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@EnableCaching
@Service
......@@ -17,13 +18,16 @@ public class FansRelService {
@Resource
private FansRelMapper fansRelMapper;
public List<FansRelEntity> queryFansByFollowerId(String followerId) {
return fansRelMapper.selectList(new LambdaQueryWrapper<FansRelEntity>().eq(FansRelEntity::getFollowerId, followerId));
public List<String> queryFansByFollowerId(String followerId) {
return fansRelMapper.selectList(new LambdaQueryWrapper<FansRelEntity>()
.eq(FansRelEntity::getFollowerId, followerId))
.stream().map(FansRelEntity::getIdolId).collect(Collectors.toList());
}
@Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator")
public List<FansRelEntity> queryFansByIdolId(String idolId) {
return fansRelMapper.selectList(new LambdaQueryWrapper<FansRelEntity>().eq(FansRelEntity::getIdolId, idolId));
public List<String> queryFansByIdolId(String idolId) {
return fansRelMapper.selectList(new LambdaQueryWrapper<FansRelEntity>().eq(FansRelEntity::getIdolId, idolId))
.stream().map(FansRelEntity::getFollowerId).collect(Collectors.toList());
}
public void addFans(String idolId, String followerId) {
......
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.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class HomePageService {
@Resource
private HomePageMapper homePageMapper;
public HomePageEntity selectByUser(String userId){
return homePageMapper.selectOne(new LambdaQueryWrapper<HomePageEntity>()
.in(HomePageEntity::getId,userId));
}
public List<HomePageEntity> selectListByUserIds(List<String> userIds){
return homePageMapper.selectList(new LambdaQueryWrapper<HomePageEntity>()
.in(HomePageEntity::getId,userIds));
}
}
......@@ -18,4 +18,11 @@ public class ThemeAttachmentService {
return themeAttachmentMapper.selectList(new LambdaQueryWrapper<ThemeAttachmentEntity>()
.eq(ThemeAttachmentEntity::getThemeId,themeId));
}
public void insertList(List<ThemeAttachmentEntity> themeAttachments) {
for (ThemeAttachmentEntity themeAttachment : themeAttachments) {
themeAttachmentMapper.insert(themeAttachment);
}
return;
}
}
......@@ -80,4 +80,8 @@ public class TopicService {
.eq(TopicEntity::getViewAmountModify, oldAmount));
return;
}
public TopicEntity queryByTitile(String topicTitle) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>().eq(TopicEntity::getTopicTitle, topicTitle));
}
}
package com.tanpu.community.util;
import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.req.CreateThemeReq;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.constants.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.entity.user.CurriculumResEntity;
import com.tanpu.community.dao.entity.user.FinProResEntity;
import com.tanpu.community.dao.entity.user.OrderFlowEntity;
import com.tanpu.community.dao.entity.zhibo.ZhiboThemeEntity;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class ConvertUtil {
public static ThemeDTO themeEntityToDTO(ThemeEntity themeEntity){
ThemeDTO themeDTO = new ThemeDTO();
BeanUtils.copyProperties(themeEntity, themeDTO);
return themeDTO;
public static ThemeQo themeEntityToDTO(ThemeEntity themeEntity) {
ThemeQo themeQO = new ThemeQo();
BeanUtils.copyProperties(themeEntity, themeQO);
return themeQO;
}
public static ThemeEntity themeDTOToEntity(ThemeDTO themeDTO){
public static ThemeEntity themeDTOToEntity(ThemeQo themeQO) {
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(themeDTO,themeEntity);
BeanUtils.copyProperties(themeQO, themeEntity);
return themeEntity;
}
public static List<ThemeDTO> themeEntitiesToDTOs(List<ThemeEntity> themeEntities){
public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) {
return themeEntities.stream().map(ConvertUtil::themeEntityToDTO).collect(Collectors.toList());
}
public static List<ThemeEntity> themeDTOSToEntitys(List<ThemeDTO> themeDTOS){
return themeDTOS.stream().map(ConvertUtil::themeDTOToEntity).collect(Collectors.toList());
public static List<ThemeEntity> themeDTOSToEntitys(List<ThemeQo> themeQos) {
return themeQos.stream().map(ConvertUtil::themeDTOToEntity).collect(Collectors.toList());
}
public static TopicDTO topicEntityToDTO(TopicEntity topicEntity){
public static TopicDTO topicEntityToDTO(TopicEntity topicEntity) {
TopicDTO topicDTO = new TopicDTO();
BeanUtils.copyProperties(topicEntity,topicDTO);
BeanUtils.copyProperties(topicEntity, topicDTO);
return topicDTO;
}
public static TopicBriefInfoDTO topicToBriefInfoDTO(TopicEntity topicEntity){
public static TopicBriefInfoDTO topicToBriefInfoDTO(TopicEntity topicEntity) {
TopicBriefInfoDTO topicBriefInfoDTO = new TopicBriefInfoDTO();
BeanUtils.copyProperties(topicEntity,topicBriefInfoDTO);
BeanUtils.copyProperties(topicEntity, topicBriefInfoDTO);
return topicBriefInfoDTO;
}
public static List<TopicDTO> topicEntitiesToDTOs(List<TopicEntity> topicEntities){
public static List<TopicDTO> topicEntitiesToDTOs(List<TopicEntity> topicEntities) {
return topicEntities.stream().map(ConvertUtil::topicEntityToDTO).collect(Collectors.toList());
}
......@@ -64,7 +65,7 @@ public class ConvertUtil {
public static DeleteTagEnum deleteTagShift(DeleteTagEnum deleteTagEnum) {
if (deleteTagEnum.getCode().equals(DeleteTagEnum.NOT_DELETED.getCode())) {
return DeleteTagEnum.DELETED;
}else {
} else {
return DeleteTagEnum.NOT_DELETED;
}
}
......@@ -72,9 +73,34 @@ public class ConvertUtil {
public static Integer deleteTagShift(Integer deleteTag) {
if (deleteTag.equals(DeleteTagEnum.NOT_DELETED.getCode())) {
return DeleteTagEnum.DELETED.getCode();
}else {
} else {
return DeleteTagEnum.NOT_DELETED.getCode();
}
}
public static List<ThemeAttachmentEntity> themeReqToAttachmentList(CreateThemeReq req, String themeId) {
if (req == null || req.getAttachment() == null || req.getAttachment().size() == 0) {
return Collections.emptyList();
}
List<ThemeAttachmentEntity> list = new ArrayList<>();
req.getAttachment().forEach((k, v) -> {
list.add(ThemeAttachmentEntity.builder()
.attachType(Integer.valueOf(k))
.attchId(v)
.themeId(themeId)
.build());
});
return list;
}
public static FollowQo homePageEntity2FollowQo(HomePageEntity entity) {
if (entity == null) {
return null;
}
FollowQo followQo = new FollowQo();
BeanUtils.copyProperties(entity, followQo);
return followQo;
}
}
......@@ -4,6 +4,8 @@ CREATE TABLE `home_page` (
`head_img` varchar(256) NOT NULL COMMENT '头像url',
`nick_name` varchar(32) NOT NULL COMMENT '昵称',
`introduction` varchar(256) NOT NULL COMMENT '个人简介',
`sex` int(3) COMMENT '性别',
`location` varchar(256) COMMENT '地址',
`create_by` varchar(64) DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`update_by` varchar(64) DEFAULT '',
......
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