This commit is contained in:
2026-03-18 10:19:42 +08:00
parent 2526ad4414
commit e58dd3529d
267 changed files with 25279 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
/*
* @desc:缓存键
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/9 12:06
*/
package consts
import commonConsts "github.com/tiger1103/gfast/v3/internal/app/common/consts"
const (
// CacheSysAuthMenu 缓存菜单key
CacheSysAuthMenu = commonConsts.CachePrefix + "sysAuthMenu"
// CacheSysDept 缓存部门key
CacheSysDept = commonConsts.CachePrefix + "sysDept"
// CacheSysRole 角色缓存key
CacheSysRole = commonConsts.CachePrefix + "sysRole"
// CacheSysWebSet 站点配置缓存key
CacheSysWebSet = commonConsts.CachePrefix + "sysWebSet"
// CacheSysCmsMenu cms缓存key
CacheSysCmsMenu = commonConsts.CachePrefix + "sysCmsMenu"
// CacheSysAuthTag 权限缓存TAG标签
CacheSysAuthTag = commonConsts.CachePrefix + "sysAuthTag"
// CacheSysModelTag 模型缓存标签
CacheSysModelTag = commonConsts.CachePrefix + "sysModelTag"
// CacheSysCmsTag cms缓存标签
CacheSysCmsTag = commonConsts.CachePrefix + "sysCmsTag"
)

View File

@@ -0,0 +1,5 @@
package consts
const (
PageSize = 10 //分页长度
)

View File

@@ -0,0 +1,13 @@
/*
* @desc:context 相关常量
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/3/16 14:52
*/
package consts
const (
// CtxKey 上下文变量存储键名,前后端系统共享
CtxKey = "GFastContext"
)

View File

@@ -0,0 +1,7 @@
package consts
const (
SuperAdminId = 1 // 超级管理员
SalesAgentId = 9 // 销售代理
SiteAdminId = 10 // 站点管理员
)

View File

@@ -0,0 +1,45 @@
package consts
type TenantType int
const (
TenantTypeSite TenantType = 1 // 站点
TenantTypeAgent TenantType = 2 // 代理
)
type CertificationStatus int
const (
CertificationStatusPending CertificationStatus = 1 // 待审核
CertificationStatusPass CertificationStatus = 2 // 审核通过
CertificationStatusFail CertificationStatus = 3 // 审核失败
CertificationStatusUnverified CertificationStatus = 4 // 未认证
)
type CertificationStatusKeyValue struct {
Key CertificationStatus // 对应原有常量值
Value string // 对应描述信息
}
// 定义枚举实例Key-Value 绑定),相当于改造后的常量
var (
CertificationStatusPendingKeyValue = CertificationStatusKeyValue{Key: CertificationStatusPending, Value: "待审核"}
CertificationStatusPassKeyValue = CertificationStatusKeyValue{Key: CertificationStatusPass, Value: "审核通过"}
CertificationStatusFailKeyValue = CertificationStatusKeyValue{Key: CertificationStatusFail, Value: "审核失败"}
CertificationStatusUnverifiedKeyValue = CertificationStatusKeyValue{Key: CertificationStatusUnverified, Value: "未认证"}
)
var certificationStatusMap = map[CertificationStatus]CertificationStatusKeyValue{
CertificationStatusPending: CertificationStatusPendingKeyValue,
CertificationStatusPass: CertificationStatusPassKeyValue,
CertificationStatusFail: CertificationStatusFailKeyValue,
CertificationStatusUnverified: CertificationStatusUnverifiedKeyValue,
}
// GetCertificationStatusKeyValue 根据 CertificationStatus 指针获取对应的 KeyValue
func GetCertificationStatusKeyValue(status CertificationStatus) CertificationStatusKeyValue {
if kv, ok := certificationStatusMap[status]; ok {
return kv
}
return CertificationStatusUnverifiedKeyValue
}

View File

@@ -0,0 +1,22 @@
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var (
AreaDict = areaDictController{}
)
type areaDictController struct {
BaseController
}
// List 用户列表
func (c *areaDictController) List(ctx context.Context, req *system.AreaDictListReq) (res *system.AreaDictListRes, err error) {
res, err = service.AreaDict().GetAreaDictListSearch(ctx, req)
return
}

View File

@@ -0,0 +1,22 @@
/*
* @desc:system base controller
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/4 18:12
*/
package controller
import (
"github.com/gogf/gf/v2/net/ghttp"
commonController "github.com/tiger1103/gfast/v3/internal/app/common/controller"
)
type BaseController struct {
commonController.BaseController
}
// Init 自动执行的初始化方法
func (c *BaseController) Init(r *ghttp.Request) {
c.BaseController.Init(r)
}

View File

@@ -0,0 +1,61 @@
/*
* @desc:缓存处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2023/2/1 18:14
*/
package controller
import (
"context"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonConsts "github.com/tiger1103/gfast/v3/internal/app/common/consts"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
)
var Cache = new(cacheController)
type cacheController struct {
BaseController
}
func (c *cacheController) Remove(ctx context.Context, req *system.CacheRemoveReq) (res *system.CacheRemoveRes, err error) {
service.Cache().RemoveByTag(ctx, commonConsts.CacheSysDictTag)
service.Cache().RemoveByTag(ctx, commonConsts.CacheSysConfigTag)
service.Cache().RemoveByTag(ctx, consts.CacheSysAuthTag)
cacheRedis := g.Cfg().MustGet(ctx, "system.cache.model").String()
if cacheRedis == commonConsts.CacheModelRedis {
cursor := 0
cachePrefix := g.Cfg().MustGet(ctx, "system.cache.prefix").String()
cachePrefix += commonConsts.CachePrefix
for {
var v *gvar.Var
v, err = g.Redis().Do(ctx, "scan", cursor, "match", cachePrefix+"*", "count", "100")
if err != nil {
return
}
data := gconv.SliceAny(v)
var dataSlice []string
err = gconv.Structs(data[1], &dataSlice)
if err != nil {
return
}
for _, d := range dataSlice {
_, err = g.Redis().Do(ctx, "del", d)
if err != nil {
return
}
}
cursor = gconv.Int(data[0])
if cursor == 0 {
break
}
}
}
return
}

View File

@@ -0,0 +1,27 @@
/*
* @desc:模块租户关系控制器
* @company:云南奇讯科技有限公司
* @Author: system
* @Date: 2026/1/6
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var ModuleTenant = moduleTenantController{}
type moduleTenantController struct {
BaseController
}
// Add 添加模块租户关系
func (c *moduleTenantController) Add(ctx context.Context, req *system.ModuleTenantAddReq) (res *system.ModuleTenantAddRes, err error) {
err = service.ModuleTenant().Add(ctx, req)
return
}

View File

@@ -0,0 +1,50 @@
/*
* @desc:xxxx功能描述
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/11/3 10:32
*/
package controller
import (
"context"
"github.com/gogf/gf/v2/crypto/gmd5"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/libUtils"
)
var Personal = new(personalController)
type personalController struct {
}
func (c *personalController) GetPersonal(ctx context.Context, req *system.PersonalInfoReq) (res *system.PersonalInfoRes, err error) {
res, err = service.Personal().GetPersonalInfo(ctx, req)
return
}
func (c *personalController) EditPersonal(ctx context.Context, req *system.PersonalEditReq) (res *system.PersonalEditRes, err error) {
ip := libUtils.GetClientIp(ctx)
userAgent := libUtils.GetUserAgent(ctx)
res = new(system.PersonalEditRes)
res.UserInfo, err = service.Personal().EditPersonal(ctx, req)
if err != nil {
return
}
key := gconv.String(res.UserInfo.Id) + "-" + gmd5.MustEncryptString(res.UserInfo.UserName) + gmd5.MustEncryptString(res.UserInfo.UserPassword)
if g.Cfg().MustGet(ctx, "gfToken.multiLogin").Bool() {
key = gconv.String(res.UserInfo.Id) + "-" + gmd5.MustEncryptString(res.UserInfo.UserName) + gmd5.MustEncryptString(res.UserInfo.UserPassword+ip+userAgent)
}
res.UserInfo.UserPassword = ""
res.Token, err = service.GfToken().GenerateToken(ctx, key, res.UserInfo)
return
}
func (c *personalController) ResetPwdPersonal(ctx context.Context, req *system.PersonalResetPwdReq) (res *system.PersonalResetPwdRes, err error) {
res, err = service.Personal().ResetPwdPersonal(ctx, req)
return
}

View File

@@ -0,0 +1,79 @@
/*
* @desc:菜单
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/16 10:36
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var Menu = menuController{}
type menuController struct {
BaseController
}
func (c *menuController) List(ctx context.Context, req *system.RuleSearchReq) (res *system.RuleListRes, err error) {
var list []*model.SysAuthRuleInfoRes
res = &system.RuleListRes{
Rules: make([]*model.SysAuthRuleTreeRes, 0),
}
list, err = service.SysAuthRule().GetMenuListSearch(ctx, req)
if req.Title != "" || req.Component != "" {
for _, menu := range list {
res.Rules = append(res.Rules, &model.SysAuthRuleTreeRes{
SysAuthRuleInfoRes: menu,
})
}
} else {
res.Rules = service.SysAuthRule().GetMenuListTree(0, list)
}
return
}
func (c *menuController) Add(ctx context.Context, req *system.RuleAddReq) (res *system.RuleAddRes, err error) {
err = service.SysAuthRule().Add(ctx, req)
return
}
// GetAddParams 获取菜单添加及编辑相关参数
func (c *menuController) GetAddParams(ctx context.Context, req *system.RuleGetParamsReq) (res *system.RuleGetParamsRes, err error) {
// 获取角色列表
res = new(system.RuleGetParamsRes)
res.Roles, err = service.SysRole().GetRoleList(ctx)
if err != nil {
return
}
res.Menus, err = service.SysAuthRule().GetIsMenuList(ctx)
return
}
// Get 获取菜单信息
func (c *menuController) Get(ctx context.Context, req *system.RuleInfoReq) (res *system.RuleInfoRes, err error) {
res = new(system.RuleInfoRes)
res.Rule, err = service.SysAuthRule().Get(ctx, req.Id)
if err != nil {
return
}
res.RoleIds, err = service.SysAuthRule().GetMenuRoles(ctx, req.Id)
return
}
// Update 菜单修改
func (c *menuController) Update(ctx context.Context, req *system.RuleUpdateReq) (res *system.RuleUpdateRes, err error) {
err = service.SysAuthRule().Update(ctx, req)
return
}
// Delete 删除菜单
func (c *menuController) Delete(ctx context.Context, req *system.RuleDeleteReq) (res *system.RuleDeleteRes, err error) {
err = service.SysAuthRule().DeleteMenuByIds(ctx, req.Ids)
return
}

View File

@@ -0,0 +1,51 @@
/*
* @desc:系统参数配置
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/4/18 21:17
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var Config = configController{}
type configController struct {
BaseController
}
// List 系统参数列表
func (c *configController) List(ctx context.Context, req *system.ConfigSearchReq) (res *system.ConfigSearchRes, err error) {
res, err = commonService.SysConfig().List(ctx, req)
return
}
// Add 添加系统参数
func (c *configController) Add(ctx context.Context, req *system.ConfigAddReq) (res *system.ConfigAddRes, err error) {
err = commonService.SysConfig().Add(ctx, req, service.Context().GetUserId(ctx))
return
}
// Get 获取系统参数
func (c *configController) Get(ctx context.Context, req *system.ConfigGetReq) (res *system.ConfigGetRes, err error) {
res, err = commonService.SysConfig().Get(ctx, req.Id)
return
}
// Edit 修改系统参数
func (c *configController) Edit(ctx context.Context, req *system.ConfigEditReq) (res *system.ConfigEditRes, err error) {
err = commonService.SysConfig().Edit(ctx, req, service.Context().GetUserId(ctx))
return
}
// Delete 删除系统参数
func (c *configController) Delete(ctx context.Context, req *system.ConfigDeleteReq) (res *system.ConfigDeleteRes, err error) {
err = commonService.SysConfig().Delete(ctx, req.Ids)
return
}

View File

@@ -0,0 +1,60 @@
/*
* @desc:部门管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/4/6 15:15
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var Dept = sysDeptController{}
type sysDeptController struct {
BaseController
}
// List 部门列表
func (c *sysDeptController) List(ctx context.Context, req *system.DeptSearchReq) (res *system.DeptSearchRes, err error) {
res = new(system.DeptSearchRes)
res.DeptList, err = service.SysDept().GetList(ctx, req)
return
}
// Add 添加部门
func (c *sysDeptController) Add(ctx context.Context, req *system.DeptAddReq) (res *system.DeptAddRes, err error) {
_, err = service.SysDept().Add(ctx, req)
return
}
// Edit 修改部门
func (c *sysDeptController) Edit(ctx context.Context, req *system.DeptEditReq) (res *system.DeptEditRes, err error) {
err = service.SysDept().Edit(ctx, req)
return
}
// Delete 删除部门
func (c *sysDeptController) Delete(ctx context.Context, req *system.DeptDeleteReq) (res *system.DeptDeleteRes, err error) {
err = service.SysDept().Delete(ctx, req.Id)
return
}
// TreeSelect 获取部门数据结构数据
func (c *sysDeptController) TreeSelect(ctx context.Context, req *system.DeptTreeSelectReq) (res *system.DeptTreeSelectRes, err error) {
var deptList []*entity.SysDept
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{
Status: "1", //正常状态数据
})
if err != nil {
return
}
res = new(system.DeptTreeSelectRes)
res.Deps = service.SysDept().GetListTree(0, deptList)
return
}

View File

@@ -0,0 +1,61 @@
/*
* @desc:字典数据管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/3/18 11:57
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var DictData = dictDataController{}
type dictDataController struct {
}
// GetDictDataTree 根据remark获取字典数据树形结构
func (c *dictDataController) GetDictDataTree(ctx context.Context, req *system.GetDictTreeReq) (res *system.GetDictTreeRes, err error) {
res, err = commonService.SysDictData().GetDictDataTree(ctx, req.Remark)
return
}
// GetDictData 获取字典数据
func (c *dictDataController) GetDictData(ctx context.Context, req *system.GetDictReq) (res *system.GetDictRes, err error) {
res, err = commonService.SysDictData().GetDictWithDataByType(ctx, req)
return
}
// List 获取字典数据列表
func (c *dictDataController) List(ctx context.Context, req *system.DictDataSearchReq) (res *system.DictDataSearchRes, err error) {
res, err = commonService.SysDictData().List(ctx, req)
return
}
// Add 添加字典数据
func (c *dictDataController) Add(ctx context.Context, req *system.DictDataAddReq) (res *system.DictDataAddRes, err error) {
err = commonService.SysDictData().Add(ctx, req, service.Context().GetUserId(ctx))
return
}
// Get 获取对应的字典数据
func (c *dictDataController) Get(ctx context.Context, req *system.DictDataGetReq) (res *system.DictDataGetRes, err error) {
res, err = commonService.SysDictData().Get(ctx, req.DictCode)
return
}
// Edit 修改字典数据
func (c *dictDataController) Edit(ctx context.Context, req *system.DictDataEditReq) (res *system.DictDataEditRes, err error) {
err = commonService.SysDictData().Edit(ctx, req, service.Context().GetUserId(ctx))
return
}
func (c *dictDataController) Delete(ctx context.Context, req *system.DictDataDeleteReq) (res *system.DictDataDeleteRes, err error) {
err = commonService.SysDictData().Delete(ctx, req.Ids)
return
}

View File

@@ -0,0 +1,57 @@
/*
* @desc:字典类型
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/3/18 11:57
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var DictType = &SysDictTypeController{}
type SysDictTypeController struct {
}
// List 字典类型列表
func (c *SysDictTypeController) List(ctx context.Context, req *system.DictTypeSearchReq) (res *system.DictTypeSearchRes, err error) {
res, err = commonService.SysDictType().List(ctx, req)
return
}
// Add 添加字典类型
func (c *SysDictTypeController) Add(ctx context.Context, req *system.DictTypeAddReq) (res *system.DictTypeAddRes, err error) {
err = commonService.SysDictType().Add(ctx, req, service.Context().GetUserId(ctx))
return
}
// Get 获取字典类型
func (c *SysDictTypeController) Get(ctx context.Context, req *system.DictTypeGetReq) (res *system.DictTypeGetRes, err error) {
res = new(system.DictTypeGetRes)
res.DictType, err = commonService.SysDictType().Get(ctx, req)
return
}
// Edit 修改字典数据
func (c *SysDictTypeController) Edit(ctx context.Context, req *system.DictTypeEditReq) (res *system.DictTypeEditRes, err error) {
err = commonService.SysDictType().Edit(ctx, req, service.Context().GetUserId(ctx))
return
}
func (c *SysDictTypeController) Delete(ctx context.Context, req *system.DictTypeDeleteReq) (res *system.DictTypeDeleteRes, err error) {
err = commonService.SysDictType().Delete(ctx, req.DictIds)
return
}
// OptionSelect 获取字典选择框列表
func (c *SysDictTypeController) OptionSelect(ctx context.Context, req *system.DictTypeAllReq) (res *system.DictTYpeAllRes, err error) {
res = new(system.DictTYpeAllRes)
res.DictType, err = commonService.SysDictType().GetAllDictType(ctx)
return
}

View File

@@ -0,0 +1,119 @@
/*
* @desc:登录
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/4/27 21:52
*/
package controller
import (
"context"
"github.com/gogf/gf/v2/crypto/gmd5"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gmode"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/libUtils"
)
var (
Login = loginController{}
)
type loginController struct {
BaseController
}
func (c *loginController) Login(ctx context.Context, req *system.UserLoginReq) (res *system.UserLoginRes, err error) {
var (
user *model.LoginUserRes
token string
permissions []string
menuList []*model.UserMenus
)
//判断验证码是否正确
debug := gmode.IsDevelop()
if !debug {
if !commonService.Captcha().VerifyString(req.VerifyKey, req.VerifyCode) {
err = gerror.New("验证码输入错误")
return
}
}
ip := libUtils.GetClientIp(ctx)
userAgent := libUtils.GetUserAgent(ctx)
user, err = service.SysUser().GetAdminUserByUsernamePassword(ctx, req)
if err != nil {
// 保存登录失败的日志信息
service.SysLoginLog().Invoke(gctx.New(), &model.LoginLogParams{
Status: 0,
Username: req.Username,
Ip: ip,
UserAgent: userAgent,
Msg: err.Error(),
Module: "系统后台",
})
return
}
err = service.SysUser().UpdateLoginInfo(ctx, user.Id, ip)
if err != nil {
return
}
// 报存登录成功的日志信息
service.SysLoginLog().Invoke(gctx.New(), &model.LoginLogParams{
Status: 1,
Username: req.Username,
Ip: ip,
UserAgent: userAgent,
Msg: "登录成功",
Module: "系统后台",
})
key := gconv.String(user.Id) + "-" + gmd5.MustEncryptString(user.UserName) + gmd5.MustEncryptString(user.UserPassword)
if g.Cfg().MustGet(ctx, "gfToken.multiLogin").Bool() {
key = gconv.String(user.Id) + "-" + gmd5.MustEncryptString(user.UserName) + gmd5.MustEncryptString(user.UserPassword+ip+userAgent)
}
user.UserPassword = ""
token, err = service.GfToken().GenerateToken(ctx, key, user)
g.Log().Debugf(ctx, "==========================key:%v;user:%v;token:%v==========================", key, user, token)
if err != nil {
g.Log().Error(ctx, err)
err = gerror.New("登录失败,后端服务出现错误")
return
}
_, err = service.ModuleTenant().AddRedisByTenantId(ctx, &system.AddRedisByTenantIdReq{TenantId: user.TenantId})
if err != nil {
return
}
//获取用户菜单数据
menuList, permissions, err = service.SysUser().GetAdminRules(ctx, user.Id)
if err != nil {
return
}
res = &system.UserLoginRes{
UserInfo: user,
Token: token,
MenuList: menuList,
Permissions: permissions,
}
//用户在线状态保存
service.SysUserOnline().Invoke(gctx.New(), &model.SysUserOnlineParams{
UserAgent: userAgent,
Uuid: gmd5.MustEncrypt(token),
Token: token,
Username: user.UserName,
Ip: ip,
})
return
}
// LoginOut 退出登录
func (c *loginController) LoginOut(ctx context.Context, req *system.UserLoginOutReq) (res *system.UserLoginOutRes, err error) {
err = service.GfToken().RemoveToken(ctx, service.GfToken().GetRequestToken(g.RequestFromCtx(ctx)))
return
}

View File

@@ -0,0 +1,35 @@
/*
* @desc:登录日志管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/4/24 22:14
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var LoginLog = loginLogController{}
type loginLogController struct {
BaseController
}
func (c *loginLogController) List(ctx context.Context, req *system.LoginLogSearchReq) (res *system.LoginLogSearchRes, err error) {
res, err = service.SysLoginLog().List(ctx, req)
return
}
func (c *loginLogController) Delete(ctx context.Context, req *system.LoginLogDelReq) (res *system.LoginLogDelRes, err error) {
err = service.SysLoginLog().DeleteLoginLogByIds(ctx, req.Ids)
return
}
func (c *loginLogController) Clear(ctx context.Context, req *system.LoginLogClearReq) (res *system.LoginLogClearRes, err error) {
err = service.SysLoginLog().ClearLoginLog(ctx)
return
}

View File

@@ -0,0 +1,147 @@
package controller
import (
"context"
"fmt"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/disk"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/load"
"github.com/shirou/gopsutil/v3/mem"
"github.com/shirou/gopsutil/v3/process"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/library/libUtils"
"os"
"runtime"
"strconv"
"time"
)
var Monitor = sysMonitorController{
startTime: gtime.Now(),
}
type sysMonitorController struct {
BaseController
startTime *gtime.Time
}
func (c *sysMonitorController) List(ctx context.Context, req *system.MonitorSearchReq) (res *system.MonitorSearchRes, err error) {
cpuNum := runtime.NumCPU() //核心数
var cpuUsed float64 = 0 //用户使用率
var cpuAvg5 float64 = 0 //CPU负载5
var cpuAvg15 float64 = 0 //当前空闲率
cpuInfo, err := cpu.Percent(time.Duration(time.Second), false)
if err == nil {
cpuUsed, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cpuInfo[0]), 64)
}
loadInfo, err := load.Avg()
if err == nil {
cpuAvg5, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", loadInfo.Load5), 64)
cpuAvg15, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", loadInfo.Load5), 64)
}
var memTotal uint64 = 0 //总内存
var memUsed uint64 = 0 //总内存 := 0 //已用内存
var memFree uint64 = 0 //剩余内存
var memUsage float64 = 0 //使用率
v, err := mem.VirtualMemory()
if err == nil {
memTotal = v.Total
memUsed = v.Used
memFree = memTotal - memUsed
memUsage, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", v.UsedPercent), 64)
}
var goTotal uint64 = 0 //go分配的总内存数
var goUsed uint64 = 0 //go使用的内存数
var goFree uint64 = 0 //go剩余的内存数
var goUsage float64 = 0 //使用率
p, err := process.NewProcess(int32(os.Getpid()))
if err == nil {
memInfo, err := p.MemoryInfo()
if err == nil {
goUsed = memInfo.RSS
goUsage = gconv.Float64(fmt.Sprintf("%.2f", gconv.Float64(goUsed)/gconv.Float64(memTotal)*100))
}
}
sysComputerIp := "" //服务器IP
ip, err := libUtils.GetLocalIP()
if err == nil {
sysComputerIp = ip
}
sysComputerName := "" //服务器名称
sysOsName := "" //操作系统
sysOsArch := "" //系统架构
sysInfo, err := host.Info()
if err == nil {
sysComputerName = sysInfo.Hostname
sysOsName = sysInfo.OS
sysOsArch = sysInfo.KernelArch
}
goName := "GoLang" //语言环境
goVersion := runtime.Version() //版本
gtime.Date()
goStartTime := c.startTime //启动时间
goRunTime := gtime.Now().Timestamp() - c.startTime.Timestamp() //运行时长(秒)
goHome := runtime.GOROOT() //安装路径
goUserDir := "" //项目路径
curDir, err := os.Getwd()
if err == nil {
goUserDir = curDir
}
//服务器磁盘信息
diskList := make([]disk.UsageStat, 0)
diskInfo, err := disk.Partitions(true) //所有分区
if err == nil {
for _, p := range diskInfo {
diskDetail, err := disk.Usage(p.Mountpoint)
if err == nil {
diskDetail.UsedPercent, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", diskDetail.UsedPercent), 64)
diskList = append(diskList, *diskDetail)
}
}
}
res = new(system.MonitorSearchRes)
res = &system.MonitorSearchRes{
"cpuNum": cpuNum,
"cpuUsed": cpuUsed,
"cpuAvg5": gconv.String(cpuAvg5),
"cpuAvg15": gconv.String(cpuAvg15),
"memTotal": memTotal,
"goTotal": goTotal,
"memUsed": memUsed,
"goUsed": goUsed,
"memFree": memFree,
"goFree": goFree,
"memUsage": memUsage,
"goUsage": goUsage,
"sysComputerName": sysComputerName,
"sysOsName": sysOsName,
"sysComputerIp": sysComputerIp,
"sysOsArch": sysOsArch,
"goName": goName,
"goVersion": goVersion,
"goStartTime": goStartTime,
"goRunTime": goRunTime,
"goHome": goHome,
"goUserDir": goUserDir,
"diskList": diskList,
}
return
}

View File

@@ -0,0 +1,43 @@
/*
* @desc:系统后台操作日志
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/21 16:10
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var OperLog = new(operateLogController)
type operateLogController struct {
BaseController
}
// List 列表
func (c *operateLogController) List(ctx context.Context, req *system.SysOperLogSearchReq) (res *system.SysOperLogSearchRes, err error) {
res, err = service.OperateLog().List(ctx, req)
return
}
// Get 获取操作日志
func (c *operateLogController) Get(ctx context.Context, req *system.SysOperLogGetReq) (res *system.SysOperLogGetRes, err error) {
res = new(system.SysOperLogGetRes)
res.SysOperLogInfoRes, err = service.OperateLog().GetByOperId(ctx, req.OperId)
return
}
func (c *operateLogController) Delete(ctx context.Context, req *system.SysOperLogDeleteReq) (res *system.SysOperLogDeleteRes, err error) {
err = service.OperateLog().DeleteByIds(ctx, req.OperIds)
return
}
func (c *operateLogController) Clear(ctx context.Context, req *system.SysOperLogClearReq) (res *system.SysOperLogClearRes, err error) {
err = service.OperateLog().ClearLog(ctx)
return
}

View File

@@ -0,0 +1,44 @@
/*
* @desc:岗位管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/4/7 23:12
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var Post = postController{}
type postController struct {
BaseController
}
// List 岗位列表
func (c *postController) List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error) {
res, err = service.SysPost().List(ctx, req)
return
}
// Add 添加岗位
func (c *postController) Add(ctx context.Context, req *system.PostAddReq) (res *system.PostAddRes, err error) {
err = service.SysPost().Add(ctx, req)
return
}
// Edit 修改岗位
func (c *postController) Edit(ctx context.Context, req *system.PostEditReq) (res *system.PostEditRes, err error) {
err = service.SysPost().Edit(ctx, req)
return
}
// Delete 删除岗位
func (c *postController) Delete(ctx context.Context, req *system.PostDeleteReq) (res *system.PostDeleteRes, err error) {
err = service.SysPost().Delete(ctx, req.Ids)
return
}

View File

@@ -0,0 +1,69 @@
/*
* @desc:角色管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/3/30 9:08
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var Role = roleController{}
type roleController struct {
BaseController
}
// List 角色列表
func (c *roleController) List(ctx context.Context, req *system.RoleListReq) (res *system.RoleListRes, err error) {
res, err = service.SysRole().GetRoleListSearch(ctx, req)
return
}
// GetParams 获取角色表单参数
func (c *roleController) GetParams(ctx context.Context, req *system.RoleGetParamsReq) (res *system.RoleGetParamsRes, err error) {
res = new(system.RoleGetParamsRes)
res.Menu, err = service.SysAuthRule().GetMenuList(ctx)
return
}
// GetParamsInfo 获取角色表单参数信息
func (c *roleController) GetParamsInfo(ctx context.Context, req *system.RoleGetParamsInfoReq) (res *system.RoleGetParamsRes, err error) {
res = new(system.RoleGetParamsRes)
res.Menu, err = service.SysAuthRule().GetMenuListByRole(ctx)
return
}
// Add 添加角色信息
func (c *roleController) Add(ctx context.Context, req *system.RoleAddReq) (res *system.RoleAddRes, err error) {
err = service.SysRole().AddRole(ctx, req)
return
}
// Get 获取角色信息
func (c *roleController) Get(ctx context.Context, req *system.RoleGetReq) (res *system.RoleGetRes, err error) {
res = new(system.RoleGetRes)
res.Role, err = service.SysRole().Get(ctx, req.Id)
if err != nil {
return
}
res.MenuIds, err = service.SysRole().GetFilteredNamedPolicy(ctx, req.Id)
return
}
// Edit 修改角色信息
func (c *roleController) Edit(ctx context.Context, req *system.RoleEditReq) (res *system.RoleEditRes, err error) {
err = service.SysRole().EditRole(ctx, req)
return
}
// Delete 删除角色
func (c *roleController) Delete(ctx context.Context, req *system.RoleDeleteReq) (res *system.RoleDeleteRes, err error) {
err = service.SysRole().DeleteByIds(ctx, req.Ids)
return
}

View File

@@ -0,0 +1,137 @@
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var (
User = userController{}
)
type userController struct {
BaseController
}
// GetUserMenus 获取用户菜单及按钮权限
func (c *userController) GetUserMenus(ctx context.Context, req *system.UserMenusReq) (res *system.UserMenusRes, err error) {
var (
permissions []string
menuList []*model.UserMenus
)
userId := service.Context().GetUserId(ctx)
menuList, permissions, err = service.SysUser().GetAdminRules(ctx, userId)
res = &system.UserMenusRes{
MenuList: menuList,
Permissions: permissions,
}
return
}
// List 用户列表
func (c *userController) List(ctx context.Context, req *system.UserSearchReq) (res *system.UserSearchRes, err error) {
var (
total interface{}
userList []*entity.SysUser
)
res = new(system.UserSearchRes)
total, userList, err = service.SysUser().List(ctx, req)
if err != nil || total == 0 {
return
}
res.Total = total
res.UserList, err = service.SysUser().GetUsersRoleDept(ctx, userList)
return
}
// GetList 用户列表
func (c *userController) GetList(ctx context.Context, req *system.GetUserSearchReq) (res *system.UserSearchRes, err error) {
var (
total interface{}
userList []*entity.SysUser
)
res = new(system.UserSearchRes)
total, userList, err = service.SysUser().GetList(ctx, req)
if err != nil || total == 0 {
return
}
res.Total = total
res.UserList, err = service.SysUser().GetUsersRoleDeptInfo(ctx, userList)
res.UserList, err = service.SysUser().GetTenantInfo(ctx, res.UserList)
return
}
// GetParams 获取用户维护相关参数
func (c *userController) GetParams(ctx context.Context, req *system.UserGetParamsReq) (res *system.UserGetParamsRes, err error) {
res = new(system.UserGetParamsRes)
res.RoleList, err = service.SysRole().GetRoleList(ctx)
if err != nil {
return
}
res.Posts, err = service.SysPost().GetUsedPost(ctx)
return
}
// GetParamsInfo 获取用户维护相关参数信息
func (c *userController) GetParamsInfo(ctx context.Context, req *system.UserGetParamsInfoReq) (res *system.UserGetParamsRes, err error) {
res = new(system.UserGetParamsRes)
res.RoleList, err = service.SysRole().GetRoleListInfo(ctx)
if err != nil {
return
}
res.Posts, err = service.SysPost().GetUsedPost(ctx)
return
}
// Add 添加用户
func (c *userController) Add(ctx context.Context, req *system.UserAddReq) (res *system.UserAddRes, err error) {
_, err = service.SysUser().Add(ctx, req)
return
}
// GetEditUser 获取修改用户信息
func (c *userController) GetEditUser(ctx context.Context, req *system.UserGetEditReq) (res *system.UserGetEditRes, err error) {
res, err = service.SysUser().GetEditUser(ctx, req.Id)
return
}
// Edit 修改用户
func (c *userController) Edit(ctx context.Context, req *system.UserEditReq) (res *system.UserEditRes, err error) {
err = service.SysUser().Edit(ctx, req)
return
}
// ResetPwd 重置密码
func (c *userController) ResetPwd(ctx context.Context, req *system.UserResetPwdReq) (res *system.UserResetPwdRes, err error) {
err = service.SysUser().ResetUserPwd(ctx, req)
return
}
// SetStatus 修改用户状态
func (c *userController) SetStatus(ctx context.Context, req *system.UserStatusReq) (res *system.UserStatusRes, err error) {
err = service.SysUser().ChangeUserStatus(ctx, req)
return
}
// Delete 删除用户
func (c *userController) Delete(ctx context.Context, req *system.UserDeleteReq) (res *system.UserDeleteRes, err error) {
err = service.SysUser().Delete(ctx, req.Ids)
return
}
// GetUsers 通过用户id批量获取用户信息
func (c *userController) GetUsers(ctx context.Context, req *system.UserGetByIdsReq) (res *system.UserGetByIdsRes, err error) {
res = new(system.UserGetByIdsRes)
res.List, err = service.SysUser().GetUsers(ctx, req.Ids)
return
}
func (c *userController) IsSuperAdmin(ctx context.Context, req *system.IsSuperAdminReq) (IsSuperAdminRes *system.IsSuperAdminRes, err error) {
IsSuperAdminRes = new(system.IsSuperAdminRes)
IsSuperAdminRes.IsSuperAdmin, err = service.SysUser().IsSuperAdmin(ctx, req)
return
}

View File

@@ -0,0 +1,28 @@
/*
* @desc:在线用户管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2023/1/10 17:23
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var UserOnline = new(SysUserOnlineController)
type SysUserOnlineController struct{}
func (c *SysUserOnlineController) List(ctx context.Context, req *system.SysUserOnlineSearchReq) (res *system.SysUserOnlineSearchRes, err error) {
res, err = service.SysUserOnline().GetOnlineListPage(ctx, req)
return
}
func (c *SysUserOnlineController) ForceLogout(ctx context.Context, req *system.SysUserOnlineForceLogoutReq) (res *system.SysUserOnlineForceLogoutRes, err error) {
err = service.SysUserOnline().ForceLogout(ctx, req.Ids)
return
}

View File

@@ -0,0 +1,57 @@
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
var (
Tenant = tenantController{}
)
type tenantController struct {
BaseController
}
// List 用户列表
func (c *tenantController) List(ctx context.Context, req *system.TenantListReq) (res *system.TenantListRes, err error) {
res, err = service.Tenant().GetTenantListSearch(ctx, req)
return
}
// Add 添加用户
func (c *tenantController) Add(ctx context.Context, req *system.TenantAddReq) (res *system.TenantAddRes, err error) {
err = service.Tenant().Add(ctx, req)
return
}
// Edit 修改租户
func (c *tenantController) Edit(ctx context.Context, req *system.TenantEditReq) (res *system.TenantEditRes, err error) {
err = service.Tenant().Edit(ctx, req)
return
}
func (c *tenantController) GetTenantDetailsByIds(ctx context.Context, req *system.GetTenantDetailsByIdsReq) (res *system.GetTenantDetailsByIdsRes, err error) {
res, err = service.Tenant().GetTenantDetailsByIds(ctx, req)
return
}
func (c *tenantController) GetTenantDetails(ctx context.Context, req *system.GetTenantDetailsReq) (res *system.GetTenantDetailsRes, err error) {
res = new(system.GetTenantDetailsRes)
res.Tenant, err = service.Tenant().GetTenantDetails(ctx, req.TenantId)
return
}
func (c *tenantController) GetTenantAdminById(ctx context.Context, req *system.GetTenantDetailsReq) (res *system.GetTenantListRes, err error) {
res = new(system.GetTenantListRes)
res.List, err = service.Tenant().GetTenantAdminById(ctx, req.TenantId)
return
}
func (c *tenantController) GetTenantList(ctx context.Context, req *system.GetTenantListReq) (res *system.GetTenantListRes, err error) {
res = new(system.GetTenantListRes)
res.List, err = service.Tenant().GetTenantIdList(ctx, req)
return
}

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// areaDictDao is the data access object for table sys_user.
// You can define custom methods on it to extend its functionality as you wish.
type areaDictDao struct {
*internal.AreaDictDao
}
var (
// AreaDictDao is globally public accessible object for table sys_user operations.
AreaDictDao = areaDictDao{
internal.NewAreaDictDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,83 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// AreaDictDao is the data access object for table sys_user.
type AreaDictDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns AreaDictColumns // columns contains all the column names of Table for convenient usage.
}
// AreaDictColumns defines and stores column names for table sys_user.
type AreaDictColumns struct {
Id string //
CityName string // 城市名称
ParentId string // 父级id
ShortName string // 城市缩写名称
Depth string // 城市层级
MergerName string // 城市组合名称
}
// areaDictColumns holds the columns for table sys_user.
var areaDictColumns = AreaDictColumns{
Id: "id",
CityName: "city_name",
ParentId: "parent_id",
ShortName: "short_name",
Depth: "depth",
MergerName: "merger_name",
}
// NewAreaDictDao creates and returns a new DAO object for table data access.
func NewAreaDictDao() *AreaDictDao {
return &AreaDictDao{
group: "default",
table: "area_dict",
columns: areaDictColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *AreaDictDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *AreaDictDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *AreaDictDao) Columns() AreaDictColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *AreaDictDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *AreaDictDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *AreaDictDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,95 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2026-01-06
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// ModuleTenantDao is the data access object for table module_tenant.
type ModuleTenantDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns ModuleTenantColumns // columns contains all the column names of Table for convenient usage.
}
// ModuleTenantColumns defines and stores column names for table module_tenant.
type ModuleTenantColumns struct {
Id string //
CreateBy string // 创建者
UpdateBy string // 更新者
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
ModuleKey string // 模块Key
TenantId string // 租户ID
ExpireAt string // 到期时间
AssetId string // 资产ID
AssetSkuId string // 资产SKU ID
TenantModuleType string // 租户模块类型
CertificationStatus string // 状态
}
// moduleTenantColumns holds the columns for table module_tenant.
var moduleTenantColumns = ModuleTenantColumns{
Id: "id",
CreateBy: "create_by",
UpdateBy: "update_by",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
ModuleKey: "module_key",
TenantId: "tenant_id",
ExpireAt: "expire_at",
AssetId: "asset_id",
AssetSkuId: "asset_sku_id",
TenantModuleType: "tenant_module_type",
CertificationStatus: "certification_status",
}
// NewModuleTenantDao creates and returns a new DAO object for table data access.
func NewModuleTenantDao() *ModuleTenantDao {
return &ModuleTenantDao{
group: "default",
table: "module_tenant",
columns: moduleTenantColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *ModuleTenantDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *ModuleTenantDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *ModuleTenantDao) Columns() ModuleTenantColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *ModuleTenantDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *ModuleTenantDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *ModuleTenantDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,114 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysAuthRuleDao is the data access object for table sys_auth_rule.
type SysAuthRuleDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysAuthRuleColumns // columns contains all the column names of Table for convenient usage.
}
// SysAuthRuleColumns defines and stores column names for table sys_auth_rule.
type SysAuthRuleColumns struct {
Id string //
Pid string // 父ID
Name string // 规则名称
Title string // 规则名称
Icon string // 图标
Condition string // 条件
Remark string // 备注
MenuType string // 类型 0目录 1菜单 2按钮
Weigh string // 权重
IsHide string // 显示状态
Path string // 路由地址
Component string // 组件路径
IsLink string // 是否外链 1是 0否
ModuleType string // 所属模块
ModelId string // 模型ID
IsIframe string // 是否内嵌iframe
IsCached string // 是否缓存
Redirect string // 路由重定向地址
IsAffix string // 是否固定
LinkUrl string // 链接地址
CreatedAt string // 创建日期
UpdatedAt string // 修改日期
}
// sysAuthRuleColumns holds the columns for table sys_auth_rule.
var sysAuthRuleColumns = SysAuthRuleColumns{
Id: "id",
Pid: "pid",
Name: "name",
Title: "title",
Icon: "icon",
Condition: "condition",
Remark: "remark",
MenuType: "menu_type",
Weigh: "weigh",
IsHide: "is_hide",
Path: "path",
Component: "component",
IsLink: "is_link",
ModuleType: "module_type",
ModelId: "model_id",
IsIframe: "is_iframe",
IsCached: "is_cached",
Redirect: "redirect",
IsAffix: "is_affix",
LinkUrl: "link_url",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewSysAuthRuleDao creates and returns a new DAO object for table data access.
func NewSysAuthRuleDao() *SysAuthRuleDao {
return &SysAuthRuleDao{
group: "default",
table: "sys_auth_rule",
columns: sysAuthRuleColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysAuthRuleDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysAuthRuleDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysAuthRuleDao) Columns() SysAuthRuleColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysAuthRuleDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysAuthRuleDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysAuthRuleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,98 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysDeptDao is the data access object for table sys_dept.
type SysDeptDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysDeptColumns // columns contains all the column names of Table for convenient usage.
}
// SysDeptColumns defines and stores column names for table sys_dept.
type SysDeptColumns struct {
DeptId string // 部门id
ParentId string // 父部门id
Ancestors string // 祖级列表
DeptName string // 部门名称
OrderNum string // 显示顺序
Leader string // 负责人
Phone string // 联系电话
Email string // 邮箱
Status string // 部门状态0正常 1停用
CreatedBy string // 创建人
UpdatedBy string // 修改人
CreatedAt string // 创建时间
UpdatedAt string // 修改时间
DeletedAt string // 删除时间
}
// sysDeptColumns holds the columns for table sys_dept.
var sysDeptColumns = SysDeptColumns{
DeptId: "dept_id",
ParentId: "parent_id",
Ancestors: "ancestors",
DeptName: "dept_name",
OrderNum: "order_num",
Leader: "leader",
Phone: "phone",
Email: "email",
Status: "status",
CreatedBy: "created_by",
UpdatedBy: "updated_by",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
}
// NewSysDeptDao creates and returns a new DAO object for table data access.
func NewSysDeptDao() *SysDeptDao {
return &SysDeptDao{
group: "default",
table: "sys_dept",
columns: sysDeptColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysDeptDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysDeptDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysDeptDao) Columns() SysDeptColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysDeptDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysDeptDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysDeptDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,102 @@
// ==========================================================================
// GFast自动生成dao internal操作代码。
// 生成日期2023-01-12 17:43:50
// 生成路径: internal/app/system/dao/internal/sys_job.go
// 生成人gfast
// desc:定时任务
// company:云南奇讯科技有限公司
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysJobDao is the manager for logic model data accessing and custom defined data operations functions management.
type SysJobDao struct {
table string // Table is the underlying table name of the DAO.
group string // Group is the database configuration group name of current DAO.
columns SysJobColumns // Columns is the short type for Columns, which contains all the column names of Table for convenient usage.
}
// SysJobColumns defines and stores column names for table sys_job.
type SysJobColumns struct {
JobId string // 任务ID
JobName string // 任务名称
JobParams string // 参数
JobGroup string // 任务组名
InvokeTarget string // 任务方法
CronExpression string // cron执行表达式
MisfirePolicy string // 计划执行策略
Concurrent string // 是否并发执行
Status string // 状态
CreatedBy string // 创建者
UpdatedBy string // 更新者
Remark string // 备注信息
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
}
var sysJobColumns = SysJobColumns{
JobId: "job_id",
JobName: "job_name",
JobParams: "job_params",
JobGroup: "job_group",
InvokeTarget: "invoke_target",
CronExpression: "cron_expression",
MisfirePolicy: "misfire_policy",
Concurrent: "concurrent",
Status: "status",
CreatedBy: "created_by",
UpdatedBy: "updated_by",
Remark: "remark",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewSysJobDao creates and returns a new DAO object for table data access.
func NewSysJobDao() *SysJobDao {
return &SysJobDao{
group: "default",
table: "sys_job",
columns: sysJobColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysJobDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysJobDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysJobDao) Columns() SysJobColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysJobDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysJobDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysJobDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,79 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysJobLogDao is the data access object for table sys_job_log.
type SysJobLogDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysJobLogColumns // columns contains all the column names of Table for convenient usage.
}
// SysJobLogColumns defines and stores column names for table sys_job_log.
type SysJobLogColumns struct {
Id string // 主键
TargetName string // 方法名
CreatedAt string // 执行日期
Result string // 执行结果
}
// sysJobLogColumns holds the columns for table sys_job_log.
var sysJobLogColumns = SysJobLogColumns{
Id: "id",
TargetName: "target_name",
CreatedAt: "created_at",
Result: "result",
}
// NewSysJobLogDao creates and returns a new DAO object for table data access.
func NewSysJobLogDao() *SysJobLogDao {
return &SysJobLogDao{
group: "default",
table: "sys_job_log",
columns: sysJobLogColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysJobLogDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysJobLogDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysJobLogDao) Columns() SysJobLogColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysJobLogDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysJobLogDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysJobLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,90 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-08 11:31:48
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysLoginLogDao is the data access object for table sys_login_log.
type SysLoginLogDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysLoginLogColumns // columns contains all the column names of Table for convenient usage.
}
// SysLoginLogColumns defines and stores column names for table sys_login_log.
type SysLoginLogColumns struct {
InfoId string // 访问ID
LoginName string // 登录账号
Ipaddr string // 登录IP地址
LoginLocation string // 登录地点
Browser string // 浏览器类型
Os string // 操作系统
Status string // 登录状态0成功 1失败
Msg string // 提示消息
LoginTime string // 登录时间
Module string // 登录模块
}
// sysLoginLogColumns holds the columns for table sys_login_log.
var sysLoginLogColumns = SysLoginLogColumns{
InfoId: "info_id",
LoginName: "login_name",
Ipaddr: "ipaddr",
LoginLocation: "login_location",
Browser: "browser",
Os: "os",
Status: "status",
Msg: "msg",
LoginTime: "login_time",
Module: "module",
}
// NewSysLoginLogDao creates and returns a new DAO object for table data access.
func NewSysLoginLogDao() *SysLoginLogDao {
return &SysLoginLogDao{
group: "default",
table: "sys_login_log",
columns: sysLoginLogColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysLoginLogDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysLoginLogDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysLoginLogDao) Columns() SysLoginLogColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysLoginLogDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysLoginLogDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysLoginLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,99 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysOperLogDao is the data access object for table sys_oper_log.
type SysOperLogDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysOperLogColumns // columns contains all the column names of Table for convenient usage.
}
// SysOperLogColumns defines and stores column names for table sys_oper_log.
type SysOperLogColumns struct {
OperId string // 日志主键
Title string // 模块标题
BusinessType string // 业务类型0其它 1新增 2修改 3删除
Method string // 方法名称
RequestMethod string // 请求方式
OperatorType string // 操作类别0其它 1后台用户 2手机端用户
OperName string // 操作人员
DeptName string // 部门名称
OperUrl string // 请求URL
OperIp string // 主机地址
OperLocation string // 操作地点
OperParam string // 请求参数
ErrorMsg string // 错误消息
OperTime string // 操作时间
}
// sysOperLogColumns holds the columns for table sys_oper_log.
var sysOperLogColumns = SysOperLogColumns{
OperId: "oper_id",
Title: "title",
BusinessType: "business_type",
Method: "method",
RequestMethod: "request_method",
OperatorType: "operator_type",
OperName: "oper_name",
DeptName: "dept_name",
OperUrl: "oper_url",
OperIp: "oper_ip",
OperLocation: "oper_location",
OperParam: "oper_param",
ErrorMsg: "error_msg",
OperTime: "oper_time",
}
// NewSysOperLogDao creates and returns a new DAO object for table data access.
func NewSysOperLogDao() *SysOperLogDao {
return &SysOperLogDao{
group: "default",
table: "sys_oper_log",
columns: sysOperLogColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysOperLogDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysOperLogDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysOperLogDao) Columns() SysOperLogColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysOperLogDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysOperLogDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysOperLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,92 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-07 23:26:21
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysPostDao is the data access object for table sys_post.
type SysPostDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysPostColumns // columns contains all the column names of Table for convenient usage.
}
// SysPostColumns defines and stores column names for table sys_post.
type SysPostColumns struct {
PostId string // 岗位ID
PostCode string // 岗位编码
PostName string // 岗位名称
PostSort string // 显示顺序
Status string // 状态0正常 1停用
Remark string // 备注
CreatedBy string // 创建人
UpdatedBy string // 修改人
CreatedAt string // 创建时间
UpdatedAt string // 修改时间
DeletedAt string // 删除时间
}
// sysPostColumns holds the columns for table sys_post.
var sysPostColumns = SysPostColumns{
PostId: "post_id",
PostCode: "post_code",
PostName: "post_name",
PostSort: "post_sort",
Status: "status",
Remark: "remark",
CreatedBy: "created_by",
UpdatedBy: "updated_by",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
}
// NewSysPostDao creates and returns a new DAO object for table data access.
func NewSysPostDao() *SysPostDao {
return &SysPostDao{
group: "default",
table: "sys_post",
columns: sysPostColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysPostDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysPostDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysPostDao) Columns() SysPostColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysPostDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysPostDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysPostDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,86 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysRoleDao is the data access object for table sys_role.
type SysRoleDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysRoleColumns // columns contains all the column names of Table for convenient usage.
}
// SysRoleColumns defines and stores column names for table sys_role.
type SysRoleColumns struct {
Id string //
Status string // 状态;0:禁用;1:正常
ListOrder string // 排序
Name string // 角色名称
Remark string // 备注
DataScope string // 数据范围1全部数据权限 2自定数据权限 3本部门数据权限 4本部门及以下数据权限
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
}
// sysRoleColumns holds the columns for table sys_role.
var sysRoleColumns = SysRoleColumns{
Id: "id",
Status: "status",
ListOrder: "list_order",
Name: "name",
Remark: "remark",
DataScope: "data_scope",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewSysRoleDao creates and returns a new DAO object for table data access.
func NewSysRoleDao() *SysRoleDao {
return &SysRoleDao{
group: "default",
table: "sys_role",
columns: sysRoleColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysRoleDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysRoleDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysRoleDao) Columns() SysRoleColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysRoleDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysRoleDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysRoleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,75 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysRoleDeptDao is the data access object for table sys_role_dept.
type SysRoleDeptDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysRoleDeptColumns // columns contains all the column names of Table for convenient usage.
}
// SysRoleDeptColumns defines and stores column names for table sys_role_dept.
type SysRoleDeptColumns struct {
RoleId string // 角色ID
DeptId string // 部门ID
}
// sysRoleDeptColumns holds the columns for table sys_role_dept.
var sysRoleDeptColumns = SysRoleDeptColumns{
RoleId: "role_id",
DeptId: "dept_id",
}
// NewSysRoleDeptDao creates and returns a new DAO object for table data access.
func NewSysRoleDeptDao() *SysRoleDeptDao {
return &SysRoleDeptDao{
group: "default",
table: "sys_role_dept",
columns: sysRoleDeptColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysRoleDeptDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysRoleDeptDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysRoleDeptDao) Columns() SysRoleDeptColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysRoleDeptDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysRoleDeptDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysRoleDeptDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,114 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysUserDao is the data access object for table sys_user.
type SysUserDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysUserColumns // columns contains all the column names of Table for convenient usage.
}
// SysUserColumns defines and stores column names for table sys_user.
type SysUserColumns struct {
Id string //
UserName string // 用户名
Mobile string // 中国手机不带国家代码,国际手机号格式为:国家代码-手机号
UserNickname string // 用户昵称
Birthday string // 生日
UserPassword string // 登录密码;cmf_password加密
UserSalt string // 加密盐
UserStatus string // 用户状态;0:禁用,1:正常,2:未验证
UserEmail string // 用户登录邮箱
Sex string // 性别;0:保密,1:男,2:女
Avatar string // 用户头像
DeptId string // 部门id
Remark string // 备注
IsAdmin string // 是否后台管理员 1 是 0 否
Address string // 联系地址
Describe string // 描述信息
LastLoginIp string // 最后登录ip
LastLoginTime string // 最后登录时间
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 删除时间
TenantId string
}
// sysUserColumns holds the columns for table sys_user.
var sysUserColumns = SysUserColumns{
Id: "id",
UserName: "user_name",
Mobile: "mobile",
UserNickname: "user_nickname",
Birthday: "birthday",
UserPassword: "user_password",
UserSalt: "user_salt",
UserStatus: "user_status",
UserEmail: "user_email",
Sex: "sex",
Avatar: "avatar",
DeptId: "dept_id",
Remark: "remark",
IsAdmin: "is_admin",
Address: "address",
Describe: "describe",
LastLoginIp: "last_login_ip",
LastLoginTime: "last_login_time",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
TenantId: "tenant_id",
}
// NewSysUserDao creates and returns a new DAO object for table data access.
func NewSysUserDao() *SysUserDao {
return &SysUserDao{
group: "default",
table: "sys_user",
columns: sysUserColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysUserDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysUserDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysUserDao) Columns() SysUserColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysUserDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysUserDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysUserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,87 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysUserOnlineDao is the data access object for table sys_user_online.
type SysUserOnlineDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysUserOnlineColumns // columns contains all the column names of Table for convenient usage.
}
// SysUserOnlineColumns defines and stores column names for table sys_user_online.
type SysUserOnlineColumns struct {
Id string //
Uuid string // 用户标识
Token string // 用户token
CreateTime string // 登录时间
UserName string // 用户名
Ip string // 登录ip
Explorer string // 浏览器
Os string // 操作系统
}
// sysUserOnlineColumns holds the columns for table sys_user_online.
var sysUserOnlineColumns = SysUserOnlineColumns{
Id: "id",
Uuid: "uuid",
Token: "token",
CreateTime: "create_time",
UserName: "user_name",
Ip: "ip",
Explorer: "explorer",
Os: "os",
}
// NewSysUserOnlineDao creates and returns a new DAO object for table data access.
func NewSysUserOnlineDao() *SysUserOnlineDao {
return &SysUserOnlineDao{
group: "default",
table: "sys_user_online",
columns: sysUserOnlineColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysUserOnlineDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysUserOnlineDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysUserOnlineDao) Columns() SysUserOnlineColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysUserOnlineDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysUserOnlineDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysUserOnlineDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,74 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysUserPostDao is the data access object for table sys_user_post.
type SysUserPostDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysUserPostColumns // columns contains all the column names of Table for convenient usage.
}
// SysUserPostColumns defines and stores column names for table sys_user_post.
type SysUserPostColumns struct {
UserId string // 用户ID
PostId string // 岗位ID
}
// sysUserPostColumns holds the columns for table sys_user_post.
var sysUserPostColumns = SysUserPostColumns{
UserId: "user_id",
PostId: "post_id",
}
// NewSysUserPostDao creates and returns a new DAO object for table data access.
func NewSysUserPostDao() *SysUserPostDao {
return &SysUserPostDao{
group: "default",
table: "sys_user_post",
columns: sysUserPostColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysUserPostDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysUserPostDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysUserPostDao) Columns() SysUserPostColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysUserPostDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysUserPostDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysUserPostDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,91 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// TenantDao is the data access object for table sys_user.
type TenantDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns TenantColumns // columns contains all the column names of Table for convenient usage.
}
// TenantColumns defines and stores column names for table sys_user.
type TenantColumns struct {
Id string //
CreateBy string // 创建者
UpdateBy string // 更新者
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
TenantName string // 租户名称
TenantType string // 租户类型
CityCode string // 城市编码
BusinessLicense string // 营业执照
TenantSource string // 租户来源
}
// tenantColumns holds the columns for table sys_user.
var tenantColumns = TenantColumns{
Id: "id",
CreateBy: "create_by",
UpdateBy: "update_by",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
TenantName: "tenant_name",
TenantType: "tenant_type",
CityCode: "city_code",
BusinessLicense: "business_license",
TenantSource: "tenant_source",
}
// NewTenantDao creates and returns a new DAO object for table data access.
func NewTenantDao() *TenantDao {
return &TenantDao{
group: "default",
table: "tenant",
columns: tenantColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *TenantDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *TenantDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *TenantDao) Columns() TenantColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *TenantDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *TenantDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *TenantDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,107 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// ToolsGenTableDao is the data access object for table tools_gen_table.
type ToolsGenTableDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns ToolsGenTableColumns // columns contains all the column names of Table for convenient usage.
}
// ToolsGenTableColumns defines and stores column names for table tools_gen_table.
type ToolsGenTableColumns struct {
TableId string // 编号
TableName string // 表名称
TableComment string // 表描述
ClassName string // 实体类名称
TplCategory string // 使用的模板crud单表操作 tree树表操作
PackageName string // 生成包路径
ModuleName string // 生成模块名
BusinessName string // 生成业务名
FunctionName string // 生成功能名
FunctionAuthor string // 生成功能作者
Options string // 其它生成选项
CreateTime string // 创建时间
UpdateTime string // 更新时间
Remark string // 备注
Overwrite string // 是否覆盖原有文件
SortColumn string // 排序字段名
SortType string // 排序方式 (asc顺序 desc倒序)
ShowDetail string // 是否有查看详情功能
}
// toolsGenTableColumns holds the columns for table tools_gen_table.
var toolsGenTableColumns = ToolsGenTableColumns{
TableId: "table_id",
TableName: "table_name",
TableComment: "table_comment",
ClassName: "class_name",
TplCategory: "tpl_category",
PackageName: "package_name",
ModuleName: "module_name",
BusinessName: "business_name",
FunctionName: "function_name",
FunctionAuthor: "function_author",
Options: "options",
CreateTime: "create_time",
UpdateTime: "update_time",
Remark: "remark",
Overwrite: "overwrite",
SortColumn: "sort_column",
SortType: "sort_type",
ShowDetail: "show_detail",
}
// NewToolsGenTableDao creates and returns a new DAO object for table data access.
func NewToolsGenTableDao() *ToolsGenTableDao {
return &ToolsGenTableDao{
group: "default",
table: "tools_gen_table",
columns: toolsGenTableColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *ToolsGenTableDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *ToolsGenTableDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *ToolsGenTableDao) Columns() ToolsGenTableColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *ToolsGenTableDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *ToolsGenTableDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *ToolsGenTableDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,151 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// ToolsGenTableColumnDao is the data access object for table tools_gen_table_column.
type ToolsGenTableColumnDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns ToolsGenTableColumnColumns // columns contains all the column names of Table for convenient usage.
}
// ToolsGenTableColumnColumns defines and stores column names for table tools_gen_table_column.
type ToolsGenTableColumnColumns struct {
ColumnId string // 编号
TableId string // 归属表编号
ColumnName string // 列名称
ColumnComment string // 列描述
ColumnType string // 列类型
GoType string // Go类型
TsType string // TS类型
GoField string // Go字段名
HtmlField string // html字段名
IsPk string // 是否主键1是
IsIncrement string // 是否自增1是
IsRequired string // 是否必填1是
IsInsert string // 是否为插入字段1是
IsEdit string // 是否编辑字段1是
IsList string // 是否列表字段1是
IsDetail string // 是否详情字段
IsQuery string // 是否查询字段1是
SortOrderEdit string // 插入编辑显示顺序
SortOrderList string // 列表显示顺序
SortOrderDetail string // 详情显示顺序
SortOrderQuery string // 查询显示顺序
QueryType string // 查询方式(等于、不等于、大于、小于、范围)
HtmlType string // 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)
DictType string // 字典类型
LinkTableName string // 关联表名
LinkTableClass string // 关联表类名
LinkTableModuleName string // 关联表模块名
LinkTableBusinessName string // 关联表业务名
LinkTablePackage string // 关联表包名
LinkLabelId string // 关联表键名
LinkLabelName string // 关联表字段值
ColSpan string // 详情页占列数
RowSpan string // 详情页占行数
IsRowStart string // 详情页为行首
MinWidth string // 表格最小宽度
IsFixed string // 是否表格列左固定
IsOverflowTooltip string // 是否过长自动隐藏
IsCascade string // 是否级联查询
ParentColumnName string // 上级字段名
CascadeColumnName string // 级联查询字段
}
// toolsGenTableColumnColumns holds the columns for table tools_gen_table_column.
var toolsGenTableColumnColumns = ToolsGenTableColumnColumns{
ColumnId: "column_id",
TableId: "table_id",
ColumnName: "column_name",
ColumnComment: "column_comment",
ColumnType: "column_type",
GoType: "go_type",
TsType: "ts_type",
GoField: "go_field",
HtmlField: "html_field",
IsPk: "is_pk",
IsIncrement: "is_increment",
IsRequired: "is_required",
IsInsert: "is_insert",
IsEdit: "is_edit",
IsList: "is_list",
IsDetail: "is_detail",
IsQuery: "is_query",
SortOrderEdit: "sort_order_edit",
SortOrderList: "sort_order_list",
SortOrderDetail: "sort_order_detail",
SortOrderQuery: "sort_order_query",
QueryType: "query_type",
HtmlType: "html_type",
DictType: "dict_type",
LinkTableName: "link_table_name",
LinkTableClass: "link_table_class",
LinkTableModuleName: "link_table_module_name",
LinkTableBusinessName: "link_table_business_name",
LinkTablePackage: "link_table_package",
LinkLabelId: "link_label_id",
LinkLabelName: "link_label_name",
ColSpan: "col_span",
RowSpan: "row_span",
IsRowStart: "is_row_start",
MinWidth: "min_width",
IsFixed: "is_fixed",
IsOverflowTooltip: "is_overflow_tooltip",
IsCascade: "is_cascade",
ParentColumnName: "parent_column_name",
CascadeColumnName: "cascade_column_name",
}
// NewToolsGenTableColumnDao creates and returns a new DAO object for table data access.
func NewToolsGenTableColumnDao() *ToolsGenTableColumnDao {
return &ToolsGenTableColumnDao{
group: "default",
table: "tools_gen_table_column",
columns: toolsGenTableColumnColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *ToolsGenTableColumnDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *ToolsGenTableColumnDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *ToolsGenTableColumnDao) Columns() ToolsGenTableColumnColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *ToolsGenTableColumnDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *ToolsGenTableColumnDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *ToolsGenTableColumnDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// moduleTenantDao is the data access object for table module_tenant.
// You can define custom methods on it to extend its functionality as you wish.
type moduleTenantDao struct {
*internal.ModuleTenantDao
}
var (
// ModuleTenant is globally public accessible object for table module_tenant operations.
ModuleTenant = moduleTenantDao{
internal.NewModuleTenantDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// sysAuthRuleDao is the data access object for table sys_auth_rule.
// You can define custom methods on it to extend its functionality as you wish.
type sysAuthRuleDao struct {
*internal.SysAuthRuleDao
}
var (
// SysAuthRule is globally public accessible object for table sys_auth_rule operations.
SysAuthRule = sysAuthRuleDao{
internal.NewSysAuthRuleDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// internalSysDeptDao is internal type for wrapping internal DAO implements.
type internalSysDeptDao = *internal.SysDeptDao
// sysDeptDao is the data access object for table sys_dept.
// You can define custom methods on it to extend its functionality as you wish.
type sysDeptDao struct {
internalSysDeptDao
}
var (
// SysDept is globally public accessible object for table sys_dept operations.
SysDept = sysDeptDao{
internal.NewSysDeptDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,29 @@
// ==========================================================================
// GFast自动生成dao操作代码。
// 生成日期2023-01-12 17:43:50
// 生成路径: internal/app/system/dao/sys_job.go
// 生成人gfast
// desc:定时任务
// company:云南奇讯科技有限公司
// ==========================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// sysJobDao is the manager for logic model data accessing and custom defined data operations functions management.
// You can define custom methods on it to extend its functionality as you wish.
type sysJobDao struct {
*internal.SysJobDao
}
var (
// SysJob is globally public accessible object for table tools_gen_table operations.
SysJob = sysJobDao{
internal.NewSysJobDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// internalSysJobLogDao is internal type for wrapping internal DAO implements.
type internalSysJobLogDao = *internal.SysJobLogDao
// sysJobLogDao is the data access object for table sys_job_log.
// You can define custom methods on it to extend its functionality as you wish.
type sysJobLogDao struct {
internalSysJobLogDao
}
var (
// SysJobLog is globally public accessible object for table sys_job_log operations.
SysJobLog = sysJobLogDao{
internal.NewSysJobLogDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// sysLoginLogDao is the data access object for table sys_login_log.
// You can define custom methods on it to extend its functionality as you wish.
type sysLoginLogDao struct {
*internal.SysLoginLogDao
}
var (
// SysLoginLog is globally public accessible object for table sys_login_log operations.
SysLoginLog = sysLoginLogDao{
internal.NewSysLoginLogDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// internalSysOperLogDao is internal type for wrapping internal DAO implements.
type internalSysOperLogDao = *internal.SysOperLogDao
// sysOperLogDao is the data access object for table sys_oper_log.
// You can define custom methods on it to extend its functionality as you wish.
type sysOperLogDao struct {
internalSysOperLogDao
}
var (
// SysOperLog is globally public accessible object for table sys_oper_log operations.
SysOperLog = sysOperLogDao{
internal.NewSysOperLogDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// sysPostDao is the data access object for table sys_post.
// You can define custom methods on it to extend its functionality as you wish.
type sysPostDao struct {
*internal.SysPostDao
}
var (
// SysPost is globally public accessible object for table sys_post operations.
SysPost = sysPostDao{
internal.NewSysPostDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// sysRoleDao is the data access object for table sys_role.
// You can define custom methods on it to extend its functionality as you wish.
type sysRoleDao struct {
*internal.SysRoleDao
}
var (
// SysRole is globally public accessible object for table sys_role operations.
SysRole = sysRoleDao{
internal.NewSysRoleDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// internalSysRoleDeptDao is internal type for wrapping internal DAO implements.
type internalSysRoleDeptDao = *internal.SysRoleDeptDao
// sysRoleDeptDao is the data access object for table sys_role_dept.
// You can define custom methods on it to extend its functionality as you wish.
type sysRoleDeptDao struct {
internalSysRoleDeptDao
}
var (
// SysRoleDept is globally public accessible object for table sys_role_dept operations.
SysRoleDept = sysRoleDeptDao{
internal.NewSysRoleDeptDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// sysUserDao is the data access object for table sys_user.
// You can define custom methods on it to extend its functionality as you wish.
type sysUserDao struct {
*internal.SysUserDao
}
var (
// SysUser is globally public accessible object for table sys_user operations.
SysUser = sysUserDao{
internal.NewSysUserDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// internalSysUserOnlineDao is internal type for wrapping internal DAO implements.
type internalSysUserOnlineDao = *internal.SysUserOnlineDao
// sysUserOnlineDao is the data access object for table sys_user_online.
// You can define custom methods on it to extend its functionality as you wish.
type sysUserOnlineDao struct {
internalSysUserOnlineDao
}
var (
// SysUserOnline is globally public accessible object for table sys_user_online operations.
SysUserOnline = sysUserOnlineDao{
internal.NewSysUserOnlineDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// internalSysUserPostDao is internal type for wrapping internal DAO implements.
type internalSysUserPostDao = *internal.SysUserPostDao
// sysUserPostDao is the data access object for table sys_user_post.
// You can define custom methods on it to extend its functionality as you wish.
type sysUserPostDao struct {
internalSysUserPostDao
}
var (
// SysUserPost is globally public accessible object for table sys_user_post operations.
SysUserPost = sysUserPostDao{
internal.NewSysUserPostDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// tenantDao is the data access object for table sys_user.
// You can define custom methods on it to extend its functionality as you wish.
type tenantDao struct {
*internal.TenantDao
}
var (
// TenantDao is globally public accessible object for table sys_user operations.
TenantDao = tenantDao{
internal.NewTenantDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// internalToolsGenTableDao is internal type for wrapping internal DAO implements.
type internalToolsGenTableDao = *internal.ToolsGenTableDao
// toolsGenTableDao is the data access object for table tools_gen_table.
// You can define custom methods on it to extend its functionality as you wish.
type toolsGenTableDao struct {
internalToolsGenTableDao
}
var (
// ToolsGenTable is globally public accessible object for table tools_gen_table operations.
ToolsGenTable = toolsGenTableDao{
internal.NewToolsGenTableDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/system/dao/internal"
)
// internalToolsGenTableColumnDao is internal type for wrapping internal DAO implements.
type internalToolsGenTableColumnDao = *internal.ToolsGenTableColumnDao
// toolsGenTableColumnDao is the data access object for table tools_gen_table_column.
// You can define custom methods on it to extend its functionality as you wish.
type toolsGenTableColumnDao struct {
internalToolsGenTableColumnDao
}
var (
// ToolsGenTableColumn is globally public accessible object for table tools_gen_table_column operations.
ToolsGenTableColumn = toolsGenTableColumnDao{
internal.NewToolsGenTableColumnDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,86 @@
/*
* @desc:用户处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/23 15:08
*/
package tenant
import (
"context"
"github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonConsts "github.com/tiger1103/gfast/v3/internal/app/common/consts"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterAreaDict(New())
}
type sAreaDict struct {
}
func New() *sAreaDict {
return &sAreaDict{}
}
func (s *sAreaDict) GetAreaDictListSearch(ctx context.Context, req *system.AreaDictListReq) (res *system.AreaDictListRes, err error) {
res = new(system.AreaDictListRes)
g.Try(ctx, func(ctx context.Context) {
model := dao.AreaDictDao.Ctx(ctx)
res.Total, err = model.Count()
liberr.ErrIsNil(ctx, err, "获取租户数据失败")
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
err = model.Page(res.CurrentPage, req.PageSize).Order("id asc").Scan(&res.List)
liberr.ErrIsNil(ctx, err, "获取数据失败")
})
return
}
// GetAreaDicById 通过ids查询多个地区信息
func (s *sAreaDict) GetAreaDicById(ctx context.Context, ids []string) (area []*model.AreaDictRes, err error) {
if len(ids) == 0 {
return
}
idsSet := gset.NewStrSetFrom(ids).Slice()
err = g.Try(ctx, func(ctx context.Context) {
err = dao.AreaDictDao.Ctx(ctx).Where(dao.SysUser.Columns().Id+" in(?)", idsSet).
Order(dao.AreaDictDao.Columns().Id + " ASC").Scan(&area)
})
return
}
// GetAreaDict 获取所有正常状态下的
func (s *sAreaDict) GetAreaDict(ctx context.Context) (list []*model.AreaDictRes, err error) {
cache := commonService.Cache()
//从缓存获取
data := cache.Get(ctx, commonConsts.CacheSysDict+"_area")
if !data.IsNil() {
err = data.Structs(&list)
return
}
err = g.Try(ctx, func(ctx context.Context) {
err = dao.AreaDictDao.Ctx(ctx).Where("status", 1).Order("id ASC").Scan(&list)
liberr.ErrIsNil(ctx, err, "获取字典类型数据出错")
//缓存
cache.Set(ctx, commonConsts.CacheSysDict+"_area", list, 0, commonConsts.CacheSysDictTag)
})
return
}

View File

@@ -0,0 +1,66 @@
/*
* @desc:context-service
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/23 14:51
*/
package context
import (
"context"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
)
func init() {
service.RegisterContext(New())
}
type sContext struct{}
func New() *sContext {
return &sContext{}
}
// Init 初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。
func (s *sContext) Init(r *ghttp.Request, customCtx *model.Context) {
r.SetCtxVar(consts.CtxKey, customCtx)
}
// Get 获得上下文变量如果没有设置那么返回nil
func (s *sContext) Get(ctx context.Context) *model.Context {
value := ctx.Value(consts.CtxKey)
if value == nil {
return nil
}
if localCtx, ok := value.(*model.Context); ok {
return localCtx
}
return nil
}
// SetUser 将上下文信息设置到上下文请求中,注意是完整覆盖
func (s *sContext) SetUser(ctx context.Context, ctxUser *model.ContextUser) {
s.Get(ctx).User = ctxUser
}
// GetLoginUser 获取当前登陆用户信息
func (s *sContext) GetLoginUser(ctx context.Context) *model.ContextUser {
context := s.Get(ctx)
if context == nil {
return nil
}
return context.User
}
// GetUserId 获取当前登录用户id
func (s *sContext) GetUserId(ctx context.Context) uint64 {
user := s.GetLoginUser(ctx)
if user != nil {
return user.Id
}
return 0
}

View File

@@ -0,0 +1,17 @@
package logic
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/middleware"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/personal"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysAuthRule"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysDept"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysLoginLog"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysOperLog"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysPost"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysRole"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysUser"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/sysUserOnline"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/token"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/tenant"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/areaDict"
import _ "github.com/tiger1103/gfast/v3/internal/app/system/logic/moduleTenant"

View File

@@ -0,0 +1,135 @@
/*
* @desc:中间件
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/23 15:05
*/
package middleware
import (
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/libResponse"
)
func init() {
service.RegisterMiddleware(New())
}
func New() *sMiddleware {
return &sMiddleware{}
}
type sMiddleware struct{}
// Ctx 自定义上下文对象
func (s *sMiddleware) Ctx(r *ghttp.Request) {
ctx := r.GetCtx()
// 初始化登录用户信息
data, err := service.GfToken().ParseToken(r)
if err != nil {
// 执行下一步请求逻辑
r.Middleware.Next()
}
if data != nil {
context := new(model.Context)
err = gconv.Struct(data.Data, &context.User)
if err != nil {
g.Log().Error(ctx, err)
// 执行下一步请求逻辑
r.Middleware.Next()
}
service.Context().Init(r, context)
}
// 执行下一步请求逻辑
r.Middleware.Next()
}
// Auth 权限判断处理中间件
func (s *sMiddleware) Auth(r *ghttp.Request) {
ctx := r.GetCtx()
//获取登陆用户id
adminId := service.Context().GetUserId(ctx)
accessParams := r.Get("accessParams").Strings()
accessParamsStr := ""
if len(accessParams) > 0 && accessParams[0] != "undefined" {
accessParamsStr = "?" + gstr.Join(accessParams, "&")
}
url := gstr.TrimLeft(r.Request.URL.Path, "/") + accessParamsStr
/*if r.Method != "GET" && adminId != 1 && url!="api/v1/system/login" {
libResponse.FailJson(true, r, "对不起!演示系统,不能删改数据!")
}*/
//获取无需验证权限的用户id
tagSuperAdmin := false
service.SysUser().NotCheckAuthAdminIds(ctx).Iterator(func(v interface{}) bool {
if gconv.Uint64(v) == adminId {
tagSuperAdmin = true
return false
}
return true
})
if tagSuperAdmin {
r.Middleware.Next()
//不要再往后面执行
return
}
//获取地址对应的菜单id
menuList, err := service.SysAuthRule().GetMenuList(ctx)
if err != nil {
g.Log().Error(ctx, err)
libResponse.FailJson(true, r, "请求数据失败")
}
var menu *model.SysAuthRuleInfoRes
for _, m := range menuList {
ms := gstr.SubStr(m.Name, 0, gstr.Pos(m.Name, "?"))
if m.Name == url || ms == url {
menu = m
break
}
}
//只验证存在数据库中的规则
if menu != nil {
//若是不登录能访问的接口则不判断权限
excludePaths := g.Cfg().MustGet(ctx, "gfToken.excludePaths").Strings()
for _, p := range excludePaths {
if gstr.Equal(menu.Name, gstr.TrimLeft(p, "/")) {
r.Middleware.Next()
return
}
}
//若存在不需要验证的条件则跳过
if gstr.Equal(menu.Condition, "nocheck") {
r.Middleware.Next()
return
}
menuId := menu.Id
//菜单没存数据库不验证权限
if menuId != 0 {
//判断权限操作
enforcer, err := commonService.CasbinEnforcer(ctx)
if err != nil {
g.Log().Error(ctx, err)
libResponse.FailJson(true, r, "获取权限失败")
}
hasAccess := false
hasAccess, err = enforcer.Enforce(fmt.Sprintf("%s%d", service.SysUser().GetCasBinUserPrefix(), adminId), gconv.String(menuId), "All")
if err != nil {
g.Log().Error(ctx, err)
libResponse.FailJson(true, r, "判断权限失败")
}
if !hasAccess {
libResponse.FailJson(true, r, "没有访问权限")
}
}
} else if menu == nil && accessParamsStr != "" {
libResponse.FailJson(true, r, "没有访问权限")
}
r.Middleware.Next()
}

View File

@@ -0,0 +1,189 @@
/*
* @desc:模块租户关系处理
* @company:云南奇讯科技有限公司
* @Author: system
* @Date: 2026/1/6
*/
package moduleTenant
import (
"context"
"fmt"
"gitea.com/red-future/common/beans"
"gitea.com/red-future/common/http"
"gitea.com/red-future/common/utils"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
"time"
)
func init() {
service.RegisterModuleTenant(New())
}
type sModuleTenant struct {
}
func New() *sModuleTenant {
return &sModuleTenant{}
}
// Add 添加模块租户关系
func (s *sModuleTenant) Add(ctx context.Context, req *system.ModuleTenantAddReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
// 获取用户信息
var getUserInfo *beans.User
getUserInfo, err = utils.GetUserInfo(ctx)
liberr.ErrIsNil(ctx, err, "获取用户信息失败")
// 获取sku信息
assetSukRes := new(system.AssetSku)
// 获取当前请求的 headers 并传递到下游
headers := make(map[string]string)
if r := g.RequestFromCtx(ctx); r != nil {
for k, v := range r.Request.Header {
if len(v) > 0 {
headers[k] = v[0]
}
}
}
if err = http.Get(ctx, "asset/sku/getAssetSkuModule", headers, &assetSukRes,
"id", req.AssetSkuId,
); err != nil {
return
}
liberr.ErrIsNil(ctx, err, "获取资产sku信息失败")
if assetSukRes.ExpireAt != nil {
liberr.ErrIsNil(ctx, err, "sku到期时间不能为空")
}
// 获取模块key
var moduleKey string
// 遍历 map 的所有键值对
for key, value := range beans.ModuleAssetId {
if value == assetSukRes.AssetId.Hex() {
moduleKey = key
break
}
}
// 检查是否已存在相同的模块租户关系
var moduleTenant *entity.ModuleTenant
moduleTenant, err = s.GetByModuleKeyAndTenantId(ctx, moduleKey, gconv.Uint64(getUserInfo.TenantId))
liberr.ErrIsNil(ctx, err, "检查模块租户关系失败")
if moduleTenant != nil {
now := gtime.Now()
if moduleTenant.ExpireAt != nil && !moduleTenant.ExpireAt.Before(now) {
// 使用原到期时间 + SKU到期时间
duration := assetSukRes.ExpireAt.Sub(gtime.Now())
assetSukRes.ExpireAt = moduleTenant.ExpireAt.Add(duration)
}
// 更新模块租户关系
_, err = dao.ModuleTenant.Ctx(ctx).TX(tx).WherePri(moduleTenant.Id).Update(do.ModuleTenant{
UpdateBy: getUserInfo.UserName,
ExpireAt: assetSukRes.ExpireAt,
})
return
}
// 设置认证状态
certificationStatus := consts.CertificationStatusPass
if req.TenantModuleType == beans.TenantModuleTypeSupplier {
certificationStatus = consts.CertificationStatusUnverified
}
// 添加模块租户关系
_, err = dao.ModuleTenant.Ctx(ctx).TX(tx).InsertAndGetId(do.ModuleTenant{
CreateBy: getUserInfo.UserName,
UpdateBy: getUserInfo.UserName,
ModuleKey: moduleKey,
AssetId: assetSukRes.AssetId.Hex(),
AssetSkuId: req.AssetSkuId.Hex(),
TenantId: getUserInfo.TenantId,
TenantModuleType: req.TenantModuleType,
CertificationStatus: certificationStatus,
ExpireAt: assetSukRes.ExpireAt,
})
liberr.ErrIsNil(ctx, err, "添加模块租户关系失败")
// 设置缓存
_, err = s.AddRedisByTenantId(ctx, &system.AddRedisByTenantIdReq{
TenantId: getUserInfo.TenantId,
})
liberr.ErrIsNil(ctx, err, "设置缓存失败")
})
return err
})
return
}
// Check 检查模块开通状态
func (s *sModuleTenant) Check(ctx context.Context, req *system.ModuleTenantCheckReq) (res *system.ModuleTenantCheckRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
res = new(system.ModuleTenantCheckRes)
// 查询模块租户关系
moduleTenant, err := s.GetByModuleKeyAndTenantId(ctx, req.ModuleKey, req.TenantId)
liberr.ErrIsNil(ctx, err, "查询模块租户关系失败")
// 判断状态
if g.IsEmpty(moduleTenant) {
// 没有记录,未开通
res.Message = "您未开通此功能模块,请开通后再使用"
res.Status = false
} else {
_, err = s.AddRedisByTenantId(ctx, &system.AddRedisByTenantIdReq{
TenantId: req.TenantId,
})
liberr.ErrIsNil(ctx, err, "设置缓存失败")
// 有记录,检查是否到期
now := gtime.Now()
if moduleTenant.ExpireAt != nil && moduleTenant.ExpireAt.Before(now) {
res.Message = "功能模块已到期,请续期后再使用"
res.Status = false
} else {
res.Status = true
if moduleTenant.CertificationStatus == consts.CertificationStatusPass {
res.Message = "已开通"
res.CertificationStatus = true
} else {
keyValue := consts.GetCertificationStatusKeyValue(moduleTenant.CertificationStatus)
res.Message = fmt.Sprintf("功能模块认证状态:%s", keyValue.Value)
res.CertificationStatus = false
}
}
}
})
return
}
// GetByModuleKeyAndTenantId 根据模块Key和租户ID获取模块租户关系
func (s *sModuleTenant) GetByModuleKeyAndTenantId(ctx context.Context, moduleKey string, tenantId uint64) (moduleTenant *entity.ModuleTenant, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.ModuleTenant.Ctx(ctx).
Where(dao.ModuleTenant.Columns().ModuleKey, moduleKey).
Where(dao.ModuleTenant.Columns().TenantId, tenantId).
Scan(&moduleTenant)
liberr.ErrIsNil(ctx, err, "获取模块租户关系失败")
})
return
}
// AddRedisByTenantId 根据租户ID获取模块租户关系存到redis
func (s *sModuleTenant) AddRedisByTenantId(ctx context.Context, req *system.AddRedisByTenantIdReq) (res *system.AddRedisByTenantIdRes, err error) {
res = new(system.AddRedisByTenantIdRes)
//从数据库获取
err = dao.ModuleTenant.Ctx(ctx).
Where(dao.ModuleTenant.Columns().TenantId, req.TenantId).
Scan(&res.List)
liberr.ErrIsNil(ctx, err, "获取模块租户关系失败")
if !g.IsEmpty(res.List) {
err = g.Redis().SetEX(ctx, fmt.Sprintf("module_tenant:tenantId-%d", gconv.Int(req.TenantId)), res.List, gconv.Int64(time.Minute*1))
liberr.ErrIsNil(ctx, err, "设置缓存失败")
}
return
}

View File

@@ -0,0 +1,96 @@
/*
* @desc:xxxx功能描述
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/11/3 9:55
*/
package personal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/grand"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
service "github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/libUtils"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterPersonal(New())
}
type sPersonal struct {
}
func New() *sPersonal {
return &sPersonal{}
}
func (s *sPersonal) GetPersonalInfo(ctx context.Context, req *system.PersonalInfoReq) (res *system.PersonalInfoRes, err error) {
res = new(system.PersonalInfoRes)
userId := service.Context().GetUserId(ctx)
res.User, err = service.SysUser().GetUserInfoById(ctx, userId)
var dept *entity.SysDept
dept, err = service.SysDept().GetByDeptId(ctx, res.User.DeptId)
res.DeptName = dept.DeptName
allRoles, err := service.SysRole().GetRoleList(ctx)
roles, err := service.SysUser().GetAdminRole(ctx, userId, allRoles)
name := make([]string, len(roles))
roleIds := make([]uint, len(roles))
for k, v := range roles {
name[k] = v.Name
roleIds[k] = v.Id
}
res.Roles = name
if err != nil {
return
}
return
}
func (s *sPersonal) EditPersonal(ctx context.Context, req *system.PersonalEditReq) (user *model.LoginUserRes, err error) {
userId := service.Context().GetUserId(ctx)
err = service.SysUser().UserNameOrMobileExists(ctx, "", req.Mobile, int64(userId))
if err != nil {
return
}
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysUser.Ctx(ctx).TX(tx).WherePri(userId).Update(do.SysUser{
Mobile: req.Mobile,
UserNickname: req.Nickname,
Remark: req.Remark,
Sex: req.Sex,
UserEmail: req.UserEmail,
Describe: req.Describe,
Avatar: req.Avatar,
})
liberr.ErrIsNil(ctx, err, "修改用户信息失败")
user, err = service.SysUser().GetUserById(ctx, userId)
liberr.ErrIsNil(ctx, err)
})
return err
})
return
}
func (s *sPersonal) ResetPwdPersonal(ctx context.Context, req *system.PersonalResetPwdReq) (res *system.PersonalResetPwdRes, err error) {
userId := service.Context().GetUserId(ctx)
salt := grand.S(10)
password := libUtils.EncryptPassword(req.Password, salt)
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysUser.Ctx(ctx).WherePri(userId).Update(g.Map{
dao.SysUser.Columns().UserSalt: salt,
dao.SysUser.Columns().UserPassword: password,
})
liberr.ErrIsNil(ctx, err, "重置用户密码失败")
})
return
}

View File

@@ -0,0 +1,360 @@
/*
* @desc:菜单处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/23 16:14
*/
package sysAuthRule
import (
"context"
"fmt"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysAuthRule(New())
}
func New() *sSysAuthRule {
return &sSysAuthRule{}
}
type sSysAuthRule struct {
}
func (s *sSysAuthRule) GetMenuListSearch(ctx context.Context, req *system.RuleSearchReq) (res []*model.SysAuthRuleInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysAuthRule.Ctx(ctx)
if req.Title != "" {
m = m.Where("title like ?", "%"+req.Title+"%")
}
if req.Component != "" {
m = m.Where("component like ?", "%"+req.Component+"%")
}
err = m.Fields(model.SysAuthRuleInfoRes{}).Order("weigh desc,id asc").Scan(&res)
liberr.ErrIsNil(ctx, err, "获取菜单失败")
})
return
}
// GetIsMenuList 获取isMenu=0|1
func (s *sSysAuthRule) GetIsMenuList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) {
list, err := s.GetMenuList(ctx)
if err != nil {
return nil, err
}
var gList = make([]*model.SysAuthRuleInfoRes, 0, len(list))
for _, v := range list {
if v.MenuType == 0 || v.MenuType == 1 {
gList = append(gList, v)
}
}
return gList, nil
}
// GetMenuList 获取所有菜单
func (s *sSysAuthRule) GetMenuList(ctx context.Context) (list []*model.SysAuthRuleInfoRes, err error) {
cache := commonService.Cache()
//从缓存获取
iList := cache.GetOrSetFuncLock(ctx, consts.CacheSysAuthMenu, s.getMenuListFromDb, 0, consts.CacheSysAuthTag)
if !iList.IsEmpty() {
err = gconv.Struct(iList, &list)
liberr.ErrIsNil(ctx, err)
}
return
}
// GetMenuListByRole 根据角色获取所有菜单
func (s *sSysAuthRule) GetMenuListByRole(ctx context.Context) (list []*model.SysAuthRuleInfoRes, err error) {
cache := commonService.Cache()
//从缓存获取
iList := cache.GetOrSetFuncLock(ctx, consts.CacheSysAuthMenu, s.getMenuListFromDb, 0, consts.CacheSysAuthTag)
if !iList.IsEmpty() {
err = gconv.Struct(iList, &list)
liberr.ErrIsNil(ctx, err)
}
isSuperAdmin, err := service.SysUser().IsSuperAdmin(ctx, &system.IsSuperAdminReq{})
if err != nil {
return
}
if !isSuperAdmin {
// 根据token获取用户id
userId := service.Context().GetUserId(ctx)
if !g.IsEmpty(userId) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e, "获取权限引擎失败")
var userRole []string
userRole, err = enforcer.GetRolesForUser(fmt.Sprintf("%s%d", service.SysUser().GetCasBinUserPrefix(), service.Context().GetUserId(ctx)))
liberr.ErrIsNil(ctx, err, "获取用户角色失败")
userPermissions := enforcer.GetPermissionsForUser(userRole[0])
// 构建规则ID的map避免多次遍历
ruleMap := make(map[string]struct{})
for _, item := range userPermissions {
if len(item) > 1 {
ruleMap[item[1]] = struct{}{}
}
}
// 遍历菜单列表,判断 ruleMap 中是否包含 v.Id
var filteredList []*model.SysAuthRuleInfoRes
for _, v := range list {
if _, exists := ruleMap[gconv.String(v.Id)]; exists {
filteredList = append(filteredList, v)
}
}
list = filteredList
}
}
return
}
// 从数据库获取所有菜单
func (s *sSysAuthRule) getMenuListFromDb(ctx context.Context) (value interface{}, err error) {
err = g.Try(ctx, func(ctx context.Context) {
var v []*model.SysAuthRuleInfoRes
//从数据库获取
err = dao.SysAuthRule.Ctx(ctx).
Fields(model.SysAuthRuleInfoRes{}).Order("weigh desc,id asc").Scan(&v)
liberr.ErrIsNil(ctx, err, "获取菜单数据失败")
value = v
})
return
}
// GetIsButtonList 获取所有按钮isMenu=2 菜单列表
func (s *sSysAuthRule) GetIsButtonList(ctx context.Context) ([]*model.SysAuthRuleInfoRes, error) {
list, err := s.GetMenuList(ctx)
if err != nil {
return nil, err
}
var gList = make([]*model.SysAuthRuleInfoRes, 0, len(list))
for _, v := range list {
if v.MenuType == 2 {
gList = append(gList, v)
}
}
return gList, nil
}
// Add 添加菜单
func (s *sSysAuthRule) Add(ctx context.Context, req *system.RuleAddReq) (err error) {
if s.menuNameExists(ctx, req.Name, 0) {
err = gerror.New("接口规则已经存在")
return
}
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
//菜单数据
data := do.SysAuthRule{
Pid: req.Pid,
Name: req.Name,
Title: req.Title,
Icon: req.Icon,
Condition: req.Condition,
Remark: req.Remark,
MenuType: req.MenuType,
Weigh: req.Weigh,
IsHide: req.IsHide,
Path: req.Path,
Component: req.Component,
IsLink: req.IsLink,
IsIframe: req.IsIframe,
IsCached: req.IsCached,
Redirect: req.Redirect,
IsAffix: req.IsAffix,
LinkUrl: req.LinkUrl,
}
ruleId, e := dao.SysAuthRule.Ctx(ctx).TX(tx).InsertAndGetId(data)
liberr.ErrIsNil(ctx, e, "添加菜单失败")
e = s.BindRoleRule(ctx, ruleId, req.Roles)
liberr.ErrIsNil(ctx, e, "添加菜单失败")
})
return err
})
if err == nil {
// 删除相关缓存
commonService.Cache().Remove(ctx, consts.CacheSysAuthMenu)
}
return
}
// 检查菜单规则是否存在
func (s *sSysAuthRule) menuNameExists(ctx context.Context, name string, id uint) bool {
m := dao.SysAuthRule.Ctx(ctx).Where("name=?", name)
if id != 0 {
m = m.Where("id!=?", id)
}
c, err := m.Fields(dao.SysAuthRule.Columns().Id).Limit(1).One()
if err != nil {
g.Log().Error(ctx, err)
return false
}
return !c.IsEmpty()
}
// BindRoleRule 绑定角色权限
func (s *sSysAuthRule) BindRoleRule(ctx context.Context, ruleId interface{}, roleIds []uint) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
for _, roleId := range roleIds {
_, err = enforcer.AddPolicy(fmt.Sprintf("%d", roleId), fmt.Sprintf("%d", ruleId), "All")
liberr.ErrIsNil(ctx, err)
}
})
return
}
func (s *sSysAuthRule) Get(ctx context.Context, id uint) (rule *entity.SysAuthRule, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysAuthRule.Ctx(ctx).WherePri(id).Scan(&rule)
liberr.ErrIsNil(ctx, err, "获取菜单失败")
})
return
}
func (s *sSysAuthRule) GetMenuRoles(ctx context.Context, id uint) (roleIds []uint, err error) {
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
policies := enforcer.GetFilteredNamedPolicy("p", 1, gconv.String(id))
for _, policy := range policies {
roleIds = append(roleIds, gconv.Uint(policy[0]))
}
})
return
}
func (s *sSysAuthRule) Update(ctx context.Context, req *system.RuleUpdateReq) (err error) {
if s.menuNameExists(ctx, req.Name, req.Id) {
err = gerror.New("接口规则已经存在")
return
}
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
//菜单数据
data := do.SysAuthRule{
Pid: req.Pid,
Name: req.Name,
Title: req.Title,
Icon: req.Icon,
Condition: req.Condition,
Remark: req.Remark,
MenuType: req.MenuType,
Weigh: req.Weigh,
IsHide: req.IsHide,
Path: req.Path,
Component: req.Component,
IsLink: req.IsLink,
IsIframe: req.IsIframe,
IsCached: req.IsCached,
Redirect: req.Redirect,
IsAffix: req.IsAffix,
LinkUrl: req.LinkUrl,
}
_, e := dao.SysAuthRule.Ctx(ctx).TX(tx).WherePri(req.Id).Update(data)
liberr.ErrIsNil(ctx, e, "添加菜单失败")
e = s.UpdateRoleRule(ctx, req.Id, req.Roles)
liberr.ErrIsNil(ctx, e, "添加菜单失败")
})
return err
})
if err == nil {
// 删除相关缓存
commonService.Cache().Remove(ctx, consts.CacheSysAuthMenu)
}
return
}
func (s *sSysAuthRule) UpdateRoleRule(ctx context.Context, ruleId uint, roleIds []uint) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
//删除旧权限
_, e = enforcer.RemoveFilteredPolicy(1, gconv.String(ruleId))
liberr.ErrIsNil(ctx, e)
// 添加新权限
roleIdsStrArr := gconv.Strings(roleIds)
for _, v := range roleIdsStrArr {
_, e = enforcer.AddPolicy(v, gconv.String(ruleId), "All")
liberr.ErrIsNil(ctx, e)
}
})
return
}
func (s *sSysAuthRule) GetMenuListTree(pid uint, list []*model.SysAuthRuleInfoRes) []*model.SysAuthRuleTreeRes {
tree := make([]*model.SysAuthRuleTreeRes, 0, len(list))
for _, menu := range list {
if menu.Pid == pid {
t := &model.SysAuthRuleTreeRes{
SysAuthRuleInfoRes: menu,
}
child := s.GetMenuListTree(menu.Id, list)
if child != nil {
t.Children = child
}
tree = append(tree, t)
}
}
return tree
}
// DeleteMenuByIds 删除菜单
func (s *sSysAuthRule) DeleteMenuByIds(ctx context.Context, ids []int) (err error) {
var list []*model.SysAuthRuleInfoRes
list, err = s.GetMenuList(ctx)
if err != nil {
return
}
childrenIds := make([]int, 0, len(list))
for _, id := range ids {
rules := s.FindSonByParentId(list, gconv.Uint(id))
for _, child := range rules {
childrenIds = append(childrenIds, gconv.Int(child.Id))
}
}
ids = append(ids, childrenIds...)
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
return g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysAuthRule.Ctx(ctx).Where("id in (?)", ids).Delete()
liberr.ErrIsNil(ctx, err, "删除失败")
//删除权限
enforcer, err := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, err)
for _, v := range ids {
_, err = enforcer.RemoveFilteredPolicy(1, gconv.String(v))
liberr.ErrIsNil(ctx, err)
}
// 删除相关缓存
commonService.Cache().Remove(ctx, consts.CacheSysAuthMenu)
})
})
return
}
func (s *sSysAuthRule) FindSonByParentId(list []*model.SysAuthRuleInfoRes, pid uint) []*model.SysAuthRuleInfoRes {
children := make([]*model.SysAuthRuleInfoRes, 0, len(list))
for _, v := range list {
if v.Pid == pid {
children = append(children, v)
fChildren := s.FindSonByParentId(list, v.Id)
children = append(children, fChildren...)
}
}
return children
}

View File

@@ -0,0 +1,198 @@
/*
* @desc:部门管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/26 15:14
*/
package sysDept
import (
"context"
"database/sql"
"gitea.com/red-future/common/beans"
"gitea.com/red-future/common/utils"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysDept(New())
}
func New() *sSysDept {
return &sSysDept{}
}
type sSysDept struct {
}
func (s *sSysDept) GetList(ctx context.Context, req *system.DeptSearchReq) (list []*entity.SysDept, err error) {
list, err = s.GetFromCache(ctx)
if err != nil {
return
}
var getUserInfo *beans.User
getUserInfo, err = utils.GetUserInfo(ctx)
liberr.ErrIsNil(ctx, err)
rList := make([]*entity.SysDept, 0, len(list))
for _, v := range list {
if gconv.Uint64(getUserInfo.TenantId) != v.TenantId {
continue
}
if req.DeptName != "" || req.Status != "" {
if req.DeptName != "" && !gstr.ContainsI(v.DeptName, req.DeptName) {
continue
}
if req.Status != "" && v.Status != gconv.Uint(req.Status) {
continue
}
}
rList = append(rList, v)
}
list = rList
return
}
func (s *sSysDept) GetFromCache(ctx context.Context) (list []*entity.SysDept, err error) {
err = g.Try(ctx, func(ctx context.Context) {
cache := commonService.Cache()
//从缓存获取
iList := cache.GetOrSetFuncLock(ctx, consts.CacheSysDept, func(ctx context.Context) (value interface{}, err error) {
err = dao.SysDept.Ctx(ctx).Scan(&list)
liberr.ErrIsNil(ctx, err, "获取部门列表失败")
value = list
return
}, 0, consts.CacheSysAuthTag)
if !iList.IsEmpty() {
err = gconv.Struct(iList, &list)
liberr.ErrIsNil(ctx, err)
}
})
return
}
// Add 添加部门
func (s *sSysDept) Add(ctx context.Context, req *system.DeptAddReq) (id int64, err error) {
err = g.Try(ctx, func(ctx context.Context) {
if g.IsEmpty(req.TenantId) {
var getUserInfo *beans.User
getUserInfo, err = utils.GetUserInfo(ctx)
liberr.ErrIsNil(ctx, err)
req.TenantId = gconv.Uint64(getUserInfo.TenantId)
}
var insertId sql.Result
insertId, err = dao.SysDept.Ctx(ctx).Insert(do.SysDept{
ParentId: req.ParentID,
DeptName: req.DeptName,
OrderNum: req.OrderNum,
Leader: req.Leader,
Phone: req.Phone,
Email: req.Email,
Status: req.Status,
CreatedBy: service.Context().GetUserId(ctx),
TenantId: req.TenantId,
})
liberr.ErrIsNil(ctx, err, "添加部门失败")
id, err = insertId.LastInsertId()
liberr.ErrIsNil(ctx, err, "获取插入id失败")
// 删除缓存
commonService.Cache().Remove(ctx, consts.CacheSysDept)
})
return
}
// Edit 部门修改
func (s *sSysDept) Edit(ctx context.Context, req *system.DeptEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysDept.Ctx(ctx).WherePri(req.DeptId).Update(do.SysDept{
ParentId: req.ParentID,
DeptName: req.DeptName,
OrderNum: req.OrderNum,
Leader: req.Leader,
Phone: req.Phone,
Email: req.Email,
Status: req.Status,
UpdatedBy: service.Context().GetUserId(ctx),
})
liberr.ErrIsNil(ctx, err, "修改部门失败")
// 删除缓存
commonService.Cache().Remove(ctx, consts.CacheSysDept)
})
return
}
func (s *sSysDept) Delete(ctx context.Context, id uint64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
var list []*entity.SysDept
err = dao.SysDept.Ctx(ctx).Scan(&list)
liberr.ErrIsNil(ctx, err, "不存在部门信息")
children := s.FindSonByParentId(list, id)
ids := make([]uint64, 0, len(list))
for _, v := range children {
ids = append(ids, v.DeptId)
}
ids = append(ids, id)
_, err = dao.SysDept.Ctx(ctx).Where(dao.SysDept.Columns().DeptId+" in (?)", ids).Delete()
liberr.ErrIsNil(ctx, err, "删除部门失败")
// 删除缓存
commonService.Cache().Remove(ctx, consts.CacheSysDept)
})
return
}
func (s *sSysDept) FindSonByParentId(deptList []*entity.SysDept, deptId uint64) []*entity.SysDept {
children := make([]*entity.SysDept, 0, len(deptList))
for _, v := range deptList {
if v.ParentId == deptId {
children = append(children, v)
fChildren := s.FindSonByParentId(deptList, v.DeptId)
children = append(children, fChildren...)
}
}
return children
}
// GetListTree 部门树形菜单
func (s *sSysDept) GetListTree(pid uint64, list []*entity.SysDept) (deptTree []*model.SysDeptTreeRes) {
deptTree = make([]*model.SysDeptTreeRes, 0, len(list))
for _, v := range list {
if v.ParentId == pid {
t := &model.SysDeptTreeRes{
SysDept: v,
}
child := s.GetListTree(v.DeptId, list)
if len(child) > 0 {
t.Children = child
}
deptTree = append(deptTree, t)
}
}
return
}
// GetByDeptId 通过部门id获取部门信息
func (s *sSysDept) GetByDeptId(ctx context.Context, deptId uint64) (dept *entity.SysDept, err error) {
var depts []*entity.SysDept
depts, err = s.GetFromCache(ctx)
if err != nil {
return
}
for _, v := range depts {
if v.DeptId == deptId {
dept = v
break
}
}
return
}

View File

@@ -0,0 +1,103 @@
/*
* @desc:登录日志
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/26 15:20
*/
package sysLoginLog
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/grpool"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysLoginLog(New())
}
func New() *sSysLoginLog {
return &sSysLoginLog{
Pool: grpool.New(100),
}
}
type sSysLoginLog struct {
Pool *grpool.Pool
}
func (s *sSysLoginLog) Invoke(ctx context.Context, data *model.LoginLogParams) {
s.Pool.Add(
ctx,
func(ctx context.Context) {
//写入日志数据
service.SysUser().LoginLog(ctx, data)
},
)
}
func (s *sSysLoginLog) List(ctx context.Context, req *system.LoginLogSearchReq) (res *system.LoginLogSearchRes, err error) {
res = new(system.LoginLogSearchRes)
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
m := dao.SysLoginLog.Ctx(ctx)
order := "info_id DESC"
if req.LoginName != "" {
m = m.Where("login_name like ?", "%"+req.LoginName+"%")
}
if req.Status != "" {
m = m.Where("status", gconv.Int(req.Status))
}
if req.Ipaddr != "" {
m = m.Where("ipaddr like ?", "%"+req.Ipaddr+"%")
}
if req.LoginLocation != "" {
m = m.Where("login_location like ?", "%"+req.LoginLocation+"%")
}
if len(req.DateRange) != 0 {
m = m.Where("login_time >=? AND login_time <=?", req.DateRange[0], req.DateRange[1])
}
if req.SortName != "" {
if req.SortOrder != "" {
order = req.SortName + " " + req.SortOrder
} else {
order = req.SortName + " DESC"
}
}
err = g.Try(ctx, func(ctx context.Context) {
res.Total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取日志失败")
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res.List)
liberr.ErrIsNil(ctx, err, "获取日志数据失败")
})
return
}
func (s *sSysLoginLog) DeleteLoginLogByIds(ctx context.Context, ids []int) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysLoginLog.Ctx(ctx).Delete("info_id in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}
func (s *sSysLoginLog) ClearLoginLog(ctx context.Context) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = g.DB().Ctx(ctx).Exec(ctx, "truncate "+dao.SysLoginLog.Table())
liberr.ErrIsNil(ctx, err, "清除失败")
})
return
}

View File

@@ -0,0 +1,195 @@
/*
* @desc:后台操作日志业务处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/21 16:14
*/
package sysOperLog
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/grpool"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/text/gstr"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/libUtils"
"github.com/tiger1103/gfast/v3/library/liberr"
)
type sOperateLog struct {
Pool *grpool.Pool
}
func init() {
service.RegisterOperateLog(New())
}
func New() *sOperateLog {
return &sOperateLog{
Pool: grpool.New(100),
}
}
// OperationLog 操作日志写入
func (s *sOperateLog) OperationLog(r *ghttp.Request) {
userInfo := service.Context().GetLoginUser(r.GetCtx())
if userInfo == nil {
return
}
url := r.Request.URL //请求地址
//获取菜单
//获取地址对应的菜单id
menuList, err := service.SysAuthRule().GetMenuList(r.GetCtx())
if err != nil {
g.Log().Error(r.GetCtx(), err)
return
}
var menu *model.SysAuthRuleInfoRes
path := gstr.TrimLeft(url.Path, "/")
for _, m := range menuList {
if gstr.Equal(m.Name, path) {
menu = m
break
}
}
data := &model.SysOperLogAdd{
User: userInfo,
Menu: menu,
Url: url,
Params: r.GetMap(),
Method: r.Method,
ClientIp: libUtils.GetClientIp(r.GetCtx()),
OperatorType: 1,
}
s.Invoke(gctx.New(), data)
}
func (s *sOperateLog) Invoke(ctx context.Context, data *model.SysOperLogAdd) {
s.Pool.Add(ctx, func(ctx context.Context) {
//写入日志数据
s.operationLogAdd(ctx, data)
})
}
// OperationLogAdd 添加操作日志
func (s *sOperateLog) operationLogAdd(ctx context.Context, data *model.SysOperLogAdd) {
menuTitle := ""
if data.Menu != nil {
menuTitle = data.Menu.Title
}
dept, err := service.SysDept().GetByDeptId(ctx, data.User.DeptId)
if err != nil {
g.Log().Error(ctx, err)
return
}
if dept == nil {
dept = &entity.SysDept{}
}
insertData := &do.SysOperLog{
Title: menuTitle,
Method: data.Url.Path,
RequestMethod: data.Method,
OperatorType: data.OperatorType,
OperName: data.User.UserName,
DeptName: dept.DeptName,
OperIp: data.ClientIp,
OperLocation: libUtils.GetCityByIp(data.ClientIp),
OperTime: gtime.Now(),
OperParam: data.Params,
}
rawQuery := data.Url.RawQuery
if rawQuery != "" {
rawQuery = "?" + rawQuery
}
insertData.OperUrl = data.Url.Path + rawQuery
_, err = dao.SysOperLog.Ctx(ctx).Insert(insertData)
if err != nil {
g.Log().Error(ctx, err)
}
}
func (s *sOperateLog) List(ctx context.Context, req *system.SysOperLogSearchReq) (listRes *system.SysOperLogSearchRes, err error) {
listRes = new(system.SysOperLogSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysOperLog.Ctx(ctx)
if req.Title != "" {
m = m.Where(dao.SysOperLog.Columns().Title+" = ?", req.Title)
}
if req.RequestMethod != "" {
m = m.Where(dao.SysOperLog.Columns().RequestMethod+" = ?", req.RequestMethod)
}
if req.OperName != "" {
m = m.Where(dao.SysOperLog.Columns().OperName+" like ?", "%"+req.OperName+"%")
}
if len(req.DateRange) != 0 {
m = m.Where("oper_time >=? AND oper_time <=?", req.DateRange[0], req.DateRange[1])
}
listRes.Total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if req.PageNum == 0 {
req.PageNum = 1
}
listRes.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "oper_id DESC"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.SysOperLogInfoRes
err = m.Fields(system.SysOperLogSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.SysOperLogListRes, len(res))
for k, v := range res {
listRes.List[k] = &model.SysOperLogListRes{
OperId: v.OperId,
Title: v.Title,
RequestMethod: v.RequestMethod,
OperName: v.OperName,
DeptName: v.DeptName,
LinkedDeptName: v.LinkedDeptName,
OperUrl: v.OperUrl,
OperIp: v.OperIp,
OperLocation: v.OperLocation,
OperParam: v.OperParam,
OperTime: v.OperTime,
}
}
})
return
}
func (s *sOperateLog) GetByOperId(ctx context.Context, operId uint64) (res *model.SysOperLogInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysOperLog.Ctx(ctx).WithAll().Where(dao.SysOperLog.Columns().OperId, operId).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取信息失败")
})
return
}
func (s *sOperateLog) DeleteByIds(ctx context.Context, ids []uint64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysOperLog.Ctx(ctx).Delete("oper_id in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}
func (s *sOperateLog) ClearLog(ctx context.Context) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = g.DB().Ctx(ctx).Exec(ctx, "truncate "+dao.SysOperLog.Table())
liberr.ErrIsNil(ctx, err, "清除失败")
})
return
}

View File

@@ -0,0 +1,111 @@
/*
* @desc:岗位管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/26 15:28
*/
package sysPost
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysPost(New())
}
func New() *sSysPost {
return &sSysPost{}
}
type sSysPost struct {
}
// List 岗位列表
func (s *sSysPost) List(ctx context.Context, req *system.PostSearchReq) (res *system.PostSearchRes, err error) {
res = new(system.PostSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysPost.Ctx(ctx)
if req != nil {
if req.PostCode != "" {
m = m.Where("post_code like ?", "%"+req.PostCode+"%")
}
if req.PostName != "" {
m = m.Where("post_name like ?", "%"+req.PostName+"%")
}
if req.Status != "" {
m = m.Where("status", gconv.Uint(req.Status))
}
}
res.Total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取岗位失败")
if req.PageNum == 0 {
req.PageNum = 1
}
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
res.CurrentPage = req.PageNum
err = m.Page(req.PageNum, req.PageSize).Order("post_sort asc,post_id asc").Scan(&res.PostList)
liberr.ErrIsNil(ctx, err, "获取岗位失败")
})
return
}
func (s *sSysPost) Add(ctx context.Context, req *system.PostAddReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysPost.Ctx(ctx).Insert(do.SysPost{
PostCode: req.PostCode,
PostName: req.PostName,
PostSort: req.PostSort,
Status: req.Status,
Remark: req.Remark,
CreatedBy: service.Context().GetUserId(ctx),
})
liberr.ErrIsNil(ctx, err, "添加岗位失败")
})
return
}
func (s *sSysPost) Edit(ctx context.Context, req *system.PostEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysPost.Ctx(ctx).WherePri(req.PostId).Update(do.SysPost{
PostCode: req.PostCode,
PostName: req.PostName,
PostSort: req.PostSort,
Status: req.Status,
Remark: req.Remark,
UpdatedBy: service.Context().GetUserId(ctx),
})
liberr.ErrIsNil(ctx, err, "修改岗位失败")
})
return
}
func (s *sSysPost) Delete(ctx context.Context, ids []int) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysPost.Ctx(ctx).Where(dao.SysPost.Columns().PostId+" in(?)", ids).Delete()
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}
// GetUsedPost 获取正常状态的岗位
func (s *sSysPost) GetUsedPost(ctx context.Context) (list []*entity.SysPost, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysPost.Ctx(ctx).Where(dao.SysPost.Columns().Status, 1).
Order(dao.SysPost.Columns().PostSort + " ASC, " + dao.SysPost.Columns().PostId + " ASC ").Scan(&list)
liberr.ErrIsNil(ctx, err, "获取岗位数据失败")
})
return
}

View File

@@ -0,0 +1,225 @@
/*
* @desc:角色管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/26 15:54
*/
package sysRole
import (
"context"
"gitea.com/red-future/common/beans"
"gitea.com/red-future/common/utils"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysRole(New())
}
func New() *sSysRole {
return &sSysRole{}
}
type sSysRole struct {
}
func (s *sSysRole) GetRoleListSearch(ctx context.Context, req *system.RoleListReq) (res *system.RoleListRes, err error) {
res = new(system.RoleListRes)
g.Try(ctx, func(ctx context.Context) {
model := dao.SysRole.Ctx(ctx)
var getUserInfo *beans.User
getUserInfo, err = utils.GetUserInfo(ctx)
liberr.ErrIsNil(ctx, err)
model = model.Where("tenant_id", gconv.Uint64(getUserInfo.TenantId))
if req.RoleName != "" {
model = model.Where("name like ?", "%"+req.RoleName+"%")
}
if req.Status != "" {
model = model.Where("status", gconv.Int(req.Status))
}
res.Total, err = model.Count()
liberr.ErrIsNil(ctx, err, "获取角色数据失败")
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
err = model.Page(res.CurrentPage, req.PageSize).Order("id asc").Scan(&res.List)
liberr.ErrIsNil(ctx, err, "获取数据失败")
})
return
}
// GetRoleList 获取角色列表
func (s *sSysRole) GetRoleList(ctx context.Context) (list []*entity.SysRole, err error) {
cache := commonService.Cache()
//从缓存获取
iList := cache.GetOrSetFuncLock(ctx, consts.CacheSysRole, s.getRoleListFromDb, 0, consts.CacheSysAuthTag)
if !iList.IsEmpty() {
err = gconv.Struct(iList, &list)
}
return
}
// GetRoleListInfo 获取角色列表信息
func (s *sSysRole) GetRoleListInfo(ctx context.Context) (list []*entity.SysRole, err error) {
cache := commonService.Cache()
//从缓存获取
iList := cache.GetOrSetFuncLock(ctx, consts.CacheSysRole, s.getRoleListFromDb, 0, consts.CacheSysAuthTag)
if !iList.IsEmpty() {
err = gconv.Struct(iList, &list)
}
var user *beans.User
user, err = utils.GetUserInfo(ctx)
liberr.ErrIsNil(ctx, err)
rList := make([]*entity.SysRole, 0, len(list))
for _, v := range list {
if !g.IsEmpty(user.TenantId) && gconv.Uint64(user.TenantId) != v.TenantId {
continue
}
rList = append(rList, v)
}
list = rList
return
}
// 从数据库获取所有角色
func (s *sSysRole) getRoleListFromDb(ctx context.Context) (value interface{}, err error) {
err = g.Try(ctx, func(ctx context.Context) {
var v []*entity.SysRole
//从数据库获取
err = dao.SysRole.Ctx(ctx).
Order(dao.SysRole.Columns().ListOrder + " asc," + dao.SysRole.Columns().Id + " asc").
Scan(&v)
liberr.ErrIsNil(ctx, err, "获取角色数据失败")
value = v
})
return
}
// AddRoleRule 添加角色权限
func (s *sSysRole) AddRoleRule(ctx context.Context, ruleIds []uint, roleId int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
ruleIdsStr := gconv.Strings(ruleIds)
for _, v := range ruleIdsStr {
_, err = enforcer.AddPolicy(gconv.String(roleId), v, "All")
liberr.ErrIsNil(ctx, err)
}
})
return
}
// DelRoleRule 删除角色权限
func (s *sSysRole) DelRoleRule(ctx context.Context, roleId int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
_, err = enforcer.RemoveFilteredPolicy(0, gconv.String(roleId))
liberr.ErrIsNil(ctx, e)
})
return
}
func (s *sSysRole) AddRole(ctx context.Context, req *system.RoleAddReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
var getUserInfo *beans.User
getUserInfo, err = utils.GetUserInfo(ctx)
liberr.ErrIsNil(ctx, err)
req.TenantId = gconv.Uint64(gconv.Uint64(getUserInfo.TenantId))
roleId, e := dao.SysRole.Ctx(ctx).TX(tx).InsertAndGetId(req)
liberr.ErrIsNil(ctx, e, "添加角色失败")
//添加角色权限
e = s.AddRoleRule(ctx, req.MenuIds, roleId)
liberr.ErrIsNil(ctx, e)
//清除缓存
commonService.Cache().Remove(ctx, consts.CacheSysRole)
})
return err
})
return
}
func (s *sSysRole) Get(ctx context.Context, id uint) (res *entity.SysRole, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysRole.Ctx(ctx).WherePri(id).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取角色信息失败")
})
return
}
// GetFilteredNamedPolicy 获取角色关联的菜单规则
func (s *sSysRole) GetFilteredNamedPolicy(ctx context.Context, id uint) (gpSlice []int, err error) {
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
gp := enforcer.GetFilteredNamedPolicy("p", 0, gconv.String(id))
gpSlice = make([]int, len(gp))
for k, v := range gp {
gpSlice[k] = gconv.Int(v[1])
}
})
return
}
// EditRole 修改角色
func (s *sSysRole) EditRole(ctx context.Context, req *system.RoleEditReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
_, e := dao.SysRole.Ctx(ctx).TX(tx).WherePri(req.Id).Data(&do.SysRole{
Status: req.Status,
ListOrder: req.ListOrder,
Name: req.Name,
Remark: req.Remark,
}).Update()
liberr.ErrIsNil(ctx, e, "修改角色失败")
//删除角色权限
e = s.DelRoleRule(ctx, req.Id)
liberr.ErrIsNil(ctx, e)
//添加角色权限
e = s.AddRoleRule(ctx, req.MenuIds, req.Id)
liberr.ErrIsNil(ctx, e)
//清除缓存
commonService.Cache().Remove(ctx, consts.CacheSysRole)
})
return err
})
return
}
// DeleteByIds 删除角色
func (s *sSysRole) DeleteByIds(ctx context.Context, ids []int64) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysRole.Ctx(ctx).TX(tx).Where(dao.SysRole.Columns().Id+" in(?)", ids).Delete()
liberr.ErrIsNil(ctx, err, "删除角色失败")
//删除角色权限
for _, v := range ids {
err = s.DelRoleRule(ctx, v)
liberr.ErrIsNil(ctx, err)
}
//清除缓存
commonService.Cache().Remove(ctx, consts.CacheSysRole)
})
return err
})
return
}

View File

@@ -0,0 +1,784 @@
/*
* @desc:用户处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/23 15:08
*/
package sysUser
import (
"context"
"fmt"
"gitea.com/red-future/common/beans"
"gitea.com/red-future/common/utils"
"github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
"github.com/mssola/user_agent"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/libUtils"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysUser(New())
}
type sSysUser struct {
casBinUserPrefix string //CasBin 用户id前缀
}
func New() *sSysUser {
return &sSysUser{
casBinUserPrefix: "u_",
}
}
func (s *sSysUser) GetCasBinUserPrefix() string {
return s.casBinUserPrefix
}
func (s *sSysUser) NotCheckAuthAdminIds(ctx context.Context) *gset.Set {
ids := g.Cfg().MustGet(ctx, "system.notCheckAuthAdminIds")
if !g.IsNil(ids) {
return gset.NewFrom(ids)
}
return gset.New()
}
func (s *sSysUser) GetAdminUserByUsernamePassword(ctx context.Context, req *system.UserLoginReq) (user *model.LoginUserRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
user, err = s.GetUserByUsername(ctx, req.Username)
liberr.ErrIsNil(ctx, err)
liberr.ValueIsNil(user, "账号密码错误")
//验证密码
if libUtils.EncryptPassword(req.Password, user.UserSalt) != user.UserPassword {
liberr.ErrIsNil(ctx, gerror.New("账号密码错误"))
}
//账号状态
if user.UserStatus == 0 {
liberr.ErrIsNil(ctx, gerror.New("账号已被冻结"))
}
})
return
}
// GetUserByUsername 通过用户名获取用户信息
func (s *sSysUser) GetUserByUsername(ctx context.Context, userName string) (user *model.LoginUserRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
user = &model.LoginUserRes{}
err = dao.SysUser.Ctx(ctx).Fields(user).Where(dao.SysUser.Columns().UserName, userName).Scan(user)
liberr.ErrIsNil(ctx, err, "账号密码错误")
})
return
}
// GetUserById 通过用户名获取用户信息
func (s *sSysUser) GetUserById(ctx context.Context, id uint64) (user *model.LoginUserRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
user = &model.LoginUserRes{}
err = dao.SysUser.Ctx(ctx).Fields(user).WherePri(id).Scan(user)
liberr.ErrIsNil(ctx, err, "获取用户信息失败")
})
return
}
// LoginLog 记录登录日志
func (s *sSysUser) LoginLog(ctx context.Context, params *model.LoginLogParams) {
ua := user_agent.New(params.UserAgent)
browser, _ := ua.Browser()
loginData := &do.SysLoginLog{
LoginName: params.Username,
Ipaddr: params.Ip,
LoginLocation: libUtils.GetCityByIp(params.Ip),
Browser: browser,
Os: ua.OS(),
Status: params.Status,
Msg: params.Msg,
LoginTime: gtime.Now(),
Module: params.Module,
}
_, err := dao.SysLoginLog.Ctx(ctx).Insert(loginData)
if err != nil {
g.Log().Error(ctx, err)
}
}
func (s *sSysUser) UpdateLoginInfo(ctx context.Context, id uint64, ip string) (err error) {
g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysUser.Ctx(ctx).WherePri(id).Unscoped().Update(g.Map{
dao.SysUser.Columns().LastLoginIp: ip,
dao.SysUser.Columns().LastLoginTime: gtime.Now(),
})
liberr.ErrIsNil(ctx, err, "更新用户登录信息失败")
})
return
}
// GetAdminRules 获取用户菜单数据
func (s *sSysUser) GetAdminRules(ctx context.Context, userId uint64) (menuList []*model.UserMenus, permissions []string, err error) {
err = g.Try(ctx, func(ctx context.Context) {
//是否超管
isSuperAdmin := false
//获取无需验证权限的用户id
s.NotCheckAuthAdminIds(ctx).Iterator(func(v interface{}) bool {
if gconv.Uint64(v) == userId {
isSuperAdmin = true
return false
}
return true
})
//获取用户菜单数据
allRoles, err := service.SysRole().GetRoleList(ctx)
liberr.ErrIsNil(ctx, err)
roles, err := s.GetAdminRole(ctx, userId, allRoles)
liberr.ErrIsNil(ctx, err)
name := make([]string, len(roles))
roleIds := make([]uint, len(roles))
for k, v := range roles {
name[k] = v.Name
roleIds[k] = v.Id
}
//获取菜单信息
if isSuperAdmin {
//超管获取所有菜单
permissions = []string{"*/*/*"}
menuList, err = s.GetAllMenus(ctx)
liberr.ErrIsNil(ctx, err)
} else {
menuList, err = s.GetAdminMenusByRoleIds(ctx, roleIds)
liberr.ErrIsNil(ctx, err)
permissions, err = s.GetPermissions(ctx, roleIds)
liberr.ErrIsNil(ctx, err)
}
})
return
}
// GetAdminRole 获取用户角色
func (s *sSysUser) GetAdminRole(ctx context.Context, userId uint64, allRoleList []*entity.SysRole) (roles []*entity.SysRole, err error) {
var roleIds []uint
roleIds, err = s.GetAdminRoleIds(ctx, userId)
if err != nil {
return
}
roles = make([]*entity.SysRole, 0, len(allRoleList))
for _, v := range allRoleList {
for _, id := range roleIds {
if id == v.Id {
roles = append(roles, v)
}
}
if len(roles) == len(roleIds) {
break
}
}
return
}
// GetAdminRoleIds 获取用户角色ids
func (s *sSysUser) GetAdminRoleIds(ctx context.Context, userId uint64) (roleIds []uint, err error) {
enforcer, e := commonService.CasbinEnforcer(ctx)
if e != nil {
err = e
return
}
//查询关联角色规则
groupPolicy := enforcer.GetFilteredGroupingPolicy(0, fmt.Sprintf("%s%d", s.casBinUserPrefix, userId))
if len(groupPolicy) > 0 {
roleIds = make([]uint, len(groupPolicy))
//得到角色id的切片
for k, v := range groupPolicy {
roleIds[k] = gconv.Uint(v[1])
}
}
return
}
func (s *sSysUser) GetAllMenus(ctx context.Context) (menus []*model.UserMenus, err error) {
//获取所有开启的菜单
var allMenus []*model.SysAuthRuleInfoRes
allMenus, err = service.SysAuthRule().GetIsMenuList(ctx)
if err != nil {
return
}
menus = make([]*model.UserMenus, len(allMenus))
for k, v := range allMenus {
var menu *model.UserMenu
menu = s.setMenuData(menu, v)
menus[k] = &model.UserMenus{UserMenu: menu}
}
menus = s.GetMenusTree(menus, 0)
return
}
func (s *sSysUser) GetAdminMenusByRoleIds(ctx context.Context, roleIds []uint) (menus []*model.UserMenus, err error) {
//获取角色对应的菜单id
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
menuIds := map[int64]int64{}
for _, roleId := range roleIds {
//查询当前权限
gp := enforcer.GetFilteredPolicy(0, gconv.String(roleId))
for _, p := range gp {
mid := gconv.Int64(p[1])
menuIds[mid] = mid
}
}
//获取所有开启的菜单
allMenus, err := service.SysAuthRule().GetIsMenuList(ctx)
liberr.ErrIsNil(ctx, err)
menus = make([]*model.UserMenus, 0, len(allMenus))
for _, v := range allMenus {
if _, ok := menuIds[gconv.Int64(v.Id)]; gstr.Equal(v.Condition, "nocheck") || ok {
var roleMenu *model.UserMenu
roleMenu = s.setMenuData(roleMenu, v)
menus = append(menus, &model.UserMenus{UserMenu: roleMenu})
}
}
menus = s.GetMenusTree(menus, 0)
})
return
}
func (s *sSysUser) GetMenusTree(menus []*model.UserMenus, pid uint) []*model.UserMenus {
returnList := make([]*model.UserMenus, 0, len(menus))
for _, menu := range menus {
if menu.Pid == pid {
menu.Children = s.GetMenusTree(menus, menu.Id)
returnList = append(returnList, menu)
}
}
return returnList
}
func (s *sSysUser) setMenuData(menu *model.UserMenu, entity *model.SysAuthRuleInfoRes) *model.UserMenu {
menu = &model.UserMenu{
Id: entity.Id,
Pid: entity.Pid,
Name: gstr.CaseCamelLower(gstr.Replace(entity.Name, "/", "_")),
Component: entity.Component,
Path: entity.Path,
MenuMeta: &model.MenuMeta{
Icon: entity.Icon,
Title: entity.Title,
IsLink: "",
IsHide: entity.IsHide == 1,
IsKeepAlive: entity.IsCached == 1,
IsAffix: entity.IsAffix == 1,
IsIframe: entity.IsIframe == 1,
},
}
if menu.MenuMeta.IsIframe || entity.IsLink == 1 {
menu.MenuMeta.IsLink = entity.LinkUrl
}
return menu
}
func (s *sSysUser) GetPermissions(ctx context.Context, roleIds []uint) (userButtons []string, err error) {
err = g.Try(ctx, func(ctx context.Context) {
//获取角色对应的菜单id
enforcer, err := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, err)
menuIds := map[int64]int64{}
for _, roleId := range roleIds {
//查询当前权限
gp := enforcer.GetFilteredPolicy(0, gconv.String(roleId))
for _, p := range gp {
mid := gconv.Int64(p[1])
menuIds[mid] = mid
}
}
//获取所有开启的按钮
allButtons, err := service.SysAuthRule().GetIsButtonList(ctx)
liberr.ErrIsNil(ctx, err)
userButtons = make([]string, 0, len(allButtons))
for _, button := range allButtons {
if _, ok := menuIds[gconv.Int64(button.Id)]; gstr.Equal(button.Condition, "nocheck") || ok {
userButtons = append(userButtons, button.Name)
}
}
})
return
}
// List 用户列表
func (s *sSysUser) List(ctx context.Context, req *system.UserSearchReq) (total interface{}, userList []*entity.SysUser, err error) {
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysUser.Ctx(ctx)
if req.KeyWords != "" {
keyWords := "%" + req.KeyWords + "%"
m = m.Where("user_name like ? or user_nickname like ?", keyWords, keyWords)
}
if req.DeptId != "" {
deptIds, e := s.getSearchDeptIds(ctx, gconv.Uint64(req.DeptId))
liberr.ErrIsNil(ctx, e)
m = m.Where("dept_id in (?)", deptIds)
}
if req.Status != "" {
m = m.Where("user_status", gconv.Int(req.Status))
}
if req.Mobile != "" {
m = m.Where("mobile like ?", "%"+req.Mobile+"%")
}
if len(req.DateRange) > 0 {
m = m.Where("created_at >=? AND created_at <=?", req.DateRange[0], req.DateRange[1])
}
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
if req.PageNum == 0 {
req.PageNum = 1
}
total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取用户数据失败")
err = m.FieldsEx(dao.SysUser.Columns().UserPassword, dao.SysUser.Columns().UserSalt).
Page(req.PageNum, req.PageSize).Order("id asc").Scan(&userList)
liberr.ErrIsNil(ctx, err, "获取用户列表失败")
})
return
}
// GetUsersRoleDept 获取多个用户角色 部门信息
func (s *sSysUser) GetUsersRoleDept(ctx context.Context, userList []*entity.SysUser) (users []*model.SysUserRoleDeptRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
allRoles, e := service.SysRole().GetRoleList(ctx)
liberr.ErrIsNil(ctx, e)
depts, e := service.SysDept().GetFromCache(ctx)
liberr.ErrIsNil(ctx, e)
users = make([]*model.SysUserRoleDeptRes, len(userList))
for k, u := range userList {
var dept *entity.SysDept
users[k] = &model.SysUserRoleDeptRes{
SysUser: u,
}
for _, d := range depts {
if u.DeptId == uint64(d.DeptId) {
dept = d
}
}
users[k].Dept = dept
roles, e := s.GetAdminRole(ctx, u.Id, allRoles)
liberr.ErrIsNil(ctx, e)
for _, r := range roles {
users[k].RoleInfo = append(users[k].RoleInfo, &model.SysUserRoleInfoRes{RoleId: r.Id, Name: r.Name})
}
}
})
return
}
// GetList 用户列表(根据当前租户)
func (s *sSysUser) GetList(ctx context.Context, req *system.GetUserSearchReq) (total interface{}, userList []*entity.SysUser, err error) {
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysUser.Ctx(ctx)
var getUserInfo *beans.User
getUserInfo, err = utils.GetUserInfo(ctx)
liberr.ErrIsNil(ctx, err)
var tenantDetails *entity.Tenant
tenantDetails, err = service.Tenant().GetTenantDetails(ctx, gconv.Uint64(getUserInfo.TenantId))
liberr.ErrIsNil(ctx, err)
if tenantDetails.TenantType == consts.TenantTypeAgent {
var adminByIdList []entity.Tenant
adminByIdList, err = service.Tenant().GetTenantAdminById(ctx, tenantDetails.Id)
liberr.ErrIsNil(ctx, err)
idList := make([]uint64, 0)
for _, user := range adminByIdList {
idList = append(idList, gconv.Uint64(user.AdminBy))
}
m = m.Where("id in (?)", idList)
} else {
m = m.Where("tenant_id", tenantDetails.Id)
}
if req.KeyWords != "" {
keyWords := "%" + req.KeyWords + "%"
m = m.Where("user_name like ? or user_nickname like ?", keyWords, keyWords)
}
if req.DeptId != "" {
deptIds, e := s.getSearchDeptIds(ctx, gconv.Uint64(req.DeptId))
liberr.ErrIsNil(ctx, e)
m = m.Where("dept_id in (?)", deptIds)
}
if req.Status != "" {
m = m.Where("user_status", gconv.Int(req.Status))
}
if req.Mobile != "" {
m = m.Where("mobile like ?", "%"+req.Mobile+"%")
}
if len(req.DateRange) > 0 {
m = m.Where("created_at >=? AND created_at <=?", req.DateRange[0], req.DateRange[1])
}
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
if req.PageNum == 0 {
req.PageNum = 1
}
total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取用户数据失败")
err = m.FieldsEx(dao.SysUser.Columns().UserPassword, dao.SysUser.Columns().UserSalt).
Page(req.PageNum, req.PageSize).Order("id asc").Scan(&userList)
liberr.ErrIsNil(ctx, err, "获取用户列表失败")
})
return
}
// GetUsersRoleDeptInfo 获取多个用户角色 部门信息
func (s *sSysUser) GetUsersRoleDeptInfo(ctx context.Context, userList []*entity.SysUser) (users []*model.SysUserRoleDeptRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
allRoles, e := service.SysRole().GetRoleList(ctx)
liberr.ErrIsNil(ctx, e)
depts, e := service.SysDept().GetFromCache(ctx)
liberr.ErrIsNil(ctx, e)
users = make([]*model.SysUserRoleDeptRes, len(userList))
for k, u := range userList {
var dept *entity.SysDept
users[k] = &model.SysUserRoleDeptRes{
SysUser: u,
}
for _, d := range depts {
if u.DeptId == d.DeptId {
dept = d
}
}
users[k].Dept = dept
roles, e := s.GetAdminRole(ctx, u.Id, allRoles)
liberr.ErrIsNil(ctx, e)
for _, r := range roles {
users[k].IsOperation = true
if r.Id == consts.SuperAdminId || r.Id == consts.SalesAgentId || r.Id == consts.SiteAdminId {
users[k].IsOperation = false
}
users[k].RoleInfo = append(users[k].RoleInfo, &model.SysUserRoleInfoRes{RoleId: r.Id, Name: r.Name})
}
}
})
return
}
func (s *sSysUser) GetTenantInfo(ctx context.Context, userList []*model.SysUserRoleDeptRes) (user []*model.SysUserRoleDeptRes, err error) {
// 1. 创建一个用于存放 ID 的空字符串切片
idList := make([]uint64, 0, len(userList))
// 2. 遍历原始列表
for _, user := range userList {
idList = append(idList, gconv.Uint64(user.TenantId))
}
var tenantList *system.GetTenantDetailsByIdsRes
tenantList, err = service.Tenant().GetTenantDetailsByIds(ctx, &system.GetTenantDetailsByIdsReq{
TenantIds: idList,
})
liberr.ErrIsNil(ctx, err)
for _, user := range userList {
for _, tenant := range tenantList.List {
if user.TenantId == tenant.Id {
user.TenantName = tenant.TenantName
}
}
}
return userList, nil
}
func (s *sSysUser) getSearchDeptIds(ctx context.Context, deptId uint64) (deptIds []uint64, err error) {
err = g.Try(ctx, func(ctx context.Context) {
deptAll, e := service.SysDept().GetFromCache(ctx)
liberr.ErrIsNil(ctx, e)
deptWithChildren := service.SysDept().FindSonByParentId(deptAll, deptId)
deptIds = make([]uint64, len(deptWithChildren))
for k, v := range deptWithChildren {
deptIds[k] = v.DeptId
}
deptIds = append(deptIds, deptId)
})
return
}
func (s *sSysUser) Add(ctx context.Context, req *system.UserAddReq) (res *system.UserAddRes, err error) {
err = s.UserNameOrMobileExists(ctx, req.UserName, req.Mobile)
if err != nil {
return
}
var getUserInfo *beans.User
getUserInfo, err = utils.GetUserInfo(ctx)
liberr.ErrIsNil(ctx, err)
req.UserSalt = grand.S(10)
req.Password = libUtils.EncryptPassword(req.Password, req.UserSalt)
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
userId, e := dao.SysUser.Ctx(ctx).TX(tx).InsertAndGetId(do.SysUser{
UserName: req.UserName,
Mobile: req.Mobile,
UserNickname: req.NickName,
UserPassword: req.Password,
UserSalt: req.UserSalt,
UserStatus: req.Status,
UserEmail: req.Email,
Sex: req.Sex,
DeptId: req.DeptId,
Remark: req.Remark,
IsAdmin: req.IsAdmin,
TenantId: gconv.Uint64(getUserInfo.TenantId),
})
res = new(system.UserAddRes)
res.UserId = userId
liberr.ErrIsNil(ctx, e, "添加用户失败")
e = s.addUserRole(ctx, req.RoleIds, userId)
liberr.ErrIsNil(ctx, e, "设置用户权限失败")
e = s.AddUserPost(ctx, tx, req.PostIds, userId)
liberr.ErrIsNil(ctx, e)
})
return err
})
return
}
func (s *sSysUser) Edit(ctx context.Context, req *system.UserEditReq) (err error) {
err = s.UserNameOrMobileExists(ctx, "", req.Mobile, req.UserId)
if err != nil {
return
}
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysUser.Ctx(ctx).TX(tx).WherePri(req.UserId).Update(do.SysUser{
Mobile: req.Mobile,
UserNickname: req.NickName,
UserStatus: req.Status,
UserEmail: req.Email,
Sex: req.Sex,
DeptId: req.DeptId,
Remark: req.Remark,
IsAdmin: req.IsAdmin,
})
liberr.ErrIsNil(ctx, err, "修改用户信息失败")
//设置用户所属角色信息
err = s.EditUserRole(ctx, req.RoleIds, req.UserId)
liberr.ErrIsNil(ctx, err, "设置用户权限失败")
err = s.AddUserPost(ctx, tx, req.PostIds, req.UserId)
liberr.ErrIsNil(ctx, err)
})
return err
})
return
}
// AddUserPost 添加用户岗位信息
func (s *sSysUser) AddUserPost(ctx context.Context, tx gdb.TX, postIds []int64, userId int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//删除旧岗位信息
_, err = dao.SysUserPost.Ctx(ctx).TX(tx).Where(dao.SysUserPost.Columns().UserId, userId).Delete()
liberr.ErrIsNil(ctx, err, "设置用户岗位失败")
if len(postIds) == 0 {
return
}
//添加用户岗位信息
data := g.List{}
for _, v := range postIds {
data = append(data, g.Map{
dao.SysUserPost.Columns().UserId: userId,
dao.SysUserPost.Columns().PostId: v,
})
}
_, err = dao.SysUserPost.Ctx(ctx).TX(tx).Data(data).Insert()
liberr.ErrIsNil(ctx, err, "设置用户岗位失败")
})
return
}
// AddUserRole 添加用户角色信息
func (s *sSysUser) addUserRole(ctx context.Context, roleIds []int64, userId int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
for _, v := range roleIds {
_, e = enforcer.AddGroupingPolicy(fmt.Sprintf("%s%d", s.casBinUserPrefix, userId), gconv.String(v))
liberr.ErrIsNil(ctx, e)
}
})
return
}
// EditUserRole 修改用户角色信息
func (s *sSysUser) EditUserRole(ctx context.Context, roleIds []int64, userId int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
//删除用户旧角色信息
enforcer.RemoveFilteredGroupingPolicy(0, fmt.Sprintf("%s%d", s.casBinUserPrefix, userId))
for _, v := range roleIds {
_, err = enforcer.AddGroupingPolicy(fmt.Sprintf("%s%d", s.casBinUserPrefix, userId), gconv.String(v))
liberr.ErrIsNil(ctx, err)
}
})
return
}
func (s *sSysUser) UserNameOrMobileExists(ctx context.Context, userName, mobile string, id ...int64) error {
user := (*entity.SysUser)(nil)
err := g.Try(ctx, func(ctx context.Context) {
m := dao.SysUser.Ctx(ctx)
if len(id) > 0 {
m = m.Where(dao.SysUser.Columns().Id+" != ", id)
}
m = m.Where(fmt.Sprintf("%s='%s' OR %s='%s'",
dao.SysUser.Columns().UserName,
userName,
dao.SysUser.Columns().Mobile,
mobile))
err := m.Limit(1).Scan(&user)
liberr.ErrIsNil(ctx, err, "获取用户信息失败")
if user == nil {
return
}
if user.UserName == userName {
liberr.ErrIsNil(ctx, gerror.New("账号已存在"))
}
if user.Mobile == mobile {
liberr.ErrIsNil(ctx, gerror.New("手机号已存在"))
}
})
return err
}
// GetEditUser 获取编辑用户信息
func (s *sSysUser) GetEditUser(ctx context.Context, id uint64) (res *system.UserGetEditRes, err error) {
res = new(system.UserGetEditRes)
err = g.Try(ctx, func(ctx context.Context) {
//获取用户信息
res.User, err = s.GetUserInfoById(ctx, id)
liberr.ErrIsNil(ctx, err)
//获取已选择的角色信息
res.CheckedRoleIds, err = s.GetAdminRoleIds(ctx, id)
liberr.ErrIsNil(ctx, err)
res.CheckedPosts, err = s.GetUserPostIds(ctx, id)
liberr.ErrIsNil(ctx, err)
})
return
}
// GetUserInfoById 通过Id获取用户信息
func (s *sSysUser) GetUserInfoById(ctx context.Context, id uint64, withPwd ...bool) (user *entity.SysUser, err error) {
err = g.Try(ctx, func(ctx context.Context) {
if len(withPwd) > 0 && withPwd[0] {
//用户用户信息
err = dao.SysUser.Ctx(ctx).Where(dao.SysUser.Columns().Id, id).Scan(&user)
} else {
//用户用户信息
err = dao.SysUser.Ctx(ctx).Where(dao.SysUser.Columns().Id, id).
FieldsEx(dao.SysUser.Columns().UserPassword, dao.SysUser.Columns().UserSalt).Scan(&user)
}
liberr.ErrIsNil(ctx, err, "获取用户数据失败")
})
return
}
// GetUserPostIds 获取用户岗位
func (s *sSysUser) GetUserPostIds(ctx context.Context, userId uint64) (postIds []int64, err error) {
err = g.Try(ctx, func(ctx context.Context) {
var list []*entity.SysUserPost
err = dao.SysUserPost.Ctx(ctx).Where(dao.SysUserPost.Columns().UserId, userId).Scan(&list)
liberr.ErrIsNil(ctx, err, "获取用户岗位信息失败")
postIds = make([]int64, 0)
for _, entity := range list {
postIds = append(postIds, entity.PostId)
}
})
return
}
// ResetUserPwd 重置用户密码
func (s *sSysUser) ResetUserPwd(ctx context.Context, req *system.UserResetPwdReq) (err error) {
salt := grand.S(10)
password := libUtils.EncryptPassword(req.Password, salt)
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysUser.Ctx(ctx).WherePri(req.Id).Update(g.Map{
dao.SysUser.Columns().UserSalt: salt,
dao.SysUser.Columns().UserPassword: password,
})
liberr.ErrIsNil(ctx, err, "重置用户密码失败")
})
return
}
func (s *sSysUser) ChangeUserStatus(ctx context.Context, req *system.UserStatusReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysUser.Ctx(ctx).WherePri(req.Id).Update(do.SysUser{UserStatus: req.UserStatus})
liberr.ErrIsNil(ctx, err, "设置用户状态失败")
})
return
}
// Delete 删除用户
func (s *sSysUser) Delete(ctx context.Context, ids []int) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysUser.Ctx(ctx).TX(tx).Where(dao.SysUser.Columns().Id+" in(?)", ids).Delete()
liberr.ErrIsNil(ctx, err, "删除用户失败")
//删除对应权限
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e)
for _, v := range ids {
enforcer.RemoveFilteredGroupingPolicy(0, fmt.Sprintf("%s%d", s.casBinUserPrefix, v))
}
//删除用户对应的岗位
_, err = dao.SysUserPost.Ctx(ctx).TX(tx).Delete(dao.SysUserPost.Columns().UserId+" in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除用户的岗位失败")
})
return err
})
return
}
// GetUsers 通过用户ids查询多个用户信息
func (s *sSysUser) GetUsers(ctx context.Context, ids []int) (users []*model.SysUserSimpleRes, err error) {
if len(ids) == 0 {
return
}
idsSet := gset.NewIntSetFrom(ids).Slice()
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysUser.Ctx(ctx).Where(dao.SysUser.Columns().Id+" in(?)", idsSet).
Order(dao.SysUser.Columns().Id + " ASC").Scan(&users)
})
return
}
func (s *sSysUser) IsSuperAdmin(ctx context.Context, req *system.IsSuperAdminReq) (isSuperAdmin bool, err error) {
_ = req
isSuperAdmin = false
// 获取用户id
getUserInfo, err := utils.GetUserInfo(ctx)
if err != nil {
return
}
userId := getUserInfo.Id
if !g.IsEmpty(userId) {
var roleIds []uint
roleIds, err = service.SysUser().GetAdminRoleIds(ctx, gconv.Uint64(userId))
liberr.ErrIsNil(ctx, err, "获取用户角色失败")
for _, v := range roleIds {
if v == consts.SuperAdminId {
isSuperAdmin = true
return
} else {
isSuperAdmin = false
}
}
}
return
}

View File

@@ -0,0 +1,185 @@
/*
* @desc:用户在线状态处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2023/1/10 14:50
*/
package sysUserOnline
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/grpool"
"github.com/gogf/gf/v2/os/gtime"
"github.com/mssola/user_agent"
"github.com/tiger1103/gfast/v3/api/v1/common"
"github.com/tiger1103/gfast/v3/api/v1/system"
comModel "github.com/tiger1103/gfast/v3/internal/app/common/model"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysUserOnline(New())
}
func New() *sSysUserOnline {
return &sSysUserOnline{
Pool: grpool.New(100),
}
}
type sSysUserOnline struct {
Pool *grpool.Pool
}
func (s *sSysUserOnline) Invoke(ctx context.Context, params *model.SysUserOnlineParams) {
s.Pool.Add(ctx, func(ctx context.Context) {
//写入数据
s.SaveOnline(ctx, params)
})
}
// SaveOnline 保存用户在线状态
func (s *sSysUserOnline) SaveOnline(ctx context.Context, params *model.SysUserOnlineParams) {
err := g.Try(ctx, func(ctx context.Context) {
ua := user_agent.New(params.UserAgent)
browser, _ := ua.Browser()
os := ua.OS()
var (
info *entity.SysUserOnline
data = &do.SysUserOnline{
Uuid: params.Uuid,
Token: params.Token,
CreateTime: gtime.Now(),
UserName: params.Username,
Ip: params.Ip,
Explorer: browser,
Os: os,
}
)
//查询是否已存在当前用户
err := dao.SysUserOnline.Ctx(ctx).Fields(dao.SysUserOnline.Columns().Id).
Where(dao.SysUserOnline.Columns().Token, data.Token).
Scan(&info)
liberr.ErrIsNil(ctx, err)
//若已存在则更新
if info != nil {
_, err = dao.SysUserOnline.Ctx(ctx).
Where(dao.SysUserOnline.Columns().Id, info.Id).
FieldsEx(dao.SysUserOnline.Columns().Id).Update(data)
liberr.ErrIsNil(ctx, err)
} else { //否则新增
_, err = dao.SysUserOnline.Ctx(ctx).
FieldsEx(dao.SysUserOnline.Columns().Id).Insert(data)
liberr.ErrIsNil(ctx, err)
}
})
if err != nil {
g.Log().Error(ctx, err)
}
}
// CheckUserOnline 检查在线用户
func (s *sSysUserOnline) CheckUserOnline(ctx context.Context) {
param := &system.SysUserOnlineSearchReq{
PageReq: common.PageReq{
PageReq: comModel.PageReq{
PageNum: 1,
PageSize: 50,
},
},
}
var total int
for {
var (
res *system.SysUserOnlineSearchRes
err error
)
res, err = s.GetOnlineListPage(ctx, param, true)
if err != nil {
g.Log().Error(ctx, err)
break
}
if res.List == nil {
break
}
for _, v := range res.List {
if b := s.UserIsOnline(ctx, v.Token); !b {
s.DeleteOnlineByToken(ctx, v.Token)
}
}
if param.PageNum*param.PageSize >= total {
break
}
param.PageNum++
}
}
// GetOnlineListPage 搜素在线用户列表
func (s *sSysUserOnline) GetOnlineListPage(ctx context.Context, req *system.SysUserOnlineSearchReq, hasToken ...bool) (res *system.SysUserOnlineSearchRes, err error) {
if req.PageNum == 0 {
req.PageNum = 1
}
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
model := dao.SysUserOnline.Ctx(ctx)
if req.Ip != "" {
model = model.Where("ip like ?", "%"+req.Ip+"%")
}
if req.Username != "" {
model = model.Where("user_name like ?", "%"+req.Username+"%")
}
res = new(system.SysUserOnlineSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
res.Total, err = model.Count()
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if len(hasToken) == 0 || !hasToken[0] {
model = model.FieldsEx("token")
}
err = model.Page(req.PageNum, req.PageSize).Order("create_time DESC").Scan(&res.List)
liberr.ErrIsNil(ctx, err, "获取数据失败")
})
return
}
func (s *sSysUserOnline) UserIsOnline(ctx context.Context, token string) bool {
err := g.Try(ctx, func(ctx context.Context) {
_, _, err := service.GfToken().GetTokenData(ctx, token)
liberr.ErrIsNil(ctx, err)
})
return err == nil
}
func (s *sSysUserOnline) DeleteOnlineByToken(ctx context.Context, token string) (err error) {
_, err = dao.SysUserOnline.Ctx(ctx).Delete(dao.SysUserOnline.Columns().Token, token)
return
}
func (s *sSysUserOnline) ForceLogout(ctx context.Context, ids []int) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
var onlineList []*entity.SysUserOnline
onlineList, err = s.GetInfosByIds(ctx, ids)
liberr.ErrIsNil(ctx, err)
_, err = dao.SysUserOnline.Ctx(ctx).Where(dao.SysUserOnline.Columns().Id+" in(?)", ids).Delete()
liberr.ErrIsNil(ctx, err)
for _, v := range onlineList {
err = service.GfToken().RemoveToken(ctx, v.Token)
liberr.ErrIsNil(ctx, err)
}
})
return
}
func (s *sSysUserOnline) GetInfosByIds(ctx context.Context, ids []int) (onlineList []*entity.SysUserOnline, err error) {
err = dao.SysUserOnline.Ctx(ctx).Where(dao.SysUserOnline.Columns().Id+" in(?)", ids).Scan(&onlineList)
return
}

View File

@@ -0,0 +1,303 @@
/*
* @desc:用户处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/23 15:08
*/
package tenant
import (
"context"
"database/sql"
"errors"
"fmt"
"gitea.com/red-future/common/beans"
"gitea.com/red-future/common/minio"
"gitea.com/red-future/common/utils"
"github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/libUtils"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterTenant(New())
}
type sTenant struct {
}
func New() *sTenant {
return &sTenant{}
}
func (s *sTenant) GetTenantListSearch(ctx context.Context, req *system.TenantListReq) (res *system.TenantListRes, err error) {
res = new(system.TenantListRes)
err = g.Try(ctx, func(ctx context.Context) {
res.ImgAddressPrefix = minio.GetFileAddressPrefix(ctx)
model := dao.TenantDao.Ctx(ctx)
// 根据toke获取用户id
userId := service.Context().GetUserId(ctx)
getUserById, err := service.SysUser().GetUserById(ctx, userId)
liberr.ErrIsNil(ctx, err, "获取用户信息失败")
roleIds, err := service.SysUser().GetAdminRoleIds(ctx, userId)
// 根据用户角色查询对应数据9代理10普通
for _, v := range roleIds {
if v == consts.SalesAgentId || v == consts.SiteAdminId {
model = model.Where(dao.TenantDao.Columns().TenantSource, gconv.Int64(getUserById.TenantId))
}
}
if !g.IsEmpty(req.TenantName) {
model = model.Where(dao.TenantDao.Columns().TenantName+" like ? ", "%"+req.TenantName+"%")
}
if !g.IsEmpty(req.TenantType) {
model = model.Where(dao.TenantDao.Columns().TenantType, gconv.Int(req.TenantType))
}
if !g.IsEmpty(req.CityCode) {
model = model.Where(dao.TenantDao.Columns().CityCode, gconv.String(req.CityCode))
}
res.Total, err = model.Count()
liberr.ErrIsNil(ctx, err, "获取租户数据失败")
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
err = model.Page(res.CurrentPage, req.PageSize).Order(dao.TenantDao.Columns().CreatedAt + " desc").Scan(&res.List)
liberr.ErrIsNil(ctx, err, "获取数据失败")
var list []map[string]interface{}
err = utils.Struct(res.List, &list)
liberr.ErrIsNil(ctx, err, "转换数据失败")
// 2. 提取id
userIds := make([]int, 0, len(list))
cityIds := make([]string, 0, len(list))
for _, obj := range list {
// 提取id并转换JSON数字是float64
idFloat, ok := obj["adminBy"].(float64)
if !ok {
fmt.Println("警告adminBy字段非数字")
continue
}
cityFloat, ok := obj["cityCode"].(string)
if !ok {
fmt.Println("警告cityCode字段非字符串")
continue
}
userIds = append(userIds, int(idFloat))
cityIds = append(cityIds, cityFloat)
}
userList, err := service.SysUser().GetUsers(ctx, userIds)
liberr.ErrIsNil(ctx, err, "获取租户信息失败")
areaDicList, err := service.AreaDict().GetAreaDict(ctx)
liberr.ErrIsNil(ctx, err, "获取地区字典失败")
for _, list := range res.List {
for _, areas := range areaDicList {
if fmt.Sprintf("%d", areas.Id) == list.CityCode {
list.CityName = areas.CityName
list.CityMergerName = areas.MergerName
}
}
for _, users := range userList {
if users.Id == list.AdminBy {
list.UserName = users.UserName
list.Mobile = users.Mobile
list.UserNickname = users.UserNickname
}
}
}
})
return
}
func (s *sTenant) Add(ctx context.Context, req *system.TenantAddReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
// 根据token获取用户id
userId := service.Context().GetUserId(ctx)
var getUserInfo *beans.User
getUserInfo, err = utils.GetUserInfo(ctx)
var userTenantId uint64
if err == nil && !g.IsEmpty(getUserInfo.TenantId) {
userTenantId = gconv.Uint64(getUserInfo.TenantId)
}
if !g.IsEmpty(userId) {
var roleIds []uint
roleIds, err = service.SysUser().GetAdminRoleIds(ctx, userId)
liberr.ErrIsNil(ctx, err, "获取用户角色失败")
// 如果是代理和普通用户只能添加普通类型1普通类型2代理类型
for _, v := range roleIds {
if v == consts.SalesAgentId || v == consts.SiteAdminId {
req.TenantType = consts.TenantTypeSite
if v == consts.SalesAgentId {
// 验证代理区域是否在当前代理的管辖范围内
tenantEntity := new(entity.Tenant)
err = dao.TenantDao.Ctx(ctx).TX(tx).Where(dao.TenantDao.Columns().Id, userTenantId).Scan(tenantEntity)
liberr.ErrIsNil(ctx, err, "获取租户数据失败")
var count int
count, err = dao.AreaDictDao.Ctx(ctx).TX(tx).Where("("+dao.AreaDictDao.Columns().Id+"=? OR "+dao.AreaDictDao.Columns().ParentId+"=?) AND "+dao.AreaDictDao.Columns().Id+"=?", tenantEntity.CityCode, tenantEntity.CityCode, req.CityCode).Count()
liberr.ErrIsNil(ctx, err, "验证代理区域失败")
if count == 0 {
liberr.ErrIsNil(ctx, errors.New("所选城市不在当前代理的管辖范围内"))
}
} else {
if req.TenantType == consts.TenantTypeAgent {
liberr.ErrIsNil(ctx, errors.New("代理商不能添加代理商"))
}
}
break
}
}
} else {
// 如果是普通用户只能添加普通类型1普通类型2代理类型
req.TenantType = consts.TenantTypeSite
}
if req.TenantType == consts.TenantTypeAgent {
// 验证代理区域是否已有代理商
var count int
count, err = dao.TenantDao.Ctx(ctx).TX(tx).Where(dao.TenantDao.Columns().CityCode, req.CityCode).Count()
liberr.ErrIsNil(ctx, err, "获取租户数据失败")
if count > 0 {
liberr.ErrIsNil(ctx, errors.New("该城市已有代理商"))
}
}
var tenantId int64
tenantId, err = dao.TenantDao.Ctx(ctx).TX(tx).InsertAndGetId(do.Tenant{
CreateBy: userId,
UpdateBy: userId,
TenantName: req.TenantName,
TenantType: req.TenantType,
CityCode: req.CityCode,
BusinessLicense: req.BusinessLicense,
TenantSource: userTenantId,
})
liberr.ErrIsNil(ctx, err, "添加租户失败")
var RoleIds = []int64{consts.SiteAdminId}
if !g.IsNil(req.TenantType) && req.TenantType == consts.TenantTypeAgent {
RoleIds = []int64{consts.SalesAgentId}
}
// 在同一事务中添加部门
var deptId int64
var deptInsertId sql.Result
deptInsertId, err = dao.SysDept.Ctx(ctx).TX(tx).Insert(do.SysDept{
ParentId: 0,
DeptName: req.TenantName,
OrderNum: 0,
Leader: req.UserNickname,
Phone: req.Mobile,
Email: req.Mobile + "@qq.com",
Status: 1,
CreatedBy: userId,
TenantId: uint64(tenantId),
})
liberr.ErrIsNil(ctx, err, "添加部门失败")
deptId, err = deptInsertId.LastInsertId()
liberr.ErrIsNil(ctx, err, "获取部门ID失败")
// 在同一事务中添加用户
err = service.SysUser().UserNameOrMobileExists(ctx, req.UserName, req.Mobile)
liberr.ErrIsNil(ctx, err)
userSalt := grand.S(10)
userPassword := libUtils.EncryptPassword(req.UserPassword, userSalt)
var adminUserId int64
adminUserId, err = dao.SysUser.Ctx(ctx).TX(tx).InsertAndGetId(do.SysUser{
UserName: req.UserName,
Mobile: req.Mobile,
UserNickname: req.UserNickname,
UserPassword: userPassword,
UserSalt: userSalt,
UserStatus: 1,
DeptId: uint64(deptId),
IsAdmin: 1,
TenantId: uint64(tenantId),
})
liberr.ErrIsNil(ctx, err, "添加用户失败")
// 添加用户角色信息使用Casbin
enforcer, e := commonService.CasbinEnforcer(ctx)
liberr.ErrIsNil(ctx, e, "获取权限引擎失败")
for _, v := range RoleIds {
_, e = enforcer.AddGroupingPolicy(fmt.Sprintf("u_%d", adminUserId), gconv.String(v))
liberr.ErrIsNil(ctx, e, "设置用户权限失败")
}
// 更新租户的AdminBy字段
_, err = dao.TenantDao.Ctx(ctx).TX(tx).WherePri(tenantId).Update(do.Tenant{
AdminBy: adminUserId,
})
liberr.ErrIsNil(ctx, err, "修改租户信息失败")
})
return err
})
return
}
func (s *sTenant) Edit(ctx context.Context, req *system.TenantEditReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
userId := service.Context().GetUserId(ctx)
tenant := do.Tenant{
UpdateBy: userId,
TenantName: req.TenantName,
CityCode: req.CityCode,
BusinessLicense: req.BusinessLicense,
}
if !g.IsEmpty(req.TenantType) {
tenant.TenantType = req.TenantType
}
_, err = dao.TenantDao.Ctx(ctx).TX(tx).WherePri(req.Id).Update(tenant)
liberr.ErrIsNil(ctx, err, "修改租户信息失败")
})
return err
})
return
}
func (s *sTenant) GetTenantDetailsByIds(ctx context.Context, req *system.GetTenantDetailsByIdsReq) (res *system.GetTenantDetailsByIdsRes, err error) {
res = new(system.GetTenantDetailsByIdsRes)
if len(req.TenantIds) == 0 {
return
}
idsSet := gset.NewIntSetFrom(gconv.Ints(req.TenantIds)).Slice()
err = g.Try(ctx, func(ctx context.Context) {
err = dao.TenantDao.Ctx(ctx).Where(dao.TenantDao.Columns().Id+" in(?)", idsSet).Order(dao.TenantDao.Columns().Id + " ASC").Scan(&res.List)
})
return
}
func (s *sTenant) GetTenantDetails(ctx context.Context, id uint64) (res *entity.Tenant, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.TenantDao.Ctx(ctx).WherePri(id).Scan(&res)
})
return
}
func (s *sTenant) GetTenantAdminById(ctx context.Context, id uint64) (res []entity.Tenant, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.TenantDao.Ctx(ctx).Where(dao.TenantDao.Columns().Id+" =(?) or "+dao.TenantDao.Columns().TenantSource+" =(?)", id, id).Order(dao.TenantDao.Columns().Id + " ASC").Scan(&res)
})
return
}
func (s *sTenant) GetTenantIdList(ctx context.Context, req *system.GetTenantListReq) (res []entity.Tenant, err error) {
err = g.Try(ctx, func(ctx context.Context) {
model := dao.TenantDao.Ctx(ctx)
if !g.IsEmpty(req.TenantId) {
model.Where(dao.TenantDao.Columns().Id, req.TenantId)
}
err = model.Scan(&res)
})
return
}

View File

@@ -0,0 +1,51 @@
/*
* @desc:token功能
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/27 17:01
*/
package token
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/tiger1103/gfast-token/gftoken"
"github.com/tiger1103/gfast/v3/internal/app/common/consts"
commonModel "github.com/tiger1103/gfast/v3/internal/app/common/model"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
type sToken struct {
*gftoken.GfToken
}
func New() *sToken {
var (
ctx = gctx.New()
opt *commonModel.TokenOptions
err = g.Cfg().MustGet(ctx, "gfToken").Struct(&opt)
fun gftoken.OptionFunc
)
liberr.ErrIsNil(ctx, err)
if opt.CacheModel == consts.CacheModelRedis {
fun = gftoken.WithGRedis()
} else {
fun = gftoken.WithGCache()
}
return &sToken{
GfToken: gftoken.NewGfToken(
gftoken.WithCacheKey(opt.CacheKey),
gftoken.WithTimeout(opt.Timeout),
gftoken.WithMaxRefresh(opt.MaxRefresh),
gftoken.WithMultiLogin(opt.MultiLogin),
gftoken.WithExcludePaths(opt.ExcludePaths),
fun,
),
}
}
func init() {
service.RegisterGToken(New())
}

View File

View File

@@ -0,0 +1,15 @@
/*
* @desc:租户模型对象
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/7 11:47
*/
package model
import "github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
// AreaDictRes 地区数据
type AreaDictRes struct {
*entity.AreaDict
}

View File

@@ -0,0 +1,16 @@
/*
* @desc:context-model
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/16 14:45
*/
package model
type Context struct {
User *ContextUser // User in context.
}
type ContextUser struct {
*LoginUserRes
}

View File

@@ -0,0 +1,20 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// AreaDict is the golang structure of table tenant for DAO operations like Where/Data.
type AreaDict struct {
g.Meta `orm:"table:area_dict, do:true"`
Id interface{} //
CityName interface{} // 城市名称
ParentId interface{} // 父级id
ShortName interface{} // 城市缩写名称
Depth interface{} // 城市层级
MergerName interface{} // 城市组合名称
}

View File

@@ -0,0 +1,27 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// ModuleTenant is the golang structure of table ModuleTenant for DAO operations like Where/Data.
type ModuleTenant struct {
g.Meta `orm:"table:module_tenant, do:true"`
Id interface{} //
CreateBy interface{} // 创建者
UpdateBy interface{} // 更新者
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
ModuleKey interface{} //模块Key
TenantId interface{} //租户ID
ExpireAt *gtime.Time //到期时间
AssetId interface{} //资产ID
AssetSkuId interface{} //资产SKU ID
TenantModuleType interface{} //租户模块类型
CertificationStatus interface{} //状态
}

View File

@@ -0,0 +1,37 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysAuthRule is the golang structure of table sys_auth_rule for DAO operations like Where/Data.
type SysAuthRule struct {
g.Meta `orm:"table:sys_auth_rule, do:true"`
Id interface{} //
Pid interface{} // 父ID
Name interface{} // 规则名称
Title interface{} // 规则名称
Icon interface{} // 图标
Condition interface{} // 条件
Remark interface{} // 备注
MenuType interface{} // 类型 0目录 1菜单 2按钮
Weigh interface{} // 权重
IsHide interface{} // 显示状态
Path interface{} // 路由地址
Component interface{} // 组件路径
IsLink interface{} // 是否外链 1是 0否
ModuleType interface{} // 所属模块
ModelId interface{} // 模型ID
IsIframe interface{} // 是否内嵌iframe
IsCached interface{} // 是否缓存
Redirect interface{} // 路由重定向地址
IsAffix interface{} // 是否固定
LinkUrl interface{} // 链接地址
CreatedAt *gtime.Time // 创建日期
UpdatedAt *gtime.Time // 修改日期
}

View File

@@ -0,0 +1,30 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysDept is the golang structure of table sys_dept for DAO operations like Where/Data.
type SysDept struct {
g.Meta `orm:"table:sys_dept, do:true"`
DeptId interface{} // 部门id
ParentId interface{} // 父部门id
Ancestors interface{} // 祖级列表
DeptName interface{} // 部门名称
OrderNum interface{} // 显示顺序
Leader interface{} // 负责人
Phone interface{} // 联系电话
Email interface{} // 邮箱
Status interface{} // 部门状态0正常 1停用
CreatedBy interface{} // 创建人
UpdatedBy interface{} // 修改人
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 修改时间
DeletedAt *gtime.Time // 删除时间
TenantId interface{} // 租户id
}

View File

@@ -0,0 +1,25 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-08 11:31:48
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysLoginLog is the golang structure of table sys_login_log for DAO operations like Where/Data.
type SysLoginLog struct {
g.Meta `orm:"table:sys_login_log, do:true"`
InfoId interface{} // 访问ID
LoginName interface{} // 登录账号
Ipaddr interface{} // 登录IP地址
LoginLocation interface{} // 登录地点
Browser interface{} // 浏览器类型
Os interface{} // 操作系统
Status interface{} // 登录状态0成功 1失败
Msg interface{} // 提示消息
LoginTime *gtime.Time // 登录时间
Module interface{} // 登录模块
}

View File

@@ -0,0 +1,29 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysOperLog is the golang structure of table sys_oper_log for DAO operations like Where/Data.
type SysOperLog struct {
g.Meta `orm:"table:sys_oper_log, do:true"`
OperId interface{} // 日志主键
Title interface{} // 模块标题
BusinessType interface{} // 业务类型0其它 1新增 2修改 3删除
Method interface{} // 方法名称
RequestMethod interface{} // 请求方式
OperatorType interface{} // 操作类别0其它 1后台用户 2手机端用户
OperName interface{} // 操作人员
DeptName interface{} // 部门名称
OperUrl interface{} // 请求URL
OperIp interface{} // 主机地址
OperLocation interface{} // 操作地点
OperParam interface{} // 请求参数
ErrorMsg interface{} // 错误消息
OperTime *gtime.Time // 操作时间
}

View File

@@ -0,0 +1,26 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-07 23:26:21
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysPost is the golang structure of table sys_post for DAO operations like Where/Data.
type SysPost struct {
g.Meta `orm:"table:sys_post, do:true"`
PostId interface{} // 岗位ID
PostCode interface{} // 岗位编码
PostName interface{} // 岗位名称
PostSort interface{} // 显示顺序
Status interface{} // 状态0正常 1停用
Remark interface{} // 备注
CreatedBy interface{} // 创建人
UpdatedBy interface{} // 修改人
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 修改时间
DeletedAt *gtime.Time // 删除时间
}

View File

@@ -0,0 +1,24 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysRole is the golang structure of table sys_role for DAO operations like Where/Data.
type SysRole struct {
g.Meta `orm:"table:sys_role, do:true"`
Id interface{} //
Status interface{} // 状态;0:禁用;1:正常
ListOrder interface{} // 排序
Name interface{} // 角色名称
Remark interface{} // 备注
DataScope interface{} // 数据范围1全部数据权限 2自定数据权限 3本部门数据权限 4本部门及以下数据权限
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
TenantId interface{} // 租户id
}

View File

@@ -0,0 +1,16 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// SysRoleDept is the golang structure of table sys_role_dept for DAO operations like Where/Data.
type SysRoleDept struct {
g.Meta `orm:"table:sys_role_dept, do:true"`
RoleId interface{} // 角色ID
DeptId interface{} // 部门ID
}

View File

@@ -0,0 +1,37 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysUser is the golang structure of table sys_user for DAO operations like Where/Data.
type SysUser struct {
g.Meta `orm:"table:sys_user, do:true"`
Id interface{} //
UserName interface{} // 用户名
Mobile interface{} // 中国手机不带国家代码,国际手机号格式为:国家代码-手机号
UserNickname interface{} // 用户昵称
Birthday interface{} // 生日
UserPassword interface{} // 登录密码;cmf_password加密
UserSalt interface{} // 加密盐
UserStatus interface{} // 用户状态;0:禁用,1:正常,2:未验证
UserEmail interface{} // 用户登录邮箱
Sex interface{} // 性别;0:保密,1:男,2:女
Avatar interface{} // 用户头像
DeptId interface{} // 部门id
Remark interface{} // 备注
IsAdmin interface{} // 是否后台管理员 1 是 0 否
Address interface{} // 联系地址
Describe interface{} // 描述信息
LastLoginIp interface{} // 最后登录ip
LastLoginTime *gtime.Time // 最后登录时间
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 删除时间
TenantId interface{} //租户id
}

View File

@@ -0,0 +1,23 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysUserOnline is the golang structure of table sys_user_online for DAO operations like Where/Data.
type SysUserOnline struct {
g.Meta `orm:"table:sys_user_online, do:true"`
Id interface{} //
Uuid interface{} // 用户标识
Token interface{} // 用户token
CreateTime *gtime.Time // 登录时间
UserName interface{} // 用户名
Ip interface{} // 登录ip
Explorer interface{} // 浏览器
Os interface{} // 操作系统
}

View File

@@ -0,0 +1,16 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// SysUserPost is the golang structure of table sys_user_post for DAO operations like Where/Data.
type SysUserPost struct {
g.Meta `orm:"table:sys_user_post, do:true"`
UserId interface{} // 用户ID
PostId interface{} // 岗位ID
}

View File

@@ -0,0 +1,26 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// Tenant is the golang structure of table tenant for DAO operations like Where/Data.
type Tenant struct {
g.Meta `orm:"table:tenant, do:true"`
Id interface{} //
CreateBy interface{} // 创建者
UpdateBy interface{} // 更新者
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
TenantName interface{} // 租户名称
TenantType interface{} // 租户类型
CityCode interface{} // 城市编码
BusinessLicense interface{} // 营业执照
TenantSource interface{} // 租户来源
AdminBy interface{} // 管理者
}

View File

@@ -0,0 +1,16 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23
// =================================================================================
package entity
// AreaDict is the golang structure for table tenant.
type AreaDict struct {
Id int `json:"id" description:""`
CityName string `json:"cityName" description:"城市名称"`
ParentId int `json:"parentId" description:"父级id"`
ShortName string `json:"shortName" description:"城市缩写名称"`
Depth int `json:"depth" description:"城市层级"`
MergerName string `json:"mergerName" description:"城市组合名称"`
Status int `json:"status" description:"状态"`
}

View File

@@ -0,0 +1,29 @@
/*
* @desc:模块租户关系实体
* @company:云南奇讯科技有限公司
* @Author: system
* @Date: 2026/1/6
*/
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
)
// ModuleTenant is the golang structure for table module_tenant.
type ModuleTenant struct {
Id uint64 `json:"id" description:""`
CreateBy uint64 `json:"createBy" description:"创建者"`
UpdateBy uint64 `json:"updateBy" description:"更新者"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"`
ModuleKey string `json:"moduleKey" description:"模块Key"`
TenantId uint64 `json:"tenantId" description:"租户ID"`
ExpireAt *gtime.Time `json:"expireAt" description:"到期时间"`
AssetId string `json:"assetId" description:"资产ID"`
AssetSkuId string `json:"assetSkuId" description:"资产SKU ID"`
TenantModuleType string `json:"tenantModuleType" description:"租户模块类型"`
CertificationStatus consts.CertificationStatus `json:"certificationStatus" description:"认证状态"`
}

View File

@@ -0,0 +1,35 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysAuthRule is the golang structure for table sys_auth_rule.
type SysAuthRule struct {
Id uint `json:"id" description:""`
Pid uint `json:"pid" description:"父ID"`
Name string `json:"name" description:"规则名称"`
Title string `json:"title" description:"规则名称"`
Icon string `json:"icon" description:"图标"`
Condition string `json:"condition" description:"条件"`
Remark string `json:"remark" description:"备注"`
MenuType uint `json:"menuType" description:"类型 0目录 1菜单 2按钮"`
Weigh int `json:"weigh" description:"权重"`
IsHide uint `json:"isHide" description:"显示状态"`
Path string `json:"path" description:"路由地址"`
Component string `json:"component" description:"组件路径"`
IsLink uint `json:"isLink" description:"是否外链 1是 0否"`
ModuleType string `json:"moduleType" description:"所属模块"`
ModelId uint `json:"modelId" description:"模型ID"`
IsIframe uint `json:"isIframe" description:"是否内嵌iframe"`
IsCached uint `json:"isCached" description:"是否缓存"`
Redirect string `json:"redirect" description:"路由重定向地址"`
IsAffix uint `json:"isAffix" description:"是否固定"`
LinkUrl string `json:"linkUrl" description:"链接地址"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建日期"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"修改日期"`
}

View File

@@ -0,0 +1,28 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysDept is the golang structure for table sys_dept.
type SysDept struct {
DeptId uint64 `json:"deptId" description:"部门id"`
ParentId uint64 `json:"parentId" description:"父部门id"`
Ancestors string `json:"ancestors" description:"祖级列表"`
DeptName string `json:"deptName" description:"部门名称"`
OrderNum int `json:"orderNum" description:"显示顺序"`
Leader string `json:"leader" description:"负责人"`
Phone string `json:"phone" description:"联系电话"`
Email string `json:"email" description:"邮箱"`
Status uint `json:"status" description:"部门状态0正常 1停用"`
CreatedBy uint64 `json:"createdBy" description:"创建人"`
UpdatedBy int64 `json:"updatedBy" description:"修改人"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"修改时间"`
DeletedAt *gtime.Time `json:"deletedAt" description:"删除时间"`
TenantId uint64 `json:"tenantId" description:"租户id"`
}

View File

@@ -0,0 +1,23 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-08 11:31:48
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysLoginLog is the golang structure for table sys_login_log.
type SysLoginLog struct {
InfoId int64 `json:"infoId" description:"访问ID"`
LoginName string `json:"loginName" description:"登录账号"`
Ipaddr string `json:"ipaddr" description:"登录IP地址"`
LoginLocation string `json:"loginLocation" description:"登录地点"`
Browser string `json:"browser" description:"浏览器类型"`
Os string `json:"os" description:"操作系统"`
Status int `json:"status" description:"登录状态0成功 1失败"`
Msg string `json:"msg" description:"提示消息"`
LoginTime *gtime.Time `json:"loginTime" description:"登录时间"`
Module string `json:"module" description:"登录模块"`
}

View File

@@ -0,0 +1,27 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysOperLog is the golang structure for table sys_oper_log.
type SysOperLog struct {
OperId uint64 `json:"operId" description:"日志主键"`
Title string `json:"title" description:"模块标题"`
BusinessType int `json:"businessType" description:"业务类型0其它 1新增 2修改 3删除"`
Method string `json:"method" description:"方法名称"`
RequestMethod string `json:"requestMethod" description:"请求方式"`
OperatorType int `json:"operatorType" description:"操作类别0其它 1后台用户 2手机端用户"`
OperName string `json:"operName" description:"操作人员"`
DeptName string `json:"deptName" description:"部门名称"`
OperUrl string `json:"operUrl" description:"请求URL"`
OperIp string `json:"operIp" description:"主机地址"`
OperLocation string `json:"operLocation" description:"操作地点"`
OperParam string `json:"operParam" description:"请求参数"`
ErrorMsg string `json:"errorMsg" description:"错误消息"`
OperTime *gtime.Time `json:"operTime" description:"操作时间"`
}

View File

@@ -0,0 +1,24 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-07 23:26:21
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysPost is the golang structure for table sys_post.
type SysPost struct {
PostId uint64 `json:"postId" description:"岗位ID"`
PostCode string `json:"postCode" description:"岗位编码"`
PostName string `json:"postName" description:"岗位名称"`
PostSort int `json:"postSort" description:"显示顺序"`
Status uint `json:"status" description:"状态0正常 1停用"`
Remark string `json:"remark" description:"备注"`
CreatedBy uint64 `json:"createdBy" description:"创建人"`
UpdatedBy uint64 `json:"updatedBy" description:"修改人"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"修改时间"`
DeletedAt *gtime.Time `json:"deletedAt" description:"删除时间"`
}

View File

@@ -0,0 +1,22 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysRole is the golang structure for table sys_role.
type SysRole struct {
Id uint `json:"id" description:""`
Status uint `json:"status" description:"状态;0:禁用;1:正常"`
ListOrder uint `json:"listOrder" description:"排序"`
Name string `json:"name" description:"角色名称"`
Remark string `json:"remark" description:"备注"`
DataScope uint `json:"dataScope" description:"数据范围1全部数据权限 2自定数据权限 3本部门数据权限 4本部门及以下数据权限"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"`
TenantId uint64 `json:"tenantId" description:"租户id"`
}

View File

@@ -0,0 +1,11 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
// SysRoleDept is the golang structure for table sys_role_dept.
type SysRoleDept struct {
RoleId int64 `json:"roleId" description:"角色ID"`
DeptId int64 `json:"deptId" description:"部门ID"`
}

Some files were not shown because too many files have changed in this diff Show More