tianboguang 3 rokov pred
commit
3efeeae525

+ 60 - 0
pom.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.6.3</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>com.fdage</groupId>
+    <artifactId>FollowHeartPlay</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>FollowHeartPlay</name>
+    <description>Demo project for Spring Boot</description>
+    <properties>
+        <java.version>1.8</java.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>2.2.2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.fdkankan</groupId>
+            <artifactId>4dkankan-common-utils</artifactId>
+            <version>2.0.0-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 13 - 0
src/main/java/com/fdage/followheartplay/FollowHeartPlayApplication.java

@@ -0,0 +1,13 @@
+package com.fdage.followheartplay;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class FollowHeartPlayApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(FollowHeartPlayApplication.class, args);
+    }
+
+}

+ 34 - 0
src/main/java/com/fdage/followheartplay/controller/SceneController.java

@@ -0,0 +1,34 @@
+package com.fdage.followheartplay.controller;
+
+import com.fdage.followheartplay.dto.SceneDto;
+import com.fdage.followheartplay.service.SceneService;
+import com.fdkankan.common.response.ResultData;
+import com.fdkankan.common.util.JwtUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/scene")
+public class SceneController {
+
+    @Autowired
+    private SceneService sceneService;
+
+    /**
+     * 查询场景信息
+     * @param token
+     * @param type 0:未购买,1:已购买,空全部
+     * @return
+     */
+    @PostMapping("/list")
+    public ResultData getScenes(@RequestHeader String token, Integer type){
+        String username = JwtUtil.getUsername(token);
+        List<SceneDto> sceneEntities = sceneService.getScenesByTypeAndUserId("3",type);
+        return ResultData.ok(sceneEntities);
+    }
+}

+ 15 - 0
src/main/java/com/fdage/followheartplay/dto/SceneDto.java

@@ -0,0 +1,15 @@
+package com.fdage.followheartplay.dto;
+
+public interface SceneDto {
+
+    public Long getId();
+
+    public String getSceneName();
+
+    public String getSceneCoverUrl();
+
+    public String getSceneData() ;
+
+    public Long getUserId();
+
+}

+ 46 - 0
src/main/java/com/fdage/followheartplay/entity/BaseEntity.java

@@ -0,0 +1,46 @@
+package com.fdage.followheartplay.entity;
+
+import javax.persistence.Column;
+import java.util.Date;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/2/15
+ **/
+public class BaseEntity {
+
+    /**
+     * 创建人id
+     */
+    @Column(name = "creater_id")
+    private Long createrId;
+
+    /**
+     * 创建时间
+     */
+    @Column(name = "create_time")
+    private Date createTime;
+
+    /**
+     * 修改人id
+     */
+    @Column(name = "updater_id")
+    private Long updaterId;
+
+    /**
+     * 修改时间
+     */
+    @Column(name = "update_time")
+    private Date updateTime;
+
+    /**
+     * 0-有效,1-删除, 2-禁用
+     */
+    @Column(name = "tb_status")
+    private Integer tbStatus;
+
+}

+ 47 - 0
src/main/java/com/fdage/followheartplay/entity/SceneBuyRecordEntity.java

@@ -0,0 +1,47 @@
+package com.fdage.followheartplay.entity;
+
+import javax.persistence.*;
+
+/**
+ * 场景购买记录实体
+ */
+@Entity
+@Table(name="scene_buy_record_entity",schema = "follow_heart_play")
+public class SceneBuyRecordEntity extends BaseEntity{
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private Long id;
+
+    @Column(name = "scene_id")
+    private Long sceneId;
+
+    @Column(name = "user_name")
+    private Long userName;
+
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+
+    public Long getSceneId() {
+        return sceneId;
+    }
+
+    public void setSceneId(Long sceneId) {
+        this.sceneId = sceneId;
+    }
+
+    public Long getUserName() {
+        return userName;
+    }
+
+    public void setUserName(Long userName) {
+        this.userName = userName;
+    }
+}

+ 52 - 0
src/main/java/com/fdage/followheartplay/entity/SceneEntity.java

@@ -0,0 +1,52 @@
+package com.fdage.followheartplay.entity;
+
+import javax.persistence.*;
+
+/**
+ * 场景实体
+ */
+@Entity
+@Table(name="scene_entity",schema = "follow_heart_play")
+public class SceneEntity extends BaseEntity{
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private Long id;
+    @Column(name = "scene_name")
+    private String sceneName;
+    @Column(name = "scene_cover_url")
+    private String sceneCoverUrl;
+    @Column(name = "scene_data")
+    private String sceneData;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getSceneName() {
+        return sceneName;
+    }
+
+    public void setSceneName(String sceneName) {
+        this.sceneName = sceneName;
+    }
+
+    public String getSceneCoverUrl() {
+        return sceneCoverUrl;
+    }
+
+    public void setSceneCoverUrl(String sceneCoverUrl) {
+        this.sceneCoverUrl = sceneCoverUrl;
+    }
+
+    public String getSceneData() {
+        return sceneData;
+    }
+    public void setSceneData(String sceneData) {
+        this.sceneData = sceneData;
+    }
+}

+ 26 - 0
src/main/java/com/fdage/followheartplay/repository/SceneRepository.java

@@ -0,0 +1,26 @@
+package com.fdage.followheartplay.repository;
+
+import com.fdage.followheartplay.dto.SceneDto;
+import com.fdage.followheartplay.entity.SceneEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface SceneRepository extends JpaRepository<SceneEntity,Long> {
+
+    @Query(nativeQuery = true, value = "select c.id,c.scene_name sceneName,scene_cover_url sceneCoverUrl,scene_data sceneData,bre.user_name userName from scene_entity c " +
+            "left join scene_buy_record_entity bre on c.id = bre.scene_id and bre.user_name = :userName and bre.tb_status=0 where c.tb_status = 0")
+    List<SceneDto> findAllBuyRecordByUserIdAndType(@Param("userName")String userName);
+
+    @Query(nativeQuery = true,value = "select c.id, c.scene_name sceneName, scene_cover_url sceneCoverUrl, scene_data sceneData,bre.user_name userName from scene_entity c" +
+            " left join scene_buy_record_entity bre on c.id = bre.scene_id and bre.user_name = :userName and bre.tb_status=0 where bre.id is null and c.tb_status = 0")
+    List<SceneDto> findAllUnBuyRecordByUserIdAndType(@Param("userName")String userName);
+
+    @Query(nativeQuery = true,value = "select c.id, c.scene_name sceneName, scene_cover_url sceneCoverUrl, scene_data sceneData,bre.user_name userName from scene_entity c" +
+            " left join scene_buy_record_entity bre on c.id = bre.scene_id and bre.user_name = :userName and bre.tb_status=0 where bre.id is not null and c.tb_status = 0")
+    List<SceneDto> findAllBuiedRecordByUserIdAndType(@Param("userName")String userName);
+}

+ 30 - 0
src/main/java/com/fdage/followheartplay/service/SceneService.java

@@ -0,0 +1,30 @@
+package com.fdage.followheartplay.service;
+
+import com.fdage.followheartplay.dto.SceneDto;
+import com.fdage.followheartplay.repository.SceneRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
+
+import java.util.List;
+
+@Service
+public class SceneService {
+
+    @Autowired
+    private SceneRepository sceneRepository;
+
+    public List<SceneDto> getScenesByTypeAndUserId(String userName, Integer type) {
+        // 查询所有
+        if(ObjectUtils.isEmpty(type)){
+            return sceneRepository.findAllBuyRecordByUserIdAndType(userName);
+        }
+        // 查询未购买
+        if(type == 0){
+            return sceneRepository.findAllUnBuyRecordByUserIdAndType(userName);
+        }
+
+        // 查询已购买
+        return sceneRepository.findAllBuiedRecordByUserIdAndType(userName);
+    }
+}

+ 51 - 0
src/main/java/com/fdage/followheartplay/vo/SceneQueryVo.java

@@ -0,0 +1,51 @@
+package com.fdage.followheartplay.vo;
+
+import com.fdkankan.common.request.RequestBase;
+
+public class SceneQueryVo extends RequestBase {
+    private Long id;
+    private String userId;
+    private String sceneName;
+    private String sceneCoverUrl;
+    private String sceneData;
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getSceneName() {
+        return sceneName;
+    }
+
+    public void setSceneName(String sceneName) {
+        this.sceneName = sceneName;
+    }
+
+    public String getSceneCoverUrl() {
+        return sceneCoverUrl;
+    }
+
+    public void setSceneCoverUrl(String sceneCoverUrl) {
+        this.sceneCoverUrl = sceneCoverUrl;
+    }
+
+    public String getSceneData() {
+        return sceneData;
+    }
+
+    public void setSceneData(String sceneData) {
+        this.sceneData = sceneData;
+    }
+}

+ 17 - 0
src/main/resources/application.yml

@@ -0,0 +1,17 @@
+spring:
+  #连接mysql数据库
+  datasource:
+    url: jdbc:mysql://192.168.0.47:3306/follow_heart_play?useUnicode=true&characterEncoding=utf8
+    username: root
+    password: 123123
+    driver-class-name: com.mysql.jdbc.Driver
+
+  jpa:
+    # 数据库类型
+    database: MySQL
+    hibernate:
+      ddl-auto: none
+    # -控制台显示sql语句
+    show-sql: true
+    # 是否自动创建数据库表
+    generate-ddl: false

+ 13 - 0
src/test/java/com/fdage/followheartplay/FollowHeartPlayApplicationTests.java

@@ -0,0 +1,13 @@
+package com.fdage.followheartplay;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class FollowHeartPlayApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}