Browse Source

dict添加,字段修改

terry 2 years ago
parent
commit
21a8a5e778

+ 50 - 26
app/device/controller/utilController.go

@@ -4,6 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/app/device/model"
 	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
 	"iot_manager_service/util"
 	"net/http"
 	"strconv"
@@ -33,47 +34,70 @@ type utilCtl struct{}
 func (c *utilCtl) GetModelList(ctx *gin.Context) {
 	t := ctx.Query("type")
 	d := ctx.Query("deviceType")
+	id := ctx.Query("id")
+	pid := ctx.Query("pid")
 	modeType, err := strconv.Atoi(t)
 	if err != nil || modeType < 1 || modeType > 3 {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("type invalid", nil))
 		return
 	}
+	modeType++ //前端传入的1和2,实际是2和3
+
 	deviceType, err := strconv.Atoi(d)
 	if err != nil {
 		ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("deviceType invalid", nil))
 		return
 	}
-
-	vendor, err := service.UtilService.GetDeviceVendor(modeType, deviceType)
-	if err != nil {
-		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
-		return
+	parentId := -1
+	if id != "" {
+		parentId, _ = strconv.Atoi(id)
+	} else if pid != "" {
+		parentId, _ = strconv.Atoi(pid)
 	}
+
+	value, _ := ctx.Get(middleware.Authorization)
+	claims := value.(*middleware.Claims)
+
 	var result []model.VendorDetail
 	if modeType == model.TypeVendor {
-		result = append(result, model.VendorDetail{
-			Id:       vendor.ID,
-			ParentId: vendor.ParentId,
-			Vendor:   vendor.VendorValue,
-			Brand:    "",
-			Model:    "",
-		})
+		vendors, err := service.UtilService.GetDeviceVendor(claims.TenantId, deviceType)
+		if err != nil {
+			ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+			return
+		}
+		for _, vendor := range vendors {
+			result = append(result, model.VendorDetail{
+				Id:       vendor.ID,
+				ParentId: vendor.ParentId,
+				Vendor:   vendor.VendorValue,
+			})
+		}
 	} else if modeType == model.TypeBrand {
-		result = append(result, model.VendorDetail{
-			Id:       vendor.ID,
-			ParentId: vendor.ParentId,
-			Vendor:   "",
-			Brand:    vendor.VendorValue,
-			Model:    "",
-		})
+		vendors, err := service.UtilService.GetDeviceBrand(claims.TenantId, deviceType)
+		if err != nil {
+			ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+			return
+		}
+		for _, vendor := range vendors {
+			result = append(result, model.VendorDetail{
+				Id:       vendor.ID,
+				ParentId: vendor.ParentId,
+				Brand:    vendor.VendorValue,
+			})
+		}
 	} else if modeType == model.TypeModel {
-		result = append(result, model.VendorDetail{
-			Id:       vendor.ID,
-			ParentId: vendor.ParentId,
-			Vendor:   "",
-			Brand:    "",
-			Model:    vendor.VendorValue,
-		})
+		vendors, err := service.UtilService.GetDeviceModel(claims.TenantId, deviceType, parentId)
+		if err != nil {
+			ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+			return
+		}
+		for _, vendor := range vendors {
+			result = append(result, model.VendorDetail{
+				Id:       vendor.ID,
+				ParentId: vendor.ParentId,
+				Model:    vendor.VendorValue,
+			})
+		}
 	}
 	ctx.JSON(http.StatusOK, util.SuccessResponse("", result))
 }

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

@@ -10,10 +10,10 @@ 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"`        //灯杆编码
 	LampPoleLocation string    `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置

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

@@ -13,7 +13,7 @@ func InitDB(db *gorm.DB) {
 	Db = db
 	err := Db.AutoMigrate(
 		&dao.User{},
-		&Dict{},
+		&dao.Dict{},
 		&LampPoleGroup{},
 		&LampPole{},
 		&Gateway{},

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

@@ -16,11 +16,11 @@ type InfoBoard struct {
 	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        string    `gorm:"type:varchar(32)" json:"gatewayId"`                //所属网关id
+	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地址

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

@@ -18,7 +18,7 @@ type IpBroadcast struct {
 	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地址         //服务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"`                     //安装时间

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

@@ -23,7 +23,32 @@ func (DeviceVendor) TableName() string {
 	return "device_vendor"
 }
 
-func (c *DeviceVendor) GetByType() error {
-	err := Db.Debug().Model(&c).Where(" vendor_type = ? and device_type = ?", c.VendorType, c.DeviceType).Find(&c).Error
-	return err
+func (c *DeviceVendor) GetVendor() ([]DeviceVendor, error) {
+	var vendors []DeviceVendor
+	err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
+		Where(" vendor_type = 1 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).
+		Find(&vendors).Error
+	return vendors, err
+}
+
+func (c *DeviceVendor) GetBrand() ([]DeviceVendor, error) {
+	var vendors []DeviceVendor
+	err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
+		Where(" vendor_type = 2 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).Find(&vendors).Error
+	return vendors, err
+}
+
+func (c *DeviceVendor) GetModel() ([]DeviceVendor, error) {
+	var vendors []DeviceVendor
+	if c.ParentId > 0 {
+		err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
+			Where(" vendor_type = 3 and device_type = ? and is_deleted = 0 and tenant_id = ? and parent_id = ?",
+				c.DeviceType, c.TenantId, c.ParentId).Find(&vendors).Error
+		return vendors, err
+	} else {
+		err := Db.Debug().Model(&c).Select("id, parent_id, vendor_value").
+			Where(" vendor_type = 3 and device_type = ? and is_deleted = 0 and tenant_id = ?", c.DeviceType, c.TenantId).Find(&vendors).Error
+		return vendors, err
+	}
+
 }

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

@@ -15,13 +15,13 @@ type Zigbee struct {
 	LampPoleName     string     `gorm:"type: varchar(64)" json:"lampPoleName"`     //灯杆名称
 	LampPoleSN       string     `gorm:"type: varchar(64)" json:"lampPoleSn"`       //灯杆编码
 	LampPoleLocation string     `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
-	PoleLng          float64    `gorm:"type:double(17, 14) " json:"poleLng"`       //经度
-	PoleLat          float64    `gorm:"type:double(17, 14)  " json:"poleLat"`      //纬度
+	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"`                   //设备型号
-	GatewayId        string     `gorm:"type:varchar(32)" json:"gatewayId"`         //所属网关id
+	GatewayId        int        `gorm:"type:int" json:"gatewayId"`                 //所属网关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"`         //所属网关编码
 	ChanelNum        int        `gorm:"type:int" json:"channelNum"`                //通道号
 	NetworkNum       int        `gorm:"type:int" json:"networkNum"`                //网络号
 	InstallTime      *time.Time `gorm:"type:date" json:"installTime"`              //安装时间

+ 4 - 3
app/device/service/operationHisService.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"
@@ -61,9 +62,9 @@ func (s *operationHisService) List(tenantId int, handleContent, operationType, m
 		detail := model.OperationHisDetail{
 			OperationHis: his,
 		}
-		detail.HandleName = util.GetUserName(tenantId, his.HandleUserId)
-		detail.OperationTypeName = util.GetControlType(tenantId, his.OperationType)
-		detail.ModuleTypeName = util.GetModuleName(tenantId, his.ModuleType)
+		detail.HandleName = service.UserService.GetUserName(tenantId, his.HandleUserId)
+		detail.OperationTypeName = service.DictService.GetControlType(tenantId, his.OperationType)
+		detail.ModuleTypeName = service.DictService.GetModuleName(tenantId, his.ModuleType)
 		details = append(details, detail)
 	}
 	return details, nil

+ 22 - 8
app/device/service/utilService.go

@@ -8,28 +8,42 @@ var UtilService = new(utilService)
 
 type utilService struct{}
 
-func (s *utilService) GetDeviceVendor(modeType, deviceType int) (*dao.DeviceVendor, error) {
+func (s *utilService) GetDeviceVendor(tenantId, deviceType int) ([]dao.DeviceVendor, error) {
 	// 创建查询实例
 	device := &dao.DeviceVendor{
-		VendorType: modeType,
+		TenantId:   tenantId,
 		DeviceType: deviceType,
 	}
-	err := device.GetByType()
+	vendors, err := device.GetVendor()
 	if err != nil {
 		return nil, err
 	}
-	return device, nil
+	return vendors, nil
 }
 
-func (s *utilService) GetTenantCode(modeType, deviceType int) (*dao.DeviceVendor, error) {
+func (s *utilService) GetDeviceBrand(tenantId, deviceType int) ([]dao.DeviceVendor, error) {
 	// 创建查询实例
 	device := &dao.DeviceVendor{
-		VendorType: modeType,
+		TenantId:   tenantId,
 		DeviceType: deviceType,
 	}
-	err := device.GetByType()
+	vendors, err := device.GetBrand()
 	if err != nil {
 		return nil, err
 	}
-	return device, nil
+	return vendors, nil
+}
+
+func (s *utilService) GetDeviceModel(tenantId, deviceType, parentId int) ([]dao.DeviceVendor, error) {
+	// 创建查询实例
+	device := &dao.DeviceVendor{
+		TenantId:   tenantId,
+		DeviceType: deviceType,
+		ParentId:   parentId,
+	}
+	vendors, err := device.GetModel()
+	if err != nil {
+		return nil, err
+	}
+	return vendors, nil
 }

+ 0 - 3
app/middleware/checkAuth.go

@@ -1,7 +1,6 @@
 package middleware
 
 import (
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"iot_manager_service/util"
 	"net/http"
@@ -20,13 +19,11 @@ func CheckAuth() gin.HandlerFunc {
 		}
 
 		authorization := ctx.GetHeader(Authorization)
-		fmt.Printf("CheckAuth authorization = %s \n", authorization)
 		if authorization != "" {
 			token := parseAccessToken(authorization)
 			if token != nil {
 				ctx.Set(Authorization, token)
 				ctx.Next()
-				fmt.Printf("CheckAuth next \n")
 				return
 			}
 		}

+ 22 - 0
app/system/controller/dict.go

@@ -0,0 +1,22 @@
+package controller
+
+import (
+	"github.com/gin-gonic/gin"
+	"iot_manager_service/app/system/service"
+	"iot_manager_service/util"
+	"net/http"
+)
+
+var Dict = new(dict)
+
+type dict struct{}
+
+func (c *dict) Dictionary(ctx *gin.Context) {
+	code := ctx.Query("code")
+	result, err := service.DictService.GetByCode(code)
+	if err != nil {
+		ctx.JSON(http.StatusOK, util.FailResponse(err.Error(), nil))
+		return
+	}
+	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Success, result))
+}

+ 8 - 0
app/device/dao/dict.go

@@ -20,3 +20,11 @@ func (Dict) TableName() string {
 func (c *Dict) GetByCodeAndKey() error {
 	return Db.Debug().Model(&c).Where("code = ? and dict_key = ?", c.Code, c.DictKey).Find(&c).Error
 }
+
+func (c *Dict) GetByCode() ([]Dict, error) {
+	var dict []Dict
+	err := Db.Debug().Model(&c).Select("code, dict_key, dict_value").
+		Where("code = ? and parent_id > 0 and is_sealed = 0 and is_deleted = 0", c.Code).
+		Find(&dict).Error
+	return dict, err
+}

+ 75 - 0
app/system/service/dictService.go

@@ -0,0 +1,75 @@
+package service
+
+import (
+	"fmt"
+	"iot_manager_service/app/system/dao"
+	"iot_manager_service/util"
+	"strconv"
+)
+
+// 字典管理服务
+var DictService = new(dictService)
+
+type dictService struct{}
+
+const (
+	ControlTypeKey = "%d:dict:control_type:%d"
+	ControlType    = "control_type"
+	ModuleType     = "module_his_type"
+	SexNameKey     = "%d:sys:sex_name:%d"
+	ModuleTypeKey  = "%d:dict:module_type:%d"
+	Sex            = "sex"
+)
+
+func (s *dictService) GetByCode(code string) ([]dao.Dict, error) {
+	dict := &dao.Dict{Code: code}
+	return dict.GetByCode()
+}
+
+func (s *dictService) GetControlType(tenantId int, id int) string {
+	var name string
+	key := fmt.Sprintf(ControlTypeKey, tenantId, id)
+	name, err := util.Redis.Get(key).Result()
+	if err != nil {
+		dict := &dao.Dict{Code: ControlType, DictKey: strconv.Itoa(id)}
+		if err := dict.GetByCodeAndKey(); err != nil {
+			fmt.Printf("GetByCodeAndKey err = %d \n", err)
+		} else {
+			name = dict.DictValue
+			util.Redis.Set(key, name, -1)
+		}
+	}
+	return name
+}
+
+func (s *dictService) GetModuleName(tenantId int, id int) string {
+	var name string
+	key := fmt.Sprintf(ModuleTypeKey, tenantId, id)
+	name, err := util.Redis.Get(key).Result()
+	if err != nil {
+		dict := &dao.Dict{Code: ModuleType, DictKey: strconv.Itoa(id)}
+		if err := dict.GetByCodeAndKey(); err != nil {
+			fmt.Printf("GetByCodeAndKey err = %d \n", err)
+		} else {
+			name = dict.DictValue
+			util.Redis.Set(key, name, -1)
+		}
+	}
+	return name
+}
+
+func (s *dictService) GetSexName(tenantId int, id int) string {
+	var name string
+	key := fmt.Sprintf(SexNameKey, tenantId, id)
+	name, err := util.Redis.Get(key).Result()
+	if err != nil {
+		dict := &dao.Dict{Code: Sex, DictKey: strconv.Itoa(id)}
+		if err := dict.GetByCodeAndKey(); err != nil {
+			fmt.Printf("GetByCodeAndKey err = %d \n", err)
+		} else {
+			name = dict.DictValue
+			util.Redis.Set(key, name, -1)
+		}
+	}
+	return name
+}

+ 19 - 0
app/system/service/roleService.go

@@ -1,6 +1,7 @@
 package service
 
 import (
+	"fmt"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/app/system/model"
 	"iot_manager_service/util"
@@ -153,3 +154,21 @@ func (s *roleService) Grant(req *model.ReqRoleGrant) error {
 	menuErr := RoleMenuService.UpdateRoleMenus(roleIds, menuIds)
 	return menuErr
 }
+
+const RoleNameKey = "%d:sys:role_name:%d"
+
+func (s *roleService) GetRoleName(tenantId int, roleId int64) string {
+	var name string
+	key := fmt.Sprintf(RoleNameKey, tenantId, roleId)
+	name, err := util.Redis.Get(key).Result()
+	if err != nil {
+		role := &dao.Role{ID: roleId}
+		if err := role.GetRole(); err != nil {
+			fmt.Printf("GetRole err = %s \n", err)
+		} else {
+			name = role.RoleName
+			util.Redis.Set(key, name, -1)
+		}
+	}
+	return name
+}

+ 19 - 0
app/system/service/tenantService.go

@@ -1,6 +1,7 @@
 package service
 
 import (
+	"fmt"
 	"iot_manager_service/app/system/dao"
 	"iot_manager_service/util"
 	"time"
@@ -118,3 +119,21 @@ func (s *tenantService) Remove(id int64) *util.Errors {
 	}
 	return nil
 }
+
+const TenantNameKey = "%d:sys:tenant_name:%d"
+
+func (s *tenantService) GetTenantName(tenantId int, id int) string {
+	var name string
+	key := fmt.Sprintf(TenantNameKey, tenantId, id)
+	name, err := util.Redis.Get(key).Result()
+	if err != nil {
+		tenant := &dao.Tenant{TenantId: id}
+		if err := tenant.GetTenant(); err != nil {
+			fmt.Printf("GetTenant err = %s \n", err)
+		} else {
+			name = tenant.TenantName
+			util.Redis.Set(key, name, -1)
+		}
+	}
+	return name
+}

+ 24 - 6
app/system/service/userService.go

@@ -25,9 +25,9 @@ func (s *userService) Get(id int64) (*model.UserDetail, error) {
 	}
 	detail := &model.UserDetail{
 		User:       *user,
-		TenantName: util.GetTenantName(user.TenantId, user.TenantId),
-		RoleName:   util.GetRoleName(user.TenantId, user.RoleId),
-		SexName:    util.GetSexName(user.TenantId, user.Sex),
+		TenantName: TenantService.GetTenantName(user.TenantId, user.TenantId),
+		RoleName:   RoleService.GetRoleName(user.TenantId, user.RoleId),
+		SexName:    DictService.GetSexName(user.TenantId, user.Sex),
 	}
 	return detail, nil
 }
@@ -79,9 +79,9 @@ func (s *userService) List(account, realName string, current, size int) ([]model
 	for _, user := range users {
 		details = append(details, model.UserDetail{
 			User:       user,
-			TenantName: util.GetTenantName(user.TenantId, user.TenantId),
-			RoleName:   util.GetRoleName(user.TenantId, user.RoleId),
-			SexName:    util.GetSexName(user.TenantId, user.Sex),
+			TenantName: TenantService.GetTenantName(user.TenantId, user.TenantId),
+			RoleName:   RoleService.GetRoleName(user.TenantId, user.RoleId),
+			SexName:    DictService.GetSexName(user.TenantId, user.Sex),
 		})
 	}
 	return details, nil
@@ -141,3 +141,21 @@ func (s *userService) Grant(userIds []string, roleIds string) error {
 	user := &dao.User{}
 	return user.UpdateRoles(userIds, roleIds)
 }
+
+const UserKey = "%d:sys:user:%d"
+
+func (s *userService) GetUserName(tenantId int, id int64) string {
+	var name string
+	key := fmt.Sprintf(UserKey, tenantId, id)
+	name, err := util.Redis.Get(key).Result()
+	if err != nil {
+		user := &dao.User{ID: id}
+		if err := user.GetUser(); err != nil {
+			fmt.Printf("GetUser err = %s \n", err)
+		} else {
+			name = user.Name
+			util.Redis.Set(key, name, time.Second*10)
+		}
+	}
+	return name
+}

+ 6 - 1
router/router.go

@@ -32,7 +32,7 @@ func InitRouter(engine *gin.Engine) {
 	}
 
 	//公共方法
-	share := device.Group("/api/longchi/share")
+	share := engine.Group("/api/longchi/share")
 	{
 		share.GET("/tenantcode/getTenantCode", controller.Util.GetTenantCode)
 	}
@@ -421,6 +421,11 @@ func InitRouter(engine *gin.Engine) {
 		menu.GET("top-menu", system.Menu.TopMenu)
 		menu.GET("authRoutes", system.Menu.Routes)
 	}
+	//字典
+	dict := engine.Group("/api/blade-system/dict")
+	{
+		dict.GET("/dictionary", system.Dict.Dictionary)
+	}
 
 	//工作台
 	workbench := engine.Group("/api/longchi/report/workbench/")

+ 0 - 109
util/redis.go

@@ -3,10 +3,7 @@ package util
 import (
 	"fmt"
 	"github.com/go-redis/redis"
-	device "iot_manager_service/app/device/dao"
-	system "iot_manager_service/app/system/dao"
 	"iot_manager_service/config"
-	"strconv"
 	"time"
 )
 
@@ -32,115 +29,9 @@ func InitRedis() error {
 }
 
 const (
-	UserKey        = "%d:sys:user:%d"
-	ModuleTypeKey  = "%d:dict:module_type:%d"
-	ControlTypeKey = "%d:dict:control_type:%d"
-	TenantNameKey  = "%d:sys:tenant_name:%d"
-	RoleNameKey    = "%d:sys:role_name:%d"
-	SexNameKey     = "%d:sys:sex_name:%d"
 	DeviceStateKey = "dev_state:%s"
-
-	ControlType = "control_type"
-	ModuleType  = "module_his_type"
-	Sex         = "sex"
 )
 
-func GetUserName(tenantId int, id int64) string {
-	var name string
-	key := fmt.Sprintf(UserKey, tenantId, id)
-	name, err := Redis.Get(key).Result()
-	if err != nil {
-		user := &system.User{ID: id}
-		if err := user.GetUser(); err != nil {
-			fmt.Printf("GetUser err = %s \n", err)
-		} else {
-			name = user.Name
-			Redis.Set(key, name, time.Second*10)
-		}
-	}
-	return name
-}
-
-func GetModuleName(tenantId int, id int) string {
-	var name string
-	key := fmt.Sprintf(ModuleTypeKey, tenantId, id)
-	name, err := Redis.Get(key).Result()
-	if err != nil {
-		dict := &device.Dict{Code: ModuleType, DictKey: strconv.Itoa(id)}
-		if err := dict.GetByCodeAndKey(); err != nil {
-			fmt.Printf("GetByCodeAndKey err = %d \n", err)
-		} else {
-			name = dict.DictValue
-			Redis.Set(key, name, -1)
-		}
-	}
-	return name
-}
-
-func GetControlType(tenantId int, id int) string {
-	var name string
-	key := fmt.Sprintf(ControlTypeKey, tenantId, id)
-	name, err := Redis.Get(key).Result()
-	if err != nil {
-		dict := &device.Dict{Code: ControlType, DictKey: strconv.Itoa(id)}
-		if err := dict.GetByCodeAndKey(); err != nil {
-			fmt.Printf("GetByCodeAndKey err = %d \n", err)
-		} else {
-			name = dict.DictValue
-			Redis.Set(key, name, -1)
-		}
-	}
-	return name
-}
-
-func GetSexName(tenantId int, id int) string {
-	var name string
-	key := fmt.Sprintf(SexNameKey, tenantId, id)
-	name, err := Redis.Get(key).Result()
-	if err != nil {
-		dict := &device.Dict{Code: Sex, DictKey: strconv.Itoa(id)}
-		if err := dict.GetByCodeAndKey(); err != nil {
-			fmt.Printf("GetByCodeAndKey err = %d \n", err)
-		} else {
-			name = dict.DictValue
-			Redis.Set(key, name, -1)
-		}
-	}
-	return name
-}
-
-func GetTenantName(tenantId int, id int) string {
-	var name string
-	key := fmt.Sprintf(TenantNameKey, tenantId, id)
-	name, err := Redis.Get(key).Result()
-	if err != nil {
-		tenant := &system.Tenant{TenantId: id}
-		if err := tenant.GetTenant(); err != nil {
-			fmt.Printf("GetTenant err = %s \n", err)
-		} else {
-			name = tenant.TenantName
-			Redis.Set(key, name, -1)
-		}
-	}
-	return name
-}
-
-func GetRoleName(tenantId int, roleId int64) string {
-	var name string
-	key := fmt.Sprintf(RoleNameKey, tenantId, roleId)
-	name, err := Redis.Get(key).Result()
-	if err != nil {
-		role := &system.Role{ID: roleId}
-		if err := role.GetRole(); err != nil {
-			fmt.Printf("GetRole err = %s \n", err)
-		} else {
-			name = role.RoleName
-			Redis.Set(key, name, -1)
-		}
-	}
-	return name
-}
-
 func GetDeviceState(sn string) int {
 	key := fmt.Sprintf(DeviceStateKey, sn)
 	value, err := Redis.Get(key).Int()