|
|
@@ -16,14 +16,15 @@ import (
|
|
|
var vUser userName
|
|
|
|
|
|
type userName struct {
|
|
|
- mtx sync.RWMutex //锁
|
|
|
- data map[int64]string //数据[loginId]accountName
|
|
|
+ mtx sync.RWMutex // 锁
|
|
|
+ data map[int64]userData // 数据[loginId]userData
|
|
|
last time.Time
|
|
|
}
|
|
|
|
|
|
type userData struct {
|
|
|
- LOGINID int64 //登录ID
|
|
|
- USERNAME string // 用户名字
|
|
|
+ LOGINID int64 `json:"LOGINID" xorm:"'LOGINID'"` // 登录ID
|
|
|
+ LOGINCODE string `json:"LOGINCODE" xorm:"'LOGINCODE'"` // 登录代码
|
|
|
+ USERNAME string `json:"USERNAME" xorm:"'USERNAME'"` // 用户名字
|
|
|
}
|
|
|
|
|
|
// 加载数据
|
|
|
@@ -41,7 +42,7 @@ func (r *userName) load() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- sqlId := "select l.loginid, s.username" +
|
|
|
+ sqlId := "select l.loginid, l.logincode, s.username" +
|
|
|
" from loginaccount l" +
|
|
|
" left join systemmanager s" +
|
|
|
" on l.logincode = s.logincode" +
|
|
|
@@ -52,15 +53,15 @@ func (r *userName) load() {
|
|
|
if err := s.Find(&sData); err != nil {
|
|
|
logger.GetLogger().Errorf("cache load usrname, %v", err)
|
|
|
} else {
|
|
|
- r.data = make(map[int64]string)
|
|
|
+ r.data = make(map[int64]userData)
|
|
|
for i := range sData {
|
|
|
- r.data[sData[i].LOGINID] = sData[i].USERNAME
|
|
|
+ r.data[sData[i].LOGINID] = sData[i]
|
|
|
}
|
|
|
r.last = time.Now()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (r *userName) get(loginId int64) string {
|
|
|
+func (r *userName) name(loginId int64) string {
|
|
|
r.mtx.RLock()
|
|
|
defer r.mtx.RUnlock()
|
|
|
|
|
|
@@ -69,18 +70,43 @@ func (r *userName) get(loginId int64) string {
|
|
|
}
|
|
|
|
|
|
if v, ok := r.data[loginId]; ok {
|
|
|
- return v
|
|
|
+ return v.USERNAME
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|
|
|
+
|
|
|
+func (r *userName) loginCode(loginId int64) string {
|
|
|
+ r.mtx.RLock()
|
|
|
+ defer r.mtx.RUnlock()
|
|
|
+
|
|
|
+ if r.data == nil {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+
|
|
|
+ if v, ok := r.data[loginId]; ok {
|
|
|
+ return v.LOGINCODE
|
|
|
}
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
// 根据登录ID获取名称
|
|
|
func GetUserNameByLoginId(loginId int64) string {
|
|
|
- if v := vUser.get(loginId); v !=""{
|
|
|
+ if v := vUser.name(loginId); v != "" {
|
|
|
return v
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
vUser.load()
|
|
|
}
|
|
|
|
|
|
- return vUser.get(loginId)
|
|
|
-}
|
|
|
+ return vUser.name(loginId)
|
|
|
+}
|
|
|
+
|
|
|
+// 根据登录ID获取登录代码
|
|
|
+func GetLoginCodeByLoginId(loginId int64) string {
|
|
|
+ if v := vUser.loginCode(loginId); v != "" {
|
|
|
+ return v
|
|
|
+ } else {
|
|
|
+ vUser.load()
|
|
|
+ }
|
|
|
+
|
|
|
+ return vUser.loginCode(loginId)
|
|
|
+}
|