terry il y a 3 ans
Parent
commit
9c5593df6e
77 fichiers modifiés avec 825 ajouts et 543 suppressions
  1. 3 3
      app/device/controller/GatewayController.go
  2. 1 1
      app/device/controller/LightStrategy.go
  3. 1 1
      app/device/controller/alarmController.go
  4. 1 1
      app/device/controller/alarmTerminalController.go
  5. 1 1
      app/device/controller/bridgeController.go
  6. 1 1
      app/device/controller/bridgeSensorController.go
  7. 1 1
      app/device/controller/cameraController.go
  8. 2 2
      app/device/controller/captureUintController.go
  9. 1 1
      app/device/controller/garbageController.go
  10. 2 2
      app/device/controller/garbageWayGroupController.go
  11. 2 2
      app/device/controller/handleHistoryController.go
  12. 1 1
      app/device/controller/infoBoardController.go
  13. 1 1
      app/device/controller/ipBroadcastController.go
  14. 1 1
      app/device/controller/lampPoleController.go
  15. 3 3
      app/device/controller/lampPoleGroupController.go
  16. 1 1
      app/device/controller/lightController.go
  17. 1 1
      app/device/controller/manholeCoverController.go
  18. 1 1
      app/device/controller/onDemandGroupController.go
  19. 1 1
      app/device/controller/onDemandSensorController.go
  20. 1 1
      app/device/controller/optoSensorController.go
  21. 1 1
      app/device/controller/switchBoxController.go
  22. 1 1
      app/device/controller/transformerController.go
  23. 1 1
      app/device/controller/zigbeeController.go
  24. 20 6
      app/device/dao/alarmTerminalDao.go
  25. 14 0
      app/device/dao/cameraDao.go
  26. 19 5
      app/device/dao/captureUnitDao.go
  27. 1 1
      app/device/dao/common.go
  28. 11 4
      app/device/dao/gatewayDao.go
  29. 20 6
      app/device/dao/infoBoardDao.go
  30. 25 11
      app/device/dao/ipBroadcastDao.go
  31. 22 8
      app/device/dao/lightControlDao.go
  32. 5 5
      app/device/dao/manholeCoverDao.go
  33. 0 42
      app/device/dao/operationHisDao.go
  34. 20 6
      app/device/dao/optoSensoDao.go
  35. 24 10
      app/device/dao/zigbeeDao.go
  36. 5 5
      app/device/model/camera.go
  37. 1 1
      app/device/model/captureUint.go
  38. 0 59
      app/device/model/common.go
  39. 14 14
      app/device/model/gateway.go
  40. 17 17
      app/device/model/lampPole.go
  41. 5 5
      app/device/model/lampPoleGroup.go
  42. 4 19
      app/device/model/lightControl.go
  43. 10 11
      app/device/service/LightStrategyService.go
  44. 8 7
      app/device/service/alarmService.go
  45. 24 7
      app/device/service/alarmTerminalService.go
  46. 10 6
      app/device/service/bridgeSensorService.go
  47. 8 7
      app/device/service/bridgeService.go
  48. 26 6
      app/device/service/cameraService.go
  49. 39 19
      app/device/service/captureUintService.go
  50. 8 7
      app/device/service/garbageService.go
  51. 11 10
      app/device/service/garbageWayGroupService.go
  52. 32 18
      app/device/service/gatewayService.go
  53. 25 7
      app/device/service/infoBoardService.go
  54. 3 3
      app/device/service/intelligentLightingService.go
  55. 26 8
      app/device/service/ipBroadcastService.go
  56. 9 24
      app/device/service/lampPoleGroupService.go
  57. 18 18
      app/device/service/lampPoleService.go
  58. 0 5
      app/device/service/lightConditionService.go
  59. 45 44
      app/device/service/lightControlService.go
  60. 9 7
      app/device/service/manholeCoverService.go
  61. 8 4
      app/device/service/onDemandGroupService.go
  62. 8 6
      app/device/service/onDemandSensorService.go
  63. 25 7
      app/device/service/optoSensoService.go
  64. 24 9
      app/device/service/switchBoxService.go
  65. 8 6
      app/device/service/transformerService.go
  66. 26 9
      app/device/service/zigbeeService.go
  67. 5 1
      app/system/controller/tenant.go
  68. 10 12
      app/system/controller/token.go
  69. 5 1
      app/system/controller/user.go
  70. 44 0
      app/system/dao/operationHisDao.go
  71. 4 2
      app/device/model/OperationHis.go
  72. 14 13
      app/device/service/operationHisService.go
  73. 2 2
      app/system/service/tenantService.go
  74. 2 2
      app/system/service/userService.go
  75. 1 1
      build.bat
  76. 70 0
      util/common.go
  77. 1 0
      util/redis.go

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

@@ -81,7 +81,7 @@ func (c *gatewayCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GatewayService.Remove(claims.UserId, req.IDs)
+	err := service.GatewayService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return
@@ -130,8 +130,8 @@ func gatewayDaoToModel(device dao.Gateway) model.GatewayDetail {
 		Gateway:           device,
 		CountLampPole:     0,
 		EndLineTime:       "",
-		NetworkState:      "",
-		RunState:          "",
+		NetworkState:      2,
+		RunState:          2,
 		Cpu:               "",
 		Memory:            "",
 		AlarmTerminalList: nil,

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

@@ -86,7 +86,7 @@ func (c *lightStrategyCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LightStrategyService.Remove(claims.UserId, req.IDs)
+	err := service.LightStrategyService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *alarmCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.AlarmService.Remove(claims.UserId, req.IDs)
+	err := service.AlarmService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *alarmTerminalCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.AlarmTerminalService.Remove(claims.UserId, req.IDs)
+	err := service.AlarmTerminalService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *bridgeCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.BridgeService.Remove(claims.UserId, req.IDs)
+	err := service.BridgeService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *bridgeSensorCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.BridgeSensorService.Remove(claims.UserId, req.IDs)
+	err := service.BridgeSensorService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -87,7 +87,7 @@ func (c *cameraCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.CameraService.Remove(claims.UserId, req.IDs)
+	err := service.CameraService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -169,14 +169,14 @@ func (c *captureUintCtl) Remove(ctx *gin.Context) {
 		return
 	}
 	if req.Type == model.TypeCapture {
-		err := service.CaptureUintService.RemoveCapture(claims.UserId, req.IDs)
+		err := service.CaptureUintService.RemoveCapture(claims.UserId, claims.TenantId, req.IDs)
 		if err != nil {
 			ctx.JSON(http.StatusOK, err)
 			return
 		}
 		ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
 	} else if req.Type == model.TypePoint {
-		err := service.CaptureUintService.RemovePoint(claims.UserId, req.IDs)
+		err := service.CaptureUintService.RemovePoint(claims.UserId, claims.TenantId, req.IDs)
 		if err != nil {
 			ctx.JSON(http.StatusOK, err)
 			return

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

@@ -83,7 +83,7 @@ func (c *garbageCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GarbageService.Remove(claims.UserId, req.IDs)
+	err := service.GarbageService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -33,7 +33,7 @@ func (c *garbageWayCtl) Detail(ctx *gin.Context) {
 }
 
 func (c *garbageWayCtl) List(ctx *gin.Context) {
-	searchValue := ctx.Query("searchValue")
+	searchValue := ctx.Query("wayName")
 	current, _ := strconv.Atoi(ctx.Query("current"))
 	size, _ := strconv.Atoi(ctx.Query("size"))
 	if current == 0 {
@@ -83,7 +83,7 @@ func (c *garbageWayCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.GarbageWayGroupService.Remove(claims.UserId, req.IDs)
+	err := service.GarbageWayGroupService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -2,8 +2,8 @@ package controller
 
 import (
 	"github.com/gin-gonic/gin"
-	"iot_manager_service/app/device/service"
 	"iot_manager_service/app/middleware"
+	service2 "iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"net/http"
 	"strconv"
@@ -29,7 +29,7 @@ func (c *handleHistoryCtl) List(ctx *gin.Context) {
 	if size <= 0 || size > 100 {
 		size = 10
 	}
-	list, err := service.OperationHisService.List(claims.TenantId, handleContent, operationType, moduleType, current,
+	list, err := service2.OperationHisService.List(claims.TenantId, handleContent, operationType, moduleType, current,
 		size)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)

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

@@ -83,7 +83,7 @@ func (c *infoBoardCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.InfoBoardService.Remove(claims.UserId, req.IDs)
+	err := service.InfoBoardService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *ipBroadcastCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.IpBroadcastService.Remove(claims.UserId, req.IDs)
+	err := service.IpBroadcastService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -100,7 +100,7 @@ func (c *lampPoleCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LampPoleService.Remove(claims.UserId, req.IDs)
+	err := service.LampPoleService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -142,8 +142,8 @@ func lampPoleGroupDaoToModel(device dao.LampPoleGroup) model.LampPoleGroupDetail
 		LampPoleGroup:  device,
 		PublicName:     "",
 		LampPoleVOList: []model.LampPoleDetail{},
-		CameraList:     []model.Camera{},
-		SwitchBoxList:  []model.SwitchBox{},
-		InfoBoardList:  []model.InfoBoard{},
+		CameraList:     []dao.CameraDevice{},
+		SwitchBoxList:  []dao.SwitchBox{},
+		InfoBoardList:  []dao.InfoBoard{},
 	}
 }

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

@@ -85,7 +85,7 @@ func (c *lightCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.LightControlService.Remove(claims.UserId, req.IDs)
+	err := service.LightControlService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *manholeCoverCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.ManholeCoverService.Remove(claims.UserId, req.IDs)
+	err := service.ManholeCoverService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -81,7 +81,7 @@ func (c *onDemandGroupCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OnDemandGroupService.Remove(claims.UserId, req.IDs)
+	err := service.OnDemandGroupService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *onDemandSensorCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OnDemandSensorService.Remove(claims.UserId, req.IDs)
+	err := service.OnDemandSensorService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *optoSensorCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.OptoSensorService.Remove(claims.UserId, req.IDs)
+	err := service.OptoSensorService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *switchBoxCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.SwitchBoxService.Remove(claims.UserId, req.IDs)
+	err := service.SwitchBoxService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *transformerCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.TransformerService.Remove(claims.UserId, req.IDs)
+	err := service.TransformerService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

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

@@ -83,7 +83,7 @@ func (c *zigbeeCtl) Remove(ctx *gin.Context) {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.ZigbeeService.Remove(claims.UserId, req.IDs)
+	err := service.ZigbeeService.Remove(claims.UserId, claims.TenantId, req.IDs)
 	if err != nil {
 		ctx.JSON(http.StatusOK, err)
 		return

+ 20 - 6
app/device/dao/alarmTerminalDao.go

@@ -10,17 +10,17 @@ type AlarmTerminal struct {
 	ID               int       `gorm:"primary_key" json:"id"`                     //编号
 	TerminalName     string    `gorm:"varchar(64)" json:"terminalName"`           //设备名称
 	TerminalSN       string    `gorm:"type:varchar(60)" json:"terminalSn"`        //设备序编码
-	BrandID          int       `gorm:"type:int" json:"brandId"`                   //设备品牌ID
-	ModelID          int       `gorm:"type:int" json:"modelId"`                   //设备型号ID
-	GatewayID        int       `gorm:"type:int" json:"gatewayId"`                 //所属网关
-	LampPoleID       int       `gorm:"type:int" json:"lampPoleId"`                //所属灯杆 灯杆ID
+	BrandId          int       `gorm:"type:int" json:"brandId"`                   //设备品牌ID
+	ModelId          int       `gorm:"type:int" json:"modelId"`                   //设备型号ID
+	GatewayId        int       `gorm:"type:int" json:"gatewayId"`                 //所属网关
+	LampPoleId       int       `gorm:"type:int" json:"lampPoleId"`                //所属灯杆 灯杆ID
 	LampPoleName     string    `gorm:"type:varchar(64)" json:"lampPoleName"`      //灯杆名称
-	LampPoleSN       string    `gorm:"type:varchar(64)" json:"lampPoleSn"`        //灯杆编码
+	LampPoleSn       string    `gorm:"type:varchar(64)" json:"lampPoleSn"`        //灯杆编码
 	LampPoleLocation string    `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
 	PoleLng          float64   `gorm:"type:double(17, 14) " json:"poleLng"`       //经度
 	PoleLat          float64   `gorm:"type:double(17, 14)  " json:"poleLat"`      //纬度
 	Numeration       int       `gorm:"type:int" json:"numeration"`                //编号
-	ServeID          int       `gorm:"type:int" json:"serveID"`                   //所属服务ID
+	ServeId          int       `gorm:"type:int" json:"serveID"`                   //所属服务ID
 	IPAddress        string    `gorm:"type:varchar(50)" json:"ipAddress"`         //IP地址
 	InstallTime      time.Time `gorm:"type:date" json:"installTime"`              //安装时间
 	TenantId         int       `gorm:"type:int" json:"tenantId"`                  //租户id
@@ -89,3 +89,17 @@ func (c AlarmTerminal) GetAllDevices() ([]*AlarmTerminal, error) {
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c AlarmTerminal) GetDevicesByGateway() []AlarmTerminal {
+	var devices []AlarmTerminal
+	Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
+		c.GatewayId).Find(&devices)
+	return devices
+}
+
+func (c AlarmTerminal) GetDevicesByLampPole() []AlarmTerminal {
+	var devices []AlarmTerminal
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

+ 14 - 0
app/device/dao/cameraDao.go

@@ -88,3 +88,17 @@ func (c CameraDevice) GetAllDevices() ([]*CameraDevice, error) {
 func (c *CameraDevice) UpdateEnable() error {
 	return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Updates(map[string]interface{}{"is_enable": c.IsEnable}).Error
 }
+
+func (c CameraDevice) GetDevicesByGateway() []CameraDevice {
+	var devices []CameraDevice
+	Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
+		c.GatewayId).Find(&devices)
+	return devices
+}
+
+func (c CameraDevice) GetDevicesByLampPole() []CameraDevice {
+	var devices []CameraDevice
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

+ 19 - 5
app/device/dao/captureUnitDao.go

@@ -8,7 +8,7 @@ import (
 type CaptureUnit struct {
 	ID                     int       `gorm:"primary_key" json:"id"`                                //编号
 	CaptureName            string    `gorm:"type:varchar(64)" json:"captureName"`                  //设备名称
-	CaptureSN              string    `gorm:"type:varchar(60)" json:"captureSn"`                    //设备序列号
+	CaptureSn              string    `gorm:"type:varchar(60)" json:"captureSn"`                    //设备序列号
 	PointId                int       `gorm:"type:int" json:"pointId"`                              //卡口ID
 	LampPoleId             int       `gorm:"type:int" json:"lampPoleId"`                           //灯杆ID
 	WayName                string    `gorm:"type:varchar(64)" json:"wayName"`                      //道路名称
@@ -28,7 +28,7 @@ type CaptureUnit struct {
 	CapturePort            int       `gorm:"type:int" json:"capturePort"`                          //端口
 	GatewayId              int       `gorm:"type:int" json:"gatewayId"`                            //网关ID
 	GatewayName            string    `gorm:"type:varchar(80)" json:"gatewayName"`                  //网关名称
-	GatewaySN              string    `gorm:"type:varchar(30)" json:"gatewaySn"`                    //网关编码
+	GatewaySn              string    `gorm:"type:varchar(30)" json:"gatewaySn"`                    //网关编码
 	TenantId               int       `gorm:"type:int" json:"tenantId"`                             //租户ID
 	CreateTime             time.Time `gorm:"type:datetime" json:"createTime"`                      //新增时间
 	CreateUser             int64     `gorm:"type:bigint" json:"createUser"`                        //新增记录操作用户ID
@@ -44,7 +44,7 @@ func (CaptureUnit) TableName() string {
 func (c CaptureUnit) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where("capture_sn = ? and is_deleted = ?",
-		c.CaptureSN, c.IsDeleted).Count(&count).Error
+		c.CaptureSn, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
@@ -64,8 +64,8 @@ func (c *CaptureUnit) GetDevice() error {
 func (c CaptureUnit) GetDevices(offset, limit int) ([]CaptureUnit, error) {
 	var Captures []CaptureUnit
 	db := Db.Debug().Model(&c)
-	if c.CaptureSN != "" {
-		db = db.Where("capture_name like ? or capture_sn like ?", "%"+c.CaptureSN+"%", "%"+c.CaptureSN+"%")
+	if c.CaptureSn != "" {
+		db = db.Where("capture_name like ? or capture_sn like ?", "%"+c.CaptureSn+"%", "%"+c.CaptureSn+"%")
 	}
 
 	err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&Captures).Error
@@ -82,3 +82,17 @@ func (c CaptureUnit) GetAllDevices() ([]*CaptureUnit, error) {
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&Captures).Error
 	return Captures, err
 }
+
+func (c CaptureUnit) GetDevicesByGateway() []CaptureUnit {
+	var devices []CaptureUnit
+	Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
+		c.GatewayId).Find(&devices)
+	return devices
+}
+
+func (c CaptureUnit) GetDevicesByLampPole() []CaptureUnit {
+	var devices []CaptureUnit
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

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

@@ -41,7 +41,7 @@ func InitDB(db *gorm.DB) {
 		&LightStrategy{},
 		&LightCondition{},
 		&DeviceVendor{},
-		&OperationHis{},
+		&dao.OperationHistory{},
 	).Error
 	if err != nil {
 		panic(fmt.Sprintf("AutoMigrate err : %v", err))

+ 11 - 4
app/device/dao/gatewayDao.go

@@ -9,7 +9,7 @@ import (
 type Gateway struct {
 	ID                 int       `gorm:"primary_key" json:"id"`                           //编号
 	GatewayName        string    `gorm:"type:varchar(64)"  json:"gatewayName"`            //设备名称
-	GatewaySN          string    `gorm:"type:varchar(60)" json:"gatewaySn"`               //设备序列号
+	GatewaySn          string    `gorm:"type:varchar(60)" json:"gatewaySn"`               //设备序列号
 	LampPoleId         int       `gorm:"type:int" json:"lampPoleId"`                      //所属灯杆
 	LampPoleSn         string    `gorm:"type:varchar(64)" json:"lampPoleSn"`              //所属灯杆SN
 	LampPoleName       string    `gorm:"type:varchar(64)" json:"lampPoleName"`            //灯杆名称
@@ -47,7 +47,7 @@ func (c *Gateway) Delete() error {
 func (c Gateway) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where(" gateway_sn = ? and is_deleted = ?",
-		c.GatewaySN, c.IsDeleted).Count(&count).Error
+		c.GatewaySn, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
@@ -82,8 +82,8 @@ func (c *Gateway) GetDevice() error {
 func (c Gateway) GetDevices(offset, limit int) ([]Gateway, error) {
 	var devices []Gateway
 	db := Db.Debug().Model(&c)
-	if c.GatewaySN != "" {
-		db = db.Where("gateway_name like ? or gateway_sn like ?", "%"+c.GatewaySN+"%", "%"+c.GatewaySN+"%")
+	if c.GatewaySn != "" {
+		db = db.Where("gateway_name like ? or gateway_sn like ?", "%"+c.GatewaySn+"%", "%"+c.GatewaySn+"%")
 	}
 
 	err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&devices).Error
@@ -95,3 +95,10 @@ func (c Gateway) GetAllDevices() ([]*Gateway, error) {
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c Gateway) GetDevicesByLampPole() []Gateway {
+	var devices []Gateway
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

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

@@ -9,18 +9,18 @@ import (
 type InfoBoard struct {
 	ID               int       `gorm:"primary_key" json:"id"`                            //编号
 	InfoName         string    `gorm:"type:varchar(60)" json:"infoName"`                 //名称
-	SN               string    `gorm:"type:varchar(60)" json:"sn"`                       //设备序列号
+	Sn               string    `gorm:"type:varchar(60)" json:"sn"`                       //设备序列号
 	LampPoleId       int       `gorm:"type:int" json:"LampPoleId"`                       //所属灯杆id
 	LampPoleName     string    `gorm:"type:varchar(64)" json:"lampPoleName"`             //灯杆名称
-	LampPoleSN       string    `gorm:"type:varchar(64)" json:"lampPoleSn"`               //灯杆编码
+	LampPoleSn       string    `gorm:"type:varchar(64)" json:"lampPoleSn"`               //灯杆编码
 	LampPoleLocation string    `gorm:"type:varchar(255)" json:"lampPoleLocation"`        //灯杆安装位置
 	PoleLng          float64   `gorm:"type:double(17, 14) " json:"poleLng"`              //经度
 	PoleLat          float64   `gorm:"type:double(17, 14)  " json:"poleLat"`             //纬度
 	GatewayId        int       `gorm:"type:int" json:"gatewayId"`                        //所属网关id
 	GroupId          int       `gorm:"type:int" json:"groupId"`                          //所属灯杆分组
 	Resolution       int       `gorm:"type:int" json:"resolution"`                       //分辨率
-	BrandID          int       `gorm:"type:int" json:"brandId"`                          //设备名
-	ModelID          int       `gorm:"type:int" json:"modelId"`                          //设备型号
+	BrandId          int       `gorm:"type:int" json:"brandId"`                          //设备名
+	ModelId          int       `gorm:"type:int" json:"modelId"`                          //设备型号
 	InfoSize         int       `gorm:"type:int" json:"infoSize"`                         //信息屏尺寸
 	RatedPower       float32   `gorm:"type:float(8, 2); default 0.00" json:"ratedPower"` //额定功率(LED灯)
 	IPAddress        string    `gorm:"type:varchar(64)" json:"ipAddress"`                //IP地址
@@ -51,14 +51,14 @@ func (c InfoBoard) Delete() error {
 func (c InfoBoard) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where("  sn = ? and is_deleted = ?",
-		c.SN, c.IsDeleted).Count(&count).Error
+		c.Sn, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
 func (c InfoBoard) IsExistedByNameAndCode() bool {
 	var devices []InfoBoard
 	err := Db.Debug().Model(&c).Where(" sn = ? and is_deleted = ?",
-		c.SN, c.IsDeleted).Find(&devices).Error
+		c.Sn, c.IsDeleted).Find(&devices).Error
 	//如果查询不到,返回相应的错误
 	if gorm.IsRecordNotFoundError(err) {
 		return false
@@ -95,3 +95,17 @@ func (c InfoBoard) GetAllDevices() ([]*InfoBoard, error) {
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c InfoBoard) GetDevicesByGateway() []InfoBoard {
+	var devices []InfoBoard
+	Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
+		c.GatewayId).Find(&devices)
+	return devices
+}
+
+func (c InfoBoard) GetDevicesByLampPole() []InfoBoard {
+	var devices []InfoBoard
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

+ 25 - 11
app/device/dao/ipBroadcastDao.go

@@ -8,17 +8,17 @@ import (
 type IpBroadcast struct {
 	ID               int        `gorm:"primary_key" json:"id"`                            //编号
 	CastName         string     `gorm:"type:varchar(64)" json:"castName"`                 //设备名称
-	CastSN           string     `gorm:"type:varchar(60)" json:"castSn"`                   //设备序列号
+	CastSn           string     `gorm:"type:varchar(60)" json:"castSn"`                   //设备序列号
 	LampPoleId       int        `gorm:"type:int" json:"LampPoleId"`                       //所属灯杆id
-	LampPoleSN       string     `gorm:"type:varchar(64)" json:"lampPoleSn"`               //所属灯杆sn
+	LampPoleSn       string     `gorm:"type:varchar(64)" json:"lampPoleSn"`               //所属灯杆sn
 	GroupId          int        `gorm:"type:int" json:"groupId"`                          //灯杆分组ID
-	GatewayID        int        `gorm:"type:int" json:"gatewayId"`                        //所属网关id
-	GatewaySN        string     `gorm:"type:varchar(64)" json:"gatewaySn"`                //所属网关sn
-	BrandID          int        `gorm:"type:int" json:"brandId"`                          //设备名称
-	ModelID          int        `gorm:"type:int" json:"modelId"`                          //设备型号
+	GatewayId        int        `gorm:"type:int" json:"gatewayId"`                        //所属网关id
+	GatewaySn        string     `gorm:"type:varchar(64)" json:"gatewaySn"`                //所属网关sn
+	BrandId          int        `gorm:"type:int" json:"brandId"`                          //设备名称
+	ModelId          int        `gorm:"type:int" json:"modelId"`                          //设备型号
 	RatedPower       float32    `gorm:"type:float(8, 2); default 0.00" json:"ratedPower"` //额定功率(LED灯)
 	IPAddress        string     `gorm:"type:varchar(50)" json:"ipAddress"`                //IP地址
-	ServiceIPAddress string     `gorm:"type:varchar(50)" json:"serviceIpAddress"`         //IP地址         //服务IP地址
+	ServiceIpAddress string     `gorm:"type:varchar(50)" json:"serviceIpAddress"`         //服务IP地址
 	ServerPort       int        `gorm:"type:int" json:"serverPort"`                       //服务端口
 	SoundVolume      int        `gorm:"type:int" json:"soundVolume"`                      //音量0-100换算
 	InstallTime      *time.Time `gorm:"type:date" json:"installTime"`                     //安装时间
@@ -42,14 +42,14 @@ func (c IpBroadcast) Delete() error {
 func (c IpBroadcast) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where("  cast_sn = ? and is_deleted = ?",
-		c.CastSN, c.IsDeleted).Count(&count).Error
+		c.CastSn, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
 func (c IpBroadcast) IsExistedByNameAndCode() bool {
 	var devices []IpBroadcast
 	err := Db.Debug().Model(&c).Where(" cast_sn = ? and is_deleted = ?",
-		c.CastSN, c.IsDeleted).Find(&devices).Error
+		c.CastSn, c.IsDeleted).Find(&devices).Error
 	//如果查询不到,返回相应的错误
 	if gorm.IsRecordNotFoundError(err) {
 		return false
@@ -81,9 +81,23 @@ func (c IpBroadcast) GetDevices(offset, limit int) ([]IpBroadcast, error) {
 	return devices, err
 }
 
-func (c IpBroadcast) GetAllDevices() ([]*IpBroadcast, error) {
-	var devices []*IpBroadcast
+func (c IpBroadcast) GetAllDevices() ([]IpBroadcast, error) {
+	var devices []IpBroadcast
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId,
 		c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c IpBroadcast) GetDevicesByGateway() []IpBroadcast {
+	var devices []IpBroadcast
+	Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
+		c.GatewayId).Find(&devices)
+	return devices
+}
+
+func (c IpBroadcast) GetDevicesByLampPole() []IpBroadcast {
+	var devices []IpBroadcast
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

+ 22 - 8
app/device/dao/lightControlDao.go

@@ -9,13 +9,13 @@ import (
 type LightControl struct {
 	ID               int       `gorm:"primary_key" json:"id"`                     //编号
 	Name             string    `gorm:"type:varchar(64)"  json:"name"`             //名称
-	SN               string    `gorm:"type:varchar(60)" json:"sn"`                //设备序列号
+	Sn               string    `gorm:"type:varchar(60)" json:"sn"`                //设备序列号
 	ControlType      int       `gorm:"type:int" json:"controlType"`               //控制器类型 type:0=485灯控,1=NB-iot箱
 	GroupId          int       `gorm:"type:int" json:"groupId"`                   //所属灯杆分组
 	GatewayId        int       `gorm:"type:varchar(32)" json:"gatewayId"`         //所属网关id
 	LampPoleId       int       `gorm:"type:int" json:"lampPoleId"`                //所属灯杆 灯杆ID
 	LampPoleName     string    `gorm:"type:varchar(64)" json:"lampPoleName"`      //灯杆名称
-	LampPoleSN       string    `gorm:"type:varchar(64)" json:"lampPoleSn"`        //灯杆SN
+	LampPoleSn       string    `gorm:"type:varchar(64)" json:"lampPoleSn"`        //灯杆SN
 	LampPoleLocation string    `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
 	LampLat          float64   `gorm:"type:double(17,14)" json:"lampLat"`         //纬度
 	LampLng          float64   `gorm:"type:double(17,14)" json:"lampLng"`         //经度
@@ -31,7 +31,7 @@ type LightControl struct {
 	IsDeleted        int       `gorm:"type:int;default 0" json:"isDeleted"`       //是否删除 0=未删除,1=删除
 	Status           int       `gorm:"type:int" json:"status"`                    //状态 0=正常,1=异常
 	Tag              string    `gorm:"type:varchar(255)" json:"tag"`              //标签,(备用,逗号区分)
-	ControlNO        string    `gorm:"type:varchar(10)" json:"controlNo"`         //编号
+	ControlNo        string    `gorm:"type:varchar(10)" json:"controlNo"`         //编号
 	ChannelNum       int       `gorm:"type:int" json:"channelNum"`                //通道号
 	NetworkNum       int       `gorm:"type:int" json:"networkNum"`                //网络号
 	ZigbeeId         int       `gorm:"type:int" json:"zigbeeId"`                  //zigbeeID
@@ -53,7 +53,7 @@ func (c *LightControl) Delete() error {
 func (c LightControl) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where("sn = ? and is_deleted = ?",
-		c.SN, c.IsDeleted).Count(&count).Error
+		c.Sn, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
@@ -99,8 +99,8 @@ func (c LightControl) GetDevices(offset, limit int) ([]LightControl, error) {
 	var devices []LightControl
 
 	db := Db.Debug().Model(&c)
-	if c.SN != "" {
-		db = db.Where("name like ? or sn like ?", "%"+c.SN+"%", "%"+c.SN+"%")
+	if c.Sn != "" {
+		db = db.Where("name like ? or sn like ?", "%"+c.Sn+"%", "%"+c.Sn+"%")
 	}
 	if c.ControlType != 0 {
 		db = db.Where("control_type = ?", c.ControlType)
@@ -113,8 +113,22 @@ func (c LightControl) GetDevices(offset, limit int) ([]LightControl, error) {
 	return devices, err
 }
 
-func (c LightControl) GetAllDevices() ([]*LightControl, error) {
-	var devices []*LightControl
+func (c LightControl) GetAllDevices() ([]LightControl, error) {
+	var devices []LightControl
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c LightControl) GetDevicesByGateway() []LightControl {
+	var devices []LightControl
+	Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
+		c.GatewayId).Find(&devices)
+	return devices
+}
+
+func (c LightControl) GetDevicesByLampPole() []LightControl {
+	var devices []LightControl
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

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

@@ -9,10 +9,10 @@ import (
 type ManholeCover struct {
 	ID                  int        `gorm:"primary_key" json:"id"`                    //编号
 	ManholeName         string     `gorm:"type:varchar(64)" json:"manholeName"`      //设备名称
-	ManholeSN           string     `gorm:"type:varchar(60)" json:"manholeSn"`        //设备序列号
+	ManholeSn           string     `gorm:"type:varchar(60)" json:"manholeSn"`        //设备序列号
 	DeviceIMei          string     `gorm:"type:varchar(64)" json:"deviceIMei"`       //IMEI-唯一不允许重复
-	BrandID             int        `gorm:"type:int" json:"brandID"`                  //设备名称
-	ModelID             int        `gorm:"type:int" json:"modelID"`                  //设备型号
+	BrandId             int        `gorm:"type:int" json:"brandID"`                  //设备名称
+	ModelId             int        `gorm:"type:int" json:"modelID"`                  //设备型号
 	KindType            int        `gorm:"type:int" json:"transPhotoUrl"`            //种类
 	Radius              int        `gorm:"type:int" json:"radius"`                   //半径
 	MaterialQuality     int        `gorm:"type:int" json:"materialQuality"`          //材质
@@ -52,14 +52,14 @@ func (c ManholeCover) Delete() error {
 func (c ManholeCover) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where("  manhole_sn = ? and is_deleted = ?",
-		c.ManholeSN, c.IsDeleted).Count(&count).Error
+		c.ManholeSn, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
 func (c ManholeCover) IsExistedByNameAndCode() bool {
 	var devices []ManholeCover
 	err := Db.Debug().Model(&c).Where(" manhole_sn = ? and is_deleted = ?",
-		c.ManholeSN, c.IsDeleted).Find(&devices).Error
+		c.ManholeSn, c.IsDeleted).Find(&devices).Error
 	//如果查询不到,返回相应的错误
 	if gorm.IsRecordNotFoundError(err) {
 		return false

+ 0 - 42
app/device/dao/operationHisDao.go

@@ -1,42 +0,0 @@
-package dao
-
-import (
-	"time"
-)
-
-// OperationHis 操作记录
-type OperationHis struct {
-	ID            int       `gorm:"primary_key" json:"id"`                                      //编号
-	OperationType int       `gorm:"type:int" json:"operationType"`                              //操作类型
-	ModuleType    int       `gorm:"type:int" json:"moduleType"`                                 //操作模块
-	HandleContent string    `gorm:"type:varchar(1000)" json:"handleContent"`                    //操作内容
-	HandleUserId  int64     `gorm:"type:bigint" json:"handleUserId"`                            //操作用户ID
-	HandleTime    time.Time `gorm:"type:timestamp;default CURRENT_TIMESTAMP" json:"handleTime"` //操作时间
-	TenantId      int       `gorm:"type:int" json:"tenantId"`                                   //租户ID
-}
-
-func (OperationHis) TableName() string {
-	return "t_sys_handle_his"
-}
-
-func (c *OperationHis) Create() error {
-	return Db.Debug().Model(&c).Save(&c).Error
-}
-
-func (c OperationHis) GetHistories(offset, limit int) ([]OperationHis, error) {
-	var list []OperationHis
-	db := Db.Debug().Model(&c)
-	if c.OperationType > 0 {
-		db = db.Where("operation_type = ?", c.OperationType)
-	}
-	if c.ModuleType > 0 {
-		db = db.Where("module_type = ?", c.ModuleType)
-	}
-	if c.HandleContent != "" {
-		db = db.Where("handle_content like ?", "%"+c.HandleContent+"%")
-	}
-
-	err := Db.Debug().Model(&c).Offset(offset).Limit(limit).Find(&list).Error
-
-	return list, err
-}

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

@@ -9,15 +9,15 @@ import (
 type OptoSensor struct {
 	ID               int        `gorm:"primary_key" json:"id"`                     //编号
 	Name             string     `gorm:"type:varchar(64)" json:"name"`              //名称
-	SN               string     `gorm:"type:varchar(60)" json:"sn"`                //唯一编码
+	Sn               string     `gorm:"type:varchar(60)" json:"sn"`                //唯一编码
 	LampPoleId       int        `gorm:"type:int" json:"lampPoleId"`                //灯杆id
 	LampPoleName     string     `gorm:"type:varchar(64)" json:"lampPoleName"`      //灯杆名称
-	LampPoleSN       string     `gorm:"type:varchar(64)" json:"lampPoleSn"`        //灯杆编码
+	LampPoleSn       string     `gorm:"type:varchar(64)" json:"lampPoleSn"`        //灯杆编码
 	LampPoleLocation string     `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
 	LampLng          float64    `gorm:"type:double(17, 14) " json:"poleLng"`       //经度
 	LampLat          float64    `gorm:"type:double(17, 14)  " json:"poleLat"`      //纬度
-	BrandID          int        `gorm:"type:int" json:"brandId"`                   //设备名称
-	ModelID          int        `gorm:"type:int" json:"modelId"`                   //设备型号
+	BrandId          int        `gorm:"type:int" json:"brandId"`                   //设备名称
+	ModelId          int        `gorm:"type:int" json:"modelId"`                   //设备型号
 	GatewayId        int        `gorm:"type:int" json:"gatewayId"`                 //所属网关id
 	InstallTime      *time.Time `gorm:"type:date" json:"installTime"`              //安装时间
 	IPAddress        string     `gorm:"type:varchar(64)" json:"ipAddress"`         //IP地址-备用
@@ -44,14 +44,14 @@ func (c OptoSensor) Delete() error {
 func (c OptoSensor) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where("  sn = ? and is_deleted = ?",
-		c.SN, c.IsDeleted).Count(&count).Error
+		c.Sn, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
 func (c OptoSensor) IsExistedByNameAndCode() bool {
 	var devices []Zigbee
 	err := Db.Debug().Model(&c).Where(" sn = ? and is_deleted = ?",
-		c.SN, c.IsDeleted).Find(&devices).Error
+		c.Sn, c.IsDeleted).Find(&devices).Error
 	//如果查询不到,返回相应的错误
 	if gorm.IsRecordNotFoundError(err) {
 		return false
@@ -88,3 +88,17 @@ func (c OptoSensor) GetAllDevices() ([]*OptoSensor, error) {
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c OptoSensor) GetDevicesByGateway() []OptoSensor {
+	var devices []OptoSensor
+	Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
+		c.GatewayId).Find(&devices)
+	return devices
+}
+
+func (c OptoSensor) GetDevicesByLampPole() []OptoSensor {
+	var devices []OptoSensor
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

+ 24 - 10
app/device/dao/zigbeeDao.go

@@ -9,20 +9,20 @@ import (
 type Zigbee struct {
 	ID               int        `gorm:"primary_key" json:"id"`                     //编号
 	Name             string     `gorm:"type:varchar(64)" json:"name"`              //名称
-	SN               string     `gorm:"type:varchar(60)" json:"sn"`                //唯一编码
+	Sn               string     `gorm:"type:varchar(60)" json:"sn"`                //唯一编码
 	GroupId          int        `gorm:"type:int" json:"groupId"`                   //所属灯杆分组id
 	LampPoleId       int        `gorm:"type:int" json:"lampPoleId"`                //所属灯杆id
 	LampPoleName     string     `gorm:"type: varchar(64)" json:"lampPoleName"`     //灯杆名称
-	LampPoleSN       string     `gorm:"type: varchar(64)" json:"lampPoleSn"`       //灯杆编码
+	LampPoleSn       string     `gorm:"type: varchar(64)" json:"lampPoleSn"`       //灯杆编码
 	LampPoleLocation string     `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
 	PoleLng          float64    `gorm:"type:double(17, 14)" json:"poleLng"`        //经度
 	PoleLat          float64    `gorm:"type:double(17, 14)" json:"poleLat"`        //纬度
-	BrandID          int        `gorm:"type:int" json:"brandId"`                   //设备名称
-	ModelID          int        `gorm:"type:int" json:"modelId"`                   //设备型号
+	BrandId          int        `gorm:"type:int" json:"brandId"`                   //设备名称
+	ModelId          int        `gorm:"type:int" json:"modelId"`                   //设备型号
 	GatewayId        int        `gorm:"type:int" json:"gatewayId"`                 //所属网关id
 	GatewayName      string     `gorm:"type:varchar(64)" json:"gatewayName"`       //所属网关名称
-	GatewaySN        string     `gorm:"type:varchar(60)" json:"gatewaySn"`         //所属网关编码
-	ChanelNum        int        `gorm:"type:int" json:"channelNum"`                //通道号
+	GatewaySn        string     `gorm:"type:varchar(60)" json:"gatewaySn"`         //所属网关编码
+	ChannelNum       int        `gorm:"type:int" json:"channelNum"`                //通道号
 	NetworkNum       int        `gorm:"type:int" json:"networkNum"`                //网络号
 	InstallTime      *time.Time `gorm:"type:date" json:"installTime"`              //安装时间
 	TenantId         int        `gorm:"type:int" json:"tenantId"`                  //租户id
@@ -48,14 +48,14 @@ func (c Zigbee) Delete() error {
 func (c Zigbee) IsExistedBySN() bool {
 	var count = 0
 	_ = Db.Debug().Model(&c).Where("  sn = ? and is_deleted = ?",
-		c.SN, c.IsDeleted).Count(&count).Error
+		c.Sn, c.IsDeleted).Count(&count).Error
 	return count > 0
 }
 
 func (c Zigbee) IsExistedByNameAndCode() bool {
 	var devices []Zigbee
 	err := Db.Debug().Model(&c).Where(" sn = ? and is_deleted = ?",
-		c.SN, c.IsDeleted).Find(&devices).Error
+		c.Sn, c.IsDeleted).Find(&devices).Error
 	//如果查询不到,返回相应的错误
 	if gorm.IsRecordNotFoundError(err) {
 		return false
@@ -87,8 +87,22 @@ func (c Zigbee) GetDevices(offset, limit int) ([]Zigbee, error) {
 	return devices, err
 }
 
-func (c Zigbee) GetAllDevices() ([]*Zigbee, error) {
-	var devices []*Zigbee
+func (c Zigbee) GetAllDevices() ([]Zigbee, error) {
+	var devices []Zigbee
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c Zigbee) GetDevicesByGateway() []Zigbee {
+	var devices []Zigbee
+	Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
+		c.GatewayId).Find(&devices)
+	return devices
+}
+
+func (c Zigbee) GetDevicesByLampPole() []Zigbee {
+	var devices []Zigbee
+	Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
+		c.LampPoleId).Find(&devices)
+	return devices
+}

+ 5 - 5
app/device/model/camera.go

@@ -4,11 +4,11 @@ import "iot_manager_service/app/device/dao"
 
 type CameraDetail struct {
 	dao.CameraDevice
-	PoleGroupName   string `json:"poleGroupName"`   //品牌名称
-	Brand           string `json:"brand"`           //型号名称
-	Model           string `json:"model"`           //摄像头类型名称
-	CameraTypeName  string `json:"cameraTypeName"`  //运行状态
-	RunState        string `json:"runState"`        //网络状态
+	PoleGroupName   string `json:"poleGroupName"`   //灯杆分组名
+	Brand           string `json:"brand"`           //品牌名称
+	Model           string `json:"model"`           //型名称
+	CameraTypeName  string `json:"cameraTypeName"`  //摄像头类型名称
+	RunState        int    `json:"runState"`        //运行状态
 	NetworkState    string `json:"networkState"`    //网络状态
 	EndLineTime     string `json:"endLineTime"`     //最后在线时间
 	QueryGatewayIds string `json:"queryGatewayIds"` //虚拟字段---用作网关调用这里关联

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

@@ -12,7 +12,7 @@ type CaptureDetail struct {
 	PointName       string  `json:"pointName"`       //卡口名称
 	PointSn         string  `json:"pointSn"`         //卡口编码
 	PointLocation   string  `json:"pointLocation"`   //卡口位置
-	NetworkState    string  `json:"networkState"`    //通讯状态 1在线2离线
+	NetworkState    int     `json:"networkState"`    //通讯状态 1在线2离线
 	EndLineTime     string  `json:"endLineTime"`     //最后在线时间
 }
 

+ 0 - 59
app/device/model/common.go

@@ -50,62 +50,3 @@ const (
 	TransformerList     = "%d:TransformerList:GetList"
 	GatewayList         = "%d:GatewayList:GetList"
 )
-
-//Operation type 操作类型
-const (
-	OperationDefault          = iota
-	OperationLogin            //登录
-	OperationLogout           //注销
-	OperationCreate           //新增
-	OperationUpdate           //修改
-	OperationRemove           //删除
-	OperationImport           //导入导出
-	OperationLightStrategy    //开关灯控策略
-	OperationOrderCreate      //工单发起
-	OperationOrderChange      //工单转派
-	OperationOrderHandle      //工单处理
-	OperationProgramPublish   //节目发布待审核
-	OperationProgramResult    //节目处理结果
-	OperationStrategyRelation //策略关联
-	OperationControl          //操作
-	OperationAlarmHandle      //告警处理
-	OperationOrderFinish      //工单签收(接单)
-)
-
-const (
-	ModuleTypeDefault        = iota //操作记录模块
-	ModuleTypeDevice                //设备台账管理
-	ModuleTypeInfoBar               //信息发布系统
-	ModuleTypeOrder                 //工单运维
-	ModuleTypeNotification          //通知公告
-	ModuleTypeLightStrategy         //照明策略
-	ModuleTypeLighting              //智慧照明系统-智能照明
-	ModuleTypeSystem                //系统管理
-	ModuleTypeAlarm                 //告警管理
-	ModuleTypeOperation             //运营分析
-	ModuleTypeRecord                //记录处理
-	ModuleTypeWisdomLighting        //智能感应照明系统-灯随车走照明控制
-)
-
-type AlarmTerminal struct {
-}
-type CaptureUnit struct {
-}
-type Gateway struct {
-}
-type IpBroadcast struct {
-}
-type LightControl struct {
-}
-type Sensor struct {
-}
-type Zigbee struct {
-}
-type OptoSensor struct {
-}
-type Camera struct {
-}
-type SwitchBox struct {
-}
-type InfoBoard struct {
-}

+ 14 - 14
app/device/model/gateway.go

@@ -6,20 +6,20 @@ import (
 
 type GatewayDetail struct {
 	dao.Gateway
-	CountLampPole     int             `json:"countLampPole"`         //关联设备数 //todo 修改返回名
-	EndLineTime       string          `json:"endLineTime"`           //最后上线时间
-	NetworkState      string          `json:"networkState"`          //网络状态
-	RunState          string          `json:"runState"`              //运行状态
-	Cpu               string          `json:"cpu"`                   //CPU占有率
-	Memory            string          `json:"memory"`                //内存占有率
-	AlarmTerminalList []AlarmTerminal `json:"akeyAlarmTerminalList"` //一键告警集合
-	CameraList        []Camera        `json:"cameraList"`            //摄像头集合
-	CaptureUnitList   []CaptureUnit   `json:"captureUnitList"`       //抓拍单元集合
-	InfoBoardList     []InfoBoard     `json:"infoBoardList"`         //信息屏集合
-	IpBroadcastList   []IpBroadcast   `json:"ipBroadcastList"`       //IP音柱集合
-	LightControlList  []LightControl  `json:"lightControlList"`      //灯控集合
-	ZigbeeList        []Zigbee        `json:"zigbeeList"`            //ZigBee集合
-	OptoSensorList    []OptoSensor    `json:"optoSensorList"`        //气象站集合
+	CountLampPole     int                 `json:"countLampPole"`         //关联设备数 //todo 修改返回名
+	EndLineTime       string              `json:"endLineTime"`           //最后上线时间
+	NetworkState      int                 `json:"networkState"`          //网络状态
+	RunState          int                 `json:"runState"`              //运行状态
+	Cpu               string              `json:"cpu"`                   //CPU占有率
+	Memory            string              `json:"memory"`                //内存占有率
+	AlarmTerminalList []dao.AlarmTerminal `json:"akeyAlarmTerminalList"` //一键告警集合
+	CameraList        []dao.CameraDevice  `json:"cameraList"`            //摄像头集合
+	CaptureUnitList   []dao.CaptureUnit   `json:"captureUnitList"`       //抓拍单元集合
+	InfoBoardList     []dao.InfoBoard     `json:"infoBoardList"`         //信息屏集合
+	IpBroadcastList   []dao.IpBroadcast   `json:"ipBroadcastList"`       //IP音柱集合
+	LightControlList  []dao.LightControl  `json:"lightControlList"`      //灯控集合
+	ZigbeeList        []dao.Zigbee        `json:"zigbeeList"`            //ZigBee集合
+	OptoSensorList    []dao.OptoSensor    `json:"optoSensorList"`        //气象站集合
 }
 
 type RspGatewayList struct {

+ 17 - 17
app/device/model/lampPole.go

@@ -6,23 +6,23 @@ import (
 
 type LampPoleDetail struct {
 	dao.LampPole
-	IsCrossName       string          `json:"isCrossName"`           //是否路口名称
-	TagName           string          `json:"tagName"`               //标签(中文)
-	ProvincesName     string          `json:"provincesName"`         //省市区组合地址
-	GatewaySn         string          `json:"gatewaySn"`             //网关编码
-	BoxSn             string          `json:"boxSn"`                 //配电箱编码
-	RunState          string          `json:"runState"`              //运行状态
-	PoleGroupName     string          `json:"poleGroupName"`         //灯杆分组名称
-	BoxName           string          `json:"boxName"`               //配电箱名称
-	AlarmTerminalList []AlarmTerminal `json:"akeyAlarmTerminalList"` //一键告警集合
-	CameraList        []Camera        `json:"cameraList"`            //摄像头集合
-	CaptureUnitList   []CaptureUnit   `json:"captureUnitList"`       //抓拍单元集合
-	GatewayList       []Gateway       `json:"gatewayList"`           //网关集合
-	InfoBoardList     []InfoBoard     `json:"infoBoardList"`         //信息屏集合
-	IpBroadcastList   []IpBroadcast   `json:"ipBroadcastList"`       //IP音柱集合
-	LightControlList  []LightControl  `json:"lightControlList"`      //灯控集合
-	SensorList        []Sensor        `json:"sensorList"`            //环境监测集合
-	ZigbeeList        []Zigbee        `json:"zigbeeList"`            //ZigBee集合
+	IsCrossName       string              `json:"isCrossName"`           //是否路口名称
+	TagName           string              `json:"tagName"`               //标签(中文)
+	ProvincesName     string              `json:"provincesName"`         //省市区组合地址
+	GatewaySn         string              `json:"gatewaySn"`             //网关编码
+	BoxSn             string              `json:"boxSn"`                 //配电箱编码
+	RunState          string              `json:"runState"`              //运行状态
+	PoleGroupName     string              `json:"poleGroupName"`         //灯杆分组名称
+	BoxName           string              `json:"boxName"`               //配电箱名称
+	AlarmTerminalList []dao.AlarmTerminal `json:"akeyAlarmTerminalList"` //一键告警集合
+	CameraList        []dao.CameraDevice  `json:"cameraList"`            //摄像头集合
+	CaptureUnitList   []dao.CaptureUnit   `json:"captureUnitList"`       //抓拍单元集合
+	GatewayList       []dao.Gateway       `json:"gatewayList"`           //网关集合
+	InfoBoardList     []dao.InfoBoard     `json:"infoBoardList"`         //信息屏集合
+	IpBroadcastList   []dao.IpBroadcast   `json:"ipBroadcastList"`       //IP音柱集合
+	LightControlList  []dao.LightControl  `json:"lightControlList"`      //灯控集合
+	SensorList        []dao.OptoSensor    `json:"sensorList"`            //环境监测集合
+	ZigbeeList        []dao.Zigbee        `json:"zigbeeList"`            //ZigBee集合
 }
 
 type RspLampPoleList struct {

+ 5 - 5
app/device/model/lampPoleGroup.go

@@ -6,11 +6,11 @@ import (
 
 type LampPoleGroupDetail struct {
 	dao.LampPoleGroup
-	PublicName     string           `json:"publicName"`     // 用于虚拟字段组成的树
-	LampPoleVOList []LampPoleDetail `json:"lampPoleVOList"` //分组下的所有灯杆集合
-	CameraList     []Camera         `json:"cameraList"`     //智能安防中调用摄像头直播列表
-	SwitchBoxList  []SwitchBox      `json:"switchBoxList"`  //智能安防中调用配电箱直播列表
-	InfoBoardList  []InfoBoard      `json:"infoBoardList"`  //节目组下查询分组下的信息屏集合
+	PublicName     string             `json:"publicName"`     // 用于虚拟字段组成的树
+	LampPoleVOList []LampPoleDetail   `json:"lampPoleVOList"` //分组下的所有灯杆集合
+	CameraList     []dao.CameraDevice `json:"cameraList"`     //智能安防中调用摄像头直播列表
+	SwitchBoxList  []dao.SwitchBox    `json:"switchBoxList"`  //智能安防中调用配电箱直播列表
+	InfoBoardList  []dao.InfoBoard    `json:"infoBoardList"`  //节目组下查询分组下的信息屏集合
 }
 
 type RspLampPoleGroupList struct {

+ 4 - 19
app/device/model/lightControl.go

@@ -6,23 +6,9 @@ import (
 
 type LightControlDetail struct {
 	dao.LightControl
-	IsCrossName       string          `json:"isCrossName"`           //是否路口名称
-	TagName           string          `json:"tagName"`               //标签(中文)
-	ProvincesName     string          `json:"provincesName"`         //省市区组合地址
-	GatewaySn         string          `json:"gatewaySn"`             //网关编码
-	BoxSn             string          `json:"boxSn"`                 //配电箱编码
-	RunState          string          `json:"runState"`              //运行状态
-	PoleGroupName     string          `json:"poleGroupName"`         //灯杆分组名称
-	BoxName           string          `json:"boxName"`               //配电箱名称
-	AlarmTerminalList []AlarmTerminal `json:"akeyAlarmTerminalList"` //一键告警集合
-	CameraList        []Camera        `json:"cameraList"`            //摄像头集合
-	CaptureUnitList   []CaptureUnit   `json:"captureUnitList"`       //抓拍单元集合
-	GatewayList       []Gateway       `json:"gatewayList"`           //网关集合
-	InfoBoardList     []InfoBoard     `json:"infoBoardList"`         //信息屏集合
-	IpBroadcastList   []IpBroadcast   `json:"ipBroadcastList"`       //IP音柱集合
-	LightControlList  []LightControl  `json:"lightControlList"`      //灯控集合
-	SensorList        []Sensor        `json:"sensorList"`            //环境监测集合
-	ZigbeeList        []Zigbee        `json:"zigbeeList"`            //ZigBee集合
+	EndLineTime  string `json:"endLineTime"`  //最后上线时间
+	NetworkState int    `json:"networkState"` //网络状态
+	RunState     int    `json:"runState"`     //运行状态
 }
 
 type RspLightControlList struct {
@@ -34,8 +20,7 @@ type RspLightControlList struct {
 }
 
 type ReqLightControlRemove struct {
-	IDs int `json:"ids"` //分组编码
-
+	IDs  int    `json:"ids"`  //分组编码
 	Name string `json:"name"` //名称
 }
 

+ 10 - 11
app/device/service/LightStrategyService.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"sort"
 	"time"
@@ -89,11 +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) {
-			//todo 光照度请填写完整
-			return nil
+			return util.ParamsInvalidResponse("光照度请填写完整", nil)
 		} else if lightCondition.ScopeEnd > 0 && lightCondition.ScopeStart >= lightCondition.ScopeEnd {
-			//todo 光照度起始值不能大于结束值
-			return nil
+			return util.ParamsInvalidResponse("光照度起始值不能大于结束值", nil)
 		}
 		overlapList = append(overlapList, lightCondition)
 
@@ -116,8 +115,7 @@ func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *m
 		tmp := -1
 		for _, overLap := range overlapList {
 			if tmp >= overLap.ScopeStart {
-				//todo 区间有重叠
-				return nil
+				return util.ParamsInvalidResponse("光照条件区间有重叠", nil)
 			}
 			tmp = overLap.ScopeEnd
 		}
@@ -171,14 +169,15 @@ func (s *lightStrategyService) CreateOrUpdate(userId int64, tenantId int, req *m
 
 	//存策略条件
 	_ = TimeConditionService.Save(timeList)
-	//_ = LightConditionService.Save(strategy.LightConditionList)
+	_ = LightConditionService.Save(strategy.LightConditionList)
 
 	//todo 调用设备云端的新增或修改
 
 	//todo 自动续期
 	//strategy.IsAutomaticRenewal
 
-	//todo operation record
+	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)
 }
 
@@ -223,7 +222,7 @@ func (s *lightStrategyService) List(searchValue string, current, size int) ([]mo
 	return details, nil
 }
 
-func (s *lightStrategyService) Remove(userId int64, id int) *util.Errors {
+func (s *lightStrategyService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	strategy := &dao.LightStrategy{
 		ID:         id,
@@ -231,12 +230,12 @@ func (s *lightStrategyService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-
-	//todo operation record
 	err := strategy.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeLightStrategy, util.GetDeviceObject(strategy.ID, strategy.LightName), util.OperationSuccess)
 	return nil
 }
 

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

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -43,6 +44,8 @@ func (s *alarmService) CreateOrUpdate(userId int64, tenantId int, req dao.Alarm)
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 
@@ -56,7 +59,8 @@ func (s *alarmService) CreateOrUpdate(userId int64, tenantId int, req dao.Alarm)
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -72,7 +76,7 @@ func (s *alarmService) List(poleGroupName string, current, size int) ([]dao.Alar
 	return devices, nil
 }
 
-func (s *alarmService) Remove(userId int64, id int) *util.Errors {
+func (s *alarmService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Alarm{
 		ID:         id,
@@ -80,15 +84,12 @@ func (s *alarmService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-
-	//todo
-	// service.lampPoleService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeAlarmServer, util.GetDeviceObject(device.ID, device.ServeName), util.OperationSuccess)
 	return nil
 }
 

+ 24 - 7
app/device/service/alarmTerminalService.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -43,6 +44,8 @@ func (s *alarmTerminalService) CreateOrUpdate(userId int64, tenantId int, req da
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 
@@ -56,7 +59,8 @@ func (s *alarmTerminalService) CreateOrUpdate(userId int64, tenantId int, req da
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -72,7 +76,7 @@ func (s *alarmTerminalService) List(poleGroupName string, current, size int) ([]
 	return devices, nil
 }
 
-func (s *alarmTerminalService) Remove(userId int64, id int) *util.Errors {
+func (s *alarmTerminalService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.AlarmTerminal{
 		ID:         id,
@@ -80,14 +84,27 @@ func (s *alarmTerminalService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-
-	//todo
-	// service.lampPoleService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeAlarmTerminal, util.GetDeviceObject(device.ID, device.TerminalName), util.OperationSuccess)
 	return nil
 }
+
+func (s *alarmTerminalService) GetByGateway(id int) []dao.AlarmTerminal {
+	// 创建查询实例
+	device := &dao.AlarmTerminal{
+		GatewayId: id,
+	}
+	return device.GetDevicesByGateway()
+}
+
+func (s *alarmTerminalService) GetByLampPole(id int) []dao.AlarmTerminal {
+	// 创建查询实例
+	device := &dao.AlarmTerminal{
+		LampPoleId: id,
+	}
+	return device.GetDevicesByLampPole()
+}

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

@@ -3,6 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -41,6 +42,8 @@ func (s *bridgeSensorService) CreateOrUpdate(userId int64, tenantId int, req dao
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -52,9 +55,11 @@ func (s *bridgeSensorService) CreateOrUpdate(userId int64, tenantId int, req dao
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
+
 func (s *bridgeSensorService) List(searchValue string, current, size int) ([]dao.BridgeSensor, *util.Errors) {
 	device := dao.BridgeSensor{}
 	if searchValue != "" {
@@ -70,7 +75,8 @@ func (s *bridgeSensorService) List(searchValue string, current, size int) ([]dao
 	}
 	return devices, nil
 }
-func (s *bridgeSensorService) Remove(userId int64, id int) *util.Errors {
+
+func (s *bridgeSensorService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.BridgeSensor{
 		ID:         id,
@@ -78,14 +84,12 @@ func (s *bridgeSensorService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeBridgeSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
 	return nil
 }
 

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

@@ -3,6 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -21,7 +22,6 @@ func (s *bridgeService) Get(id int) (*dao.Bridge, *util.Errors) {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
 	return device, nil
-
 }
 
 func (s *bridgeService) CreateOrUpdate(userId int64, tenantId int, req dao.Bridge) *util.Errors {
@@ -41,6 +41,8 @@ func (s *bridgeService) CreateOrUpdate(userId int64, tenantId int, req dao.Bridg
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 
@@ -53,7 +55,8 @@ func (s *bridgeService) CreateOrUpdate(userId int64, tenantId int, req dao.Bridg
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -73,7 +76,7 @@ func (s *bridgeService) List(searchValue string, current, size int) ([]dao.Bridg
 	return devices, nil
 }
 
-func (s *bridgeService) Remove(userId int64, id int) *util.Errors {
+func (s *bridgeService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Bridge{
 		ID:         id,
@@ -81,14 +84,12 @@ func (s *bridgeService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeBridge, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
 	return nil
 }
 

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

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"strconv"
 	"time"
@@ -46,6 +47,8 @@ func (s *cameraService) CreateOrUpdate(userId int64, tenantId int, req *model.Ca
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 
@@ -54,7 +57,8 @@ func (s *cameraService) CreateOrUpdate(userId int64, tenantId int, req *model.Ca
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -75,8 +79,7 @@ func (s *cameraService) Get(id int) (*model.CameraDetail, *util.Errors) {
 		detail.CameraTypeName = model.CameraTypeGunName
 	}
 
-	//todo 获取运行状态
-	// runState = 	forVidiconService.queryRtStatus();
+	detail.RunState = util.GetDeviceState(device.DeviceSN)
 	return detail, nil
 }
 
@@ -105,14 +108,14 @@ func (s *cameraService) List(searchValue, cameraType string, current, size int)
 	for _, d := range devices {
 		details = append(details, model.CameraDetail{
 			CameraDevice: d,
-			RunState:     "", // todo queryRtStatus
+			RunState:     util.GetDeviceState(device.DeviceSN),
 		})
 	}
 
 	return details, nil
 }
 
-func (s *cameraService) Remove(userId int64, id int) *util.Errors {
+func (s *cameraService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.CameraDevice{
 		ID:         id,
@@ -121,11 +124,12 @@ func (s *cameraService) Remove(userId int64, id int) *util.Errors {
 		UpdateTime: time.Now(),
 	}
 
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeCamera, util.GetDeviceObject(device.ID, device.DeviceName), util.OperationSuccess)
 	return nil
 }
 
@@ -160,3 +164,19 @@ func (s *cameraService) Enable(id, status int) *util.Errors {
 	}
 	return nil
 }
+
+func (s *cameraService) GetByGateway(id int) []dao.CameraDevice {
+	// 创建查询实例
+	device := &dao.CameraDevice{
+		GatewayId: id,
+	}
+	return device.GetDevicesByGateway()
+}
+
+func (s *cameraService) GetByLampPole(id int) []dao.CameraDevice {
+	// 创建查询实例
+	device := &dao.CameraDevice{
+		LampPoleId: id,
+	}
+	return device.GetDevicesByLampPole()
+}

+ 39 - 19
app/device/service/captureUintService.go

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

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

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -42,6 +43,8 @@ func (s *garbageService) CreateOrUpdate(userId int64, tenantId int, req dao.Garb
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -52,8 +55,8 @@ func (s *garbageService) CreateOrUpdate(userId int64, tenantId int, req dao.Garb
 		fmt.Printf("Update err = %s \n", err.Error())
 		return util.FailResponse(err.Error(), nil)
 	}
-
-	//todo operation record
+	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)
 }
 
@@ -73,7 +76,7 @@ func (s *garbageService) List(searchValue string, current, size int) ([]dao.Garb
 	return devices, nil
 }
 
-func (s *garbageService) Remove(userId int64, id int) *util.Errors {
+func (s *garbageService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Garbage{
 		ID:         id,
@@ -81,14 +84,12 @@ func (s *garbageService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.garbageWayService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeGarbage, util.GetDeviceObject(device.ID, device.DeviceName), util.OperationSuccess)
 	return nil
 }
 

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

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -42,6 +43,8 @@ func (s *garbageWayGroupService) CreateOrUpdate(userId int64, tenantId int, req
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -53,16 +56,16 @@ func (s *garbageWayGroupService) CreateOrUpdate(userId int64, tenantId int, req
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
 func (s *garbageWayGroupService) List(searchValue string, current, size int) ([]dao.GarbageWayGroup, *util.Errors) {
 	device := dao.GarbageWayGroup{}
-	//if searchValue != "" {
-	//	device.TransSN = searchValue
-	//	device.TransName = searchValue
-	//}
+	if searchValue != "" {
+		device.GroupName = searchValue
+	}
 
 	offset := (current - 1) * size
 	limit := size
@@ -73,7 +76,7 @@ func (s *garbageWayGroupService) List(searchValue string, current, size int) ([]
 	return devices, nil
 }
 
-func (s *garbageWayGroupService) Remove(userId int64, id int) *util.Errors {
+func (s *garbageWayGroupService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.GarbageWayGroup{
 		ID:         id,
@@ -81,14 +84,12 @@ func (s *garbageWayGroupService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeGarbageGroup, util.GetDeviceObject(device.ID, device.GroupName), util.OperationSuccess)
 	return nil
 }
 

+ 32 - 18
app/device/service/gatewayService.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -31,10 +32,11 @@ func (s *gatewayService) Get(id int) (*model.GatewayDetail, *util.Errors) {
 	} else {
 		fmt.Printf("GatewayRelationService.Get err = %v", err)
 	}
-	//todo 获取网关状态
-	//			vo.setEndLineTime(time);
-	//			vo.setNetworkState(online);
-	//			vo.setRunState(online);
+
+	detail.EndLineTime = ""
+	state := util.GetDeviceState(device.GatewaySn)
+	detail.RunState = state
+	detail.NetworkState = state
 	return detail, nil
 }
 
@@ -69,6 +71,8 @@ func (s *gatewayService) CreateOrUpdate(userId int64, tenantId int, req *model.G
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 
@@ -77,7 +81,8 @@ func (s *gatewayService) CreateOrUpdate(userId int64, tenantId int, req *model.G
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -86,7 +91,7 @@ func (s *gatewayService) List(searchValue string, current, size int) ([]model.Ga
 	device := dao.Gateway{}
 
 	if searchValue != "" {
-		device.GatewaySN = searchValue
+		device.GatewaySn = searchValue
 	}
 
 	offset := (current - 1) * size
@@ -106,7 +111,7 @@ func (s *gatewayService) List(searchValue string, current, size int) ([]model.Ga
 	return details, nil
 }
 
-func (s *gatewayService) Remove(userId int64, id int) *util.Errors {
+func (s *gatewayService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Gateway{
 		ID:         id,
@@ -119,11 +124,12 @@ func (s *gatewayService) Remove(userId int64, id int) *util.Errors {
 		return util.OperationInvalidResponse(model.GatewayHasRelation, nil)
 	}
 
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeGateway, util.GetDeviceObject(device.ID, device.GatewayName), util.OperationSuccess)
 	return nil
 }
 
@@ -140,7 +146,7 @@ func (s *gatewayService) GetList(tenantId int) ([]*dao.Gateway, *util.Errors) {
 	}
 	devices, err = device.GetAllDevices()
 	for _, device := range devices {
-		device.GatewayName = device.GatewayName + "(" + device.GatewaySN + ")"
+		device.GatewayName = device.GatewayName + "(" + device.GatewaySn + ")"
 	}
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
@@ -163,17 +169,17 @@ func (s *gatewayService) GetRelevanceDetail(id int) (*model.GatewayDetail, *util
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	//todo get gateway ipBroadcast lightcontroller... list
+
 	return &model.GatewayDetail{
 		Gateway:           *device,
-		AlarmTerminalList: nil,
-		CameraList:        nil,
-		CaptureUnitList:   nil,
-		InfoBoardList:     nil,
-		IpBroadcastList:   nil,
-		LightControlList:  nil,
-		OptoSensorList:    nil,
-		ZigbeeList:        nil,
+		AlarmTerminalList: AlarmTerminalService.GetByGateway(device.ID),
+		CameraList:        CameraService.GetByGateway(device.ID),
+		CaptureUnitList:   CaptureUintService.GetCaptureByGateway(device.ID),
+		InfoBoardList:     InfoBoardService.GetByGateway(device.ID),
+		IpBroadcastList:   IpBroadcastService.GetByGateway(device.ID),
+		LightControlList:  LightControlService.GetByGateway(device.ID),
+		OptoSensorList:    OptoSensorService.GetByGateway(device.ID),
+		ZigbeeList:        ZigbeeService.GetByGateway(device.ID),
 	}, nil
 }
 
@@ -188,3 +194,11 @@ func (s *gatewayService) GetOne(id int) (*dao.Gateway, *util.Errors) {
 	}
 	return device, nil
 }
+
+func (s *gatewayService) GetByLampPole(id int) []dao.Gateway {
+	// 创建查询实例
+	device := &dao.Gateway{
+		LampPoleId: id,
+	}
+	return device.GetDevicesByLampPole()
+}

+ 25 - 7
app/device/service/infoBoardService.go

@@ -3,6 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -41,6 +42,8 @@ func (s *infoBoardService) CreateOrUpdate(userId int64, tenantId int, req dao.In
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -52,14 +55,15 @@ func (s *infoBoardService) CreateOrUpdate(userId int64, tenantId int, req dao.In
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
 func (s *infoBoardService) List(searchValue string, current, size int) ([]dao.InfoBoard, *util.Errors) {
 	device := dao.InfoBoard{}
 	if searchValue != "" {
-		device.SN = searchValue
+		device.Sn = searchValue
 		device.InfoName = searchValue
 	}
 
@@ -72,7 +76,7 @@ func (s *infoBoardService) List(searchValue string, current, size int) ([]dao.In
 	return devices, nil
 }
 
-func (s *infoBoardService) Remove(userId int64, id int) *util.Errors {
+func (s *infoBoardService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.InfoBoard{
 		ID:         id,
@@ -80,13 +84,27 @@ func (s *infoBoardService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeInfoBoard, util.GetDeviceObject(device.ID, device.InfoName), util.OperationSuccess)
 	return nil
 }
+
+func (s *infoBoardService) GetByGateway(id int) []dao.InfoBoard {
+	// 创建查询实例
+	device := &dao.InfoBoard{
+		GatewayId: id,
+	}
+	return device.GetDevicesByGateway()
+}
+
+func (s *infoBoardService) GetByLampPole(id int) []dao.InfoBoard {
+	// 创建查询实例
+	device := &dao.InfoBoard{
+		LampPoleId: id,
+	}
+	return device.GetDevicesByLampPole()
+}

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

@@ -18,7 +18,7 @@ func (s *intelligentLightingService) GetDetailByLight(tenantId, id int) (model.R
 	detail := model.RspIntelligentLightDetail{}
 	lightControl, _ := LightControlService.GetOne(id)
 	if lightControl != nil {
-		lightControl.LampPoleName = lightControl.LampPoleName + "(" + lightControl.LampPoleSN + ")"
+		lightControl.LampPoleName = lightControl.LampPoleName + "(" + lightControl.LampPoleSn + ")"
 		detail.LightControlList = []dao.LightControl{*lightControl}
 		detail.LampPoleName = lightControl.LampPoleName
 	}
@@ -103,9 +103,9 @@ func (s *intelligentLightingService) List(tenantId int, searchValue string, curr
 			PublicName:   intelligentLight.LightControl.Name,
 			PublicId:     intelligentLight.LightControl.ID,
 			LampPoleName: intelligentLight.LightControl.LampPoleName,
-			LampPoleSn:   intelligentLight.LightControl.LampPoleSN,
+			LampPoleSn:   intelligentLight.LightControl.LampPoleSn,
 			StrategyName: intelligentLight.LightName,
-			DeviceSn:     intelligentLight.LightControl.SN,
+			DeviceSn:     intelligentLight.LightControl.Sn,
 			ControlType:  intelligentLight.LightControl.ControlType,
 			IsShowOpts:   true,
 		}

+ 26 - 8
app/device/service/ipBroadcastService.go

@@ -3,6 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -41,6 +42,8 @@ func (s *ipBroadcastService) CreateOrUpdate(userId int64, tenantId int, req dao.
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -52,14 +55,15 @@ func (s *ipBroadcastService) CreateOrUpdate(userId int64, tenantId int, req dao.
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
 func (s *ipBroadcastService) List(searchValue string, current, size int) ([]dao.IpBroadcast, *util.Errors) {
 	device := dao.IpBroadcast{}
 	if searchValue != "" {
-		device.CastSN = searchValue
+		device.CastSn = searchValue
 		device.CastName = searchValue
 	}
 
@@ -72,7 +76,7 @@ func (s *ipBroadcastService) List(searchValue string, current, size int) ([]dao.
 	return devices, nil
 }
 
-func (s *ipBroadcastService) Remove(userId int64, id int) *util.Errors {
+func (s *ipBroadcastService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.IpBroadcast{
 		ID:         id,
@@ -80,18 +84,16 @@ func (s *ipBroadcastService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeIPBroadcast, util.GetDeviceObject(device.ID, device.CastName), util.OperationSuccess)
 	return nil
 }
 
-func (s *ipBroadcastService) GetList(tenantId int) ([]*dao.IpBroadcast, *util.Errors) {
+func (s *ipBroadcastService) GetList(tenantId int) ([]dao.IpBroadcast, *util.Errors) {
 	device := &dao.IpBroadcast{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -103,3 +105,19 @@ func (s *ipBroadcastService) GetList(tenantId int) ([]*dao.IpBroadcast, *util.Er
 
 	return devices, nil
 }
+
+func (s *ipBroadcastService) GetByGateway(id int) []dao.IpBroadcast {
+	// 创建查询实例
+	device := &dao.IpBroadcast{
+		GatewayId: id,
+	}
+	return device.GetDevicesByGateway()
+}
+
+func (s *ipBroadcastService) GetByLampPole(id int) []dao.IpBroadcast {
+	// 创建查询实例
+	device := &dao.IpBroadcast{
+		LampPoleId: id,
+	}
+	return device.GetDevicesByLampPole()
+}

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

@@ -4,8 +4,8 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
-	"strings"
 	"time"
 )
 
@@ -27,7 +27,6 @@ func (s *lampPoleGroupService) Get(id int) (*dao.LampPoleGroup, *util.Errors) {
 }
 
 func (s *lampPoleGroupService) CreateOrUpdate(userId int64, tenantId int, req *dao.LampPoleGroup) *util.Errors {
-	var build strings.Builder
 	device := req
 	device.TenantId = tenantId
 	device.UpdateUser = userId
@@ -36,19 +35,16 @@ func (s *lampPoleGroupService) CreateOrUpdate(userId int64, tenantId int, req *d
 	if req.ID == 0 {
 		device.CreateTime = time.Now()
 		device.CreateUser = userId
-		build.WriteString("新增(灯杆分组)【" + device.PoleGroupName + "】")
 		if device.IsExistedByName() {
 			fmt.Printf("Create IsExistedByName \n")
 			return util.ParamsInvalidResponse(model.RepeatedName, nil)
 		}
 		if err := device.Create(); err != nil {
 			fmt.Printf("Create err = %s \n", err.Error())
-			build.WriteString("失败")
-			OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
 			return util.FailResponse(err.Error(), nil)
 		}
-		build.WriteString("成功")
-		OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
+		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)
 	}
 
@@ -57,20 +53,12 @@ func (s *lampPoleGroupService) CreateOrUpdate(userId int64, tenantId int, req *d
 		return util.ParamsInvalidResponse(model.RepeatedName, nil)
 	}
 
-	build.WriteString("修改(灯杆分组)【" + device.PoleGroupName + "】")
 	if err := device.Update(); err != nil {
 		fmt.Printf("Update err = %s \n", err.Error())
-		build.WriteString("失败")
-
-		OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
-
 		return util.FailResponse(err.Error(), nil)
 	}
-	build.WriteString("成功")
-
-	OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
-
-	//todo operation record
+	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)
 }
 
@@ -90,8 +78,6 @@ func (s *lampPoleGroupService) List(poleGroupName string, current, size int) ([]
 }
 
 func (s *lampPoleGroupService) Remove(userId int64, tenantId int, id int, name string) *util.Errors {
-	var build strings.Builder
-
 	device := &dao.LampPoleGroup{
 		ID:         id,
 		IsDeleted:  1,
@@ -101,15 +87,14 @@ func (s *lampPoleGroupService) Remove(userId int64, tenantId int, id int, name s
 
 	//todo
 	// service.lampPoleService.CountRelation()
-	build.WriteString("删除(灯杆分组)【" + name + "】")
 	err := device.Delete()
 	if err != nil {
-		build.WriteString("失败")
-		OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
+		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)
 	}
-	build.WriteString("成功")
-	OperationHisService.Save(userId, tenantId, model.OperationRemove, model.ModuleTypeDevice, build.String())
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeLampPoleGroup, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationSuccess)
 	return nil
 }
 

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

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -22,7 +23,6 @@ func (s *lampPoleService) Get(id int) (*dao.LampPole, *util.Errors) {
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	//todo runstate 需要使用各个设备的状态来处理
 	return device, nil
 }
 
@@ -35,18 +35,18 @@ func (s *lampPoleService) GetRelevanceDetail(id int) (*model.LampPoleDetail, *ut
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	//todo get gateway ipBroadcast lightcontroller... list
+
 	return &model.LampPoleDetail{
 		LampPole:          *device,
-		AlarmTerminalList: nil,
-		CameraList:        nil,
-		CaptureUnitList:   nil,
-		GatewayList:       nil,
-		InfoBoardList:     nil,
-		IpBroadcastList:   nil,
-		LightControlList:  nil,
-		SensorList:        nil,
-		ZigbeeList:        nil,
+		AlarmTerminalList: AlarmTerminalService.GetByLampPole(device.ID),
+		CameraList:        CameraService.GetByLampPole(device.ID),
+		CaptureUnitList:   CaptureUintService.GetByLampPole(device.ID),
+		GatewayList:       GatewayService.GetByLampPole(device.ID),
+		InfoBoardList:     InfoBoardService.GetByLampPole(device.ID),
+		IpBroadcastList:   IpBroadcastService.GetByLampPole(device.ID),
+		LightControlList:  LightControlService.GetByLampPole(device.ID),
+		SensorList:        OptoSensorService.GetByLampPole(device.ID),
+		ZigbeeList:        ZigbeeService.GetByLampPole(device.ID),
 	}, nil
 }
 
@@ -70,6 +70,8 @@ func (s *lampPoleService) CreateOrUpdate(userId int64, tenantId int, req *dao.La
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 
@@ -78,7 +80,8 @@ func (s *lampPoleService) CreateOrUpdate(userId int64, tenantId int, req *dao.La
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -100,7 +103,7 @@ func (s *lampPoleService) List(searchValue, groupId, boxId string, current, size
 	return devices, nil
 }
 
-func (s *lampPoleService) Remove(userId int64, id int) *util.Errors {
+func (s *lampPoleService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.LampPole{
 		ID:         id,
@@ -108,15 +111,12 @@ func (s *lampPoleService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-
-	//todo
-	// service.lampPoleService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeLampPole, util.GetDeviceObject(device.ID, device.PoleName), util.OperationSuccess)
 	return nil
 }
 

+ 0 - 5
app/device/service/lightConditionService.go

@@ -45,11 +45,6 @@ func (s *lightConditionService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-
-	//todo
-	// service.gatewayService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)

+ 45 - 44
app/device/service/lightControlService.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"strconv"
 	"strings"
@@ -15,7 +16,7 @@ var LightControlService = new(lightControlService)
 
 type lightControlService struct{}
 
-func (s *lightControlService) Get(id int) (*dao.LightControl, *util.Errors) {
+func (s *lightControlService) Get(id int) (*model.LightControlDetail, *util.Errors) {
 	// 创建查询实例
 	device := &dao.LightControl{
 		ID: id,
@@ -24,32 +25,14 @@ func (s *lightControlService) Get(id int) (*dao.LightControl, *util.Errors) {
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-	//todo runstate 需要使用各个设备的状态来处理
-	return device, nil
-}
-
-func (s *lightControlService) GetRelevanceDetail(id int) (*model.LightControlDetail, *util.Errors) {
-	// 创建查询实例
-	device := &dao.LightControl{
-		ID: id,
+	state := util.GetDeviceState(device.Sn)
+	detail := model.LightControlDetail{
+		LightControl: *device,
+		EndLineTime:  "",
+		NetworkState: state,
+		RunState:     state,
 	}
-	err := device.GetDevice()
-	if err != nil {
-		return nil, util.FailResponse(err.Error(), nil)
-	}
-	//todo get gateway ipBroadcast lightcontroller... list
-	return &model.LightControlDetail{
-		LightControl:      *device,
-		AlarmTerminalList: nil,
-		CameraList:        nil,
-		CaptureUnitList:   nil,
-		GatewayList:       nil,
-		InfoBoardList:     nil,
-		IpBroadcastList:   nil,
-		LightControlList:  nil,
-		SensorList:        nil,
-		ZigbeeList:        nil,
-	}, nil
+	return &detail, nil
 }
 
 func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *dao.LightControl) *util.Errors {
@@ -64,7 +47,7 @@ func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *da
 			device.LampLat = lampPole.PoleLat
 			device.LampLng = lampPole.PoleLng
 			device.LampPoleName = lampPole.PoleName
-			device.LampPoleSN = lampPole.PoleSN
+			device.LampPoleSn = lampPole.PoleSN
 			device.LampPoleLocation = lampPole.InstallLocation
 			device.GroupId = lampPole.GroupId
 		} else {
@@ -77,19 +60,21 @@ func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *da
 			return util.ParamsInvalidResponse(model.ZigbeeSelect, nil)
 		}
 		if device.IsOnDemand == 0 {
-			if device.ControlNO == "" {
+			if device.ControlNo == "" {
 				return util.ParamsInvalidResponse(model.ControlNONull, nil)
 			}
-			if !checkControlNoIsCompliance(device.ControlNO) {
+			if !checkControlNoIsCompliance(device.ControlNo) {
 				return util.ParamsInvalidResponse(model.ControlNOInvalid, nil)
 			}
 		}
-		//todo zigbee
-		// Zigbee zigbee = zigbeeService.getById(lightControl.getZigbeeId());
-		// lightControl.setZigbeeName(zigbee.getName());
-		// lightControl.setZigbeeSn(zigbee.getSn());
-		// lightControl.setChanelNum(zigbee.getChanelNum());
-		// lightControl.setNetworkNum(zigbee.getNetworkNum());
+		zigbee, err := ZigbeeService.Get(device.ZigbeeId)
+		if err != nil {
+			return err
+		}
+		device.ZigbeeName = zigbee.Name
+		device.ZigbeeSn = zigbee.Sn
+		device.ChannelNum = zigbee.ChannelNum
+		device.NetworkNum = zigbee.NetworkNum
 	}
 
 	if device.ID == 0 {
@@ -105,6 +90,8 @@ func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *da
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 
@@ -113,7 +100,8 @@ func (s *lightControlService) CreateOrUpdate(userId int64, tenantId int, req *da
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -121,7 +109,7 @@ func (s *lightControlService) List(searchValue, controlType, zigbeeId string, cu
 	*util.Errors) {
 	device := dao.LightControl{}
 	if searchValue != "" {
-		device.SN = searchValue
+		device.Sn = searchValue
 	}
 	if controlType != "" {
 		cType, err := strconv.Atoi(controlType)
@@ -145,7 +133,7 @@ func (s *lightControlService) List(searchValue, controlType, zigbeeId string, cu
 	return devices, nil
 }
 
-func (s *lightControlService) Remove(userId int64, id int) *util.Errors {
+func (s *lightControlService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.LightControl{
 		ID:         id,
@@ -153,19 +141,16 @@ func (s *lightControlService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-
-	//todo
-	// service.lampPoleService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeLightControl, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
 	return nil
 }
 
-func (s *lightControlService) GetList(tenantId int) ([]*dao.LightControl, *util.Errors) {
+func (s *lightControlService) GetList(tenantId int) ([]dao.LightControl, *util.Errors) {
 	device := &dao.LightControl{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -215,6 +200,22 @@ func (s *lightControlService) GetByGroupId(groupId int) ([]dao.LightControl, *ut
 	return devices, nil
 }
 
+func (s *lightControlService) GetByGateway(id int) []dao.LightControl {
+	// 创建查询实例
+	device := &dao.LightControl{
+		GatewayId: id,
+	}
+	return device.GetDevicesByGateway()
+}
+
+func (s *lightControlService) GetByLampPole(id int) []dao.LightControl {
+	// 创建查询实例
+	device := &dao.LightControl{
+		LampPoleId: id,
+	}
+	return device.GetDevicesByLampPole()
+}
+
 //检查灯控编号是否合规1-1——255-255
 func checkControlNoIsCompliance(controlNo string) bool {
 	arr := strings.Split(controlNo, "-")

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

@@ -3,6 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -41,6 +42,8 @@ func (s *manholeCoverService) CreateOrUpdate(userId int64, tenantId int, req dao
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -52,14 +55,15 @@ func (s *manholeCoverService) CreateOrUpdate(userId int64, tenantId int, req dao
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
 func (s *manholeCoverService) List(searchValue string, current, size int) ([]dao.ManholeCover, *util.Errors) {
 	device := dao.ManholeCover{}
 	if searchValue != "" {
-		device.ManholeSN = searchValue
+		device.ManholeSn = searchValue
 		device.ManholeName = searchValue
 	}
 
@@ -72,7 +76,7 @@ func (s *manholeCoverService) List(searchValue string, current, size int) ([]dao
 	return devices, nil
 }
 
-func (s *manholeCoverService) Remove(userId int64, id int) *util.Errors {
+func (s *manholeCoverService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.ManholeCover{
 		ID:         id,
@@ -80,14 +84,12 @@ func (s *manholeCoverService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeManholeCover, util.GetDeviceObject(device.ID, device.ManholeName), util.OperationSuccess)
 	return nil
 }
 

+ 8 - 4
app/device/service/onDemandGroupService.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"strconv"
 	"time"
@@ -46,6 +47,8 @@ func (s *onDemandGroupService) CreateOrUpdate(userId int64, tenantId int, req *d
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 
@@ -54,7 +57,8 @@ func (s *onDemandGroupService) CreateOrUpdate(userId int64, tenantId int, req *d
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -74,7 +78,7 @@ func (s *onDemandGroupService) List(searchValue string, current, size int) ([]da
 	return devices, nil
 }
 
-func (s *onDemandGroupService) Remove(userId int64, id int) *util.Errors {
+func (s *onDemandGroupService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.OnDemandGroup{
 		ID:         id,
@@ -82,12 +86,12 @@ func (s *onDemandGroupService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeAlarmServer, util.GetDeviceObject(device.ID, device.PoleGroupName), util.OperationSuccess)
 	return nil
 }
 

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

@@ -3,6 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -39,6 +40,8 @@ func (s *onDemandSensorService) CreateOrUpdate(userId int64, tenantId int, req d
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	device.UpdateUser = userId
@@ -52,7 +55,8 @@ func (s *onDemandSensorService) CreateOrUpdate(userId int64, tenantId int, req d
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -72,7 +76,7 @@ func (s *onDemandSensorService) List(searchValue string, current, size int) ([]d
 	return devices, nil
 }
 
-func (s *onDemandSensorService) Remove(userId int64, id int) *util.Errors {
+func (s *onDemandSensorService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.OnDemandSensor{
 		ID:         id,
@@ -80,13 +84,11 @@ func (s *onDemandSensorService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeOnDemandSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
 	return nil
 }

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

@@ -3,6 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -41,6 +42,8 @@ func (s *optoSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.O
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -52,14 +55,15 @@ func (s *optoSensorService) CreateOrUpdate(userId int64, tenantId int, req dao.O
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
 func (s *optoSensorService) List(searchValue string, current, size int) ([]dao.OptoSensor, *util.Errors) {
 	device := dao.OptoSensor{}
 	if searchValue != "" {
-		device.SN = searchValue
+		device.Sn = searchValue
 		device.Name = searchValue
 	}
 
@@ -72,7 +76,7 @@ func (s *optoSensorService) List(searchValue string, current, size int) ([]dao.O
 	return devices, nil
 }
 
-func (s *optoSensorService) Remove(userId int64, id int) *util.Errors {
+func (s *optoSensorService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.OptoSensor{
 		ID:         id,
@@ -80,14 +84,12 @@ func (s *optoSensorService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeOptoSensor, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
 	return nil
 }
 
@@ -103,3 +105,19 @@ func (s *optoSensorService) GetList(tenantId int) ([]*dao.OptoSensor, *util.Erro
 
 	return devices, nil
 }
+
+func (s *optoSensorService) GetByGateway(id int) []dao.OptoSensor {
+	// 创建查询实例
+	device := &dao.OptoSensor{
+		GatewayId: id,
+	}
+	return device.GetDevicesByGateway()
+}
+
+func (s *optoSensorService) GetByLampPole(id int) []dao.OptoSensor {
+	// 创建查询实例
+	device := &dao.OptoSensor{
+		LampPoleId: id,
+	}
+	return device.GetDevicesByLampPole()
+}

+ 24 - 9
app/device/service/switchBoxService.go

@@ -3,6 +3,8 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -41,6 +43,9 @@ func (s *switchBoxService) CreateOrUpdate(userId int64, tenantId int, req dao.Sw
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	//更新
@@ -52,7 +57,9 @@ func (s *switchBoxService) CreateOrUpdate(userId int64, tenantId int, req dao.Sw
 		fmt.Printf("Update err = %s \n", err.Error())
 		return util.FailResponse(err.Error(), nil)
 	}
-	//todo operation record
+	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)
 }
 
@@ -72,7 +79,7 @@ func (s *switchBoxService) List(searchValue string, current, size int) ([]dao.Sw
 	return devices, nil
 }
 
-func (s *switchBoxService) Remove(userId int64, id int) *util.Errors {
+func (s *switchBoxService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.SwitchBox{
 		ID:         id,
@@ -80,27 +87,35 @@ func (s *switchBoxService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.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)
 	return nil
 }
 
 func (s *switchBoxService) GetList(tenantId int) ([]*dao.SwitchBox, *util.Errors) {
-	// todo use redis cache
+	var devices []*dao.SwitchBox
+	err := util.Redis.Get(getSwitchBoxListRedisKey(tenantId)).Scan(&devices)
+	if err == nil {
+		return devices, nil
+	}
+
 	device := &dao.SwitchBox{
 		TenantId:  tenantId,
 		IsDeleted: 0,
 	}
-	devices, err := device.GetAllDevices()
+	devices, err = device.GetAllDevices()
 	if err != nil {
 		return nil, util.FailResponse(err.Error(), nil)
 	}
-
+	_ = util.Redis.Set(getSwitchBoxListRedisKey(tenantId), devices, 0).Err()
 	return devices, nil
 }
+
+func getSwitchBoxListRedisKey(tenantId int) string {
+	return fmt.Sprintf(model.SwitchBoxList, tenantId)
+}

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

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
 	"iot_manager_service/app/device/model"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -42,6 +43,8 @@ func (s *transformerService) CreateOrUpdate(userId int64, tenantId int, req dao.
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -53,7 +56,8 @@ func (s *transformerService) CreateOrUpdate(userId int64, tenantId int, req dao.
 		return util.FailResponse(err.Error(), nil)
 	}
 
-	//todo operation record
+	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)
 }
 
@@ -73,7 +77,7 @@ func (s *transformerService) List(searchValue string, current, size int) ([]dao.
 	return devices, nil
 }
 
-func (s *transformerService) Remove(userId int64, id int) *util.Errors {
+func (s *transformerService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Transformer{
 		ID:         id,
@@ -81,14 +85,12 @@ func (s *transformerService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeTransformer, util.GetDeviceObject(device.ID, device.TransName), util.OperationSuccess)
 	return nil
 }
 

+ 26 - 9
app/device/service/zigbeeService.go

@@ -3,6 +3,7 @@ package service
 import (
 	"fmt"
 	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/system/service"
 	"iot_manager_service/util"
 	"time"
 )
@@ -41,6 +42,8 @@ func (s *zigbeeService) CreateOrUpdate(userId int64, tenantId int, req dao.Zigbe
 			fmt.Printf("Create err = %s \n", err.Error())
 			return util.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)
 	}
 	if device.IsExistedByNameAndCode() {
@@ -51,15 +54,15 @@ func (s *zigbeeService) CreateOrUpdate(userId int64, tenantId int, req dao.Zigbe
 		fmt.Printf("Update err = %s \n", err.Error())
 		return util.FailResponse(err.Error(), nil)
 	}
-
-	//todo operation record
+	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)
 }
 
 func (s *zigbeeService) List(searchValue string, current, size int) ([]dao.Zigbee, *util.Errors) {
 	device := dao.Zigbee{}
 	if searchValue != "" {
-		device.SN = searchValue
+		device.Sn = searchValue
 		device.Name = searchValue
 	}
 
@@ -72,7 +75,7 @@ func (s *zigbeeService) List(searchValue string, current, size int) ([]dao.Zigbe
 	return devices, nil
 }
 
-func (s *zigbeeService) Remove(userId int64, id int) *util.Errors {
+func (s *zigbeeService) Remove(userId int64, tenantId int, id int) *util.Errors {
 	// 创建查询实例
 	device := &dao.Zigbee{
 		ID:         id,
@@ -80,18 +83,16 @@ func (s *zigbeeService) Remove(userId int64, id int) *util.Errors {
 		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
-	//todo
-	// service.transformerService.CountRelation()
-
-	//todo operation record
 	err := device.Delete()
 	if err != nil {
 		return util.FailResponse(err.Error(), nil)
 	}
+	service.OperationHisService.Save(userId, tenantId, util.OperationRemove, util.ModuleTypeDevice,
+		util.DeviceTypeZigbee, util.GetDeviceObject(device.ID, device.Name), util.OperationSuccess)
 	return nil
 }
 
-func (s *zigbeeService) GetList(tenantId int) ([]*dao.Zigbee, *util.Errors) {
+func (s *zigbeeService) GetList(tenantId int) ([]dao.Zigbee, *util.Errors) {
 	device := &dao.Zigbee{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -103,3 +104,19 @@ func (s *zigbeeService) GetList(tenantId int) ([]*dao.Zigbee, *util.Errors) {
 
 	return devices, nil
 }
+
+func (s *zigbeeService) GetByGateway(id int) []dao.Zigbee {
+	// 创建查询实例
+	device := &dao.Zigbee{
+		GatewayId: id,
+	}
+	return device.GetDevicesByGateway()
+}
+
+func (s *zigbeeService) GetByLampPole(id int) []dao.Zigbee {
+	// 创建查询实例
+	device := &dao.Zigbee{
+		LampPoleId: id,
+	}
+	return device.GetDevicesByLampPole()
+}

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

@@ -2,6 +2,7 @@ package controller
 
 import (
 	"github.com/gin-gonic/gin"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
 	"iot_manager_service/app/system/service"
@@ -81,12 +82,15 @@ func (c *tenant) Submit(ctx *gin.Context) {
 }
 
 func (c *tenant) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqTenantRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.TenantService.Remove(req.IDs)
+	err := service.TenantService.Remove(claims.UserId, req.IDs)
 	ctx.JSON(http.StatusOK, err)
 }
 

+ 10 - 12
app/system/controller/token.go

@@ -107,14 +107,12 @@ func (c *auth) Token(ctx *gin.Context) {
 }
 
 func (c *auth) Logout(ctx *gin.Context) {
-	value, isExist := ctx.Get(middleware.Authorization)
-	if !isExist || value == nil {
-		ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
-		return
-	}
-	jwtToken := value.(*middleware.Claims)
-	_ = util.Redis.Del(getAccessTokenKey(jwtToken.TenantId, jwtToken.UserId, jwtToken.Random)).Err()
-	//todo 操作记录
+	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))
 }
 
@@ -208,9 +206,11 @@ func captchaGrant(token model.Token, ctx *gin.Context) (*model.UserInfo, *util.E
 		info.User = service.UserService.GetOne(token.TenantId, token.UserName, token.Password)
 		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)
+		}
 	}
-
-	//todo 操作记录
 	return info, nil
 }
 
@@ -232,8 +232,6 @@ func refreshGrant(token model.Token) (*model.UserInfo, *util.Errors) {
 
 	info.User = service.UserService.GetOneByTenantId(token.TenantId)
 	info.Roles = []string{"admin"}
-
-	//todo 操作记录
 	return info, nil
 }
 

+ 5 - 1
app/system/controller/user.go

@@ -2,6 +2,7 @@ package controller
 
 import (
 	"github.com/gin-gonic/gin"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
 	"iot_manager_service/app/system/service"
@@ -81,12 +82,15 @@ func (c *user) Update(ctx *gin.Context) {
 }
 
 func (c *user) Remove(ctx *gin.Context) {
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var req *model.ReqUserRemove
 	if err := ctx.ShouldBindJSON(&req); err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
 		return
 	}
-	err := service.UserService.Remove(req.IDs)
+	err := service.UserService.Remove(claims.UserId, req.IDs)
 	ctx.JSON(http.StatusOK, err)
 }
 

+ 44 - 0
app/system/dao/operationHisDao.go

@@ -0,0 +1,44 @@
+package dao
+
+import (
+	"time"
+)
+
+// OperationHistory 操作记录
+type OperationHistory struct {
+	ID            int       `gorm:"primary_key" json:"id"`            //编号
+	OperationType int       `gorm:"type:int" json:"operationType"`    //操作类型
+	ModuleType    int       `gorm:"type:int" json:"moduleType"`       //操作模块
+	DeviceType    int       `gorm:"type:int" json:"deviceType"`       //操作模块
+	Object        string    `gorm:"type:varchar(48)" json:"object"`   //操作对象 一般为设备ID+Name
+	Result        int       `gorm:"type:int" json:"result"`           //0 成功 1失败
+	HandleUserId  int64     `gorm:"type:bigint" json:"handleUserId"`  //操作用户ID
+	HandleTime    time.Time `gorm:"type:timestamp" json:"handleTime"` //操作时间
+	TenantId      int       `gorm:"type:int" json:"tenantId"`         //租户ID
+}
+
+func (OperationHistory) TableName() string {
+	return "operation_history"
+}
+
+func (c *OperationHistory) Create() error {
+	return Db.Debug().Model(&c).Save(&c).Error
+}
+
+func (c OperationHistory) GetHistories(offset, limit int) ([]OperationHistory, error) {
+	var list []OperationHistory
+	db := Db.Debug().Model(&c)
+	if c.OperationType > 0 {
+		db = db.Where("operation_type = ?", c.OperationType)
+	}
+	if c.ModuleType > 0 {
+		db = db.Where("module_type = ?", c.ModuleType)
+	}
+	if c.Object != "" {
+		db = db.Where("object like ?", "%"+c.Object+"%")
+	}
+
+	err := Db.Debug().Model(&c).Offset(offset).Limit(limit).Find(&list).Error
+
+	return list, err
+}

+ 4 - 2
app/device/model/OperationHis.go

@@ -1,9 +1,11 @@
 package model
 
-import "iot_manager_service/app/device/dao"
+import (
+	"iot_manager_service/app/system/dao"
+)
 
 type OperationHisDetail struct {
-	dao.OperationHis
+	dao.OperationHistory
 	HandleName        string `json:"handle_name"`       //操作人
 	OperationTypeName string `json:"operationTypeName"` //操作类型
 	ModuleTypeName    string `json:"moduleTypeName"`    //操作模块

+ 14 - 13
app/device/service/operationHisService.go

@@ -2,9 +2,8 @@ package service
 
 import (
 	"fmt"
-	"iot_manager_service/app/device/dao"
-	"iot_manager_service/app/device/model"
-	"iot_manager_service/app/system/service"
+	"iot_manager_service/app/system/dao"
+	"iot_manager_service/app/system/model"
 	"iot_manager_service/util"
 	"strconv"
 	"time"
@@ -15,12 +14,14 @@ var OperationHisService = new(operationHisService)
 
 type operationHisService struct{}
 
-func (s *operationHisService) Save(userId int64, tenantId int, handleType, handleModuleType int,
-	handleContent string) {
-	operation := dao.OperationHis{
+func (s *operationHisService) Save(userId int64, tenantId int, handleType, handleModuleType, deviceType int,
+	handleObject string, handleResult int) {
+	operation := dao.OperationHistory{
 		OperationType: handleType,
 		ModuleType:    handleModuleType,
-		HandleContent: handleContent,
+		DeviceType:    deviceType,
+		Object:        handleObject,
+		Result:        handleResult,
 		HandleUserId:  userId,
 		HandleTime:    time.Now(),
 		TenantId:      tenantId,
@@ -33,8 +34,8 @@ 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) {
-	his := dao.OperationHis{
-		HandleContent: handleContent,
+	his := dao.OperationHistory{
+		Object: handleContent,
 	}
 	if operationType != "" {
 		operation, err := strconv.Atoi(operationType)
@@ -60,11 +61,11 @@ func (s *operationHisService) List(tenantId int, handleContent, operationType, m
 	var details []model.OperationHisDetail
 	for _, his := range list {
 		detail := model.OperationHisDetail{
-			OperationHis: his,
+			OperationHistory: his,
 		}
-		detail.HandleName = service.UserService.GetUserName(tenantId, his.HandleUserId)
-		detail.OperationTypeName = service.DictService.GetControlType(tenantId, his.OperationType)
-		detail.ModuleTypeName = service.DictService.GetModuleName(tenantId, his.ModuleType)
+		detail.HandleName = UserService.GetUserName(tenantId, his.HandleUserId)
+		detail.OperationTypeName = DictService.GetControlType(tenantId, his.OperationType)
+		detail.ModuleTypeName = DictService.GetModuleName(tenantId, his.ModuleType)
 		details = append(details, detail)
 	}
 	return details, nil

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

@@ -106,11 +106,11 @@ func (s *tenantService) GetList() ([]dao.Tenant, error) {
 	return tenants, nil
 }
 
-func (s *tenantService) Remove(id int64) *util.Errors {
+func (s *tenantService) Remove(userId, id int64) *util.Errors {
 	tenant := &dao.Tenant{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: id, // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	err := tenant.Remove()

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

@@ -105,11 +105,11 @@ func (s *userService) Update(req dao.User) *util.Errors {
 	return nil
 }
 
-func (s *userService) Remove(id int64) *util.Errors {
+func (s *userService) Remove(userId, id int64) *util.Errors {
 	user := &dao.User{
 		ID:         id,
 		IsDeleted:  1,
-		UpdateUser: id, // todo 使用登录态
+		UpdateUser: userId,
 		UpdateTime: time.Now(),
 	}
 	err := user.Remove()

+ 1 - 1
build.bat

@@ -1,3 +1,3 @@
 set GOARCH=amd64
 set GOOS=linux
-go build -o build/terry_test_service ./
+go build -o build/iot_service ./

+ 70 - 0
util/common.go

@@ -7,6 +7,76 @@ import (
 	"time"
 )
 
+//Operation type 操作类型
+const (
+	OperationDefault          = iota
+	OperationLogin            //登录
+	OperationLogout           //注销
+	OperationCreate           //新增
+	OperationUpdate           //修改
+	OperationRemove           //删除
+	OperationImport           //导入导出
+	OperationLightStrategy    //开关灯控策略
+	OperationOrderCreate      //工单发起
+	OperationOrderChange      //工单转派
+	OperationOrderHandle      //工单处理
+	OperationProgramPublish   //节目发布待审核
+	OperationProgramResult    //节目处理结果
+	OperationStrategyRelation //策略关联
+	OperationControl          //操作
+	OperationAlarmHandle      //告警处理
+
+	OperationSuccess = 0
+	OperationFail    = 1
+)
+
+const (
+	ModuleTypeDefault        = iota //操作记录模块
+	ModuleTypeDevice                //设备台账管理
+	ModuleTypeInfoBar               //信息发布系统
+	ModuleTypeOrder                 //工单运维
+	ModuleTypeNotification          //通知公告
+	ModuleTypeLightStrategy         //照明策略
+	ModuleTypeLighting              //智慧照明系统-智能照明
+	ModuleTypeSystem                //系统管理
+	ModuleTypeAlarm                 //告警管理
+	ModuleTypeOperation             //运营分析
+	ModuleTypeRecord                //记录处理
+	ModuleTypeWisdomLighting        //智能感应照明系统-灯随车走照明控制
+)
+
+//deviceType 设备类型 1** 交通 2** 农业
+const (
+	DeviceTypeDefault        = 0   //--
+	DeviceTypeCamera         = 100 //摄像头
+	DeviceTypeLightControl   = 101 //灯控
+	DeviceTypeInfoBoard      = 102 //信息屏
+	DeviceTypeSwitchBox      = 103 //配电箱
+	DeviceTypeGateway        = 104 //网关
+	DeviceTypeOptoSensor     = 105 // 环境监测
+	DeviceTypeZigbee         = 106 //ZigBee
+	DeviceTypeAlarmTerminal  = 107 //一键告警终端
+	DeviceTypeAlarmServer    = 108 //一键告警服务端
+	DeviceTypeBridgeSensor   = 109 //桥梁传感器
+	DeviceTypeBridge         = 110 //桥梁
+	DeviceTypeIPBroadcast    = 111 //ip音柱
+	DeviceTypeManholeCover   = 112 //井盖
+	DeviceTypeGarbage        = 113 //垃圾桶
+	DeviceTypeLampPoleGroup  = 114 //灯杆分组
+	DeviceTypeLampPole       = 115 //灯杆
+	DeviceTypeCaptureUnit    = 116 //抓拍单元
+	DeviceTypePoint          = 117 //卡口
+	DeviceTypeGarbageGroup   = 118 //垃圾桶分组
+	DeviceTypeLightStrategy  = 119 //灯控策略
+	DeviceTypeOnDemandGroup  = 120 //灯随车走分组
+	DeviceTypeOnDemandSensor = 121 //灯随车走传感器
+	DeviceTypeTransformer    = 122 //变压器
+)
+
+func GetDeviceObject(id int, name string) string {
+	return strconv.Itoa(id) + "(" + name + ")"
+}
+
 func StringToInt(id string) int {
 	if id != "" {
 		id, err := strconv.Atoi(id)

+ 1 - 0
util/redis.go

@@ -32,6 +32,7 @@ const (
 	DeviceStateKey = "dev_state:%s"
 )
 
+//GetDeviceState 获取设备状态 1在线 2离线
 func GetDeviceState(sn string) int {
 	key := fmt.Sprintf(DeviceStateKey, sn)
 	value, err := Redis.Get(key).Int()