|
|
@@ -5,7 +5,8 @@ import (
|
|
|
"iot_manager_service/app/device/dao"
|
|
|
"iot_manager_service/app/device/model"
|
|
|
"iot_manager_service/app/system/service"
|
|
|
- "iot_manager_service/util"
|
|
|
+ "iot_manager_service/util/cache"
|
|
|
+ "iot_manager_service/util/common"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
@@ -14,7 +15,7 @@ var CaptureUintService = new(captureUintService)
|
|
|
|
|
|
type captureUintService struct{}
|
|
|
|
|
|
-func (s *captureUintService) CaptureSubmit(userId int64, tenantId int, req *model.CaptureDetail) *util.Errors {
|
|
|
+func (s *captureUintService) CaptureSubmit(userId int64, tenantId int, req *model.CaptureDetail) *common.Errors {
|
|
|
device := req.CaptureUnit
|
|
|
device.TenantId = tenantId
|
|
|
device.UpdateUser = userId
|
|
|
@@ -30,46 +31,46 @@ func (s *captureUintService) CaptureSubmit(userId int64, tenantId int, req *mode
|
|
|
|
|
|
if device.IsExistedBySN() {
|
|
|
fmt.Printf("Create IsExistedBySN \n")
|
|
|
- return util.ParamsInvalidResponse(model.RepeatedPrompts, nil)
|
|
|
+ return common.ParamsInvalidResponse(model.RepeatedPrompts, nil)
|
|
|
}
|
|
|
fmt.Printf("device = %+v \n", device)
|
|
|
if err := device.Create(); err != nil {
|
|
|
fmt.Printf("Create err = %s \n", err.Error())
|
|
|
- return util.FailResponse(err.Error(), nil)
|
|
|
+ return common.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)
|
|
|
+ service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
|
|
|
+ common.DeviceTypeCaptureUnit, common.GetDeviceObject(device.ID, device.GatewayName), common.OperationSuccess)
|
|
|
+ return common.SuccessResponse(common.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
if err := device.Update(); err != nil {
|
|
|
fmt.Printf("Update err = %s \n", err.Error())
|
|
|
- return util.FailResponse(err.Error(), nil)
|
|
|
+ return common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
- 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)
|
|
|
+ service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
|
|
|
+ common.DeviceTypeCaptureUnit, common.GetDeviceObject(device.ID, device.GatewayName), common.OperationSuccess)
|
|
|
+ return common.SuccessResponse(common.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) GetCapture(id int) (*model.CaptureDetail, *util.Errors) {
|
|
|
+func (s *captureUintService) GetCapture(id int) (*model.CaptureDetail, *common.Errors) {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CaptureUnit{
|
|
|
ID: id,
|
|
|
}
|
|
|
err := device.GetDevice()
|
|
|
if err != nil {
|
|
|
- return nil, util.FailResponse(err.Error(), nil)
|
|
|
+ return nil, common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
detail := &model.CaptureDetail{CaptureUnit: *device}
|
|
|
- endTime, state := util.GetDeviceState(device.CaptureSn)
|
|
|
+ endTime, state := cache.GetDeviceState(device.CaptureSn)
|
|
|
detail.NetworkState = state
|
|
|
detail.EndLineTime = endTime
|
|
|
|
|
|
return detail, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) CaptureList(searchValue string, current, size int) ([]model.CaptureDetail, *util.Errors) {
|
|
|
+func (s *captureUintService) CaptureList(searchValue string, current, size int) ([]model.CaptureDetail, *common.Errors) {
|
|
|
var details []model.CaptureDetail
|
|
|
device := dao.CaptureUnit{}
|
|
|
|
|
|
@@ -82,11 +83,11 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
|
|
|
devices, err := device.GetDevices(offset, limit)
|
|
|
|
|
|
if err != nil {
|
|
|
- return nil, util.FailResponse(err.Error(), nil)
|
|
|
+ return nil, common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
for _, d := range devices {
|
|
|
- endTime, state := util.GetDeviceState(d.CaptureSn)
|
|
|
+ endTime, state := cache.GetDeviceState(d.CaptureSn)
|
|
|
details = append(details, model.CaptureDetail{
|
|
|
CaptureUnit: d,
|
|
|
EndLineTime: endTime,
|
|
|
@@ -97,14 +98,14 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
|
|
|
return details, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) CaptureGetList(tenantId int) ([]*dao.CaptureUnit, *util.Errors) {
|
|
|
+func (s *captureUintService) CaptureGetList(tenantId int) ([]*dao.CaptureUnit, *common.Errors) {
|
|
|
device := &dao.CaptureUnit{
|
|
|
TenantId: tenantId,
|
|
|
IsDeleted: 0,
|
|
|
}
|
|
|
devices, err := device.GetAllDevices()
|
|
|
if err != nil {
|
|
|
- return nil, util.FailResponse(err.Error(), nil)
|
|
|
+ return nil, common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
for _, d := range devices {
|
|
|
d.CaptureName = d.CaptureName + "(" + d.CaptureSn + ")"
|
|
|
@@ -112,20 +113,20 @@ func (s *captureUintService) CaptureGetList(tenantId int) ([]*dao.CaptureUnit, *
|
|
|
return devices, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) GetPoint(id int) (*dao.CheckPoint, *util.Errors) {
|
|
|
+func (s *captureUintService) GetPoint(id int) (*dao.CheckPoint, *common.Errors) {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CheckPoint{
|
|
|
ID: id,
|
|
|
}
|
|
|
err := device.GetDevice()
|
|
|
if err != nil {
|
|
|
- return nil, util.FailResponse(err.Error(), nil)
|
|
|
+ return nil, common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
return device, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) PointSubmit(userId int64, tenantId int, req *dao.CheckPoint) *util.Errors {
|
|
|
+func (s *captureUintService) PointSubmit(userId int64, tenantId int, req *dao.CheckPoint) *common.Errors {
|
|
|
device := req
|
|
|
device.TenantId = tenantId
|
|
|
device.UpdateUser = userId
|
|
|
@@ -137,29 +138,29 @@ func (s *captureUintService) PointSubmit(userId int64, tenantId int, req *dao.Ch
|
|
|
|
|
|
if device.IsExistedBySN() {
|
|
|
fmt.Printf("Create IsExistedBySN \n")
|
|
|
- return util.ParamsInvalidResponse(model.RepeatedPrompts, nil)
|
|
|
+ return common.ParamsInvalidResponse(model.RepeatedPrompts, nil)
|
|
|
}
|
|
|
fmt.Printf("device = %+v \n", device)
|
|
|
if err := device.Create(); err != nil {
|
|
|
fmt.Printf("Create err = %s \n", err.Error())
|
|
|
- return util.FailResponse(err.Error(), nil)
|
|
|
+ return common.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)
|
|
|
+ service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
|
|
|
+ common.DeviceTypePoint, common.GetDeviceObject(device.ID, device.PointName), common.OperationSuccess)
|
|
|
+ return common.SuccessResponse(common.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
if err := device.Update(); err != nil {
|
|
|
fmt.Printf("Update err = %s \n", err.Error())
|
|
|
- return util.FailResponse(err.Error(), nil)
|
|
|
+ return common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
- 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)
|
|
|
+ service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
|
|
|
+ common.DeviceTypePoint, common.GetDeviceObject(device.ID, device.PointName), common.OperationSuccess)
|
|
|
+ return common.SuccessResponse(common.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) PointList(searchValue string, current, size int) ([]dao.CheckPoint, *util.Errors) {
|
|
|
+func (s *captureUintService) PointList(searchValue string, current, size int) ([]dao.CheckPoint, *common.Errors) {
|
|
|
device := dao.CheckPoint{}
|
|
|
if searchValue != "" {
|
|
|
device.PointSN = searchValue
|
|
|
@@ -169,19 +170,19 @@ func (s *captureUintService) PointList(searchValue string, current, size int) ([
|
|
|
limit := size
|
|
|
devices, err := device.GetDevices(offset, limit)
|
|
|
if err != nil {
|
|
|
- return nil, util.FailResponse(err.Error(), nil)
|
|
|
+ return nil, common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
return devices, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) PointGetList(tenantId int) ([]*dao.CheckPoint, *util.Errors) {
|
|
|
+func (s *captureUintService) PointGetList(tenantId int) ([]*dao.CheckPoint, *common.Errors) {
|
|
|
device := &dao.CheckPoint{
|
|
|
TenantId: tenantId,
|
|
|
IsDeleted: 0,
|
|
|
}
|
|
|
devices, err := device.GetAllDevices()
|
|
|
if err != nil {
|
|
|
- return nil, util.FailResponse(err.Error(), nil)
|
|
|
+ return nil, common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
for _, d := range devices {
|
|
|
d.PointName = d.PointName + "(" + d.PointSN + ")"
|
|
|
@@ -189,7 +190,7 @@ func (s *captureUintService) PointGetList(tenantId int) ([]*dao.CheckPoint, *uti
|
|
|
return devices, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) RemoveCapture(userId int64, tenantId int, id int) *util.Errors {
|
|
|
+func (s *captureUintService) RemoveCapture(userId int64, tenantId int, id int) *common.Errors {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CaptureUnit{
|
|
|
ID: id,
|
|
|
@@ -199,14 +200,14 @@ func (s *captureUintService) RemoveCapture(userId int64, tenantId int, id int) *
|
|
|
}
|
|
|
err := device.Delete()
|
|
|
if err != nil {
|
|
|
- return util.FailResponse(err.Error(), nil)
|
|
|
+ return common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
- service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
|
|
|
- util.DeviceTypeCaptureUnit, util.GetDeviceObject(device.ID, device.CaptureName), util.OperationSuccess)
|
|
|
+ service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
|
|
|
+ common.DeviceTypeCaptureUnit, common.GetDeviceObject(device.ID, device.CaptureName), common.OperationSuccess)
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) RemovePoint(userId int64, tenantId int, id int) *util.Errors {
|
|
|
+func (s *captureUintService) RemovePoint(userId int64, tenantId int, id int) *common.Errors {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CheckPoint{
|
|
|
ID: id,
|
|
|
@@ -216,10 +217,10 @@ func (s *captureUintService) RemovePoint(userId int64, tenantId int, id int) *ut
|
|
|
}
|
|
|
err := device.Delete()
|
|
|
if err != nil {
|
|
|
- return util.FailResponse(err.Error(), nil)
|
|
|
+ return common.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
- service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
|
|
|
- util.DeviceTypePoint, util.GetDeviceObject(device.ID, device.PointName), util.OperationSuccess)
|
|
|
+ service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
|
|
|
+ common.DeviceTypePoint, common.GetDeviceObject(device.ID, device.PointName), common.OperationSuccess)
|
|
|
return nil
|
|
|
}
|
|
|
|