123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- package common
- import (
- "math/rand"
- "strconv"
- "strings"
- "time"
- )
- 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
- )
- const (
- DeviceTypeDefault = 0
- DeviceTypeCamera = 100
- DeviceTypeLightControl = 101
- DeviceTypeInfoBoard = 102
- DeviceTypeSwitchBox = 103
- DeviceTypeGateway = 104
- DeviceTypeOptoSensor = 105
- DeviceTypeZigbee = 106
- DeviceTypeAlarmTerminal = 107
- DeviceTypeAlarmServer = 108
- DeviceTypeBridgeSensor = 109
- DeviceTypeBridge = 110
- DeviceTypeIPBroadcast = 111
- DeviceTypeManholeCover = 112
- DeviceTypeGarbage = 113
- DeviceTypeLampPoleGroup = 114
- DeviceTypeLampPole = 115
- DeviceTypeCaptureUnit = 116
- DeviceTypePoint = 117
- DeviceTypeGarbageGroup = 118
- DeviceTypeLightStrategy = 119
- DeviceTypeOnDemandGroup = 120
- DeviceTypeOnDemandSensor = 121
- DeviceTypeTransformer = 122
- )
- var mLocation *time.Location
- func init() {
- loc, err := time.LoadLocation("Asia/Shanghai")
- if err != nil {
- mLocation = time.FixedZone("CST", 8*3600)
- } else {
- mLocation = loc
- }
- }
- func GetDeviceObject(id int, name string) string {
- return strconv.Itoa(id) + "(" + name + ")"
- }
- func StringToInt(id string) int {
- if id != "" {
- id, err := strconv.Atoi(id)
- if err == nil {
- return id
- }
- }
- return -1
- }
- func RandomString(n int) string {
- var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
- rand.Seed(time.Now().Unix())
- b := make([]rune, n)
- for i := range b {
- b[i] = letters[rand.Intn(len(letters))]
- }
- return string(b)
- }
- func RandomString2(n int) string {
- var letters = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
- rand.Seed(time.Now().Unix())
- b := make([]rune, n)
- for i := range b {
- b[i] = letters[rand.Intn(len(letters))]
- }
- return string(b)
- }
- func StringToInt64Array(str string) []int64 {
- tmp := strings.Split(str, ",")
- var result []int64
- for _, t := range tmp {
- i, _ := strconv.ParseInt(t, 10, 64)
- result = append(result, i)
- }
- return result
- }
- func StringToIntArray(str string) []int {
- tmp := strings.Split(str, ",")
- var result []int
- for _, t := range tmp {
- i, _ := strconv.Atoi(t)
- result = append(result, i)
- }
- return result
- }
- func MlParseTime(strTime string) (time.Time, error) {
- if strings.Contains(strTime, ".") {
- return time.ParseInLocation("2006-01-02 15:04:05.000", strTime, mLocation)
- }
- return time.ParseInLocation("2006-01-02 15:04:05", strTime, mLocation)
- }
- func IsAdmin(roleId int64) bool {
- return roleId == 1
- }
|