hpds_jkw_web/internal/handler/index.go

46 lines
1.0 KiB
Go
Raw Normal View History

2023-01-06 10:09:23 +08:00
package handler
import (
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"hpds-iot-web/model"
"time"
"xorm.io/xorm"
)
type HandlerService struct {
Engine *xorm.Engine
Logger *zap.Logger
}
func NewHandlerService(engine *xorm.Engine, logger *zap.Logger) *HandlerService {
return &HandlerService{
Engine: engine,
Logger: logger,
}
}
func (s HandlerService) Health(c *gin.Context) (data interface{}, err error) {
return time.Now().Unix(), nil
}
func (s HandlerService) SaveLog(action, category, targetId, oldValue, newValue, operatorId, operatorAddr, operatorDevice string) {
operationLog := &model.OperationLog{
Action: action,
Category: category,
TargetId: targetId,
OldValue: oldValue,
NewValue: newValue,
Operator: operatorId,
OperateAddr: operatorAddr,
OperateDevice: operatorDevice,
}
_, err := s.Engine.Insert(operationLog)
if err != nil {
s.Logger.With(zap.Namespace("DAO"),
zap.String("method", "SaveLog"),
zap.Any("operationLog", operationLog),
).Error(err.Error())
}
}