Browse Source

fix:zzf

develoven 1 year ago
parent
commit
7dc4fe6650
4 changed files with 8 additions and 7 deletions
  1. 1 1
      api/gateway/device.go
  2. 1 1
      api/gateway/gateway.go
  3. 4 3
      initialize/router.go
  4. 2 2
      service/device/device.go

+ 1 - 1
api/gateway/device.go

@@ -58,7 +58,7 @@ func (d *DeviceService) DeviceAdd(c *gin.Context) {
 // @Accept json
 // @Accept json
 // @Produce json
 // @Produce json
 // @Success 200 {string} string "ok"
 // @Success 200 {string} string "ok"
-// @Router /v1/device/:mac/remove [post]
+// @Router /v1/device/:mac/remove [delete]
 func (d *DeviceService) DeviceRemove(c *gin.Context) {
 func (d *DeviceService) DeviceRemove(c *gin.Context) {
 	mac := c.Param("mac")
 	mac := c.Param("mac")
 	count := d.RemoveDevice(mac)
 	count := d.RemoveDevice(mac)

+ 1 - 1
api/gateway/gateway.go

@@ -317,7 +317,7 @@ func StopCollect(c *gin.Context) {
 // @Accept json
 // @Accept json
 // @Produce json
 // @Produce json
 // @Success 200 {string} string "ok"
 // @Success 200 {string} string "ok"
-// @Router /v1/device/:mac/disconnect [delete]
+// @Router /v1/device/:mac/disconnect [get]
 func Disconnect(c *gin.Context) {
 func Disconnect(c *gin.Context) {
 	mac := c.Param("mac")
 	mac := c.Param("mac")
 	disconnectUrl := global.Config.Gateway.BaseUrl + global.Config.Gateway.DisconnectUrl
 	disconnectUrl := global.Config.Gateway.BaseUrl + global.Config.Gateway.DisconnectUrl

+ 4 - 3
initialize/router.go

@@ -9,6 +9,7 @@ import (
 	"confrontation-training/middleware"
 	"confrontation-training/middleware"
 	"confrontation-training/models"
 	"confrontation-training/models"
 	modelsChat "confrontation-training/models/chat"
 	modelsChat "confrontation-training/models/chat"
+	modelsDevice "confrontation-training/models/gateway"
 	"fmt"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/gin-gonic/gin"
 	swaggerFiles "github.com/swaggo/files"
 	swaggerFiles "github.com/swaggo/files"
@@ -19,7 +20,7 @@ import (
 func Router() {
 func Router() {
 
 
 	//初始化表格
 	//初始化表格
-	initTableErr := global.Db.AutoMigrate(&models.User{}, &modelsChat.Question{}, &modelsChat.Answer{})
+	initTableErr := global.Db.AutoMigrate(&models.User{}, &modelsChat.Question{}, &modelsChat.Answer{}, &modelsDevice.DeviceInfo{})
 	if initTableErr != nil {
 	if initTableErr != nil {
 		fmt.Printf("初始化表格异常:%s", initTableErr.Error())
 		fmt.Printf("初始化表格异常:%s", initTableErr.Error())
 		return
 		return
@@ -51,7 +52,7 @@ func Router() {
 	user.POST("/reset", gateway.GetUser().ResetPassword)
 	user.POST("/reset", gateway.GetUser().ResetPassword)
 	user.GET("/find", gateway.GetUser().UserList)
 	user.GET("/find", gateway.GetUser().UserList)
 	user.POST("/change/password", gateway.GetUser().ModePass)
 	user.POST("/change/password", gateway.GetUser().ModePass)
-	device := v1.Group("/device")
+	device := v1.Group("/device/")
 	device.GET("/scan", gateway.ScanDevice)
 	device.GET("/scan", gateway.ScanDevice)
 	device.GET("/connection", gateway.ConnectDevice)
 	device.GET("/connection", gateway.ConnectDevice)
 	device.POST("/write/data/", gateway.WriteData)
 	device.POST("/write/data/", gateway.WriteData)
@@ -60,7 +61,7 @@ func Router() {
 	device.GET("/:mac/stop/collect/", gateway.StopCollect)
 	device.GET("/:mac/stop/collect/", gateway.StopCollect)
 	device.GET("/:mac/disconnect/", gateway.Disconnect)
 	device.GET("/:mac/disconnect/", gateway.Disconnect)
 	device.POST("/add/", gateway.GetDeviceService().DeviceAdd)
 	device.POST("/add/", gateway.GetDeviceService().DeviceAdd)
-	device.DELETE("/:mac/remove", gateway.GetDeviceService().DeviceRemove)
+	device.DELETE("/:mac/remove/", gateway.GetDeviceService().DeviceRemove)
 	device.GET("/list/:type", gateway.GetDeviceService().DeviceList)
 	device.GET("/list/:type", gateway.GetDeviceService().DeviceList)
 	chats := v1.Group("/chat")
 	chats := v1.Group("/chat")
 	chats.GET("/get/chat/", chat.GetQuestionService().GetQuestion)
 	chats.GET("/get/chat/", chat.GetQuestionService().GetQuestion)

+ 2 - 2
service/device/device.go

@@ -20,11 +20,11 @@ func (d *DeviceService) FindDeviceByType(deviceType string) ([]deviceModel.Devic
 	return deviceList, count
 	return deviceList, count
 }
 }
 func (d *DeviceService) CreateDevice(param deviceModel.DeviceAddParam) *gorm.DB {
 func (d *DeviceService) CreateDevice(param deviceModel.DeviceAddParam) *gorm.DB {
-	addParam := deviceModel.DeviceAddParam{
+	addParam := deviceModel.DeviceInfo{
 		Type: param.Type,
 		Type: param.Type,
 		Mac:  param.Mac,
 		Mac:  param.Mac,
 	}
 	}
-	return global.Db.Create(addParam)
+	return global.Db.Create(&addParam)
 }
 }
 
 
 func (d *DeviceService) RemoveDevice(mac string) int64 {
 func (d *DeviceService) RemoveDevice(mac string) int64 {