|
|
@@ -2,9 +2,9 @@ package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "iot_manager_service/app/dao"
|
|
|
- "iot_manager_service/app/model"
|
|
|
- "iot_manager_service/app/utils"
|
|
|
+ "iot_manager_service/app/device/dao"
|
|
|
+ "iot_manager_service/app/device/model"
|
|
|
+ "iot_manager_service/util"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
@@ -13,7 +13,7 @@ var CaptureUintService = new(captureUintService)
|
|
|
|
|
|
type captureUintService struct{}
|
|
|
|
|
|
-func (s *captureUintService) CaptureSubmit(req *model.CaptureDetail) *utils.Errors {
|
|
|
+func (s *captureUintService) CaptureSubmit(req *model.CaptureDetail) *util.Errors {
|
|
|
device := req.CaptureUint
|
|
|
if device.TenantId == "" {
|
|
|
device.TenantId = "000000" // todo: 使用登录态
|
|
|
@@ -31,33 +31,33 @@ func (s *captureUintService) CaptureSubmit(req *model.CaptureDetail) *utils.Erro
|
|
|
|
|
|
if device.IsExistedBySN() {
|
|
|
fmt.Printf("Create IsExistedBySN \n")
|
|
|
- return utils.ParamsInvalidResponse(model.RepeatedPrompts, nil)
|
|
|
+ return util.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 utils.FailResponse(err.Error(), nil)
|
|
|
+ return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
- return utils.SuccessResponse(utils.Succeeded, nil)
|
|
|
+ return util.SuccessResponse(util.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
if err := device.Update(); err != nil {
|
|
|
fmt.Printf("Update err = %s \n", err.Error())
|
|
|
- return utils.FailResponse(err.Error(), nil)
|
|
|
+ return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
//todo operation record
|
|
|
- return utils.SuccessResponse(utils.Succeeded, nil)
|
|
|
+ return util.SuccessResponse(util.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) GetCapture(id int) (*model.CaptureDetail, *utils.Errors) {
|
|
|
+func (s *captureUintService) GetCapture(id int) (*model.CaptureDetail, *util.Errors) {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CaptureUint{
|
|
|
ID: id,
|
|
|
}
|
|
|
err := device.GetDevice()
|
|
|
if err != nil {
|
|
|
- return nil, utils.FailResponse(err.Error(), nil)
|
|
|
+ return nil, util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
detail := &model.CaptureDetail{CaptureUint: *device}
|
|
|
//todo 获取实时在线最新数据
|
|
|
@@ -67,7 +67,7 @@ func (s *captureUintService) GetCapture(id int) (*model.CaptureDetail, *utils.Er
|
|
|
return detail, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) CaptureList(searchValue string, current, size int) ([]model.CaptureDetail, *utils.Errors) {
|
|
|
+func (s *captureUintService) CaptureList(searchValue string, current, size int) ([]model.CaptureDetail, *util.Errors) {
|
|
|
var details []model.CaptureDetail
|
|
|
device := dao.CaptureUint{}
|
|
|
|
|
|
@@ -80,7 +80,7 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
|
|
|
devices, err := device.GetDevices(offset, limit)
|
|
|
|
|
|
if err != nil {
|
|
|
- return nil, utils.FailResponse(err.Error(), nil)
|
|
|
+ return nil, util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
for _, d := range devices {
|
|
|
@@ -96,14 +96,14 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
|
|
|
return details, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) CaptureGetList() ([]*dao.CaptureUint, *utils.Errors) {
|
|
|
+func (s *captureUintService) CaptureGetList() ([]*dao.CaptureUint, *util.Errors) {
|
|
|
device := &dao.CaptureUint{
|
|
|
TenantId: "000000", // todo 使用登录态
|
|
|
IsDeleted: 0,
|
|
|
}
|
|
|
devices, err := device.GetAllDevices()
|
|
|
if err != nil {
|
|
|
- return nil, utils.FailResponse(err.Error(), nil)
|
|
|
+ return nil, util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
for _, d := range devices {
|
|
|
d.CaptureName = d.CaptureName + "(" + d.CaptureSN + ")"
|
|
|
@@ -111,20 +111,20 @@ func (s *captureUintService) CaptureGetList() ([]*dao.CaptureUint, *utils.Errors
|
|
|
return devices, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) GetPoint(id int) (*dao.CheckPoint, *utils.Errors) {
|
|
|
+func (s *captureUintService) GetPoint(id int) (*dao.CheckPoint, *util.Errors) {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CheckPoint{
|
|
|
ID: id,
|
|
|
}
|
|
|
err := device.GetDevice()
|
|
|
if err != nil {
|
|
|
- return nil, utils.FailResponse(err.Error(), nil)
|
|
|
+ return nil, util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
return device, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) PointSubmit(req *dao.CheckPoint) *utils.Errors {
|
|
|
+func (s *captureUintService) PointSubmit(req *dao.CheckPoint) *util.Errors {
|
|
|
device := req
|
|
|
if device.TenantId == "" {
|
|
|
device.TenantId = "000000" // todo: 使用登录态
|
|
|
@@ -138,26 +138,26 @@ func (s *captureUintService) PointSubmit(req *dao.CheckPoint) *utils.Errors {
|
|
|
|
|
|
if device.IsExistedBySN() {
|
|
|
fmt.Printf("Create IsExistedBySN \n")
|
|
|
- return utils.ParamsInvalidResponse(model.RepeatedPrompts, nil)
|
|
|
+ return util.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 utils.FailResponse(err.Error(), nil)
|
|
|
+ return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
- return utils.SuccessResponse(utils.Succeeded, nil)
|
|
|
+ return util.SuccessResponse(util.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
if err := device.Update(); err != nil {
|
|
|
fmt.Printf("Update err = %s \n", err.Error())
|
|
|
- return utils.FailResponse(err.Error(), nil)
|
|
|
+ return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
|
|
|
//todo operation record
|
|
|
- return utils.SuccessResponse(utils.Succeeded, nil)
|
|
|
+ return util.SuccessResponse(util.Succeeded, nil)
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) PointList(searchValue string, current, size int) ([]dao.CheckPoint, *utils.Errors) {
|
|
|
+func (s *captureUintService) PointList(searchValue string, current, size int) ([]dao.CheckPoint, *util.Errors) {
|
|
|
device := dao.CheckPoint{}
|
|
|
if searchValue != "" {
|
|
|
device.PointSN = searchValue
|
|
|
@@ -167,19 +167,19 @@ func (s *captureUintService) PointList(searchValue string, current, size int) ([
|
|
|
limit := size
|
|
|
devices, err := device.GetDevices(offset, limit)
|
|
|
if err != nil {
|
|
|
- return nil, utils.FailResponse(err.Error(), nil)
|
|
|
+ return nil, util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
return devices, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) PointGetList() ([]*dao.CheckPoint, *utils.Errors) {
|
|
|
+func (s *captureUintService) PointGetList() ([]*dao.CheckPoint, *util.Errors) {
|
|
|
device := &dao.CheckPoint{
|
|
|
TenantId: "000000", // todo 使用登录态
|
|
|
IsDeleted: 0,
|
|
|
}
|
|
|
devices, err := device.GetAllDevices()
|
|
|
if err != nil {
|
|
|
- return nil, utils.FailResponse(err.Error(), nil)
|
|
|
+ return nil, util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
for _, d := range devices {
|
|
|
d.PointName = d.PointName + "(" + d.PointSN + ")"
|
|
|
@@ -187,7 +187,7 @@ func (s *captureUintService) PointGetList() ([]*dao.CheckPoint, *utils.Errors) {
|
|
|
return devices, nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) RemoveCapture(id int) *utils.Errors {
|
|
|
+func (s *captureUintService) RemoveCapture(id int) *util.Errors {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CaptureUint{
|
|
|
ID: id,
|
|
|
@@ -199,12 +199,12 @@ func (s *captureUintService) RemoveCapture(id int) *utils.Errors {
|
|
|
//todo operation record
|
|
|
err := device.Delete()
|
|
|
if err != nil {
|
|
|
- return utils.FailResponse(err.Error(), nil)
|
|
|
+ return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *captureUintService) RemovePoint(id int) *utils.Errors {
|
|
|
+func (s *captureUintService) RemovePoint(id int) *util.Errors {
|
|
|
// 创建查询实例
|
|
|
device := &dao.CheckPoint{
|
|
|
ID: id,
|
|
|
@@ -216,7 +216,7 @@ func (s *captureUintService) RemovePoint(id int) *utils.Errors {
|
|
|
//todo operation record
|
|
|
err := device.Delete()
|
|
|
if err != nil {
|
|
|
- return utils.FailResponse(err.Error(), nil)
|
|
|
+ return util.FailResponse(err.Error(), nil)
|
|
|
}
|
|
|
return nil
|
|
|
}
|