diff --git a/crontask/corn.go b/crontask/corn.go index 3b3b4a1..ff88329 100644 --- a/crontask/corn.go +++ b/crontask/corn.go @@ -17,7 +17,7 @@ import ( func Run() { crontab := cron.New(cron.WithSeconds()) crontab.AddFunc("0 */1 * * * ?", CheckAndroidDevices) - crontab.AddFunc("0 */1 * * * ?", CheckIOSDevices) + // crontab.AddFunc("0 */1 * * * ?", CheckIOSDevices) crontab.AddFunc("*/15 * * * * ?", CheckMonkeyTasks) crontab.Start() fmt.Println("[Crontab] 定时任务启动") diff --git a/device/device_v2.go b/device/device_v2.go index 90d6e8e..049f69d 100644 --- a/device/device_v2.go +++ b/device/device_v2.go @@ -106,3 +106,38 @@ func UpdateDeviceStatusV2(c *gin.Context) { rsp.Data = dv c.JSON(http.StatusOK, rsp) } + +// @Tags 设备相关 /api/device/v2/ +// @Summary 查询设备 +// @Description 根据udid查询设备 +// @accept x-www-form-urlencoded +// @Param udid query string true "设备udid" +// @Success 200 {object} models.Response "返回设备信息" +// @Router /api/device/v2/get_device [get] +func GetDeviceByUdidV2(c *gin.Context) { + rsp := controllers.NewResponse() + + udid := c.DefaultQuery("udid", "") + if udid == "" { + c.JSON(http.StatusOK, rsp.Error("udid error")) + return + } + db, err := dbsql.GetConn(dbsql.DSN_qaoms()) + if err != nil { + c.JSON(http.StatusOK, rsp.Error(err.Error())) + return + } + defer dbsql.Close(db) + + var dv models.DeviceV2 + + db.Model(models.DeviceV2{}).Where("udid = ?", udid).Last(&dv) + + if dv.ID < 1 { + c.JSON(http.StatusOK, rsp.Error("没有找到该设备,udid-"+udid)) + return + } + + rsp.Data = dv + c.JSON(http.StatusOK, rsp.Success()) +} diff --git a/docs/docs.go b/docs/docs.go index 72bc958..0c9266b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -346,6 +346,35 @@ const docTemplate = `{ } } }, + "/api/device/v2/get_device": { + "get": { + "description": "根据udid查询设备", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "tags": [ + "设备相关 /api/device/v2/" + ], + "summary": "查询设备", + "parameters": [ + { + "type": "string", + "description": "设备udid", + "name": "udid", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "返回设备信息", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/api/device/v2/update_status": { "post": { "description": "更新设备状态,错误的状态会被拒绝", diff --git a/docs/swagger.json b/docs/swagger.json index 3759b06..f15528c 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -334,6 +334,35 @@ } } }, + "/api/device/v2/get_device": { + "get": { + "description": "根据udid查询设备", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "tags": [ + "设备相关 /api/device/v2/" + ], + "summary": "查询设备", + "parameters": [ + { + "type": "string", + "description": "设备udid", + "name": "udid", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "返回设备信息", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/api/device/v2/update_status": { "post": { "description": "更新设备状态,错误的状态会被拒绝", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9136c13..ed51dda 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -263,6 +263,25 @@ paths: summary: 新建设备 tags: - 设备相关 /api/device/v2/ + /api/device/v2/get_device: + get: + consumes: + - application/x-www-form-urlencoded + description: 根据udid查询设备 + parameters: + - description: 设备udid + in: query + name: udid + required: true + type: string + responses: + "200": + description: 返回设备信息 + schema: + $ref: '#/definitions/models.Response' + summary: 查询设备 + tags: + - 设备相关 /api/device/v2/ /api/device/v2/update_status: post: consumes: diff --git a/models/oms_devices.go b/models/oms_devices.go index c705d73..46417b0 100644 --- a/models/oms_devices.go +++ b/models/oms_devices.go @@ -8,7 +8,7 @@ import ( // Device 结构体 type DeviceV2 struct { - ID uint `gorm:"primarykey"` // 主键ID + ID uint `json:"id" gorm:"primarykey"` // 主键ID ProductId *int `json:"product_id" form:"product_id" gorm:"column:product_id;comment:产品表主键id;"` DeviceName string `json:"device_name" form:"device_name" gorm:"column:device_name;comment:;"` Brand string `json:"brand" form:"brand" gorm:"column:brand;comment:设备品牌;"` @@ -19,7 +19,7 @@ type DeviceV2 struct { LanIp string `json:"lan_ip" form:"lan_ip" gorm:"column:lan_ip;comment:局域网ip地址;"` Status string `json:"status" form:"status" gorm:"column:status;comment:描述设备的状态;"` StatusDetails string `json:"status_details" form:"status_details" gorm:"column:status_details;comment:设备详细状态;"` - IsEnabled *int `json:"is_enabled" form:"is_enabled" gorm:"column:is_enabled;comment:;"` + IsEnabled int `json:"is_enabled" form:"is_enabled" gorm:"column:is_enabled;comment:;"` CreatedAt time.Time `json:"create_time" gorm:"column:created_at;autoCreate"` // 创建时间 UpdatedAt time.Time `json:"update_time" gorm:"column:updated_at;autoUpdate"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // 删除时间 diff --git a/router/v2.go b/router/v2.go index dde3daa..c29c7e0 100644 --- a/router/v2.go +++ b/router/v2.go @@ -20,4 +20,5 @@ func setRouteV2(r *gin.Engine) { r.POST("/api/device/v2/create", device.CreateDeviceV2) r.POST("/api/device/v2/update_status", device.UpdateDeviceStatusV2) + r.GET("/api/device/v2/get_device", device.GetDeviceByUdidV2) }