operationHisService.go 1.9 KB

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