99 lines
2.0 KiB
Go
99 lines
2.0 KiB
Go
package system
|
|
|
|
import (
|
|
"f5"
|
|
"main/constant"
|
|
"main/model/system"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AuditApi struct {
|
|
}
|
|
|
|
func (this *AuditApi) AuditList(c *gin.Context) {
|
|
var auditList []system.Audit
|
|
err := f5.GetApp().GetOrmDb(constant.CONF_DB).Find(&auditList).Error
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 0,
|
|
"message": "success",
|
|
"data": auditList,
|
|
})
|
|
}
|
|
|
|
func (this *AuditApi) AddAudit(c *gin.Context) {
|
|
audit := system.Audit{}
|
|
if err := c.ShouldBindJSON(&audit); err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
var count int64
|
|
f5.GetApp().GetOrmDb(constant.CONF_DB).Table(audit.TableName()).Where("model = ?", audit.Model).Count(&count)
|
|
if count > 0 {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": "无法再插入",
|
|
})
|
|
return
|
|
}
|
|
|
|
err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(&audit).Error
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 0,
|
|
"message": "success",
|
|
})
|
|
}
|
|
|
|
func (this *AuditApi) UpdateAudit(c *gin.Context) {
|
|
idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64)
|
|
audit := system.Audit{}
|
|
var count int64
|
|
f5.GetApp().GetOrmDb(constant.CONF_DB).Table(audit.TableName()).Where("idx = ?", idx).Count(&count)
|
|
if count < 1 {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": "不存在的数据",
|
|
})
|
|
return
|
|
}
|
|
|
|
if err := c.ShouldBindJSON(&audit); err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
err := f5.GetApp().GetOrmDb(constant.CONF_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&audit).Error
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 0,
|
|
"message": "success",
|
|
})
|
|
}
|