2023-01-06 10:09:23 +08:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2023-01-06 19:15:52 +08:00
|
|
|
"git.hpds.cc/Component/logging"
|
2023-01-06 10:09:23 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"hpds-iot-web/model"
|
|
|
|
"time"
|
|
|
|
"xorm.io/xorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HandlerService struct {
|
|
|
|
Engine *xorm.Engine
|
2023-01-06 19:15:52 +08:00
|
|
|
Logger *logging.Logger
|
2023-01-06 10:09:23 +08:00
|
|
|
}
|
|
|
|
|
2023-01-06 19:15:52 +08:00
|
|
|
func NewHandlerService(engine *xorm.Engine, logger *logging.Logger) *HandlerService {
|
2023-01-06 10:09:23 +08:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|