133 lines
3.7 KiB
Go
133 lines
3.7 KiB
Go
|
package api
|
||
|
|
||
|
import (
|
||
|
"ifms/internal/mods/autocontrol/biz"
|
||
|
"ifms/internal/mods/autocontrol/schema"
|
||
|
"ifms/pkg/util"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
// 设备运行日志表
|
||
|
type DeviceRunLog struct {
|
||
|
DeviceRunLogBIZ *biz.DeviceRunLog
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceRunLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Query device run log list
|
||
|
// @Param current query int true "pagination index" default(1)
|
||
|
// @Param pageSize query int true "pagination size" default(10)
|
||
|
// @Success 200 {object} util.ResponseResult{data=[]schema.DeviceRunLog}
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-run-logs [get]
|
||
|
func (a *DeviceRunLog) Query(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
var params schema.DeviceRunLogQueryParam
|
||
|
if err := util.ParseQuery(c, ¶ms); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
result, err := a.DeviceRunLogBIZ.Query(ctx, params)
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResPage(c, result.Data, result.PageResult)
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceRunLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Get device run log record by ID
|
||
|
// @Param id path string true "unique id"
|
||
|
// @Success 200 {object} util.ResponseResult{data=schema.DeviceRunLog}
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-run-logs/{id} [get]
|
||
|
func (a *DeviceRunLog) Get(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
item, err := a.DeviceRunLogBIZ.Get(ctx, c.Param("id"))
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResSuccess(c, item)
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceRunLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Create device run log record
|
||
|
// @Param body body schema.DeviceRunLogForm true "Request body"
|
||
|
// @Success 200 {object} util.ResponseResult{data=schema.DeviceRunLog}
|
||
|
// @Failure 400 {object} util.ResponseResult
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-run-logs [post]
|
||
|
func (a *DeviceRunLog) Create(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
item := new(schema.DeviceRunLogForm)
|
||
|
if err := util.ParseJSON(c, item); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
} else if err := item.Validate(); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
result, err := a.DeviceRunLogBIZ.Create(ctx, item)
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResSuccess(c, result)
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceRunLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Update device run log record by ID
|
||
|
// @Param id path string true "unique id"
|
||
|
// @Param body body schema.DeviceRunLogForm true "Request body"
|
||
|
// @Success 200 {object} util.ResponseResult
|
||
|
// @Failure 400 {object} util.ResponseResult
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-run-logs/{id} [put]
|
||
|
func (a *DeviceRunLog) Update(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
item := new(schema.DeviceRunLogForm)
|
||
|
if err := util.ParseJSON(c, item); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
} else if err := item.Validate(); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := a.DeviceRunLogBIZ.Update(ctx, c.Param("id"), item)
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResOK(c)
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceRunLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Delete device run log record by ID
|
||
|
// @Param id path string true "unique id"
|
||
|
// @Success 200 {object} util.ResponseResult
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-run-logs/{id} [delete]
|
||
|
func (a *DeviceRunLog) Delete(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
err := a.DeviceRunLogBIZ.Delete(ctx, c.Param("id"))
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResOK(c)
|
||
|
}
|