package service import ( "fmt" "iot_manager_service/app/device/dao" "iot_manager_service/app/device/model" "iot_manager_service/util" "strconv" "time" ) // 操作记录服务 var OperationHisService = new(operationHisService) type operationHisService struct{} func (s *operationHisService) Save(userId int64, tenantId int, handleType, handleModuleType int, handleContent string) { operation := dao.OperationHis{ OperationType: handleType, ModuleType: handleModuleType, HandleContent: handleContent, HandleUserId: userId, HandleTime: time.Now(), TenantId: tenantId, } err := operation.Create() if err != nil { fmt.Printf("Operation save err =%v \n", err) } } func (s *operationHisService) List(tenantId int, handleContent, operationType, moduleType string, current, size int) ([]model.OperationHisDetail, *util.Errors) { his := dao.OperationHis{ HandleContent: handleContent, } if operationType != "" { operation, err := strconv.Atoi(operationType) if err != nil { return nil, util.FailResponse(err.Error(), nil) } his.OperationType = operation } if moduleType != "" { module, err := strconv.Atoi(moduleType) if err != nil { return nil, util.FailResponse(err.Error(), nil) } his.ModuleType = module } offset := (current - 1) * size limit := size list, err := his.GetHistories(offset, limit) if err != nil { return nil, util.FailResponse(err.Error(), nil) } var details []model.OperationHisDetail for _, his := range list { detail := model.OperationHisDetail{ OperationHis: his, } detail.HandleName = util.GetUserName(tenantId, his.HandleUserId) detail.OperationTypeName = util.GetControlType(tenantId, his.OperationType) detail.ModuleTypeName = util.GetModuleName(tenantId, his.ModuleType) details = append(details, detail) } return details, nil }