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

req和resp封装

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