You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package monkey
|
|
|
|
import (
|
|
"autogo/controllers"
|
|
"autogo/dbsql"
|
|
"autogo/models"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/spf13/cast"
|
|
)
|
|
|
|
// @Tags Monkey相关 /api/monkey/v1/
|
|
// @Summary 上报Monkey结果
|
|
// @Description 上报Monkey结果
|
|
// @accept x-www-form-urlencoded
|
|
// @Param task_id formData int true "任务id"
|
|
// @Param crash_log_list formData string false "要更新的任务状态"
|
|
// @Param activity_name_info formData string false "要更新的任务状态"
|
|
// @Param device_name formData string false "要更新的任务状态"
|
|
// @Param status formData string false "要更新的任务状态"
|
|
// @Success 200 {object} models.Response "返回更新后的任务信息"
|
|
// @Router /api/monkey/v1/task/result [post]
|
|
func UploadMonkeyResult(c *gin.Context) {
|
|
rsp := controllers.NewResponse()
|
|
|
|
var res models.MonkeyResult
|
|
res.TaskId = cast.ToInt(c.PostForm("task_id"))
|
|
if res.TaskId < 1 {
|
|
rsp.Error("task_id error:" + c.PostForm("task_id"))
|
|
c.JSON(http.StatusOK, rsp)
|
|
}
|
|
res.CrashLogs = c.PostForm("crash_log_list")
|
|
res.ActivityNameInfo = c.PostForm("activity_name_info")
|
|
res.DeviceName = c.PostForm("device_name")
|
|
res.Logs = c.PostForm("log_list")
|
|
|
|
db, err := dbsql.GetConn(dbsql.DSN)
|
|
if err != nil {
|
|
rsp.Error(err.Error())
|
|
c.JSON(http.StatusOK, rsp)
|
|
return
|
|
}
|
|
defer dbsql.Close(db)
|
|
db.Create(&res)
|
|
if res.ID < 1 {
|
|
rsp.Error("保存Monkey任务失败")
|
|
c.JSON(http.StatusOK, rsp)
|
|
return
|
|
}
|
|
|
|
rsp.Success()
|
|
rsp.Data = res
|
|
c.JSON(http.StatusOK, rsp)
|
|
}
|
|
|
|
// @Tags Monkey相关 /api/monkey/v1/
|
|
// @Summary 获取Monkey结果
|
|
// @Description 通过任务id获取Monkey结果
|
|
// @accept x-www-form-urlencoded
|
|
// @Param task_id query int true "任务id"
|
|
// @Success 200 {object} models.Response "返回任务结果"
|
|
// @Router /api/monkey/v1/task/result [get]
|
|
func GetMonkeyResult(c *gin.Context) {
|
|
rsp := controllers.NewResponse()
|
|
|
|
var list []models.MonkeyResult
|
|
db, err := dbsql.GetConn(dbsql.DSN)
|
|
if err != nil {
|
|
rsp.Error(err.Error())
|
|
c.JSON(http.StatusOK, rsp)
|
|
return
|
|
}
|
|
defer dbsql.Close(db)
|
|
db.Where("task_id = ?", c.Query("task_id")).Find(&list)
|
|
for i, _ := range list {
|
|
var strs []string
|
|
json.Unmarshal([]byte(list[i].CrashLogs), &strs)
|
|
if len(strs) > 0 {
|
|
list[i].CrashLogList = strs
|
|
}
|
|
json.Unmarshal([]byte(list[i].ActivityNameInfo), &strs)
|
|
if len(strs) > 0 {
|
|
list[i].ActivityList = strs
|
|
}
|
|
json.Unmarshal([]byte(list[i].Logs), &strs)
|
|
if len(strs) > 0 {
|
|
list[i].LogList = strs
|
|
}
|
|
}
|
|
|
|
rsp.Success()
|
|
rsp.Data = list
|
|
c.JSON(http.StatusOK, rsp)
|
|
}
|