├── README.md ├── src ├── main │ ├── java │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ └── com │ │ │ └── example │ │ │ └── demo │ │ │ ├── mapper │ │ │ ├── MockUserMapper.java │ │ │ ├── MockFeedsMapper.java │ │ │ ├── TagListMapper.java │ │ │ ├── UserMapper.java │ │ │ ├── CommentMapper.java │ │ │ ├── UgcCommentMapper.java │ │ │ ├── FeedsMapper.java │ │ │ └── UgcMapper.java │ │ │ ├── DemoApplication.java │ │ │ ├── SwaggerMvcConfig.java │ │ │ ├── table │ │ │ ├── TableTagList.java │ │ │ ├── TableHotFeeds.java │ │ │ ├── User.java │ │ │ ├── TableComment.java │ │ │ ├── TableFeedUgc.java │ │ │ └── TableUser.java │ │ │ ├── Swagger2Config.java │ │ │ ├── ApiResponse.java │ │ │ ├── JsonConverterConfig.java │ │ │ ├── JsonNullConfig.java │ │ │ └── controller │ │ │ ├── TagListController.java │ │ │ ├── CommentController.java │ │ │ ├── UserController.java │ │ │ ├── FeedsController.java │ │ │ └── UgcController.java │ └── resources │ │ ├── application.yml │ │ └── com │ │ └── example │ │ └── demo │ │ └── mapper │ │ ├── MockUserMapper.xml │ │ ├── TagListMapper.xml │ │ ├── CommentMapper.xml │ │ ├── UgcCommentMapper.xml │ │ ├── UserMapper.xml │ │ ├── MockFeedsMapper.xml │ │ ├── FeedsMapper.xml │ │ └── UgcMapper.xml └── test │ └── java │ └── com │ └── example │ └── demo │ └── DemoApplicationTests.java ├── .gitignore ├── pom.xml └── HELP.md /README.md: -------------------------------------------------------------------------------- 1 | # PPJoke-Web 2 | 3 | ### [Jetpack开发短视频应用APP](https://github.com/zion223/Jetpack-MVVM-PPJoke) 项目后端源码 4 | -------------------------------------------------------------------------------- /src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: com.example.demo.DemoApplication 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /src/test/java/com/example/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/MockUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.table.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | @Mapper 9 | public interface MockUserMapper { 10 | int delete(int id); 11 | 12 | int Update(User user); 13 | 14 | int insertUser(User user); 15 | 16 | List ListUser(); 17 | 18 | List findUserByName(String name); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | @SpringBootApplication 8 | public class DemoApplication { 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | @RequestMapping(value = "") 14 | public String welcome() { 15 | return "

welcome to jetpack server

"; 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/MockFeedsMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.table.TableComment; 4 | import com.example.demo.table.TableHotFeeds; 5 | import com.example.demo.table.TableTagList; 6 | import com.example.demo.table.TableUser; 7 | import org.apache.ibatis.annotations.Mapper; 8 | 9 | @Mapper 10 | public interface MockFeedsMapper { 11 | 12 | int insertHotFeeds(TableHotFeeds feeds); 13 | 14 | 15 | int insertTag(TableTagList tagList); 16 | 17 | 18 | int insertComments(TableComment comment); 19 | 20 | 21 | int insertUser(TableUser user); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/TagListMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.table.TableTagList; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface TagListMapper { 11 | List queryTagList(@Param("tagId") long tagId, 12 | @Param("pageCount") int pageCount, 13 | @Param("userId") long userId, 14 | @Param("tagType") String tagType, 15 | @Param("offset") int offset); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 #设置端口号 3 | servlet: 4 | context-path: /serverdemo 5 | 6 | 7 | spring: 8 | datasource: 9 | url: jdbc:mysql://62.234.57.125:3306/ppjoke?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true 10 | username: root 11 | password: 15215325438+Aa 12 | driver-class-name: com.mysql.cj.jdbc.Driver 13 | tomcat: 14 | init-s-q-l: SET NAMES utf8mb4 15 | 16 | servlet: 17 | multipart: 18 | file-size-threshold:2KB 19 | max-file-size:200MB 20 | max-request-size:215MB 21 | 22 | jpa: 23 | hibernate: 24 | ddl-auto: update 25 | show-sql: true 26 | 27 | mybatis: 28 | configuration: 29 | logImpl: org.apache.ibatis.logging.stdout.StdOutImpl 30 | type-aliases-package: com.example.demo.table 31 | mapper-locations: classpath:/com/example/demo/mapper/*.xml 32 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.table.TableUser; 4 | import com.example.demo.table.User; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import java.util.List; 9 | 10 | @Mapper 11 | public interface UserMapper { 12 | TableUser queryUser(@Param("userId") long userId); 13 | 14 | TableUser queryUserByQQOpenId(@Param("qqOpenId") String qqOpenId); 15 | 16 | int delete(@Param("userId") long userId); 17 | 18 | int Update(@Param("user") TableUser user); 19 | 20 | int insertUser(@Param("user") TableUser user); 21 | 22 | List queryFans(@Param("userId") long userId, @Param("offset") int offset, @Param("pageCount") int pageCount); 23 | 24 | List queryFollows(@Param("userId") long userId, @Param("offset") int offset, @Param("pageCount") int pageCount); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/SwaggerMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | @Configuration 8 | public class SwaggerMvcConfig extends WebMvcConfigurerAdapter { 9 | 10 | @Override 11 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 12 | registry.addResourceHandler("/**") 13 | .addResourceLocations("classpath:/static/"); 14 | // 解决swagger无法访问 15 | registry.addResourceHandler("/swagger-ui.html") 16 | .addResourceLocations("classpath:/META-INF/resources/"); 17 | // 解决swagger的js文件无法访问 18 | registry.addResourceHandler("/webjars/**") 19 | .addResourceLocations("classpath:/META-INF/resources/webjars/"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/CommentMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.table.TableComment; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface CommentMapper { 11 | TableComment queryTopComment(@Param("itemId") long itemId); 12 | 13 | TableComment queryComment(@Param("itemId") long itemId); 14 | 15 | List queryCommentList(@Param("itemId") long itemId, 16 | @Param("id") int id, 17 | @Param("pageCount") int pageCount); 18 | 19 | boolean addComment(@Param("comment") TableComment comment); 20 | 21 | TableComment queryCommentByUserId(@Param("itemId") long itemId, @Param("userId") long userId, @Param("offset") int offset); 22 | 23 | void addWatchHistory(@Param("userId") long userId, @Param("itemId") long itemId, @Param("time") long time); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/table/TableTagList.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.table; 2 | 3 | 4 | import javax.persistence.*; 5 | 6 | @Table(name = "table_tag_list") 7 | @Entity 8 | public class TableTagList { 9 | @Id 10 | @GeneratedValue 11 | public int id; 12 | 13 | @Column(name = "icon", length = 1000) 14 | public String icon; 15 | 16 | @Column(name = "background", length = 1000) 17 | public String background; 18 | 19 | @Column(name = "activity_icon", length = 1000) 20 | public String activityIcon; 21 | 22 | @Column(name = "title") 23 | public String title; 24 | 25 | @Column(name = "intro") 26 | public String intro; 27 | 28 | @Column(name = "feed_num") 29 | public int feedNum; 30 | 31 | @Column(name = "tag_id") 32 | public long tagId; 33 | 34 | @Column(name = "enter_num") 35 | public int enterNum; 36 | 37 | @Column(name = "follow_num") 38 | public int followNum; 39 | 40 | @Transient 41 | public boolean hasFollow; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/UgcCommentMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.table.TableFeedUgc; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | @Mapper 8 | public interface UgcCommentMapper { 9 | TableFeedUgc queryUgcByCommentId(@Param("commentId") long commentId); 10 | 11 | void setCommentUgc(@Param("ugc") TableFeedUgc ugc); 12 | 13 | int increaseCommentCount(@Param("commentId") long commentId, @Param("increaseCount") int increaseCount); 14 | 15 | int increaseLikeCount(@Param("commentId") long commentId, @Param("increaseCount") int increaseCount); 16 | 17 | int increaseShareCount(@Param("commentId") long commentId); 18 | 19 | int toggleCommentLike(@Param("commentId") long commentId, @Param("userId") long userId); 20 | 21 | Object isCommentLike(@Param("commentId") long commentId, @Param("userId") long userId); 22 | 23 | int deleteComment(@Param("itemId") long itemId, @Param("commentId") long commentId); 24 | 25 | int deleteAllComments(@Param("itemId") long itemId); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/FeedsMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.table.TableHotFeeds; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface FeedsMapper { 11 | 12 | List queryHotFeedsList(@Param("feedType") String feedType, 13 | @Param("inId") int id, 14 | @Param("pageCount") int pageCount); 15 | 16 | int addFeed(@Param("feed") TableHotFeeds feed); 17 | 18 | List queryProfileFeeds(@Param("userId") long userId, 19 | @Param("pageCount") int pageCount, 20 | @Param("profileType") String profileType, 21 | @Param("feedId") int feedId); 22 | 23 | int deleteFeed(@Param("itemId") long itemId); 24 | 25 | TableHotFeeds queryFeed(@Param("itemId") long itemId); 26 | 27 | List queryHistory(@Param("userId") Long userId, @Param("pageCount") int pageCount, @Param("feedId") int feedId); 28 | 29 | List queryFavorite(@Param("userId") Long userId, @Param("pageCount") int pageCount, @Param("feedId") int feedId); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/table/TableHotFeeds.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.table; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | 6 | @Entity 7 | @Table(name = "table_hot_feeds") 8 | public class TableHotFeeds implements Serializable { 9 | @Id 10 | @GeneratedValue 11 | public int id; 12 | 13 | @Column(name = "item_id") 14 | public long itemId; 15 | 16 | @Column(name = "item_type") 17 | public int itemType; 18 | 19 | @Column(name = "create_time") 20 | public long createTime; 21 | 22 | @Column(name = "duration", length = 10) 23 | public double duration; 24 | 25 | @Column(name = "feeds_text", length = 1000) 26 | public String feeds_text; 27 | 28 | @Column(name = "author_id") 29 | public long authorId; 30 | 31 | @Column(name = "activity_icon", length = 1000) 32 | public String activityIcon; 33 | 34 | @Column(name = "activity_text") 35 | public String activityText; 36 | 37 | @Column(name = "video_width") 38 | public int width; 39 | 40 | @Column(name = "video_height") 41 | public int height; 42 | 43 | @Column(name = "video_url", length = 1000) 44 | public String url; 45 | 46 | @Column(name = "video_cover", length = 1000) 47 | public String cover; 48 | 49 | @Transient 50 | public TableUser author; 51 | 52 | @Transient 53 | public TableComment topComment; 54 | 55 | @Transient 56 | public TableFeedUgc ugc; 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/table/User.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.table; 2 | 3 | 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | 7 | @ApiModel(value = "用户对象") 8 | public class User { 9 | 10 | @ApiModelProperty(value = "用户Id", name = "id") 11 | private int id; 12 | 13 | @ApiModelProperty(value = "用户名", name = "name") 14 | private String name; 15 | 16 | @ApiModelProperty(value = "用户密码", name = "password") 17 | private String password; 18 | 19 | @ApiModelProperty(value = "用户手机号", name = "number") 20 | private String number; 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getPassword() { 39 | return password; 40 | } 41 | 42 | public void setPassword(String password) { 43 | this.password = password; 44 | } 45 | 46 | 47 | public String getNumber() { 48 | return number; 49 | } 50 | 51 | public void setNumber(String number) { 52 | this.number = number; 53 | } 54 | 55 | 56 | @Override 57 | public String toString() { 58 | return "User [id=" + id + ", name=" + name + ", password=" + password + ", number=" + number + "]"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import springfox.documentation.builders.ApiInfoBuilder; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.spi.DocumentationType; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | @Configuration 16 | @EnableSwagger2 17 | @EnableWebMvc 18 | @ComponentScan(basePackages = {"com.example.demo"}) 19 | public class Swagger2Config { 20 | 21 | @Bean 22 | public Docket createRestApi() { 23 | return new Docket(DocumentationType.SWAGGER_2) 24 | .select() 25 | .apis(RequestHandlerSelectors.basePackage("com.example.demo")) 26 | .paths(PathSelectors.any()) 27 | .build() 28 | .apiInfo(apiInfo()); 29 | } 30 | 31 | 32 | private ApiInfo apiInfo() { 33 | return new ApiInfoBuilder() 34 | .title("Jetpack项目Api文档") 35 | .description("") 36 | .version("1.0") 37 | .build(); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/resources/com/example/demo/mapper/MockUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 20 | 21 | 23 | INSERT INTO user 24 | ( 25 | id,name,password,number 26 | ) 27 | VALUES ( 28 | #{id}, 29 | #{name, jdbcType=VARCHAR}, 30 | #{password, jdbcType=VARCHAR}, 31 | #{number} 32 | ) 33 | 34 | 35 | 36 | delete from user where id=#{id} 37 | 38 | 39 | 40 | update user set user.name=#{name},user.password=#{password},user.number=#{number} where user.id=#{id} 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/table/TableComment.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.table; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | import javax.persistence.*; 6 | 7 | @Entity 8 | @Table(name = "table_feeds_comment") 9 | @JsonIgnoreProperties({"TEXT", "IMAGE", "VIDEO"}) 10 | public class TableComment { 11 | 12 | public static final int TEXT = 1; 13 | public static final int IMAGE = 2; 14 | public static final int VIDEO = 3; 15 | 16 | @Id 17 | @GeneratedValue 18 | public int id; 19 | 20 | @Column(name = "item_id") 21 | public long itemId; 22 | 23 | @Column(name = "comment_id") 24 | public long commentId; 25 | 26 | @Column(name = "user_id") 27 | public long userId; 28 | 29 | //1 文字 2图片 3视频 30 | @Column(name = "comment_type") 31 | public int commentType; 32 | 33 | @Column(name = "create_time") 34 | public long createTime; 35 | 36 | @Column(name = "comment_count") 37 | public int commentCount; 38 | 39 | @Column(name = "like_count") 40 | public int likeCount; 41 | 42 | @Column(name = "comment_text", length = 200) 43 | public String commentText; 44 | 45 | @Column(name = "image_url", length = 1000) 46 | public String imageUrl; 47 | 48 | @Column(name = "video_url", length = 1000) 49 | public String videoUrl; 50 | 51 | @Column(name = "width") 52 | public int width; 53 | 54 | @Column(name = "height") 55 | public int height; 56 | 57 | @Transient 58 | public boolean hasLiked; 59 | 60 | @Transient 61 | public TableUser author; 62 | 63 | @Transient 64 | public TableFeedUgc ugc; 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/ApiResponse.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | import java.io.Serializable; 7 | 8 | @JsonIgnoreProperties({"responseBody"}) 9 | public class ApiResponse implements Serializable { 10 | public static final int STATUS_SUCCESS = 200; 11 | public static final int STATUS_FAILED = 0; 12 | 13 | private int status = STATUS_SUCCESS; 14 | private String message = "成功"; 15 | private JSONObject data = new JSONObject(); 16 | 17 | public int getStatus() { 18 | return status; 19 | } 20 | 21 | public void setStatus(int status) { 22 | this.status = status; 23 | } 24 | 25 | public String getMessage() { 26 | return message; 27 | } 28 | 29 | public void setMessage(String message) { 30 | this.message = message; 31 | } 32 | 33 | public JSONObject getData() { 34 | return data; 35 | } 36 | 37 | public void setData(String objectKey, T data) { 38 | JSONObject body = new JSONObject(); 39 | body.put(objectKey, data); 40 | this.data.put("data", body); 41 | } 42 | 43 | public void setData(T data) { 44 | this.data.put("data", data); 45 | } 46 | 47 | public void setResult(int status, String message) { 48 | setStatus(status); 49 | setMessage(message); 50 | } 51 | 52 | public void setResult(int status, String message, T data) { 53 | String msg = status == STATUS_SUCCESS && message == null ? "成功" : message; 54 | setStatus(status); 55 | setMessage(msg); 56 | setData(data); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/JsonConverterConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.http.converter.HttpMessageConverter; 8 | import org.springframework.http.converter.StringHttpMessageConverter; 9 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; 10 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 11 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 12 | 13 | import java.nio.charset.Charset; 14 | import java.nio.charset.StandardCharsets; 15 | import java.util.List; 16 | 17 | @Configuration 18 | @EnableWebMvc 19 | @ComponentScan 20 | public class JsonConverterConfig extends WebMvcConfigurerAdapter { 21 | 22 | @Bean 23 | public HttpMessageConverter responseBodyConverter() { 24 | return new StringHttpMessageConverter(StandardCharsets.UTF_8); 25 | } 26 | 27 | @Bean 28 | public ObjectMapper getObjectMapper() { 29 | return new ObjectMapper(); 30 | } 31 | 32 | @Bean 33 | public MappingJackson2HttpMessageConverter messageConverter() { 34 | MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); 35 | converter.setObjectMapper(getObjectMapper()); 36 | return converter; 37 | } 38 | 39 | @Override 40 | public void configureMessageConverters(List> converters) { 41 | super.configureMessageConverters(converters); 42 | //解决中文乱码 43 | converters.add(responseBodyConverter()); 44 | converters.add(messageConverter()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/JsonNullConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.databind.*; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.ComponentScan; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.Primary; 11 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 12 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 13 | 14 | import java.io.IOException; 15 | 16 | @Configuration 17 | @EnableWebMvc 18 | @ComponentScan 19 | public class JsonNullConfig { 20 | 21 | @Bean 22 | public Jackson2ObjectMapperBuilder objectMapperBuilder() { 23 | Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); 24 | builder.featuresToDisable( 25 | SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, 26 | DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); 27 | return builder; 28 | } 29 | 30 | @Bean 31 | @Primary 32 | @ConditionalOnMissingBean(ObjectMapper.class) 33 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 34 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 35 | objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer() { 36 | @Override 37 | public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { 38 | jsonGenerator.writeString(""); 39 | } 40 | }); 41 | return objectMapper; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/UgcMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.table.TableFeedUgc; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | @Mapper 8 | public interface UgcMapper { 9 | TableFeedUgc queryUgcByItemId(@Param("itemId") long itemId); 10 | 11 | TableFeedUgc queryUgcByCommentId(@Param("commentId") long itemId); 12 | 13 | int increaseCommentCount(@Param("itemId") long itemId, @Param("increaseCount") int increaseCount); 14 | 15 | int queryCommentCount(@Param("itemId") long itemId); 16 | 17 | int increaseLikeCount(@Param("itemId") long itemId, @Param("increaseCount") int increaseCount); 18 | 19 | int queryLikeCount(@Param("itemId") long itemId); 20 | 21 | int increaseShareCount(@Param("itemId") long itemId); 22 | 23 | int queryShareCount(@Param("itemId") long itemId); 24 | 25 | int toggleLike(@Param("itemId") long itemId, @Param("userId") long userId); 26 | 27 | Object isLiked(@Param("itemId") long itemId, @Param("userId") long userId); 28 | 29 | void setUgc(TableFeedUgc ugc); 30 | 31 | void toggleTagListFollow(@Param("tagId") long tagId, @Param("userId") long userId); 32 | 33 | Object hasFollowTag(@Param("tagId") long tagId, @Param("userId") long userId); 34 | 35 | void toggleCommentLike(@Param("commentId") long commentId, @Param("userId") long userId); 36 | 37 | Object isCommentLike(@Param("commentId") long commentId, @Param("userId") long userId); 38 | 39 | void toggleUserFollow(@Param("followUserId") long followUserId, @Param("userId") long userId); 40 | 41 | Object isUserFollow(@Param("followUserId") long followUserId, @Param("userId") long userId); 42 | 43 | void dissFeed(@Param("itemId") long itemId, @Param("userId") long userId); 44 | 45 | Object hasDissFeed(@Param("itemId") long itemId, @Param("userId") long userId); 46 | 47 | int toggleFavorite(@Param("itemId") Long itemId, @Param("userId") Long userId); 48 | 49 | Object hasFavorite(@Param("itemId") Long itemId, @Param("userId") Long userId); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/resources/com/example/demo/mapper/TagListMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 43 | 44 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/table/TableFeedUgc.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.table; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | import javax.persistence.*; 6 | 7 | @Table(name = "table_ugc") 8 | @Entity 9 | @JsonIgnoreProperties({"id", "itemId", "commentId"}) 10 | public class TableFeedUgc { 11 | @Id 12 | @GeneratedValue 13 | public int id; 14 | 15 | @Column(name = "item_id") 16 | public long itemId; 17 | 18 | @Column(name = "like_count") 19 | public int likeCount; 20 | 21 | @Column(name = "share_count") 22 | public int shareCount; 23 | 24 | @Column(name = "comment_count") 25 | public int commentCount; 26 | 27 | @Transient 28 | public boolean hasFavorite; 29 | 30 | @Transient 31 | public boolean hasLiked; 32 | 33 | @Transient 34 | public boolean hasdiss; 35 | 36 | public boolean isHasDissed() { 37 | return hasdiss; 38 | } 39 | 40 | public void setHasDissed(boolean hasDissed) { 41 | this.hasdiss = hasDissed; 42 | } 43 | 44 | public boolean isHasFavorite() { 45 | return hasFavorite; 46 | } 47 | 48 | public void setHasFavorite(boolean hasFavorite) { 49 | this.hasFavorite = hasFavorite; 50 | } 51 | 52 | public int getId() { 53 | return id; 54 | } 55 | 56 | public void setId(int id) { 57 | this.id = id; 58 | } 59 | 60 | public long getItemId() { 61 | return itemId; 62 | } 63 | 64 | public void setItemId(long itemId) { 65 | this.itemId = itemId; 66 | } 67 | 68 | public int getLikeCount() { 69 | return likeCount; 70 | } 71 | 72 | public void setLikeCount(int likeCount) { 73 | this.likeCount = likeCount; 74 | } 75 | 76 | public int getShareCount() { 77 | return shareCount; 78 | } 79 | 80 | public void setShareCount(int shareCount) { 81 | this.shareCount = shareCount; 82 | } 83 | 84 | public int getCommentCount() { 85 | return commentCount; 86 | } 87 | 88 | public void setCommentCount(int commentCount) { 89 | this.commentCount = commentCount; 90 | } 91 | 92 | public boolean isHasLiked() { 93 | return hasLiked; 94 | } 95 | 96 | public void setHasLiked(boolean hasLiked) { 97 | this.hasLiked = hasLiked; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/TagListController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import com.example.demo.ApiResponse; 4 | import com.example.demo.mapper.TagListMapper; 5 | import com.example.demo.mapper.UgcMapper; 6 | import com.example.demo.table.TableTagList; 7 | import com.fasterxml.jackson.annotation.JsonView; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.annotation.RequestParam; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import javax.annotation.Resource; 16 | import java.util.List; 17 | 18 | @RestController 19 | @RequestMapping(value = "/tag") 20 | @Api(value = "帖子标签列表API") 21 | public class TagListController { 22 | 23 | @Resource 24 | TagListMapper tagListMapper; 25 | 26 | @Resource 27 | UgcMapper ugcMapper; 28 | 29 | @ApiOperation(value = "查询tagList数据") 30 | @RequestMapping(value = "queryTagList", method = RequestMethod.GET) 31 | @JsonView(value = TableTagList.class) 32 | public ApiResponse> queryTagList(@RequestParam(value = "tagId", required = false, defaultValue = "0") long tagId, 33 | @RequestParam(value = "pageCount", required = false, defaultValue = "10") int pageCount, 34 | @RequestParam(value = "userId", required = false, defaultValue = "0") long userId, 35 | @RequestParam(value = "offset", required = true, defaultValue = "0") int offset, 36 | @RequestParam(value = "tagType", required = false, defaultValue = "all") String tagType) { 37 | 38 | List lists = tagListMapper.queryTagList(tagId == 0 ? -1 : tagId, pageCount, userId, tagType, offset); 39 | if (userId > 0) { 40 | for (TableTagList tag : lists) { 41 | Object followTag = ugcMapper.hasFollowTag(tag.tagId, userId); 42 | tag.hasFollow = followTag == null ? false : (Boolean) followTag; 43 | } 44 | } 45 | 46 | ApiResponse> response = new ApiResponse<>(); 47 | response.setResult(ApiResponse.STATUS_SUCCESS, null, lists); 48 | return response; 49 | } 50 | 51 | 52 | @ApiOperation(value = "变更对某个标签的喜欢") 53 | @RequestMapping(value = "toggleTagFollow") 54 | @JsonView(value = Boolean.class) 55 | public ApiResponse toggleTagFollow(@RequestParam(value = "tagId", required = false, defaultValue = "0") long tagId, 56 | @RequestParam(value = "userId", required = false, defaultValue = "0") long userId) { 57 | 58 | ApiResponse response = new ApiResponse<>(); 59 | if (tagId == 0 || userId == 0) { 60 | response.setResult(ApiResponse.STATUS_FAILED, "tagId 或 userId 不能为空"); 61 | return response; 62 | } 63 | 64 | ugcMapper.toggleTagListFollow(tagId, userId); 65 | Object followTag = ugcMapper.hasFollowTag(tagId, userId); 66 | response.setData("hasFollow", followTag != null && (Boolean) followTag); 67 | return response; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/resources/com/example/demo/mapper/CommentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 30 | 31 | 34 | 35 | 39 | 40 | 41 | insert into table_feeds_comment (comment_id,comment_type,comment_text,user_id,item_id,create_time,image_url,video_url,width,height) 42 | values (#{comment.commentId},#{comment.commentType},#{comment.commentText},#{comment.userId},#{comment.itemId},#{comment.createTime},#{comment.imageUrl},#{comment.videoUrl},#{comment.width},#{comment.height}) 43 | 44 | 45 | 46 | 47 | select count(*) from table_watch_history where user_id= #{userId} and item_id= #{itemId} 48 | 49 | 50 | 51 | 52 | insert into table_watch_history (user_id,item_id,time) values (#{userId},#{itemId},#{time}) 53 | 54 | 55 | select id from table_watch_history where user_id= #{userId} and item_id= #{itemId} 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.7.RELEASE 9 | 10 | 11 | com.example 12 | demo 13 | jar 14 | 0.0.2-SNAPSHOT 15 | demo 16 | Demo project for PPJoke 17 | 18 | 19 | 1.8 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-data-jpa 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | mysql 43 | mysql-connector-java 44 | runtime 45 | 46 | 47 | 48 | org.mybatis 49 | mybatis 50 | 3.4.6 51 | 52 | 53 | 54 | org.mybatis.spring.boot 55 | mybatis-spring-boot-starter 56 | 1.3.2 57 | 58 | 59 | 60 | io.springfox 61 | springfox-swagger2 62 | 2.9.2 63 | 64 | 65 | io.springfox 66 | springfox-swagger-ui 67 | 2.9.2 68 | 69 | 70 | 71 | com.alibaba 72 | fastjson 73 | 1.2.4 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.springframework.boot 82 | spring-boot-maven-plugin 83 | 84 | 85 | 86 | repackage 87 | build-info 88 | 89 | 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-surefire-plugin 95 | 96 | true 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /HELP.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | ### Reference Documentation 4 | For further reference, please consider the following sections: 5 | 6 | * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) 7 | * [Spring Web Starter](https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/#boot-features-developing-web-applications) 8 | 9 | ### Guides 10 | The following guides illustrate how to use some features concretely: 11 | 12 | * [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) 13 | * [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) 14 | * [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/) 15 | 16 | ├── HELP.md 17 | ├── mvnw 18 | ├── mvnw.cmd 19 | ├── pom.xml 20 | ├── server.iml 21 | ├── src 22 | │   ├── main 23 | │   │   ├── java 24 | │   │   │   └── com 25 | │   │   │   └── example 26 | │   │   │   └── demo 27 | │   │   │   ├── ApiResponse.java 接口数据返回包装 28 | │   │   │   ├── DemoApplication.java 程序入口类 29 | │   │   │   ├── JsonConverterConfig.java Json转换中文乱码 30 | │   │   │   ├── JsonNullConfig.java Jso转换null转"" 31 | │   │   │   ├── Swagger2Config.java 在线Api文档 32 | │   │   │   ├── SwaggerMvcConfig.java 同上 33 | │   │   │   ├── controller 控制器 34 | │   │   │   │   ├── CommentController.java 评论相关的接口处理 35 | │   │   │   │   ├── FeedsController.java 帖子相关的接口处理 36 | │   │   │   │   ├── TagListController.java 标签相关接口处理 37 | │   │   │   │   ├── UgcController.java 互动行为接口处理 38 | │   │   │   │   └── UserController.java 用户相关的接口处理 39 | │   │   │   ├── mapper 数据库查询-接口定义的地方 40 | │   │   │   │   ├── CommentMapper.java 41 | │   │   │   │   ├── FeedsMapper.java 42 | │   │   │   │   ├── MockFeedsMapper.java 43 | │   │   │   │   ├── MockUserMapper.java 44 | │   │   │   │   ├── TagListMapper.java 45 | │   │   │   │   ├── UgcCommentMapper.java 46 | │   │   │   │   ├── UgcMapper.java 47 | │   │   │   │   └── UserMapper.java 48 | │   │   │   ├── mock 构造mock数据 49 | │   │   │   │   ├── MockFeedsController.java 构造mock数据的接口控制器 50 | │   │   │   │   ├── comments 51 | │   │   │   │   │   ├── CommentJsonParse.java 解析评论json 52 | │   │   │   │   │   ├── FeedsComment.java 解析帖子json 53 | │   │   │   │   │   └── comment.json 评论数据构造的json文件 54 | │   │   │   │   ├── feeds 55 | │   │   │   │   │   ├── HotFeeds.java 帖子的javaBean 56 | │   │   │   │   │   ├── HotJsonParse.java 解析帖子的 57 | │   │   │   │   │   └── mock.json 帖子数据构造的json文件 58 | │   │   │   │   ├── taglist 59 | │   │   │   │   │   ├── TagList.java 标签javaBean 60 | │   │   │   │   │   ├── TagListJsonParse.java 解析标签json数据的 61 | │   │   │   │   │   └── mock.json 标签数据构造的json文件 62 | │   │   │   │   └── user 63 | │   │   │   │   └── MockUserController.java 构造用户信息数据的控制器 64 | │   │   │   └── table 65 | │   │   │   ├── TableComment.java 各个java实体Bean以及数据库表 66 | │   │   │   ├── TableFeedUgc.java 67 | │   │   │   ├── TableHotFeeds.java 68 | │   │   │   ├── TableTagList.java 69 | │   │   │   ├── TableUser.java 70 | │   │   │   └── User.java 71 | │   │   └── resources 72 | │   │   ├── application.yml 程序配置的类 相当于android主工程的build.gradle 73 | │   │   ├── com 74 | │   │   │   └── example 75 | │   │   │   └── demo 76 | │   │   │   └── mapper mapper接口真正的实现的地方,写法符合mybatis3.6语法 77 | │   │   │   ├── CommentMapper.xml 78 | │   │   │   ├── FeedsMapper.xml 79 | │   │   │   ├── MockFeedsMapper.xml 80 | │   │   │   ├── MockUserMapper.xml 81 | │   │   │   ├── TagListMapper.xml 82 | │   │   │   ├── UgcCommentMapper.xml 83 | │   │   │   ├── UgcMapper.xml 84 | │   │   │   └── UserMapper.xml 85 | │___|_______|_____________________________________________ 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/table/TableUser.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.table; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | 6 | @Entity 7 | @Table(name = "table_user") 8 | public class TableUser implements Serializable { 9 | @Id 10 | @GeneratedValue(strategy = GenerationType.AUTO) 11 | public int id; 12 | 13 | @Column(name = "user_id") 14 | public long userId; 15 | 16 | @Column(name = "name") 17 | public String name; 18 | 19 | @Column(name = "avatar", length = 1000) 20 | public String avatar; 21 | 22 | @Column(name = "description", length = 100) 23 | public String description; 24 | 25 | @Column(name = "like_count") 26 | public int likeCount; 27 | 28 | @Column(name = "top_count") 29 | public int topCommentCount; 30 | 31 | @Column(name = "follow_count") 32 | public int followCount; 33 | 34 | @Column(name = "follower_count") 35 | public int followerCount; 36 | 37 | @Column(name = "qq_openid") 38 | public String qqOpenId; 39 | 40 | @Column(name = "expires_time") 41 | public long expires_time; 42 | 43 | @Column(name = "score") 44 | public long score; 45 | 46 | @Column(name = "history_count") 47 | public int historyCount; 48 | 49 | @Column(name = "comment_count") 50 | public int commentCount; 51 | 52 | @Column(name = "favorite_count") 53 | public int favoriteCount; 54 | 55 | @Column(name = "feed_count") 56 | public int feedCount; 57 | 58 | @Transient 59 | public boolean hasFollow; 60 | 61 | public boolean isHasFollow() { 62 | return hasFollow; 63 | } 64 | 65 | public void setHasFollow(boolean hasFollow) { 66 | this.hasFollow = hasFollow; 67 | } 68 | 69 | public int getHistoryCount() { 70 | return historyCount; 71 | } 72 | 73 | public void setHistoryCount(int historyCount) { 74 | this.historyCount = historyCount; 75 | } 76 | 77 | public int getCommentCount() { 78 | return commentCount; 79 | } 80 | 81 | public void setCommentCount(int commentCount) { 82 | this.commentCount = commentCount; 83 | } 84 | 85 | public int getFavoriteCount() { 86 | return favoriteCount; 87 | } 88 | 89 | public void setFavoriteCount(int favoriteCount) { 90 | this.favoriteCount = favoriteCount; 91 | } 92 | 93 | public int getFeedCount() { 94 | return feedCount; 95 | } 96 | 97 | public void setFeedCount(int feedCount) { 98 | this.feedCount = feedCount; 99 | } 100 | 101 | public long getScore() { 102 | return score; 103 | } 104 | 105 | public void setScore(long score) { 106 | this.score = score; 107 | } 108 | 109 | public int getFollowerCount() { 110 | return followerCount; 111 | } 112 | 113 | public void setFollowerCount(int followerCount) { 114 | this.followerCount = followerCount; 115 | } 116 | 117 | public long getExpires_time() { 118 | return expires_time; 119 | } 120 | 121 | public void setExpires_time(long expires_time) { 122 | this.expires_time = expires_time; 123 | } 124 | 125 | public String getQqOpenId() { 126 | return qqOpenId; 127 | } 128 | 129 | public void setQqOpenId(String qqOpenId) { 130 | this.qqOpenId = qqOpenId; 131 | } 132 | 133 | public int getId() { 134 | return id; 135 | } 136 | 137 | public void setId(int id) { 138 | this.id = id; 139 | } 140 | 141 | public long getUserId() { 142 | return userId; 143 | } 144 | 145 | public void setUserId(long userId) { 146 | this.userId = userId; 147 | } 148 | 149 | public String getName() { 150 | return name; 151 | } 152 | 153 | public void setName(String name) { 154 | this.name = name; 155 | } 156 | 157 | public String getAvatar() { 158 | return avatar; 159 | } 160 | 161 | public void setAvatar(String avatar) { 162 | this.avatar = avatar; 163 | } 164 | 165 | public String getDescription() { 166 | return description; 167 | } 168 | 169 | public void setDescription(String description) { 170 | this.description = description; 171 | } 172 | 173 | public int getLikeCount() { 174 | return likeCount; 175 | } 176 | 177 | public void setLikeCount(int likeCount) { 178 | this.likeCount = likeCount; 179 | } 180 | 181 | public int getTopCommentCount() { 182 | return topCommentCount; 183 | } 184 | 185 | public void setTopCommentCount(int topCommentCount) { 186 | this.topCommentCount = topCommentCount; 187 | } 188 | 189 | public int getFollowCount() { 190 | return followCount; 191 | } 192 | 193 | public void setFollowCount(int followCount) { 194 | this.followCount = followCount; 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/main/resources/com/example/demo/mapper/UgcCommentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | select count(*) from table_feed_comment_ugc where comment_id = ${ugc.itemId} 19 | 20 | 21 | 22 | update table_feed_comment_ugc 23 | set comment_count = ${ugc.commentCount},like_count=${ugc.likeCount},share_count= ${ugc.shareCount} 24 | where comment_id = ${ugc.itemId} 25 | 26 | 27 | insert into table_feed_comment_ugc 28 | (comment_id,like_count,share_count,comment_count) 29 | values (#{ugc.itemId},#{ugc.likeCount},#{ugc.shareCount},#{ugc.commentCount}) 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | select count(*) from table_feed_comment_ugc where comment_id = #{commentId} 41 | 42 | 43 | 44 | update table_feed_comment_ugc 45 | set comment_count = comment_count+ #{increaseCount} 46 | where comment_id = ${commentId} 47 | 48 | 49 | insert table_feed_comment_ugc (comment_count,comment_id) values (comment_count+1,${commentId}) 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | select count(*) from table_feed_comment_ugc where comment_id = ${commentId} 58 | 59 | 60 | 61 | update table_feed_comment_ugc 62 | set like_count = like_count+ #{increaseCount} 63 | where comment_id = ${commentId} 64 | 65 | 66 | insert table_feed_comment_ugc (like_count,comment_id) values (like_count+#{increaseCount},${commentId}) 67 | 68 | 69 | 70 | 71 | 72 | 73 | select count(*) from table_feed_comment_ugc where comment_id = ${commentId} 74 | 75 | 76 | 77 | update table_feed_comment_ugc 78 | set share_count = share_count+1 79 | where comment_id = ${commentId} 80 | 81 | 82 | insert table_feed_comment_ugc (share_count,comment_id) values (share_count+1,${commentId}) 83 | 84 | 85 | 86 | 87 | 88 | 89 | select count(*) from table_feed_comment_like where comment_id = ${commentId} and user_id =${userId} 90 | 91 | 92 | 93 | update table_feed_comment_like 94 | set has_like = has_like^1 95 | where comment_id = ${commentId} and user_id =${userId} 96 | 97 | 98 | insert into table_feed_comment_like (comment_id,user_id,has_like)values 99 | (#{commentId},${userId},has_like^1) 100 | 101 | 102 | 103 | 104 | 107 | 108 | 109 | delete from table_feeds_comment where item_id=#{itemId} and comment_id=#{commentId} 110 | 111 | 112 | 113 | delete from table_feeds_comment where item_id = #{itemId} 114 | 115 | -------------------------------------------------------------------------------- /src/main/resources/com/example/demo/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 32 | 33 | 34 | 35 | select count(*) from table_user where user_id= #{user.userId} 36 | 37 | 38 | 39 | update table_user 40 | 41 | 42 | name = #{user.name}, 43 | 44 | 45 | avatar = #{user.avatar}, 46 | 47 | 48 | description = #{user.description}, 49 | 50 | 51 | like_count = #{user.likeCount}, 52 | 53 | 54 | top_count = #{user.topCommentCount}, 55 | 56 | 57 | follow_count = #{user.followCount}, 58 | 59 | 60 | follower_count = #{user.followerCount}, 61 | 62 | 63 | score = #{user.score}, 64 | 65 | 66 | history_count = #{user.historyCount}, 67 | 68 | 69 | favorite_count = #{user.favoriteCount}, 70 | 71 | 72 | feed_count = #{user.feedCount}, 73 | 74 | 75 | comment_count = #{user.commentCount}, 76 | 77 | 78 | where user_id= #{user.userId} 79 | 80 | 81 | INSERT INTO table_user 82 | (qq_openid,user_id,name,avatar,description,like_count,top_count,follow_count,follower_count,expires_time,score,history_count,comment_count,favorite_count,feed_count) 83 | VALUES ( 84 | #{user.qqOpenId,jdbcType=VARCHAR}, 85 | #{user.userId,jdbcType=BIGINT}, 86 | #{user.name,jdbcType=VARCHAR}, 87 | #{user.avatar,jdbcType=VARCHAR}, 88 | #{user.description,jdbcType=VARCHAR}, 89 | #{user.likeCount,jdbcType=INTEGER}, 90 | #{user.topCommentCount,jdbcType=INTEGER}, 91 | #{user.followerCount,jdbcType=INTEGER}, 92 | #{user.followCount,jdbcType=INTEGER}, 93 | #{user.expires_time,jdbcType=BIGINT}, 94 | #{user.score,jdbcType=BIGINT}, 95 | #{user.historyCount,jdbcType=INTEGER}, 96 | #{user.commentCount,jdbcType=INTEGER}, 97 | #{user.favoriteCount,jdbcType=INTEGER}, 98 | #{user.feedCount,jdbcType=INTEGER} 99 | ) 100 | 101 | 102 | 103 | 104 | 111 | 112 | 113 | 120 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/CommentController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import com.example.demo.ApiResponse; 4 | import com.example.demo.mapper.CommentMapper; 5 | import com.example.demo.mapper.UgcCommentMapper; 6 | import com.example.demo.mapper.UgcMapper; 7 | import com.example.demo.mapper.UserMapper; 8 | import com.example.demo.table.TableComment; 9 | import com.example.demo.table.TableUser; 10 | import com.fasterxml.jackson.annotation.JsonView; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.springframework.util.StringUtils; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import javax.annotation.Resource; 17 | import java.util.List; 18 | 19 | @RestController 20 | @RequestMapping(value = "/comment") 21 | @Api(value = "帖子的评论列表查询API") 22 | public class CommentController { 23 | 24 | @Resource 25 | CommentMapper commentMapper; 26 | 27 | @Resource 28 | UserMapper userMapper; 29 | 30 | @Resource 31 | UgcMapper ugcMapper; 32 | 33 | @Resource 34 | UgcCommentMapper ugcCommentMapper; 35 | 36 | @ApiOperation(value = "用于查询帖子的评论列表 支持分页") 37 | @RequestMapping(value = "queryFeedComments", method = RequestMethod.GET) 38 | @JsonView(value = TableComment.class) 39 | public ApiResponse queryFeedComments(@RequestParam(value = "userId", required = false, defaultValue = "0") Long userId, 40 | @RequestParam(value = "pageCount", required = false, defaultValue = "10") Integer pageCount, @RequestParam(value = "itemId", required = true) Long itemId, 41 | @RequestParam(value = "id", required = false, defaultValue = "0") Integer id) { 42 | 43 | ApiResponse response = new ApiResponse<>(); 44 | if (itemId == null) { 45 | response.setResult(ApiResponse.STATUS_FAILED, "itemId不能为空"); 46 | return response; 47 | } 48 | 49 | List comments = commentMapper.queryCommentList(itemId, id <= 0 ? Integer.MAX_VALUE : id, pageCount); 50 | if (comments != null && comments.size() > 0) { 51 | for (TableComment comment : comments) { 52 | comment.author = userMapper.queryUser(comment.userId); 53 | comment.ugc = ugcCommentMapper.queryUgcByCommentId(comment.commentId); 54 | if (comment.ugc != null) { 55 | Object ugcCommentLike = ugcCommentMapper.isCommentLike(comment.commentId, userId); 56 | comment.ugc.hasLiked = ugcCommentLike == null ? false : (Boolean) ugcCommentLike; 57 | } 58 | } 59 | } 60 | response.setResult(ApiResponse.STATUS_SUCCESS, null, comments); 61 | 62 | if (userId != 0) { 63 | TableUser user = userMapper.queryUser(userId); 64 | if (user != null) { 65 | user.historyCount = user.historyCount + 1; 66 | userMapper.insertUser(user); 67 | } 68 | } 69 | 70 | if (userId != 0) { 71 | commentMapper.addWatchHistory(userId, itemId, System.currentTimeMillis()); 72 | } 73 | return response; 74 | } 75 | 76 | 77 | @ApiOperation(value = "用于帖子增加一条评论") 78 | @PostMapping(value = "addComment") 79 | @JsonView(value = TableComment.class) 80 | public ApiResponse addComment(@RequestParam(value = "userId", required = false, defaultValue = "0") Long userId, 81 | @RequestParam(value = "itemId", required = true) Long itemId, 82 | @RequestParam(value = "commentText", required = false, defaultValue = "") String commentText, 83 | @RequestParam(value = "image_url", required = false, defaultValue = "") String image_url, 84 | @RequestParam(value = "video_url", required = false, defaultValue = "") String video_url, 85 | @RequestParam(value = "width", required = false, defaultValue = "") int width, 86 | @RequestParam(value = "height", required = false, defaultValue = "") int height) { 87 | 88 | ApiResponse response = new ApiResponse<>(); 89 | if (itemId == null || userId == null || StringUtils.isEmpty(commentText)) { 90 | response.setResult(ApiResponse.STATUS_FAILED, "itemId|userId|commentText不能为空"); 91 | return response; 92 | } 93 | 94 | int commentType = TableComment.TEXT; 95 | if (!StringUtils.isEmpty(video_url)) { 96 | commentType = TableComment.VIDEO; 97 | } else if (!StringUtils.isEmpty(image_url)) { 98 | commentType = TableComment.IMAGE; 99 | } 100 | 101 | TableComment comment = new TableComment(); 102 | comment.userId = userId; 103 | comment.itemId = itemId; 104 | comment.commentText = commentText; 105 | comment.commentType = commentType; 106 | comment.commentId = System.currentTimeMillis() * 1000; 107 | comment.createTime = System.currentTimeMillis(); 108 | comment.imageUrl = image_url; 109 | comment.videoUrl = video_url; 110 | comment.width = width; 111 | comment.height = height; 112 | 113 | commentMapper.addComment(comment); 114 | ugcMapper.increaseCommentCount(itemId, 1); 115 | 116 | comment.author = userMapper.queryUser(userId); 117 | response.setResult(ApiResponse.STATUS_SUCCESS, null, comment); 118 | 119 | 120 | TableUser user = userMapper.queryUser(userId); 121 | if (user != null) { 122 | user.commentCount = user.commentCount + 1; 123 | userMapper.insertUser(user); 124 | } 125 | 126 | return response; 127 | } 128 | 129 | 130 | @ApiOperation(value = "删除帖子的一条评论") 131 | @RequestMapping(value = "deleteComment", method = RequestMethod.GET) 132 | @JsonView(value = TableComment.class) 133 | public ApiResponse deleteComment(@RequestParam(value = "itemId", defaultValue = "0") Long itemId, 134 | @RequestParam(value = "userId", defaultValue = "0") Long userId, 135 | @RequestParam(value = "commentId", defaultValue = "0") Long commentId) { 136 | 137 | ApiResponse response = new ApiResponse<>(); 138 | if (itemId == null || commentId == null) { 139 | response.setResult(ApiResponse.STATUS_FAILED, "commentId|itemId不能为空"); 140 | return response; 141 | } 142 | int result = ugcCommentMapper.deleteComment(itemId, commentId); 143 | ugcMapper.increaseCommentCount(itemId, -1); 144 | 145 | TableUser user = userMapper.queryUser(userId); 146 | if (user != null) { 147 | user.commentCount = user.commentCount - 1; 148 | userMapper.insertUser(user); 149 | } 150 | response.setData("result", result > 0); 151 | return response; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import com.example.demo.ApiResponse; 4 | import com.example.demo.mapper.UgcMapper; 5 | import com.example.demo.mapper.UserMapper; 6 | import com.example.demo.table.TableUser; 7 | import com.example.demo.table.User; 8 | import com.fasterxml.jackson.annotation.JsonView; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.util.StringUtils; 12 | import org.springframework.validation.BindingResult; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import javax.annotation.Resource; 16 | import javax.validation.Valid; 17 | import java.util.List; 18 | 19 | 20 | @RestController 21 | @RequestMapping(value = "/user") 22 | @Api(value = "用户信息接口API") 23 | public class UserController { 24 | @Resource 25 | private UserMapper userMapper; 26 | 27 | @Resource 28 | UgcMapper ugcMapper; 29 | 30 | @RequestMapping(value = "query", method = RequestMethod.GET) 31 | @ApiOperation(value = "查询用户", notes = "根据id来查询用户") 32 | @JsonView(value = TableUser.class) 33 | public ApiResponse query(@RequestParam(value = "userId") long userId) { 34 | ApiResponse response = new ApiResponse<>(); 35 | TableUser user = userMapper.queryUser(userId); 36 | if (user != null) { 37 | response.setData(user); 38 | } 39 | return response; 40 | } 41 | 42 | 43 | @RequestMapping(value = "relation", method = RequestMethod.GET) 44 | @ApiOperation(value = "查询两个用户的关系", notes = "根据id来查询用户") 45 | @JsonView(value = TableUser.class) 46 | public ApiResponse relation(@RequestParam(value = "authorId") long authorId, @RequestParam("userId") long userId) { 47 | ApiResponse response = new ApiResponse<>(); 48 | TableUser user = userMapper.queryUser(authorId); 49 | try { 50 | user.hasFollow = (boolean) ugcMapper.isUserFollow(userId, authorId); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | response.setData(user); 55 | return response; 56 | } 57 | 58 | 59 | @RequestMapping(value = "delete", method = RequestMethod.GET) 60 | @ApiOperation(value = "删除用户", notes = "根据id来删除用户") 61 | @JsonView(value = Boolean.class) 62 | public ApiResponse delete(@RequestParam(value = "userId") long userId) { 63 | ApiResponse response = new ApiResponse<>(); 64 | int result = userMapper.delete(userId); 65 | response.setData(result >= 1); 66 | return response; 67 | } 68 | 69 | @RequestMapping(value = "update", method = RequestMethod.POST) 70 | @ApiOperation(value = "更新用户信息", notes = "根据id来更新用户信息") 71 | @JsonView(value = Boolean.class) 72 | public ApiResponse update(@RequestParam @Valid TableUser user, BindingResult binding) { 73 | ApiResponse response = new ApiResponse<>(); 74 | int result = userMapper.Update(user); 75 | response.setData(result >= 1); 76 | return response; 77 | } 78 | 79 | @RequestMapping(value = "insert", method = RequestMethod.GET) 80 | @ApiOperation(value = "插入新的用户", notes = "插入新的用户") 81 | @JsonView(User.class) 82 | @ResponseBody 83 | public ApiResponse insert(@RequestParam(value = "qqOpenId", required = true) String qqOpenId, 84 | @RequestParam(value = "name", required = true) String name, 85 | @RequestParam(value = "avatar", required = true) String avatar, 86 | @RequestParam(value = "description", required = false, defaultValue = "") String description, 87 | @RequestParam(value = "likeCount", required = false, defaultValue = "0") Integer likeCount, 88 | @RequestParam(value = "topCommentCount", required = false, defaultValue = "0") Integer topCommentCount, 89 | @RequestParam(value = "followCount", required = false, defaultValue = "0") Integer followCount, 90 | @RequestParam(value = "expires_time", required = true) long expires_time) { 91 | TableUser exitOne = userMapper.queryUserByQQOpenId(qqOpenId); 92 | if (exitOne == null) { 93 | exitOne = new TableUser(); 94 | exitOne.userId = System.currentTimeMillis() / 1000; 95 | } 96 | exitOne.qqOpenId = qqOpenId; 97 | exitOne.name = name; 98 | exitOne.avatar = avatar; 99 | if (!StringUtils.isEmpty(description)) { 100 | exitOne.description = description; 101 | } 102 | 103 | if (topCommentCount > 0) { 104 | exitOne.description = description; 105 | } 106 | 107 | if (likeCount > 0) { 108 | exitOne.likeCount = likeCount; 109 | } 110 | 111 | if (followCount > 0) { 112 | exitOne.followerCount = followCount; 113 | 114 | } 115 | 116 | if (expires_time > 0) { 117 | exitOne.expires_time = expires_time; 118 | } 119 | 120 | userMapper.insertUser(exitOne); 121 | TableUser tableUser = userMapper.queryUser(exitOne.userId); 122 | ApiResponse response = new ApiResponse<>(); 123 | response.setData(tableUser); 124 | return response; 125 | } 126 | 127 | 128 | @RequestMapping(value = "queryFans", method = RequestMethod.GET) 129 | @ApiOperation(value = "查询粉丝列表", notes = "查询粉丝列表") 130 | @JsonView(User.class) 131 | public ApiResponse> queryFans(@RequestParam(value = "userId", defaultValue = "0") Long userId, 132 | @RequestParam(value = "page", defaultValue = "0") Integer page, 133 | @RequestParam(value = "pageCount", defaultValue = "10", required = false) Integer pageCount) { 134 | ApiResponse> response = new ApiResponse<>(); 135 | if (userId == 0) { 136 | response.setData("data", null); 137 | return response; 138 | } 139 | List users = userMapper.queryFans(userId, pageCount * page, pageCount); 140 | response.setData("data", users); 141 | return response; 142 | } 143 | 144 | 145 | @RequestMapping(value = "queryFollows", method = RequestMethod.GET) 146 | @ApiOperation(value = "查询关注列表", notes = "查询关注列表") 147 | @JsonView(User.class) 148 | public ApiResponse> queryFollows(@RequestParam(value = "userId", defaultValue = "0") Long userId, 149 | @RequestParam(value = "page", defaultValue = "0") Integer page, 150 | @RequestParam(value = "pageCount", defaultValue = "10", required = false) Integer pageCount) { 151 | ApiResponse> response = new ApiResponse<>(); 152 | if (userId == 0) { 153 | response.setData("data", null); 154 | return response; 155 | } 156 | List users = userMapper.queryFollows(userId, pageCount * page, pageCount); 157 | response.setData("data", users); 158 | return response; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/main/resources/com/example/demo/mapper/MockFeedsMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 63 | 64 | INSERT INTO table_hot_feeds 65 | ( 66 | id,item_id,item_type,create_time,duration, 67 | feeds_text,author_id,activity_text, 68 | activity_icon,video_width,video_height,video_url,video_cover 69 | ) 70 | VALUES ( 71 | #{id}, 72 | #{itemId,jdbcType=BIGINT}, 73 | #{itemType, jdbcType=INTEGER}, 74 | #{createTime,jdbcType=INTEGER}, 75 | #{duration,jdbcType=DOUBLE}, 76 | #{feeds_text,jdbcType=VARCHAR}, 77 | #{authorId,jdbcType=BIGINT}, 78 | #{activityText,jdbcType=VARCHAR}, 79 | #{activityIcon,jdbcType=LONGVARCHAR}, 80 | #{width,jdbcType=INTEGER}, 81 | #{height,jdbcType=INTEGER}, 82 | #{url,jdbcType=LONGVARCHAR}, 83 | #{cover,jdbcType=LONGVARCHAR} 84 | ) 85 | 86 | 87 | 89 | INSERT INTO table_feeds_comment (id,item_id,user_id,comment_id,comment_type,create_time,comment_count,like_count,comment_text,image_url,video_url,width,height) 90 | VALUES ( 91 | #{id}, 92 | #{itemId,jdbcType=BIGINT}, 93 | #{userId,jdbcType=BIGINT}, 94 | #{commentId,jdbcType=BIGINT}, 95 | #{commentType,jdbcType=INTEGER}, 96 | #{createTime,jdbcType=INTEGER}, 97 | #{commentCount,jdbcType=INTEGER}, 98 | #{likeCount,jdbcType=INTEGER}, 99 | #{commentText,jdbcType=VARCHAR}, 100 | #{imageUrl,jdbcType=LONGVARCHAR}, 101 | #{videoUrl,jdbcType=LONGVARCHAR}, 102 | #{width,jdbcType=INTEGER}, 103 | #{height,jdbcType=INTEGER} 104 | ) 105 | 106 | 107 | 108 | 110 | 111 | 112 | select count(*) from table_user where user_id = #{userId} 113 | 114 | 115 | 116 | update table_user set name =#{name},avatar =#{avatar},description= #{description} where 117 | user_id=#{userId} 118 | 119 | 120 | INSERT INTO table_user 121 | ( 122 | id,user_id,name,avatar,description 123 | ) 124 | VALUES ( 125 | #{id}, 126 | #{userId,jdbcType=BIGINT}, 127 | #{name,jdbcType=VARCHAR}, 128 | #{avatar,jdbcType=LONGVARCHAR}, 129 | #{description,jdbcType=VARCHAR} 130 | ) 131 | 132 | 133 | 134 | 135 | 136 | 138 | 139 | 140 | select count(*) from table_tag_list where tag_id = #{tagId} 141 | 142 | 143 | 144 | update table_tag_list set title =#{title},intro =#{intro},icon= #{icon},activity_icon= 145 | #{activityIcon},background=#{background},feed_num= #{feedNum} ,enter_num= #{enterNum},follow_num= 146 | #{followNum} where 147 | tag_id=#{tagId} 148 | 149 | 150 | INSERT INTO table_tag_list 151 | ( 152 | id,title,intro,icon,activity_icon,feed_num,enter_num,follow_num,tag_id,background 153 | ) 154 | VALUES ( 155 | #{id}, 156 | #{title}, 157 | #{intro}, 158 | #{icon}, 159 | #{activityIcon}, 160 | #{feedNum}, 161 | #{enterNum}, 162 | #{followNum}, 163 | #{tagId}, 164 | #{background} 165 | ) 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /src/main/resources/com/example/demo/mapper/FeedsMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 76 | 77 | 78 | insert into table_hot_feeds 79 | (item_id,item_type,create_time,duration,feeds_text,author_id,activity_text,activity_icon,video_width,video_height,video_url,video_cover) 80 | values (#{feed.itemId}, 81 | #{feed.itemType}, 82 | #{feed.createTime}, 83 | #{feed.duration}, 84 | #{feed.feeds_text}, 85 | #{feed.authorId}, 86 | #{feed.activityText}, 87 | #{feed.activityIcon}, 88 | #{feed.width}, 89 | #{feed.height}, 90 | #{feed.url}, 91 | #{feed.cover}) 92 | 93 | 94 | 95 | 143 | 144 | 145 | 146 | delete from table_hot_feeds where table_hot_feeds.item_id= #{itemId} 147 | 148 | 149 | 152 | 153 | 160 | 161 | 162 | 170 | -------------------------------------------------------------------------------- /src/main/resources/com/example/demo/mapper/UgcMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | insert into table_ugc 18 | (item_id,like_count,share_count,comment_count) 19 | values (${itemId},${likeCount},${shareCount},${commentCount}) on duplicate key update item_id=${itemId} 20 | 21 | 22 | 25 | 26 | 29 | 32 | 33 | 34 | 35 | select count(*) from table_ugc where item_id = ${itemId} 36 | 37 | 38 | 39 | update table_ugc 40 | set comment_count = comment_count+ #{increaseCount} 41 | where item_id = ${itemId} 42 | 43 | 44 | insert table_ugc (comment_count,item_id) values (comment_count+#{increaseCount},${itemId}) 45 | 46 | 47 | 48 | 49 | 52 | 53 | 54 | 55 | select count(*) from table_ugc where item_id = ${itemId} 56 | 57 | 58 | 59 | update table_ugc 60 | set like_count = like_count+ #{increaseCount} 61 | where item_id = ${itemId} 62 | 63 | 64 | insert table_ugc (like_count,item_id) values (like_count+#{increaseCount},${itemId}) 65 | 66 | 67 | 68 | 69 | 72 | 73 | 74 | 75 | select count(*) from table_ugc where item_id = ${itemId} 76 | 77 | 78 | 79 | update table_ugc 80 | set share_count = share_count+1 81 | where item_id = ${itemId} 82 | 83 | 84 | insert table_ugc (share_count,item_id) values (share_count+1,${itemId}) 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | select count(*) from table_ugc_like where item_id = ${itemId} and user_id =${userId} 93 | 94 | 95 | 96 | update table_ugc_like 97 | set has_like=has_like^1,has_diss= 0 98 | where item_id = ${itemId} and user_id =${userId} 99 | 100 | 101 | insert into table_ugc_like (item_id,user_id,has_like)values (#{itemId},${userId},has_like^1) 102 | 103 | 104 | 105 | 106 | 109 | 110 | 111 | 112 | 113 | select count(*) from table_ugc_like where item_id = ${itemId} and user_id =${userId} 114 | 115 | 116 | 117 | update table_ugc_like 118 | set has_diss = has_diss^1,has_like= 0 119 | where item_id = ${itemId} and user_id =${userId} 120 | 121 | 122 | insert into table_ugc_like (item_id,user_id,has_diss)values (#{itemId},${userId},has_diss^1) 123 | 124 | 125 | 126 | 127 | 130 | 131 | 132 | 133 | 134 | select count(*) from table_tag_list_like where tag_id = ${tagId} and user_id =${userId} 135 | 136 | 137 | 138 | update table_tag_list_like 139 | set has_like = has_like^1 140 | where tag_id = ${tagId} and user_id =${userId} 141 | 142 | 143 | insert into table_tag_list_like (tag_id,user_id,has_like)values (${tagId},${userId},has_like^1) 144 | 145 | 146 | 147 | 148 | 151 | 152 | 153 | 154 | 155 | select count(*) from table_feed_comment_like where comment_id = ${commentId} and user_id =${userId} 156 | 157 | 158 | 159 | update table_feed_comment_like 160 | set has_like = has_like^1 161 | where comment_id = ${commentId} and user_id =${userId} 162 | 163 | 164 | insert into table_feed_comment_like (comment_id,user_id,has_like)values 165 | (#{commentId},${userId},has_like^1) 166 | 167 | 168 | 169 | 170 | 173 | 174 | 175 | 176 | 177 | select count(*) from table_user_follow where follow_user_id = ${followUserId} and user_id =${userId} 178 | 179 | 180 | 181 | update table_user_follow 182 | set has_follow = has_follow^1 183 | where user_id = ${userId} and follow_user_id =${followUserId} 184 | 185 | 186 | insert into table_user_follow (user_id,follow_user_id,has_follow)values 187 | (#{userId},${followUserId},1) 188 | 189 | 190 | 191 | 192 | 195 | 196 | 197 | 198 | 199 | select count(*) from table_ugc_like where item_id = ${itemId} and user_id =${userId} 200 | 201 | 202 | 203 | update table_ugc_like 204 | set has_favorite=has_favorite^1 205 | where item_id = ${itemId} and user_id =${userId} 206 | 207 | 208 | insert into table_ugc_like (item_id,user_id,has_favorite)values (#{itemId},${userId},has_favorite^1) 209 | 210 | 211 | 212 | 213 | 216 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/FeedsController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | 4 | import com.example.demo.ApiResponse; 5 | import com.example.demo.mapper.*; 6 | import com.example.demo.table.TableComment; 7 | import com.example.demo.table.TableFeedUgc; 8 | import com.example.demo.table.TableHotFeeds; 9 | import com.example.demo.table.TableUser; 10 | import com.fasterxml.jackson.annotation.JsonView; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.springframework.util.StringUtils; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestMethod; 16 | import org.springframework.web.bind.annotation.RequestParam; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | import javax.annotation.Resource; 20 | import java.util.ArrayList; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | 24 | @RestController 25 | @RequestMapping(value = "/feeds") 26 | @Api(value = "帖子列表流控制器API") 27 | public class FeedsController { 28 | @Resource 29 | FeedsMapper feedsMapper; 30 | 31 | @Resource 32 | UserMapper userMapper; 33 | @Resource 34 | CommentMapper commentMapper; 35 | 36 | @Resource 37 | UgcMapper ugcMapper; 38 | 39 | @Resource 40 | UgcCommentMapper ugcCommentMapper; 41 | 42 | @ApiOperation(value = "查询帖子列表数据") 43 | @RequestMapping(value = "queryHotFeedsList", method = RequestMethod.GET) 44 | @JsonView(value = TableHotFeeds.class) 45 | public ApiResponse> queryHotFeedsList(@RequestParam(value = "feedType", required = false, defaultValue = "") String feedType, 46 | @RequestParam(value = "userId", required = false, defaultValue = "0") Long userId, 47 | @RequestParam(value = "feedId", required = false, defaultValue = "0") Integer feedId, 48 | @RequestParam(value = "pageCount", required = false, defaultValue = "10") Integer pageCount) { 49 | 50 | List feeds = feedsMapper.queryHotFeedsList(feedType, feedId, pageCount); 51 | if (feeds != null && feeds.size() > 0) { 52 | fillFeedList(userId, feeds); 53 | } 54 | ApiResponse> response = new ApiResponse<>(); 55 | response.setResult(ApiResponse.STATUS_SUCCESS, null, feeds); 56 | return response; 57 | } 58 | 59 | 60 | @RequestMapping(value = "/queryProfileFeeds", method = RequestMethod.GET) 61 | @ApiOperation(value = "查询用户的动态帖子", notes = "根据id来查询") 62 | @JsonView(value = TableHotFeeds.class) 63 | public ApiResponse queryProfileFeeds(@RequestParam(value = "userId", required = true) long userId, 64 | @RequestParam(value = "pageCount", required = false, defaultValue = "10") int pageCount, 65 | @RequestParam(value = "profileType", required = true) String profileType, 66 | @RequestParam(value = "feedId", required = true, defaultValue = "0") int feedId) { 67 | 68 | ApiResponse response = new ApiResponse<>(); 69 | List tableHotFeeds = feedsMapper.queryProfileFeeds(userId, pageCount, profileType, feedId <= 0 ? Integer.MAX_VALUE : feedId); 70 | HashMap> tempMap = new HashMap<>(); 71 | if (tableHotFeeds != null) { 72 | for (TableHotFeeds feed : tableHotFeeds) { 73 | List comments = tempMap.get(feed.itemId); 74 | if (comments == null) { 75 | comments = new ArrayList<>(); 76 | tempMap.put(feed.itemId, comments); 77 | } 78 | int offset = comments.size(); 79 | TableComment comment = commentMapper.queryCommentByUserId(feed.itemId, userId, offset); 80 | if (comment != null) { 81 | comment.author = userMapper.queryUser(comment.userId); 82 | comment.ugc = ugcCommentMapper.queryUgcByCommentId(comment.commentId); 83 | if (comment.ugc != null) { 84 | Object commentLike = ugcCommentMapper.isCommentLike(comment.commentId, userId); 85 | comment.ugc.hasLiked = commentLike == null ? false : (Boolean) commentLike; 86 | } 87 | feed.topComment = comment; 88 | 89 | comments.add(comment.commentId); 90 | } 91 | feed.author = userMapper.queryUser(feed.authorId); 92 | feed.ugc = ugcMapper.queryUgcByItemId(feed.itemId); 93 | if (feed.ugc != null && userId > 0) { 94 | Object liked = ugcMapper.isLiked(feed.itemId, userId); 95 | Object favorite = ugcMapper.hasFavorite(feed.itemId, userId); 96 | feed.ugc.hasLiked = liked != null && (Boolean) liked; 97 | feed.ugc.hasFavorite = favorite != null && (Boolean) favorite; 98 | } 99 | } 100 | } 101 | 102 | tempMap.clear(); 103 | response.setResult(ApiResponse.STATUS_SUCCESS, null, tableHotFeeds); 104 | return response; 105 | } 106 | 107 | 108 | @ApiOperation(value = "发布一条新的帖子") 109 | @RequestMapping(value = "publish", method = RequestMethod.POST) 110 | @JsonView(value = TableHotFeeds.class) 111 | public ApiResponse publishFeed(@RequestParam(value = "feedType", required = false, defaultValue = "1") int feedType, 112 | @RequestParam(value = "userId", required = false, defaultValue = "0") Long userId, 113 | @RequestParam(value = "coverUrl", required = false, defaultValue = "") String coverUrl, 114 | @RequestParam(value = "fileUrl", required = false, defaultValue = "") String fileUrl, 115 | @RequestParam(value = "fileWidth", required = false, defaultValue = "0") int fileWidth, 116 | @RequestParam(value = "fileHeight", required = false, defaultValue = "0") int fileHeight, 117 | @RequestParam(value = "tagId", required = false, defaultValue = "0") long tagId, 118 | @RequestParam(value = "tagTitle", required = false, defaultValue = "") String tagTitle, 119 | @RequestParam(value = "feedText", required = false, defaultValue = "") String feedText) { 120 | 121 | TableUser tableUser = userMapper.queryUser(userId); 122 | if (tableUser == null) { 123 | ApiResponse response = new ApiResponse<>(); 124 | response.setResult(ApiResponse.STATUS_FAILED, "用户未登录,请先登陆"); 125 | return response; 126 | } 127 | 128 | TableHotFeeds feed = new TableHotFeeds(); 129 | feed.itemId = System.currentTimeMillis(); 130 | feed.itemType = feedType; 131 | feed.authorId = userId; 132 | feed.cover = feedType == 1 ? StringUtils.isEmpty(fileUrl) ? null : fileUrl : coverUrl; 133 | feed.url = feedType == 1 ? null : fileUrl; 134 | feed.width = fileWidth; 135 | feed.height = fileHeight; 136 | feed.activityIcon = null; 137 | feed.activityText = StringUtils.isEmpty(tagTitle) ? null : tagTitle; 138 | feed.feeds_text = StringUtils.isEmpty(feedText) ? null : feedText; 139 | feed.createTime = System.currentTimeMillis(); 140 | 141 | 142 | TableFeedUgc ugc = new TableFeedUgc(); 143 | feed.ugc = ugc; 144 | ugc.itemId = feed.itemId; 145 | ugcMapper.setUgc(ugc); 146 | int result = feedsMapper.addFeed(feed); 147 | 148 | ApiResponse response = new ApiResponse<>(); 149 | if (result != -1) { 150 | response.setData("result", "success"); 151 | } else { 152 | response.setData("result", "failed"); 153 | } 154 | return response; 155 | } 156 | 157 | @RequestMapping(value = "deleteFeed", method = RequestMethod.GET) 158 | @ApiOperation(value = "删除一条帖子") 159 | public ApiResponse deleteFeed(@RequestParam("itemId") Long itemId) { 160 | ApiResponse response = new ApiResponse<>(); 161 | if (itemId == null) { 162 | response.setData("result", "itemId不能为空"); 163 | return response; 164 | } 165 | int result1 = feedsMapper.deleteFeed(itemId); 166 | int result2 = ugcCommentMapper.deleteAllComments(itemId); 167 | response.setData("result", result1 >= 0 && result2 >= 0); 168 | return response; 169 | } 170 | 171 | @RequestMapping(value = "queryUserBehaviorList", method = RequestMethod.GET) 172 | @ApiOperation(value = "查询历史观看记录,或者收藏的记录") 173 | public ApiResponse> queryUserBehaviorList(@RequestParam("userId") Long userId, 174 | @RequestParam(value = "pageCount", defaultValue = "10", required = false) int pageCount, 175 | @RequestParam(value = "feedId", defaultValue = "0") int feedId, 176 | @RequestParam(value = "behavior", defaultValue = "0") int behavior) { 177 | if (behavior == 0) { 178 | return queryFavorite(userId, pageCount, feedId); 179 | } else { 180 | return queryHistory(userId, pageCount, feedId); 181 | } 182 | } 183 | 184 | 185 | @RequestMapping(value = "queryHistory", method = RequestMethod.GET) 186 | @ApiOperation(value = "查询历史观看记录") 187 | public ApiResponse> queryHistory(@RequestParam("userId") Long userId, 188 | @RequestParam(value = "pageCount", defaultValue = "10", required = false) int pageCount, 189 | @RequestParam(value = "feedId", defaultValue = "0") int feedId) { 190 | ApiResponse> response = new ApiResponse<>(); 191 | if (userId == null) { 192 | response.setResult(ApiResponse.STATUS_FAILED, "userId不能为空", null); 193 | return response; 194 | } 195 | List history = feedsMapper.queryHistory(userId, pageCount, feedId <= 0 ? Integer.MAX_VALUE : feedId); 196 | if (history != null) { 197 | fillFeedList(userId, history); 198 | } 199 | response.setResult(ApiResponse.STATUS_FAILED, null, history); 200 | return response; 201 | } 202 | 203 | 204 | @RequestMapping(value = "queryFavorite", method = RequestMethod.GET) 205 | @ApiOperation(value = "查询收藏记录") 206 | public ApiResponse> queryFavorite(@RequestParam("userId") Long userId, 207 | @RequestParam(value = "pageCount", defaultValue = "10", required = false) int pageCount, 208 | @RequestParam("feedId") int feedId) { 209 | ApiResponse> response = new ApiResponse<>(); 210 | if (userId == null) { 211 | response.setResult(ApiResponse.STATUS_FAILED, "userId不能为空", null); 212 | return response; 213 | } 214 | List favorite = feedsMapper.queryFavorite(userId, pageCount, feedId <= 0 ? Integer.MAX_VALUE : feedId); 215 | if (favorite != null) { 216 | fillFeedList(userId, favorite); 217 | } 218 | response.setResult(ApiResponse.STATUS_FAILED, null, favorite); 219 | return response; 220 | } 221 | 222 | private void fillFeedList(@RequestParam("userId") Long userId, List list) { 223 | for (TableHotFeeds feed : list) { 224 | feed.author = userMapper.queryUser(feed.authorId); 225 | feed.ugc = ugcMapper.queryUgcByItemId(feed.itemId); 226 | Object userFollow = ugcMapper.isUserFollow(userId, feed.authorId); 227 | feed.author.hasFollow = userFollow == null ? false : ((Boolean) userFollow); 228 | if (feed.ugc != null && userId > 0) { 229 | Object liked = ugcMapper.isLiked(feed.itemId, userId); 230 | Object favorite = ugcMapper.hasFavorite(feed.itemId, userId); 231 | Object hasdiss = ugcMapper.hasDissFeed(feed.itemId, userId); 232 | feed.ugc.hasdiss = hasdiss == null ? false : (Boolean) hasdiss; 233 | feed.ugc.hasLiked = liked == null ? false : (Boolean) liked; 234 | feed.ugc.hasFavorite = favorite != null && (Boolean) favorite; 235 | } 236 | TableComment topComment = commentMapper.queryTopComment(feed.itemId); 237 | if (topComment != null) { 238 | TableFeedUgc feedUgc = ugcCommentMapper.queryUgcByCommentId(topComment.commentId); 239 | if (feedUgc != null) { 240 | Object commentLike = ugcCommentMapper.isCommentLike(topComment.commentId, userId); 241 | feedUgc.hasLiked = commentLike == null ? false : ((Boolean) commentLike); 242 | topComment.ugc = feedUgc; 243 | } 244 | topComment.author = userMapper.queryUser(topComment.userId); 245 | feed.topComment = topComment; 246 | } 247 | } 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/UgcController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | 4 | import com.example.demo.ApiResponse; 5 | import com.example.demo.mapper.*; 6 | import com.example.demo.table.TableComment; 7 | import com.example.demo.table.TableFeedUgc; 8 | import com.example.demo.table.TableHotFeeds; 9 | import com.example.demo.table.TableUser; 10 | import com.fasterxml.jackson.annotation.JsonView; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestMethod; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | import org.springframework.web.bind.annotation.RestController; 17 | 18 | import javax.annotation.Resource; 19 | 20 | @RestController 21 | @RequestMapping(value = "/ugc") 22 | @Api(value = "帖子相关接口API") 23 | public class UgcController { 24 | @Resource 25 | UgcMapper ugcMapper; 26 | 27 | @Resource 28 | UgcCommentMapper ugcCommentMapper; 29 | 30 | @Resource 31 | CommentMapper commentMapper; 32 | 33 | @Resource 34 | FeedsMapper feedsMapper; 35 | 36 | @Resource 37 | UserMapper userMapper; 38 | 39 | @RequestMapping(value = "/queryUgcByItemId", method = RequestMethod.GET) 40 | @ApiOperation(value = "根据itemId查询段子的ugc属性") 41 | public ApiResponse queryUgcByItemId(Long itemId) { 42 | ApiResponse response = new ApiResponse<>(); 43 | if (itemId == null) { 44 | response.setResult(ApiResponse.STATUS_FAILED, "itemId 不能为空"); 45 | return response; 46 | } 47 | TableFeedUgc feedUgc = ugcMapper.queryUgcByItemId(itemId); 48 | response.setResult(ApiResponse.STATUS_SUCCESS, null, feedUgc); 49 | return response; 50 | } 51 | 52 | 53 | // @RequestMapping(value = "/queryUgcByCommentId", method = RequestMethod.GET) 54 | // @ApiOperation(value = "根据commentId查询评论的ugc属性") 55 | // public ApiResponse queryUgcByCommentId(@RequestParam("commentId") Long commentId) { 56 | // ApiResponse response = new ApiResponse(); 57 | // if (commentId == null) { 58 | // response.setResult(ApiResponse.STATUS_FAILED, "commentId 不能为空"); 59 | // return response; 60 | // } 61 | // TableFeedUgc feedUgc = commentMapper.queryUgcByCommentId(commentId); 62 | // feedUgc.hasLiked = commentMapper.isCommentLike() 63 | // response.setResult(ApiResponse.STATUS_SUCCESS, null, feedUgc); 64 | // return response; 65 | // } 66 | 67 | 68 | @RequestMapping(value = "/increaseCommentCount", method = RequestMethod.GET) 69 | @ApiOperation(value = "增加段子评论的数量") 70 | public ApiResponse increaseCommentCount(Long itemId) { 71 | ApiResponse response = new ApiResponse<>(); 72 | if (itemId == null) { 73 | response.setResult(ApiResponse.STATUS_FAILED, "itemId 不能为空"); 74 | return response; 75 | } 76 | ugcMapper.increaseCommentCount(itemId, 1); 77 | int commentCount = ugcMapper.queryCommentCount(itemId); 78 | response.setData("count", commentCount); 79 | return response; 80 | } 81 | 82 | @RequestMapping(value = "toggleFavorite", method = RequestMethod.GET) 83 | @ApiOperation(value = "收藏一个帖子", notes = "根据itemId来收藏一个帖子") 84 | @JsonView(value = Boolean.class) 85 | public ApiResponse toggleFavorite(@RequestParam(value = "itemId", defaultValue = "0") Long itemId, @RequestParam(value = "userId", defaultValue = "0") Long userId) { 86 | ApiResponse response = new ApiResponse<>(); 87 | if (itemId == 0 || userId == 0) { 88 | response.setData("result", "itemId|userId 不能为空"); 89 | return response; 90 | } 91 | TableUser user = userMapper.queryUser(userId); 92 | ugcMapper.toggleFavorite(itemId, userId); 93 | Object hasFavorite = ugcMapper.hasFavorite(itemId, userId); 94 | boolean result = hasFavorite != null && (boolean) hasFavorite; 95 | if (result) { 96 | user.favoriteCount = user.favoriteCount + 1; 97 | response.setData("hasFavorite", true); 98 | } else { 99 | user.favoriteCount = user.favoriteCount - 1; 100 | response.setData("hasFavorite", false); 101 | } 102 | userMapper.insertUser(user); 103 | return response; 104 | 105 | } 106 | 107 | @RequestMapping(value = "/increaseLikeCount", method = RequestMethod.GET) 108 | @ApiOperation(value = "增加一条段子喜欢的数量") 109 | public ApiResponse increaseLikeCount(Long itemId) { 110 | ApiResponse response = new ApiResponse<>(); 111 | if (itemId == null) { 112 | response.setResult(ApiResponse.STATUS_FAILED, "itemId 不能为空"); 113 | return response; 114 | } 115 | ugcMapper.increaseLikeCount(itemId, 1); 116 | int likeCount = ugcMapper.queryLikeCount(itemId); 117 | response.setData("count", likeCount); 118 | return response; 119 | } 120 | 121 | @RequestMapping(value = "/increaseShareCount", method = RequestMethod.GET) 122 | @ApiOperation(value = "增加一条段子分享的数量") 123 | public ApiResponse increaseShareCount(Long itemId) { 124 | ApiResponse response = new ApiResponse<>(); 125 | if (itemId == null) { 126 | response.setResult(ApiResponse.STATUS_FAILED, "itemId 不能为空"); 127 | return response; 128 | } 129 | ugcMapper.increaseShareCount(itemId); 130 | int shareCount = ugcMapper.queryShareCount(itemId); 131 | response.setData("count", shareCount); 132 | return response; 133 | } 134 | 135 | @RequestMapping(value = "/toggleFeedLike", method = RequestMethod.GET) 136 | @ApiOperation(value = "变换用户对该条段子的喜欢结果") 137 | public ApiResponse toggleLike(Long itemId, Long userId) { 138 | ApiResponse apiResponse = new ApiResponse<>(); 139 | if (itemId == null || userId == null) { 140 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "itemId或者userId不能为空"); 141 | return apiResponse; 142 | } 143 | 144 | TableHotFeeds feed = feedsMapper.queryFeed(itemId); 145 | if (feed != null) { 146 | TableUser user = userMapper.queryUser(userId); 147 | if (user != null) { 148 | Object liked = ugcMapper.isLiked(itemId, userId); 149 | boolean hasLiked = liked == null ? false : (Boolean) liked; 150 | if (hasLiked) { 151 | ugcMapper.dissFeed(itemId, userId); 152 | } else { 153 | ugcMapper.toggleLike(itemId, userId); 154 | } 155 | ugcMapper.increaseLikeCount(itemId, hasLiked ? -1 : 1); 156 | apiResponse.setData("hasLiked", !hasLiked); 157 | user.likeCount = !hasLiked ? user.likeCount + 1 : user.likeCount - 1; 158 | userMapper.insertUser(user); 159 | } else { 160 | apiResponse.setResult(ApiResponse.STATUS_FAILED, String.format("不存在userId=%s 的用户", userId)); 161 | } 162 | } else { 163 | apiResponse.setResult(ApiResponse.STATUS_FAILED, String.format("不存在itemId=%s的帖子", itemId)); 164 | } 165 | 166 | return apiResponse; 167 | } 168 | 169 | @RequestMapping(value = "/isLiked", method = RequestMethod.GET) 170 | @ApiOperation(value = "查询用户对该条段子的喜欢结果") 171 | public ApiResponse isLiked(Long itemId, Long userId) { 172 | ApiResponse apiResponse = new ApiResponse<>(); 173 | if (itemId == null || userId == null) { 174 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "itemId或者userId不能为空"); 175 | return apiResponse; 176 | } 177 | Object liked = ugcMapper.isLiked(itemId, userId); 178 | boolean hasLiked = liked == null ? false : (Boolean) liked; 179 | apiResponse.setData("hasLiked", hasLiked); 180 | return apiResponse; 181 | } 182 | 183 | 184 | @RequestMapping(value = "/toggleTagListFollow", method = RequestMethod.GET) 185 | @ApiOperation(value = "变换用户对该标签类型的喜欢结果") 186 | public ApiResponse toggleTagListFollow(Long tagId, Long userId) { 187 | ApiResponse apiResponse = new ApiResponse<>(); 188 | if (tagId == null || userId == null) { 189 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "tagId或者userId不能为空"); 190 | return apiResponse; 191 | } 192 | 193 | ugcMapper.toggleTagListFollow(tagId, userId); 194 | Object liked = ugcMapper.hasFollowTag(tagId, userId); 195 | boolean hasLiked = liked != null && (Boolean) liked; 196 | apiResponse.setData("hasLiked", hasLiked); 197 | return apiResponse; 198 | } 199 | 200 | 201 | @RequestMapping(value = "/hasFollowTag", method = RequestMethod.GET) 202 | @ApiOperation(value = "查询用户对该标签类型的喜欢结果") 203 | public ApiResponse hasFollowTag(Long tagId, Long userId) { 204 | ApiResponse apiResponse = new ApiResponse<>(); 205 | if (tagId == null || userId == null) { 206 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "tagId或者userId不能为空"); 207 | return apiResponse; 208 | } 209 | 210 | Object liked = ugcMapper.hasFollowTag(tagId, userId); 211 | boolean hasLiked = liked == null ? false : (Boolean) liked; 212 | apiResponse.setData("hasLiked", hasLiked); 213 | return apiResponse; 214 | } 215 | 216 | 217 | @RequestMapping(value = "/toggleCommentLike", method = RequestMethod.GET) 218 | @ApiOperation(value = "变更用户对一条评论的喜欢状态") 219 | public ApiResponse toggleCommentLike(Long commentId, Long userId) { 220 | ApiResponse apiResponse = new ApiResponse<>(); 221 | if (commentId == null || userId == null) { 222 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "commentId或者userId不能为空"); 223 | return apiResponse; 224 | } 225 | 226 | ugcCommentMapper.toggleCommentLike(commentId, userId); 227 | Object commentLike = ugcMapper.isCommentLike(commentId, userId); 228 | boolean hasLiked = commentLike != null && (Boolean) commentLike; 229 | ugcCommentMapper.increaseLikeCount(commentId, hasLiked ? 1 : -1); 230 | apiResponse.setData("hasLiked", hasLiked); 231 | 232 | TableComment comment = commentMapper.queryComment(commentId); 233 | if (comment != null && comment.author != null) { 234 | TableUser user = userMapper.queryUser(comment.userId); 235 | if (user != null) { 236 | if (hasLiked) { 237 | user.likeCount = user.likeCount + 1; 238 | } else { 239 | user.likeCount = user.likeCount - 1; 240 | } 241 | userMapper.insertUser(user); 242 | } 243 | } 244 | 245 | return apiResponse; 246 | } 247 | 248 | @RequestMapping(value = "/isCommentLike", method = RequestMethod.GET) 249 | @ApiOperation(value = "查询用户对一条评论的喜欢状态") 250 | public ApiResponse isCommentLike(Long commentId, Long userId) { 251 | ApiResponse apiResponse = new ApiResponse<>(); 252 | if (commentId == null || userId == null) { 253 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "commentId或者userId不能为空"); 254 | return apiResponse; 255 | } 256 | 257 | Object commentLike = ugcCommentMapper.isCommentLike(commentId, userId); 258 | boolean hasLiked = commentLike != null && (Boolean) commentLike; 259 | apiResponse.setData("hasLiked", hasLiked); 260 | return apiResponse; 261 | } 262 | 263 | 264 | @RequestMapping(value = "/toggleUserFollow", method = RequestMethod.GET) 265 | @ApiOperation(value = "变更用户对另一个用户的喜欢状态") 266 | public ApiResponse toggleUserFollow(@RequestParam(value = "followUserId") Long followUserId, @RequestParam(value = "userId") Long userId) { 267 | ApiResponse apiResponse = new ApiResponse<>(); 268 | if (followUserId == null || userId == null) { 269 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "followUserId或者userId不能为空"); 270 | return apiResponse; 271 | } 272 | 273 | ugcMapper.toggleUserFollow(followUserId, userId); 274 | Boolean hasFollow = (boolean) ugcMapper.isUserFollow(followUserId, userId); 275 | TableUser followUser = userMapper.queryUser(followUserId); 276 | if (followUser != null) { 277 | if (hasFollow) { 278 | followUser.followCount = followUser.followCount + 1; 279 | } else { 280 | followUser.followCount = followUser.followCount - 1; 281 | } 282 | } 283 | 284 | TableUser user = userMapper.queryUser(userId); 285 | if (user != null) { 286 | if (hasFollow) { 287 | user.followerCount = user.followerCount + 1; 288 | } else { 289 | user.followerCount = user.followerCount - 1; 290 | } 291 | } 292 | 293 | userMapper.insertUser(followUser); 294 | userMapper.insertUser(user); 295 | apiResponse.setData("hasLiked", hasFollow); 296 | return apiResponse; 297 | } 298 | 299 | @RequestMapping(value = "/isUserFollow", method = RequestMethod.GET) 300 | @ApiOperation(value = "查询用户对另一个用户的喜欢状态") 301 | public ApiResponse isUserFollow(@RequestParam(value = "followUserId") Long followUserId, @RequestParam(value = "userId") Long userId) { 302 | ApiResponse apiResponse = new ApiResponse<>(); 303 | if (followUserId == null || userId == null) { 304 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "commentId或者userId不能为空"); 305 | return apiResponse; 306 | } 307 | 308 | Object commentLike = ugcMapper.isUserFollow(followUserId, userId); 309 | boolean hasLiked = commentLike != null && (Boolean) commentLike; 310 | apiResponse.setData("hasLiked", hasLiked); 311 | return apiResponse; 312 | } 313 | 314 | 315 | @RequestMapping(value = "/dissFeed", method = RequestMethod.GET) 316 | @ApiOperation(value = "变更用户对一个帖子的diss状态") 317 | public ApiResponse dissFeed(Long itemId, Long userId) { 318 | ApiResponse apiResponse = new ApiResponse<>(); 319 | if (itemId == null || userId == null) { 320 | apiResponse.setResult(ApiResponse.STATUS_FAILED, "itemId或者userId不能为空"); 321 | return apiResponse; 322 | } 323 | 324 | TableHotFeeds feed = feedsMapper.queryFeed(itemId); 325 | if (feed != null) { 326 | TableUser user = userMapper.queryUser(userId); 327 | if (user != null) { 328 | user.likeCount = user.likeCount - 1; 329 | userMapper.insertUser(user); 330 | } 331 | } 332 | ugcMapper.dissFeed(itemId, userId); 333 | ugcMapper.increaseLikeCount(itemId, -1); 334 | return hasDissFeed(itemId, userId); 335 | } 336 | 337 | @RequestMapping(value = "/hasDissFeed", method = RequestMethod.GET) 338 | @ApiOperation(value = "查询用户对一个帖子的diss状态") 339 | public ApiResponse hasDissFeed(Long itemId, Long userId) { 340 | ApiResponse response = new ApiResponse<>(); 341 | if (itemId == null || userId == null) { 342 | response.setResult(ApiResponse.STATUS_FAILED, "itemId或者userId不能为空"); 343 | return response; 344 | } 345 | Object dissFeed = ugcMapper.hasDissFeed(itemId, userId); 346 | boolean hasLiked = dissFeed != null && (Boolean) dissFeed; 347 | response.setData("hasLiked", hasLiked); 348 | return response; 349 | } 350 | } 351 | --------------------------------------------------------------------------------