operationHisService.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package service
  2. import (
  3. "fmt"
  4. "iot_manager_service/app/device/dao"
  5. "iot_manager_service/app/device/model"
  6. "iot_manager_service/app/system/service"
  7. "iot_manager_service/util"
  8. "strconv"
  9. "time"
  10. )
  11. // 操作记录服务
  12. var OperationHisService = new(operationHisService)
  13. type operationHisService struct{}
  14. func (s *operationHisService) Save(userId int64, tenantId int, handleType, handleModuleType int,
  15. handleContent string) {
  16. operation := dao.OperationHis{
  17. OperationType: handleType,
  18. ModuleType: handleModuleType,
  19. HandleContent: handleContent,
  20. HandleUserId: userId,
  21. HandleTime: time.Now(),
  22. TenantId: tenantId,
  23. }
  24. err := operation.Create()
  25. if err != nil {
  26. fmt.Printf("Operation save err =%v \n", err)
  27. }
  28. }
  29. func (s *operationHisService) List(tenantId int, handleContent, operationType, moduleType string, current,
  30. size int) ([]model.OperationHisDetail, *util.Errors) {
  31. his := dao.OperationHis{
  32. HandleContent: handleContent,
  33. }
  34. if operationType != "" {
  35. operation, err := strconv.Atoi(operationType)
  36. if err != nil {
  37. return nil, util.FailResponse(err.Error(), nil)
  38. }
  39. his.OperationType = operation
  40. }
  41. if moduleType != "" {
  42. module, err := strconv.Atoi(moduleType)
  43. if err != nil {
  44. return nil, util.FailResponse(err.Error(), nil)
  45. }
  46. his.ModuleType = module
  47. }
  48. offset := (current - 1) * size
  49. limit := size
  50. list, err := his.GetHistories(offset, limit)
  51. if err != nil {
  52. return nil, util.FailResponse(err.Error(), nil)
  53. }
  54. var details []model.OperationHisDetail
  55. for _, his := range list {
  56. detail := model.OperationHisDetail{
  57. OperationHis: his,
  58. }
  59. detail.HandleName = service.UserService.GetUserName(tenantId, his.HandleUserId)
  60. detail.OperationTypeName = service.DictService.GetControlType(tenantId, his.OperationType)
  61. detail.ModuleTypeName = service.DictService.GetModuleName(tenantId, his.ModuleType)
  62. details = append(details, detail)
  63. }
  64. return details, nil
  65. }