1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.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{
- ret1[v.DeviceCode] = v.DeviceType
- ret2[v.DeviceType] = v.DeviceCode
- }
- }
- codeMap = ret1
- nameMap = ret2
- return ret1, ret2, result.Error
- }
|