2ed5dfa6a1
iotlcm-app:小程序端 + 用户端服务。 - app/:uni-app 小程序前端(基于 unibest,MIT) - 微信 AppID → YOUR_WX_APPID,uni-app AppID → __UNI__YOURAPPID - 内网后端地址 → admin.iotlcm.example.com - 应用标题与 unibest 模板 README 重写(保留上游致谢与 MIT 声明) - server/:GoFrame 用户端服务(基于 XiuAdmin,Apache-2.0) - module xiuadmin → git.5iot.com/iotlcm-public/iotlcm-app(360 文件) - 支付回调地址 → app.iotlcm.example.com,商户名与应用名泛化 - 真实手机号 → 合法 11 位编造号(保留号段前 3 位 + 后 4 位) - 依赖号码尾部的断言同步更新 - 补 server/LICENSE(Apache-2.0) - 移除内部资产:CI 触发器 - 补根 README,LF 行尾 + .gitattributes 已知:TestSysDept_RefreshDeptAncestors 在源仓同一提交上同样失败,属既有缺陷。
76 lines
2.9 KiB
Go
76 lines
2.9 KiB
Go
// Package mcache
|
|
// @Link https://github.com/xiujiecn/xiu-admin
|
|
// @Copyright Copyright (c) 2025 LiXiujie
|
|
// @Author Lxj <li@xiujie.cn>
|
|
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
|
package mcache
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/event"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service"
|
|
"time"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func init() {
|
|
event.EventsInstance().Register(consts.EventKeyUserLogout, func(ctx context.Context, eventKey string, args ...interface{}) {
|
|
if len(args) == 0 {
|
|
return
|
|
}
|
|
userId := args[0].(int64)
|
|
RemoveUserAccessCodeList(ctx, userId)
|
|
g.Log().Infof(ctx, "mcache_access_list.go EventKeyUserLogout userId: %d", userId)
|
|
})
|
|
|
|
}
|
|
|
|
func GetUserAccessCodeList(ctx context.Context, userId int64) ([]string, []string, error) {
|
|
accessCodeList, err := Instance().Get(ctx, fmt.Sprintf(consts.MemCacheUserAccessCodeList, userId))
|
|
menuRoleDataAccessCodeList, err := Instance().Get(ctx, fmt.Sprintf(consts.MemCacheUserRoleDataAccessCodeList, userId))
|
|
if err != nil || accessCodeList == nil {
|
|
accessCodeCurrList, menuRoleDataAccessCodeList, err := service.SysAuth().GetUserAccessCodeList(ctx, userId)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
accessCodeCurrList = ensureCurrentUserAccessCode(accessCodeCurrList)
|
|
if len(accessCodeCurrList) == 0 {
|
|
accessCodeCurrList = []string{"null"}
|
|
}
|
|
Instance().Set(ctx, fmt.Sprintf(consts.MemCacheUserAccessCodeList, userId), accessCodeCurrList, time.Hour*24)
|
|
Instance().Set(ctx, fmt.Sprintf(consts.MemCacheUserRoleDataAccessCodeList, userId), menuRoleDataAccessCodeList, time.Hour*24)
|
|
return accessCodeCurrList, menuRoleDataAccessCodeList, nil
|
|
}
|
|
return ensureCurrentUserAccessCode(accessCodeList.Strings()), menuRoleDataAccessCodeList.Strings(), nil
|
|
}
|
|
|
|
func ensureCurrentUserAccessCode(accessCodeList []string) []string {
|
|
for _, code := range accessCodeList {
|
|
if code == consts.SysCheckPermissionCurrentUser {
|
|
return accessCodeList
|
|
}
|
|
}
|
|
return append(accessCodeList, consts.SysCheckPermissionCurrentUser)
|
|
}
|
|
|
|
func SetUserAccessCodeList(ctx context.Context, userId int64, accessCodeList []string) error {
|
|
return Instance().Set(ctx, fmt.Sprintf(consts.MemCacheUserAccessCodeList, userId), accessCodeList, time.Hour*24)
|
|
}
|
|
|
|
func SetUserRoleDataAccessCodeList(ctx context.Context, userId int64, roleDataAccessCodeList []string) error {
|
|
return Instance().Set(ctx, fmt.Sprintf(consts.MemCacheUserRoleDataAccessCodeList, userId), roleDataAccessCodeList, time.Hour*24)
|
|
}
|
|
|
|
func RemoveUserRoleDataAccessCodeList(ctx context.Context, userId int64) error {
|
|
_, err := Instance().Remove(ctx, fmt.Sprintf(consts.MemCacheUserRoleDataAccessCodeList, userId))
|
|
return err
|
|
}
|
|
|
|
func RemoveUserAccessCodeList(ctx context.Context, userId int64) error {
|
|
_, err := Instance().Remove(ctx, fmt.Sprintf(consts.MemCacheUserAccessCodeList, userId))
|
|
return err
|
|
}
|