123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- // Copyright 2019 githup.com. All rights reserved.
- // Use of this source code is governed by githup.com.
- package model
- import (
- "github.com/jinzhu/gorm"
- "sync"
- )
- type TDeviceTypeItem struct {
- ID int64 `gorm:"column:ID" json:"id" form:"id"`
- DeviceType string `gorm:"column:DeviceType" json:"device_type" form:"device_type"`
- DeviceCode int32 `gorm:"column:DeviceCode" json:"device_code" form:"device_code"`
- }
- func (TDeviceTypeItem) TableName() string {
- return "DeviceTypeItem"
- }
- var codeMap = map[int32]string{}
- var nameMap = map[string]int32{}
- var mux sync.Mutex
- func (p *TDeviceTypeItem) AllMap(db *gorm.DB) (map[int32]string, map[string]int32, error) {
- mux.Lock()
- defer mux.Unlock()
- if len(codeMap) > 0 && len(nameMap) > 0 {
- return codeMap, nameMap, nil
- }
- list := []TDeviceTypeItem{}
- result := db.Table(p.TableName()).Find(&list)
- ret1 := map[int32]string{}
- ret2 := map[string]int32{}
- for _, v := range list {
- if v.DeviceCode == DeviceTypeDust ||
- v.DeviceCode == DeviceTypeVedio ||
- v.DeviceCode == DeviceTypeAttendance ||
- v.DeviceCode == DeviceTypeTower ||
- v.DeviceCode == DeviceTypeLift {
- ret1[v.DeviceCode] = v.DeviceType
- ret2[v.DeviceType] = v.DeviceCode
- }
- }
- codeMap = ret1
- nameMap = ret2
- return ret1, ret2, result.Error
- }
|