|
|
@@ -4,6 +4,7 @@ import (
|
|
|
"fmt"
|
|
|
"iot_manager_service/app/device/dao"
|
|
|
"iot_manager_service/app/device/model"
|
|
|
+ "iot_manager_service/app/system/service"
|
|
|
"iot_manager_service/util"
|
|
|
"time"
|
|
|
)
|
|
|
@@ -20,7 +21,7 @@ func (s *captureUintService) CaptureSubmit(userId int64, tenantId int, req *mode
|
|
|
device.UpdateTime = time.Now()
|
|
|
if gateway, err := GatewayService.GetOne(device.GatewayId); err == nil {
|
|
|
device.GatewayName = gateway.GatewayName
|
|
|
- device.GatewaySN = gateway.GatewaySN
|
|
|
+ device.GatewaySn = gateway.GatewaySn
|
|
|
}
|
|
|
|
|
|
if device.ID == 0 {
|
|
|
@@ -36,6 +37,8 @@ func (s *captureUintService) CaptureSubmit(userId int64, tenantId int, req *mode
|
|
|
fmt.Printf("Create err = %s \n", err.Error())
|
|
|
return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
+ service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
|
|
|
+ util.DeviceTypeCaptureUnit, util.GetDeviceObject(device.ID, device.GatewayName), util.OperationSuccess)
|
|
|
return util.SuccessResponse(util.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
@@ -44,7 +47,8 @@ func (s *captureUintService) CaptureSubmit(userId int64, tenantId int, req *mode
|
|
|
return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
- //todo operation record
|
|
|
+ service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
|
|
|
+ util.DeviceTypeCaptureUnit, util.GetDeviceObject(device.ID, device.GatewayName), util.OperationSuccess)
|
|
|
return util.SuccessResponse(util.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
@@ -58,9 +62,8 @@ func (s *captureUintService) GetCapture(id int) (*model.CaptureDetail, *util.Err
|
|
|
return nil, util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
detail := &model.CaptureDetail{CaptureUnit: *device}
|
|
|
- //todo 获取实时在线最新数据
|
|
|
- // detail.EndLineTime = *
|
|
|
- // detail.NetworkState = *
|
|
|
+ detail.EndLineTime = ""
|
|
|
+ detail.NetworkState = util.GetDeviceState(device.CaptureSn)
|
|
|
|
|
|
return detail, nil
|
|
|
}
|
|
|
@@ -70,7 +73,7 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
|
|
|
device := dao.CaptureUnit{}
|
|
|
|
|
|
if searchValue != "" {
|
|
|
- device.CaptureSN = searchValue
|
|
|
+ device.CaptureSn = searchValue
|
|
|
}
|
|
|
|
|
|
offset := (current - 1) * size
|
|
|
@@ -83,11 +86,9 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
|
|
|
|
|
|
for _, d := range devices {
|
|
|
details = append(details, model.CaptureDetail{
|
|
|
- CaptureUnit: d,
|
|
|
- //todo 获取实时在线最新数据
|
|
|
- // detail.EndLineTime = *
|
|
|
- // detail.NetworkState = *
|
|
|
-
|
|
|
+ CaptureUnit: d,
|
|
|
+ EndLineTime: "",
|
|
|
+ NetworkState: util.GetDeviceState(device.CaptureSn),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -104,7 +105,7 @@ func (s *captureUintService) CaptureGetList(tenantId int) ([]*dao.CaptureUnit, *
|
|
|
return nil, util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
for _, d := range devices {
|
|
|
- d.CaptureName = d.CaptureName + "(" + d.CaptureSN + ")"
|
|
|
+ d.CaptureName = d.CaptureName + "(" + d.CaptureSn + ")"
|
|
|
}
|
|
|
return devices, nil
|
|
|
}
|
|
|
@@ -141,6 +142,8 @@ func (s *captureUintService) PointSubmit(userId int64, tenantId int, req *dao.Ch
|
|
|
fmt.Printf("Create err = %s \n", err.Error())
|
|
|
return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
+ service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
|
|
|
+ util.DeviceTypePoint, util.GetDeviceObject(device.ID, device.PointName), util.OperationSuccess)
|
|
|
return util.SuccessResponse(util.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
@@ -149,7 +152,8 @@ func (s *captureUintService) PointSubmit(userId int64, tenantId int, req *dao.Ch
|
|
|
return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
- //todo operation record
|
|
|
+ service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
|
|
|
+ util.DeviceTypePoint, util.GetDeviceObject(device.ID, device.PointName), util.OperationSuccess)
|
|
|
return util.SuccessResponse(util.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
@@ -183,7 +187,7 @@ func (s *captureUintService) PointGetList(tenantId int) ([]*dao.CheckPoint, *uti
|
|
|
return devices, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) RemoveCapture(userId int64, id int) *util.Errors {
|
|
|
+func (s *captureUintService) RemoveCapture(userId int64, tenantId int, id int) *util.Errors {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CaptureUnit{
|
|
|
ID: id,
|
|
|
@@ -191,16 +195,16 @@ func (s *captureUintService) RemoveCapture(userId int64, id int) *util.Errors {
|
|
|
UpdateUser: userId,
|
|
|
UpdateTime: time.Now(),
|
|
|
}
|
|
|
-
|
|
|
- //todo operation record
|
|
|
err := device.Delete()
|
|
|
if err != nil {
|
|
|
return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
+ service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
|
|
|
+ util.DeviceTypeCaptureUnit, util.GetDeviceObject(device.ID, device.CaptureName), util.OperationSuccess)
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) RemovePoint(userId int64, id int) *util.Errors {
|
|
|
+func (s *captureUintService) RemovePoint(userId int64, tenantId int, id int) *util.Errors {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CheckPoint{
|
|
|
ID: id,
|
|
|
@@ -208,11 +212,27 @@ func (s *captureUintService) RemovePoint(userId int64, id int) *util.Errors {
|
|
|
UpdateUser: userId,
|
|
|
UpdateTime: time.Now(),
|
|
|
}
|
|
|
-
|
|
|
- //todo operation record
|
|
|
err := device.Delete()
|
|
|
if err != nil {
|
|
|
return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
+ service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
|
|
|
+ util.DeviceTypePoint, util.GetDeviceObject(device.ID, device.PointName), util.OperationSuccess)
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func (s *captureUintService) GetCaptureByGateway(id int) []dao.CaptureUnit {
|
|
|
+ // 创建查询实例
|
|
|
+ device := &dao.CaptureUnit{
|
|
|
+ GatewayId: id,
|
|
|
+ }
|
|
|
+ return device.GetDevicesByGateway()
|
|
|
+}
|
|
|
+
|
|
|
+func (s *captureUintService) GetByLampPole(id int) []dao.CaptureUnit {
|
|
|
+ // 创建查询实例
|
|
|
+ device := &dao.CaptureUnit{
|
|
|
+ LampPoleId: id,
|
|
|
+ }
|
|
|
+ return device.GetDevicesByLampPole()
|
|
|
+}
|