Forráskód Böngészése

更新userid 为int64 tenant 为int

terry 2 éve
szülő
commit
05abee61f6
100 módosított fájl, 924 hozzáadás és 818 törlés
  1. 24 14
      app/device/controller/wisdomGatewayController.go
  2. 17 22
      app/device/controller/IntelligentLightingStrategy.go
  3. 11 4
      app/device/controller/LightStrategy.go
  4. 13 3
      app/device/controller/alarmController.go
  5. 9 2
      app/device/controller/alarmTerminalController.go
  6. 13 3
      app/device/controller/bridgeController.go
  7. 13 3
      app/device/controller/bridgeSensorController.go
  8. 13 3
      app/device/controller/cameraController.go
  9. 22 6
      app/device/controller/captureUintController.go
  10. 13 3
      app/device/controller/garbageController.go
  11. 13 3
      app/device/controller/garbageWayGroupController.go
  12. 6 1
      app/device/controller/handleHistoryController.go
  13. 9 2
      app/device/controller/infoBoardController.go
  14. 9 2
      app/device/controller/ipBroadcastController.go
  15. 13 3
      app/device/controller/lampPoleController.go
  16. 22 5
      app/device/controller/lampPoleGroupController.go
  17. 14 3
      app/device/controller/lightController.go
  18. 13 3
      app/device/controller/manholeCoverController.go
  19. 13 3
      app/device/controller/onDemandGroupController.go
  20. 9 2
      app/device/controller/onDemandSensorController.go
  21. 13 3
      app/device/controller/optoSensorController.go
  22. 14 3
      app/device/controller/switchBoxController.go
  23. 13 3
      app/device/controller/transformerController.go
  24. 9 15
      app/device/controller/workbenchController.go
  25. 13 3
      app/device/controller/zigbeeController.go
  26. 6 5
      app/device/dao/LightStrategyDao.go
  27. 21 21
      app/device/dao/alarmDao.go
  28. 9 9
      app/device/dao/alarmTerminalDao.go
  29. 18 18
      app/device/dao/bridgeDao.go
  30. 3 3
      app/device/dao/bridgeSensorDao.go
  31. 3 3
      app/device/dao/cameraDao.go
  32. 16 16
      app/device/dao/captureUintDao.go
  33. 3 3
      app/device/dao/checkPointDao.go
  34. 3 1
      app/device/dao/common.go
  35. 8 8
      app/device/dao/garbageDao.go
  36. 3 3
      app/device/dao/garbageWayGroupDao.go
  37. 3 3
      app/device/dao/gatewayDao.go
  38. 1 1
      app/device/dao/gatewayRelationDao.go
  39. 6 6
      app/device/dao/infoBoardDao.go
  40. 20 16
      app/device/dao/intelligentLightingDao.go
  41. 9 9
      app/device/dao/ipBroadcastDao.go
  42. 3 3
      app/device/dao/lampPoleDao.go
  43. 3 3
      app/device/dao/lampPoleGroupDao.go
  44. 6 6
      app/device/dao/lightConditionDao.go
  45. 3 3
      app/device/dao/lightControlDao.go
  46. 4 4
      app/device/dao/manholeCoverDao.go
  47. 3 3
      app/device/dao/onDemandGroupDao.go
  48. 6 5
      app/device/dao/onDemandSensorDao.go
  49. 2 2
      app/device/dao/operationHisDao.go
  50. 6 6
      app/device/dao/optoSensoDao.go
  51. 3 3
      app/device/dao/switchBoxDao.go
  52. 2 2
      app/device/dao/timeConditionDao.go
  53. 3 3
      app/device/dao/transformerDao.go
  54. 3 3
      app/device/dao/venderDao.go
  55. 2 2
      app/device/dao/workbenchDao.go
  56. 6 4
      app/device/dao/zigbeeDao.go
  57. 1 1
      app/device/model/captureUint.go
  58. 9 9
      app/device/model/common.go
  59. 10 26
      app/device/model/intelligentLighting.go
  60. 12 15
      app/device/service/LightStrategyService.go
  61. 11 13
      app/device/service/alarmService.go
  62. 6 8
      app/device/service/alarmTerminalService.go
  63. 10 10
      app/device/service/bridgeSensorService.go
  64. 10 7
      app/device/service/bridgeService.go
  65. 8 10
      app/device/service/cameraService.go
  66. 23 27
      app/device/service/captureUintService.go
  67. 11 8
      app/device/service/garbageService.go
  68. 10 7
      app/device/service/garbageWayGroupService.go
  69. 0 113
      app/device/service/gatewayRelationService.go
  70. 12 14
      app/device/service/gatewayService.go
  71. 8 5
      app/device/service/infoBoardService.go
  72. 27 38
      app/device/service/intelligentLightingService.go
  73. 10 7
      app/device/service/ipBroadcastService.go
  74. 24 27
      app/device/service/lampPoleGroupService.go
  75. 8 10
      app/device/service/lampPoleService.go
  76. 2 2
      app/device/service/lightConditionService.go
  77. 8 10
      app/device/service/lightControlService.go
  78. 10 7
      app/device/service/manholeCoverService.go
  79. 11 13
      app/device/service/onDemandGroupService.go
  80. 8 5
      app/device/service/onDemandSensorService.go
  81. 6 8
      app/device/service/operationHisService.go
  82. 8 7
      app/device/service/optoSensoService.go
  83. 10 10
      app/device/service/switchBoxService.go
  84. 13 10
      app/device/service/transformerService.go
  85. 2 2
      app/device/service/workbenchService.go
  86. 10 7
      app/device/service/zigbeeService.go
  87. 12 1
      app/middleware/checkAuth.go
  88. 0 1
      app/middleware/cros.go
  89. 11 7
      app/middleware/token.go
  90. 1 1
      app/system/controller/menu.go
  91. 6 1
      app/system/controller/tenant.go
  92. 7 4
      app/system/controller/token.go
  93. 30 30
      app/system/dao/tenant.go
  94. 23 23
      app/system/dao/user.go
  95. 1 2
      app/system/model/tenant.go
  96. 3 3
      app/system/model/token.go
  97. 3 4
      app/system/service/tenantService.go
  98. 2 2
      app/system/service/userService.go
  99. 9 9
      router/router.go
  100. 0 0
      util/redis.go

+ 24 - 14
app/device/controller/wisdomGatewayController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -12,11 +13,11 @@ import (
 )
 
 // 智慧网关基本信息管理对象
-var WisdomGateway = new(wisdomGatewayCtl)
+var Gateway = new(gatewayCtl)
 
-type wisdomGatewayCtl struct{}
+type gatewayCtl struct{}
 
-func (c *wisdomGatewayCtl) Detail(ctx *gin.Context) {
+func (c *gatewayCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
@@ -31,7 +32,7 @@ func (c *wisdomGatewayCtl) Detail(ctx *gin.Context) {
 	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
 }
 
-func (c *wisdomGatewayCtl) List(ctx *gin.Context) {
+func (c *gatewayCtl) List(ctx *gin.Context) {
 	searchValue := ctx.Query("searchValue")
 	current, _ := strconv.Atoi(ctx.Query("current"))
 	size, _ := strconv.Atoi(ctx.Query("size"))
@@ -58,23 +59,29 @@ func (c *wisdomGatewayCtl) List(ctx *gin.Context) {
 	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
 }
 
-func (c *wisdomGatewayCtl) CreateOrUpdate(ctx *gin.Context) {
+func (c *gatewayCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.GatewayDetail
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GatewayService.CreateOrUpdate(req)
+	err := service.GatewayService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
-func (c *wisdomGatewayCtl) Remove(ctx *gin.Context) {
+func (c *gatewayCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqGatewayRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GatewayService.Remove(req.IDs)
+	err := service.GatewayService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -82,17 +89,20 @@ func (c *wisdomGatewayCtl) Remove(ctx *gin.Context) {
 	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
 }
 
-func (c *wisdomGatewayCtl) ImportExcel(ctx *gin.Context) {
+func (c *gatewayCtl) ImportExcel(ctx *gin.Context) {
 }
 
-func (c *wisdomGatewayCtl) ExportExcel(ctx *gin.Context) {
+func (c *gatewayCtl) ExportExcel(ctx *gin.Context) {
 }
 
-func (c *wisdomGatewayCtl) ExportTemplate(ctx *gin.Context) {
+func (c *gatewayCtl) ExportTemplate(ctx *gin.Context) {
 }
 
-func (c *wisdomGatewayCtl) GetList(ctx *gin.Context) {
-	devices, err := service.GatewayService.GetList()
+func (c *gatewayCtl) GetList(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.GatewayService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -100,7 +110,7 @@ func (c *wisdomGatewayCtl) GetList(ctx *gin.Context) {
 	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
 }
 
-func (c *wisdomGatewayCtl) GetRelevanceDetail(ctx *gin.Context) {
+func (c *gatewayCtl) GetRelevanceDetail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))

+ 17 - 22
app/device/controller/IntelligentLightingStrategy.go

@@ -4,6 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -15,6 +16,9 @@ var IntelligentLighting = new(intelligentLightingCtl)
 type intelligentLightingCtl struct{}
 
 func (c *intelligentLightingCtl) Detail(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	publicId, e := strconv.Atoi(ctx.Query("publicId"))
 	if e != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
@@ -25,43 +29,34 @@ func (c *intelligentLightingCtl) Detail(ctx *gin.Context) {
 		return
 	}
 
-	//当前类型1=灯杆2=灯杆分组
-	relationType, e := strconv.Atoi(ctx.Query("type"))
-	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+	detail, err := service.IntelligentLightingService.GetDetailByLight(claims.TenantId, publicId)
+	if err != nil {
+		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	if relationType == model.RelationTypeLight {
-		detail, err := service.IntelligentLightingService.GetDetailByLight(publicId)
-		if err != nil {
-			ctx.JSON(http.StatusOK, err)
-			return
-		}
-		ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
-	} else if relationType == model.RelationTypeLampPoleGroup {
-		detail, err := service.IntelligentLightingService.GetDetailByGroup(publicId)
-		if err != nil {
-			ctx.JSON(http.StatusOK, err)
-			return
-		}
-		ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
-	} else {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.RelationTypeInvalid, nil))
-	}
+	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
 }
 
 func (c *intelligentLightingCtl) List(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	searchValue := ctx.Query("searchValue")
 	groupId := ctx.Query("groupId")
 	current, _ := strconv.Atoi(ctx.Query("current"))
 	size, _ := strconv.Atoi(ctx.Query("size"))
+	gId, err := strconv.Atoi(groupId)
+	if err != nil {
+		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("groupId invalid", nil))
+		return
+	}
 	if current == 0 {
 		current = 1
 	}
 	if size <= 0 || size > 100 {
 		size = 10
 	}
-	strategies, err := service.IntelligentLightingService.List(searchValue, groupId, current, size)
+	strategies, err := service.IntelligentLightingService.List(claims.TenantId, searchValue, current, size, gId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 11 - 4
app/device/controller/LightStrategy.go

@@ -4,6 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -56,30 +57,36 @@ func (c *lightStrategyCtl) List(ctx *gin.Context) {
 	}
 
 	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
-
 }
+
 func (c *lightStrategyCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	// 参数验证
 	var req *model.LightStrategyDetail
 	if err := ctx.ShouldBind(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LightStrategyService.CreateOrUpdate(req)
+	err := service.LightStrategyService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
 	ctx.JSON(http.StatusOK, nil)
-
 }
+
 func (c *lightStrategyCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqLightStrategyRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LightStrategyService.Remove(req.IDs)
+	err := service.LightStrategyService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/alarmController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *alarmCtl) List(ctx *gin.Context) {
 }
 
 func (c *alarmCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.Alarm
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.AlarmService.CreateOrUpdate(req)
+	err := service.AlarmService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *alarmCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqAlarmRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.AlarmService.Remove(req.IDs)
+	err := service.AlarmService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -94,7 +101,10 @@ func (c *alarmCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *alarmCtl) GetList(ctx *gin.Context) {
-	devices, err := service.AlarmService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.AlarmService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 9 - 2
app/device/controller/alarmTerminalController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *alarmTerminalCtl) List(ctx *gin.Context) {
 }
 
 func (c *alarmTerminalCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.AlarmTerminal
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.AlarmTerminalService.CreateOrUpdate(req)
+	err := service.AlarmTerminalService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *alarmTerminalCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqAlarmTerminalRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.AlarmTerminalService.Remove(req.IDs)
+	err := service.AlarmTerminalService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/bridgeController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *bridgeCtl) List(ctx *gin.Context) {
 }
 
 func (c *bridgeCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.Bridge
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.BridgeService.CreateOrUpdate(req)
+	err := service.BridgeService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *bridgeCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqBridgeRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.BridgeService.Remove(req.IDs)
+	err := service.BridgeService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -94,7 +101,10 @@ func (c *bridgeCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *bridgeCtl) GetList(ctx *gin.Context) {
-	devices, err := service.BridgeService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.BridgeService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/bridgeSensorController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *bridgeSensorCtl) List(ctx *gin.Context) {
 }
 
 func (c *bridgeSensorCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.BridgeSensor
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.BridgeSensorService.CreateOrUpdate(req)
+	err := service.BridgeSensorService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *bridgeSensorCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqBridgeSensorRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.BridgeSensorService.Remove(req.IDs)
+	err := service.BridgeSensorService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -94,7 +101,10 @@ func (c *bridgeSensorCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *bridgeSensorCtl) GetList(ctx *gin.Context) {
-	devices, err := service.BridgeSensorService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.BridgeSensorService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/cameraController.go

@@ -4,6 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -60,13 +61,16 @@ func (c *cameraCtl) List(ctx *gin.Context) {
 }
 
 func (c *cameraCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	// 参数验证
 	var req *model.CameraDetail
 	if err := ctx.ShouldBind(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.CameraService.CreateOrUpdate(req)
+	err := service.CameraService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -75,12 +79,15 @@ func (c *cameraCtl) CreateOrUpdate(ctx *gin.Context) {
 }
 
 func (c *cameraCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqCameraRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.CameraService.Remove(req.IDs)
+	err := service.CameraService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -101,7 +108,10 @@ func (c *cameraCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *cameraCtl) GetList(ctx *gin.Context) {
-	devices, err := service.CameraService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.CameraService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 22 - 6
app/device/controller/captureUintController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -71,13 +72,16 @@ func (c *captureUintCtl) CaptureList(ctx *gin.Context) {
 }
 
 func (c *captureUintCtl) CaptureSubmit(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	// 参数验证
 	var req *model.CaptureDetail
 	if err := ctx.ShouldBind(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.CaptureUintService.CaptureSubmit(req)
+	err := service.CaptureUintService.CaptureSubmit(claims.UserId, claims.TenantId, req)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -114,13 +118,16 @@ func (c *captureUintCtl) PointList(ctx *gin.Context) {
 }
 
 func (c *captureUintCtl) PointSubmit(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	// 参数验证
 	var req *dao.CheckPoint
 	if err := ctx.ShouldBind(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.CaptureUintService.PointSubmit(req)
+	err := service.CaptureUintService.PointSubmit(claims.UserId, claims.TenantId, req)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -129,7 +136,10 @@ func (c *captureUintCtl) PointSubmit(ctx *gin.Context) {
 }
 
 func (c *captureUintCtl) CaptureGetList(ctx *gin.Context) {
-	devices, err := service.CaptureUintService.CaptureGetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.CaptureUintService.CaptureGetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -138,7 +148,10 @@ func (c *captureUintCtl) CaptureGetList(ctx *gin.Context) {
 }
 
 func (c *captureUintCtl) PointGetList(ctx *gin.Context) {
-	devices, err := service.CaptureUintService.PointGetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.CaptureUintService.PointGetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -147,20 +160,23 @@ func (c *captureUintCtl) PointGetList(ctx *gin.Context) {
 }
 
 func (c *captureUintCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqCaptureRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	if req.Type == model.TypeCapture {
-		err := service.CaptureUintService.RemoveCapture(req.IDs)
+		err := service.CaptureUintService.RemoveCapture(claims.UserId, req.IDs)
 		if err != nil {
 			ctx.JSON(http.StatusOK, err)
 			return
 		}
 		ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
 	} else if req.Type == model.TypePoint {
-		err := service.CaptureUintService.RemovePoint(req.IDs)
+		err := service.CaptureUintService.RemovePoint(claims.UserId, req.IDs)
 		if err != nil {
 			ctx.JSON(http.StatusOK, err)
 			return

+ 13 - 3
app/device/controller/garbageController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *garbageCtl) List(ctx *gin.Context) {
 }
 
 func (c *garbageCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.Garbage
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GarbageService.CreateOrUpdate(req)
+	err := service.GarbageService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *garbageCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqGarbageRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GarbageService.Remove(req.IDs)
+	err := service.GarbageService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -94,7 +101,10 @@ func (c *garbageCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *garbageCtl) GetList(ctx *gin.Context) {
-	devices, err := service.GarbageService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.GarbageService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/garbageWayGroupController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *garbageWayCtl) List(ctx *gin.Context) {
 }
 
 func (c *garbageWayCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.GarbageWayGroup
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GarbageWayGroupService.CreateOrUpdate(req)
+	err := service.GarbageWayGroupService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *garbageWayCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqGarbageWayGroupRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GarbageWayGroupService.Remove(req.IDs)
+	err := service.GarbageWayGroupService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -85,7 +92,10 @@ func (c *garbageWayCtl) Remove(ctx *gin.Context) {
 }
 
 func (c *garbageWayCtl) GetList(ctx *gin.Context) {
-	devices, err := service.GarbageWayGroupService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.GarbageWayGroupService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 6 - 1
app/device/controller/handleHistoryController.go

@@ -3,6 +3,7 @@ package controller
 import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"net/http"
 	"strconv"
@@ -14,6 +15,9 @@ var HandleHistory = new(handleHistoryCtl)
 type handleHistoryCtl struct{}
 
 func (c *handleHistoryCtl) List(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	handleContent := ctx.Query("handleContent")
 	operationType := ctx.Query("operationType")
 	moduleType := ctx.Query("moduleType")
@@ -25,7 +29,8 @@ func (c *handleHistoryCtl) List(ctx *gin.Context) {
 	if size <= 0 || size > 100 {
 		size = 10
 	}
-	list, err := service.OperationHisService.List(handleContent, operationType, moduleType, current, size)
+	list, err := service.OperationHisService.List(claims.TenantId, handleContent, operationType, moduleType, current,
+		size)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 9 - 2
app/device/controller/infoBoardController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *infoBoardCtl) List(ctx *gin.Context) {
 }
 
 func (c *infoBoardCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.InfoBoard
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.InfoBoardService.CreateOrUpdate(req)
+	err := service.InfoBoardService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *infoBoardCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqInfoBoardRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.InfoBoardService.Remove(req.IDs)
+	err := service.InfoBoardService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 9 - 2
app/device/controller/ipBroadcastController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *ipBroadcastCtl) List(ctx *gin.Context) {
 }
 
 func (c *ipBroadcastCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.IpBroadcast
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.IpBroadcastService.CreateOrUpdate(req)
+	err := service.IpBroadcastService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *ipBroadcastCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqIpBroadcastRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.IpBroadcastService.Remove(req.IDs)
+	err := service.IpBroadcastService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/lampPoleController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -32,12 +33,15 @@ func (c *lampPoleCtl) Detail(ctx *gin.Context) {
 }
 
 func (c *lampPoleCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *dao.LampPole
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LampPoleService.CreateOrUpdate(req)
+	err := service.LampPoleService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
@@ -88,12 +92,15 @@ func (c *lampPoleCtl) GetRelevanceDetail(ctx *gin.Context) {
 }
 
 func (c *lampPoleCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqLampPoleRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LampPoleService.Remove(req.IDs)
+	err := service.LampPoleService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -111,7 +118,10 @@ func (c *lampPoleCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *lampPoleCtl) GetList(ctx *gin.Context) {
-	devices, err := service.LampPoleService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.LampPoleService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 22 - 5
app/device/controller/lampPoleGroupController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -34,12 +35,16 @@ func (c *lampPoleGroupCtl) Detail(ctx *gin.Context) {
 
 // CreateOrUpdate 新增、更新
 func (c *lampPoleGroupCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *dao.LampPoleGroup
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LampPoleGroupService.CreateOrUpdate(req)
+
+	err := service.LampPoleGroupService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
@@ -75,12 +80,15 @@ func (c *lampPoleGroupCtl) List(ctx *gin.Context) {
 
 // Remove 删除
 func (c *lampPoleGroupCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqLampPoleGroupRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LampPoleGroupService.Remove(req.IDs, req.Name)
+	err := service.LampPoleGroupService.Remove(claims.UserId, claims.TenantId, req.IDs, req.Name)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -90,7 +98,10 @@ func (c *lampPoleGroupCtl) Remove(ctx *gin.Context) {
 
 // GetList 获取下拉列表
 func (c *lampPoleGroupCtl) GetList(ctx *gin.Context) {
-	devices, err := service.LampPoleGroupService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.LampPoleGroupService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -100,7 +111,10 @@ func (c *lampPoleGroupCtl) GetList(ctx *gin.Context) {
 
 // FiltrationList 获取智能照明灯杆分组下拉(过滤掉没有灯控的分组显示)
 func (c *lampPoleGroupCtl) FiltrationList(ctx *gin.Context) {
-	devices, err := service.LampPoleGroupService.GetFiltration()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.LampPoleGroupService.GetFiltration(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -110,9 +124,12 @@ func (c *lampPoleGroupCtl) FiltrationList(ctx *gin.Context) {
 
 // GetTree 获取所有的灯杆分组所属灯杆
 func (c *lampPoleGroupCtl) GetTree(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	//todo 灯杆列表赋值
 	// var rsp model.ReqLampPoleGroupSubmit
-	devices, err := service.LampPoleGroupService.GetTree()
+	devices, err := service.LampPoleGroupService.GetTree(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 14 - 3
app/device/controller/lightController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -63,22 +64,28 @@ func (c *lightCtl) List(ctx *gin.Context) {
 }
 
 func (c *lightCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *dao.LightControl
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LightControlService.CreateOrUpdate(req)
+	err := service.LightControlService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *lightCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqLightControlRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LightControlService.Remove(req.IDs)
+	err := service.LightControlService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -96,7 +103,10 @@ func (c *lightCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *lightCtl) GetList(ctx *gin.Context) {
-	devices, err := service.LightControlService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.LightControlService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -128,6 +138,7 @@ func (c *lightCtl) Switch(ctx *gin.Context) {
 func lightControlDaoToModel(device dao.LightControl) model.LightControlDetail {
 	return model.LightControlDetail{LightControl: device}
 }
+
 func (c *lightCtl) ChangeHandSwitch(ctx *gin.Context) {
 
 }

+ 13 - 3
app/device/controller/manholeCoverController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *manholeCoverCtl) List(ctx *gin.Context) {
 }
 
 func (c *manholeCoverCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.ManholeCover
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.ManholeCoverService.CreateOrUpdate(req)
+	err := service.ManholeCoverService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *manholeCoverCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqManholeCoverRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.ManholeCoverService.Remove(req.IDs)
+	err := service.ManholeCoverService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -94,7 +101,10 @@ func (c *manholeCoverCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *manholeCoverCtl) GetList(ctx *gin.Context) {
-	devices, err := service.ManholeCoverService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.ManholeCoverService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/onDemandGroupController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -59,22 +60,28 @@ func (c *onDemandGroupCtl) List(ctx *gin.Context) {
 }
 
 func (c *onDemandGroupCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *dao.OnDemandGroup
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OnDemandGroupService.CreateOrUpdate(req)
+	err := service.OnDemandGroupService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *onDemandGroupCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqOnDemandGroupRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OnDemandGroupService.Remove(req.IDs)
+	err := service.OnDemandGroupService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -83,7 +90,10 @@ func (c *onDemandGroupCtl) Remove(ctx *gin.Context) {
 }
 
 func (c *onDemandGroupCtl) GetList(ctx *gin.Context) {
-	devices, err := service.OnDemandGroupService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.OnDemandGroupService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 9 - 2
app/device/controller/onDemandSensorController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *onDemandSensorCtl) List(ctx *gin.Context) {
 }
 
 func (c *onDemandSensorCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.OnDemandSensor
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OnDemandSensorService.CreateOrUpdate(req)
+	err := service.OnDemandSensorService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *onDemandSensorCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqOnDemandSensorRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OnDemandSensorService.Remove(req.IDs)
+	err := service.OnDemandSensorService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/optoSensorController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *optoSensorCtl) List(ctx *gin.Context) {
 }
 
 func (c *optoSensorCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.OptoSensor
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OptoSensorService.CreateOrUpdate(req)
+	err := service.OptoSensorService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *optoSensorCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqOptoSensorRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OptoSensorService.Remove(req.IDs)
+	err := service.OptoSensorService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -94,7 +101,10 @@ func (c *optoSensorCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *optoSensorCtl) GetList(ctx *gin.Context) {
-	devices, err := service.OptoSensorService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.OptoSensorService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 14 - 3
app/device/controller/switchBoxController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *switchBoxCtl) List(ctx *gin.Context) {
 }
 
 func (c *switchBoxCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.SwitchBox
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.SwitchBoxService.CreateOrUpdate(req)
+	err := service.SwitchBoxService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *switchBoxCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqSwitchBoxRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.SwitchBoxService.Remove(req.IDs)
+	err := service.SwitchBoxService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -85,13 +92,17 @@ func (c *switchBoxCtl) Remove(ctx *gin.Context) {
 }
 
 func (c *switchBoxCtl) GetList(ctx *gin.Context) {
-	devices, err := service.SwitchBoxService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.SwitchBoxService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
 	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
 }
+
 func (c *switchBoxCtl) ImportExcel(ctx *gin.Context) {
 }
 func (c *switchBoxCtl) ExportExcel(ctx *gin.Context) {

+ 13 - 3
app/device/controller/transformerController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *transformerCtl) List(ctx *gin.Context) {
 }
 
 func (c *transformerCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.Transformer
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.TransformerService.CreateOrUpdate(req)
+	err := service.TransformerService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *transformerCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqTransformerRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.TransformerService.Remove(req.IDs)
+	err := service.TransformerService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -85,7 +92,10 @@ func (c *transformerCtl) Remove(ctx *gin.Context) {
 }
 
 func (c *transformerCtl) GetList(ctx *gin.Context) {
-	devices, err := service.TransformerService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.TransformerService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 9 - 15
app/device/controller/workbenchController.go

@@ -14,12 +14,10 @@ var Workbench = new(workbenchCtl)
 type workbenchCtl struct{}
 
 func (c *workbenchCtl) CountDevice(ctx *gin.Context) {
-	value, isExist := ctx.Get(middleware.Authorization)
-	if !isExist || value == nil {
-		ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
-	}
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
 
-	devices, err := service.WorkbenchService.CountDevice(value.(*middleware.JwtToken).TenantId)
+	devices, err := service.WorkbenchService.CountDevice(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -28,12 +26,10 @@ func (c *workbenchCtl) CountDevice(ctx *gin.Context) {
 }
 
 func (c *workbenchCtl) CountAlarm(ctx *gin.Context) {
-	value, isExist := ctx.Get(middleware.Authorization)
-	if !isExist || value == nil {
-		ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
-	}
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
 
-	alarms, err := service.WorkbenchService.CountAlarm(value.(*middleware.JwtToken).TenantId)
+	alarms, err := service.WorkbenchService.CountAlarm(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -42,12 +38,10 @@ func (c *workbenchCtl) CountAlarm(ctx *gin.Context) {
 }
 
 func (c *workbenchCtl) Aqi(ctx *gin.Context) {
-	value, isExist := ctx.Get(middleware.Authorization)
-	if !isExist || value == nil {
-		ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
-	}
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
 
-	alarms, err := service.WorkbenchService.CountAlarm(value.(*middleware.JwtToken).TenantId)
+	alarms, err := service.WorkbenchService.CountAlarm(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 13 - 3
app/device/controller/zigbeeController.go

@@ -5,6 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"math"
 	"net/http"
@@ -61,22 +62,28 @@ func (c *zigbeeCtl) List(ctx *gin.Context) {
 }
 
 func (c *zigbeeCtl) CreateOrUpdate(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req dao.Zigbee
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.ZigbeeService.CreateOrUpdate(req)
+	err := service.ZigbeeService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
 	ctx.JSON(http.StatusOK, err)
 }
 
 func (c *zigbeeCtl) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqZigbeeRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.ZigbeeService.Remove(req.IDs)
+	err := service.ZigbeeService.Remove(claims.UserId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -94,7 +101,10 @@ func (c *zigbeeCtl) ExportTemplate(ctx *gin.Context) {
 }
 
 func (c *zigbeeCtl) GetList(ctx *gin.Context) {
-	devices, err := service.ZigbeeService.GetList()
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
+	devices, err := service.ZigbeeService.GetList(claims.TenantId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 6 - 5
app/device/dao/LightStrategyDao.go

@@ -14,13 +14,13 @@ type LightStrategy struct {
 	EndTime            string    `gorm:"type:varchar(60)" json:"endTime"`              //策略期限结束时间
 	IsAllYear          int       `gorm:"type:int;default 1" json:"isAllYear"`          //全年设置2=是,1=否
 	IsAutomaticRenewal int       `gorm:"type:int;default 1" json:"isAutomaticRenewal"` //自动续期设置 2=是,1=否
+	TenantId           int       `gorm:"type:int" json:"tenantId"`                     //租户ID
 	CreateTime         time.Time `gorm:"type:datetime" json:"createTime"`              //新增时间
-	CreateUser         string    `gorm:"type:varchar(60)" json:"createUser"`           //新增记录操作用户ID
+	CreateUser         int64     `gorm:"type:bigint" json:"createUser"`                //新增记录操作用户ID
 	UpdateTime         time.Time `gorm:"type:datetime" json:"updateTime"`              //修改时间
-	UpdateUser         string    `gorm:"type:varchar(60)" json:"updateUser"`           //修改用户
+	UpdateUser         int64     `gorm:"type:bigint" json:"updateUser"`                //修改用户
 	IsDeleted          int       `gorm:"type:int;default 0" json:"isDeleted"`          //是否删除 0=未删除,1=删除
 	Status             int       `gorm:"type:int;default 1" json:"status"`             //状态 0=正常,1=异常
-	TenantID           string    `gorm:"type:varchar(12)" json:"tenantID"`             //租户id
 	LightSn            string    `gorm:"type:varchar(64)" json:"lightSn"`              //策略编码
 	ManualTime         int       `gorm:"type:int;default 0" json:"manualTime"`         //手动控制时间
 }
@@ -44,7 +44,7 @@ func (c LightStrategy) IsExistedBySN() bool {
 func (c LightStrategy) IsExistedByNameAndCode() bool {
 	var Strategies []LightStrategy
 	err := Db.Debug().Model(&c).Where("gateway_sn = ? and is_deleted = ?",
-		c.TenantID, c.IsDeleted).Find(&Strategies).Error
+		c.TenantId, c.IsDeleted).Find(&Strategies).Error
 	if gorm.IsRecordNotFoundError(err) {
 		return false
 	}
@@ -82,6 +82,7 @@ func (c LightStrategy) GetStrategies(offset, limit int) ([]LightStrategy, error)
 
 func (c LightStrategy) GetAllStrategies() ([]*LightStrategy, error) {
 	var Strategies []*LightStrategy
-	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantID, c.IsDeleted).Scan(&Strategies).Error
+	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId,
+		c.IsDeleted).Scan(&Strategies).Error
 	return Strategies, err
 }

+ 21 - 21
app/device/dao/alarmDao.go

@@ -7,27 +7,27 @@ import (
 
 // Alarm 一键报警服务
 type Alarm struct {
-	ID          int        `gorm:"primary_key" json:"id"`              //编号
-	ServeName   string     `gorm:" varchar(64)" json:"serveName"`      //设备名称
-	ServeSN     string     `gorm:"type:varchar(60)" json:"serveSN"`    //设备序编码
-	BrandID     int        `gorm:"type:int" json:"brandID"`            //设备品牌ID
-	ModelID     int        `gorm:"type:int" json:"modelID"`            //设备型号ID
-	ServeType   int        `gorm:"type: int" json:"serveType"`         //服务
-	ServeIP     string     `gorm:"type:varchar(50)" json:"serveIP"`    //所属服务IP地址
-	ServeProt   int        `gorm:"type:int  " json:"serveProt"`        //端口
-	Account     string     `gorm:"type:varchar(4000) " json:"account"` //账号
-	Pwd         string     `gorm:"type:varchar(4000) " json:"pwd"`     //密码
-	Numeration  int        `gorm:"type:int" json:"numeration"`         //编号
-	IPAddress   string     `gorm:"type:varchar(50)" json:"ipAddress"`  //IP地址
-	InstallTime *time.Time `gorm:"type:date" json:"installTime"`       //安装时间
-	TenantId    string     `gorm:"type:varchar(12)" json:"tenantId"`   //租户id
-	CreateTime  time.Time  `gorm:"type:datetime" json:"createTime"`    //新增时间
-	CreateUser  string     `gorm:"type:varchar(60)" json:"createUser"` //新增记录操作用户ID
-	UpdateTime  time.Time  `gorm:"type:datetime" json:"updateTime"`    //修改时间
-	UpdateUser  string     `gorm:"type:varchar(60)" json:"updateUser"` //修改用户
-	IsDeleted   int        `gorm:"type:int" json:"isDeleted"`          //是否删除 0=未删除,1=删除
-	Status      int        `gorm:"type:int  " json:"status"`           //告警状态 1处理完成2待处理3无需处理
-	Tag         string     `gorm:"type:varchar(255)" json:"tag"`       //标签,(备用,逗号区分)
+	ID          int        `gorm:"primary_key" json:"id"`             //编号
+	ServeName   string     `gorm:"varchar(64)" json:"serveName"`      //设备名称
+	ServeSN     string     `gorm:"type:varchar(60)" json:"serveSN"`   //设备序编码
+	BrandID     int        `gorm:"type:int" json:"brandID"`           //设备品牌ID
+	ModelID     int        `gorm:"type:int" json:"modelID"`           //设备型号ID
+	ServeType   int        `gorm:"type:int" json:"serveType"`         //服务
+	ServeIP     string     `gorm:"type:varchar(50)" json:"serveIP"`   //所属服务IP地址
+	ServePort   int        `gorm:"type:int" json:"servePort"`         //端口
+	Account     string     `gorm:"type:varchar(4000)" json:"account"` //账号
+	Pwd         string     `gorm:"type:varchar(4000)" json:"pwd"`     //密码
+	Numeration  int        `gorm:"type:int" json:"numeration"`        //编号
+	IPAddress   string     `gorm:"type:varchar(50)" json:"ipAddress"` //IP地址
+	InstallTime *time.Time `gorm:"type:date" json:"installTime"`      //安装时间
+	TenantId    int        `gorm:"type:int" json:"tenantId"`          //租户id
+	CreateTime  time.Time  `gorm:"type:datetime" json:"createTime"`   //新增时间
+	CreateUser  int64      `gorm:"type:bigint" json:"createUser"`     //新增记录操作用户ID
+	UpdateTime  time.Time  `gorm:"type:datetime" json:"updateTime"`   //修改时间
+	UpdateUser  int64      `gorm:"type:bigint" json:"updateUser"`     //修改用户
+	IsDeleted   int        `gorm:"type:int" json:"isDeleted"`         //是否删除 0=未删除,1=删除
+	Status      int        `gorm:"type:int" json:"status"`            //告警状态 1处理完成2待处理3无需处理
+	Tag         string     `gorm:"type:varchar(255)" json:"tag"`      //标签,(备用,逗号区分)
 }
 
 func (Alarm) TableName() string {

+ 9 - 9
app/device/dao/alarmTerminalDao.go

@@ -8,26 +8,26 @@ import (
 // AlarmTerminal 一键报警服务
 type AlarmTerminal struct {
 	ID               int       `gorm:"primary_key" json:"id"`                     //编号
-	TerminalName     string    `gorm:" varchar(64)" json:"terminalName"`          //设备名称
+	TerminalName     string    `gorm:"varchar(64)" json:"terminalName"`           //设备名称
 	TerminalSN       string    `gorm:"type:varchar(60)" json:"terminalSN"`        //设备序编码
 	BrandID          int       `gorm:"type:int" json:"brandID"`                   //设备品牌ID
 	ModelID          int       `gorm:"type:int" json:"modelID"`                   //设备型号ID
-	GatewayID        int       `gorm:"type: int" json:"gatewayID"`                //所属网关
-	LampPoleID       int       `gorm:"type: int" json:"lampPoleID"`               //所属灯杆 灯杆ID
-	LampPoleName     string    `gorm:"type: varchar(64)" json:"lampPoleName"`     //灯杆名称
-	LampPoleSN       string    `gorm:"type: varchar(64)" json:"lampPoleSN"`       //灯杆编码
+	GatewayID        int       `gorm:"type:int" json:"gatewayID"`                 //所属网关
+	LampPoleID       int       `gorm:"type:int" json:"lampPoleID"`                //所属灯杆 灯杆ID
+	LampPoleName     string    `gorm:"type:varchar(64)" json:"lampPoleName"`      //灯杆名称
+	LampPoleSN       string    `gorm:"type:varchar(64)" json:"lampPoleSN"`        //灯杆编码
 	LampPoleLocation string    `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
 	PoleLng          float64   `gorm:"type:double(17, 14) " json:"poleLng"`       //经度
 	PoleLat          float64   `gorm:"type:double(17, 14)  " json:"poleLat"`      //纬度
-	Numeration       int       `gorm:"type: int" json:"numeration"`               //编号
+	Numeration       int       `gorm:"type:int" json:"numeration"`                //编号
 	ServeID          int       `gorm:"type:int" json:"serveID"`                   //所属服务ID
 	IPAddress        string    `gorm:"type:varchar(50)" json:"ipAddress"`         //IP地址
 	InstallTime      time.Time `gorm:"type:date" json:"installTime"`              //安装时间
-	TenantId         string    `gorm:"type:varchar(12)" json:"tenantId"`          //租户id
+	TenantId         int       `gorm:"type:int" json:"tenantId"`                  //租户id
 	CreateTime       time.Time `gorm:"type:datetime" json:"createTime"`           //新增时间
-	CreateUser       string    `gorm:"type:varchar(60)" json:"createUser"`        //新增记录操作用户ID
+	CreateUser       int64     `gorm:"type:bigint" json:"createUser"`             //新增记录操作用户ID
 	UpdateTime       time.Time `gorm:"type:datetime" json:"updateTime"`           //修改时间
-	UpdateUser       string    `gorm:"type:varchar(60)" json:"updateUser"`        //修改用户
+	UpdateUser       int64     `gorm:"type:bigint" json:"updateUser"`             //修改用户
 	IsDeleted        int       `gorm:"type:int" json:"isDeleted"`                 //是否删除 0=未删除,1=删除
 	Status           int       `gorm:"type:int  " json:"status"`                  //告警状态 1处理完成2待处理3无需处理
 	Tag              string    `gorm:"type:varchar(255)" json:"tag"`              //标签,(备用,逗号区分)

+ 18 - 18
app/device/dao/bridgeDao.go

@@ -9,31 +9,31 @@ type Bridge struct {
 	ID                int       `gorm:"primary_key" json:"id"`                      //编号
 	Name              string    `gorm:"type:varchar(64)" json:"name"`               //名称
 	SN                string    `gorm:"type:varchar(60)" json:"sn"`                 //唯一编码
-	Lng               float64   `gorm:"type:double(17, 14) " json:"lng"`            //经度
-	Lat               float64   `gorm:"type:double(17, 14)  " json:"lat"`           //纬度
-	ProvinceName      string    `gorm:" type:varchar(60)" json:"provinceName"`      //省份
+	Lng               float64   `gorm:"type:double(17, 14)" json:"lng"`             //经度
+	Lat               float64   `gorm:"type:double(17, 14)" json:"lat"`             //纬度
+	ProvinceName      string    `gorm:"type:varchar(60)" json:"provinceName"`       //省份
 	CityName          string    `gorm:"type:varchar(60)" json:"cityName"`           //市
 	DistrictName      string    `gorm:"type:varchar(60)" json:"districtName"`       //区
 	InstallPosition   string    `gorm:"type:varchar(100)" json:"installLocation"`   //位置
-	PurposeType       int       `gorm:" type:int" json:"purposeType"`               //用途类型
-	StraddlesType     int       `gorm:"type: int " json:"straddlesType"`            //跨越类型
-	StuffType         int       `gorm:"type: int " json:"stuffType"`                //材料类型
-	StructureType     int       `gorm:"type: int " json:"structureType"`            //结构类型
-	TechniqueGrade    int       `gorm:" type: int " json:"techniqueGrade"`          //技术等级
-	CompletionTime    string    `gorm:" type:date" json:"completionTime"`           //建成时间
-	Length            int       `gorm:"type: int " json:"length"`                   //长度
-	Width             int       `gorm:"type: int " json:"width"`                    //宽度
-	Height            int       `gorm:"type: int " json:"height"`                   //高度
-	TrafficNum        int       `gorm:"type: int " json:"trafficNum"`               //车道数
-	IsOpenTraffic     int       `gorm:" type: int " json:"isOpenTraffic"`           //是否已通车
-	DesignSpeed       int       `gorm:"type: int " json:"designSpeed"`              //设计时速
+	PurposeType       int       `gorm:"type:int" json:"purposeType"`                //用途类型
+	StraddlesType     int       `gorm:"type:int" json:"straddlesType"`              //跨越类型
+	StuffType         int       `gorm:"type:int" json:"stuffType"`                  //材料类型
+	StructureType     int       `gorm:"type:int" json:"structureType"`              //结构类型
+	TechniqueGrade    int       `gorm:"type:int" json:"techniqueGrade"`             //技术等级
+	CompletionTime    string    `gorm:"type:date" json:"completionTime"`            //建成时间
+	Length            int       `gorm:"type:int" json:"length"`                     //长度
+	Width             int       `gorm:"type:int" json:"width"`                      //宽度
+	Height            int       `gorm:"type:int" json:"height"`                     //高度
+	TrafficNum        int       `gorm:"type:int" json:"trafficNum"`                 //车道数
+	IsOpenTraffic     int       `gorm:"type:int" json:"isOpenTraffic"`              //是否已通车
+	DesignSpeed       int       `gorm:"type:int" json:"designSpeed"`                //设计时速
 	BriefIntroduction string    `gorm:"type:varchar(255)" json:"briefIntroduction"` //简介
 	Photo             string    `gorm:"type:varchar(255)" json:"photo"`             //照片
-	TenantId          string    `gorm:"type:varchar(12)" json:"tenantId"`           //租户id
+	TenantId          int       `gorm:"type:int" json:"tenantId"`                   //租户id
 	CreateTime        time.Time `gorm:"type:datetime" json:"createTime"`            //新增时间
-	CreateUser        string    `gorm:"type:varchar(60)" json:"createUser"`         //新增记录操作用户ID
+	CreateUser        int64     `gorm:"type:bigint" json:"createUser"`              //新增记录操作用户ID
 	UpdateTime        time.Time `gorm:"type:datetime" json:"updateTime"`            //修改时间
-	UpdateUser        string    `gorm:"type:varchar(60)" json:"updateUser"`         //修改用户
+	UpdateUser        int64     `gorm:"type:bigint" json:"updateUser"`              //修改用户
 	IsDeleted         int       `gorm:"type:int;default 0" json:"isDeleted"`        //是否删除 0=未删除,1=删除
 	Status            int       `gorm:"type:int" json:"status"`                     //状态 0=正常,1=异常
 }

+ 3 - 3
app/device/dao/bridgeSensorDao.go

@@ -19,11 +19,11 @@ type BridgeSensor struct {
 	InstallPosition  string     `gorm:"type:varchar(100)" json:"installPosition"` //安装位置
 	InstallTime      *time.Time `gorm:"type:date" json:"installTime"`             //安装时间
 	IPAddress        string     `gorm:"type:varchar(64)" json:"ipAddress"`        //IP地址-备用
-	TenantID         string     `gorm:"type:varchar(12)" json:"tenantID"`         //租户id
+	TenantID         int        `gorm:"type:int" json:"tenantID"`                 //租户id
 	CreateTime       time.Time  `gorm:"type:datetime" json:"createTime"`          //新增时间
-	CreateUser       string     `gorm:"type:varchar(60)" json:"createUser"`       //新增记录操作用户ID
+	CreateUser       int64      `gorm:"type:bigint" json:"createUser"`            //新增记录操作用户ID
 	UpdateTime       time.Time  `gorm:"type:datetime" json:"updateTime"`          //修改时间
-	UpdateUser       string     `gorm:"type:varchar(60)" json:"updateUser"`       //修改用户
+	UpdateUser       int64      `gorm:"type:bigint" json:"updateUser"`            //修改用户
 	IsDeleted        int        `gorm:"type:int;default 0" json:"isDeleted"`      //是否删除 0=未删除,1=删除
 	Status           int        `gorm:"type:int" json:"status"`                   //状态 0=正常,1=异常
 	IsEnable         int        `gorm:"type:tinyint; default 1" json:"isEnable"`  //启用禁用:1启用,2禁用

+ 3 - 3
app/device/dao/cameraDao.go

@@ -24,11 +24,11 @@ type CameraDevice struct {
 	MonitorAddress   string    `gorm:"type:varchar(255)" json:"monitorAddress"`        //监控地址 ip:端口
 	IPAddress        string    `gorm:"type:varchar(40)" json:"ipAddress"`              //IP地址
 	InstallTime      time.Time `gorm:"type:date" json:"installTime"`                   //安装时间
-	TenantId         string    `gorm:"type:varchar(12)" json:"tenantId"`               //租户ID
+	TenantId         int       `gorm:"type:int" json:"tenantId"`                       //租户ID
 	CreateTime       time.Time `gorm:"type:datetime" json:"createTime"`                //新增时间
-	CreateUser       string    `gorm:"type:varchar(60)" json:"createUser"`             //新增记录操作用户ID
+	CreateUser       int64     `gorm:"type:bigint" json:"createUser"`                  //新增记录操作用户ID
 	UpdateTime       time.Time `gorm:"type:datetime" json:"updateTime"`                //修改时间
-	UpdateUser       string    `gorm:"type:varchar(60)" json:"updateUser"`             //修改用户
+	UpdateUser       int64     `gorm:"type:bigint" json:"updateUser"`                  //修改用户
 	IsDeleted        int       `gorm:"type:int;default 0" json:"isDeleted"`            //是否删除 0=未删除,1=删除
 	Status           int       `gorm:"type:int" json:"status"`                         //状态 0=正常,1=异常
 	Tag              string    `gorm:"type:varchar(255)" json:"tag"`                   //标签,(备用,逗号区分)

+ 16 - 16
app/device/dao/captureUintDao.go

@@ -4,8 +4,8 @@ import (
 	"time"
 )
 
-//CaptureUint 抓拍单元
-type CaptureUint struct {
+//CaptureUnit 抓拍单元
+type CaptureUnit struct {
 	ID                     int       `gorm:"primary_key" json:"id"`                                //编号
 	CaptureName            string    `gorm:"type:varchar(64)" json:"captureName"`                  //设备名称
 	CaptureSN              string    `gorm:"type:varchar(60)" json:"captureSn"`                    //设备序列号
@@ -29,40 +29,40 @@ type CaptureUint struct {
 	GatewayId              int       `gorm:"type:int" json:"gatewayId"`                            //网关ID
 	GatewayName            string    `gorm:"type:varchar(80)" json:"gatewayName"`                  //网关名称
 	GatewaySN              string    `gorm:"type:varchar(30)" json:"gatewaySn"`                    //网关编码
-	TenantId               string    `gorm:"type:varchar(12)" json:"tenantId"`                     //租户ID
+	TenantId               int       `gorm:"type:int" json:"tenantId"`                             //租户ID
 	CreateTime             time.Time `gorm:"type:datetime" json:"createTime"`                      //新增时间
-	CreateUser             string    `gorm:"type:varchar(30)" json:"createUser"`                   //新增记录操作用户ID
+	CreateUser             int64     `gorm:"type:bigint" json:"createUser"`                        //新增记录操作用户ID
 	UpdateTime             time.Time `gorm:"type:datetime" json:"updateTime"`                      //修改时间
-	UpdateUser             string    `gorm:"type:varchar(30)" json:"updateUser"`                   //修改用户
+	UpdateUser             int64     `gorm:"type:bigint" json:"updateUser"`                        //修改用户
 	IsDeleted              int       `gorm:"type:int;default 0" json:"isDeleted"`                  //是否删除 0=未删除,1=删除
 }
 
-func (CaptureUint) TableName() string {
-	return "t_dev_capture_uint"
+func (CaptureUnit) TableName() string {
+	return "t_dev_capture_unit"
 }
 
-func (c CaptureUint) IsExistedBySN() bool {
+func (c CaptureUnit) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where("capture_sn = ? and is_deleted = ?",
 		c.CaptureSN, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
-func (c *CaptureUint) Create() error {
+func (c *CaptureUnit) Create() error {
 	return Db.Debug().Model(&c).Save(&c).Error
 }
 
-func (c *CaptureUint) Update() error {
+func (c *CaptureUnit) Update() error {
 	return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
 }
 
-func (c *CaptureUint) GetDevice() error {
+func (c *CaptureUnit) GetDevice() error {
 	err := Db.Debug().Model(&c).Where(" id = ? ", c.ID).First(&c).Error
 	return err
 }
 
-func (c CaptureUint) GetDevices(offset, limit int) ([]CaptureUint, error) {
-	var Captures []CaptureUint
+func (c CaptureUnit) GetDevices(offset, limit int) ([]CaptureUnit, error) {
+	var Captures []CaptureUnit
 	db := Db.Debug().Model(&c)
 	if c.CaptureSN != "" {
 		db = db.Where("capture_name like ? or capture_sn like ?", "%"+c.CaptureSN+"%", "%"+c.CaptureSN+"%")
@@ -72,13 +72,13 @@ func (c CaptureUint) GetDevices(offset, limit int) ([]CaptureUint, error) {
 	return Captures, err
 }
 
-func (c *CaptureUint) Delete() error {
+func (c *CaptureUnit) Delete() error {
 	return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
 		"update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
 }
 
-func (c CaptureUint) GetAllDevices() ([]*CaptureUint, error) {
-	var Captures []*CaptureUint
+func (c CaptureUnit) GetAllDevices() ([]*CaptureUnit, error) {
+	var Captures []*CaptureUnit
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&Captures).Error
 	return Captures, err
 }

+ 3 - 3
app/device/dao/checkPointDao.go

@@ -10,11 +10,11 @@ type CheckPoint struct {
 	PointName     string    `gorm:"type:varchar(64)" json:"pointName"`      //卡口名称
 	PointSN       string    `gorm:"type:varchar(60)" json:"pointSn"`        //卡口编码
 	PointLocation string    `gorm:"type:varchar(150)" json:"pointLocation"` //卡口位置
-	TenantId      string    `gorm:"type:varchar(12)" json:"tenantId"`       //租户ID
+	TenantId      int       `gorm:"type:int" json:"tenantId"`               //租户ID
 	CreateTime    time.Time `gorm:"type:datetime" json:"createTime"`        //新增时间
-	CreateUser    string    `gorm:"type:varchar(30)" json:"createUser"`     //新增记录操作用户ID
+	CreateUser    int64     `gorm:"type:bigint" json:"createUser"`          //新增记录操作用户ID
 	UpdateTime    time.Time `gorm:"type:datetime" json:"updateTime"`        //修改时间
-	UpdateUser    string    `gorm:"type:varchar(30)" json:"updateUser"`     //修改用户
+	UpdateUser    int64     `gorm:"type:bigint" json:"updateUser"`          //修改用户
 	IsDeleted     int       `gorm:"type:int;default 0" json:"isDeleted"`    //是否删除 0=未删除,1=删除
 }
 

+ 3 - 1
app/device/dao/common.go

@@ -28,7 +28,7 @@ func InitDB(db *gorm.DB) {
 		&CameraDevice{},
 		&InfoBoard{},
 		&Alarm{},
-		&CaptureUint{},
+		&CaptureUnit{},
 		&CheckPoint{},
 		&AlarmTerminal{},
 		&Bridge{},
@@ -36,11 +36,13 @@ func InitDB(db *gorm.DB) {
 		&IpBroadcast{},
 		&ManholeCover{},
 		&OptoSensor{},
+		&SwitchBox{},
 		&IntelligentLight{},
 		&TimeCondition{},
 		&LightStrategy{},
 		&LightCondition{},
 		&DeviceVendor{},
+		&OperationHis{},
 	).Error
 	if err != nil {
 		panic(fmt.Sprintf("AutoMigrate err : %v", err))

+ 8 - 8
app/device/dao/garbageDao.go

@@ -17,25 +17,25 @@ type Garbage struct {
 	ModelId         int       `gorm:"type:int" json:"modelId"`                  //型号
 	GarbageOneType  int       `gorm:"type:int" json:"garbageOneType"`           //桶1类型
 	GarbageTwoType  int       `gorm:"type:int" json:"garbageTwoType"`           //桶2类型
-	GarbageHeight   int       `gorm:"int" json:"garbageHeight"`                 //内桶高度
-	TotalHeight     int       `gorm:"int" json:"totalHeight"`                   //传感器距离内桶高度
+	GarbageHeight   int       `gorm:"type:int" json:"garbageHeight"`            //内桶高度
+	TotalHeight     int       `gorm:"type:int" json:"totalHeight"`              //传感器距离内桶高度
 	InstallTime     time.Time `gorm:"type:date" json:"installTime"`             //安装时间
 	WayID           int       `gorm:"type:int" json:"wayID"`                    //所属道路号
 	CameraID        int       `gorm:"type:int" json:"cameraID"`                 //摄像机id
 	CameraSN        string    `gorm:"type:varchar(60)" json:"cameraSN"`         //摄像机sn
-	PoleLng         float64   `gorm:"type:double(17, 14) " json:"poleLng"`      //经度
-	PoleLat         float64   `gorm:"type:double(17, 14)  " json:"poleLat"`     //纬度
-	ProvinceName    string    `gorm:" type:varchar(60)" json:"provinceName"`    //省份
+	PoleLng         float64   `gorm:"type:double(17, 14)" json:"poleLng"`       //经度
+	PoleLat         float64   `gorm:"type:double(17, 14)" json:"poleLat"`       //纬度
+	ProvinceName    string    `gorm:"type:varchar(60)" json:"provinceName"`     //省份
 	CityName        string    `gorm:"type:varchar(60)" json:"cityName"`         //市
 	DistrictName    string    `gorm:"type:varchar(60)" json:"districtName"`     //区
 	InstallLocation string    `gorm:"type:varchar(100)" json:"installLocation"` //安装位置
 	PhotoUrl        string    `gorm:"type:varchar(255)" json:"photoUrl"`        //供电箱照片地址
 	Remark          string    `gorm:"type:varchar(1000)" json:"remark"`         //备注
-	TenantId        string    `gorm:"type:varchar(12)" json:"tenantId"`         //租户id
+	TenantId        int       `gorm:"type:int" json:"tenantId"`                 //租户id
 	CreateTime      time.Time `gorm:"type:datetime" json:"createTime"`          //新增时间
-	CreateUser      string    `gorm:"type:varchar(60)" json:"createUser"`       //新增记录操作用户ID
+	CreateUser      int64     `gorm:"type:bigint" json:"createUser"`            //新增记录操作用户ID
 	UpdateTime      time.Time `gorm:"type:datetime" json:"updateTime"`          //修改时间
-	UpdateUser      string    `gorm:"type:varchar(60)" json:"updateUser"`       //修改用户
+	UpdateUser      int64     `gorm:"type:bigint" json:"updateUser"`            //修改用户
 	IsDeleted       int       `gorm:"type:int;default 0" json:"isDeleted"`      //是否删除 0=未删除,1=删除
 	Threshold       int       `gorm:"type:int" json:"threshold"`                //阈值设定:告警百分比%
 }

+ 3 - 3
app/device/dao/garbageWayGroupDao.go

@@ -9,11 +9,11 @@ import (
 type GarbageWayGroup struct {
 	ID         int       `gorm:"primary_key" json:"id"`               //编号
 	GroupName  string    `gorm:"type:varchar(64)" json:"groupName"`   //分组名称
-	TenantId   string    `gorm:"type:varchar(12)" json:"tenantId"`    //租户id
+	TenantId   int       `gorm:"type:int" json:"tenantId"`            //租户id
 	CreateTime time.Time `gorm:"type:datetime" json:"createTime"`     //新增时间
-	CreateUser string    `gorm:"type:varchar(60)" json:"createUser"`  //新增记录操作用户ID
+	CreateUser int64     `gorm:"type:bigint" json:"createUser"`       //新增记录操作用户ID
 	UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`     //修改时间
-	UpdateUser string    `gorm:"type:varchar(60)" json:"updateUser"`  //修改用户
+	UpdateUser int64     `gorm:"type:bigint" json:"updateUser"`       //修改用户
 	IsDeleted  int       `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
 	Remark     string    `gorm:"type:varchar(255)" json:"remark"`     //备注
 }

+ 3 - 3
app/device/dao/gatewayDao.go

@@ -25,11 +25,11 @@ type Gateway struct {
 	DoNum              int       `gorm:"type:int;default 0" json:"doNum"`                 //DO口数量
 	Num485             int       `gorm:"type:int;default 0" json:"num485"`                //485口数量
 	NetworkNum         int       `gorm:"type:int;default 0" json:"networkNum"`            //网口数量
-	TenantId           string    `gorm:"type:varchar(12)" json:"tenantId"`                //租户ID
+	TenantId           int       `gorm:"type:int" json:"tenantId"`                        //租户ID
 	CreateTime         time.Time `gorm:"type:datetime" json:"createTime"`                 //新增时间
-	CreateUser         string    `gorm:"type:varchar(60)" json:"createUser"`              //新增记录操作用户ID
+	CreateUser         int64     `gorm:"type:bigint" json:"createUser"`                   //新增记录操作用户ID
 	UpdateTime         time.Time `gorm:"type:datetime" json:"updateTime"`                 //修改时间
-	UpdateUser         string    `gorm:"type:varchar(60)" json:"updateUser"`              //修改用户
+	UpdateUser         int64     `gorm:"type:bigint" json:"updateUser"`                   //修改用户
 	IsDeleted          int       `gorm:"type:int;default 0" json:"isDeleted"`             //是否删除 0=未删除,1=删除
 	Status             int       `gorm:"type:int" json:"status"`                          //状态 0=正常,1=异常
 	Tag                string    `gorm:"type:varchar(255)" json:"tag"`                    //标签,(备用,逗号区分)

+ 1 - 1
app/device/dao/gatewayRelationDao.go

@@ -15,7 +15,7 @@ type GatewayRelation struct {
 	CaptureUnitCount   int       `gorm:"type:int;default 0"`                  //抓拍单元数量
 	IpBroadcastCount   int       `gorm:"type:int;default 0"`                  //IP音柱数量
 	Total              int       `gorm:"type:int;default 0"`                  //总数
-	TenantId           string    `gorm:"type:varchar(12)" json:"tenantId"`    //租户ID
+	TenantId           int       `gorm:"type:int" json:"tenantId"`            //租户ID
 	CreateTime         time.Time `gorm:"type:datetime" json:"createTime"`     //新增时间
 	UpdateTime         time.Time `gorm:"type:datetime" json:"updateTime"`     //修改时间
 	IsDeleted          int       `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删

+ 6 - 6
app/device/dao/infoBoardDao.go

@@ -11,8 +11,8 @@ type InfoBoard struct {
 	InfoName         string    `gorm:"type:varchar(60)" json:"infoName"`                 //名称
 	SN               string    `gorm:"type:varchar(60)" json:"sn"`                       //设备序列号
 	LampPoleId       int       `gorm:"type:int" json:"LampPoleId"`                       //所属灯杆id
-	LampPoleName     string    `gorm:"type: varchar(64)" json:"lampPoleName"`            //灯杆名称
-	LampPoleSN       string    `gorm:"type: varchar(64)" json:"lampPoleSN"`              //灯杆编码
+	LampPoleName     string    `gorm:"type:varchar(64)" json:"lampPoleName"`             //灯杆名称
+	LampPoleSN       string    `gorm:"type:varchar(64)" json:"lampPoleSN"`               //灯杆编码
 	LampPoleLocation string    `gorm:"type:varchar(255)" json:"lampPoleLocation"`        //灯杆安装位置
 	PoleLng          float64   `gorm:"type:double(17, 14) " json:"poleLng"`              //经度
 	PoleLat          float64   `gorm:"type:double(17, 14)  " json:"poleLat"`             //纬度
@@ -28,15 +28,15 @@ type InfoBoard struct {
 	BootEndTime      string    `gorm:"type:time" json:"bootEndTime"`                     //开机结束时间
 	NeverCloseDown   int       `gorm:"type:int" json:"neverCloseDown"`                   //永不关机:1-选择,2-取消
 	InstallTime      time.Time `gorm:"type:date" json:"installTime"`                     //安装时间
-	TenantId         string    `gorm:"type:varchar(12)" json:"tenantId"`                 //租户id
+	TenantId         int       `gorm:"type:int" json:"tenantId"`                         //租户ID
 	CreateTime       time.Time `gorm:"type:datetime" json:"createTime"`                  //新增时间
-	CreateUser       string    `gorm:"type:varchar(60)" json:"createUser"`               //新增记录操作用户ID
+	CreateUser       int64     `gorm:"type:bigint" json:"createUser"`                    //新增记录操作用户ID
 	UpdateTime       time.Time `gorm:"type:datetime" json:"updateTime"`                  //修改时间
-	UpdateUser       string    `gorm:"type:varchar(60)" json:"updateUser"`               //修改用户
+	UpdateUser       int64     `gorm:"type:bigint" json:"updateUser"`                    //修改用户
 	IsDeleted        int       `gorm:"type:int;default 0" json:"isDeleted"`              //是否删除 0=未删除,1=删除
 	Tag              string    `gorm:"type:varchar(255)" json:"tag"`                     //标签,保留字段(逗号区分)
 	ExteriorUid      int       `gorm:"type:bigint" json:"exteriorUid"`                   //外设ID
-	IsEnable         int       `gorm:"type: int; default 2 " json:"isEnable"`            //启用禁用:1启用,2禁用
+	IsEnable         int       `gorm:"type:int; default 2 " json:"isEnable"`             //启用禁用:1启用,2禁用
 }
 
 func (InfoBoard) TableName() string {

+ 20 - 16
app/device/dao/intelligentLightingDao.go

@@ -7,7 +7,8 @@ import (
 type IntelligentLightGroupRelation struct {
 	IntelligentLight
 	LightStrategy
-	LampPoleGroup
+	LightControl
+	TimeCondition
 }
 
 type IntelligentLight struct {
@@ -15,12 +16,12 @@ type IntelligentLight struct {
 	LightID      int       `gorm:"type:int" json:"lightID"`             //照明策略id
 	RelationType int       `gorm:"type:int" json:"relationType"`        //关联类型1=灯控,2=灯杆分组
 	Rid          int       `gorm:"type:int" json:"rid"`                 //关联外键ID 根据type类型关联至其表
-	CreateTime   time.Time `gorm:"type:timestamp" json:"createTime"`    //新增时间
-	CreateUser   string    `gorm:"type:varchar(60)" json:"createUser"`  //新增记录操作用户ID
-	UpdateTime   time.Time `gorm:"type:timestamp" json:"updateTime"`    //修改时间
-	UpdateUser   string    `gorm:"type:varchar(60)" json:"updateUser"`  //修改用户
+	TenantId     int       `gorm:"type:int" json:"tenantId"`            //租户ID
+	CreateTime   time.Time `gorm:"type:datetime" json:"createTime"`     //新增时间
+	CreateUser   int64     `gorm:"type:bigint" json:"createUser"`       //新增记录操作用户ID
+	UpdateTime   time.Time `gorm:"type:datetime" json:"updateTime"`     //修改时间
+	UpdateUser   int64     `gorm:"type:bigint" json:"updateUser"`       //修改用户
 	IsDeleted    int       `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
-	TenantID     string    `gorm:"type:varchar(12)" json:"tenantID"`    //租户id
 }
 
 func (IntelligentLight) TableName() string {
@@ -36,7 +37,7 @@ func (c *IntelligentLight) BatchGet(ids []int) ([]IntelligentLight, error) {
 func (c *IntelligentLight) GetByRidAndType() ([]IntelligentLight, error) {
 	var intelligentLights []IntelligentLight
 	db := Db.Debug().Model(&c).Where("relation_type = ? and is_deleted = 0 and tenant_id = ?",
-		c.RelationType, c.TenantID)
+		c.RelationType, c.TenantId)
 	if c.Rid > 0 {
 		db = db.Where("rid = ?", c.Rid)
 	}
@@ -44,18 +45,21 @@ func (c *IntelligentLight) GetByRidAndType() ([]IntelligentLight, error) {
 	return intelligentLights, err
 }
 
-func (c *IntelligentLight) GetByType() ([]IntelligentLightGroupRelation, error) {
+func (c *IntelligentLight) GetByGroup(searchValue string, current, size,
+	groupId int) ([]IntelligentLightGroupRelation, error) {
 	var groupRelations []IntelligentLightGroupRelation
-	selectStr := "lig.*,gro.id,gro.pole_group_name,b.light_name,b.light_sn,b.start_time,b.end_time,b.is_all_year,b.is_automatic_renewal"
-	whereStr := "lig.is_deleted = 0 and relation_type = 2 and lig.tenant_id = ? and gro.is_deleted = 0"
-	whereValue := []interface{}{c.TenantID}
-	if c.Rid > 0 {
-		whereStr += " and lig.rid = ?"
-		whereValue = append(whereValue, c.Rid)
+	selectStr := "lig.*,con.id,con.name,b.light_name,t.luminance"
+	whereStr := "lig.is_deleted = 0 and relation_type = 1 and lig.tenant_id = ? and con.group_id = ?"
+	whereValue := []interface{}{c.TenantId, groupId}
+	if searchValue != "" {
+		whereStr += " and (con.sn like '%?%' or con.name like '%?%')"
+		whereValue = append(whereValue, searchValue, searchValue)
 	}
 	err := Db.Debug().Table("t_strategy_intelligent_light lig").Select(selectStr).
-		Joins("left join t_dev_lamp_pole_group gro ON lig.rid = gro.id").
+		Joins("left join t_dev_light_control con ON lig.rid = con.id").
 		Joins("left join t_strategy_light b ON b.id = lig.light_id").
-		Where(whereStr, whereValue...).Order("lig.create_time desc").Scan(&groupRelations).Error
+		Joins("left join t_strategy_time_condition t ON t.light_id = lig.light_id").
+		Where(whereStr, whereValue...).Offset(current).Limit(size).
+		Order("lig.create_time desc").Scan(&groupRelations).Error
 	return groupRelations, err
 }

+ 9 - 9
app/device/dao/ipBroadcastDao.go

@@ -10,25 +10,24 @@ type IpBroadcast struct {
 	CastName         string     `gorm:"type:varchar(64)" json:"castName"`                 //设备名称
 	CastSN           string     `gorm:"type:varchar(60)" json:"castSN"`                   //设备序列号
 	LampPoleId       int        `gorm:"type:int" json:"LampPoleId"`                       //所属灯杆id
-	LampPoleSN       string     `gorm:"type: varchar(64)" json:"lampPoleSN"`              //所属灯杆sn
+	LampPoleSN       string     `gorm:"type:varchar(64)" json:"lampPoleSN"`               //所属灯杆sn
 	GroupId          int        `gorm:"type:int" json:"groupId"`                          //灯杆分组ID
-	GatewayID        int        `gorm:"type: int" json:"gatewayID"`                       //所属网关id
+	GatewayID        int        `gorm:"type:int" json:"gatewayID"`                        //所属网关id
 	GatewaySN        string     `gorm:"type:varchar(64)" json:"gatewaySN"`                //所属网关sn
 	BrandID          int        `gorm:"type:int" json:"brandID"`                          //设备名称
 	ModelID          int        `gorm:"type:int" json:"modelID"`                          //设备型号
 	RatedPower       float32    `gorm:"type:float(8, 2); default 0.00" json:"ratedPower"` //额定功率(LED灯)
 	IPAddress        string     `gorm:"type:varchar(50)" json:"ipAddress"`                //IP地址
 	ServiceIPAddress string     `gorm:"type:varchar(50)" json:"serviceIPAddress"`         //IP地址         //服务IP地址
-	ServerPort       int        `gorm:"type: int" json:"serverPort"`                      //服务端口
-	SoundVolume      int        `gorm:"type: int" json:"soundVolume"`                     //音量0-100换算
+	ServerPort       int        `gorm:"type:int" json:"serverPort"`                       //服务端口
+	SoundVolume      int        `gorm:"type:int" json:"soundVolume"`                      //音量0-100换算
 	InstallTime      *time.Time `gorm:"type:date" json:"installTime"`                     //安装时间
+	TenantId         int        `gorm:"type:int" json:"tenantId"`                         //租户ID
 	CreateTime       time.Time  `gorm:"type:datetime" json:"createTime"`                  //新增时间
-	CreateUser       string     `gorm:"type:varchar(60)" json:"createUser"`               //新增记录操作用户ID
+	CreateUser       int64      `gorm:"type:bigint" json:"createUser"`                    //新增记录操作用户ID
 	UpdateTime       time.Time  `gorm:"type:datetime" json:"updateTime"`                  //修改时间
-	UpdateUser       string     `gorm:"type:varchar(60)" json:"updateUser"`               //修改用户
+	UpdateUser       int64      `gorm:"type:bigint" json:"updateUser"`                    //修改用户
 	IsDeleted        int        `gorm:"type:int;default 0" json:"isDeleted"`              //是否删除 0=未删除,1=删除
-	TenantID         string     `gorm:"type:varchar(12)" json:"tenantID"`                 //租户id
-
 }
 
 func (IpBroadcast) TableName() string {
@@ -84,6 +83,7 @@ func (c IpBroadcast) GetDevices(offset, limit int) ([]IpBroadcast, error) {
 
 func (c IpBroadcast) GetAllDevices() ([]*IpBroadcast, error) {
 	var devices []*IpBroadcast
-	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantID, c.IsDeleted).Scan(&devices).Error
+	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId,
+		c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }

+ 3 - 3
app/device/dao/lampPoleDao.go

@@ -26,11 +26,11 @@ type LampPole struct {
 	IsCross         int       `gorm:"type:int" json:"isCross"`                  //是否为路口-0-是1-不是
 	InstallTime     time.Time `gorm:"type:date" json:"installTime"`             //安装时间
 	LampPolePhoto   string    `gorm:"type:varchar(255)" json:"lampPolePhoto"`   //灯杆照片
-	TenantId        string    `gorm:"type:varchar(12)" json:"tenantId"`         //租户ID
+	TenantId        int       `gorm:"type:int" json:"tenantId"`                 //租户ID
 	CreateTime      time.Time `gorm:"type:datetime" json:"createTime"`          //新增时间
-	CreateUser      string    `gorm:"type:varchar(60)" json:"createUser"`       //新增记录操作用户ID
+	CreateUser      int64     `gorm:"type:bigint" json:"createUser"`            //新增记录操作用户ID
 	UpdateTime      time.Time `gorm:"type:datetime" json:"updateTime"`          //修改时间
-	UpdateUser      string    `gorm:"type:varchar(60)" json:"updateUser"`       //修改用户
+	UpdateUser      int64     `gorm:"type:bigint" json:"updateUser"`            //修改用户
 	IsDeleted       int       `gorm:"type:int;default 0" json:"isDeleted"`      //是否删除 0=未删除,1=删除
 	Status          int       `gorm:"type:int" json:"status"`                   //状态 0=正常,1=异常
 	Tag             string    `gorm:"type:varchar(255)" json:"tag"`             //标签,(备用,逗号区分)

+ 3 - 3
app/device/dao/lampPoleGroupDao.go

@@ -9,11 +9,11 @@ import (
 type LampPoleGroup struct {
 	ID            int       `gorm:"primary_key" json:"id"`                 //编号
 	PoleGroupName string    `gorm:"type:varchar(64)" json:"poleGroupName"` //分组名称
-	TenantId      string    `gorm:"type:varchar(12)" json:"tenantId"`      //租户ID
+	TenantId      int       `gorm:"type:int" json:"tenantId"`              //租户ID
 	CreateTime    time.Time `gorm:"type:datetime" json:"createTime"`       //新增时间
-	CreateUser    string    `gorm:"type:varchar(60)" json:"createUser"`    //新增记录操作用户ID
+	CreateUser    int64     `gorm:"type:bigint" json:"createUser"`         //新增记录操作用户ID
 	UpdateTime    time.Time `gorm:"type:datetime" json:"updateTime"`       //修改时间
-	UpdateUser    string    `gorm:"type:varchar(60)" json:"updateUser"`    //修改用户
+	UpdateUser    int64     `gorm:"type:bigint" json:"updateUser"`         //修改用户
 	IsDeleted     int       `gorm:"type:int;default 0" json:"isDeleted"`   //是否删除 0=未删除,1=删除
 	Tag           string    `gorm:"type:varchar(255)" json:"tag"`          //标签,(备用,逗号区分)
 	Remark        string    `gorm:"type:varchar(255)" json:"remark"`       //备注

+ 6 - 6
app/device/dao/lightConditionDao.go

@@ -4,15 +4,15 @@ import "time"
 
 type LightCondition struct {
 	ID         int       `gorm:"primary key" json:"id"`               //编号
-	LightId    int       `gorm:"type: int" json:"lightId"`            //照明策略id
+	LightId    int       `gorm:"type:int" json:"lightId"`             //照明策略id
 	ScopeStart int       `gorm:"type:int" json:"scopeStart"`          //光照度范围开始值
-	ScopeEnd   int       `gorm:"type: int" json:"scopeEnd"`           //光照度范围结束值
+	ScopeEnd   int       `gorm:"type:int" json:"scopeEnd"`            //光照度范围结束值
 	Luminance  int       `gorm:"type:int " json:"luminance"`          //开灯亮度
 	Remark     string    `gorm:"type:varchar(255)" json:"remark"`     //备注
-	CreateTime time.Time `gorm:"type: datetime" json:"createTime"`    //新增时间
-	CreateUser string    `gorm:"type:varchar(60)" json:"createUser"`  //新增记录操作用户ID
-	UpdateTime time.Time `gorm:"type: datetime" json:"updateTime"`    //修改时间
-	UpdateUser string    `gorm:"type:varchar(60)" json:"updateUser"`  //修改用户
+	CreateTime time.Time `gorm:"type:datetime" json:"createTime"`     //新增时间
+	CreateUser int64     `gorm:"type:bigint" json:"createUser"`       //新增记录操作用户ID
+	UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`     //修改时间
+	UpdateUser int64     `gorm:"type:bigint" json:"updateUser"`       //修改用户
 	IsDeleted  int       `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
 }
 

+ 3 - 3
app/device/dao/lightControlDao.go

@@ -23,11 +23,11 @@ type LightControl struct {
 	BrandId          int       `gorm:"type:int" json:"brandId"`                   //设备品牌
 	ModelId          int       `gorm:"type:int" json:"modelId"`                   //设备型号
 	InstallTime      time.Time `gorm:"type:date" json:"installTime"`              //安装时间
-	TenantId         string    `gorm:"type:varchar(12)" json:"tenantId"`          //租户ID
+	TenantId         int       `gorm:"type:int" json:"tenantId"`                  //租户ID
 	CreateTime       time.Time `gorm:"type:datetime" json:"createTime"`           //新增时间
-	CreateUser       string    `gorm:"type:varchar(60)" json:"createUser"`        //新增记录操作用户ID
+	CreateUser       int64     `gorm:"type:bigint" json:"createUser"`             //新增记录操作用户ID
 	UpdateTime       time.Time `gorm:"type:datetime" json:"updateTime"`           //修改时间
-	UpdateUser       string    `gorm:"type:varchar(60)" json:"updateUser"`        //修改用户
+	UpdateUser       int64     `gorm:"type:bigint" json:"updateUser"`             //修改用户
 	IsDeleted        int       `gorm:"type:int;default 0" json:"isDeleted"`       //是否删除 0=未删除,1=删除
 	Status           int       `gorm:"type:int" json:"status"`                    //状态 0=正常,1=异常
 	Tag              string    `gorm:"type:varchar(255)" json:"tag"`              //标签,(备用,逗号区分)

+ 4 - 4
app/device/dao/manholeCoverDao.go

@@ -19,7 +19,7 @@ type ManholeCover struct {
 	InstallLocationType int        `gorm:"type:int" json:"installLocationType"`      //安装位置类型
 	WayName             string     `gorm:"type:varchar(60)" json:"wayName"`          //所属道路
 	InstallTime         *time.Time `gorm:"type:date" json:"installTime"`             //安装时间
-	ProvinceName        string     `gorm:" varchar(12)" json:"provinceName"`         //省份
+	ProvinceName        string     `gorm:"varchar(12)" json:"provinceName"`          //省份
 	CityName            string     `gorm:"type:varchar(12)" json:"cityName"`         //市
 	DistrictName        string     `gorm:"type:varchar(12)" json:"districtName"`     //区
 	InstallLocation     string     `gorm:"type:varchar(100)" json:"installLocation"` //安装位置
@@ -27,11 +27,11 @@ type ManholeCover struct {
 	Longitude           float64    `gorm:"type:double(17, 14)  " json:"longitude"`   //经度
 	PhotoUrl            string     `gorm:"type:varchar(255) " json:"photoUrl"`       //照片地址
 	Remark              string     `gorm:"type:varchar(1000)  " json:"remark"`       //备注
-	TenantId            string     `gorm:"type:varchar(12)" json:"tenantId"`         //租户id
+	TenantId            int        `gorm:"type:int" json:"tenantId"`                 //租户ID
 	CreateTime          time.Time  `gorm:"type:datetime" json:"createTime"`          //新增时间
-	CreateUser          string     `gorm:"type:varchar(60)" json:"createUser"`       //新增记录操作用户ID
+	CreateUser          int64      `gorm:"type:bigint" json:"createUser"`            //新增记录操作用户ID
 	UpdateTime          time.Time  `gorm:"type:datetime" json:"updateTime"`          //修改时间
-	UpdateUser          string     `gorm:"type:varchar(60)" json:"updateUser"`       //修改用户
+	UpdateUser          int64      `gorm:"type:bigint" json:"updateUser"`            //修改用户
 	IsDeleted           int        `gorm:"type:int;default 0" json:"isDeleted"`      //是否删除 0=未删除,1=删除
 	Status              int        `gorm:"type:int" json:"status"`                   //状态 0=正常,1=异常
 	Tag                 string     `gorm:"type:varchar(255)" json:"tag"`             //标签,保留字段(逗号区分)

+ 3 - 3
app/device/dao/onDemandGroupDao.go

@@ -14,11 +14,11 @@ type OnDemandGroup struct {
 	LightingNum       int       `gorm:"type:int" json:"lightingNum"`           //亮灯数量
 	BeforeLightingNum int       `gorm:"type:int" json:"beforeLightingNum"`     //提前亮灯数
 	OutTimes          int       `gorm:"type:int" json:"outTimes"`              //延迟时间
-	TenantId          string    `gorm:"type:varchar(12)" json:"tenantId"`      //租户ID
+	TenantId          int       `gorm:"type:int" json:"tenantId"`              //租户ID
 	CreateTime        time.Time `gorm:"type:datetime" json:"createTime"`       //新增时间
-	CreateUser        string    `gorm:"type:varchar(60)" json:"createUser"`    //新增记录操作用户ID
+	CreateUser        int64     `gorm:"type:bigint" json:"createUser"`         //新增记录操作用户ID
 	UpdateTime        time.Time `gorm:"type:datetime" json:"updateTime"`       //修改时间
-	UpdateUser        string    `gorm:"type:varchar(60)" json:"updateUser"`    //修改用户
+	UpdateUser        int64     `gorm:"type:bigint" json:"updateUser"`         //修改用户
 	IsDeleted         int       `gorm:"type:int;default 0" json:"isDeleted"`   //是否删除 0=未删除,1=删除
 }
 

+ 6 - 5
app/device/dao/onDemandSensorDao.go

@@ -14,12 +14,12 @@ type OnDemandSensor struct {
 	ModelID     int       `gorm:"type:int" json:"modelID"`              //设备型号
 	LampPoleID  int       `gorm:"type:int" json:"lampPoleID"`           //所属灯杆
 	SensorPhoto string    `gorm:"type:varchar(255)" json:"sensorPhoto"` //传感器照片
-	TenantID    string    `gorm:"type:varchar(12)" json:"tenantID"`     //租户ID
 	InstallTime time.Time `gorm:"type:date" json:"installTime"`         //安装时间
-	CreateTime  time.Time `gorm:"type:date" json:"creatTime"`           //新增时间
-	CreateUser  string    `gorm:"type:varchar(60)" json:"createUser"`   //新增记录操作用户ID
+	TenantId    int       `gorm:"type:int" json:"tenantId"`             //租户ID
+	CreateTime  time.Time `gorm:"type:datetime" json:"createTime"`      //新增时间
+	CreateUser  int64     `gorm:"type:bigint" json:"createUser"`        //新增记录操作用户ID
 	UpdateTime  time.Time `gorm:"type:datetime" json:"updateTime"`      //修改时间
-	UpdateUser  string    `gorm:"type:varchar(60)" json:"updateUser"`   //修改用户
+	UpdateUser  int64     `gorm:"type:bigint" json:"updateUser"`        //修改用户
 	IsDeleted   int       `gorm:"type:int; default 0" json:"isDeleted"` //是否删除:0=未删除,1=删除
 	Status      int       `gorm:"type:int; default 0" json:"status"`    //状态0=正常,1=异常
 }
@@ -77,6 +77,7 @@ func (c OnDemandSensor) GetDevices(offset, limit int) ([]OnDemandSensor, error)
 
 func (c OnDemandSensor) GetAllDevices() ([]*OnDemandSensor, error) {
 	var devices []*OnDemandSensor
-	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantID, c.IsDeleted).Scan(&devices).Error
+	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId,
+		c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }

+ 2 - 2
app/device/dao/operationHisDao.go

@@ -10,9 +10,9 @@ type OperationHis struct {
 	OperationType int       `gorm:"type:int" json:"operationType"`                              //操作类型
 	ModuleType    int       `gorm:"type:int" json:"moduleType"`                                 //操作模块
 	HandleContent string    `gorm:"type:varchar(1000)" json:"handleContent"`                    //操作内容
-	HandleUserId  string    `gorm:"type:varchar(255)" json:"handleUserId"`                      //操作用户ID
+	HandleUserId  int64     `gorm:"type:bigint" json:"handleUserId"`                            //操作用户ID
 	HandleTime    time.Time `gorm:"type:timestamp;default CURRENT_TIMESTAMP" json:"handleTime"` //操作时间
-	TenantId      string    `gorm:"type:varchar(12)" json:"tenantId"`                           //租户id
+	TenantId      int       `gorm:"type:int" json:"tenantId"`                                   //租户ID
 }
 
 func (OperationHis) TableName() string {

+ 6 - 6
app/device/dao/optoSensoDao.go

@@ -10,9 +10,9 @@ type OptoSensor struct {
 	ID               int        `gorm:"primary_key" json:"id"`                     //编号
 	Name             string     `gorm:"type:varchar(64)" json:"name"`              //名称
 	SN               string     `gorm:"type:varchar(60)" json:"sn"`                //唯一编码
-	GroupId          int        `gorm:"type:int" json:"groupId"`                   //所属灯杆分组
-	LampPoleName     string     `gorm:"type: varchar(64)" json:"lampPoleName"`     //灯杆名称
-	LampPoleSN       string     `gorm:"type: varchar(64)" json:"lampPoleSN"`       //灯杆编码
+	LampPoleId       int        `gorm:"type:int" json:"lampPoleId"`                //灯杆id
+	LampPoleName     string     `gorm:"type:varchar(64)" json:"lampPoleName"`      //灯杆名称
+	LampPoleSN       string     `gorm:"type:varchar(64)" json:"lampPoleSN"`        //灯杆编码
 	LampPoleLocation string     `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
 	LampLng          float64    `gorm:"type:double(17, 14) " json:"poleLng"`       //经度
 	LampLat          float64    `gorm:"type:double(17, 14)  " json:"poleLat"`      //纬度
@@ -22,11 +22,11 @@ type OptoSensor struct {
 	InstallTime      *time.Time `gorm:"type:date" json:"installTime"`              //安装时间
 	IPAddress        string     `gorm:"type:varchar(64)" json:"ipAddress"`         //IP地址-备用
 	IsDefault        int        `gorm:"type:int;default 0" json:"isDefault"`       //是否设为首页默认展示 0=不展示,1=设置展示
-	TenantId         string     `gorm:"type:varchar(12)" json:"tenantId"`          //租户id
+	TenantId         int        `gorm:"type:int" json:"tenantId"`                  //租户ID
 	CreateTime       time.Time  `gorm:"type:datetime" json:"createTime"`           //新增时间
-	CreateUser       string     `gorm:"type:varchar(60)" json:"createUser"`        //新增记录操作用户ID
+	CreateUser       int64      `gorm:"type:bigint" json:"createUser"`             //新增记录操作用户ID
 	UpdateTime       time.Time  `gorm:"type:datetime" json:"updateTime"`           //修改时间
-	UpdateUser       string     `gorm:"type:varchar(60)" json:"updateUser"`        //修改用户
+	UpdateUser       int64      `gorm:"type:bigint" json:"updateUser"`             //修改用户
 	IsDeleted        int        `gorm:"type:int;default 0" json:"isDeleted"`       //是否删除 0=未删除,1=删除
 	Status           int        `gorm:"type:int" json:"status"`                    //状态 0=正常,1=异常
 	Tag              string     `gorm:"type:varchar(255)" json:"tag"`              //标签,保留字段(逗号区分)

+ 3 - 3
app/device/dao/switchBoxDao.go

@@ -22,12 +22,12 @@ type SwitchBox struct {
 	PoleLng        float64   `gorm:"type:double(17, 14) " json:"poleLng"`               //经度
 	PoleLat        float64   `gorm:"type:double(17, 14)  " json:"poleLat"`              //纬度
 	MonitorAddress string    `gorm:"type:varchar(255)   " json:"monitorAddress"`        //监控地址
-	TenantId       string    `gorm:"type:varchar(12)" json:"tenantId"`                  //租户id
 	InstallTime    time.Time `gorm:"type:date" json:"installTime"`                      //安装时间
+	TenantId       int       `gorm:"type:int" json:"tenantId"`                          //租户id
 	CreateTime     time.Time `gorm:"type:datetime" json:"createTime"`                   //新增时间
-	CreateUser     string    `gorm:"type:varchar(60)" json:"createUser"`                //新增记录操作用户ID
+	CreateUser     int64     `gorm:"type:bigint" json:"createUser"`                     //新增记录操作用户ID
 	UpdateTime     time.Time `gorm:"type:datetime" json:"updateTime"`                   //修改时间
-	UpdateUser     string    `gorm:"type:varchar(60)" json:"updateUser"`                //修改用户
+	UpdateUser     int64     `gorm:"type:bigint" json:"updateUser"`                     //修改用户
 	IsDeleted      int       `gorm:"type:int;default 0" json:"isDeleted"`               //是否删除 0=未删除,1=删除
 	Status         int       `gorm:"type:int" json:"status"`                            //状态 0=正常,1=异常
 	Tag            string    `gorm:"type:varchar(255)" json:"tag"`                      //标签,保留字段(逗号区分)

+ 2 - 2
app/device/dao/timeConditionDao.go

@@ -10,9 +10,9 @@ type TimeCondition struct {
 	Luminance  int       `gorm:"type:int " json:"luminance"`          //开灯亮度
 	Remark     string    `gorm:"type:varchar(255)" json:"remark"`     //备注
 	CreateTime time.Time `gorm:"type:datetime" json:"createTime"`     //新增时间
-	CreateUser string    `gorm:"type:varchar(60)" json:"createUser"`  //新增记录操作用户ID
+	CreateUser int64     `gorm:"type:bigint" json:"createUser"`       //新增记录操作用户ID
 	UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`     //修改时间
-	UpdateUser string    `gorm:"type:varchar(60)" json:"updateUser"`  //修改用户
+	UpdateUser int64     `gorm:"type:bigint" json:"updateUser"`       //修改用户
 	IsDeleted  int       `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
 	Sunshine   int       `gorm:"type:int;default 1" json:"sunshine"`  //日出日落 设置 2=开启,1=不开启
 }

+ 3 - 3
app/device/dao/transformerDao.go

@@ -14,16 +14,16 @@ type Transformer struct {
 	ProvinceName    string     `gorm:" varchar(12)" json:"provinceName"`                  //省份
 	CityName        string     `gorm:"type:varchar(12)" json:"cityName"`                  //市
 	DistrictName    string     `gorm:"type:varchar(12)" json:"districtName"`              //区
-	TenantId        string     `gorm:"type:varchar(12)" json:"tenantId"`                  //租户id
 	InstallLocation string     `gorm:"type:varchar(100)" json:"installLocation"`          //详细位置
 	PoleLng         float64    `gorm:"type:double(17, 14) " json:"poleLng"`               //经度
 	PoleLat         float64    `gorm:"type:double(17, 14)  " json:"poleLat"`              //纬度
 	TransPhotoUrl   string     `gorm:"type:varchar(255)" json:"transPhotoUrl"`            //变压器照片地址
 	InstallTime     *time.Time `gorm:"type:date" json:"installTime"`                      //安装时间
+	TenantId        int        `gorm:"type:int" json:"tenantId"`                          //租户id
 	CreateTime      time.Time  `gorm:"type:datetime" json:"createTime"`                   //新增时间
-	CreateUser      string     `gorm:"type:varchar(60)" json:"createUser"`                //新增记录操作用户ID
+	CreateUser      int64      `gorm:"type:bigint" json:"createUser"`                     //新增记录操作用户ID
 	UpdateTime      time.Time  `gorm:"type:datetime" json:"updateTime"`                   //修改时间
-	UpdateUser      string     `gorm:"type:varchar(60)" json:"updateUser"`                //修改用户
+	UpdateUser      int64      `gorm:"type:bigint" json:"updateUser"`                     //修改用户
 	IsDeleted       int        `gorm:"type:int;default 0" json:"isDeleted"`               //是否删除 0=未删除,1=删除
 	Status          int        `gorm:"type:int" json:"status"`                            //状态 0=正常,1=异常
 }

+ 3 - 3
app/device/dao/venderDao.go

@@ -11,11 +11,11 @@ type DeviceVendor struct {
 	VendorValue string    `gorm:"type:varchar(200)" json:"vendorValue"` //值
 	ParentId    int       `gorm:"type:int" json:"parentId"`             //父id,厂家为-1
 	DeviceType  int       `gorm:"type:int" json:"deviceType"`           //设备类型
-	TenantId    string    `gorm:"type:varchar(12)" json:"tenantId"`     //租户id
+	TenantId    int       `gorm:"type:int" json:"tenantId"`             //租户id
 	CreateTime  time.Time `gorm:"type:datetime" json:"createTime"`      //新增时间
-	CreateUser  string    `gorm:"type:varchar(60)" json:"createUser"`   //新增记录操作用户ID
+	CreateUser  int64     `gorm:"type:bigint" json:"createUser"`        //新增记录操作用户ID
 	UpdateTime  time.Time `gorm:"type:datetime" json:"updateTime"`      //修改时间
-	UpdateUser  string    `gorm:"type:varchar(60)" json:"updateUser"`   //修改用户
+	UpdateUser  int64     `gorm:"type:bigint" json:"updateUser"`        //修改用户
 	IsDeleted   int       `gorm:"type:int" json:"isDeleted"`            //是否删除 0=未删除,1=删除
 }
 

+ 2 - 2
app/device/dao/workbenchDao.go

@@ -5,7 +5,7 @@ type CountDevice struct {
 	DeviceType string `json:"deviceType"`
 }
 
-func GetDeviceCount(tenantId string) ([]CountDevice, error) {
+func GetDeviceCount(tenantId int) ([]CountDevice, error) {
 	var result []CountDevice
 	var count CountDevice
 	Db.Debug().Model(&LampPole{}).Select(" count(*) count_num, 'lamppole' device_type ").
@@ -50,7 +50,7 @@ type CountAlarm struct {
 	Backlog        int `json:"backlog"`
 }
 
-func GetAlarmCount(tenantId string) (*CountAlarm, error) {
+func GetAlarmCount(tenantId int) (*CountAlarm, error) {
 	var alarm CountAlarm
 	return &alarm, nil
 }

+ 6 - 4
app/device/dao/zigbeeDao.go

@@ -10,7 +10,8 @@ type Zigbee struct {
 	ID               int        `gorm:"primary_key" json:"id"`                     //编号
 	Name             string     `gorm:"type:varchar(64)" json:"name"`              //名称
 	SN               string     `gorm:"type:varchar(60)" json:"sn"`                //唯一编码
-	GroupId          int        `gorm:"type:int" json:"groupId"`                   //所属灯杆分组
+	GroupId          int        `gorm:"type:int" json:"groupId"`                   //所属灯杆分组id
+	LampPoleId       int        `gorm:"type:int" json:"lampPoleId"`                //所属灯杆id
 	LampPoleName     string     `gorm:"type: varchar(64)" json:"lampPoleName"`     //灯杆名称
 	LampPoleSN       string     `gorm:"type: varchar(64)" json:"lampPoleSN"`       //灯杆编码
 	LampPoleLocation string     `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
@@ -24,12 +25,13 @@ type Zigbee struct {
 	ChanelNum        int        `gorm:"type:int" json:"chanelNum"`                 //通道号
 	NetworkNum       int        `gorm:"type:int" json:"networkNum"`                //网络号
 	InstallTime      *time.Time `gorm:"type:date" json:"installTime"`              //安装时间
-	TenantId         string     `gorm:"type:varchar(12)" json:"tenantId"`          //租户id
+	TenantId         int        `gorm:"type:int" json:"tenantId"`                  //租户id
 	CreateTime       time.Time  `gorm:"type:datetime" json:"createTime"`           //新增时间
-	CreateUser       string     `gorm:"type:varchar(60)" json:"createUser"`        //新增记录操作用户ID
+	CreateUser       int64      `gorm:"type:bigint" json:"createUser"`             //新增记录操作用户ID
 	UpdateTime       time.Time  `gorm:"type:datetime" json:"updateTime"`           //修改时间
-	UpdateUser       string     `gorm:"type:varchar(60)" json:"updateUser"`        //修改用户
+	UpdateUser       int64      `gorm:"type:bigint" json:"updateUser"`             //修改用户
 	IsDeleted        int        `gorm:"type:int;default 0" json:"isDeleted"`       //是否删除 0=未删除,1=删除
+	Status           int        `gorm:"type:int" json:"status"`                    //状态0=正常 状态0=正常,1=异常
 	Tag              string     `gorm:"type:varchar(255)" json:"tag"`              //标签,保留字段(逗号区分)
 	IPAddress        string     `gorm:"type:varchar(64)" json:"ipAddress"`         //IP地址-备用
 }

+ 1 - 1
app/device/model/captureUint.go

@@ -3,7 +3,7 @@ package model
 import "iot_manager_service/app/device/dao"
 
 type CaptureDetail struct {
-	dao.CaptureUint
+	dao.CaptureUnit
 	PoleName        string  `json:"poleName"`        //灯杆名称
 	PoleSn          string  `json:"poleSn"`          //灯杆编码
 	PoleLat         float32 `json:"poleLat"`         //灯杆纬度

+ 9 - 9
app/device/model/common.go

@@ -40,15 +40,15 @@ const (
 
 //redis
 const (
-	AlarmList           = "%s:AlarmList:GetList"
-	LampPoleGroupList   = "%s:LampPoleGroupList:GetList"
-	GroupFiltrationList = "%s:GroupFiltrationList:GetList"
-	GarbageList         = "%s:GarbageList:GetList"
-	GarbageWayGroupList = "%s:GarbageWayGroupList:GetList"
-	OnDemandGroupList   = "%s:OnDemandGroupList:GetList"
-	SwitchBoxList       = "%s:SwitchBoxList:GetList"
-	TransformerList     = "%s:TransformerList:GetList"
-	WisdomGatewayList   = "%s:WisdomGatewayList:GetList"
+	AlarmList           = "%d:AlarmList:GetList"
+	LampPoleGroupList   = "%d:LampPoleGroupList:GetList"
+	GroupFiltrationList = "%d:GroupFiltrationList:GetList"
+	GarbageList         = "%d:GarbageList:GetList"
+	GarbageWayGroupList = "%d:GarbageWayGroupList:GetList"
+	OnDemandGroupList   = "%d:OnDemandGroupList:GetList"
+	SwitchBoxList       = "%d:SwitchBoxList:GetList"
+	TransformerList     = "%d:TransformerList:GetList"
+	GatewayList         = "%d:GatewayList:GetList"
 )
 
 //Operation type 操作类型

+ 10 - 26
app/device/model/intelligentLighting.go

@@ -40,32 +40,16 @@ type TimeConditionSimple struct {
 }
 
 type RspIntelligentLightListDetail struct {
-	dao.IntelligentLight
-	LightControlState  string                          `json:"lightControlState"`  //灯控状态
-	RunState           string                          `json:"runState"`           //运行状态
-	PublicName         string                          `json:"publicName"`         //设备名称(灯杆与灯杆分组公用)
-	PublicId           string                          `json:"publicId"`           //设备Id(灯杆与灯杆分组公用ID)
-	GroupId            string                          `json:"groupId"`            //灯杆分组ID
-	LampPoleName       string                          `json:"lampPoleName"`       //灯杆名称
-	LampPoleSn         string                          `json:"lampPoleSn"`         //灯杆编码
-	Location           string                          `json:"location"`           //安装位置
-	InstallTime        string                          `json:"installTime"`        //安装时间
-	LampLat            string                          `json:"lampLat"`            //经度
-	LampLng            string                          `json:"lampLng"`            //纬度
-	LightName          string                          `json:"lightName"`          //策略名称
-	LightSn            string                          `json:"lightSn"`            //策略编码
-	DeviceSn           string                          `json:"deviceSn"`           //灯控设备编码
-	StartTime          string                          `json:"startTime"`          //生效日期-策略开始时间
-	EndTime            string                          `json:"endTime"`            //生效日期-策略结束时间
-	ControlType        int                             `json:"controlType"`        //灯控类型
-	IsAllYear          int                             `json:"isAllYear"`          //全年设置2=是,1=否
-	IsAutomaticRenewal int                             `json:"isAutomaticRenewal"` //自动续期设置 2=是,1=否
-	EffectiveDate      int                             `json:"effectiveDate"`      //生效日期
-	Children           []RspIntelligentLightListDetail `json:"children"`           //灯控子集
-	CombinationStrList []string                        `json:"combinationStrList"` //照明策略条件组合展示集合
-	CombinationStr     string                          `json:"combinationStr"`     //详情照明策略组合展示
-	IsShowOpts         string                          `json:"isShowOpts"`         //页面是否显示操作按钮
-	HandSwitch         int                             `json:"handSwitch"`         //手动开关:1=开启,2,关闭
+	LightControlState int    `json:"lightControlState"` //灯控状态
+	RunState          int    `json:"runState"`          //运行状态
+	PublicName        string `json:"publicName"`        //设备名称(灯杆与灯杆分组公用)
+	PublicId          int    `json:"publicId"`          //设备Id(灯杆与灯杆分组公用ID)
+	LampPoleName      string `json:"lampPoleName"`      //灯杆名称
+	LampPoleSn        string `json:"lampPoleSn"`        //灯杆编码
+	StrategyName      string `json:"strategyName"`      //策略名称
+	DeviceSn          string `json:"deviceSn"`          //灯控设备编码
+	ControlType       int    `json:"controlType"`       //灯控类型
+	IsShowOpts        bool   `json:"isShowOpts"`        //页面是否显示操作按钮
 }
 
 type RspIntelligentLightList struct {

+ 12 - 15
app/device/service/LightStrategyService.go

@@ -35,17 +35,14 @@ func (s *lightStrategyService) Get(id int) (*model.LightStrategyDetail, *util.Er
 	}
 	lightStrategy.LightType = lightStrategy.LightType + "策略"
 	return lightStrategy, nil
-
 }
 
-func (s *lightStrategyService) CreateOrUpdate(req *model.LightStrategyDetail) *util.Errors {
+func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *model.LightStrategyDetail) *util.Errors {
 	// 创建查询实例
 	strategy := req
 	fmt.Printf("CreateOrUpdate strategy = %+v \n", strategy)
-	if strategy.TenantID == "" {
-		strategy.TenantID = "000000" // todo: 使用登录态
-	}
-	strategy.UpdateUser = "TODO" // todo: 使用登录态
+	strategy.TenantId = tenantId
+	strategy.UpdateUser = userId
 	strategy.UpdateTime = time.Now()
 
 	if len(strategy.LightConditionList) == 0 {
@@ -80,7 +77,7 @@ func (s *lightStrategyService) CreateOrUpdate(req *model.LightStrategyDetail) *u
 
 	if req.ID == 0 {
 		strategy.CreateTime = time.Now()
-		strategy.CreateUser = "TODO" // todo: 使用登录态
+		strategy.CreateUser = userId
 		if strategy.IsExistedBySN() {
 			fmt.Printf("Create GetstrategyID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -101,10 +98,10 @@ func (s *lightStrategyService) CreateOrUpdate(req *model.LightStrategyDetail) *u
 		overlapList = append(overlapList, lightCondition)
 
 		if lightCondition.ID == 0 {
-			lightCondition.CreateUser = "TODO" //todo 登录态
+			lightCondition.CreateUser = userId
 			lightCondition.CreateTime = time.Now()
 		} else {
-			lightCondition.UpdateUser = "TODO" //todo 登录态
+			lightCondition.UpdateUser = userId
 			lightCondition.UpdateTime = time.Now()
 		}
 		lightCondition.LightId = req.ID
@@ -142,18 +139,18 @@ func (s *lightStrategyService) CreateOrUpdate(req *model.LightStrategyDetail) *u
 			return util.FailResponse(model.TimeConditionInvalid, nil)
 		}
 		if timeCondition.ID == 0 {
-			timeCondition.CreateUser = "TODO" //todo 登录态
+			timeCondition.CreateUser = userId
 			timeCondition.CreateTime = time.Now()
 		} else {
-			timeCondition.UpdateUser = "TODO" //todo 登录态
+			timeCondition.UpdateUser = userId
 			timeCondition.UpdateTime = time.Now()
 		}
 		timeCondition.LightId = req.ID
 		if timeCondition.ID == 0 {
-			timeCondition.CreateUser = "TODO" //todo 登录态
+			timeCondition.CreateUser = userId
 			timeCondition.CreateTime = time.Now()
 		}
-		timeCondition.UpdateUser = "TODO" //todo 登录态
+		timeCondition.UpdateUser = userId
 		timeCondition.UpdateTime = time.Now()
 
 		timeList = append(timeList, timeCondition)
@@ -226,12 +223,12 @@ func (s *lightStrategyService) List(searchValue string, current, size int) ([]mo
 	return details, nil
 }
 
-func (s *lightStrategyService) Remove(id int) *util.Errors {
+func (s *lightStrategyService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	strategy := &dao.LightStrategy{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 

+ 11 - 13
app/device/service/alarmService.go

@@ -25,17 +25,15 @@ func (s *alarmService) Get(id int) (*dao.Alarm, *util.Errors) {
 	return device, nil
 }
 
-func (s *alarmService) CreateOrUpdate(req dao.Alarm) *util.Errors {
+func (s *alarmService) CreateOrUpdate(userId int64, tenantId int, req dao.Alarm) *util.Errors {
 	device := req
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -74,12 +72,12 @@ func (s *alarmService) List(poleGroupName string, current, size int) ([]dao.Alar
 	return devices, nil
 }
 
-func (s *alarmService) Remove(id int) *util.Errors {
+func (s *alarmService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Alarm{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 
@@ -94,24 +92,24 @@ func (s *alarmService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *alarmService) GetList() ([]*dao.Alarm, *util.Errors) {
+func (s *alarmService) GetList(tenantId int) ([]*dao.Alarm, *util.Errors) {
 	var devices []*dao.Alarm
-	err := util.Redis.Get(getAlarmListRedisKey("000000")).Scan(&devices)
+	err := util.Redis.Get(getAlarmListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 	device := &dao.Alarm{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getAlarmListRedisKey("000000"), devices, 0).Err()
+	_ = util.Redis.Set(getAlarmListRedisKey(tenantId), devices, 0).Err()
 	return devices, nil
 }
 
-func getAlarmListRedisKey(tenantId string) string {
+func getAlarmListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.AlarmList, tenantId)
 }

+ 6 - 8
app/device/service/alarmTerminalService.go

@@ -25,17 +25,15 @@ func (s *alarmTerminalService) Get(id int) (*dao.AlarmTerminal, *util.Errors) {
 	return device, nil
 }
 
-func (s *alarmTerminalService) CreateOrUpdate(req dao.AlarmTerminal) *util.Errors {
+func (s *alarmTerminalService) CreateOrUpdate(userId int64, tenantId int, req dao.AlarmTerminal) *util.Errors {
 	device := req
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -74,12 +72,12 @@ func (s *alarmTerminalService) List(poleGroupName string, current, size int) ([]
 	return devices, nil
 }
 
-func (s *alarmTerminalService) Remove(id int) *util.Errors {
+func (s *alarmTerminalService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.AlarmTerminal{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 

+ 10 - 10
app/device/service/bridgeSensorService.go

@@ -22,17 +22,17 @@ func (s *bridgeSensorService) Get(id int) (*dao.BridgeSensor, *util.Errors) {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
 	return device, nil
-
 }
 
-func (s *bridgeSensorService) CreateOrUpdate(req dao.BridgeSensor) *util.Errors {
+func (s *bridgeSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.BridgeSensor) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantID = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -70,12 +70,12 @@ func (s *bridgeSensorService) List(searchValue string, current, size int) ([]dao
 	}
 	return devices, nil
 }
-func (s *bridgeSensorService) Remove(id int) *util.Errors {
+func (s *bridgeSensorService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.BridgeSensor{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -89,22 +89,22 @@ func (s *bridgeSensorService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *bridgeSensorService) GetList() ([]*dao.BridgeSensor, *util.Errors) {
+func (s *bridgeSensorService) GetList(tenantId int) ([]*dao.BridgeSensor, *util.Errors) {
 	var devices []*dao.BridgeSensor
-	err := util.Redis.Get(getTransformerListRedisKey("000000")).Scan(&devices)
+	err := util.Redis.Get(getTransformerListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 
 	device := &dao.BridgeSensor{
-		TenantID:  "000000", // todo 使用登录态
+		TenantID:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getTransformerListRedisKey("000000"), devices, 0).Err()
+	_ = util.Redis.Set(getTransformerListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }

+ 10 - 7
app/device/service/bridgeService.go

@@ -24,14 +24,15 @@ func (s *bridgeService) Get(id int) (*dao.Bridge, *util.Errors) {
 
 }
 
-func (s *bridgeService) CreateOrUpdate(req dao.Bridge) *util.Errors {
+func (s *bridgeService) CreateOrUpdate(userId int64, tenantId int, req dao.Bridge) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -55,6 +56,7 @@ func (s *bridgeService) CreateOrUpdate(req dao.Bridge) *util.Errors {
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *bridgeService) List(searchValue string, current, size int) ([]dao.Bridge, *util.Errors) {
 	device := dao.Bridge{}
 	if searchValue != "" {
@@ -70,12 +72,13 @@ func (s *bridgeService) List(searchValue string, current, size int) ([]dao.Bridg
 	}
 	return devices, nil
 }
-func (s *bridgeService) Remove(id int) *util.Errors {
+
+func (s *bridgeService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Bridge{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -89,10 +92,10 @@ func (s *bridgeService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *bridgeService) GetList() ([]*dao.Bridge, *util.Errors) {
+func (s *bridgeService) GetList(tenantId int) ([]*dao.Bridge, *util.Errors) {
 	// todo use redis cache
 	device := &dao.Bridge{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 8 - 10
app/device/service/cameraService.go

@@ -14,12 +14,10 @@ var CameraService = new(cameraService)
 
 type cameraService struct{}
 
-func (s *cameraService) CreateOrUpdate(req *model.CameraDetail) *util.Errors {
+func (s *cameraService) CreateOrUpdate(userId int64, tenantId int, req *model.CameraDetail) *util.Errors {
 	device := req.CameraDevice
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if device.LampPoleId != 0 {
 		lampPole, err := LampPoleService.GetOne(device.LampPoleId)
@@ -37,7 +35,7 @@ func (s *cameraService) CreateOrUpdate(req *model.CameraDetail) *util.Errors {
 
 	if device.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -114,12 +112,12 @@ func (s *cameraService) List(searchValue, cameraType string, current, size int)
 	return details, nil
 }
 
-func (s *cameraService) Remove(id int) *util.Errors {
+func (s *cameraService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.CameraDevice{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 
@@ -131,9 +129,9 @@ func (s *cameraService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *cameraService) GetList() ([]dao.CameraDevice, *util.Errors) {
+func (s *cameraService) GetList(tenantId int) ([]dao.CameraDevice, *util.Errors) {
 	device := &dao.CameraDevice{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 23 - 27
app/device/service/captureUintService.go

@@ -13,12 +13,10 @@ var CaptureUintService = new(captureUintService)
 
 type captureUintService struct{}
 
-func (s *captureUintService) CaptureSubmit(req *model.CaptureDetail) *util.Errors {
-	device := req.CaptureUint
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+func (s *captureUintService) CaptureSubmit(userId int64, tenantId int, req *model.CaptureDetail) *util.Errors {
+	device := req.CaptureUnit
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if gateway, err := GatewayService.GetOne(device.GatewayId); err == nil {
 		device.GatewayName = gateway.GatewayName
@@ -27,7 +25,7 @@ func (s *captureUintService) CaptureSubmit(req *model.CaptureDetail) *util.Error
 
 	if device.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -52,14 +50,14 @@ func (s *captureUintService) CaptureSubmit(req *model.CaptureDetail) *util.Error
 
 func (s *captureUintService) GetCapture(id int) (*model.CaptureDetail, *util.Errors) {
 	// 创建查询实例
-	device := &dao.CaptureUint{
+	device := &dao.CaptureUnit{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	detail := &model.CaptureDetail{CaptureUint: *device}
+	detail := &model.CaptureDetail{CaptureUnit: *device}
 	//todo 获取实时在线最新数据
 	// detail.EndLineTime = *
 	// detail.NetworkState = *
@@ -69,7 +67,7 @@ func (s *captureUintService) GetCapture(id int) (*model.CaptureDetail, *util.Err
 
 func (s *captureUintService) CaptureList(searchValue string, current, size int) ([]model.CaptureDetail, *util.Errors) {
 	var details []model.CaptureDetail
-	device := dao.CaptureUint{}
+	device := dao.CaptureUnit{}
 
 	if searchValue != "" {
 		device.CaptureSN = searchValue
@@ -85,7 +83,7 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
 
 	for _, d := range devices {
 		details = append(details, model.CaptureDetail{
-			CaptureUint: d,
+			CaptureUnit: d,
 			//todo 获取实时在线最新数据
 			// detail.EndLineTime = *
 			// detail.NetworkState = *
@@ -96,9 +94,9 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
 	return details, nil
 }
 
-func (s *captureUintService) CaptureGetList() ([]*dao.CaptureUint, *util.Errors) {
-	device := &dao.CaptureUint{
-		TenantId:  "000000", // todo 使用登录态
+func (s *captureUintService) CaptureGetList(tenantId int) ([]*dao.CaptureUnit, *util.Errors) {
+	device := &dao.CaptureUnit{
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()
@@ -124,17 +122,15 @@ func (s *captureUintService) GetPoint(id int) (*dao.CheckPoint, *util.Errors) {
 	return device, nil
 }
 
-func (s *captureUintService) PointSubmit(req *dao.CheckPoint) *util.Errors {
+func (s *captureUintService) PointSubmit(userId int64, tenantId int, req *dao.CheckPoint) *util.Errors {
 	device := req
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 
 	if device.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -172,9 +168,9 @@ func (s *captureUintService) PointList(searchValue string, current, size int) ([
 	return devices, nil
 }
 
-func (s *captureUintService) PointGetList() ([]*dao.CheckPoint, *util.Errors) {
+func (s *captureUintService) PointGetList(tenantId int) ([]*dao.CheckPoint, *util.Errors) {
 	device := &dao.CheckPoint{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()
@@ -187,12 +183,12 @@ func (s *captureUintService) PointGetList() ([]*dao.CheckPoint, *util.Errors) {
 	return devices, nil
 }
 
-func (s *captureUintService) RemoveCapture(id int) *util.Errors {
+func (s *captureUintService) RemoveCapture(userId int64, id int) *util.Errors {
 	// 创建查询实例
-	device := &dao.CaptureUint{
+	device := &dao.CaptureUnit{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 
@@ -204,12 +200,12 @@ func (s *captureUintService) RemoveCapture(id int) *util.Errors {
 	return nil
 }
 
-func (s *captureUintService) RemovePoint(id int) *util.Errors {
+func (s *captureUintService) RemovePoint(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.CheckPoint{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 

+ 11 - 8
app/device/service/garbageService.go

@@ -25,14 +25,15 @@ func (s *garbageService) Get(id int) (*dao.Garbage, *util.Errors) {
 
 }
 
-func (s *garbageService) CreateOrUpdate(req dao.Garbage) *util.Errors {
+func (s *garbageService) CreateOrUpdate(userId int64, tenantId int, req dao.Garbage) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.UpdateUser = userId
+	device.TenantId = tenantId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -55,6 +56,7 @@ func (s *garbageService) CreateOrUpdate(req dao.Garbage) *util.Errors {
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *garbageService) List(searchValue string, current, size int) ([]dao.Garbage, *util.Errors) {
 	device := dao.Garbage{}
 	if searchValue != "" {
@@ -70,12 +72,13 @@ func (s *garbageService) List(searchValue string, current, size int) ([]dao.Garb
 	}
 	return devices, nil
 }
-func (s *garbageService) Remove(id int) *util.Errors {
+
+func (s *garbageService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Garbage{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -89,21 +92,21 @@ func (s *garbageService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *garbageService) GetList() ([]*dao.Garbage, *util.Errors) {
+func (s *garbageService) GetList(tenantId int) ([]*dao.Garbage, *util.Errors) {
 	var devices []*dao.Garbage
 	err := util.Redis.Get(getGarbageListRedisKey("000000")).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 	device := &dao.Garbage{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getAlarmListRedisKey("000000"), devices, 0).Err()
+	_ = util.Redis.Set(getAlarmListRedisKey(tenantId), devices, 0).Err()
 	return devices, nil
 }
 

+ 10 - 7
app/device/service/garbageWayGroupService.go

@@ -25,14 +25,15 @@ func (s *garbageWayGroupService) Get(id int) (*dao.GarbageWayGroup, *util.Errors
 
 }
 
-func (s *garbageWayGroupService) CreateOrUpdate(req dao.GarbageWayGroup) *util.Errors {
+func (s *garbageWayGroupService) CreateOrUpdate(userId int64, tenantId int, req dao.GarbageWayGroup) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedByName() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("存在重名,请更改名称!", nil)
@@ -55,6 +56,7 @@ func (s *garbageWayGroupService) CreateOrUpdate(req dao.GarbageWayGroup) *util.E
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *garbageWayGroupService) List(searchValue string, current, size int) ([]dao.GarbageWayGroup, *util.Errors) {
 	device := dao.GarbageWayGroup{}
 	//if searchValue != "" {
@@ -70,12 +72,13 @@ func (s *garbageWayGroupService) List(searchValue string, current, size int) ([]
 	}
 	return devices, nil
 }
-func (s *garbageWayGroupService) Remove(id int) *util.Errors {
+
+func (s *garbageWayGroupService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.GarbageWayGroup{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -89,14 +92,14 @@ func (s *garbageWayGroupService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *garbageWayGroupService) GetList() ([]*dao.GarbageWayGroup, *util.Errors) {
+func (s *garbageWayGroupService) GetList(tenantId int) ([]*dao.GarbageWayGroup, *util.Errors) {
 	var devices []*dao.GarbageWayGroup
 	err := util.Redis.Get(getGarbageWayGroupListRedisKey("000000")).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 	device := &dao.GarbageWayGroup{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err = device.GetAllDevices()

+ 0 - 113
app/device/service/gatewayRelationService.go

@@ -1,11 +1,8 @@
 package service
 
 import (
-	"fmt"
 	"iot_manager_service/app/device/dao"
-	"iot_manager_service/app/device/model"
 	"iot_manager_service/util"
-	"time"
 )
 
 // 中间件管理服务
@@ -24,113 +21,3 @@ func (s *gatewayRelationService) Get(id int) (*dao.GatewayRelation, *util.Errors
 	}
 	return relation, nil
 }
-
-func (s *gatewayRelationService) Create(req *model.GatewayDetail) *util.Errors {
-	device := req.Gateway
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
-	device.UpdateTime = time.Now()
-	if device.LampPoleId != 0 {
-		lampPole, err := LampPoleService.GetOne(device.LampPoleId)
-		if err == nil {
-			device.LampLat = lampPole.PoleLat
-			device.LampLng = lampPole.PoleLng
-			device.LampPoleName = lampPole.PoleName
-			device.LampPoleSn = lampPole.PoleSN
-			device.LampPoleLocation = lampPole.InstallLocation
-		} else {
-			fmt.Printf("LampPoleService.GetOne err = %v \n", err)
-		}
-	}
-
-	if device.ID == 0 {
-		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
-
-		if device.IsExistedBySN() {
-			fmt.Printf("Create IsExistedBySN \n")
-			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 util.FailResponse(err.Error(), nil)
-		}
-		return util.SuccessResponse(util.Succeeded, nil)
-	}
-
-	if err := device.Update(); err != nil {
-		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
-	}
-
-	//todo operation record
-	return util.SuccessResponse(util.Succeeded, nil)
-}
-
-func (s *gatewayRelationService) Update(req *model.GatewayDetail) *util.Errors {
-	device := req.Gateway
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
-	device.UpdateTime = time.Now()
-	if device.LampPoleId != 0 {
-		lampPole, err := LampPoleService.GetOne(device.LampPoleId)
-		if err == nil {
-			device.LampLat = lampPole.PoleLat
-			device.LampLng = lampPole.PoleLng
-			device.LampPoleName = lampPole.PoleName
-			device.LampPoleSn = lampPole.PoleSN
-			device.LampPoleLocation = lampPole.InstallLocation
-		} else {
-			fmt.Printf("LampPoleService.GetOne err = %v \n", err)
-		}
-	}
-
-	if device.ID == 0 {
-		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
-
-		if device.IsExistedBySN() {
-			fmt.Printf("Create IsExistedBySN \n")
-			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 util.FailResponse(err.Error(), nil)
-		}
-		return util.SuccessResponse(util.Succeeded, nil)
-	}
-
-	if err := device.Update(); err != nil {
-		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
-	}
-
-	//todo operation record
-	return util.SuccessResponse(util.Succeeded, nil)
-}
-
-func (s *gatewayRelationService) Remove(id int) *util.Errors {
-	// 创建查询实例
-	device := &dao.Gateway{
-		ID:         id,
-		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
-		UpdateTime: time.Now(),
-	}
-
-	//todo
-	// service.gatewayService.CountRelation()
-
-	//todo operation record
-	err := device.Delete()
-	if err != nil {
-		return util.FailResponse(err.Error(), nil)
-	}
-	return nil
-}

+ 12 - 14
app/device/service/gatewayService.go

@@ -38,12 +38,10 @@ func (s *gatewayService) Get(id int) (*model.GatewayDetail, *util.Errors) {
 	return detail, nil
 }
 
-func (s *gatewayService) CreateOrUpdate(req *model.GatewayDetail) *util.Errors {
+func (s *gatewayService) CreateOrUpdate(userId int64, tenantId int, req *model.GatewayDetail) *util.Errors {
 	device := req.Gateway
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if device.LampPoleId != 0 {
 		lampPole, err := LampPoleService.GetOne(device.LampPoleId)
@@ -60,7 +58,7 @@ func (s *gatewayService) CreateOrUpdate(req *model.GatewayDetail) *util.Errors {
 
 	if device.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -108,12 +106,12 @@ func (s *gatewayService) List(searchValue string, current, size int) ([]model.Ga
 	return details, nil
 }
 
-func (s *gatewayService) Remove(id int) *util.Errors {
+func (s *gatewayService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Gateway{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 
@@ -129,15 +127,15 @@ func (s *gatewayService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *gatewayService) GetList() ([]*dao.Gateway, *util.Errors) {
+func (s *gatewayService) GetList(tenantId int) ([]*dao.Gateway, *util.Errors) {
 	var devices []*dao.Gateway
-	err := util.Redis.Get(getGatewayListRedisKey("000000")).Scan(&devices)
+	err := util.Redis.Get(getGatewayListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 
 	device := &dao.Gateway{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err = device.GetAllDevices()
@@ -147,13 +145,13 @@ func (s *gatewayService) GetList() ([]*dao.Gateway, *util.Errors) {
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getGatewayListRedisKey("000000"), devices, 0).Err()
+	_ = util.Redis.Set(getGatewayListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
 
-func getGatewayListRedisKey(tenantId string) string {
-	return fmt.Sprintf(model.WisdomGatewayList, tenantId)
+func getGatewayListRedisKey(tenantId int) string {
+	return fmt.Sprintf(model.GatewayList, tenantId)
 }
 
 func (s *gatewayService) GetRelevanceDetail(id int) (*model.GatewayDetail, *util.Errors) {

+ 8 - 5
app/device/service/infoBoardService.go

@@ -24,14 +24,15 @@ func (s *infoBoardService) Get(id int) (*dao.InfoBoard, *util.Errors) {
 
 }
 
-func (s *infoBoardService) CreateOrUpdate(req dao.InfoBoard) *util.Errors {
+func (s *infoBoardService) CreateOrUpdate(userId int64, tenantId int, req dao.InfoBoard) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -54,6 +55,7 @@ func (s *infoBoardService) CreateOrUpdate(req dao.InfoBoard) *util.Errors {
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *infoBoardService) List(searchValue string, current, size int) ([]dao.InfoBoard, *util.Errors) {
 	device := dao.InfoBoard{}
 	if searchValue != "" {
@@ -69,12 +71,13 @@ func (s *infoBoardService) List(searchValue string, current, size int) ([]dao.In
 	}
 	return devices, nil
 }
-func (s *infoBoardService) Remove(id int) *util.Errors {
+
+func (s *infoBoardService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.InfoBoard{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo

+ 27 - 38
app/device/service/intelligentLightingService.go

@@ -13,7 +13,8 @@ var IntelligentLightingService = new(intelligentLightingService)
 
 type intelligentLightingService struct{}
 
-func (s *intelligentLightingService) GetDetailByLight(id int) (model.RspIntelligentLightDetail, *util.Errors) {
+func (s *intelligentLightingService) GetDetailByLight(tenantId, id int) (model.RspIntelligentLightDetail,
+	*util.Errors) {
 	detail := model.RspIntelligentLightDetail{}
 	lightControl, _ := LightControlService.GetOne(id)
 	if lightControl != nil {
@@ -21,30 +22,18 @@ func (s *intelligentLightingService) GetDetailByLight(id int) (model.RspIntellig
 		detail.LightControlList = []dao.LightControl{*lightControl}
 		detail.LampPoleName = lightControl.LampPoleName
 	}
-	detail.LightRelMap = s.GetLightRelation(id, model.RelationTypeLight)
-	return detail, nil
-}
-
-func (s *intelligentLightingService) GetDetailByGroup(id int) (model.RspIntelligentLightDetailByGroup, *util.Errors) {
-	detail := model.RspIntelligentLightDetailByGroup{}
-	lampPoleGroup, _ := LightControlService.GetByGroupId(id)
-	if len(lampPoleGroup) > 0 {
-		detail.LightControlList = lampPoleGroup
-		detail.LampPoleGroupName = lampPoleGroup[0].LampPoleName
-	}
-	detail.CountLampPole = LampPoleService.CountLampPole(id)
-	detail.LightRelMap = s.GetLightRelation(id, model.RelationTypeLampPoleGroup)
+	detail.LightRelMap = s.GetLightRelation(tenantId, id, model.RelationTypeLight)
 	return detail, nil
 }
 
-func (s *intelligentLightingService) GetLightRelation(rId, relationType int) model.IntelligentLightSimple {
+func (s *intelligentLightingService) GetLightRelation(tenantId, rId, relationType int) model.IntelligentLightSimple {
 	detail := model.IntelligentLightSimple{}
 
 	// 获取照明策略关联
 	intelligentLight := dao.IntelligentLight{
 		Rid:          rId,
 		RelationType: relationType,
-		TenantID:     "000000", //todo 使用登录态
+		TenantId:     tenantId,
 	}
 	relations, _ := intelligentLight.GetByRidAndType()
 	if len(relations) == 0 {
@@ -54,6 +43,7 @@ func (s *intelligentLightingService) GetLightRelation(rId, relationType int) mod
 
 	// 获取策略详情(日期,如果是年,使用当前年起始日期)
 	lightStrategy, _ := LightStrategyService.GetOne(lightId)
+
 	if lightStrategy == nil {
 		return detail
 	}
@@ -95,40 +85,39 @@ func (s *intelligentLightingService) BatchGet(ids []int) []dao.IntelligentLight
 	return intelligentLights
 }
 
-func (s *intelligentLightingService) List(searchValue, groupId string, current, size int) ([]model.RspIntelligentLightListDetail,
-	*util.Errors) {
+func (s *intelligentLightingService) List(tenantId int, searchValue string, current, size,
+	groupId int) ([]model.RspIntelligentLightListDetail, error) {
 	var result []model.RspIntelligentLightListDetail
 	//获取策略关联信息
 	intelligent := &dao.IntelligentLight{
 		RelationType: model.RelationTypeLampPoleGroup,
-		TenantID:     "000000", //todo 使用登录态
+		TenantId:     tenantId,
 	}
-	gId := -1
-	if groupId != "" {
-		gId, _ = strconv.Atoi(groupId)
-		intelligent.Rid = gId
+
+	list, err := intelligent.GetByGroup(searchValue, current, size, groupId)
+	if err != nil {
+		return nil, nil
 	}
-	list, err := intelligent.GetByType()
 	for _, intelligentLight := range list {
 		detail := model.RspIntelligentLightListDetail{
-			IntelligentLight:   intelligentLight.IntelligentLight,
-			PublicName:         intelligentLight.LampPoleGroup.PoleGroupName,
-			PublicId:           strconv.Itoa(intelligentLight.LampPoleGroup.ID),
-			LightName:          intelligentLight.LightName,
-			LightSn:            intelligentLight.LightSn,
-			DeviceSn:           "全组",
-			StartTime:          intelligentLight.StartTime,
-			EndTime:            intelligentLight.EndTime,
-			IsAllYear:          intelligentLight.IsAllYear,
-			IsAutomaticRenewal: intelligentLight.IsAutomaticRenewal,
+			PublicName:   intelligentLight.LightControl.Name,
+			PublicId:     intelligentLight.LightControl.ID,
+			LampPoleName: intelligentLight.LightControl.LampPoleName,
+			LampPoleSn:   intelligentLight.LightControl.LampPoleSN,
+			StrategyName: intelligentLight.LightName,
+			DeviceSn:     intelligentLight.LightControl.SN,
+			ControlType:  intelligentLight.LightControl.ControlType,
+			IsShowOpts:   true,
 		}
-		if len(detail.Children) > 0 {
-			detail.IsShowOpts = "true"
+
+		if intelligentLight.Luminance > 0 {
+			detail.LightControlState = 1
+		} else {
+			detail.LightControlState = 2
 		}
+		detail.RunState = util.GetDeviceState(detail.DeviceSn)
 		result = append(result, detail)
 	}
-	fmt.Printf("list = %+v \n", list)
-	fmt.Printf("err = %v \n", err)
 
 	return result, nil
 }

+ 10 - 7
app/device/service/ipBroadcastService.go

@@ -24,14 +24,15 @@ func (s *ipBroadcastService) Get(id int) (*dao.IpBroadcast, *util.Errors) {
 
 }
 
-func (s *ipBroadcastService) CreateOrUpdate(req dao.IpBroadcast) *util.Errors {
+func (s *ipBroadcastService) CreateOrUpdate(userId int64, tenantId int, req dao.IpBroadcast) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -54,6 +55,7 @@ func (s *ipBroadcastService) CreateOrUpdate(req dao.IpBroadcast) *util.Errors {
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *ipBroadcastService) List(searchValue string, current, size int) ([]dao.IpBroadcast, *util.Errors) {
 	device := dao.IpBroadcast{}
 	if searchValue != "" {
@@ -69,12 +71,13 @@ func (s *ipBroadcastService) List(searchValue string, current, size int) ([]dao.
 	}
 	return devices, nil
 }
-func (s *ipBroadcastService) Remove(id int) *util.Errors {
+
+func (s *ipBroadcastService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.IpBroadcast{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -88,9 +91,9 @@ func (s *ipBroadcastService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *ipBroadcastService) GetList() ([]*dao.IpBroadcast, *util.Errors) {
+func (s *ipBroadcastService) GetList(tenantId int) ([]*dao.IpBroadcast, *util.Errors) {
 	device := &dao.IpBroadcast{
-		TenantID:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 24 - 27
app/device/service/lampPoleGroupService.go

@@ -26,19 +26,16 @@ func (s *lampPoleGroupService) Get(id int) (*dao.LampPoleGroup, *util.Errors) {
 	return device, nil
 }
 
-func (s *lampPoleGroupService) CreateOrUpdate(req *dao.LampPoleGroup) *util.Errors {
+func (s *lampPoleGroupService) CreateOrUpdate(userId int64, tenantId int, req *dao.LampPoleGroup) *util.Errors {
 	var build strings.Builder
-
 	device := req
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		build.WriteString("新增(灯杆分组)【" + device.PoleGroupName + "】")
 		if device.IsExistedByName() {
 			fmt.Printf("Create IsExistedByName \n")
@@ -47,11 +44,11 @@ func (s *lampPoleGroupService) CreateOrUpdate(req *dao.LampPoleGroup) *util.Erro
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
 			build.WriteString("失败")
-			OperationHisService.Save(model.OperationRemove, model.ModuleTypeDevice, build.String())
+			OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
 			return util.FailResponse(err.Error(), nil)
 		}
 		build.WriteString("成功")
-		OperationHisService.Save(model.OperationRemove, model.ModuleTypeDevice, build.String())
+		OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
 		return util.SuccessResponse(util.Succeeded, nil)
 	}
 
@@ -65,13 +62,13 @@ func (s *lampPoleGroupService) CreateOrUpdate(req *dao.LampPoleGroup) *util.Erro
 		fmt.Printf("Update err = %s \n", err.Error())
 		build.WriteString("失败")
 
-		OperationHisService.Save(model.OperationRemove, model.ModuleTypeDevice, build.String())
+		OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
 
 		return util.FailResponse(err.Error(), nil)
 	}
 	build.WriteString("成功")
 
-	OperationHisService.Save(model.OperationRemove, model.ModuleTypeDevice, build.String())
+	OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
 
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
@@ -92,13 +89,13 @@ func (s *lampPoleGroupService) List(poleGroupName string, current, size int) ([]
 	return devices, nil
 }
 
-func (s *lampPoleGroupService) Remove(id int, name string) *util.Errors {
+func (s *lampPoleGroupService) Remove(userId int64, tenantId int, id int, name string) *util.Errors {
 	var build strings.Builder
 
 	device := &dao.LampPoleGroup{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 
@@ -108,47 +105,47 @@ func (s *lampPoleGroupService) Remove(id int, name string) *util.Errors {
 	err := device.Delete()
 	if err != nil {
 		build.WriteString("失败")
-		OperationHisService.Save(model.OperationRemove, model.ModuleTypeDevice, build.String())
+		OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
 		return util.FailResponse(err.Error(), nil)
 	}
 	build.WriteString("成功")
-	OperationHisService.Save(model.OperationRemove, model.ModuleTypeDevice, build.String())
+	OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
 	return nil
 }
 
-func (s *lampPoleGroupService) GetList() ([]*dao.LampPoleGroup, *util.Errors) {
+func (s *lampPoleGroupService) GetList(tenantId int) ([]*dao.LampPoleGroup, *util.Errors) {
 	var devices []*dao.LampPoleGroup
-	err := util.Redis.Get(getLampPoleGroupListRedisKey("000000")).Scan(&devices)
+	err := util.Redis.Get(getLampPoleGroupListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 
 	device := &dao.LampPoleGroup{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getLampPoleGroupListRedisKey("000000"), devices, 0).Err()
+	_ = util.Redis.Set(getLampPoleGroupListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
 
-func getLampPoleGroupListRedisKey(tenantId string) string {
+func getLampPoleGroupListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.LampPoleGroupList, tenantId)
 }
 
-func (s *lampPoleGroupService) GetFiltration() ([]*dao.LampPoleGroup, *util.Errors) {
+func (s *lampPoleGroupService) GetFiltration(tenantId int) ([]*dao.LampPoleGroup, *util.Errors) {
 	var devices []*dao.LampPoleGroup
-	err := util.Redis.Get(getGroupFiltrationListRedisKey("000000")).Scan(&devices)
+	err := util.Redis.Get(getGroupFiltrationListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 
 	device := &dao.LampPoleGroup{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 
@@ -160,19 +157,19 @@ func (s *lampPoleGroupService) GetFiltration() ([]*dao.LampPoleGroup, *util.Erro
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getGroupFiltrationListRedisKey("000000"), devices, 0).Err()
+	_ = util.Redis.Set(getGroupFiltrationListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
 
-func getGroupFiltrationListRedisKey(tenantId string) string {
+func getGroupFiltrationListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.GroupFiltrationList, tenantId)
 }
 
-func (s *lampPoleGroupService) GetTree() ([]*dao.LampPoleGroup, *util.Errors) {
+func (s *lampPoleGroupService) GetTree(tenantId int) ([]*dao.LampPoleGroup, *util.Errors) {
 	// todo use redis cache
 	device := &dao.LampPoleGroup{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 

+ 8 - 10
app/device/service/lampPoleService.go

@@ -50,18 +50,16 @@ func (s *lampPoleService) GetRelevanceDetail(id int) (*model.LampPoleDetail, *ut
 	}, nil
 }
 
-func (s *lampPoleService) CreateOrUpdate(req *dao.LampPole) *util.Errors {
+func (s *lampPoleService) CreateOrUpdate(userId int64, tenantId int, req *dao.LampPole) *util.Errors {
 	device := req
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
+	device.TenantId = tenantId
 	device.CoordType = 1
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 
 	if device.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -102,12 +100,12 @@ func (s *lampPoleService) List(searchValue, groupId, boxId string, current, size
 	return devices, nil
 }
 
-func (s *lampPoleService) Remove(id int) *util.Errors {
+func (s *lampPoleService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.LampPole{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 
@@ -122,9 +120,9 @@ func (s *lampPoleService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *lampPoleService) GetList() ([]*dao.LampPole, *util.Errors) {
+func (s *lampPoleService) GetList(tenantId int) ([]*dao.LampPole, *util.Errors) {
 	device := &dao.LampPole{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 2 - 2
app/device/service/lightConditionService.go

@@ -37,12 +37,12 @@ func (s *lightConditionService) CreateOrUpdate(req dao.LightCondition) *util.Err
 	return nil
 }
 
-func (s *lightConditionService) Remove(id int) *util.Errors {
+func (s *lightConditionService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Gateway{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 

+ 8 - 10
app/device/service/lightControlService.go

@@ -52,12 +52,10 @@ func (s *lightControlService) GetRelevanceDetail(id int) (*model.LightControlDet
 	}, nil
 }
 
-func (s *lightControlService) CreateOrUpdate(req *dao.LightControl) *util.Errors {
+func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *dao.LightControl) *util.Errors {
 	device := req
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 
 	if device.LampPoleId != 0 {
@@ -96,7 +94,7 @@ func (s *lightControlService) CreateOrUpdate(req *dao.LightControl) *util.Errors
 
 	if device.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -147,12 +145,12 @@ func (s *lightControlService) List(searchValue, controlType, zigbeeId string, cu
 	return devices, nil
 }
 
-func (s *lightControlService) Remove(id int) *util.Errors {
+func (s *lightControlService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.LightControl{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 
@@ -167,9 +165,9 @@ func (s *lightControlService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *lightControlService) GetList() ([]*dao.LightControl, *util.Errors) {
+func (s *lightControlService) GetList(tenantId int) ([]*dao.LightControl, *util.Errors) {
 	device := &dao.LightControl{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 10 - 7
app/device/service/manholeCoverService.go

@@ -24,14 +24,15 @@ func (s *manholeCoverService) Get(id int) (*dao.ManholeCover, *util.Errors) {
 
 }
 
-func (s *manholeCoverService) CreateOrUpdate(req dao.ManholeCover) *util.Errors {
+func (s *manholeCoverService) CreateOrUpdate(userId int64, tenantId int, req dao.ManholeCover) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -54,6 +55,7 @@ func (s *manholeCoverService) CreateOrUpdate(req dao.ManholeCover) *util.Errors
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *manholeCoverService) List(searchValue string, current, size int) ([]dao.ManholeCover, *util.Errors) {
 	device := dao.ManholeCover{}
 	if searchValue != "" {
@@ -69,12 +71,13 @@ func (s *manholeCoverService) List(searchValue string, current, size int) ([]dao
 	}
 	return devices, nil
 }
-func (s *manholeCoverService) Remove(id int) *util.Errors {
+
+func (s *manholeCoverService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.ManholeCover{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -88,9 +91,9 @@ func (s *manholeCoverService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *manholeCoverService) GetList() ([]*dao.ManholeCover, *util.Errors) {
+func (s *manholeCoverService) GetList(tenantId int) ([]*dao.ManholeCover, *util.Errors) {
 	device := &dao.ManholeCover{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 11 - 13
app/device/service/onDemandGroupService.go

@@ -27,17 +27,15 @@ func (s *onDemandGroupService) Get(id int) (*dao.OnDemandGroup, *util.Errors) {
 	return device, nil
 }
 
-func (s *onDemandGroupService) CreateOrUpdate(req *dao.OnDemandGroup) *util.Errors {
+func (s *onDemandGroupService) CreateOrUpdate(userId int64, tenantId int, req *dao.OnDemandGroup) *util.Errors {
 	device := req
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 
 	if device.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
@@ -76,12 +74,12 @@ func (s *onDemandGroupService) List(searchValue string, current, size int) ([]da
 	return devices, nil
 }
 
-func (s *onDemandGroupService) Remove(id int) *util.Errors {
+func (s *onDemandGroupService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.OnDemandGroup{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 
@@ -93,27 +91,27 @@ func (s *onDemandGroupService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *onDemandGroupService) GetList() ([]*dao.OnDemandGroup, *util.Errors) {
+func (s *onDemandGroupService) GetList(tenantId int) ([]*dao.OnDemandGroup, *util.Errors) {
 	var devices []*dao.OnDemandGroup
-	err := util.Redis.Get(getOnDemandGroupListRedisKey("000000")).Scan(&devices)
+	err := util.Redis.Get(getOnDemandGroupListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 
 	device := &dao.OnDemandGroup{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getOnDemandGroupListRedisKey("000000"), devices, 0).Err()
+	_ = util.Redis.Set(getOnDemandGroupListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
 
-func getOnDemandGroupListRedisKey(tenantId string) string {
+func getOnDemandGroupListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.OnDemandGroupList, tenantId)
 }
 

+ 8 - 5
app/device/service/onDemandSensorService.go

@@ -24,12 +24,13 @@ func (s *onDemandSensorService) Get(id int) (*dao.OnDemandSensor, *util.Errors)
 
 }
 
-func (s *onDemandSensorService) CreateOrUpdate(req dao.OnDemandSensor) *util.Errors {
+func (s *onDemandSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.OnDemandSensor) *util.Errors {
 	// 创建查询实例
 	device := req
+	device.TenantId = tenantId
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -40,7 +41,7 @@ func (s *onDemandSensorService) CreateOrUpdate(req dao.OnDemandSensor) *util.Err
 		}
 		return util.SuccessResponse(util.Succeeded, nil)
 	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if device.IsExistedByNameAndCode() {
 		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -54,6 +55,7 @@ func (s *onDemandSensorService) CreateOrUpdate(req dao.OnDemandSensor) *util.Err
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *onDemandSensorService) List(searchValue string, current, size int) ([]dao.OnDemandSensor, *util.Errors) {
 	device := dao.OnDemandSensor{}
 	if searchValue != "" {
@@ -69,12 +71,13 @@ func (s *onDemandSensorService) List(searchValue string, current, size int) ([]d
 	}
 	return devices, nil
 }
-func (s *onDemandSensorService) Remove(id int) *util.Errors {
+
+func (s *onDemandSensorService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.OnDemandSensor{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo

+ 6 - 8
app/device/service/operationHisService.go

@@ -14,14 +14,15 @@ var OperationHisService = new(operationHisService)
 
 type operationHisService struct{}
 
-func (s *operationHisService) Save(handleType, handleModuleType int, handleContent string) {
+func (s *operationHisService) Save(userId int64, tenantId int, handleType, handleModuleType int,
+	handleContent string) {
 	operation := dao.OperationHis{
 		OperationType: handleType,
 		ModuleType:    handleModuleType,
 		HandleContent: handleContent,
-		HandleUserId:  "TODO", //todo 使用登录态
+		HandleUserId:  userId,
 		HandleTime:    time.Now(),
-		TenantId:      "000000", //todo 使用登录态
+		TenantId:      tenantId,
 	}
 	err := operation.Create()
 	if err != nil {
@@ -29,7 +30,7 @@ func (s *operationHisService) Save(handleType, handleModuleType int, handleConte
 	}
 }
 
-func (s *operationHisService) List(handleContent, operationType, moduleType string, current,
+func (s *operationHisService) List(tenantId int, handleContent, operationType, moduleType string, current,
 	size int) ([]model.OperationHisDetail, *util.Errors) {
 	his := dao.OperationHis{
 		HandleContent: handleContent,
@@ -60,10 +61,7 @@ func (s *operationHisService) List(handleContent, operationType, moduleType stri
 		detail := model.OperationHisDetail{
 			OperationHis: his,
 		}
-		uId, _ := strconv.ParseInt(his.HandleUserId, 10, 64)
-		// todo get tenantId
-		tenantId := "000000"
-		detail.HandleName = util.GetUserName(tenantId, uId)
+		detail.HandleName = util.GetUserName(tenantId, his.HandleUserId)
 		detail.OperationTypeName = util.GetControlType(tenantId, his.OperationType)
 		detail.ModuleTypeName = util.GetModuleName(tenantId, his.ModuleType)
 		details = append(details, detail)

+ 8 - 7
app/device/service/optoSensoService.go

@@ -24,14 +24,15 @@ func (s *optoSensorService) Get(id int) (*dao.OptoSensor, *util.Errors) {
 
 }
 
-func (s *optoSensorService) CreateOrUpdate(req dao.OptoSensor) *util.Errors {
+func (s *optoSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.OptoSensor) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -71,12 +72,12 @@ func (s *optoSensorService) List(searchValue string, current, size int) ([]dao.O
 	return devices, nil
 }
 
-func (s *optoSensorService) Remove(id int) *util.Errors {
+func (s *optoSensorService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.OptoSensor{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -90,9 +91,9 @@ func (s *optoSensorService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *optoSensorService) GetList() ([]*dao.OptoSensor, *util.Errors) {
+func (s *optoSensorService) GetList(tenantId int) ([]*dao.OptoSensor, *util.Errors) {
 	device := &dao.OptoSensor{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 10 - 10
app/device/service/switchBoxService.go

@@ -24,17 +24,15 @@ func (s *switchBoxService) Get(id int) (*dao.SwitchBox, *util.Errors) {
 
 }
 
-func (s *switchBoxService) CreateOrUpdate(req dao.SwitchBox) *util.Errors {
+func (s *switchBoxService) CreateOrUpdate(userId int64, tenantId int, req dao.SwitchBox) *util.Errors {
 	// 创建查询实例
 	device := req
-	if device.TenantId == "" {
-		device.TenantId = "000000" // todo: 使用登录态
-	}
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -57,6 +55,7 @@ func (s *switchBoxService) CreateOrUpdate(req dao.SwitchBox) *util.Errors {
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *switchBoxService) List(searchValue string, current, size int) ([]dao.SwitchBox, *util.Errors) {
 	device := dao.SwitchBox{}
 	if searchValue != "" {
@@ -72,12 +71,13 @@ func (s *switchBoxService) List(searchValue string, current, size int) ([]dao.Sw
 	}
 	return devices, nil
 }
-func (s *switchBoxService) Remove(id int) *util.Errors {
+
+func (s *switchBoxService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.SwitchBox{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -91,10 +91,10 @@ func (s *switchBoxService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *switchBoxService) GetList() ([]*dao.SwitchBox, *util.Errors) {
+func (s *switchBoxService) GetList(tenantId int) ([]*dao.SwitchBox, *util.Errors) {
 	// todo use redis cache
 	device := &dao.SwitchBox{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 13 - 10
app/device/service/transformerService.go

@@ -25,14 +25,15 @@ func (s *transformerService) Get(id int) (*dao.Transformer, *util.Errors) {
 
 }
 
-func (s *transformerService) CreateOrUpdate(req dao.Transformer) *util.Errors {
+func (s *transformerService) CreateOrUpdate(userId int64, tenantId int, req dao.Transformer) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -55,6 +56,7 @@ func (s *transformerService) CreateOrUpdate(req dao.Transformer) *util.Errors {
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *transformerService) List(searchValue string, current, size int) ([]dao.Transformer, *util.Errors) {
 	device := dao.Transformer{}
 	if searchValue != "" {
@@ -70,12 +72,13 @@ func (s *transformerService) List(searchValue string, current, size int) ([]dao.
 	}
 	return devices, nil
 }
-func (s *transformerService) Remove(id int) *util.Errors {
+
+func (s *transformerService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Transformer{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -89,26 +92,26 @@ func (s *transformerService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *transformerService) GetList() ([]*dao.Transformer, *util.Errors) {
+func (s *transformerService) GetList(tenantId int) ([]*dao.Transformer, *util.Errors) {
 	var devices []*dao.Transformer
-	err := util.Redis.Get(getTransformerListRedisKey("000000")).Scan(&devices)
+	err := util.Redis.Get(getTransformerListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
 
 	device := &dao.Transformer{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getTransformerListRedisKey("000000"), devices, 0).Err()
+	_ = util.Redis.Set(getTransformerListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
 
-func getTransformerListRedisKey(tenantId string) string {
+func getTransformerListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.TransformerList, tenantId)
 }

+ 2 - 2
app/device/service/workbenchService.go

@@ -10,7 +10,7 @@ var WorkbenchService = new(workbenchService)
 
 type workbenchService struct{}
 
-func (s *workbenchService) CountDevice(tenantId string) ([]dao.CountDevice, *util.Errors) {
+func (s *workbenchService) CountDevice(tenantId int) ([]dao.CountDevice, *util.Errors) {
 	counts, err := dao.GetDeviceCount(tenantId)
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
@@ -18,7 +18,7 @@ func (s *workbenchService) CountDevice(tenantId string) ([]dao.CountDevice, *uti
 	return counts, nil
 }
 
-func (s *workbenchService) CountAlarm(tenantId string) (*dao.CountAlarm, *util.Errors) {
+func (s *workbenchService) CountAlarm(tenantId int) (*dao.CountAlarm, *util.Errors) {
 	count, err := dao.GetAlarmCount(tenantId)
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)

+ 10 - 7
app/device/service/zigbeeService.go

@@ -24,14 +24,15 @@ func (s *zigbeeService) Get(id int) (*dao.Zigbee, *util.Errors) {
 
 }
 
-func (s *zigbeeService) CreateOrUpdate(req dao.Zigbee) *util.Errors {
+func (s *zigbeeService) CreateOrUpdate(userId int64, tenantId int, req dao.Zigbee) *util.Errors {
 	// 创建查询实例
 	device := req
-	device.UpdateUser = "TODO" // todo: 使用登录态
+	device.TenantId = tenantId
+	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
-		device.CreateUser = "TODO" // todo: 使用登录态
+		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
 			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
@@ -54,6 +55,7 @@ func (s *zigbeeService) CreateOrUpdate(req dao.Zigbee) *util.Errors {
 	//todo operation record
 	return util.SuccessResponse(util.Succeeded, nil)
 }
+
 func (s *zigbeeService) List(searchValue string, current, size int) ([]dao.Zigbee, *util.Errors) {
 	device := dao.Zigbee{}
 	if searchValue != "" {
@@ -69,12 +71,13 @@ func (s *zigbeeService) List(searchValue string, current, size int) ([]dao.Zigbe
 	}
 	return devices, nil
 }
-func (s *zigbeeService) Remove(id int) *util.Errors {
+
+func (s *zigbeeService) Remove(userId int64, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Zigbee{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: "TODO", // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	//todo
@@ -88,9 +91,9 @@ func (s *zigbeeService) Remove(id int) *util.Errors {
 	return nil
 }
 
-func (s *zigbeeService) GetList() ([]*dao.Zigbee, *util.Errors) {
+func (s *zigbeeService) GetList(tenantId int) ([]*dao.Zigbee, *util.Errors) {
 	device := &dao.Zigbee{
-		TenantId:  "000000", // todo 使用登录态
+		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()

+ 12 - 1
app/middleware/checkAuth.go

@@ -2,17 +2,28 @@ package middleware
 
 import (
 	"github.com/gin-gonic/gin"
+	"iot_manager_service/util"
+	"net/http"
+	"strings"
 )
 
 func CheckAuth() gin.HandlerFunc {
 	return func(ctx *gin.Context) {
+		//该路由下不校验token
+		if strings.Contains(ctx.Request.RequestURI, "/login") {
+			ctx.Next()
+			return
+		}
+
 		authorization := ctx.GetHeader(Authorization)
 		if authorization != "" {
 			token := parseAccessToken(authorization)
 			if token != nil {
 				ctx.Set(Authorization, token)
+				ctx.Next()
 			}
 		}
-		ctx.Next()
+		ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "token is invalid", nil))
+		ctx.Abort()
 	}
 }

+ 0 - 1
app/middleware/cros.go

@@ -18,7 +18,6 @@ func Cors() gin.HandlerFunc {
 		method := c.Request.Method
 		if method == "OPTIONS" {
 			c.AbortWithStatus(http.StatusNoContent)
-			c.Abort()
 		}
 		c.Next()
 	}

+ 11 - 7
app/middleware/token.go

@@ -13,9 +13,9 @@ const (
 
 var EmptyKeyFunc = func(t *jwt.Token) (interface{}, error) { return []byte(config.Instance().Server.TokenSign), nil }
 
-type JwtToken struct {
+type Claims struct {
 	jwt.StandardClaims
-	TenantId string `json:"tenant_id"`
+	TenantId int    `json:"tenant_id"`
 	UserId   int64  `json:"user_id"`
 	RoleId   int64  `json:"role_id"`
 	UserName string `json:"user_name"`
@@ -23,8 +23,8 @@ type JwtToken struct {
 	Random   string `json:"random"`
 }
 
-func GetAccessToken(userId, roleId int64, tenantId, userName string, random string) (string, error) {
-	jwtToken := JwtToken{StandardClaims: jwt.StandardClaims{
+func GetAccessToken(userId, roleId int64, tenantId int, userName string, random string) (string, error) {
+	jwtToken := Claims{StandardClaims: jwt.StandardClaims{
 		Audience:  model.Audience,
 		Issuer:    model.Issuer,
 		ExpiresAt: time.Now().Add(2 * time.Hour).Unix(),
@@ -41,10 +41,14 @@ func GetAccessToken(userId, roleId int64, tenantId, userName string, random stri
 	return claims.SignedString([]byte(config.Instance().Server.TokenSign))
 }
 
-func parseAccessToken(authorization string) *JwtToken {
-	token, err := jwt.ParseWithClaims(authorization, &JwtToken{}, EmptyKeyFunc)
+func parseAccessToken(authorization string) *Claims {
+	token, err := jwt.ParseWithClaims(authorization, &Claims{}, EmptyKeyFunc)
 	if err != nil {
 		return nil
 	}
-	return token.Claims.(*JwtToken)
+	claims, ok := token.Claims.(*Claims)
+	if !ok {
+		return nil
+	}
+	return claims
 }

+ 1 - 1
app/system/controller/menu.go

@@ -64,7 +64,7 @@ func (c *menu) Routes(ctx *gin.Context) {
 	if !isExist || value == nil {
 		ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
 	}
-	menus, err := service.MenuService.Routes(value.(*middleware.JwtToken).RoleId)
+	menus, err := service.MenuService.Routes(value.(*middleware.Claims).RoleId)
 	if err != nil {
 		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
 		return

+ 6 - 1
app/system/controller/tenant.go

@@ -49,7 +49,12 @@ func (c *tenant) List(ctx *gin.Context) {
 		size = 10
 	}
 
-	tenants, err := service.TenantService.List(tenantId, tenantName, linkman, current, size)
+	tId, err := strconv.Atoi(tenantId)
+	if err != nil {
+		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		return
+	}
+	tenants, err := service.TenantService.List(tId, tenantName, linkman, current, size)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 7 - 4
app/system/controller/token.go

@@ -9,6 +9,7 @@ import (
 	"iot_manager_service/app/middleware"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/service"
+	"strconv"
 	"time"
 
 	"iot_manager_service/app/system/model"
@@ -41,9 +42,11 @@ func (c *auth) Token(ctx *gin.Context) {
 	// 校验连续登录失败次数
 	checkLock()
 
+	tId, _ := strconv.Atoi(tenantId)
+
 	userType := ctx.GetHeader(model.UserTypeHeaderKey)
 	token := model.Token{
-		TenantId:     tenantId,
+		TenantId:     tId,
 		UserName:     userName,
 		Password:     password,
 		GrantType:    grantType,
@@ -109,7 +112,7 @@ func (c *auth) Logout(ctx *gin.Context) {
 		ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
 		return
 	}
-	jwtToken := value.(*middleware.JwtToken)
+	jwtToken := value.(*middleware.Claims)
 	_ = util.Redis.Del(getAccessTokenKey(jwtToken.TenantId, jwtToken.UserId, jwtToken.Random)).Err()
 	//todo 操作记录
 	ctx.JSON(http.StatusOK, util.SuccessResponse("", nil))
@@ -244,8 +247,8 @@ func judgeTenant(tenant *dao.Tenant) bool {
 	return true
 }
 
-func getAccessTokenKey(tenantId string, uId int64, random string) string {
-	return fmt.Sprintf("access_token_%s_%d_%s", tenantId, uId, random)
+func getAccessTokenKey(tenantId int, uId int64, random string) string {
+	return fmt.Sprintf("access_token_%d_%d_%s", tenantId, uId, random)
 }
 
 func getCaptchaKey(uId string) string {

+ 30 - 30
app/system/dao/tenant.go

@@ -4,34 +4,34 @@ import "time"
 
 // 租户
 type Tenant struct {
-	ID               int64     `gorm:"primary_key" json:"id"`                             //编号
-	TenantId         string    `gorm:"type:varchar(12);default '000000'" json:"tenantId"` //租户id
-	TenantName       string    `gorm:"type:varchar(50)" json:"tenantName"`                //租户名称
-	Domain           string    `gorm:"type:varchar(255)" json:"domain"`                   //域名地址
-	BackgroundUrl    string    `gorm:"type:varchar(1000)" json:"backgroundUrl"`           //系统背景
-	SysLogoUrl       string    `gorm:"type:varchar(1000)" json:"sysLogoUrl"`              //logo图表
-	Linkman          string    `gorm:"type:varchar(20)" json:"linkman"`                   //联系人
-	ContactNumber    string    `gorm:"type:varchar(20)" json:"contactNumber"`             //联系电话
-	Address          string    `gorm:"type:varchar(255)" json:"address"`                  //联系地址
-	AccountNumber    int       `gorm:"type:int;default -1" json:"accountNumber"`          //邮箱
-	ExpireTime       time.Time `gorm:"type:datetime" json:"expireTime"`                   //过期时间
-	DatasourceId     int64     `gorm:"type:bigint" json:"datasourceId"`                   //数据源
-	LicenseKey       string    `gorm:"type:varchar(1000)" json:"licenseKey"`              //授权码
-	BigScreenName    string    `gorm:"type:varchar(60)" json:"bigScreenName"`             //大屏端显示名称
-	CreateUser       int64     `gorm:"type:bigint" json:"createUser"`                     //创建人
-	CreateDept       int64     `gorm:"type:bigint" json:"createDept"`                     //创建部门
-	CreateTime       time.Time `gorm:"type:datetime" json:"createTime"`                   //新增时间
-	UpdateUser       int64     `gorm:"type:bigint" json:"updateUser"`                     //修改人
-	UpdateTime       time.Time `gorm:"type:datetime" json:"updateTime"`                   //修改时间
-	Status           int       `gorm:"type:int  " json:"status"`                          //状态
-	IsDeleted        int       `gorm:"type:int" json:"isDeleted"`                         //是否删除 0=未删除,1=删除
-	PassKey          string    `gorm:"type:varchar(10)" json:"passKey"`                   //租户登录Key
-	LoginDisplayName string    `gorm:"type:varchar(60)" json:"loginDisplayName"`          //登录页面显示名称
-	ContactEmail     string    `gorm:"type:varchar(255)" json:"contactEmail"`             //联系邮箱
-	CityCode         string    `gorm:"type:varchar(6)" json:"cityCode"`                   //城市行政编码
-	CityName         string    `gorm:"type:varchar(255)" json:"cityName"`                 //城市名称
-	CityLng          float64   `gorm:"type:double(18, 14)" json:"cityLng"`                //经度
-	CityLat          float64   `gorm:"type:double(18, 14)" json:"cityLat"`                //经度
+	ID               int64     `gorm:"primary_key" json:"id"`                    //编号
+	TenantId         int       `gorm:"type:int" json:"tenantId"`                 //租户ID
+	TenantName       string    `gorm:"type:varchar(50)" json:"tenantName"`       //租户名称
+	Domain           string    `gorm:"type:varchar(255)" json:"domain"`          //域名地址
+	BackgroundUrl    string    `gorm:"type:varchar(1000)" json:"backgroundUrl"`  //系统背景
+	SysLogoUrl       string    `gorm:"type:varchar(1000)" json:"sysLogoUrl"`     //logo图表
+	Linkman          string    `gorm:"type:varchar(20)" json:"linkman"`          //联系人
+	ContactNumber    string    `gorm:"type:varchar(20)" json:"contactNumber"`    //联系电话
+	Address          string    `gorm:"type:varchar(255)" json:"address"`         //联系地址
+	AccountNumber    int       `gorm:"type:int;default -1" json:"accountNumber"` //邮箱
+	ExpireTime       time.Time `gorm:"type:datetime" json:"expireTime"`          //过期时间
+	DatasourceId     int64     `gorm:"type:bigint" json:"datasourceId"`          //数据源
+	LicenseKey       string    `gorm:"type:varchar(1000)" json:"licenseKey"`     //授权码
+	BigScreenName    string    `gorm:"type:varchar(60)" json:"bigScreenName"`    //大屏端显示名称
+	CreateUser       int64     `gorm:"type:bigint" json:"createUser"`            //创建人
+	CreateDept       int64     `gorm:"type:bigint" json:"createDept"`            //创建部门
+	CreateTime       time.Time `gorm:"type:datetime" json:"createTime"`          //新增时间
+	UpdateUser       int64     `gorm:"type:bigint" json:"updateUser"`            //修改人
+	UpdateTime       time.Time `gorm:"type:datetime" json:"updateTime"`          //修改时间
+	Status           int       `gorm:"type:int  " json:"status"`                 //状态
+	IsDeleted        int       `gorm:"type:int" json:"isDeleted"`                //是否删除 0=未删除,1=删除
+	PassKey          string    `gorm:"type:varchar(10)" json:"passKey"`          //租户登录Key
+	LoginDisplayName string    `gorm:"type:varchar(60)" json:"loginDisplayName"` //登录页面显示名称
+	ContactEmail     string    `gorm:"type:varchar(255)" json:"contactEmail"`    //联系邮箱
+	CityCode         string    `gorm:"type:varchar(6)" json:"cityCode"`          //城市行政编码
+	CityName         string    `gorm:"type:varchar(255)" json:"cityName"`        //城市名称
+	CityLng          float64   `gorm:"type:double(18, 14)" json:"cityLng"`       //经度
+	CityLat          float64   `gorm:"type:double(18, 14)" json:"cityLat"`       //经度
 }
 
 func (Tenant) TableName() string {
@@ -63,8 +63,8 @@ func (c *Tenant) IsExist() bool {
 func (c *Tenant) GetTenants(offset, limit int) ([]Tenant, error) {
 	var tenants []Tenant
 	db := Db.Debug().Model(&c)
-	if c.TenantId != "" {
-		db = db.Where("tenant_id like ?", "%"+c.TenantId+"%")
+	if c.TenantId > 0 {
+		db = db.Where("tenant_id = ?", c.TenantId)
 	}
 	if c.TenantName != "" {
 		db = db.Where("tenant_name like ?", "%"+c.TenantName+"%")

+ 23 - 23
app/system/dao/user.go

@@ -6,29 +6,29 @@ import (
 
 // User 用户
 type User struct {
-	ID                      int64     `gorm:"primary_key" json:"id"`                             //编号
-	TenantId                string    `gorm:"type:varchar(12);default '000000'" json:"tenantId"` //租户id
-	Code                    string    `gorm:"type:varchar(12)" json:"code"`                      //用户编号
-	Account                 string    `gorm:"type:varchar(45)" json:"account"`                   //账号
-	Password                string    `gorm:"type:varchar(45)" json:"password"`                  //密码
-	Name                    string    `gorm:"type:varchar(20)" json:"name"`                      //昵称
-	RealName                string    `gorm:"type:varchar(12)" json:"realName"`                  //真名
-	Avatar                  string    `gorm:"type:varchar(500)" json:"avatar"`                   //头像
-	Email                   string    `gorm:"type:varchar(45)" json:"email"`                     //邮箱
-	Phone                   string    `gorm:"type:varchar(45)" json:"phone"`                     //手机
-	Birthday                string    `gorm:"type:datetime" json:"birthday"`                     //生日
-	Sex                     int       `gorm:"type:smallint" json:"sex"`                          //生日
-	RoleId                  int64     `gorm:"type:bigint" json:"roleId"`                         //角色id 数组,分隔
-	CreateUser              int64     `gorm:"type:bigint" json:"createUser"`                     //创建人
-	CreateDept              int64     `gorm:"type:bigint" json:"createDept"`                     //创建部门
-	CreateTime              time.Time `gorm:"type:datetime" json:"createTime"`                   //新增时间
-	UpdateUser              int64     `gorm:"type:bigint" json:"updateUser"`                     //修改人
-	UpdateTime              time.Time `gorm:"type:datetime" json:"updateTime"`                   //修改时间
-	Status                  int       `gorm:"type:int  " json:"status"`                          //状态
-	IsDeleted               int       `gorm:"type:int" json:"isDeleted"`                         //是否删除 0=未删除,1=删除
-	GroupId                 int       `gorm:"type:int" json:"groupId"`                           //用户分组id
-	BigScreenIndexCameraIds string    `gorm:"type:varchar(255)" json:"bigScreenIndexCameraIds"`  //数据大屏中摄像头保存位置
-	SecuritySixScreen       string    `gorm:"type:varchar(255)" json:"securitySixScreen"`        //安防页面六分屏
+	ID                      int64     `gorm:"primary_key" json:"id"`                            //编号
+	TenantId                int       `gorm:"type:int" json:"tenantId"`                         //租户ID
+	Code                    string    `gorm:"type:varchar(12)" json:"code"`                     //用户编号
+	Account                 string    `gorm:"type:varchar(45)" json:"account"`                  //账号
+	Password                string    `gorm:"type:varchar(45)" json:"password"`                 //密码
+	Name                    string    `gorm:"type:varchar(20)" json:"name"`                     //昵称
+	RealName                string    `gorm:"type:varchar(12)" json:"realName"`                 //真名
+	Avatar                  string    `gorm:"type:varchar(500)" json:"avatar"`                  //头像
+	Email                   string    `gorm:"type:varchar(45)" json:"email"`                    //邮箱
+	Phone                   string    `gorm:"type:varchar(45)" json:"phone"`                    //手机
+	Birthday                string    `gorm:"type:datetime" json:"birthday"`                    //生日
+	Sex                     int       `gorm:"type:smallint" json:"sex"`                         //生日
+	RoleId                  int64     `gorm:"type:bigint" json:"roleId"`                        //角色id 数组,分隔
+	CreateUser              int64     `gorm:"type:bigint" json:"createUser"`                    //创建人
+	CreateDept              int64     `gorm:"type:bigint" json:"createDept"`                    //创建部门
+	CreateTime              time.Time `gorm:"type:datetime" json:"createTime"`                  //新增时间
+	UpdateUser              int64     `gorm:"type:bigint" json:"updateUser"`                    //修改人
+	UpdateTime              time.Time `gorm:"type:datetime" json:"updateTime"`                  //修改时间
+	Status                  int       `gorm:"type:int  " json:"status"`                         //状态
+	IsDeleted               int       `gorm:"type:int" json:"isDeleted"`                        //是否删除 0=未删除,1=删除
+	GroupId                 int       `gorm:"type:int" json:"groupId"`                          //用户分组id
+	BigScreenIndexCameraIds string    `gorm:"type:varchar(255)" json:"bigScreenIndexCameraIds"` //数据大屏中摄像头保存位置
+	SecuritySixScreen       string    `gorm:"type:varchar(255)" json:"securitySixScreen"`       //安防页面六分屏
 }
 
 func (User) TableName() string {

+ 1 - 2
app/system/model/tenant.go

@@ -3,8 +3,7 @@ package model
 import "iot_manager_service/app/system/dao"
 
 const (
-	AdminTenantId = "1000000000000000" //默认租户
-	DES_KEY       = "0000000000000000" //租户授权码默认16位密钥
+	AdminTenantId = 999999 //默认租户
 )
 
 type RsqTenantList struct {

+ 3 - 3
app/system/model/token.go

@@ -3,7 +3,7 @@ package model
 import "iot_manager_service/app/system/dao"
 
 type Token struct {
-	TenantId     string
+	TenantId     int
 	UserName     string
 	Password     string
 	GrantType    string
@@ -19,7 +19,7 @@ type UserInfo struct {
 }
 
 type RspToken struct {
-	TenantId     string `json:"tenant_id"`
+	TenantId     int    `json:"tenant_id"`
 	UserId       int64  `json:"user_id"`
 	RoleId       int64  `json:"role_id"`
 	OauthId      string `json:"oauth_id"`
@@ -41,7 +41,7 @@ type RspCaptcha struct {
 }
 
 type RspLogin struct {
-	ID            string `json:"id"`
+	ID            int    `json:"id"`
 	Name          string `json:"name"`
 	BackgroundUrl string `json:"backgroundUrl"`
 	SysLogoUrl    string `json:"sysLogoUrl"`

+ 3 - 4
app/system/service/tenantService.go

@@ -22,7 +22,7 @@ func (s *tenantService) GetTenantByPasskey(passKey string) (*dao.Tenant, error)
 	return tenant, nil
 }
 
-func (s *tenantService) GetOne(tenantId string) (*dao.Tenant, error) {
+func (s *tenantService) GetOne(tenantId int) (*dao.Tenant, error) {
 	tenant := &dao.Tenant{
 		TenantId: tenantId,
 	}
@@ -55,11 +55,11 @@ func (s *tenantService) GetByDomain(domain string) (*dao.Tenant, error) {
 	return tenant, nil
 }
 
-func (s *tenantService) List(tenantId, tenantName, linkman string, current, size int) ([]dao.Tenant, error) {
+func (s *tenantService) List(tenantId int, tenantName, linkman string, current, size int) ([]dao.Tenant, error) {
 	tenant := &dao.Tenant{}
 	offset := (current - 1) * size
 	limit := size
-	if tenantId != "" {
+	if tenantId > 0 {
 		tenant.TenantId = tenantId
 	}
 	if tenantName != "" {
@@ -117,5 +117,4 @@ func (s *tenantService) Remove(id int64) *util.Errors {
 		return util.FailResponse(err.Error(), nil)
 	}
 	return nil
-
 }

+ 2 - 2
app/system/service/userService.go

@@ -32,7 +32,7 @@ func (s *userService) Get(id int64) (*model.UserDetail, error) {
 	return detail, nil
 }
 
-func (s *userService) GetOneByTenantId(tenantId string) *dao.User {
+func (s *userService) GetOneByTenantId(tenantId int) *dao.User {
 	user := &dao.User{
 		TenantId: tenantId,
 	}
@@ -43,7 +43,7 @@ func (s *userService) GetOneByTenantId(tenantId string) *dao.User {
 	return user
 }
 
-func (s *userService) GetOne(tenantId, account, password string) *dao.User {
+func (s *userService) GetOne(tenantId int, account, password string) *dao.User {
 	// 密码前端先MD5 后端再sha1加密
 	t := sha1.New()
 	_, _ = io.WriteString(t, password)

+ 9 - 9
router/router.go

@@ -285,15 +285,15 @@ func InitRouter(engine *gin.Engine) {
 	//智慧网关基本信息 控制器
 	wisdomGateway := device.Group("wisdomgateway")
 	{
-		wisdomGateway.GET("/detail", controller.WisdomGateway.Detail)
-		wisdomGateway.GET("/list", controller.WisdomGateway.List)
-		wisdomGateway.POST("/submit", controller.WisdomGateway.CreateOrUpdate)
-		wisdomGateway.POST("/remove", controller.WisdomGateway.Remove)
-		wisdomGateway.GET("/getList", controller.WisdomGateway.GetList)
-		wisdomGateway.GET("/getRelevanceDetail", controller.WisdomGateway.GetRelevanceDetail)
-		wisdomGateway.POST("/import-excel", controller.WisdomGateway.ImportExcel)
-		wisdomGateway.GET("/export-excel", controller.WisdomGateway.ExportExcel)
-		wisdomGateway.GET("/export-template", controller.WisdomGateway.ExportTemplate)
+		wisdomGateway.GET("/detail", controller.Gateway.Detail)
+		wisdomGateway.GET("/list", controller.Gateway.List)
+		wisdomGateway.POST("/submit", controller.Gateway.CreateOrUpdate)
+		wisdomGateway.POST("/remove", controller.Gateway.Remove)
+		wisdomGateway.GET("/getList", controller.Gateway.GetList)
+		wisdomGateway.GET("/getRelevanceDetail", controller.Gateway.GetRelevanceDetail)
+		wisdomGateway.POST("/import-excel", controller.Gateway.ImportExcel)
+		wisdomGateway.GET("/export-excel", controller.Gateway.ExportExcel)
+		wisdomGateway.GET("/export-template", controller.Gateway.ExportTemplate)
 	}
 
 	//zigBee网关 控制器

+ 0 - 0
util/redis.go


Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott