package service import ( "iot_manager_service/app/warn/dao" edgeService "iot_manager_service/app/warn/edge_service" "iot_manager_service/app/warn/model" "iot_manager_service/util/common" "strconv" "time" ) var PlatformAlarmService = new(platformAlarmService) type platformAlarmService struct{} func (s platformAlarmService) GetList(tenantId int, filter model.RequestPlatFormAlartFilter) ([]model.PlatFormAlartData, int64, error) { var list []model.PlatFormAlartData dao := dao.PlatformAlarm{ TenantId: strconv.Itoa(tenantId), } levelArr := make(map[int]string) levelArr[1] = "紧急" levelArr[2] = "严重" levelArr[3] = "普通" gets, i, err := dao.Gets(filter) for _, alart := range gets { list = append(list, model.PlatFormAlartData{ ID: alart.ID, ArmDeviceName: alart.ArmDeviceName, ArmDeviceSn: alart.ArmDeviceSn, ArmDeviceTypeName: alart.ArmDeviceTypeName, ArmContent: alart.ArmContent, LampPoleName: alart.LampPoleName, LampPoleSn: alart.LampPoleSn, ArmTime: alart.ArmTime.String(), ArmEndTime: alart.ArmEndTime.String(), ArmLevel: alart.ArmLevel, ArmLevelName: levelArr[alart.ArmLevel], LampPoleLocation: alart.LampPoleLocation, ArmHandleTime: alart.ArmHandleTime.String(), OpsStatus: alart.ArmHandle, }) } return list, i, err } func (s platformAlarmService) Refresh(tenantId int) error { viewDao := dao.ViewsAllCode{TenantId: tenantId} alls, err := viewDao.GetAlls() if err != nil { return err } newAllCode := make(map[string]dao.ViewsAllCode) for _, viewsAllCode := range alls { if viewsAllCode.Sn != "" { newAllCode[viewsAllCode.Sn] = viewsAllCode } } //fmt.Printf("newAllCode = %v", newAllCode) edgeService := edgeService.RecordAlarmRecord{} maxId, maxUpDateTime := dao.PlatformAlarm{}.GetMaxIdAndUpDateTime() //fmt.Printf("maxId = %v", maxId) list, err := edgeService.SyncAlartRecord(maxId, maxUpDateTime) if err != nil { return err } alarms := []dao.PlatformAlarm{} for _, data := range list { viewInfo := newAllCode[data.Code] parse := common.TimeStringToGoTime(data.Tend) ArmTime := common.TimeStringToGoTime(data.Updatedat) alarms = append(alarms, dao.PlatformAlarm{ ID: data.ID, TenantId: strconv.Itoa(tenantId), ArmDeviceType: viewInfo.DeviceType, ArmDeviceTypeName: viewInfo.DeviceTypeName, ArmDeviceId: viewInfo.DeviceId, ArmDeviceName: viewInfo.DeviceName, ArmDeviceSn: data.Code, LampPoleId: viewInfo.LampPoleId, LampPoleName: viewInfo.LampPoleName, LampPoleSn: viewInfo.LampPoleSn, LampPoleLocation: viewInfo.Address, ArmSource: 1, ArmEndTime: common.Time(parse), ArmTime: common.Time(ArmTime), ArmHandle: 1, ArmLevel: data.Level, ArmContent: data.Content, Status: 2, NoticeRecordId: 2222, Cid: uint(data.Cid), Cname: data.Cname, Sid: data.Sid, Threshold: float64(data.Threshold), }) } err = dao.PlatformAlarm{}.BatchCreate(alarms) return err } func (s platformAlarmService) HannleAlart(tenant_id int, id int, armHandle int, remark string) error { dao := dao.PlatformAlarm{ ID: id, ArmHandle: armHandle, ArmHanleRemark: remark, ArmHandleTime: common.Time(time.Now()), } return dao.Update() }