Quellcode durchsuchen

菜单和日志

terry vor 3 Jahren
Ursprung
Commit
c6ae0f21e2
85 geänderte Dateien mit 1224 neuen und 990 gelöschten Zeilen
  1. 10 10
      app/device/controller/GatewayController.go
  2. 6 6
      app/device/controller/IntelligentLightingStrategy.go
  3. 7 7
      app/device/controller/LightStrategy.go
  4. 8 8
      app/device/controller/alarmController.go
  5. 7 7
      app/device/controller/alarmTerminalController.go
  6. 8 8
      app/device/controller/bridgeController.go
  7. 11 11
      app/device/controller/bridgeSensorController.go
  8. 11 11
      app/device/controller/cameraController.go
  9. 15 15
      app/device/controller/captureUintController.go
  10. 8 8
      app/device/controller/garbageController.go
  11. 8 8
      app/device/controller/garbageWayGroupController.go
  12. 2 2
      app/device/controller/handleHistoryController.go
  13. 7 7
      app/device/controller/infoBoardController.go
  14. 7 7
      app/device/controller/ipBroadcastController.go
  15. 10 10
      app/device/controller/lampPoleController.go
  16. 10 10
      app/device/controller/lampPoleGroupController.go
  17. 11 11
      app/device/controller/lightController.go
  18. 8 8
      app/device/controller/manholeCoverController.go
  19. 11 11
      app/device/controller/onDemandGroupController.go
  20. 7 7
      app/device/controller/onDemandSensorController.go
  21. 8 8
      app/device/controller/optoSensorController.go
  22. 8 8
      app/device/controller/switchBoxController.go
  23. 8 8
      app/device/controller/transformerController.go
  24. 8 8
      app/device/controller/utilController.go
  25. 7 7
      app/device/controller/workbenchController.go
  26. 8 8
      app/device/controller/zigbeeController.go
  27. 23 23
      app/device/service/LightStrategyService.go
  28. 25 24
      app/device/service/alarmService.go
  29. 23 22
      app/device/service/alarmTerminalService.go
  30. 27 26
      app/device/service/bridgeSensorService.go
  31. 22 22
      app/device/service/bridgeService.go
  32. 26 25
      app/device/service/cameraService.go
  33. 44 43
      app/device/service/captureUintService.go
  34. 25 24
      app/device/service/garbageService.go
  35. 25 24
      app/device/service/garbageWayGroupService.go
  36. 3 3
      app/device/service/gatewayRelationService.go
  37. 31 30
      app/device/service/gatewayService.go
  38. 23 22
      app/device/service/infoBoardService.go
  39. 4 3
      app/device/service/intelligentLightingService.go
  40. 25 24
      app/device/service/ipBroadcastService.go
  41. 33 32
      app/device/service/lampPoleGroupService.go
  42. 27 27
      app/device/service/lampPoleService.go
  43. 6 6
      app/device/service/lightConditionService.go
  44. 33 32
      app/device/service/lightControlService.go
  45. 22 22
      app/device/service/manholeCoverService.go
  46. 26 25
      app/device/service/onDemandGroupService.go
  47. 20 20
      app/device/service/onDemandSensorService.go
  48. 25 24
      app/device/service/optoSensoService.go
  49. 28 27
      app/device/service/switchBoxService.go
  50. 5 5
      app/device/service/timeConditionService.go
  51. 25 24
      app/device/service/transformerService.go
  52. 10 10
      app/device/service/workbenchService.go
  53. 25 24
      app/device/service/zigbeeService.go
  54. 2 2
      app/middleware/checkAuth.go
  55. 0 12
      app/middleware/checkLogin.go
  56. 2 2
      app/record/controller/lightRecordController.go
  57. 2 2
      app/record/service/lightRecordService.go
  58. 2 2
      app/security/controller/securityController.go
  59. 4 3
      app/security/service/securityService.go
  60. 3 3
      app/system/controller/dict.go
  61. 10 10
      app/system/controller/menu.go
  62. 11 11
      app/system/controller/role.go
  63. 10 10
      app/system/controller/tenant.go
  64. 29 28
      app/system/controller/token.go
  65. 12 12
      app/system/controller/user.go
  66. 8 2
      app/system/dao/roleMenu.go
  67. 7 7
      app/system/service/dictService.go
  68. 6 7
      app/system/service/menuService.go
  69. 5 5
      app/system/service/operationHisService.go
  70. 16 5
      app/system/service/roleMenuService.go
  71. 14 13
      app/system/service/roleService.go
  72. 13 12
      app/system/service/tenantService.go
  73. 14 13
      app/system/service/userService.go
  74. 3 3
      config/config.go
  75. 2 2
      config/config.yaml
  76. 6 2
      go.mod
  77. 13 2
      go.sum
  78. 4 2
      main.go
  79. 4 2
      router/router.go
  80. 3 2
      util/redis.go
  81. 5 1
      util/common.go
  82. 1 1
      util/errors.go
  83. 54 0
      util/logger/lclog.go
  84. 90 0
      util/logger/logger.go
  85. 39 0
      util/logger/recover.go

+ 10 - 10
app/device/controller/GatewayController.go

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -19,7 +19,7 @@ type gatewayCtl struct{}
 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))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -28,7 +28,7 @@ func (c *gatewayCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *gatewayCtl) List(ctx *gin.Context) {
@@ -55,7 +55,7 @@ func (c *gatewayCtl) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: devices,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *gatewayCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -64,7 +64,7 @@ func (c *gatewayCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req *model.GatewayDetail
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.GatewayService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -77,7 +77,7 @@ func (c *gatewayCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqGatewayRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.GatewayService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -85,7 +85,7 @@ func (c *gatewayCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *gatewayCtl) ImportExcel(ctx *gin.Context) {
@@ -106,13 +106,13 @@ func (c *gatewayCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 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))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -121,5 +121,5 @@ func (c *gatewayCtl) GetRelevanceDetail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }

+ 6 - 6
app/device/controller/IntelligentLightingStrategy.go

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -21,11 +21,11 @@ func (c *intelligentLightingCtl) Detail(ctx *gin.Context) {
 
 	publicId, e := strconv.Atoi(ctx.Query("publicId"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 	if publicId == 0 {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.RelationIdInvalid, nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(model.RelationIdInvalid, nil))
 		return
 	}
 
@@ -34,7 +34,7 @@ func (c *intelligentLightingCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, detail))
 }
 
 func (c *intelligentLightingCtl) List(ctx *gin.Context) {
@@ -47,7 +47,7 @@ func (c *intelligentLightingCtl) List(ctx *gin.Context) {
 	size, _ := strconv.Atoi(ctx.Query("size"))
 	gId, err := strconv.Atoi(groupId)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("groupId invalid", nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse("groupId invalid", nil))
 		return
 	}
 	if current == 0 {
@@ -69,7 +69,7 @@ func (c *intelligentLightingCtl) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: strategies,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *intelligentLightingCtl) RelationList(ctx *gin.Context) {

+ 7 - 7
app/device/controller/LightStrategy.go

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -19,7 +19,7 @@ type lightStrategyCtl struct{}
 func (c *lightStrategyCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -28,7 +28,7 @@ func (c *lightStrategyCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, lightStrategy))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, lightStrategy))
 }
 
 func (c *lightStrategyCtl) List(ctx *gin.Context) {
@@ -56,7 +56,7 @@ func (c *lightStrategyCtl) List(ctx *gin.Context) {
 		Records: lightStrategies,
 	}
 
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *lightStrategyCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -66,7 +66,7 @@ func (c *lightStrategyCtl) CreateOrUpdate(ctx *gin.Context) {
 	// 参数验证
 	var req *model.LightStrategyDetail
 	if err := ctx.ShouldBind(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.LightStrategyService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -83,7 +83,7 @@ func (c *lightStrategyCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqLightStrategyRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.LightStrategyService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -91,6 +91,6 @@ func (c *lightStrategyCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 
 }

+ 8 - 8
app/device/controller/alarmController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type alarmCtl struct{}
 func (c *alarmCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *alarmCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *alarmCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *alarmCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *alarmCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *alarmCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.Alarm
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.AlarmService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *alarmCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqAlarmRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.AlarmService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *alarmCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *alarmCtl) ImportExcel(ctx *gin.Context) {
@@ -109,5 +109,5 @@ func (c *alarmCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }

+ 7 - 7
app/device/controller/alarmTerminalController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type alarmTerminalCtl struct{}
 func (c *alarmTerminalCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *alarmTerminalCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *alarmTerminalCtl) List(ctx *gin.Context) {
@@ -55,7 +55,7 @@ func (c *alarmTerminalCtl) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: devices,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *alarmTerminalCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -64,7 +64,7 @@ func (c *alarmTerminalCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.AlarmTerminal
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.AlarmTerminalService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -77,7 +77,7 @@ func (c *alarmTerminalCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqAlarmTerminalRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.AlarmTerminalService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -85,7 +85,7 @@ func (c *alarmTerminalCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *alarmTerminalCtl) ImportExcel(ctx *gin.Context) {

+ 8 - 8
app/device/controller/bridgeController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type bridgeCtl struct{}
 func (c *bridgeCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *bridgeCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *bridgeCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *bridgeCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *bridgeCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *bridgeCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.Bridge
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.BridgeService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *bridgeCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqBridgeRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.BridgeService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *bridgeCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *bridgeCtl) ImportExcel(ctx *gin.Context) {
@@ -109,5 +109,5 @@ func (c *bridgeCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }

+ 11 - 11
app/device/controller/bridgeSensorController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type bridgeSensorCtl struct{}
 func (c *bridgeSensorCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *bridgeSensorCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *bridgeSensorCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *bridgeSensorCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *bridgeSensorCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *bridgeSensorCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.BridgeSensor
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.BridgeSensorService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *bridgeSensorCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqBridgeSensorRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.BridgeSensorService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *bridgeSensorCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *bridgeSensorCtl) ImportExcel(ctx *gin.Context) {
@@ -109,17 +109,17 @@ func (c *bridgeSensorCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *bridgeSensorCtl) Enable(ctx *gin.Context) {
 	var req *model.ReqBridgeSensorEnable
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	if req.Status != model.Enable_Enable && req.Status != model.Enable_Disable {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.EnableInvalid, nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(model.EnableInvalid, nil))
 		return
 	}
 	err := service.BridgeSensorService.Enable(req.ID, req.Status)
@@ -127,5 +127,5 @@ func (c *bridgeSensorCtl) Enable(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }

+ 11 - 11
app/device/controller/cameraController.go

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -19,7 +19,7 @@ type cameraCtl struct{}
 func (c *cameraCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -28,7 +28,7 @@ func (c *cameraCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *cameraCtl) List(ctx *gin.Context) {
@@ -57,7 +57,7 @@ func (c *cameraCtl) List(ctx *gin.Context) {
 		Records: devices,
 	}
 
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *cameraCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *cameraCtl) CreateOrUpdate(ctx *gin.Context) {
 	// 参数验证
 	var req *model.CameraDetail
 	if err := ctx.ShouldBind(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.CameraService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -84,7 +84,7 @@ func (c *cameraCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqCameraRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.CameraService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -92,7 +92,7 @@ func (c *cameraCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *cameraCtl) Count(ctx *gin.Context) {
@@ -116,18 +116,18 @@ func (c *cameraCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 
 }
 
 func (c *cameraCtl) Enable(ctx *gin.Context) {
 	var req *model.ReqCameraEnable
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	if req.Status != model.Enable_Enable && req.Status != model.Enable_Disable {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.EnableInvalid, nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(model.EnableInvalid, nil))
 		return
 	}
 	err := service.CameraService.Enable(req.ID, req.Status)
@@ -135,5 +135,5 @@ func (c *cameraCtl) Enable(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }

+ 15 - 15
app/device/controller/captureUintController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type captureUintCtl struct{}
 func (c *captureUintCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 	deviceType := ctx.Query("type")
@@ -30,16 +30,16 @@ func (c *captureUintCtl) Detail(ctx *gin.Context) {
 			ctx.JSON(http.StatusOK, err)
 			return
 		}
-		ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+		ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 	} else if deviceType == model.TypePoint {
 		device, err := service.CaptureUintService.GetPoint(id)
 		if err != nil {
 			ctx.JSON(http.StatusOK, err)
 			return
 		}
-		ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+		ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 	} else {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.TypeInvalid, nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(model.TypeInvalid, nil))
 	}
 }
 
@@ -68,7 +68,7 @@ func (c *captureUintCtl) CaptureList(ctx *gin.Context) {
 		Records: devices,
 	}
 
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *captureUintCtl) CaptureSubmit(ctx *gin.Context) {
@@ -78,7 +78,7 @@ func (c *captureUintCtl) CaptureSubmit(ctx *gin.Context) {
 	// 参数验证
 	var req *model.CaptureDetail
 	if err := ctx.ShouldBind(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.CaptureUintService.CaptureSubmit(claims.UserId, claims.TenantId, req)
@@ -114,7 +114,7 @@ func (c *captureUintCtl) PointList(ctx *gin.Context) {
 		Records: devices,
 	}
 
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *captureUintCtl) PointSubmit(ctx *gin.Context) {
@@ -124,7 +124,7 @@ func (c *captureUintCtl) PointSubmit(ctx *gin.Context) {
 	// 参数验证
 	var req *dao.CheckPoint
 	if err := ctx.ShouldBind(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.CaptureUintService.PointSubmit(claims.UserId, claims.TenantId, req)
@@ -144,7 +144,7 @@ func (c *captureUintCtl) CaptureGetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *captureUintCtl) PointGetList(ctx *gin.Context) {
@@ -156,7 +156,7 @@ func (c *captureUintCtl) PointGetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *captureUintCtl) Remove(ctx *gin.Context) {
@@ -165,7 +165,7 @@ func (c *captureUintCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqCaptureRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	if req.Type == model.TypeCapture {
@@ -174,15 +174,15 @@ func (c *captureUintCtl) Remove(ctx *gin.Context) {
 			ctx.JSON(http.StatusOK, err)
 			return
 		}
-		ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+		ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 	} else if req.Type == model.TypePoint {
 		err := service.CaptureUintService.RemovePoint(claims.UserId, claims.TenantId, req.IDs)
 		if err != nil {
 			ctx.JSON(http.StatusOK, err)
 			return
 		}
-		ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+		ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 	} else {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.TypeInvalid, nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(model.TypeInvalid, nil))
 	}
 }

+ 8 - 8
app/device/controller/garbageController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type garbageCtl struct{}
 func (c *garbageCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *garbageCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *garbageCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *garbageCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *garbageCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *garbageCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.Garbage
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.GarbageService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *garbageCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqGarbageRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.GarbageService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *garbageCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *garbageCtl) ImportExcel(ctx *gin.Context) {
@@ -109,5 +109,5 @@ func (c *garbageCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }

+ 8 - 8
app/device/controller/garbageWayGroupController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type garbageWayCtl struct{}
 func (c *garbageWayCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *garbageWayCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *garbageWayCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *garbageWayCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *garbageWayCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *garbageWayCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.GarbageWayGroup
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.GarbageWayGroupService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *garbageWayCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqGarbageWayGroupRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.GarbageWayGroupService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *garbageWayCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *garbageWayCtl) GetList(ctx *gin.Context) {
@@ -100,5 +100,5 @@ func (c *garbageWayCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }

+ 2 - 2
app/device/controller/handleHistoryController.go

@@ -4,7 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/middleware"
 	service2 "iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"net/http"
 	"strconv"
 )
@@ -36,5 +36,5 @@ func (c *handleHistoryCtl) List(ctx *gin.Context) {
 		return
 	}
 
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, list))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, list))
 }

+ 7 - 7
app/device/controller/infoBoardController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type infoBoardCtl struct{}
 func (c *infoBoardCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *infoBoardCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *infoBoardCtl) List(ctx *gin.Context) {
@@ -56,7 +56,7 @@ func (c *infoBoardCtl) List(ctx *gin.Context) {
 		Records: devices,
 	}
 
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *infoBoardCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -65,7 +65,7 @@ func (c *infoBoardCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.InfoBoard
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.InfoBoardService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -78,7 +78,7 @@ func (c *infoBoardCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqInfoBoardRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.InfoBoardService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -86,7 +86,7 @@ func (c *infoBoardCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *infoBoardCtl) ImportExcel(ctx *gin.Context) {

+ 7 - 7
app/device/controller/ipBroadcastController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type ipBroadcastCtl struct{}
 func (c *ipBroadcastCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *ipBroadcastCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *ipBroadcastCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *ipBroadcastCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *ipBroadcastCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *ipBroadcastCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.IpBroadcast
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.IpBroadcastService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *ipBroadcastCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqIpBroadcastRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.IpBroadcastService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *ipBroadcastCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *ipBroadcastCtl) ImportExcel(ctx *gin.Context) {

+ 10 - 10
app/device/controller/lampPoleController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type lampPoleCtl struct{}
 func (c *lampPoleCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *lampPoleCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *lampPoleCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -38,7 +38,7 @@ func (c *lampPoleCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req *dao.LampPole
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.LampPoleService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -73,13 +73,13 @@ func (c *lampPoleCtl) List(ctx *gin.Context) {
 	for _, device := range devices {
 		rsp.Records = append(rsp.Records, lampPoleDaoToModel(device))
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *lampPoleCtl) GetRelevanceDetail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -88,7 +88,7 @@ func (c *lampPoleCtl) GetRelevanceDetail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *lampPoleCtl) Remove(ctx *gin.Context) {
@@ -97,7 +97,7 @@ func (c *lampPoleCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqLampPoleRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.LampPoleService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -105,7 +105,7 @@ func (c *lampPoleCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *lampPoleCtl) ImportExcel(ctx *gin.Context) {
@@ -126,7 +126,7 @@ func (c *lampPoleCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func lampPoleDaoToModel(device dao.LampPole) model.LampPoleDetail {

+ 10 - 10
app/device/controller/lampPoleGroupController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -21,7 +21,7 @@ type lampPoleGroupCtl struct{}
 func (c *lampPoleGroupCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -30,7 +30,7 @@ func (c *lampPoleGroupCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, lampPoleGroupDaoToModel(*device)))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, lampPoleGroupDaoToModel(*device)))
 }
 
 // CreateOrUpdate 新增、更新
@@ -40,7 +40,7 @@ func (c *lampPoleGroupCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req *dao.LampPoleGroup
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 
@@ -75,7 +75,7 @@ func (c *lampPoleGroupCtl) List(ctx *gin.Context) {
 	for _, device := range devices {
 		rsp.Records = append(rsp.Records, lampPoleGroupDaoToModel(device))
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 // Remove 删除
@@ -85,7 +85,7 @@ func (c *lampPoleGroupCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqLampPoleGroupRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.LampPoleGroupService.Remove(claims.UserId, claims.TenantId, req.IDs, req.Name)
@@ -93,7 +93,7 @@ func (c *lampPoleGroupCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 // GetList 获取下拉列表
@@ -106,7 +106,7 @@ func (c *lampPoleGroupCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 // FiltrationList 获取智能照明灯杆分组下拉(过滤掉没有灯控的分组显示)
@@ -119,7 +119,7 @@ func (c *lampPoleGroupCtl) FiltrationList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 // GetTree 获取所有的灯杆分组所属灯杆
@@ -134,7 +134,7 @@ func (c *lampPoleGroupCtl) GetTree(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func lampPoleGroupDaoToModel(device dao.LampPoleGroup) model.LampPoleGroupDetail {

+ 11 - 11
app/device/controller/lightController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type lightCtl struct{}
 func (c *lightCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *lightCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *lightCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *lightCtl) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: devices,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *lightCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *lightCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req *dao.LightControl
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.LightControlService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *lightCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqLightControlRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.LightControlService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *lightCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *lightCtl) ImportExcel(ctx *gin.Context) {
@@ -109,17 +109,17 @@ func (c *lightCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *lightCtl) Enable(ctx *gin.Context) {
 	var req *model.ReqLightControlEnable
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	if req.Status != model.Enable_Enable && req.Status != model.Enable_Disable {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.EnableInvalid, nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(model.EnableInvalid, nil))
 		return
 	}
 	err := service.LightControlService.Enable(req.ID, req.Status)
@@ -127,7 +127,7 @@ func (c *lightCtl) Enable(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *lightCtl) Switch(ctx *gin.Context) {

+ 8 - 8
app/device/controller/manholeCoverController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type manholeCoverCtl struct{}
 func (c *manholeCoverCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *manholeCoverCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *manholeCoverCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *manholeCoverCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *manholeCoverCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *manholeCoverCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.ManholeCover
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.ManholeCoverService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *manholeCoverCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqManholeCoverRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.ManholeCoverService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *manholeCoverCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *manholeCoverCtl) ImportExcel(ctx *gin.Context) {
@@ -109,7 +109,7 @@ func (c *manholeCoverCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *manholeCoverCtl) AllList(ctx *gin.Context) {

+ 11 - 11
app/device/controller/onDemandGroupController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type onDemandGroupCtl struct{}
 func (c *onDemandGroupCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *onDemandGroupCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *onDemandGroupCtl) List(ctx *gin.Context) {
@@ -56,7 +56,7 @@ func (c *onDemandGroupCtl) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: devices,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *onDemandGroupCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -65,7 +65,7 @@ func (c *onDemandGroupCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req *dao.OnDemandGroup
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.OnDemandGroupService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -78,7 +78,7 @@ func (c *onDemandGroupCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqOnDemandGroupRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.OnDemandGroupService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -86,7 +86,7 @@ func (c *onDemandGroupCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *onDemandGroupCtl) GetList(ctx *gin.Context) {
@@ -98,17 +98,17 @@ func (c *onDemandGroupCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *onDemandGroupCtl) GroupNumber(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 	if id <= 0 {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.ParamsInvalid, nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(model.ParamsInvalid, nil))
 		return
 	}
 
@@ -117,5 +117,5 @@ func (c *onDemandGroupCtl) GroupNumber(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }

+ 7 - 7
app/device/controller/onDemandSensorController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type onDemandSensorCtl struct{}
 func (c *onDemandSensorCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *onDemandSensorCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *onDemandSensorCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *onDemandSensorCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *onDemandSensorCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *onDemandSensorCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.OnDemandSensor
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.OnDemandSensorService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *onDemandSensorCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqOnDemandSensorRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.OnDemandSensorService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *onDemandSensorCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *onDemandSensorCtl) ImportExcel(ctx *gin.Context) {

+ 8 - 8
app/device/controller/optoSensorController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type optoSensorCtl struct{}
 func (c *optoSensorCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *optoSensorCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *optoSensorCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *optoSensorCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *optoSensorCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *optoSensorCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.OptoSensor
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.OptoSensorService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *optoSensorCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqOptoSensorRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.OptoSensorService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *optoSensorCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *optoSensorCtl) ImportExcel(ctx *gin.Context) {
@@ -109,7 +109,7 @@ func (c *optoSensorCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *optoSensorCtl) SetDefault(ctx *gin.Context) {

+ 8 - 8
app/device/controller/switchBoxController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type switchBoxCtl struct{}
 func (c *switchBoxCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *switchBoxCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *switchBoxCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *switchBoxCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *switchBoxCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *switchBoxCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.SwitchBox
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.SwitchBoxService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *switchBoxCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqSwitchBoxRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.SwitchBoxService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *switchBoxCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *switchBoxCtl) GetList(ctx *gin.Context) {
@@ -100,7 +100,7 @@ func (c *switchBoxCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *switchBoxCtl) ImportExcel(ctx *gin.Context) {

+ 8 - 8
app/device/controller/transformerController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type transformerCtl struct{}
 func (c *transformerCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *transformerCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *transformerCtl) List(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *transformerCtl) List(ctx *gin.Context) {
 
 		rsp.Records = append(rsp.Records, device)
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *transformerCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -67,7 +67,7 @@ func (c *transformerCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.Transformer
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.TransformerService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -80,7 +80,7 @@ func (c *transformerCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqTransformerRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.TransformerService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -88,7 +88,7 @@ func (c *transformerCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *transformerCtl) GetList(ctx *gin.Context) {
@@ -100,5 +100,5 @@ func (c *transformerCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }

+ 8 - 8
app/device/controller/utilController.go

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"net/http"
 	"strconv"
 )
@@ -38,14 +38,14 @@ func (c *utilCtl) GetModelList(ctx *gin.Context) {
 	pid := ctx.Query("pid")
 	modeType, err := strconv.Atoi(t)
 	if err != nil || modeType < 1 || modeType > 3 {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("type invalid", nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse("type invalid", nil))
 		return
 	}
 	modeType++ //前端传入的1和2,实际是2和3
 
 	deviceType, err := strconv.Atoi(d)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("deviceType invalid", nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse("deviceType invalid", nil))
 		return
 	}
 	parentId := -1
@@ -62,7 +62,7 @@ func (c *utilCtl) GetModelList(ctx *gin.Context) {
 	if modeType == model.TypeVendor {
 		vendors, err := service.UtilService.GetDeviceVendor(claims.TenantId, deviceType)
 		if err != nil {
-			ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+			ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 			return
 		}
 		for _, vendor := range vendors {
@@ -75,7 +75,7 @@ func (c *utilCtl) GetModelList(ctx *gin.Context) {
 	} else if modeType == model.TypeBrand {
 		vendors, err := service.UtilService.GetDeviceBrand(claims.TenantId, deviceType)
 		if err != nil {
-			ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+			ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 			return
 		}
 		for _, vendor := range vendors {
@@ -88,7 +88,7 @@ func (c *utilCtl) GetModelList(ctx *gin.Context) {
 	} else if modeType == model.TypeModel {
 		vendors, err := service.UtilService.GetDeviceModel(claims.TenantId, deviceType, parentId)
 		if err != nil {
-			ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+			ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 			return
 		}
 		for _, vendor := range vendors {
@@ -99,9 +99,9 @@ func (c *utilCtl) GetModelList(ctx *gin.Context) {
 			})
 		}
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse("", result))
+	ctx.JSON(http.StatusOK, common.SuccessResponse("", result))
 }
 
 func (c *utilCtl) GetTenantCode(ctx *gin.Context) {
-	ctx.JSON(http.StatusOK, util.SuccessResponse("", nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse("", nil))
 }

+ 7 - 7
app/device/controller/workbenchController.go

@@ -4,7 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"net/http"
 )
 
@@ -22,7 +22,7 @@ func (c *workbenchCtl) CountDevice(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }
 
 func (c *workbenchCtl) CountAlarm(ctx *gin.Context) {
@@ -34,7 +34,7 @@ func (c *workbenchCtl) CountAlarm(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
 }
 
 func (c *workbenchCtl) Aqi(ctx *gin.Context) {
@@ -46,7 +46,7 @@ func (c *workbenchCtl) Aqi(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
 }
 
 func (c *workbenchCtl) CountJobTodo(ctx *gin.Context) {
@@ -58,7 +58,7 @@ func (c *workbenchCtl) CountJobTodo(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
 }
 
 func (c *workbenchCtl) Notification(ctx *gin.Context) {
@@ -70,7 +70,7 @@ func (c *workbenchCtl) Notification(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
 }
 
 func (c *workbenchCtl) LightRate(ctx *gin.Context) {
@@ -82,5 +82,5 @@ func (c *workbenchCtl) LightRate(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
 }

+ 8 - 8
app/device/controller/zigbeeController.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -20,7 +20,7 @@ type zigbeeCtl struct{}
 func (c *zigbeeCtl) Detail(ctx *gin.Context) {
 	id, e := strconv.Atoi(ctx.Query("id"))
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(e.Error(), nil))
 		return
 	}
 
@@ -29,7 +29,7 @@ func (c *zigbeeCtl) Detail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, device))
 }
 
 func (c *zigbeeCtl) List(ctx *gin.Context) {
@@ -55,7 +55,7 @@ func (c *zigbeeCtl) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: devices,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *zigbeeCtl) CreateOrUpdate(ctx *gin.Context) {
@@ -64,7 +64,7 @@ func (c *zigbeeCtl) CreateOrUpdate(ctx *gin.Context) {
 
 	var req dao.Zigbee
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.ZigbeeService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
@@ -77,7 +77,7 @@ func (c *zigbeeCtl) Remove(ctx *gin.Context) {
 
 	var req *model.ReqZigbeeRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.ZigbeeService.Remove(claims.UserId, claims.TenantId, req.IDs)
@@ -85,7 +85,7 @@ func (c *zigbeeCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }
 
 func (c *zigbeeCtl) ImportExcel(ctx *gin.Context) {
@@ -106,5 +106,5 @@ func (c *zigbeeCtl) GetList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
 }

+ 23 - 23
app/device/service/LightStrategyService.go

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"sort"
 	"time"
 )
@@ -15,14 +15,14 @@ var LightStrategyService = new(lightStrategyService)
 
 type lightStrategyService struct{}
 
-func (s *lightStrategyService) Get(id int) (*model.LightStrategyDetail, *util.Errors) {
+func (s *lightStrategyService) Get(id int) (*model.LightStrategyDetail, *common.Errors) {
 	// 创建查询实例
 	strategy := &dao.LightStrategy{
 		ID: id,
 	}
 	err := strategy.GetStrategy()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	lightStrategy := &model.LightStrategyDetail{
@@ -38,7 +38,7 @@ func (s *lightStrategyService) Get(id int) (*model.LightStrategyDetail, *util.Er
 	return lightStrategy, nil
 }
 
-func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *model.LightStrategyDetail) *util.Errors {
+func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *model.LightStrategyDetail) *common.Errors {
 	// 创建查询实例
 	strategy := req
 	fmt.Printf("CreateOrUpdate strategy = %+v \n", strategy)
@@ -81,7 +81,7 @@ func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *m
 		strategy.CreateUser = userId
 		if strategy.IsExistedBySN() {
 			fmt.Printf("Create GetstrategyID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 	}
 
@@ -90,9 +90,9 @@ func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *m
 	for _, lightCondition := range strategy.LightConditionList {
 		if (lightCondition.ScopeStart != 0 && lightCondition.ScopeEnd == 0) || (lightCondition.
 			ScopeStart == 0 && lightCondition.ScopeEnd != 0) {
-			return util.ParamsInvalidResponse("光照度请填写完整", nil)
+			return common.ParamsInvalidResponse("光照度请填写完整", nil)
 		} else if lightCondition.ScopeEnd > 0 && lightCondition.ScopeStart >= lightCondition.ScopeEnd {
-			return util.ParamsInvalidResponse("光照度起始值不能大于结束值", nil)
+			return common.ParamsInvalidResponse("光照度起始值不能大于结束值", nil)
 		}
 		overlapList = append(overlapList, lightCondition)
 
@@ -115,7 +115,7 @@ func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *m
 		tmp := -1
 		for _, overLap := range overlapList {
 			if tmp >= overLap.ScopeStart {
-				return util.ParamsInvalidResponse("光照条件区间有重叠", nil)
+				return common.ParamsInvalidResponse("光照条件区间有重叠", nil)
 			}
 			tmp = overLap.ScopeEnd
 		}
@@ -128,13 +128,13 @@ func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *m
 			timeCondition.Sunshine = 1
 		}
 		if timeCondition.Sunshine == 1 && (timeCondition.StartTime == "" && timeCondition.EndTime == "") {
-			return util.FailResponse(model.TimeConditionNull, nil)
+			return common.FailResponse(model.TimeConditionNull, nil)
 		}
 		if (timeCondition.StartTime == "" && timeCondition.EndTime != "") || (timeCondition.
 			StartTime != "" && timeCondition.EndTime == "") {
-			return util.FailResponse(model.TimeConditionNull, nil)
+			return common.FailResponse(model.TimeConditionNull, nil)
 		} else if timeCondition.EndTime != "" && timeCondition.StartTime >= timeCondition.EndTime {
-			return util.FailResponse(model.TimeConditionInvalid, nil)
+			return common.FailResponse(model.TimeConditionInvalid, nil)
 		}
 		if timeCondition.ID == 0 {
 			timeCondition.CreateUser = userId
@@ -158,12 +158,12 @@ func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *m
 	if strategy.ID == 0 {
 		if err := strategy.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
 	} else {
 		if err := strategy.Update(); err != nil {
 			fmt.Printf("Update err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
 	}
 
@@ -176,12 +176,12 @@ func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *m
 	//todo 自动续期
 	//strategy.IsAutomaticRenewal
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-		util.DeviceTypeLightStrategy, util.GetDeviceObject(strategy.ID, strategy.LightName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+		common.DeviceTypeLightStrategy, common.GetDeviceObject(strategy.ID, strategy.LightName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *lightStrategyService) List(searchValue string, current, size int) ([]model.LightStrategyDetail, *util.Errors) {
+func (s *lightStrategyService) List(searchValue string, current, size int) ([]model.LightStrategyDetail, *common.Errors) {
 	strategy := dao.LightStrategy{}
 	if searchValue != "" {
 		strategy.LightSn = searchValue
@@ -191,7 +191,7 @@ func (s *lightStrategyService) List(searchValue string, current, size int) ([]mo
 	limit := size
 	strategies, err := strategy.GetStrategies(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	timeConditions, _ := TimeConditionService.GetAll()
@@ -222,7 +222,7 @@ func (s *lightStrategyService) List(searchValue string, current, size int) ([]mo
 	return details, nil
 }
 
-func (s *lightStrategyService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *lightStrategyService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	strategy := &dao.LightStrategy{
 		ID:         id,
@@ -232,14 +232,14 @@ func (s *lightStrategyService) Remove(userId int64, tenantId int, id int) *util.
 	}
 	err := strategy.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeLightStrategy, util.GetDeviceObject(strategy.ID, strategy.LightName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeLightStrategy, common.GetDeviceObject(strategy.ID, strategy.LightName), common.OperationSuccess)
 	return nil
 }
 
-func (s *lightStrategyService) GetOne(id int) (*dao.LightStrategy, *util.Errors) {
+func (s *lightStrategyService) GetOne(id int) (*dao.LightStrategy, *common.Errors) {
 	strategy := &dao.LightStrategy{
 		ID: id,
 	}

+ 25 - 24
app/device/service/alarmService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -14,19 +15,19 @@ var AlarmService = new(alarmService)
 
 type alarmService struct{}
 
-func (s *alarmService) Get(id int) (*dao.Alarm, *util.Errors) {
+func (s *alarmService) Get(id int) (*dao.Alarm, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Alarm{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 }
 
-func (s *alarmService) CreateOrUpdate(userId int64, tenantId int, req dao.Alarm) *util.Errors {
+func (s *alarmService) CreateOrUpdate(userId int64, tenantId int, req dao.Alarm) *common.Errors {
 	device := req
 	device.TenantId = tenantId
 	device.UpdateUser = userId
@@ -38,45 +39,45 @@ func (s *alarmService) CreateOrUpdate(userId int64, tenantId int, req dao.Alarm)
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
-			return util.ParamsInvalidResponse(model.RepeatedName, nil)
+			return common.ParamsInvalidResponse(model.RepeatedName, nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeAlarmServer, util.GetDeviceObject(device.ID, device.ServeName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeAlarmServer, common.GetDeviceObject(device.ID, device.ServeName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if device.IsExistedByNameAndCode() {
 		fmt.Printf("Update IsExistedByNameAndCode \n")
-		return util.ParamsInvalidResponse(model.RepeatedName, nil)
+		return common.ParamsInvalidResponse(model.RepeatedName, nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeAlarmServer, util.GetDeviceObject(device.ID, device.ServeName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeAlarmServer, common.GetDeviceObject(device.ID, device.ServeName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *alarmService) List(poleGroupName string, current, size int) ([]dao.Alarm, *util.Errors) {
+func (s *alarmService) List(poleGroupName string, current, size int) ([]dao.Alarm, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Alarm{}
 	offset := (current - 1) * size
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *alarmService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *alarmService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.Alarm{
 		ID:         id,
@@ -86,16 +87,16 @@ func (s *alarmService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeAlarmServer, util.GetDeviceObject(device.ID, device.ServeName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeAlarmServer, common.GetDeviceObject(device.ID, device.ServeName), common.OperationSuccess)
 	return nil
 }
 
-func (s *alarmService) GetList(tenantId int) ([]*dao.Alarm, *util.Errors) {
+func (s *alarmService) GetList(tenantId int) ([]*dao.Alarm, *common.Errors) {
 	var devices []*dao.Alarm
-	err := util.Redis.Get(getAlarmListRedisKey(tenantId)).Scan(&devices)
+	err := cache.Redis.Get(getAlarmListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -105,9 +106,9 @@ func (s *alarmService) GetList(tenantId int) ([]*dao.Alarm, *util.Errors) {
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getAlarmListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getAlarmListRedisKey(tenantId), devices, 0).Err()
 	return devices, nil
 }
 

+ 23 - 22
app/device/service/alarmTerminalService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -14,16 +15,16 @@ var AlarmTerminalService = new(alarmTerminalService)
 
 type alarmTerminalService struct{}
 
-func (s *alarmTerminalService) Get(id int) (*model.AlarmTerminalDetail, *util.Errors) {
+func (s *alarmTerminalService) Get(id int) (*model.AlarmTerminalDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.AlarmTerminal{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	endTime, state := util.GetDeviceState(device.TerminalSN)
+	endTime, state := cache.GetDeviceState(device.TerminalSN)
 	return &model.AlarmTerminalDetail{
 		AlarmTerminal: *device,
 		RunState:      state,
@@ -32,7 +33,7 @@ func (s *alarmTerminalService) Get(id int) (*model.AlarmTerminalDetail, *util.Er
 	}, nil
 }
 
-func (s *alarmTerminalService) CreateOrUpdate(userId int64, tenantId int, req dao.AlarmTerminal) *util.Errors {
+func (s *alarmTerminalService) CreateOrUpdate(userId int64, tenantId int, req dao.AlarmTerminal) *common.Errors {
 	device := req
 	device.TenantId = tenantId
 	device.UpdateUser = userId
@@ -44,44 +45,44 @@ func (s *alarmTerminalService) CreateOrUpdate(userId int64, tenantId int, req da
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
-			return util.ParamsInvalidResponse(model.RepeatedName, nil)
+			return common.ParamsInvalidResponse(model.RepeatedName, nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeAlarmTerminal, util.GetDeviceObject(device.ID, device.TerminalName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeAlarmTerminal, common.GetDeviceObject(device.ID, device.TerminalName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if device.IsExistedByNameAndCode() {
 		fmt.Printf("Update IsExistedByNameAndCode \n")
-		return util.ParamsInvalidResponse(model.RepeatedName, nil)
+		return common.ParamsInvalidResponse(model.RepeatedName, nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeAlarmTerminal, util.GetDeviceObject(device.ID, device.TerminalName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeAlarmTerminal, common.GetDeviceObject(device.ID, device.TerminalName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *alarmTerminalService) List(poleGroupName string, current, size int) ([]model.AlarmTerminalDetail, *util.Errors) {
+func (s *alarmTerminalService) List(poleGroupName string, current, size int) ([]model.AlarmTerminalDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.AlarmTerminal{}
 	offset := (current - 1) * size
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var details []model.AlarmTerminalDetail
 	for _, d := range devices {
-		endTime, state := util.GetDeviceState(d.TerminalSN)
+		endTime, state := cache.GetDeviceState(d.TerminalSN)
 		details = append(details, model.AlarmTerminalDetail{
 			AlarmTerminal: d,
 			RunState:      state,
@@ -92,7 +93,7 @@ func (s *alarmTerminalService) List(poleGroupName string, current, size int) ([]
 	return details, nil
 }
 
-func (s *alarmTerminalService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *alarmTerminalService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.AlarmTerminal{
 		ID:         id,
@@ -102,10 +103,10 @@ func (s *alarmTerminalService) Remove(userId int64, tenantId int, id int) *util.
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeAlarmTerminal, util.GetDeviceObject(device.ID, device.TerminalName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeAlarmTerminal, common.GetDeviceObject(device.ID, device.TerminalName), common.OperationSuccess)
 	return nil
 }
 

+ 27 - 26
app/device/service/bridgeSensorService.go

@@ -4,7 +4,8 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,19 +14,19 @@ var BridgeSensorService = new(bridgeSensorService)
 
 type bridgeSensorService struct{}
 
-func (s *bridgeSensorService) Get(id int) (*dao.BridgeSensor, *util.Errors) {
+func (s *bridgeSensorService) Get(id int) (*dao.BridgeSensor, *common.Errors) {
 	// 创建查询实例
 	device := &dao.BridgeSensor{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 }
 
-func (s *bridgeSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.BridgeSensor) *util.Errors {
+func (s *bridgeSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.BridgeSensor) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantID = tenantId
@@ -36,31 +37,31 @@ func (s *bridgeSensorService) CreateOrUpdate(userId int64, tenantId int, req dao
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeBridgeSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeBridgeSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeBridgeSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeBridgeSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *bridgeSensorService) List(searchValue string, current, size int) ([]dao.BridgeSensor, *util.Errors) {
+func (s *bridgeSensorService) List(searchValue string, current, size int) ([]dao.BridgeSensor, *common.Errors) {
 	device := dao.BridgeSensor{}
 	if searchValue != "" {
 		device.SN = searchValue
@@ -71,12 +72,12 @@ func (s *bridgeSensorService) List(searchValue string, current, size int) ([]dao
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *bridgeSensorService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *bridgeSensorService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.BridgeSensor{
 		ID:         id,
@@ -86,16 +87,16 @@ func (s *bridgeSensorService) Remove(userId int64, tenantId int, id int) *util.E
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeBridgeSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeBridgeSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
 	return nil
 }
 
-func (s *bridgeSensorService) GetList(tenantId int) ([]*dao.BridgeSensor, *util.Errors) {
+func (s *bridgeSensorService) GetList(tenantId int) ([]*dao.BridgeSensor, *common.Errors) {
 	var devices []*dao.BridgeSensor
-	err := util.Redis.Get(getTransformerListRedisKey(tenantId)).Scan(&devices)
+	err := cache.Redis.Get(getTransformerListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -106,14 +107,14 @@ func (s *bridgeSensorService) GetList(tenantId int) ([]*dao.BridgeSensor, *util.
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getTransformerListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getTransformerListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
 
-func (s *bridgeSensorService) Enable(id, status int) *util.Errors {
+func (s *bridgeSensorService) Enable(id, status int) *common.Errors {
 	// 创建查询实例
 	device := &dao.BridgeSensor{
 		ID:       id,
@@ -122,7 +123,7 @@ func (s *bridgeSensorService) Enable(id, status int) *util.Errors {
 
 	err := device.UpdateEnable()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }

+ 22 - 22
app/device/service/bridgeService.go

@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -12,19 +12,19 @@ var BridgeService = new(bridgeService)
 
 type bridgeService struct{}
 
-func (s *bridgeService) Get(id int) (*dao.Bridge, *util.Errors) {
+func (s *bridgeService) Get(id int) (*dao.Bridge, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Bridge{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 }
 
-func (s *bridgeService) CreateOrUpdate(userId int64, tenantId int, req dao.Bridge) *util.Errors {
+func (s *bridgeService) CreateOrUpdate(userId int64, tenantId int, req dao.Bridge) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -35,32 +35,32 @@ func (s *bridgeService) CreateOrUpdate(userId int64, tenantId int, req dao.Bridg
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeBridge, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeBridge, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeBridge, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeBridge, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *bridgeService) List(searchValue string, current, size int) ([]dao.Bridge, *util.Errors) {
+func (s *bridgeService) List(searchValue string, current, size int) ([]dao.Bridge, *common.Errors) {
 	device := dao.Bridge{}
 	if searchValue != "" {
 		device.SN = searchValue
@@ -71,12 +71,12 @@ func (s *bridgeService) List(searchValue string, current, size int) ([]dao.Bridg
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *bridgeService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *bridgeService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.Bridge{
 		ID:         id,
@@ -86,14 +86,14 @@ func (s *bridgeService) Remove(userId int64, tenantId int, id int) *util.Errors
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeBridge, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeBridge, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
 	return nil
 }
 
-func (s *bridgeService) GetList(tenantId int) ([]*dao.Bridge, *util.Errors) {
+func (s *bridgeService) GetList(tenantId int) ([]*dao.Bridge, *common.Errors) {
 	// todo use redis cache
 	device := &dao.Bridge{
 		TenantId:  tenantId,
@@ -101,7 +101,7 @@ func (s *bridgeService) GetList(tenantId int) ([]*dao.Bridge, *util.Errors) {
 	}
 	devices, err := device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return devices, nil

+ 26 - 25
app/device/service/cameraService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"strconv"
 	"time"
 )
@@ -15,7 +16,7 @@ var CameraService = new(cameraService)
 
 type cameraService struct{}
 
-func (s *cameraService) CreateOrUpdate(userId int64, tenantId int, req *model.CameraDetail) *util.Errors {
+func (s *cameraService) CreateOrUpdate(userId int64, tenantId int, req *model.CameraDetail) *common.Errors {
 	device := req.CameraDevice
 	device.TenantId = tenantId
 	device.UpdateUser = userId
@@ -40,36 +41,36 @@ func (s *cameraService) CreateOrUpdate(userId int64, tenantId int, req *model.Ca
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
-			return util.ParamsInvalidResponse(model.RepeatedPrompts, nil)
+			return common.ParamsInvalidResponse(model.RepeatedPrompts, nil)
 		}
 		fmt.Printf("device = %+v \n", device)
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeCamera, util.GetDeviceObject(device.ID, device.DeviceName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeCamera, common.GetDeviceObject(device.ID, device.DeviceName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeCamera, util.GetDeviceObject(device.ID, device.DeviceName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeCamera, common.GetDeviceObject(device.ID, device.DeviceName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *cameraService) Get(id int) (*model.CameraDetail, *util.Errors) {
+func (s *cameraService) Get(id int) (*model.CameraDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.CameraDevice{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	detail := &model.CameraDetail{CameraDevice: *device}
@@ -79,14 +80,14 @@ func (s *cameraService) Get(id int) (*model.CameraDetail, *util.Errors) {
 		detail.CameraTypeName = model.CameraTypeGunName
 	}
 
-	endTime, state := util.GetDeviceState(device.DeviceSN)
+	endTime, state := cache.GetDeviceState(device.DeviceSN)
 	detail.RunState = state
 	detail.NetworkState = state
 	detail.EndLineTime = endTime
 	return detail, nil
 }
 
-func (s *cameraService) List(searchValue, cameraType string, current, size int) ([]model.CameraDetail, *util.Errors) {
+func (s *cameraService) List(searchValue, cameraType string, current, size int) ([]model.CameraDetail, *common.Errors) {
 	var details []model.CameraDetail
 	device := dao.CameraDevice{}
 
@@ -105,11 +106,11 @@ func (s *cameraService) List(searchValue, cameraType string, current, size int)
 	devices, err := device.GetDevices(offset, limit)
 
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	for _, d := range devices {
-		endTime, state := util.GetDeviceState(d.DeviceSN)
+		endTime, state := cache.GetDeviceState(d.DeviceSN)
 		details = append(details, model.CameraDetail{
 			CameraDevice: d,
 			RunState:     state,
@@ -120,7 +121,7 @@ func (s *cameraService) List(searchValue, cameraType string, current, size int)
 	return details, nil
 }
 
-func (s *cameraService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *cameraService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.CameraDevice{
 		ID:         id,
@@ -131,14 +132,14 @@ func (s *cameraService) Remove(userId int64, tenantId int, id int) *util.Errors
 
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeCamera, util.GetDeviceObject(device.ID, device.DeviceName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeCamera, common.GetDeviceObject(device.ID, device.DeviceName), common.OperationSuccess)
 	return nil
 }
 
-func (s *cameraService) GetList(tenantId int) ([]dao.CameraDevice, *util.Errors) {
+func (s *cameraService) GetList(tenantId int) ([]dao.CameraDevice, *common.Errors) {
 	device := &dao.CameraDevice{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -150,13 +151,13 @@ func (s *cameraService) GetList(tenantId int) ([]dao.CameraDevice, *util.Errors)
 		results = append(results, dao.CameraDevice{ID: device.ID, DeviceName: device.DeviceName + "(" + device.DeviceSN + ")"})
 	}
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return results, nil
 }
 
-func (s *cameraService) Enable(id, status int) *util.Errors {
+func (s *cameraService) Enable(id, status int) *common.Errors {
 	// 创建查询实例
 	device := &dao.CameraDevice{
 		ID:       id,
@@ -165,7 +166,7 @@ func (s *cameraService) Enable(id, status int) *util.Errors {
 
 	err := device.UpdateEnable()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }

+ 44 - 43
app/device/service/captureUintService.go

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

+ 25 - 24
app/device/service/garbageService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,20 +14,20 @@ var GarbageService = new(garbageService)
 
 type garbageService struct{}
 
-func (s *garbageService) Get(id int) (*dao.Garbage, *util.Errors) {
+func (s *garbageService) Get(id int) (*dao.Garbage, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Garbage{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 
 }
 
-func (s *garbageService) CreateOrUpdate(userId int64, tenantId int, req dao.Garbage) *util.Errors {
+func (s *garbageService) CreateOrUpdate(userId int64, tenantId int, req dao.Garbage) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.UpdateUser = userId
@@ -37,30 +38,30 @@ func (s *garbageService) CreateOrUpdate(userId int64, tenantId int, req dao.Garb
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeGarbage, util.GetDeviceObject(device.ID, device.DeviceName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeGarbage, common.GetDeviceObject(device.ID, device.DeviceName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeGarbage, util.GetDeviceObject(device.ID, device.DeviceName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeGarbage, common.GetDeviceObject(device.ID, device.DeviceName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *garbageService) List(searchValue string, current, size int) ([]dao.Garbage, *util.Errors) {
+func (s *garbageService) List(searchValue string, current, size int) ([]dao.Garbage, *common.Errors) {
 	device := dao.Garbage{}
 	if searchValue != "" {
 		device.DeviceSN = searchValue
@@ -71,12 +72,12 @@ func (s *garbageService) List(searchValue string, current, size int) ([]dao.Garb
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *garbageService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *garbageService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.Garbage{
 		ID:         id,
@@ -86,16 +87,16 @@ func (s *garbageService) Remove(userId int64, tenantId int, id int) *util.Errors
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeGarbage, util.GetDeviceObject(device.ID, device.DeviceName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeGarbage, common.GetDeviceObject(device.ID, device.DeviceName), common.OperationSuccess)
 	return nil
 }
 
-func (s *garbageService) GetList(tenantId int) ([]*dao.Garbage, *util.Errors) {
+func (s *garbageService) GetList(tenantId int) ([]*dao.Garbage, *common.Errors) {
 	var devices []*dao.Garbage
-	err := util.Redis.Get(getGarbageListRedisKey("000000")).Scan(&devices)
+	err := cache.Redis.Get(getGarbageListRedisKey("000000")).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -105,9 +106,9 @@ func (s *garbageService) GetList(tenantId int) ([]*dao.Garbage, *util.Errors) {
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getAlarmListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getAlarmListRedisKey(tenantId), devices, 0).Err()
 	return devices, nil
 }
 

+ 25 - 24
app/device/service/garbageWayGroupService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,20 +14,20 @@ var GarbageWayGroupService = new(garbageWayGroupService)
 
 type garbageWayGroupService struct{}
 
-func (s *garbageWayGroupService) Get(id int) (*dao.GarbageWayGroup, *util.Errors) {
+func (s *garbageWayGroupService) Get(id int) (*dao.GarbageWayGroup, *common.Errors) {
 	// 创建查询实例
 	device := &dao.GarbageWayGroup{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 
 }
 
-func (s *garbageWayGroupService) CreateOrUpdate(userId int64, tenantId int, req dao.GarbageWayGroup) *util.Errors {
+func (s *garbageWayGroupService) CreateOrUpdate(userId int64, tenantId int, req dao.GarbageWayGroup) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -37,31 +38,31 @@ func (s *garbageWayGroupService) CreateOrUpdate(userId int64, tenantId int, req
 		device.CreateUser = userId
 		if device.IsExistedByName() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("存在重名,请更改名称!", nil)
+			return common.ParamsInvalidResponse("存在重名,请更改名称!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeGarbageGroup, util.GetDeviceObject(device.ID, device.GroupName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeGarbageGroup, common.GetDeviceObject(device.ID, device.GroupName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("列表中存在重名,请更改垃圾桶道路名称!", nil)
+		return common.ParamsInvalidResponse("列表中存在重名,请更改垃圾桶道路名称!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeGarbageGroup, util.GetDeviceObject(device.ID, device.GroupName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeGarbageGroup, common.GetDeviceObject(device.ID, device.GroupName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *garbageWayGroupService) List(searchValue string, current, size int) ([]dao.GarbageWayGroup, *util.Errors) {
+func (s *garbageWayGroupService) List(searchValue string, current, size int) ([]dao.GarbageWayGroup, *common.Errors) {
 	device := dao.GarbageWayGroup{}
 	if searchValue != "" {
 		device.GroupName = searchValue
@@ -71,12 +72,12 @@ func (s *garbageWayGroupService) List(searchValue string, current, size int) ([]
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *garbageWayGroupService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *garbageWayGroupService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.GarbageWayGroup{
 		ID:         id,
@@ -86,16 +87,16 @@ func (s *garbageWayGroupService) Remove(userId int64, tenantId int, id int) *uti
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeGarbageGroup, util.GetDeviceObject(device.ID, device.GroupName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeGarbageGroup, common.GetDeviceObject(device.ID, device.GroupName), common.OperationSuccess)
 	return nil
 }
 
-func (s *garbageWayGroupService) GetList(tenantId int) ([]*dao.GarbageWayGroup, *util.Errors) {
+func (s *garbageWayGroupService) GetList(tenantId int) ([]*dao.GarbageWayGroup, *common.Errors) {
 	var devices []*dao.GarbageWayGroup
-	err := util.Redis.Get(getGarbageWayGroupListRedisKey("000000")).Scan(&devices)
+	err := cache.Redis.Get(getGarbageWayGroupListRedisKey("000000")).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -105,9 +106,9 @@ func (s *garbageWayGroupService) GetList(tenantId int) ([]*dao.GarbageWayGroup,
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getGarbageWayGroupListRedisKey("000000"), devices, 0).Err()
+	_ = cache.Redis.Set(getGarbageWayGroupListRedisKey("000000"), devices, 0).Err()
 	return devices, nil
 }
 

+ 3 - 3
app/device/service/gatewayRelationService.go

@@ -2,7 +2,7 @@ package service
 
 import (
 	"iot_manager_service/app/device/dao"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 )
 
 // 中间件管理服务
@@ -10,14 +10,14 @@ var GatewayRelationService = new(gatewayRelationService)
 
 type gatewayRelationService struct{}
 
-func (s *gatewayRelationService) Get(id int) (*dao.GatewayRelation, *util.Errors) {
+func (s *gatewayRelationService) Get(id int) (*dao.GatewayRelation, *common.Errors) {
 	// 创建查询实例
 	relation := &dao.GatewayRelation{
 		ID: id,
 	}
 	err := relation.Get()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return relation, nil
 }

+ 31 - 30
app/device/service/gatewayService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -14,14 +15,14 @@ var GatewayService = new(gatewayService)
 
 type gatewayService struct{}
 
-func (s *gatewayService) Get(id int) (*model.GatewayDetail, *util.Errors) {
+func (s *gatewayService) Get(id int) (*model.GatewayDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Gateway{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	detail := &model.GatewayDetail{Gateway: *device}
@@ -33,14 +34,14 @@ func (s *gatewayService) Get(id int) (*model.GatewayDetail, *util.Errors) {
 		fmt.Printf("GatewayRelationService.Get err = %v", err)
 	}
 
-	endTime, state := util.GetDeviceState(device.GatewaySn)
+	endTime, state := cache.GetDeviceState(device.GatewaySn)
 	detail.RunState = state
 	detail.EndLineTime = endTime
 	detail.NetworkState = state
 	return detail, nil
 }
 
-func (s *gatewayService) CreateOrUpdate(userId int64, tenantId int, req *model.GatewayDetail) *util.Errors {
+func (s *gatewayService) CreateOrUpdate(userId int64, tenantId int, req *model.GatewayDetail) *common.Errors {
 	device := req.Gateway
 	device.TenantId = tenantId
 	device.UpdateUser = userId
@@ -64,29 +65,29 @@ func (s *gatewayService) CreateOrUpdate(userId int64, tenantId int, req *model.G
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
-			return util.ParamsInvalidResponse(model.RepeatedPrompts, nil)
+			return common.ParamsInvalidResponse(model.RepeatedPrompts, nil)
 		}
 		fmt.Printf("device = %+v \n", device)
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeGateway, util.GetDeviceObject(device.ID, device.GatewayName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeGateway, common.GetDeviceObject(device.ID, device.GatewayName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeGateway, util.GetDeviceObject(device.ID, device.GatewayName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeGateway, common.GetDeviceObject(device.ID, device.GatewayName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *gatewayService) List(searchValue string, current, size int) ([]model.GatewayDetail, *util.Errors) {
+func (s *gatewayService) List(searchValue string, current, size int) ([]model.GatewayDetail, *common.Errors) {
 	var details []model.GatewayDetail
 	device := dao.Gateway{}
 
@@ -98,7 +99,7 @@ func (s *gatewayService) List(searchValue string, current, size int) ([]model.Ga
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	for _, d := range devices {
 		detail := model.GatewayDetail{Gateway: d}
@@ -106,7 +107,7 @@ func (s *gatewayService) List(searchValue string, current, size int) ([]model.Ga
 		if relation != nil {
 			detail.CountLampPole = relation.Total
 		}
-		endTime, state := util.GetDeviceState(d.GatewaySn)
+		endTime, state := cache.GetDeviceState(d.GatewaySn)
 		detail.RunState = state
 		detail.EndLineTime = endTime
 		detail.NetworkState = state
@@ -115,7 +116,7 @@ func (s *gatewayService) List(searchValue string, current, size int) ([]model.Ga
 	return details, nil
 }
 
-func (s *gatewayService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *gatewayService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.Gateway{
 		ID:         id,
@@ -125,21 +126,21 @@ func (s *gatewayService) Remove(userId int64, tenantId int, id int) *util.Errors
 	}
 
 	if relation, _ := GatewayRelationService.Get(id); relation != nil && relation.Total > 0 {
-		return util.OperationInvalidResponse(model.GatewayHasRelation, nil)
+		return common.OperationInvalidResponse(model.GatewayHasRelation, nil)
 	}
 
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeGateway, util.GetDeviceObject(device.ID, device.GatewayName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeGateway, common.GetDeviceObject(device.ID, device.GatewayName), common.OperationSuccess)
 	return nil
 }
 
-func (s *gatewayService) GetList(tenantId int) ([]*dao.Gateway, *util.Errors) {
+func (s *gatewayService) GetList(tenantId int) ([]*dao.Gateway, *common.Errors) {
 	var devices []*dao.Gateway
-	err := util.Redis.Get(getGatewayListRedisKey(tenantId)).Scan(&devices)
+	err := cache.Redis.Get(getGatewayListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -153,9 +154,9 @@ func (s *gatewayService) GetList(tenantId int) ([]*dao.Gateway, *util.Errors) {
 		device.GatewayName = device.GatewayName + "(" + device.GatewaySn + ")"
 	}
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getGatewayListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getGatewayListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
@@ -164,14 +165,14 @@ func getGatewayListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.GatewayList, tenantId)
 }
 
-func (s *gatewayService) GetRelevanceDetail(id int) (*model.GatewayDetail, *util.Errors) {
+func (s *gatewayService) GetRelevanceDetail(id int) (*model.GatewayDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Gateway{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return &model.GatewayDetail{
@@ -187,14 +188,14 @@ func (s *gatewayService) GetRelevanceDetail(id int) (*model.GatewayDetail, *util
 	}, nil
 }
 
-func (s *gatewayService) GetOne(id int) (*dao.Gateway, *util.Errors) {
+func (s *gatewayService) GetOne(id int) (*dao.Gateway, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Gateway{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 }

+ 23 - 22
app/device/service/infoBoardService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,16 +14,16 @@ var InfoBoardService = new(infoBoardService)
 
 type infoBoardService struct{}
 
-func (s *infoBoardService) Get(id int) (*model.InfoBoardDetail, *util.Errors) {
+func (s *infoBoardService) Get(id int) (*model.InfoBoardDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.InfoBoard{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	endTime, state := util.GetDeviceState(device.Sn)
+	endTime, state := cache.GetDeviceState(device.Sn)
 	return &model.InfoBoardDetail{InfoBoard: *device,
 		RunState:     state,
 		NetworkState: state,
@@ -30,7 +31,7 @@ func (s *infoBoardService) Get(id int) (*model.InfoBoardDetail, *util.Errors) {
 	}, nil
 }
 
-func (s *infoBoardService) CreateOrUpdate(userId int64, tenantId int, req dao.InfoBoard) *util.Errors {
+func (s *infoBoardService) CreateOrUpdate(userId int64, tenantId int, req dao.InfoBoard) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -41,31 +42,31 @@ func (s *infoBoardService) CreateOrUpdate(userId int64, tenantId int, req dao.In
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeInfoBoard, util.GetDeviceObject(device.ID, device.InfoName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeInfoBoard, common.GetDeviceObject(device.ID, device.InfoName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeInfoBoard, util.GetDeviceObject(device.ID, device.InfoName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeInfoBoard, common.GetDeviceObject(device.ID, device.InfoName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *infoBoardService) List(searchValue string, current, size int) ([]model.InfoBoardDetail, *util.Errors) {
+func (s *infoBoardService) List(searchValue string, current, size int) ([]model.InfoBoardDetail, *common.Errors) {
 	device := dao.InfoBoard{}
 	if searchValue != "" {
 		device.Sn = searchValue
@@ -76,11 +77,11 @@ func (s *infoBoardService) List(searchValue string, current, size int) ([]model.
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var details []model.InfoBoardDetail
 	for _, d := range devices {
-		endTime, state := util.GetDeviceState(d.Sn)
+		endTime, state := cache.GetDeviceState(d.Sn)
 		details = append(details, model.InfoBoardDetail{
 			InfoBoard:    d,
 			RunState:     state,
@@ -91,7 +92,7 @@ func (s *infoBoardService) List(searchValue string, current, size int) ([]model.
 	return details, nil
 }
 
-func (s *infoBoardService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *infoBoardService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.InfoBoard{
 		ID:         id,
@@ -101,10 +102,10 @@ func (s *infoBoardService) Remove(userId int64, tenantId int, id int) *util.Erro
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeInfoBoard, util.GetDeviceObject(device.ID, device.InfoName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeInfoBoard, common.GetDeviceObject(device.ID, device.InfoName), common.OperationSuccess)
 	return nil
 }
 

+ 4 - 3
app/device/service/intelligentLightingService.go

@@ -4,7 +4,8 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"strconv"
 	"time"
 )
@@ -14,7 +15,7 @@ var IntelligentLightingService = new(intelligentLightingService)
 type intelligentLightingService struct{}
 
 func (s *intelligentLightingService) GetDetailByLight(tenantId, id int) (model.RspIntelligentLightDetail,
-	*util.Errors) {
+	*common.Errors) {
 	detail := model.RspIntelligentLightDetail{}
 	lightControl, _ := LightControlService.GetOne(id)
 	if lightControl != nil {
@@ -115,7 +116,7 @@ func (s *intelligentLightingService) List(tenantId int, searchValue string, curr
 		} else {
 			detail.LightControlState = 2
 		}
-		_, state := util.GetDeviceState(intelligentLight.LightControl.Sn)
+		_, state := cache.GetDeviceState(intelligentLight.LightControl.Sn)
 		detail.RunState = state
 		result = append(result, detail)
 	}

+ 25 - 24
app/device/service/ipBroadcastService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,16 +14,16 @@ var IpBroadcastService = new(ipBroadcastService)
 
 type ipBroadcastService struct{}
 
-func (s *ipBroadcastService) Get(id int) (*model.IpBroadcastDetail, *util.Errors) {
+func (s *ipBroadcastService) Get(id int) (*model.IpBroadcastDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.IpBroadcast{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	endTime, state := util.GetDeviceState(device.CastSn)
+	endTime, state := cache.GetDeviceState(device.CastSn)
 	return &model.IpBroadcastDetail{
 		IpBroadcast:  *device,
 		RunState:     state,
@@ -31,7 +32,7 @@ func (s *ipBroadcastService) Get(id int) (*model.IpBroadcastDetail, *util.Errors
 	}, nil
 }
 
-func (s *ipBroadcastService) CreateOrUpdate(userId int64, tenantId int, req dao.IpBroadcast) *util.Errors {
+func (s *ipBroadcastService) CreateOrUpdate(userId int64, tenantId int, req dao.IpBroadcast) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -42,31 +43,31 @@ func (s *ipBroadcastService) CreateOrUpdate(userId int64, tenantId int, req dao.
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeIPBroadcast, util.GetDeviceObject(device.ID, device.CastName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeIPBroadcast, common.GetDeviceObject(device.ID, device.CastName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeIPBroadcast, util.GetDeviceObject(device.ID, device.CastName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeIPBroadcast, common.GetDeviceObject(device.ID, device.CastName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *ipBroadcastService) List(searchValue string, current, size int) ([]model.IpBroadcastDetail, *util.Errors) {
+func (s *ipBroadcastService) List(searchValue string, current, size int) ([]model.IpBroadcastDetail, *common.Errors) {
 	device := dao.IpBroadcast{}
 	if searchValue != "" {
 		device.CastSn = searchValue
@@ -77,11 +78,11 @@ func (s *ipBroadcastService) List(searchValue string, current, size int) ([]mode
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var details []model.IpBroadcastDetail
 	for _, d := range devices {
-		endTime, state := util.GetDeviceState(d.CastSn)
+		endTime, state := cache.GetDeviceState(d.CastSn)
 		details = append(details, model.IpBroadcastDetail{
 			IpBroadcast:  d,
 			RunState:     state,
@@ -92,7 +93,7 @@ func (s *ipBroadcastService) List(searchValue string, current, size int) ([]mode
 	return details, nil
 }
 
-func (s *ipBroadcastService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *ipBroadcastService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.IpBroadcast{
 		ID:         id,
@@ -102,21 +103,21 @@ func (s *ipBroadcastService) Remove(userId int64, tenantId int, id int) *util.Er
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeIPBroadcast, util.GetDeviceObject(device.ID, device.CastName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeIPBroadcast, common.GetDeviceObject(device.ID, device.CastName), common.OperationSuccess)
 	return nil
 }
 
-func (s *ipBroadcastService) GetList(tenantId int) ([]dao.IpBroadcast, *util.Errors) {
+func (s *ipBroadcastService) GetList(tenantId int) ([]dao.IpBroadcast, *common.Errors) {
 	device := &dao.IpBroadcast{
 		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return devices, nil

+ 33 - 32
app/device/service/lampPoleGroupService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -14,19 +15,19 @@ var LampPoleGroupService = new(lampPoleGroupService)
 
 type lampPoleGroupService struct{}
 
-func (s *lampPoleGroupService) Get(id int) (*dao.LampPoleGroup, *util.Errors) {
+func (s *lampPoleGroupService) Get(id int) (*dao.LampPoleGroup, *common.Errors) {
 	// 创建查询实例
 	device := &dao.LampPoleGroup{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 }
 
-func (s *lampPoleGroupService) CreateOrUpdate(userId int64, tenantId int, req *dao.LampPoleGroup) *util.Errors {
+func (s *lampPoleGroupService) CreateOrUpdate(userId int64, tenantId int, req *dao.LampPoleGroup) *common.Errors {
 	device := req
 	device.TenantId = tenantId
 	device.UpdateUser = userId
@@ -37,32 +38,32 @@ func (s *lampPoleGroupService) CreateOrUpdate(userId int64, tenantId int, req *d
 		device.CreateUser = userId
 		if device.IsExistedByName() {
 			fmt.Printf("Create IsExistedByName \n")
-			return util.ParamsInvalidResponse(model.RepeatedName, nil)
+			return common.ParamsInvalidResponse(model.RepeatedName, nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeLampPoleGroup, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeLampPoleGroup, common.GetDeviceObject(device.ID, device.PoleGroupName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if device.IsExistedByNameAndCode() {
 		fmt.Printf("Update IsExistedByNameAndCode \n")
-		return util.ParamsInvalidResponse(model.RepeatedName, nil)
+		return common.ParamsInvalidResponse(model.RepeatedName, nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeLampPoleGroup, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeLampPoleGroup, common.GetDeviceObject(device.ID, device.PoleGroupName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *lampPoleGroupService) List(poleGroupName string, current, size int) ([]dao.LampPoleGroup, *util.Errors) {
+func (s *lampPoleGroupService) List(poleGroupName string, current, size int) ([]dao.LampPoleGroup, *common.Errors) {
 	// 创建查询实例
 	device := &dao.LampPoleGroup{
 		PoleGroupName: poleGroupName,
@@ -72,12 +73,12 @@ func (s *lampPoleGroupService) List(poleGroupName string, current, size int) ([]
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *lampPoleGroupService) Remove(userId int64, tenantId int, id int, name string) *util.Errors {
+func (s *lampPoleGroupService) Remove(userId int64, tenantId int, id int, name string) *common.Errors {
 	device := &dao.LampPoleGroup{
 		ID:         id,
 		IsDeleted:  1,
@@ -89,18 +90,18 @@ func (s *lampPoleGroupService) Remove(userId int64, tenantId int, id int, name s
 	// service.lampPoleService.CountRelation()
 	err := device.Delete()
 	if err != nil {
-		service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-			util.DeviceTypeLampPoleGroup, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationFail)
-		return util.FailResponse(err.Error(), nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+			common.DeviceTypeLampPoleGroup, common.GetDeviceObject(device.ID, device.PoleGroupName), common.OperationFail)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeLampPoleGroup, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeLampPoleGroup, common.GetDeviceObject(device.ID, device.PoleGroupName), common.OperationSuccess)
 	return nil
 }
 
-func (s *lampPoleGroupService) GetList(tenantId int) ([]*dao.LampPoleGroup, *util.Errors) {
+func (s *lampPoleGroupService) GetList(tenantId int) ([]*dao.LampPoleGroup, *common.Errors) {
 	var devices []*dao.LampPoleGroup
-	err := util.Redis.Get(getLampPoleGroupListRedisKey(tenantId)).Scan(&devices)
+	err := cache.Redis.Get(getLampPoleGroupListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -111,9 +112,9 @@ func (s *lampPoleGroupService) GetList(tenantId int) ([]*dao.LampPoleGroup, *uti
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getLampPoleGroupListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getLampPoleGroupListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
@@ -122,9 +123,9 @@ func getLampPoleGroupListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.LampPoleGroupList, tenantId)
 }
 
-func (s *lampPoleGroupService) GetFiltration(tenantId int) ([]*dao.LampPoleGroup, *util.Errors) {
+func (s *lampPoleGroupService) GetFiltration(tenantId int) ([]*dao.LampPoleGroup, *common.Errors) {
 	var devices []*dao.LampPoleGroup
-	err := util.Redis.Get(getGroupFiltrationListRedisKey(tenantId)).Scan(&devices)
+	err := cache.Redis.Get(getGroupFiltrationListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -140,9 +141,9 @@ func (s *lampPoleGroupService) GetFiltration(tenantId int) ([]*dao.LampPoleGroup
 
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getGroupFiltrationListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getGroupFiltrationListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
@@ -151,7 +152,7 @@ func getGroupFiltrationListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.GroupFiltrationList, tenantId)
 }
 
-func (s *lampPoleGroupService) GetTree(tenantId int) ([]*dao.LampPoleGroup, *util.Errors) {
+func (s *lampPoleGroupService) GetTree(tenantId int) ([]*dao.LampPoleGroup, *common.Errors) {
 	// todo use redis cache
 	device := &dao.LampPoleGroup{
 		TenantId:  tenantId,
@@ -162,7 +163,7 @@ func (s *lampPoleGroupService) GetTree(tenantId int) ([]*dao.LampPoleGroup, *uti
 
 	devices, err := device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return devices, nil

+ 27 - 27
app/device/service/lampPoleService.go

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -14,26 +14,26 @@ var LampPoleService = new(lampPoleService)
 
 type lampPoleService struct{}
 
-func (s *lampPoleService) Get(id int) (*dao.LampPole, *util.Errors) {
+func (s *lampPoleService) Get(id int) (*dao.LampPole, *common.Errors) {
 	// 创建查询实例
 	device := &dao.LampPole{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 }
 
-func (s *lampPoleService) GetRelevanceDetail(id int) (*model.LampPoleDetail, *util.Errors) {
+func (s *lampPoleService) GetRelevanceDetail(id int) (*model.LampPoleDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.LampPole{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return &model.LampPoleDetail{
@@ -50,7 +50,7 @@ func (s *lampPoleService) GetRelevanceDetail(id int) (*model.LampPoleDetail, *ut
 	}, nil
 }
 
-func (s *lampPoleService) CreateOrUpdate(userId int64, tenantId int, req *dao.LampPole) *util.Errors {
+func (s *lampPoleService) CreateOrUpdate(userId int64, tenantId int, req *dao.LampPole) *common.Errors {
 	device := req
 	device.TenantId = tenantId
 	device.CoordType = 1
@@ -63,47 +63,47 @@ func (s *lampPoleService) CreateOrUpdate(userId int64, tenantId int, req *dao.La
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
-			return util.ParamsInvalidResponse(model.RepeatedPrompts, nil)
+			return common.ParamsInvalidResponse(model.RepeatedPrompts, nil)
 		}
 		fmt.Printf("device = %+v \n", device)
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeLampPole, util.GetDeviceObject(device.ID, device.PoleName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeLampPole, common.GetDeviceObject(device.ID, device.PoleName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeLampPole, util.GetDeviceObject(device.ID, device.PoleName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeLampPole, common.GetDeviceObject(device.ID, device.PoleName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *lampPoleService) List(searchValue, groupId, boxId string, current, size int) ([]dao.LampPole, *util.Errors) {
+func (s *lampPoleService) List(searchValue, groupId, boxId string, current, size int) ([]dao.LampPole, *common.Errors) {
 	device := dao.LampPole{}
 	if searchValue != "" {
 		device.PoleSN = searchValue
 	}
 
-	device.GroupId = util.StringToInt(groupId)
-	device.BoxId = util.StringToInt(boxId)
+	device.GroupId = common.StringToInt(groupId)
+	device.BoxId = common.StringToInt(boxId)
 
 	offset := (current - 1) * size
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *lampPoleService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *lampPoleService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.LampPole{
 		ID:         id,
@@ -113,14 +113,14 @@ func (s *lampPoleService) Remove(userId int64, tenantId int, id int) *util.Error
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeLampPole, util.GetDeviceObject(device.ID, device.PoleName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeLampPole, common.GetDeviceObject(device.ID, device.PoleName), common.OperationSuccess)
 	return nil
 }
 
-func (s *lampPoleService) GetList(tenantId int) ([]*dao.LampPole, *util.Errors) {
+func (s *lampPoleService) GetList(tenantId int) ([]*dao.LampPole, *common.Errors) {
 	device := &dao.LampPole{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -130,19 +130,19 @@ func (s *lampPoleService) GetList(tenantId int) ([]*dao.LampPole, *util.Errors)
 		device.PoleName = device.PoleName + "(" + device.PoleSN + ")"
 	}
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return devices, nil
 }
 
-func (s *lampPoleService) GetOne(id int) (*dao.LampPole, *util.Errors) {
+func (s *lampPoleService) GetOne(id int) (*dao.LampPole, *common.Errors) {
 	device := &dao.LampPole{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 }

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

@@ -2,7 +2,7 @@ package service
 
 import (
 	"iot_manager_service/app/device/dao"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -11,14 +11,14 @@ var LightConditionService = new(lightConditionService)
 
 type lightConditionService struct{}
 
-func (s *lightConditionService) Get(id int) (*dao.LightCondition, *util.Errors) {
+func (s *lightConditionService) Get(id int) (*dao.LightCondition, *common.Errors) {
 	// 创建查询实例
 	condition := &dao.LightCondition{
 		ID: id,
 	}
 	err := condition.Get()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return condition, nil
 }
@@ -33,11 +33,11 @@ func (s *lightConditionService) BatchGet(ids []int) []dao.LightCondition {
 	return conditions
 }
 
-func (s *lightConditionService) CreateOrUpdate(req dao.LightCondition) *util.Errors {
+func (s *lightConditionService) CreateOrUpdate(req dao.LightCondition) *common.Errors {
 	return nil
 }
 
-func (s *lightConditionService) Remove(userId int64, id int) *util.Errors {
+func (s *lightConditionService) Remove(userId int64, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.Gateway{
 		ID:         id,
@@ -47,7 +47,7 @@ func (s *lightConditionService) Remove(userId int64, id int) *util.Errors {
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }

+ 33 - 32
app/device/service/lightControlService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"strconv"
 	"strings"
 	"time"
@@ -16,16 +17,16 @@ var LightControlService = new(lightControlService)
 
 type lightControlService struct{}
 
-func (s *lightControlService) Get(id int) (*model.LightControlDetail, *util.Errors) {
+func (s *lightControlService) Get(id int) (*model.LightControlDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.LightControl{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	endTime, state := util.GetDeviceState(device.Sn)
+	endTime, state := cache.GetDeviceState(device.Sn)
 	detail := model.LightControlDetail{
 		LightControl: *device,
 		EndLineTime:  endTime,
@@ -35,7 +36,7 @@ func (s *lightControlService) Get(id int) (*model.LightControlDetail, *util.Erro
 	return &detail, nil
 }
 
-func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *dao.LightControl) *util.Errors {
+func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *dao.LightControl) *common.Errors {
 	device := req
 	device.TenantId = tenantId
 	device.UpdateUser = userId
@@ -57,14 +58,14 @@ func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *da
 
 	if device.ControlType == model.ControlType_ZigBee {
 		if device.ZigbeeId == 0 {
-			return util.ParamsInvalidResponse(model.ZigbeeSelect, nil)
+			return common.ParamsInvalidResponse(model.ZigbeeSelect, nil)
 		}
 		if device.IsOnDemand == 0 {
 			if device.ControlNo == "" {
-				return util.ParamsInvalidResponse(model.ControlNONull, nil)
+				return common.ParamsInvalidResponse(model.ControlNONull, nil)
 			}
 			if !checkControlNoIsCompliance(device.ControlNo) {
-				return util.ParamsInvalidResponse(model.ControlNOInvalid, nil)
+				return common.ParamsInvalidResponse(model.ControlNOInvalid, nil)
 			}
 		}
 		zigbee, err := ZigbeeService.Get(device.ZigbeeId)
@@ -83,30 +84,30 @@ func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *da
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
-			return util.ParamsInvalidResponse(model.RepeatedPrompts, nil)
+			return common.ParamsInvalidResponse(model.RepeatedPrompts, nil)
 		}
 		fmt.Printf("device = %+v \n", device)
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeLightControl, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeLightControl, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeLightControl, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeLightControl, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
 func (s *lightControlService) List(searchValue, controlType, zigbeeId string, current, size int) ([]model.LightControlDetail,
-	*util.Errors) {
+	*common.Errors) {
 	device := dao.LightControl{}
 	if searchValue != "" {
 		device.Sn = searchValue
@@ -128,12 +129,12 @@ func (s *lightControlService) List(searchValue, controlType, zigbeeId string, cu
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var details []model.LightControlDetail
 	for _, d := range devices {
 		detail := model.LightControlDetail{LightControl: d}
-		endTime, state := util.GetDeviceState(d.Sn)
+		endTime, state := cache.GetDeviceState(d.Sn)
 		detail.RunState = state
 		detail.EndLineTime = endTime
 		detail.NetworkState = state
@@ -142,7 +143,7 @@ func (s *lightControlService) List(searchValue, controlType, zigbeeId string, cu
 	return details, nil
 }
 
-func (s *lightControlService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *lightControlService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.LightControl{
 		ID:         id,
@@ -152,27 +153,27 @@ func (s *lightControlService) Remove(userId int64, tenantId int, id int) *util.E
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeLightControl, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeLightControl, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
 	return nil
 }
 
-func (s *lightControlService) GetList(tenantId int) ([]dao.LightControl, *util.Errors) {
+func (s *lightControlService) GetList(tenantId int) ([]dao.LightControl, *common.Errors) {
 	device := &dao.LightControl{
 		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return devices, nil
 }
 
-func (s *lightControlService) Enable(id, status int) *util.Errors {
+func (s *lightControlService) Enable(id, status int) *common.Errors {
 	// 创建查询实例
 	device := &dao.LightControl{
 		ID:       id,
@@ -181,30 +182,30 @@ func (s *lightControlService) Enable(id, status int) *util.Errors {
 
 	err := device.UpdateEnable()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }
 
-func (s *lightControlService) GetOne(id int) (*dao.LightControl, *util.Errors) {
+func (s *lightControlService) GetOne(id int) (*dao.LightControl, *common.Errors) {
 	device := &dao.LightControl{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 }
 
-func (s *lightControlService) GetByGroupId(groupId int) ([]dao.LightControl, *util.Errors) {
+func (s *lightControlService) GetByGroupId(groupId int) ([]dao.LightControl, *common.Errors) {
 	// 创建查询实例
 	device := &dao.LightControl{
 		GroupId: groupId,
 	}
 	devices, err := device.GetDevicesByGroup()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }

+ 22 - 22
app/device/service/manholeCoverService.go

@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -12,20 +12,20 @@ var ManholeCoverService = new(manholeCoverService)
 
 type manholeCoverService struct{}
 
-func (s *manholeCoverService) Get(id int) (*dao.ManholeCover, *util.Errors) {
+func (s *manholeCoverService) Get(id int) (*dao.ManholeCover, *common.Errors) {
 	// 创建查询实例
 	device := &dao.ManholeCover{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 
 }
 
-func (s *manholeCoverService) CreateOrUpdate(userId int64, tenantId int, req dao.ManholeCover) *util.Errors {
+func (s *manholeCoverService) CreateOrUpdate(userId int64, tenantId int, req dao.ManholeCover) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -36,31 +36,31 @@ func (s *manholeCoverService) CreateOrUpdate(userId int64, tenantId int, req dao
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeManholeCover, util.GetDeviceObject(device.ID, device.ManholeName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeManholeCover, common.GetDeviceObject(device.ID, device.ManholeName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeManholeCover, util.GetDeviceObject(device.ID, device.ManholeName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeManholeCover, common.GetDeviceObject(device.ID, device.ManholeName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *manholeCoverService) List(searchValue string, current, size int) ([]dao.ManholeCover, *util.Errors) {
+func (s *manholeCoverService) List(searchValue string, current, size int) ([]dao.ManholeCover, *common.Errors) {
 	device := dao.ManholeCover{}
 	if searchValue != "" {
 		device.ManholeSn = searchValue
@@ -71,12 +71,12 @@ func (s *manholeCoverService) List(searchValue string, current, size int) ([]dao
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *manholeCoverService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *manholeCoverService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.ManholeCover{
 		ID:         id,
@@ -86,21 +86,21 @@ func (s *manholeCoverService) Remove(userId int64, tenantId int, id int) *util.E
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeManholeCover, util.GetDeviceObject(device.ID, device.ManholeName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeManholeCover, common.GetDeviceObject(device.ID, device.ManholeName), common.OperationSuccess)
 	return nil
 }
 
-func (s *manholeCoverService) GetList(tenantId int) ([]*dao.ManholeCover, *util.Errors) {
+func (s *manholeCoverService) GetList(tenantId int) ([]*dao.ManholeCover, *common.Errors) {
 	device := &dao.ManholeCover{
 		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return devices, nil

+ 26 - 25
app/device/service/onDemandGroupService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"strconv"
 	"time"
 )
@@ -15,20 +16,20 @@ var OnDemandGroupService = new(onDemandGroupService)
 
 type onDemandGroupService struct{}
 
-func (s *onDemandGroupService) Get(id int) (*dao.OnDemandGroup, *util.Errors) {
+func (s *onDemandGroupService) Get(id int) (*dao.OnDemandGroup, *common.Errors) {
 	// 创建查询实例
 	device := &dao.OnDemandGroup{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return device, nil
 }
 
-func (s *onDemandGroupService) CreateOrUpdate(userId int64, tenantId int, req *dao.OnDemandGroup) *util.Errors {
+func (s *onDemandGroupService) CreateOrUpdate(userId int64, tenantId int, req *dao.OnDemandGroup) *common.Errors {
 	device := req
 	device.TenantId = tenantId
 	device.UpdateUser = userId
@@ -40,29 +41,29 @@ func (s *onDemandGroupService) CreateOrUpdate(userId int64, tenantId int, req *d
 
 		if device.IsExistedBySN() {
 			fmt.Printf("Create IsExistedBySN \n")
-			return util.ParamsInvalidResponse(model.RepeatedPrompts, nil)
+			return common.ParamsInvalidResponse(model.RepeatedPrompts, nil)
 		}
 		fmt.Printf("device = %+v \n", device)
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeAlarmServer, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeAlarmServer, common.GetDeviceObject(device.ID, device.PoleGroupName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeAlarmServer, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeAlarmServer, common.GetDeviceObject(device.ID, device.PoleGroupName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *onDemandGroupService) List(searchValue string, current, size int) ([]dao.OnDemandGroup, *util.Errors) {
+func (s *onDemandGroupService) List(searchValue string, current, size int) ([]dao.OnDemandGroup, *common.Errors) {
 	device := dao.OnDemandGroup{}
 
 	if searchValue != "" {
@@ -73,12 +74,12 @@ func (s *onDemandGroupService) List(searchValue string, current, size int) ([]da
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *onDemandGroupService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *onDemandGroupService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.OnDemandGroup{
 		ID:         id,
@@ -88,16 +89,16 @@ func (s *onDemandGroupService) Remove(userId int64, tenantId int, id int) *util.
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeAlarmServer, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeAlarmServer, common.GetDeviceObject(device.ID, device.PoleGroupName), common.OperationSuccess)
 	return nil
 }
 
-func (s *onDemandGroupService) GetList(tenantId int) ([]*dao.OnDemandGroup, *util.Errors) {
+func (s *onDemandGroupService) GetList(tenantId int) ([]*dao.OnDemandGroup, *common.Errors) {
 	var devices []*dao.OnDemandGroup
-	err := util.Redis.Get(getOnDemandGroupListRedisKey(tenantId)).Scan(&devices)
+	err := cache.Redis.Get(getOnDemandGroupListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -108,9 +109,9 @@ func (s *onDemandGroupService) GetList(tenantId int) ([]*dao.OnDemandGroup, *uti
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getOnDemandGroupListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getOnDemandGroupListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }
@@ -119,14 +120,14 @@ func getOnDemandGroupListRedisKey(tenantId int) string {
 	return fmt.Sprintf(model.OnDemandGroupList, tenantId)
 }
 
-func (s *onDemandGroupService) GroupNumberList(id int) ([]model.RspOnDemandGroupNumber, *util.Errors) {
+func (s *onDemandGroupService) GroupNumberList(id int) ([]model.RspOnDemandGroupNumber, *common.Errors) {
 	// 创建查询实例
 	device := &dao.OnDemandGroup{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var list []model.RspOnDemandGroupNumber
 	for i := 1; i <= device.LampPoleCount; i++ {

+ 20 - 20
app/device/service/onDemandSensorService.go

@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -12,20 +12,20 @@ var OnDemandSensorService = new(onDemandSensorService)
 
 type onDemandSensorService struct{}
 
-func (s *onDemandSensorService) Get(id int) (*dao.OnDemandSensor, *util.Errors) {
+func (s *onDemandSensorService) Get(id int) (*dao.OnDemandSensor, *common.Errors) {
 	// 创建查询实例
 	device := &dao.OnDemandSensor{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 
 }
 
-func (s *onDemandSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.OnDemandSensor) *util.Errors {
+func (s *onDemandSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.OnDemandSensor) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -34,33 +34,33 @@ func (s *onDemandSensorService) CreateOrUpdate(userId int64, tenantId int, req d
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeOnDemandSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeOnDemandSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	device.UpdateUser = userId
 	device.UpdateTime = time.Now()
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeOnDemandSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeOnDemandSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *onDemandSensorService) List(searchValue string, current, size int) ([]dao.OnDemandSensor, *util.Errors) {
+func (s *onDemandSensorService) List(searchValue string, current, size int) ([]dao.OnDemandSensor, *common.Errors) {
 	device := dao.OnDemandSensor{}
 	if searchValue != "" {
 		device.SN = searchValue
@@ -71,12 +71,12 @@ func (s *onDemandSensorService) List(searchValue string, current, size int) ([]d
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *onDemandSensorService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *onDemandSensorService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.OnDemandSensor{
 		ID:         id,
@@ -86,9 +86,9 @@ func (s *onDemandSensorService) Remove(userId int64, tenantId int, id int) *util
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeOnDemandSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeOnDemandSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
 	return nil
 }

+ 25 - 24
app/device/service/optoSensoService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,16 +14,16 @@ var OptoSensorService = new(optoSensorService)
 
 type optoSensorService struct{}
 
-func (s *optoSensorService) Get(id int) (*model.OptoSensorDetail, *util.Errors) {
+func (s *optoSensorService) Get(id int) (*model.OptoSensorDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.OptoSensor{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	endTime, state := util.GetDeviceState(device.Sn)
+	endTime, state := cache.GetDeviceState(device.Sn)
 	return &model.OptoSensorDetail{
 		OptoSensor:   *device,
 		RunState:     state,
@@ -31,7 +32,7 @@ func (s *optoSensorService) Get(id int) (*model.OptoSensorDetail, *util.Errors)
 	}, nil
 }
 
-func (s *optoSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.OptoSensor) *util.Errors {
+func (s *optoSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.OptoSensor) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -42,31 +43,31 @@ func (s *optoSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.O
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeOptoSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeOptoSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeOptoSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeOptoSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *optoSensorService) List(searchValue string, current, size int) ([]model.OptoSensorDetail, *util.Errors) {
+func (s *optoSensorService) List(searchValue string, current, size int) ([]model.OptoSensorDetail, *common.Errors) {
 	device := dao.OptoSensor{}
 	if searchValue != "" {
 		device.Sn = searchValue
@@ -77,11 +78,11 @@ func (s *optoSensorService) List(searchValue string, current, size int) ([]model
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var details []model.OptoSensorDetail
 	for _, d := range devices {
-		endTime, state := util.GetDeviceState(d.Sn)
+		endTime, state := cache.GetDeviceState(d.Sn)
 		details = append(details, model.OptoSensorDetail{
 			OptoSensor:   d,
 			RunState:     state,
@@ -92,7 +93,7 @@ func (s *optoSensorService) List(searchValue string, current, size int) ([]model
 	return details, nil
 }
 
-func (s *optoSensorService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *optoSensorService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.OptoSensor{
 		ID:         id,
@@ -102,21 +103,21 @@ func (s *optoSensorService) Remove(userId int64, tenantId int, id int) *util.Err
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeOptoSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeOptoSensor, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
 	return nil
 }
 
-func (s *optoSensorService) GetList(tenantId int) ([]*dao.OptoSensor, *util.Errors) {
+func (s *optoSensorService) GetList(tenantId int) ([]*dao.OptoSensor, *common.Errors) {
 	device := &dao.OptoSensor{
 		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return devices, nil

+ 28 - 27
app/device/service/switchBoxService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,20 +14,20 @@ var SwitchBoxService = new(switchBoxService)
 
 type switchBoxService struct{}
 
-func (s *switchBoxService) Get(id int) (*dao.SwitchBox, *util.Errors) {
+func (s *switchBoxService) Get(id int) (*dao.SwitchBox, *common.Errors) {
 	// 创建查询实例
 	device := &dao.SwitchBox{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 
 }
 
-func (s *switchBoxService) CreateOrUpdate(userId int64, tenantId int, req dao.SwitchBox) *util.Errors {
+func (s *switchBoxService) CreateOrUpdate(userId int64, tenantId int, req dao.SwitchBox) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -37,33 +38,33 @@ func (s *switchBoxService) CreateOrUpdate(userId int64, tenantId int, req dao.Sw
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		util.Redis.Del(getSwitchBoxListRedisKey(tenantId))
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeSwitchBox, util.GetDeviceObject(device.ID, device.BoxName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		cache.Redis.Del(getSwitchBoxListRedisKey(tenantId))
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeSwitchBox, common.GetDeviceObject(device.ID, device.BoxName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	//更新
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	util.Redis.Del(getSwitchBoxListRedisKey(tenantId))
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeSwitchBox, util.GetDeviceObject(device.ID, device.BoxName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	cache.Redis.Del(getSwitchBoxListRedisKey(tenantId))
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeSwitchBox, common.GetDeviceObject(device.ID, device.BoxName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *switchBoxService) List(searchValue string, current, size int) ([]dao.SwitchBox, *util.Errors) {
+func (s *switchBoxService) List(searchValue string, current, size int) ([]dao.SwitchBox, *common.Errors) {
 	device := dao.SwitchBox{}
 	if searchValue != "" {
 		device.BoxSN = searchValue
@@ -74,12 +75,12 @@ func (s *switchBoxService) List(searchValue string, current, size int) ([]dao.Sw
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *switchBoxService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *switchBoxService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.SwitchBox{
 		ID:         id,
@@ -89,17 +90,17 @@ func (s *switchBoxService) Remove(userId int64, tenantId int, id int) *util.Erro
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	util.Redis.Del(getSwitchBoxListRedisKey(tenantId))
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeSwitchBox, util.GetDeviceObject(device.ID, device.BoxName), util.OperationSuccess)
+	cache.Redis.Del(getSwitchBoxListRedisKey(tenantId))
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeSwitchBox, common.GetDeviceObject(device.ID, device.BoxName), common.OperationSuccess)
 	return nil
 }
 
-func (s *switchBoxService) GetList(tenantId int) ([]*dao.SwitchBox, *util.Errors) {
+func (s *switchBoxService) GetList(tenantId int) ([]*dao.SwitchBox, *common.Errors) {
 	var devices []*dao.SwitchBox
-	err := util.Redis.Get(getSwitchBoxListRedisKey(tenantId)).Scan(&devices)
+	err := cache.Redis.Get(getSwitchBoxListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -110,9 +111,9 @@ func (s *switchBoxService) GetList(tenantId int) ([]*dao.SwitchBox, *util.Errors
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getSwitchBoxListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getSwitchBoxListRedisKey(tenantId), devices, 0).Err()
 	return devices, nil
 }
 

+ 5 - 5
app/device/service/timeConditionService.go

@@ -3,7 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 )
 
 // 灯控策略-时间策略服务
@@ -11,14 +11,14 @@ var TimeConditionService = new(timeConditionService)
 
 type timeConditionService struct{}
 
-func (s *timeConditionService) Get(id int) (*dao.TimeCondition, *util.Errors) {
+func (s *timeConditionService) Get(id int) (*dao.TimeCondition, *common.Errors) {
 	// 创建查询实例
 	condition := &dao.TimeCondition{
 		ID: id,
 	}
 	err := condition.Get()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return condition, nil
 }
@@ -47,12 +47,12 @@ func (s *timeConditionService) GetByLightId(id int) []dao.TimeCondition {
 	return conditions
 }
 
-func (s *timeConditionService) GetAll() ([]dao.TimeCondition, *util.Errors) {
+func (s *timeConditionService) GetAll() ([]dao.TimeCondition, *common.Errors) {
 	// 创建查询实例
 	condition := &dao.TimeCondition{}
 	conditions, err := condition.GetAll()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return conditions, nil
 }

+ 25 - 24
app/device/service/transformerService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,20 +14,20 @@ var TransformerService = new(transformerService)
 
 type transformerService struct{}
 
-func (s *transformerService) Get(id int) (*dao.Transformer, *util.Errors) {
+func (s *transformerService) Get(id int) (*dao.Transformer, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Transformer{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return device, nil
 
 }
 
-func (s *transformerService) CreateOrUpdate(userId int64, tenantId int, req dao.Transformer) *util.Errors {
+func (s *transformerService) CreateOrUpdate(userId int64, tenantId int, req dao.Transformer) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -37,31 +38,31 @@ func (s *transformerService) CreateOrUpdate(userId int64, tenantId int, req dao.
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeTransformer, util.GetDeviceObject(device.ID, device.TransName), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeTransformer, common.GetDeviceObject(device.ID, device.TransName), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeTransformer, util.GetDeviceObject(device.ID, device.TransName), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeTransformer, common.GetDeviceObject(device.ID, device.TransName), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *transformerService) List(searchValue string, current, size int) ([]dao.Transformer, *util.Errors) {
+func (s *transformerService) List(searchValue string, current, size int) ([]dao.Transformer, *common.Errors) {
 	device := dao.Transformer{}
 	if searchValue != "" {
 		device.TransSN = searchValue
@@ -72,12 +73,12 @@ func (s *transformerService) List(searchValue string, current, size int) ([]dao.
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return devices, nil
 }
 
-func (s *transformerService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *transformerService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.Transformer{
 		ID:         id,
@@ -87,16 +88,16 @@ func (s *transformerService) Remove(userId int64, tenantId int, id int) *util.Er
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeTransformer, util.GetDeviceObject(device.ID, device.TransName), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeTransformer, common.GetDeviceObject(device.ID, device.TransName), common.OperationSuccess)
 	return nil
 }
 
-func (s *transformerService) GetList(tenantId int) ([]*dao.Transformer, *util.Errors) {
+func (s *transformerService) GetList(tenantId int) ([]*dao.Transformer, *common.Errors) {
 	var devices []*dao.Transformer
-	err := util.Redis.Get(getTransformerListRedisKey(tenantId)).Scan(&devices)
+	err := cache.Redis.Get(getTransformerListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
 		return devices, nil
 	}
@@ -107,9 +108,9 @@ func (s *transformerService) GetList(tenantId int) ([]*dao.Transformer, *util.Er
 	}
 	devices, err = device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	_ = util.Redis.Set(getTransformerListRedisKey(tenantId), devices, 0).Err()
+	_ = cache.Redis.Set(getTransformerListRedisKey(tenantId), devices, 0).Err()
 
 	return devices, nil
 }

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

@@ -3,7 +3,7 @@ package service
 import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 )
 
 // 中间件管理服务
@@ -11,39 +11,39 @@ var WorkbenchService = new(workbenchService)
 
 type workbenchService struct{}
 
-func (s *workbenchService) CountDevice(tenantId int) ([]dao.CountDevice, *util.Errors) {
+func (s *workbenchService) CountDevice(tenantId int) ([]dao.CountDevice, *common.Errors) {
 	counts, err := dao.GetDeviceCount(tenantId)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return counts, nil
 }
 
-func (s *workbenchService) CountAlarm(tenantId int) (*dao.CountAlarm, *util.Errors) {
+func (s *workbenchService) CountAlarm(tenantId int) (*dao.CountAlarm, *common.Errors) {
 	count, err := dao.GetAlarmCount(tenantId)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return count, nil
 }
 
-func (s *workbenchService) CountJobTodo(tenantId int) (*dao.CountAlarm, *util.Errors) {
+func (s *workbenchService) CountJobTodo(tenantId int) (*dao.CountAlarm, *common.Errors) {
 	count, err := dao.GetAlarmCount(tenantId)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return count, nil
 }
 
-func (s *workbenchService) Notification(tenantId int) (*dao.Notification, *util.Errors) {
+func (s *workbenchService) Notification(tenantId int) (*dao.Notification, *common.Errors) {
 	notification, err := dao.GetNotification(tenantId)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	return notification, nil
 }
 
-func (s *workbenchService) LightRate(tenantId int) (*model.RspLightRate, *util.Errors) {
+func (s *workbenchService) LightRate(tenantId int) (*model.RspLightRate, *common.Errors) {
 	var rsp model.RspLightRate
 	return &rsp, nil
 }

+ 25 - 24
app/device/service/zigbeeService.go

@@ -5,7 +5,8 @@ import (
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -13,16 +14,16 @@ var ZigbeeService = new(zigbeeService)
 
 type zigbeeService struct{}
 
-func (s *zigbeeService) Get(id int) (*model.ZigbeeDetail, *util.Errors) {
+func (s *zigbeeService) Get(id int) (*model.ZigbeeDetail, *common.Errors) {
 	// 创建查询实例
 	device := &dao.Zigbee{
 		ID: id,
 	}
 	err := device.GetDevice()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
-	endTime, state := util.GetDeviceState(device.Sn)
+	endTime, state := cache.GetDeviceState(device.Sn)
 	return &model.ZigbeeDetail{
 		Zigbee:       *device,
 		RunState:     state,
@@ -32,7 +33,7 @@ func (s *zigbeeService) Get(id int) (*model.ZigbeeDetail, *util.Errors) {
 
 }
 
-func (s *zigbeeService) CreateOrUpdate(userId int64, tenantId int, req dao.Zigbee) *util.Errors {
+func (s *zigbeeService) CreateOrUpdate(userId int64, tenantId int, req dao.Zigbee) *common.Errors {
 	// 创建查询实例
 	device := req
 	device.TenantId = tenantId
@@ -43,30 +44,30 @@ func (s *zigbeeService) CreateOrUpdate(userId int64, tenantId int, req dao.Zigbe
 		device.CreateUser = userId
 		if device.IsExistedBySN() {
 			fmt.Printf("Create GetDeviceID err \n")
-			return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+			return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		service.OperationHisService.Save(userId, tenantId, util.OperationCreate, util.ModuleTypeDevice,
-			util.DeviceTypeZigbee, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-		return util.SuccessResponse(util.Succeeded, nil)
+		service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeDevice,
+			common.DeviceTypeZigbee, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	if device.IsExistedByNameAndCode() {
-		return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
+		return common.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
 	}
 
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationUpdate, util.ModuleTypeDevice,
-		util.DeviceTypeZigbee, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
-	return util.SuccessResponse(util.Succeeded, nil)
+	service.OperationHisService.Save(userId, tenantId, common.OperationUpdate, common.ModuleTypeDevice,
+		common.DeviceTypeZigbee, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
-func (s *zigbeeService) List(searchValue string, current, size int) ([]model.ZigbeeDetail, *util.Errors) {
+func (s *zigbeeService) List(searchValue string, current, size int) ([]model.ZigbeeDetail, *common.Errors) {
 	device := dao.Zigbee{}
 	if searchValue != "" {
 		device.Sn = searchValue
@@ -77,11 +78,11 @@ func (s *zigbeeService) List(searchValue string, current, size int) ([]model.Zig
 	limit := size
 	devices, err := device.GetDevices(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var details []model.ZigbeeDetail
 	for _, d := range devices {
-		endTime, state := util.GetDeviceState(d.Sn)
+		endTime, state := cache.GetDeviceState(d.Sn)
 		details = append(details, model.ZigbeeDetail{
 			Zigbee:       d,
 			RunState:     state,
@@ -92,7 +93,7 @@ func (s *zigbeeService) List(searchValue string, current, size int) ([]model.Zig
 	return details, nil
 }
 
-func (s *zigbeeService) Remove(userId int64, tenantId int, id int) *util.Errors {
+func (s *zigbeeService) Remove(userId int64, tenantId int, id int) *common.Errors {
 	// 创建查询实例
 	device := &dao.Zigbee{
 		ID:         id,
@@ -102,21 +103,21 @@ func (s *zigbeeService) Remove(userId int64, tenantId int, id int) *util.Errors
 	}
 	err := device.Delete()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
-		util.DeviceTypeZigbee, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
+	service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeDevice,
+		common.DeviceTypeZigbee, common.GetDeviceObject(device.ID, device.Name), common.OperationSuccess)
 	return nil
 }
 
-func (s *zigbeeService) GetList(tenantId int) ([]dao.Zigbee, *util.Errors) {
+func (s *zigbeeService) GetList(tenantId int) ([]dao.Zigbee, *common.Errors) {
 	device := &dao.Zigbee{
 		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
 	devices, err := device.GetAllDevices()
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 
 	return devices, nil

+ 2 - 2
app/middleware/checkAuth.go

@@ -2,7 +2,7 @@ package middleware
 
 import (
 	"github.com/gin-gonic/gin"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"net/http"
 	"strings"
 )
@@ -27,7 +27,7 @@ func CheckAuth() gin.HandlerFunc {
 				return
 			}
 		}
-		ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "token is invalid", nil))
+		ctx.JSON(http.StatusUnauthorized, common.NormalResponse(http.StatusUnauthorized, "token is invalid", nil))
 		ctx.Abort()
 	}
 }

+ 0 - 12
app/middleware/checkLogin.go

@@ -1,12 +0,0 @@
-package middleware
-
-import (
-	"github.com/gin-gonic/gin"
-)
-
-func CheckLogin() gin.HandlerFunc {
-	return func(ctx *gin.Context) {
-		// 前置中间件
-		ctx.Next()
-	}
-}

+ 2 - 2
app/record/controller/lightRecordController.go

@@ -3,7 +3,7 @@ package controller
 import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/record/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"net/http"
 	"strconv"
 )
@@ -27,5 +27,5 @@ func (c *lightRecordCtl) List(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, records))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
 }

+ 2 - 2
app/record/service/lightRecordService.go

@@ -2,14 +2,14 @@ package service
 
 import (
 	"iot_manager_service/app/record/dao"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 )
 
 var LightRecordService = new(lightRecordService)
 
 type lightRecordService struct{}
 
-func (s *lightRecordService) List(searchValue, start, end string, id int) ([]dao.LightRecord, *util.Errors) {
+func (s *lightRecordService) List(searchValue, start, end string, id int) ([]dao.LightRecord, *common.Errors) {
 	var records []dao.LightRecord
 	return records, nil
 }

+ 2 - 2
app/security/controller/securityController.go

@@ -4,7 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/middleware"
 	"iot_manager_service/app/security/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"net/http"
 )
 
@@ -22,5 +22,5 @@ func (c *securityCtl) GetCameraLiveList(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Success, list))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, list))
 }

+ 4 - 3
app/security/service/securityService.go

@@ -3,14 +3,15 @@ package service
 import (
 	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/security/model"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 )
 
 var SecurityService = new(securityService)
 
 type securityService struct{}
 
-func (s *securityService) GetCameraLiveList(tenantId int) ([]model.CameraLiveDetail, *util.Errors) {
+func (s *securityService) GetCameraLiveList(tenantId int) ([]model.CameraLiveDetail, *common.Errors) {
 	groups, err := service.LampPoleGroupService.GetList(tenantId)
 	if err != nil {
 		return nil, nil
@@ -21,7 +22,7 @@ func (s *securityService) GetCameraLiveList(tenantId int) ([]model.CameraLiveDet
 		cameraDevices := service.CameraService.GetByLampPoleGroup(group.ID)
 		var cameraList []model.CameraLive
 		for _, cameraDevice := range cameraDevices {
-			_, state := util.GetDeviceState(cameraDevice.DeviceSN)
+			_, state := cache.GetDeviceState(cameraDevice.DeviceSN)
 			poleGroupName := cameraDevice.DeviceName + "(离线)"
 			if state == "1" {
 				poleGroupName = cameraDevice.DeviceName + "在线"

+ 3 - 3
app/system/controller/dict.go

@@ -3,7 +3,7 @@ package controller
 import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"net/http"
 )
 
@@ -15,8 +15,8 @@ func (c *dict) Dictionary(ctx *gin.Context) {
 	code := ctx.Query("code")
 	result, err := service.DictService.GetByCode(code)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Success, result))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, result))
 }

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

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/middleware"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"net/http"
 	"strconv"
 )
@@ -18,7 +18,7 @@ func (c *menu) GetDetail(ctx *gin.Context) {
 	id := ctx.Query("id")
 	iId, err := strconv.ParseInt(id, 10, 64)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	detail, err := service.MenuService.Get(iId)
@@ -26,7 +26,7 @@ func (c *menu) GetDetail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, detail))
 }
 
 func (c *menu) List(ctx *gin.Context) {
@@ -45,10 +45,10 @@ func (c *menu) LazyList(ctx *gin.Context) {
 
 	menus, err := service.MenuService.LazyList(parentId, name, code, alias)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, menus))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, menus))
 }
 
 func (c *menu) MenuList(ctx *gin.Context) {
@@ -62,7 +62,7 @@ func (c *menu) LazyMenuList(ctx *gin.Context) {
 func (c *menu) Submit(ctx *gin.Context) {
 	var req dao.Menu
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.MenuService.Submit(req)
@@ -79,10 +79,10 @@ func (c *menu) Routes(ctx *gin.Context) {
 
 	menus, err := service.MenuService.Routes(claims.RoleId)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, menus))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, menus))
 }
 
 func (c *menu) RoutesExt(cxt *gin.Context) {
@@ -96,10 +96,10 @@ func (c *menu) Buttons(ctx *gin.Context) {
 func (c *menu) Tree(ctx *gin.Context) {
 	menus, err := service.MenuService.Tree()
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, menus))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, menus))
 }
 
 func (c *menu) GrantTree(ctx *gin.Context) {

+ 11 - 11
app/system/controller/role.go

@@ -5,7 +5,7 @@ import (
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -19,7 +19,7 @@ func (c *role) GetDetail(ctx *gin.Context) {
 	id := ctx.Query("id")
 	iId, err := strconv.ParseInt(id, 10, 64)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	role, err := service.RoleService.Get(iId)
@@ -27,7 +27,7 @@ func (c *role) GetDetail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, role))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, role))
 }
 
 func (c *role) List(ctx *gin.Context) {
@@ -56,7 +56,7 @@ func (c *role) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: roles,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *role) Tree(ctx *gin.Context) {
@@ -72,7 +72,7 @@ func (c *role) Tree(ctx *gin.Context) {
 func (c *role) Submit(ctx *gin.Context) {
 	var req dao.Role
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.RoleService.Submit(req)
@@ -82,7 +82,7 @@ func (c *role) Submit(ctx *gin.Context) {
 func (c *role) Remove(ctx *gin.Context) {
 	var req *model.ReqRoleRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.RoleService.Remove(req.IDs)
@@ -92,20 +92,20 @@ func (c *role) Remove(ctx *gin.Context) {
 func (c *role) GetList(ctx *gin.Context) {
 	roles, err := service.RoleService.GetList()
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, roles))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, roles))
 }
 
 func (c *role) Grant(ctx *gin.Context) {
 	var req *model.ReqRoleGrant
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.RoleService.Grant(req)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
 }

+ 10 - 10
app/system/controller/tenant.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -19,14 +19,14 @@ type tenant struct{}
 func (c *tenant) GetInfo(ctx *gin.Context) {
 	domain := ctx.Query("domain")
 	tenant, _ := service.TenantService.GetByDomain(domain)
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, tenant))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, tenant))
 }
 
 func (c *tenant) GetDetail(ctx *gin.Context) {
 	id := ctx.Query("id")
 	iId, err := strconv.ParseInt(id, 10, 64)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	tenant, err := service.TenantService.Get(iId)
@@ -34,7 +34,7 @@ func (c *tenant) GetDetail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, tenant))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, tenant))
 }
 
 func (c *tenant) List(ctx *gin.Context) {
@@ -52,7 +52,7 @@ func (c *tenant) List(ctx *gin.Context) {
 
 	tId, err := strconv.Atoi(tenantId)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	tenants, err := service.TenantService.List(tId, tenantName, linkman, current, size)
@@ -68,13 +68,13 @@ func (c *tenant) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: tenants,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *tenant) Submit(ctx *gin.Context) {
 	var req dao.Tenant
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.TenantService.Submit(req)
@@ -87,7 +87,7 @@ func (c *tenant) Remove(ctx *gin.Context) {
 
 	var req *model.ReqTenantRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.TenantService.Remove(claims.UserId, req.IDs)
@@ -97,7 +97,7 @@ func (c *tenant) Remove(ctx *gin.Context) {
 func (c *tenant) GetList(ctx *gin.Context) {
 	tenants, err := service.TenantService.GetList()
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, tenants))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, tenants))
 }

+ 29 - 28
app/system/controller/token.go

@@ -9,12 +9,13 @@ import (
 	"iot_manager_service/app/middleware"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/service"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"strconv"
 	"time"
 
 	"iot_manager_service/app/system/model"
 	"iot_manager_service/config"
-	"iot_manager_service/util"
 	"net/http"
 	"strings"
 )
@@ -54,7 +55,7 @@ func (c *auth) Token(ctx *gin.Context) {
 		UserType:     userType,
 	}
 	var userInfo *model.UserInfo
-	var err *util.Errors
+	var err *common.Errors
 	if grantType == "captcha" {
 		userInfo, err = captchaGrant(token, ctx)
 		if err != nil {
@@ -70,24 +71,24 @@ func (c *auth) Token(ctx *gin.Context) {
 	}
 
 	if userInfo == nil || userInfo.User == nil {
-		ctx.JSON(http.StatusOK, util.NormalResponse(http.StatusBadRequest, model.UserNotFound, nil))
+		ctx.JSON(http.StatusOK, common.NormalResponse(http.StatusBadRequest, model.UserNotFound, nil))
 		return
 	}
 	if len(userInfo.Roles) == 0 {
-		ctx.JSON(http.StatusOK, util.NormalResponse(http.StatusBadRequest, model.UserHasNoRole, nil))
+		ctx.JSON(http.StatusOK, common.NormalResponse(http.StatusBadRequest, model.UserHasNoRole, nil))
 		return
 	}
 
 	// access token过期时间2小时
-	random := util.RandomString(8)
+	random := common.RandomString(8)
 	jwtToken, e := middleware.GetAccessToken(userInfo.ID, userInfo.RoleId, userInfo.TenantId, userInfo.Account, random)
 	if e != nil {
-		ctx.JSON(http.StatusOK, util.NormalResponse(http.StatusBadRequest, e.Error(), nil))
+		ctx.JSON(http.StatusOK, common.NormalResponse(http.StatusBadRequest, e.Error(), nil))
 		return
 	}
 
 	// redis记录缓存2小时
-	util.Redis.Set(getAccessTokenKey(userInfo.TenantId, userInfo.ID, random), jwtToken, 2*time.Hour)
+	cache.Redis.Set(getAccessTokenKey(userInfo.TenantId, userInfo.ID, random), jwtToken, 2*time.Hour)
 	ctx.JSON(http.StatusOK, model.RspToken{
 		TenantId:     userInfo.TenantId,
 		UserId:       userInfo.ID,
@@ -110,35 +111,35 @@ func (c *auth) Logout(ctx *gin.Context) {
 	value, _ := ctx.Get(middleware.Authorization)
 	claims := value.(*middleware.Claims)
 
-	_ = util.Redis.Del(getAccessTokenKey(claims.TenantId, claims.UserId, claims.Random)).Err()
-	service.OperationHisService.Save(claims.UserId, claims.TenantId, util.OperationLogout, util.ModuleTypeDefault,
-		util.DeviceTypeDefault, "", util.OperationSuccess)
-	ctx.JSON(http.StatusOK, util.SuccessResponse("", nil))
+	_ = cache.Redis.Del(getAccessTokenKey(claims.TenantId, claims.UserId, claims.Random)).Err()
+	service.OperationHisService.Save(claims.UserId, claims.TenantId, common.OperationLogout, common.ModuleTypeDefault,
+		common.DeviceTypeDefault, "", common.OperationSuccess)
+	ctx.JSON(http.StatusOK, common.SuccessResponse("", nil))
 }
 
 func (c *auth) Captcha(ctx *gin.Context) {
 	id := uuid.NewV1().String()
-	code := util.RandomString2(5)
+	code := common.RandomString2(5)
 	gotItem, _ := driver.DrawCaptcha(code)
 	image := gotItem.EncodeB64string()
 	rsp := model.RspCaptcha{
 		Key:   id,
 		Image: image,
 	}
-	util.Redis.Set(getCaptchaKey(id), code, 5*time.Minute)
+	cache.Redis.Set(getCaptchaKey(id), code, 5*time.Minute)
 	ctx.JSON(http.StatusOK, rsp)
 }
 
 func (c *auth) Clear(ctx *gin.Context) {
 	//todo clear redis
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Success, nil))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, nil))
 }
 
 func (c *auth) Login(ctx *gin.Context) {
 	passKey := ctx.Query("passKey")
 	tenant, err := service.TenantService.GetTenantByPasskey(passKey)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.SuccessResponse(model.TenantNotFound, nil))
+		ctx.JSON(http.StatusOK, common.SuccessResponse(model.TenantNotFound, nil))
 		return
 	}
 	rsp := model.RspLogin{
@@ -147,7 +148,7 @@ func (c *auth) Login(ctx *gin.Context) {
 		BackgroundUrl: tenant.BackgroundUrl,
 		SysLogoUrl:    tenant.SysLogoUrl,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Success, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
 }
 
 //checkLock 校验用户登录失败次数
@@ -177,29 +178,29 @@ func parseRefreshToken(refreshToken string) *jwt.MapClaims {
 	return token.Claims.(*jwt.MapClaims)
 }
 
-func captchaGrant(token model.Token, ctx *gin.Context) (*model.UserInfo, *util.Errors) {
+func captchaGrant(token model.Token, ctx *gin.Context) (*model.UserInfo, *common.Errors) {
 	info := &model.UserInfo{}
 	key := ctx.GetHeader(model.CaptchaHeaderKey)
 	code := ctx.GetHeader(model.CaptchaHeaderCode)
 	// 获取验证码
-	result, err := util.Redis.Get(getCaptchaKey(key)).Result()
+	result, err := cache.Redis.Get(getCaptchaKey(key)).Result()
 	if err != nil {
-		return nil, util.NormalResponse(http.StatusBadRequest, model.CaptchaNotCorrect, nil)
+		return nil, common.NormalResponse(http.StatusBadRequest, model.CaptchaNotCorrect, nil)
 	}
 	redisCode := result
 	// 判断验证码
 	if config.Instance().Server.CodeEnabled && (key == "" || code == "" || !strings.EqualFold(redisCode, code)) {
-		return nil, util.NormalResponse(http.StatusBadRequest, model.CaptchaNotCorrect, nil)
+		return nil, common.NormalResponse(http.StatusBadRequest, model.CaptchaNotCorrect, nil)
 	}
 
 	if token.UserName != "" && token.Password != "" {
 		// 获取租户信息
 		tenant, err := service.TenantService.GetOne(token.TenantId)
 		if err != nil || tenant == nil {
-			return nil, util.NormalResponse(http.StatusOK, model.UserHasNoTenant, nil)
+			return nil, common.NormalResponse(http.StatusOK, model.UserHasNoTenant, nil)
 		}
 		if judgeTenant(tenant) {
-			return nil, util.NormalResponse(http.StatusOK, model.UserHasNoTenantPermission, nil)
+			return nil, common.NormalResponse(http.StatusOK, model.UserHasNoTenantPermission, nil)
 		}
 		// 获取用户类型
 		// 根据不同用户类型调用对应的接口返回数据,用户可自行拓展
@@ -207,27 +208,27 @@ func captchaGrant(token model.Token, ctx *gin.Context) (*model.UserInfo, *util.E
 		info.TenantId = token.TenantId
 		info.Roles = []string{"admin"}
 		if info.User != nil {
-			service.OperationHisService.Save(info.User.ID, info.TenantId, util.OperationLogin,
-				util.ModuleTypeDefault, util.DeviceTypeDefault, "", util.OperationSuccess)
+			service.OperationHisService.Save(info.User.ID, info.TenantId, common.OperationLogin,
+				common.ModuleTypeDefault, common.DeviceTypeDefault, "", common.OperationSuccess)
 		}
 	}
 	return info, nil
 }
 
-func refreshGrant(token model.Token) (*model.UserInfo, *util.Errors) {
+func refreshGrant(token model.Token) (*model.UserInfo, *common.Errors) {
 	info := &model.UserInfo{}
 	jwtToken := parseRefreshToken(token.RefreshToken)
 	if jwtToken == nil || len(*jwtToken) != 7 {
-		return nil, util.NormalResponse(http.StatusOK, model.UserHasNoTenantPermission, nil)
+		return nil, common.NormalResponse(http.StatusOK, model.UserHasNoTenantPermission, nil)
 	}
 
 	// 获取租户信息
 	tenant, _ := service.TenantService.GetOne(token.TenantId)
 	if tenant == nil {
-		return nil, util.NormalResponse(http.StatusOK, model.UserHasNoTenant, nil)
+		return nil, common.NormalResponse(http.StatusOK, model.UserHasNoTenant, nil)
 	}
 	if judgeTenant(tenant) {
-		return nil, util.NormalResponse(http.StatusOK, model.UserHasNoTenantPermission, nil)
+		return nil, common.NormalResponse(http.StatusOK, model.UserHasNoTenantPermission, nil)
 	}
 
 	info.User = service.UserService.GetOneByTenantId(token.TenantId)

+ 12 - 12
app/system/controller/user.go

@@ -6,7 +6,7 @@ import (
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
 	"iot_manager_service/app/system/service"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"math"
 	"net/http"
 	"strconv"
@@ -21,7 +21,7 @@ func (c *user) GetDetail(ctx *gin.Context) {
 	id := ctx.Query("id")
 	iId, err := strconv.ParseInt(id, 10, 64)
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	detail, err := service.UserService.Get(iId)
@@ -29,7 +29,7 @@ func (c *user) GetDetail(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, err)
 		return
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, detail))
 
 }
 
@@ -58,13 +58,13 @@ func (c *user) List(ctx *gin.Context) {
 		Pages:   int(pages),
 		Records: users,
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
 }
 
 func (c *user) Submit(ctx *gin.Context) {
 	var req dao.User
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.UserService.Submit(req)
@@ -74,7 +74,7 @@ func (c *user) Submit(ctx *gin.Context) {
 func (c *user) Update(ctx *gin.Context) {
 	var req dao.User
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.UserService.Update(req)
@@ -87,7 +87,7 @@ func (c *user) Remove(ctx *gin.Context) {
 
 	var req *model.ReqUserRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.UserService.Remove(claims.UserId, req.IDs)
@@ -97,7 +97,7 @@ func (c *user) Remove(ctx *gin.Context) {
 func (c *user) ResetPwd(ctx *gin.Context) {
 	var req *model.ReqUserResetPwd
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	err := service.UserService.ResetPwd(req.IDs)
@@ -107,21 +107,21 @@ func (c *user) ResetPwd(ctx *gin.Context) {
 func (c *user) GetList(ctx *gin.Context) {
 	users, err := service.UserService.GetList()
 	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.FailResponse(err.Error(), nil))
 	}
-	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, users))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, users))
 }
 
 func (c *user) Grant(ctx *gin.Context) {
 	var req *model.ReqUserGrant
 	if err := ctx.ShouldBindJSON(&req); err != nil {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
 	uIds := strings.Split(req.UserIds, ",")
 	rIds := strings.Split(req.RoleIds, ",")
 	if len(uIds) < 1 || len(rIds) < 1 {
-		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.GrantInvalid, nil))
+		ctx.JSON(http.StatusOK, common.ParamsInvalidResponse(model.GrantInvalid, nil))
 		return
 	}
 	err := service.UserService.Grant(uIds, req.RoleIds)

+ 8 - 2
app/system/dao/roleMenu.go

@@ -22,8 +22,14 @@ func (c *RoleMenu) DeleteRoleIds(roleIds []int64) error {
 	return Db.Debug().Model(&c).Where("role_id in ?", roleIds).Delete(&c).Error
 }
 
-func (c *RoleMenu) GetByRole() ([]RoleMenu, error) {
+func (c *RoleMenu) GetMenusByRole() ([]RoleMenu, error) {
 	var menus []RoleMenu
-	err := Db.Debug().Model(&c).Where("role_id = ?", c.RoleId).Find(&menus).Error
+	err := Db.Debug().Table("role_menu").Select("distinct menu_id").Where("role_id = ?", c.RoleId).Find(&menus).Error
+	return menus, err
+}
+
+func (c *RoleMenu) GetAll() ([]RoleMenu, error) {
+	var menus []RoleMenu
+	err := Db.Debug().Table("role_menu").Select("distinct menu_id").Find(&menus).Error
 	return menus, err
 }

+ 7 - 7
app/system/service/dictService.go

@@ -3,7 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/system/dao"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
 	"strconv"
 )
 
@@ -29,14 +29,14 @@ func (s *dictService) GetByCode(code string) ([]dao.Dict, error) {
 func (s *dictService) GetControlType(tenantId int, id int) string {
 	var name string
 	key := fmt.Sprintf(ControlTypeKey, tenantId, id)
-	name, err := util.Redis.Get(key).Result()
+	name, err := cache.Redis.Get(key).Result()
 	if err != nil {
 		dict := &dao.Dict{Code: ControlType, DictKey: strconv.Itoa(id)}
 		if err := dict.GetByCodeAndKey(); err != nil {
 			fmt.Printf("GetByCodeAndKey err = %d \n", err)
 		} else {
 			name = dict.DictValue
-			util.Redis.Set(key, name, -1)
+			cache.Redis.Set(key, name, -1)
 		}
 	}
 	return name
@@ -45,14 +45,14 @@ func (s *dictService) GetControlType(tenantId int, id int) string {
 func (s *dictService) GetModuleName(tenantId int, id int) string {
 	var name string
 	key := fmt.Sprintf(ModuleTypeKey, tenantId, id)
-	name, err := util.Redis.Get(key).Result()
+	name, err := cache.Redis.Get(key).Result()
 	if err != nil {
 		dict := &dao.Dict{Code: ModuleType, DictKey: strconv.Itoa(id)}
 		if err := dict.GetByCodeAndKey(); err != nil {
 			fmt.Printf("GetByCodeAndKey err = %d \n", err)
 		} else {
 			name = dict.DictValue
-			util.Redis.Set(key, name, -1)
+			cache.Redis.Set(key, name, -1)
 		}
 	}
 	return name
@@ -61,14 +61,14 @@ func (s *dictService) GetModuleName(tenantId int, id int) string {
 func (s *dictService) GetSexName(tenantId int, id int) string {
 	var name string
 	key := fmt.Sprintf(SexNameKey, tenantId, id)
-	name, err := util.Redis.Get(key).Result()
+	name, err := cache.Redis.Get(key).Result()
 	if err != nil {
 		dict := &dao.Dict{Code: Sex, DictKey: strconv.Itoa(id)}
 		if err := dict.GetByCodeAndKey(); err != nil {
 			fmt.Printf("GetByCodeAndKey err = %d \n", err)
 		} else {
 			name = dict.DictValue
-			util.Redis.Set(key, name, -1)
+			cache.Redis.Set(key, name, -1)
 		}
 	}
 	return name

+ 6 - 7
app/system/service/menuService.go

@@ -3,7 +3,7 @@ package service
 import (
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 )
 
 var MenuService = new(menuService)
@@ -21,20 +21,20 @@ func (s *menuService) Get(id int64) (*dao.Menu, error) {
 	return menu, nil
 }
 
-func (s *menuService) Submit(req dao.Menu) *util.Errors {
+func (s *menuService) Submit(req dao.Menu) *common.Errors {
 	role := &req
 	if role.ID == 0 {
 		err := role.Save()
 		if err != nil {
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		return util.SuccessResponse(util.Succeeded, nil)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	err := role.Update()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	return util.SuccessResponse(util.Succeeded, nil)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
 func (s *menuService) GetAll() []dao.Menu {
@@ -79,7 +79,6 @@ func (s *menuService) Routes(roleId int64) ([]model.MenuRouteDetail, error) {
 	}
 
 	roleMenus := RoleMenuService.GetMenuByRole(roleId)
-
 	var rsp []model.MenuRouteDetail
 	//上级角色——多个下级角色数组
 	tmp := make(map[int64][]dao.Menu)

+ 5 - 5
app/system/service/operationHisService.go

@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
-	"iot_manager_service/util"
+	"iot_manager_service/util/common"
 	"strconv"
 	"time"
 )
@@ -33,21 +33,21 @@ func (s *operationHisService) Save(userId int64, tenantId int, handleType, handl
 }
 
 func (s *operationHisService) List(tenantId int, handleContent, operationType, moduleType string, current,
-	size int) ([]model.OperationHisDetail, *util.Errors) {
+	size int) ([]model.OperationHisDetail, *common.Errors) {
 	his := dao.OperationHistory{
 		Object: handleContent,
 	}
 	if operationType != "" {
 		operation, err := strconv.Atoi(operationType)
 		if err != nil {
-			return nil, util.FailResponse(err.Error(), nil)
+			return nil, common.FailResponse(err.Error(), nil)
 		}
 		his.OperationType = operation
 	}
 	if moduleType != "" {
 		module, err := strconv.Atoi(moduleType)
 		if err != nil {
-			return nil, util.FailResponse(err.Error(), nil)
+			return nil, common.FailResponse(err.Error(), nil)
 		}
 		his.ModuleType = module
 	}
@@ -56,7 +56,7 @@ func (s *operationHisService) List(tenantId int, handleContent, operationType, m
 	limit := size
 	list, err := his.GetHistories(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var details []model.OperationHisDetail
 	for _, his := range list {

+ 16 - 5
app/system/service/roleMenuService.go

@@ -1,6 +1,9 @@
 package service
 
-import "iot_manager_service/app/system/dao"
+import (
+	"iot_manager_service/app/system/dao"
+	"iot_manager_service/util/common"
+)
 
 // 角色菜单管理服务
 var RoleMenuService = new(roleMenuService)
@@ -28,9 +31,17 @@ func (s *roleMenuService) UpdateRoleMenus(roleIds, menuIds []int64) error {
 
 func (s *roleMenuService) GetMenuByRole(roleId int64) []dao.RoleMenu {
 	roleMenu := &dao.RoleMenu{RoleId: roleId}
-	menus, err := roleMenu.GetByRole()
-	if err != nil {
-		return nil
+	if common.IsAdmin(roleId) {
+		menus, err := roleMenu.GetAll()
+		if err != nil {
+			return nil
+		}
+		return menus
+	} else {
+		menus, err := roleMenu.GetMenusByRole()
+		if err != nil {
+			return nil
+		}
+		return menus
 	}
-	return menus
 }

+ 14 - 13
app/system/service/roleService.go

@@ -4,7 +4,8 @@ import (
 	"fmt"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"strconv"
 )
 
@@ -101,20 +102,20 @@ func dfs(result []model.RoleDetail, roles []dao.Role, tmp map[int64][]dao.Role)
 	return result
 }
 
-func (s *roleService) Submit(req dao.Role) *util.Errors {
+func (s *roleService) Submit(req dao.Role) *common.Errors {
 	role := &req
 	if role.ID == 0 {
 		err := role.Save()
 		if err != nil {
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		return util.SuccessResponse(util.Succeeded, nil)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	err := role.Update()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	return util.SuccessResponse(util.Succeeded, nil)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
 func (s *roleService) GetList() ([]dao.Role, error) {
@@ -126,7 +127,7 @@ func (s *roleService) GetList() ([]dao.Role, error) {
 	return roles, nil
 }
 
-func (s *roleService) Remove(id int64) *util.Errors {
+func (s *roleService) Remove(id int64) *common.Errors {
 	role := &dao.Role{
 		ID:        id,
 		IsDeleted: 1,
@@ -137,20 +138,20 @@ func (s *roleService) Remove(id int64) *util.Errors {
 		IsDeleted: 0,
 	}
 	if queryRole.IsExistChild() {
-		return util.FailResponse(model.ExistChild, nil)
+		return common.FailResponse(model.ExistChild, nil)
 	}
 
 	err := role.Remove()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }
 
 func (s *roleService) Grant(req *model.ReqRoleGrant) error {
-	roleIds := util.StringToIntArray(req.RoleIds)
+	roleIds := common.StringToIntArray(req.RoleIds)
 	//todo 数据权限 接口权限
-	menuIds := util.StringToIntArray(req.MenuIds)
+	menuIds := common.StringToIntArray(req.MenuIds)
 	menuErr := RoleMenuService.UpdateRoleMenus(roleIds, menuIds)
 	return menuErr
 }
@@ -160,14 +161,14 @@ const RoleNameKey = "%d:sys:role_name:%d"
 func (s *roleService) GetRoleName(tenantId int, roleId int64) string {
 	var name string
 	key := fmt.Sprintf(RoleNameKey, tenantId, roleId)
-	name, err := util.Redis.Get(key).Result()
+	name, err := cache.Redis.Get(key).Result()
 	if err != nil {
 		role := &dao.Role{ID: roleId}
 		if err := role.GetRole(); err != nil {
 			fmt.Printf("GetRole err = %s \n", err)
 		} else {
 			name = role.RoleName
-			util.Redis.Set(key, name, -1)
+			cache.Redis.Set(key, name, -1)
 		}
 	}
 	return name

+ 13 - 12
app/system/service/tenantService.go

@@ -3,7 +3,8 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/system/dao"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -77,24 +78,24 @@ func (s *tenantService) List(tenantId int, tenantName, linkman string, current,
 	return tenants, nil
 }
 
-func (s *tenantService) Submit(req dao.Tenant) *util.Errors {
+func (s *tenantService) Submit(req dao.Tenant) *common.Errors {
 	tenant := &req
 	if tenant.ID == 0 {
-		tenant.PassKey = util.RandomString(8)
+		tenant.PassKey = common.RandomString(8)
 		if tenant.IsExist() {
-			tenant.PassKey = util.RandomString(8)
+			tenant.PassKey = common.RandomString(8)
 		}
 		err := tenant.Save()
 		if err != nil {
-			return util.FailResponse(err.Error(), nil)
+			return common.FailResponse(err.Error(), nil)
 		}
-		return util.SuccessResponse(util.Succeeded, nil)
+		return common.SuccessResponse(common.Succeeded, nil)
 	}
 	err := tenant.Update()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
-	return util.SuccessResponse(util.Succeeded, nil)
+	return common.SuccessResponse(common.Succeeded, nil)
 }
 
 func (s *tenantService) GetList() ([]dao.Tenant, error) {
@@ -106,7 +107,7 @@ func (s *tenantService) GetList() ([]dao.Tenant, error) {
 	return tenants, nil
 }
 
-func (s *tenantService) Remove(userId, id int64) *util.Errors {
+func (s *tenantService) Remove(userId, id int64) *common.Errors {
 	tenant := &dao.Tenant{
 		ID:         id,
 		IsDeleted:  1,
@@ -115,7 +116,7 @@ func (s *tenantService) Remove(userId, id int64) *util.Errors {
 	}
 	err := tenant.Remove()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }
@@ -125,14 +126,14 @@ const TenantNameKey = "%d:sys:tenant_name:%d"
 func (s *tenantService) GetTenantName(tenantId int, id int) string {
 	var name string
 	key := fmt.Sprintf(TenantNameKey, tenantId, id)
-	name, err := util.Redis.Get(key).Result()
+	name, err := cache.Redis.Get(key).Result()
 	if err != nil {
 		tenant := &dao.Tenant{TenantId: id}
 		if err := tenant.GetTenant(); err != nil {
 			fmt.Printf("GetTenant err = %s \n", err)
 		} else {
 			name = tenant.TenantName
-			util.Redis.Set(key, name, -1)
+			cache.Redis.Set(key, name, -1)
 		}
 	}
 	return name

+ 14 - 13
app/system/service/userService.go

@@ -6,7 +6,8 @@ import (
 	"io"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/common"
 	"time"
 )
 
@@ -60,7 +61,7 @@ func (s *userService) GetOne(tenantId int, account, password string) *dao.User {
 	return user
 }
 
-func (s *userService) List(account, realName string, current, size int) ([]model.UserDetail, *util.Errors) {
+func (s *userService) List(account, realName string, current, size int) ([]model.UserDetail, *common.Errors) {
 	user := dao.User{}
 	offset := (current - 1) * size
 	limit := size
@@ -73,7 +74,7 @@ func (s *userService) List(account, realName string, current, size int) ([]model
 
 	users, err := user.GetUsers(offset, limit)
 	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
+		return nil, common.FailResponse(err.Error(), nil)
 	}
 	var details []model.UserDetail
 	for _, user := range users {
@@ -87,25 +88,25 @@ func (s *userService) List(account, realName string, current, size int) ([]model
 	return details, nil
 }
 
-func (s *userService) Submit(req dao.User) *util.Errors {
+func (s *userService) Submit(req dao.User) *common.Errors {
 	user := &req
 	err := user.Save()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }
 
-func (s *userService) Update(req dao.User) *util.Errors {
+func (s *userService) Update(req dao.User) *common.Errors {
 	user := &req
 	err := user.Update()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }
 
-func (s *userService) Remove(userId, id int64) *util.Errors {
+func (s *userService) Remove(userId, id int64) *common.Errors {
 	user := &dao.User{
 		ID:         id,
 		IsDeleted:  1,
@@ -114,16 +115,16 @@ func (s *userService) Remove(userId, id int64) *util.Errors {
 	}
 	err := user.Remove()
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }
 
-func (s *userService) ResetPwd(id int64) *util.Errors {
+func (s *userService) ResetPwd(id int64) *common.Errors {
 	user := &dao.User{ID: id}
 	err := user.UpdatePwd(model.DefaultPwd)
 	if err != nil {
-		return util.FailResponse(err.Error(), nil)
+		return common.FailResponse(err.Error(), nil)
 	}
 	return nil
 }
@@ -147,14 +148,14 @@ const UserKey = "%d:sys:user:%d"
 func (s *userService) GetUserName(tenantId int, id int64) string {
 	var name string
 	key := fmt.Sprintf(UserKey, tenantId, id)
-	name, err := util.Redis.Get(key).Result()
+	name, err := cache.Redis.Get(key).Result()
 	if err != nil {
 		user := &dao.User{ID: id}
 		if err := user.GetUser(); err != nil {
 			fmt.Printf("GetUser err = %s \n", err)
 		} else {
 			name = user.Name
-			util.Redis.Set(key, name, time.Second*10)
+			cache.Redis.Set(key, name, time.Second*10)
 		}
 	}
 	return name

+ 3 - 3
config/config.go

@@ -61,7 +61,7 @@ type redis struct {
 }
 
 type logger struct {
-	Path   string
-	Level  string
-	Stdout bool
+	Path  string `yaml:"path"`
+	Name  string `yaml:"name"`
+	Level string `yaml:"level"`
 }

+ 2 - 2
config/config.yaml

@@ -6,9 +6,9 @@ server:
 
 # Logger configurations.
 logger:
-  path: "/log/gf-demos"
+  path: "./log"
   level: "info"
-  stdout: true
+  name: "info"
 
 # Database configurations.
 database:

+ 6 - 2
go.mod

@@ -3,6 +3,7 @@ module iot_manager_service
 go 1.17
 
 require (
+	github.com/druidcaesa/gotool v0.0.0-20220613023420-645c641d1304
 	github.com/gin-gonic/gin v1.8.1
 	github.com/go-redis/redis v6.15.9+incompatible
 	github.com/go-sql-driver/mysql v1.6.0
@@ -10,10 +11,12 @@ require (
 	github.com/jinzhu/gorm v1.9.16
 	github.com/mojocn/base64Captcha v1.3.5
 	github.com/satori/go.uuid v1.2.0
+	github.com/sirupsen/logrus v1.9.0
 	gopkg.in/yaml.v2 v2.4.0
 )
 
 require (
+	github.com/fogleman/gg v1.3.0 // indirect
 	github.com/gin-contrib/sse v0.1.0 // indirect
 	github.com/go-playground/locales v0.14.0 // indirect
 	github.com/go-playground/universal-translator v0.18.0 // indirect
@@ -21,6 +24,7 @@ require (
 	github.com/goccy/go-json v0.9.7 // indirect
 	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
 	github.com/google/go-cmp v0.5.8 // indirect
+	github.com/google/uuid v1.2.0 // indirect
 	github.com/jinzhu/inflection v1.0.0 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
 	github.com/leodido/go-urn v1.2.1 // indirect
@@ -32,9 +36,9 @@ require (
 	github.com/pelletier/go-toml/v2 v2.0.1 // indirect
 	github.com/ugorji/go/codec v1.2.7 // indirect
 	golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
-	golang.org/x/image v0.0.0-20190501045829-6d32002ffd75 // indirect
+	golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
 	golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
-	golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
+	golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
 	golang.org/x/text v0.3.7 // indirect
 	google.golang.org/protobuf v1.28.0 // indirect
 )

+ 13 - 2
go.sum

@@ -9,8 +9,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
 github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
+github.com/druidcaesa/gotool v0.0.0-20220613023420-645c641d1304 h1:YSmbj/dqe9cV3vQRLIVfXIW22qMA18oyG/C54B19TFM=
+github.com/druidcaesa/gotool v0.0.0-20220613023420-645c641d1304/go.mod h1:dYDc/fkM/uhP6dEdKhhLvpw3fgzZB7lexG1w+ZlVfyk=
 github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
 github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
+github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
+github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
 github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -57,6 +61,8 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
 github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
+github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
+github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
 github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o=
@@ -115,6 +121,8 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA
 github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
 github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
 github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
+github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
+github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
@@ -133,11 +141,13 @@ golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACk
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/image v0.0.0-20190501045829-6d32002ffd75 h1:TbGuee8sSq15Iguxu4deQ7+Bqq/d2rsQejGcEtADAMQ=
 golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
+golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
+golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
 golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -176,8 +186,9 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
 golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
+golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

+ 4 - 2
main.go

@@ -9,7 +9,8 @@ import (
 	"iot_manager_service/config"
 	_ "iot_manager_service/config"
 	"iot_manager_service/router"
-	"iot_manager_service/util"
+	"iot_manager_service/util/cache"
+	"iot_manager_service/util/logger"
 	"net/url"
 )
 
@@ -17,9 +18,10 @@ func main() {
 	// 开始调试模式
 	gin.SetMode("debug")
 
+	logger.InitLog()
 	// 实例化配置
 	initDB()
-	err := util.InitRedis()
+	err := cache.InitRedis()
 	if err != nil {
 		panic(err)
 	}

+ 4 - 2
router/router.go

@@ -7,15 +7,17 @@ import (
 	record "iot_manager_service/app/record/controller"
 	security "iot_manager_service/app/security/controller"
 	system "iot_manager_service/app/system/controller"
+	"iot_manager_service/util/logger"
 )
 
 func InitRouter(engine *gin.Engine) {
 	// 跨域处理
 	engine.Use(middleware.Cors())
-	// 登录验证中间件
-	engine.Use(middleware.CheckLogin())
 	// 校验权限
 	engine.Use(middleware.CheckAuth())
+	engine.Use(gin.Recovery())
+	engine.Use(logger.LogToFile())
+	engine.Use(logger.Recover)
 
 	// 操作历史记录
 	handleHistory := engine.Group("/api/longchi/handlehistory")

+ 3 - 2
util/redis.go

@@ -1,9 +1,10 @@
-package util
+package cache
 
 import (
 	"fmt"
 	"github.com/go-redis/redis"
 	"iot_manager_service/config"
+	"iot_manager_service/util/common"
 	"strconv"
 	"time"
 )
@@ -48,7 +49,7 @@ func GetDeviceState(id string) (retTime time.Time, retState string) {
 	//todo 需要统一
 	list, err := Redis.HMGet(DeviceStateKey+id, TLast, ONLINE).Result()
 	if err == nil && list[0] != nil || list[1] != nil {
-		t, err1 := MlParseTime(list[0].(string))
+		t, err1 := common.MlParseTime(list[0].(string))
 		s, err0 := strconv.Atoi(list[1].(string))
 		if err0 == nil && err1 == nil {
 			if s == 0 {

+ 5 - 1
util/common.go

@@ -1,4 +1,4 @@
-package util
+package common
 
 import (
 	"math/rand"
@@ -134,3 +134,7 @@ func MlParseTime(strTime string) (time.Time, error) {
 	}
 	return time.ParseInLocation("2006-01-02 15:04:05", strTime, mLocation)
 }
+
+func IsAdmin(roleId int64) bool {
+	return roleId == 1
+}

+ 1 - 1
util/errors.go

@@ -1,4 +1,4 @@
-package util
+package common
 
 type Errors struct {
 	Code    int         `json:"code"`

+ 54 - 0
util/logger/lclog.go

@@ -0,0 +1,54 @@
+package logger
+
+import (
+	"github.com/druidcaesa/gotool"
+	"github.com/sirupsen/logrus"
+	"iot_manager_service/config"
+	"os"
+	"path"
+	"time"
+)
+
+var Logger *logrus.Logger
+
+func InitLog() {
+	logFilePath := config.Instance().Logger.Path
+	logFileName := config.Instance().Logger.Name
+
+	err := os.MkdirAll(logFilePath, os.ModeDir)
+	if err != nil {
+		gotool.Logs.ErrorLog().Println(err)
+		panic(err)
+	}
+
+	// 日志文件
+	fileName := path.Join(logFilePath, logFileName) + time.Now().Format("20060102") + ".log"
+	if !gotool.FileUtils.Exists(fileName) {
+		create, err := os.Create(fileName)
+		if err != nil {
+			gotool.Logs.ErrorLog().Println(err)
+			panic(err)
+		}
+		defer create.Close()
+	}
+	// 写入文件
+	src, err := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
+	if err != nil {
+		panic(err)
+	}
+
+	// 实例化
+	logger := logrus.New()
+
+	// 设置输出
+	logger.Out = src
+
+	// 设置日志级别
+	logger.SetLevel(logrus.DebugLevel)
+
+	logger.Formatter = &logrus.JSONFormatter{
+		TimestampFormat: "2006-01-02 15:04:05.000",
+	}
+
+	Logger = logger
+}

+ 90 - 0
util/logger/logger.go

@@ -0,0 +1,90 @@
+package logger
+
+import (
+	"bytes"
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"io/ioutil"
+	"net/http"
+	"time"
+)
+
+// LoggerToFile 日志记录到文件
+func LogToFile() gin.HandlerFunc {
+	return func(ctx *gin.Context) {
+		// 初始化bodyLogWriter
+		blw := &bodyLogWriter{
+			body:           bytes.NewBufferString(""),
+			ResponseWriter: ctx.Writer,
+		}
+		ctx.Writer = blw
+
+		// 开始时间
+		startTime := time.Now()
+		// 请求方式
+		reqMethod := ctx.Request.Method
+		// 请求路由
+		reqUri := ctx.Request.RequestURI
+		//请求参数
+		request := getRequestBody(ctx)
+		// 请求IP
+		clientIP := ctx.ClientIP()
+
+		// 处理请求
+		ctx.Next()
+
+		// 结束时间
+		endTime := time.Now()
+		// 执行时间
+		latencyTime := endTime.Sub(startTime)
+		// 状态码
+		statusCode := ctx.Writer.Status()
+		// 响应
+		response := blw.body.String()
+
+		//日志格式
+		Logger.WithFields(logrus.Fields{
+			"status_code":  statusCode,
+			"latency_time": latencyTime,
+			"client_ip":    clientIP,
+			"req_method":   reqMethod,
+			"request":      request,
+			"response":     response,
+			"req_uri":      reqUri,
+		}).Info()
+	}
+}
+
+func getRequestBody(ctx *gin.Context) interface{} {
+	switch ctx.Request.Method {
+	case http.MethodGet:
+		fallthrough
+	case http.MethodDelete:
+		return ctx.Request.URL.Query()
+	case http.MethodPost:
+		fallthrough
+	case http.MethodPut:
+		fallthrough
+	case http.MethodPatch:
+		var bodyBytes []byte
+		bodyBytes, err := ioutil.ReadAll(ctx.Request.Body)
+		if err != nil {
+			return nil
+		}
+		ctx.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
+		return string(bodyBytes)
+	}
+	return nil
+}
+
+// bodyLogWriter 定义一个存储响应内容的结构体
+type bodyLogWriter struct {
+	gin.ResponseWriter
+	body *bytes.Buffer
+}
+
+// Write 读取响应数据
+func (w bodyLogWriter) Write(b []byte) (int, error) {
+	w.body.Write(b)
+	return w.ResponseWriter.Write(b)
+}

+ 39 - 0
util/logger/recover.go

@@ -0,0 +1,39 @@
+package logger
+
+import (
+	"github.com/gin-gonic/gin"
+	"net/http"
+	"runtime/debug"
+)
+
+func Recover(c *gin.Context) {
+	defer func() {
+		if r := recover(); r != nil {
+			//打印错误堆栈信息
+			Logger.Errorf("panic: %v\n", r)
+			debug.PrintStack()
+			//封装通用json返回
+			//c.JSON(http.StatusOK, Result.Fail(errorToString(r)))
+			//Result.Fail不是本例的重点,因此用下面代码代替
+			c.JSON(http.StatusOK, gin.H{
+				"code": 500,
+				"msg":  errorToString(r),
+				"data": nil,
+			})
+			//终止后续接口调用,不加的话recover到异常后,还会继续执行接口里后续代码
+			c.Abort()
+		}
+	}()
+	//加载完 defer recover,继续后续接口调用
+	c.Next()
+}
+
+// recover错误,转string
+func errorToString(r interface{}) string {
+	switch v := r.(type) {
+	case error:
+		return v.Error()
+	default:
+		return r.(string)
+	}
+}