package gateway import ( errmsg "confrontation-training/err" deviceModel "confrontation-training/models/gateway" "confrontation-training/response" deviceService "confrontation-training/service/device" "fmt" "github.com/gin-gonic/gin" ) type DeviceService struct { deviceService.DeviceService } func GetDeviceService() *DeviceService { return &DeviceService{} } // DeviceAdd // PingExample confrontation-training // @Summary 新增设备 // @Schemes // @Description 新增设备 // @Tags 设备管理 // @Param device body string true "type:类型 0脑电1心电;mac:设备MAC地址" // @Accept json // @Produce json // @Success 200 {string} string "ok" // @Router /v1/device/add [post] func (d *DeviceService) DeviceAdd(c *gin.Context) { var param deviceModel.DeviceAddParam err := c.ShouldBindJSON(¶m) if err != nil { fmt.Printf("参数格式化异常:%s", err.Error()) response.Failed(errmsg.ParamInvalid, c) return } if _, count := d.FindDeviceByMac(param.Mac); count > 0 { response.Failed(errmsg.DeviceAddFailed, c) return } if result := d.CreateDevice(param); result.Error == nil { response.Success(errmsg.DeviceAddSuccess, result.RowsAffected, c) return } else { response.Failed(errmsg.UserRegisterFailed+"数据库错:"+result.Error.Error(), c) return } }