platformAlarmService.go 3.4 KB

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