Jelajahi Sumber

添加购买接口

tianboguang 3 tahun lalu
induk
melakukan
b0b0b46bb7

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

@@ -2,9 +2,11 @@ package com.fdage.followheartplay.controller;
 
 
 import com.fdage.followheartplay.dto.SceneDto;
 import com.fdage.followheartplay.dto.SceneDto;
 import com.fdage.followheartplay.service.SceneService;
 import com.fdage.followheartplay.service.SceneService;
+import com.fdkankan.common.constant.ServerCode;
 import com.fdkankan.common.response.ResultData;
 import com.fdkankan.common.response.ResultData;
 import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.common.util.JwtUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -31,4 +33,20 @@ public class SceneController {
         List<SceneDto> sceneEntities = sceneService.getScenesByTypeAndUserId(username,type);
         List<SceneDto> sceneEntities = sceneService.getScenesByTypeAndUserId(username,type);
         return ResultData.ok(sceneEntities);
         return ResultData.ok(sceneEntities);
     }
     }
+
+    /**
+     * 查询场景信息
+     * @param token
+     * @param sceneId
+     * @return
+     */
+    @PostMapping("/buy")
+    public ResultData buy(@RequestHeader String token, Integer sceneId){
+        if(ObjectUtils.isEmpty(sceneId)){
+            return ResultData.error(ServerCode.PARAM_REQUIRED.code(),"缺少必要参数!");
+        }
+        String username = JwtUtil.getUsername(token);
+        sceneService.buy(username,sceneId);
+        return ResultData.ok();
+    }
 }
 }

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

@@ -43,4 +43,43 @@ public class BaseEntity {
     @Column(name = "tb_status")
     @Column(name = "tb_status")
     private Integer tbStatus;
     private Integer tbStatus;
 
 
+    public Long getCreaterId() {
+        return createrId;
+    }
+
+    public void setCreaterId(Long createrId) {
+        this.createrId = createrId;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Long getUpdaterId() {
+        return updaterId;
+    }
+
+    public void setUpdaterId(Long updaterId) {
+        this.updaterId = updaterId;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public Integer getTbStatus() {
+        return tbStatus;
+    }
+
+    public void setTbStatus(Integer tbStatus) {
+        this.tbStatus = tbStatus;
+    }
 }
 }

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

@@ -17,7 +17,7 @@ public class SceneBuyRecordEntity extends BaseEntity{
     private Long sceneId;
     private Long sceneId;
 
 
     @Column(name = "user_name")
     @Column(name = "user_name")
-    private Long userName;
+    private String userName;
 
 
 
 
     public Long getId() {
     public Long getId() {
@@ -37,11 +37,11 @@ public class SceneBuyRecordEntity extends BaseEntity{
         this.sceneId = sceneId;
         this.sceneId = sceneId;
     }
     }
 
 
-    public Long getUserName() {
+    public String getUserName() {
         return userName;
         return userName;
     }
     }
 
 
-    public void setUserName(Long userName) {
+    public void setUserName(String userName) {
         this.userName = userName;
         this.userName = userName;
     }
     }
 }
 }

+ 11 - 0
src/main/java/com/fdage/followheartplay/repository/SceneBuyRecordRepository.java

@@ -0,0 +1,11 @@
+package com.fdage.followheartplay.repository;
+
+import com.fdage.followheartplay.entity.SceneBuyRecordEntity;
+import com.fdage.followheartplay.entity.SceneEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface SceneBuyRecordRepository extends JpaRepository<SceneBuyRecordEntity,Long> {
+
+}

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

@@ -1,12 +1,17 @@
 package com.fdage.followheartplay.service;
 package com.fdage.followheartplay.service;
 
 
 import com.fdage.followheartplay.dto.SceneDto;
 import com.fdage.followheartplay.dto.SceneDto;
+import com.fdage.followheartplay.entity.SceneBuyRecordEntity;
+import com.fdage.followheartplay.entity.SceneEntity;
+import com.fdage.followheartplay.repository.SceneBuyRecordRepository;
 import com.fdage.followheartplay.repository.SceneRepository;
 import com.fdage.followheartplay.repository.SceneRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 import org.springframework.util.ObjectUtils;
 
 
+import java.util.Date;
 import java.util.List;
 import java.util.List;
+import java.util.Optional;
 
 
 @Service
 @Service
 public class SceneService {
 public class SceneService {
@@ -14,6 +19,9 @@ public class SceneService {
     @Autowired
     @Autowired
     private SceneRepository sceneRepository;
     private SceneRepository sceneRepository;
 
 
+    @Autowired
+    private SceneBuyRecordRepository repository;
+
     public List<SceneDto> getScenesByTypeAndUserId(String userName, Integer type) {
     public List<SceneDto> getScenesByTypeAndUserId(String userName, Integer type) {
         // 查询所有
         // 查询所有
         if(ObjectUtils.isEmpty(type)){
         if(ObjectUtils.isEmpty(type)){
@@ -27,4 +35,14 @@ public class SceneService {
         // 查询已购买
         // 查询已购买
         return sceneRepository.findAllBuiedRecordByUserIdAndType(userName);
         return sceneRepository.findAllBuiedRecordByUserIdAndType(userName);
     }
     }
+
+    public void buy(String username, Integer sceneId) {
+        SceneBuyRecordEntity entity = new SceneBuyRecordEntity();
+        entity.setSceneId(sceneId.longValue());
+        entity.setUserName(username);
+        entity.setCreateTime(new Date());
+        entity.setUpdateTime(new Date());
+        entity.setTbStatus(0);
+        repository.save(entity);
+    }
 }
 }