platformAlarmService.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package service
  2. import (
  3. "iot_manager_service/app/warn/dao"
  4. edgeService "iot_manager_service/app/warn/edge_service"
  5. "iot_manager_service/app/warn/model"
  6. "iot_manager_service/util/common"
  7. "strconv"
  8. )
  9. var PlatformAlarmService = new(platformAlarmService)
  10. type platformAlarmService struct{}
  11. func (s platformAlarmService) GetList(tenantId int, filter model.RequestPlatFormAlartFilter) ([]model.PlatFormAlartData, int64, error) {
  12. var list []model.PlatFormAlartData
  13. dao := dao.PlatformAlarm{
  14. TenantId: strconv.Itoa(tenantId),
  15. }
  16. levelArr := make(map[int]string)
  17. levelArr[1] = "紧急"
  18. levelArr[2] = "严重"
  19. levelArr[3] = "普通"
  20. gets, i, err := dao.Gets(filter)
  21. for _, alart := range gets {
  22. list = append(list, model.PlatFormAlartData{
  23. ID: alart.ID,
  24. ArmDeviceName: alart.ArmDeviceName,
  25. ArmDeviceSn: alart.ArmDeviceSn,
  26. ArmDeviceTypeName: alart.ArmDeviceTypeName,
  27. ArmContent: alart.ArmContent,
  28. LampPoleName: alart.LampPoleName,
  29. LampPoleSn: alart.LampPoleSn,
  30. ArmTime: alart.ArmTime.String(),
  31. ArmEndTime: alart.ArmEndTime.String(),
  32. ArmLevel: alart.ArmLevel,
  33. ArmLevelName: levelArr[alart.ArmLevel],
  34. LampPoleLocation: alart.LampPoleLocation,
  35. })
  36. }
  37. return list, i, err
  38. }
  39. func (s platformAlarmService) Refresh(tenantId int) error {
  40. viewDao := dao.ViewsAllCode{TenantId: tenantId}
  41. alls, err := viewDao.GetAlls()
  42. if err != nil {
  43. return err
  44. }
  45. newAllCode := make(map[string]dao.ViewsAllCode)
  46. for _, viewsAllCode := range alls {
  47. if viewsAllCode.Sn != "" {
  48. newAllCode[viewsAllCode.Sn] = viewsAllCode
  49. }
  50. }
  51. //fmt.Printf("newAllCode = %v", newAllCode)
  52. edgeService := edgeService.RecordAlarmRecord{}
  53. maxId, maxUpDateTime := dao.PlatformAlarm{}.GetMaxIdAndUpDateTime()
  54. //fmt.Printf("maxId = %v", maxId)
  55. list, err := edgeService.SyncAlartRecord(maxId, maxUpDateTime)
  56. if err != nil {
  57. return err
  58. }
  59. alarms := []dao.PlatformAlarm{}
  60. for _, data := range list {
  61. viewInfo := newAllCode[data.Code]
  62. parse := common.TimeStringToGoTime(data.Tend)
  63. ArmTime := common.TimeStringToGoTime(data.Updatedat)
  64. alarms = append(alarms, dao.PlatformAlarm{
  65. ID: data.ID,
  66. TenantId: strconv.Itoa(tenantId),
  67. ArmDeviceType: viewInfo.DeviceType,
  68. ArmDeviceTypeName: viewInfo.DeviceTypeName,
  69. ArmDeviceId: viewInfo.DeviceId,
  70. ArmDeviceName: viewInfo.DeviceName,
  71. ArmDeviceSn: data.Code,
  72. LampPoleId: viewInfo.LampPoleId,
  73. LampPoleName: viewInfo.LampPoleName,
  74. LampPoleSn: viewInfo.LampPoleSn,
  75. LampPoleLocation: viewInfo.Address,
  76. ArmSource: 1,
  77. ArmEndTime: common.Time(parse),
  78. ArmTime: common.Time(ArmTime),
  79. ArmHandle: 1,
  80. ArmLevel: data.Level,
  81. ArmContent: data.Content,
  82. Status: 2,
  83. NoticeRecordId: 2222,
  84. Cid: uint(data.Cid),
  85. Cname: data.Cname,
  86. Sid: data.Sid,
  87. Threshold: float64(data.Threshold),
  88. })
  89. }
  90. err = dao.PlatformAlarm{}.BatchCreate(alarms)
  91. return err
  92. }