multiscreenService.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package service
  2. import (
  3. deviceDao "iot_manager_service/app/device/dao"
  4. "iot_manager_service/app/middleware"
  5. "iot_manager_service/app/security/model"
  6. "iot_manager_service/app/system/dao"
  7. "log"
  8. "strconv"
  9. "strings"
  10. )
  11. var MultiscreenService = new(multiscreenService)
  12. type multiscreenService struct{}
  13. func (s multiscreenService) List(claims *middleware.Claims) ([]model.Placement, error) {
  14. securitySixScreen := s.getSlot(claims.UserId)
  15. idsSplit := strings.Split(securitySixScreen, ",")
  16. var ids []string
  17. for _, id := range idsSplit {
  18. idInt, _ := strconv.Atoi(id)
  19. if idInt < 1 {
  20. continue
  21. }
  22. ids = append(ids, strconv.Itoa(idInt))
  23. }
  24. //devices := deviceDao.CameraDevice{}.GetDevicesByIds(strings.Join(ids, ","))
  25. //fmt.Printf("devices = %v", devices)
  26. var list []model.Placement
  27. for i, id := range idsSplit {
  28. idInt, _ := strconv.Atoi(id)
  29. placement := model.Placement{}
  30. placement.ID = idInt
  31. placement.Slot = i + 1
  32. if idInt != -1 {
  33. device := deviceDao.CameraDevice{ID: idInt}
  34. err := device.GetDevice()
  35. if err != nil {
  36. continue
  37. }
  38. placement.Name = device.DeviceName
  39. placement.Sn = device.DeviceSN
  40. placement.Url = device.MonitorAddress
  41. }
  42. list = append(list, placement)
  43. }
  44. //fmt.Printf("list = %v", list)
  45. return list, nil
  46. }
  47. // Save 保存 多屏监控位置
  48. func (s multiscreenService) Save(claims *middleware.Claims, site, id int) error {
  49. securitySixScreen := s.getSlot(claims.UserId)
  50. idsSplit := strings.Split(securitySixScreen, ",")
  51. ids := ""
  52. for i := range idsSplit {
  53. if i == (site - 1) {
  54. idsSplit[i] = strconv.Itoa(id)
  55. }
  56. ids += idsSplit[i]
  57. if i < (len(idsSplit) - 1) {
  58. ids += ","
  59. }
  60. }
  61. user := &dao.User{ID: claims.UserId}
  62. user.SecuritySixScreen = ids
  63. err := user.Update()
  64. if err != nil {
  65. return err
  66. }
  67. return nil
  68. }
  69. func (s multiscreenService) getSlot(userId int64) string {
  70. user := &dao.User{ID: userId}
  71. err := user.GetUser()
  72. if err != nil {
  73. log.Fatalln(err)
  74. panic("用户取失败了")
  75. }
  76. ids := ""
  77. if user.SecuritySixScreen == "" {
  78. ids = "-1,-1,-1,-1,-1,-1"
  79. } else {
  80. ids = user.SecuritySixScreen
  81. }
  82. return ids
  83. }