作者 yangfu

feat: 2.0 角色菜单权限、账号切换、账号安全

正在显示 46 个修改的文件 包含 2361 行增加109 行删除
... ... @@ -25,4 +25,4 @@ Redis:
Type: node
Pass:
DB:
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=su_enterprise_platform_preonline port=31543 sslmode=disable TimeZone=Asia/Shanghai
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=su_enterprise_platform port=31543 sslmode=disable TimeZone=Asia/Shanghai
... ...
package auth
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/auth"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemAuthChangePasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChangePasswordRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := auth.NewSystemAuthChangePasswordLogic(r.Context(), svcCtx)
resp, err := l.SystemAuthChangePassword(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package auth
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/auth"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemAuthEditUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EditUserInfoRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := auth.NewSystemAuthEditUserInfoLogic(r.Context(), svcCtx)
resp, err := l.SystemAuthEditUserInfo(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package auth
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/auth"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemAuthResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ResetPasswordRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := auth.NewSystemAuthResetPasswordLogic(r.Context(), svcCtx)
resp, err := l.SystemAuthResetPassword(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package role
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/role"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemMenuListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MenuListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := role.NewSystemMenuListLogic(r.Context(), svcCtx)
resp, err := l.SystemMenuList(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package role
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/role"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemRoleDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RoleDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := role.NewSystemRoleDeleteLogic(r.Context(), svcCtx)
resp, err := l.SystemRoleDelete(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package role
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/role"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemRoleGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RoleGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := role.NewSystemRoleGetLogic(r.Context(), svcCtx)
resp, err := l.SystemRoleGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package role
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/role"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemRoleSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RoleSaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := role.NewSystemRoleSaveLogic(r.Context(), svcCtx)
resp, err := l.SystemRoleSave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package role
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/role"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemRoleSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RoleSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := role.NewSystemRoleSearchLogic(r.Context(), svcCtx)
resp, err := l.SystemRoleSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package role
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/role"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func SystemRoleUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RoleUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := role.NewSystemRoleUpdateLogic(r.Context(), svcCtx)
resp, err := l.SystemRoleUpdate(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -9,6 +9,8 @@ import (
company "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/company"
department "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/department"
employee "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/employee"
role "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/role"
user "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/user"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
... ... @@ -45,6 +47,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/auth/edit_user_info",
Handler: auth.SystemAuthEditUserInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/auth/change_password",
Handler: auth.SystemAuthChangePasswordHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/auth/reset_password",
Handler: auth.SystemAuthResetPasswordHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/auth/switch_company",
Handler: auth.SystemAuthSwitchCompanyHandler(serverCtx),
},
... ... @@ -59,6 +76,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/user/company_users",
Handler: user.UserCompanyUsersHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/system/company_info",
Handler: company.SystemCompanyInfoHandler(serverCtx),
... ... @@ -135,6 +167,46 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/role/:id",
Handler: role.SystemRoleGetHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/role",
Handler: role.SystemRoleSaveHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/role/:id",
Handler: role.SystemRoleDeleteHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/role/:id",
Handler: role.SystemRoleUpdateHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/role/search",
Handler: role.SystemRoleSearchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/menu/list",
Handler: role.SystemMenuListHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1/system"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/system/app/:id",
Handler: app.SystemAppGetHandler(serverCtx),
},
... ... @@ -144,7 +216,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: app.SystemAppSearchHandler(serverCtx),
},
{
Method: http.MethodGet,
Method: http.MethodPost,
Path: "/system/app/set_config",
Handler: app.SystemAppSetConfigHandler(serverCtx),
},
... ...
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
)
func UserCompanyUsersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CompanyUsersRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewUserCompanyUsersLogic(r.Context(), svcCtx)
resp, err := l.UserCompanyUsers(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -72,7 +72,7 @@ func (l *SystemAppSearchLogic) SystemAppSearch(req *types.SystemAppSearchRequest
CompanyId: token.CompanyId,
AppId: app.Id,
Status: domain.Enable,
VisibleFlag: domain.VisibleAll,
VisibleFlag: domain.VisibleParts,
VisibleUsers: make([]int64, 0),
VisibleGroups: make([]int64, 0),
AppConfig: domain.AppConfig{},
... ...
... ... @@ -2,6 +2,9 @@ package app
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
... ... @@ -24,6 +27,26 @@ func NewSystemAppSetConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *SystemAppSetConfigLogic) SystemAppSetConfig(req *types.SystemAppSetConfigRequest) (resp *types.SystemAppSetConfigResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
companyApp *domain.SysCompanyApp
//app *domain.SysApp
)
if companyApp, err = l.svcCtx.CompanyAppRepository.FindOne(l.ctx, conn, req.AppId); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
companyApp.VisibleFlag = req.VisibleFlag
companyApp.VisibleUsers = req.VisibleUsers
companyApp.VisibleDepartments = req.VisibleDepartments
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
companyApp, err = l.svcCtx.CompanyAppRepository.UpdateWithVersion(l.ctx, conn, companyApp)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.SystemAppSetConfigResponse{}
return
}
... ...
package auth
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemAuthChangePasswordLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemAuthChangePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemAuthChangePasswordLogic {
return &SystemAuthChangePasswordLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemAuthChangePasswordLogic) SystemAuthChangePassword(req *types.ChangePasswordRequest) (resp *types.ChangePasswordResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.SysUser
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, token.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
if req.OldPassword != user.Password {
return nil, xerr.NewErrMsgErr("旧密码有误", err)
}
if req.NewPassword != req.ConfirmPassword {
return nil, xerr.NewErrMsgErr("输入的密码不一致", err)
}
user.Password = req.ConfirmPassword
if err = transaction.MustUseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user); err != nil {
return err
}
return nil
}); err != nil {
return nil, xerr.NewErrMsgErr("更新失败", err)
}
return
}
... ...
package auth
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemAuthEditUserInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemAuthEditUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemAuthEditUserInfoLogic {
return &SystemAuthEditUserInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemAuthEditUserInfoLogic) SystemAuthEditUserInfo(req *types.EditUserInfoRequest) (resp *types.UserInfoResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.SysUser
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, token.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
if req.Phone != nil {
if user, err = l.svcCtx.UserRepository.FindOneByPhone(l.ctx, conn, *req.Phone); err != nil {
return nil, xerr.NewErrMsgErr("手机号已被占用", err)
}
user.Phone = *req.Phone
}
if req.Name != nil {
user.Name = *req.Name
}
if req.Avatar != nil {
user.Avatar = *req.Avatar
}
if err = transaction.MustUseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user); err != nil {
return err
}
return nil
}); err != nil {
return nil, xerr.NewErrMsgErr("更新失败", err)
}
return
}
... ...
... ... @@ -44,7 +44,7 @@ func (l *SystemAuthLoginLogic) SystemAuthLogin(req *types.AuthLoginRequest) (res
company *domain.SysCompany
)
if user, err = l.svcCtx.UserRepository.FindOneByPhone(l.ctx, conn, req.Phone); err != nil {
return nil, xerr.NewErr(err)
return nil, xerr.NewErrMsgErr("账号不存在", err)
}
switch req.LoginType {
case LoginTypeWechatLogin:
... ...
package auth
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/gateway/smslib"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemAuthResetPasswordLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemAuthResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemAuthResetPasswordLogic {
return &SystemAuthResetPasswordLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemAuthResetPasswordLogic) SystemAuthResetPassword(req *types.ResetPasswordRequest) (resp *types.ResetPasswordResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.SysUser
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, token.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
var (
skipCheckSmsCode bool = false
)
if l.svcCtx.Config.DebugSmsCode != "" && l.svcCtx.Config.DebugSmsCode == req.Code {
skipCheckSmsCode = true
}
if _, err = l.svcCtx.SmsService.CheckSmsCode(l.ctx, smslib.RequestCheckSmsCode{Phone: user.Phone, Code: req.Code}); err != nil && !skipCheckSmsCode {
return nil, xerr.NewErrMsgErr(err.Error(), err)
}
if req.NewPassword != req.ConfirmPassword {
return nil, xerr.NewErrMsgErr("输入的密码不一致", err)
}
user.Password = req.ConfirmPassword
if err = transaction.MustUseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user); err != nil {
return err
}
return nil
}); err != nil {
return nil, xerr.NewErrMsgErr("更新失败", err)
}
return
}
... ...
... ... @@ -2,6 +2,9 @@ package auth
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
... ... @@ -24,7 +27,36 @@ func NewSystemAuthSwitchCompanyLogic(ctx context.Context, svcCtx *svc.ServiceCon
}
func (l *SystemAuthSwitchCompanyLogic) SystemAuthSwitchCompany(req *types.SwitchCompanyRequest) (resp *types.AuthLoginResponse, err error) {
// todo: add your logic here and delete this line
var (
conn = l.svcCtx.DefaultDBConn()
company *domain.SysCompany
user *domain.SysUser
employee *domain.SysEmployee
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
if employee, err = l.svcCtx.EmployeeRepository.FindOneByUserId(l.ctx, conn, req.CompanyId, token.UserId); err != nil {
return nil, xerr.NewErrMsgErr("账号不存在", err)
}
if employee.AccountStatus != domain.Enable {
return nil, xerr.NewErrMsgErr("账号已被禁用", err)
}
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, employee.UserId); err != nil {
return nil, xerr.NewErrMsgErr("账号不存在", err)
}
if company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, employee.CompanyId); err != nil {
return nil, xerr.NewErrMsgErr("账号不存在", err)
}
if company.Status != domain.Enable {
return nil, xerr.NewErrMsgErr("公司已被禁用", err)
}
userToken := contextdata.UserToken{
CompanyId: employee.CompanyId,
UserId: user.Id,
EmployeeId: employee.Id,
}
tokenStr, _ := userToken.GenerateToken(l.svcCtx.Config.SystemAuth.AccessSecret, l.svcCtx.Config.SystemAuth.AccessExpire)
resp = &types.AuthLoginResponse{
Token: tokenStr,
}
return
}
... ...
... ... @@ -3,6 +3,7 @@ package auth
import (
"context"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/collection"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
... ... @@ -31,8 +32,7 @@ func (l *SystemAuthUserInfoLogic) SystemAuthUserInfo(req *types.UserInfoRequest)
conn = l.svcCtx.DefaultDBConn()
company *domain.SysCompany
user *domain.SysUser
employee *domain.SysEmployee
companies []types.Company
companies []types.AccountInfo
)
if company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId); err != nil {
return nil, xerr.NewErr(err)
... ... @@ -40,30 +40,110 @@ func (l *SystemAuthUserInfoLogic) SystemAuthUserInfo(req *types.UserInfoRequest)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId); err != nil {
return nil, xerr.NewErr(err)
}
if employee, err = l.svcCtx.EmployeeRepository.FindOne(l.ctx, conn, req.EmployeeId); err != nil {
return nil, xerr.NewErr(err)
}
if _, employees, _ := l.svcCtx.EmployeeRepository.FindByUserId(l.ctx, conn, req.UserId); len(employees) > 0 {
for _, e := range employees {
if c, _ := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, e.CompanyId); c != nil {
companies = append(companies, NewTypesCompany(c))
if findOne, _ := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, e.CompanyId); findOne != nil && findOne.Status == domain.Enable {
companies = append(companies, types.AccountInfo{
Company: NewTypesCompany(findOne),
Selected: findOne.Id == company.Id,
})
}
}
}
resp = &types.UserInfoResponse{
Id: user.Id,
Name: user.Name,
Phone: user.Phone,
Company: &types.Company{
Id: company.Id,
Name: company.Name,
},
EmployeeInfo: lo.ToPtr(NewTypesEmployee(employee)),
CompanyList: companies,
Id: user.Id,
Name: user.Name,
Phone: user.Phone,
Avatar: user.Avatar,
Accounts: companies,
Menus: l.GetUserAuthMenus(user.Id, company.Id, user.Phone == company.BaseInfo.ContactPhone),
Apps: l.GetUserApps(user.Id, company.Id),
}
return
}
func (l *SystemAuthUserInfoLogic) GetUserAuthMenus(userId int64, companyId int64, isCompanyAdmin bool) []types.Menu {
var (
conn = l.svcCtx.DefaultDBConn()
)
var typesMenus = make([]types.Menu, 0)
var menusSet = collection.NewSet()
_, roles, _ := l.svcCtx.RoleRepository.FindByEmployee(l.ctx, conn, companyId, userId, domain.NewQueryOptions().WithFindOnly())
var hasAllAuth bool
for _, role := range roles {
if !lo.Contains(role.AuthUsers, userId) {
continue
}
if role.AuthRange == domain.AuthRangeAll {
hasAllAuth = true
}
menusSet.Add(lo.ToAnySlice(role.Menus)...)
}
menuLazyLoad := domain.NewLazyLoadService(domain.FineOneMenu)
menuIds := menusSet.KeysInt64()
if isCompanyAdmin || hasAllAuth {
for _, menu := range domain.DefaultMenus {
typesMenus = append(typesMenus, types.NewTypesMenu(menu))
}
} else {
for _, menuId := range menuIds {
if menu, _ := menuLazyLoad.Load(l.ctx, conn, menuId); menu != nil {
typesMenus = append(typesMenus, types.NewTypesMenu(menu))
}
}
}
// TODO:先给所有菜单,后期修改
if len(typesMenus) == 0 {
for _, menu := range domain.DefaultMenus {
typesMenus = append(typesMenus, types.NewTypesMenu(menu))
}
}
return typesMenus
}
func (l *SystemAuthUserInfoLogic) GetUserApps(userId int64, companyId int64) []types.SystemAppItem {
var (
conn = l.svcCtx.DefaultDBConn()
typesApps = make([]types.SystemAppItem, 0)
companyApps []*domain.SysCompanyApp
err error
)
if _, companyApps, err = l.svcCtx.CompanyAppRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().MustWithKV("companyId", companyId)); err != nil {
return typesApps
}
lazyApp := domain.NewLazyLoadService(l.svcCtx.AppRepository.FindOne)
for _, companyApp := range companyApps {
var app, _ = lazyApp.Load(l.ctx, conn, companyApp.AppId)
if app == nil {
continue
}
typeApp := types.NewTypesSystemAppItem(app, companyApp)
// 有指定用户权限
if len(companyApp.VisibleUsers) > 0 && lo.Contains(companyApp.VisibleUsers, userId) {
typeApp.HasAuth = true
}
// 有部门权限
if !(typeApp.HasAuth) && len(companyApp.VisibleDepartments) > 0 {
_, departments, _ := l.svcCtx.UserDepartmentRepository.FindByUser(l.ctx, conn, companyId, []int64{userId})
if lo.ContainsBy(departments, func(item *domain.SysUserDepartment) bool {
for _, id := range companyApp.VisibleDepartments {
if id == item.DepartmentId {
return true
}
}
return false
}) {
typeApp.HasAuth = true
}
}
typesApps = append(typesApps, typeApp)
}
return typesApps
}
func NewDomainSysEmployee(item types.Employee) *domain.SysEmployee {
return &domain.SysEmployee{}
}
... ...
... ... @@ -100,7 +100,7 @@ func (l *SystemEmployeeUpdateLogic) SystemEmployeeUpdate(req *types.EmployeeUpda
return nil
}); err != nil {
return nil, xerr.NewErrMsgErr("更新失败", err)
}
return
... ...
package role
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemMenuListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemMenuListLogic {
return &SystemMenuListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemMenuListLogic) SystemMenuList(req *types.MenuListRequest) (resp *types.MenuListResponse, err error) {
// todo: add your logic here and delete this line
resp = &types.MenuListResponse{}
for _, menu := range domain.DefaultMenus {
resp.List = append(resp.List, types.NewTypesMenu(menu))
}
return
}
... ...
package role
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemRoleDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemRoleDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemRoleDeleteLogic {
return &SystemRoleDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemRoleDeleteLogic) SystemRoleDelete(req *types.RoleDeleteRequest) (resp *types.RoleDeleteResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.SysRole
)
if dm, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if dm, err = l.svcCtx.RoleRepository.Delete(l.ctx, conn, dm); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("移除失败", err)
}
return
}
... ...
package role
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemRoleGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemRoleGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemRoleGetLogic {
return &SystemRoleGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemRoleGetLogic) SystemRoleGet(req *types.RoleGetRequest) (resp *types.RoleGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.SysRole
)
// 货号唯一
if dm, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
userLazyLoad := domain.NewLazyLoadService(l.svcCtx.UserRepository.FindOne)
menuLazyLoad := domain.NewLazyLoadService(domain.FineOneMenu)
role := NewTypesSysRole(dm)
for _, userId := range dm.AuthUsers {
if user, _ := userLazyLoad.Load(l.ctx, conn, userId); user != nil {
role.AuthUsers = append(role.AuthUsers, types.NewTypesUser(user))
}
}
for _, menuId := range dm.Menus {
if menu, _ := menuLazyLoad.Load(l.ctx, conn, menuId); menu != nil {
role.Menus = append(role.Menus, types.NewTypesMenu(menu))
}
}
resp = &types.RoleGetResponse{
Role: role,
}
return
}
... ...
package role
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemRoleSaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemRoleSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemRoleSaveLogic {
return &SystemRoleSaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemRoleSaveLogic) SystemRoleSave(req *types.RoleSaveRequest) (resp *types.RoleSaveResponse, err error) {
var (
//conn = l.svcCtx.DefaultDBConn()
dm *domain.SysRole
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
// 唯一判断
dm = NewDomainSysRole(token.CompanyId, req.Role)
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.RoleRepository.Insert(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("保存失败")
}
resp = &types.RoleSaveResponse{}
return
}
func NewDomainSysRole(companyId int64, item types.Role) *domain.SysRole {
menus := domain.Values(item.Menus, func(item types.Menu) int64 {
return item.Id
})
users := domain.Values(item.AuthUsers, func(item types.User) int64 {
return item.Id
})
if item.AuthRange == 0 {
if len(menus) == len(domain.DefaultMenus) {
item.AuthRange = domain.AuthRangeAll
} else {
item.AuthRange = domain.AuthRangePart
}
}
return &domain.SysRole{
CompanyId: companyId,
Name: item.Name,
Menus: menus,
AuthUsers: users,
AuthRange: item.AuthRange,
}
}
func NewTypesSysRole(item *domain.SysRole) types.Role {
return types.Role{
Id: item.Id,
Name: item.Name,
AuthRange: item.AuthRange,
UpdatedAt: item.UpdatedAt,
}
}
... ...
package role
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemRoleSearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemRoleSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemRoleSearchLogic {
return &SystemRoleSearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemRoleSearchLogic) SystemRoleSearch(req *types.RoleSearchRequest) (resp *types.RoleSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.SysRole
total int64
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
WithKV("userName", req.UserName).
WithKV("roleName", req.RoleName)
total, dms, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, queryOptions)
list := make([]types.Role, 0)
userLazyLoad := domain.NewLazyLoadService(l.svcCtx.UserRepository.FindOne)
menuLazyLoad := domain.NewLazyLoadService(domain.FineOneMenu)
for i := range dms {
role := NewTypesSysRole(dms[i])
for j, userId := range dms[i].AuthUsers {
// 超过十名的不查用户信息
if j > 5 {
role.AuthUsers = append(role.AuthUsers, types.NewTypesUser(&domain.SysUser{Id: userId}))
}
if user, _ := userLazyLoad.Load(l.ctx, conn, userId); user != nil {
role.AuthUsers = append(role.AuthUsers, types.NewTypesUser(user))
}
}
for _, menuId := range dms[i].Menus {
if menu, _ := menuLazyLoad.Load(l.ctx, conn, menuId); menu != nil {
role.Menus = append(role.Menus, types.NewTypesMenu(menu))
}
}
list = append(list, role)
}
resp = &types.RoleSearchResponse{
List: list,
Total: total,
}
return
}
... ...
package role
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemRoleUpdateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemRoleUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemRoleUpdateLogic {
return &SystemRoleUpdateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemRoleUpdateLogic) SystemRoleUpdate(req *types.RoleUpdateRequest) (resp *types.RoleUpdateResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.SysRole
)
if dm, err = l.svcCtx.RoleRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 不可编辑判断
// 赋值
menus := domain.Values(req.Role.Menus, func(item types.Menu) int64 {
return item.Id
})
users := domain.Values(req.Role.AuthUsers, func(item types.User) int64 {
return item.Id
})
dm.Name = req.Role.Name
dm.Menus = menus
dm.AuthUsers = users
if req.Role.AuthRange == 0 {
if len(menus) == len(domain.DefaultMenus) {
dm.AuthRange = domain.AuthRangeAll
} else {
dm.AuthRange = domain.AuthRangePart
}
} else {
dm.AuthRange = req.Role.AuthRange
}
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.RoleRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.RoleUpdateResponse{}
return
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type UserCompanyUsersLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserCompanyUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserCompanyUsersLogic {
return &UserCompanyUsersLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UserCompanyUsersLogic) UserCompanyUsers(req *types.CompanyUsersRequest) (resp *types.CompanyUsersResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
users []*domain.SysUser
//total int64
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
options := domain.NewQueryOptions().MustWithKV("companyId", token.CompanyId).WithFindOnly()
_, users, _ = l.svcCtx.UserRepository.Find(l.ctx, conn, options)
resp = &types.CompanyUsersResponse{
List: make([]types.User, 0),
}
for _, user := range users {
resp.List = append(resp.List, types.NewTypesUser(user))
}
return
}
... ...
package types
import "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
func NewTypesSystemAppItem(item *domain.SysApp, cp *domain.SysCompanyApp) SystemAppItem {
return SystemAppItem{
Id: cp.Id,
Code: item.Code,
Name: item.Name,
Logo: item.Logo,
Description: item.Description,
Type: item.Type,
VersionNumber: item.VersionNumber,
Status: cp.Status,
VisibleFlag: cp.VisibleFlag,
VisibleUsers: cp.VisibleUsers,
Sort: cp.Sort,
}
}
... ...
package types
import (
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
)
func NewTypesMenu(m *domain.SysMenu) Menu {
return Menu{
Id: m.Id,
ParentId: m.ParentId,
Name: m.Name,
Code: m.Code,
Sort: m.Sort,
MenuType: m.MenuType,
Icon: m.Icon,
}
}
... ...
... ... @@ -2,9 +2,10 @@
package types
type User struct {
Id int64 `json:"id"` // 用户ID
Name string `json:"name"` // 用户名称
Phone string `json:"phone,optional,omitempty"` // 用户手机号
Id int64 `json:"id,optional"` // 用户ID
Name string `json:"name,optional"` // 用户名称
Phone string `json:"phone,optional,omitempty"` // 用户手机号
Avatar string `json:"avatar,optional,omitempty"` // 头像
}
type CompanyRegisterRequest struct {
... ... @@ -36,16 +37,53 @@ type UserInfoRequest struct {
}
type UserInfoResponse struct {
Id int64 `json:"id"` // 用户ID
Name string `json:"name"` // 用户名称
Phone string `json:"phone"` // 用户手机号
EmployeeInfo *Employee `json:"employeeInfo"` // 职员信息
Company *Company `json:"company"` // 当前公司信息
CompanyList []Company `json:"companies"` // 拥有的公司
Id int64 `json:"id"` // 用户ID
Avatar string `json:"avatar"` // 头像
Name string `json:"name"` // 用户名称
Phone string `json:"phone"` // 用户手机号
Accounts []AccountInfo `json:"accounts"` // 账号列表
Apps []SystemAppItem `json:"apps"` // 应用列表
Menus []Menu `json:"menus"` // 有权限的菜单
}
type AccountInfo struct {
Company Company `json:"company"` // 公司
Selected bool `json:"selected"` // 当前选择的账号
}
type EditUserInfoRequest struct {
Avatar *string `json:"avatar,optional"` // 头像
Name *string `json:"name,optional"` // 用户名称
Phone *string `json:"phone,optional"` // 用户手机号
}
type ChangePasswordRequest struct {
OldPassword string `json:"oldPassword,optional"` // 旧密码
NewPassword string `json:"newPassword"` // 新密码
ConfirmPassword string `json:"confirmPassword"` // 确认密码
}
type ChangePasswordResponse struct {
}
type ResetPasswordRequest struct {
Code string `json:"code"` // 验证码
NewPassword string `json:"newPassword"` // 新密码
ConfirmPassword string `json:"confirmPassword"` // 确认密码
}
type ResetPasswordResponse struct {
}
type SwitchCompanyRequest struct {
CompanyId int64 `json:"companyId"` // 公司ID
CompanyId int64 `json:"companyId,string"` // 公司ID
}
type CompanyUsersRequest struct {
}
type CompanyUsersResponse struct {
List []User `json:"list"` // 用户列表
}
type SystemCompanyInfoRequest struct {
... ... @@ -142,8 +180,71 @@ type DepartmentImportResponse struct {
}
type Role struct {
Id int64 `json:"id"` // 角色ID
Name string `json:"name"` // 角色名称
Id int64 `json:"id,optional,omitempty"` // 角色ID
Name string `json:"name,optional,omitempty"` // 角色名称
Menus []Menu `json:"menus,optional,omitempty"` // 菜单列表
AuthUsers []User `json:"users,optional,omitempty"` // 拥护该角色的用户列表 user_id 列表
AuthRange int `json:"authRange,optional,omitempty,option=0|1|2"` // 权限范围(1:全部权限 2:部分权限)
UpdatedAt int64 `json:"updatedAt,optional,omitempty"` // 更新时间
}
type RoleGetRequest struct {
Id int64 `path:"id"`
}
type RoleGetResponse struct {
Role Role `json:"role"`
}
type RoleSaveRequest struct {
Role Role `json:"role"`
}
type RoleSaveResponse struct {
}
type RoleDeleteRequest struct {
Id int64 `path:"id"`
}
type RoleDeleteResponse struct {
}
type RoleUpdateRequest struct {
Id int64 `path:"id"`
Role Role `json:"role"`
}
type RoleUpdateResponse struct {
}
type RoleSearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
RoleName string `json:"rolename,optional"` // 角色名称
UserName string `json:"userName,optional"` // 用户名称
}
type RoleSearchResponse struct {
List []Role `json:"list"`
Total int64 `json:"total"`
}
type MenuListRequest struct {
}
type MenuListResponse struct {
List []Menu `json:"list"`
}
type Menu struct {
Id int64 `json:"id,optional,omitempty"` // 菜单ID
ParentId int64 `json:"parentId,optional"` // 父级ID
Name string `json:"name,optional,omitempty"` // 菜单名称
Code string `json:"code,optional,omitempty"` // 菜单编码
MenuType string `json:"menuType,optional,omitempty"` // 菜单类型 (目录catalog、菜单menu、按钮button)
Icon string `json:"icon,optional,omitempty"` // 图标
Sort int64 `json:"sort,optional,omitempty"` // 排序
}
type Group struct {
... ... @@ -186,11 +287,14 @@ type SystemAppItem struct {
VisibleFlag int `json:"visibleFlag,omitempty"` // 1:全员可见 2:部分可见
VisibleUsers []int64 `json:"visibleUsers,omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表
Sort int `json:"sort,omitempty"` // 排序
HasAuth bool `json:"hasAuth"` // true:用户有权限 false:用户无权限
}
type SystemAppSetConfigRequest struct {
VisibleFlag int `json:"visibleFlag"` // 1:全员可见 2:部分可见
VisibleUsers []int64 `json:"visibleUsers"` // 可见的用户 所有用户:空 部分用户:用户ID列表
AppId int64 `json:"id"` // 公司应用ID
VisibleFlag int `json:"visibleFlag"` // 1:全员可见 2:部分可见
VisibleUsers []int64 `json:"visibleUsers"` // 可见的用户 所有用户:空 部分用户:用户ID列表
VisibleDepartments []int64 `json:"visibleDepartments"` // 可见的部门 部门ID列表
}
type SystemAppSetConfigResponse struct {
... ...
package types
import "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
func NewTypesUser(user *domain.SysUser) User {
return User{
Id: user.Id,
Name: user.Name,
Phone: user.Phone,
Avatar: user.Avatar,
}
}
... ...
alter table sys.company_app add column visible_departments jsonb;
update sys.company_app set visible_departments = '[]';
\ No newline at end of file
... ...
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: sys_company_app
jwt: JwtAuth
)
service Core {
@doc "详情"
@handler sys_company_appGet
get /sys_company_app/:id (SysCompanyAppGetRequest) returns (SysCompanyAppGetResponse)
@doc "保存"
@handler sys_company_appSave
post /sys_company_app (SysCompanyAppSaveRequest) returns (SysCompanyAppSaveResponse)
@doc "删除"
@handler sys_company_appDelete
delete /sys_company_app/:id (SysCompanyAppDeleteRequest) returns (SysCompanyAppDeleteResponse)
@doc "更新"
@handler sys_company_appUpdate
put /sys_company_app/:id (SysCompanyAppUpdateRequest) returns (SysCompanyAppUpdateResponse)
@doc "搜索"
@handler sys_company_appSearch
post /sys_company_app/search (SysCompanyAppSearchRequest) returns (SysCompanyAppSearchResponse)
}
type (
SysCompanyAppGetRequest {
Id int64 `path:"id"`
}
SysCompanyAppGetResponse struct{
SysCompanyApp SysCompanyAppItem `json:"sys_company_app"`
}
SysCompanyAppSaveRequest struct{
SysCompanyApp SysCompanyAppItem `json:"sys_company_app"`
}
SysCompanyAppSaveResponse struct{}
SysCompanyAppDeleteRequest struct{
Id int64 `path:"id"`
}
SysCompanyAppDeleteResponse struct{}
SysCompanyAppUpdateRequest struct{
Id int64 `path:"id"`
SysCompanyApp SysCompanyAppItem `json:"sys_company_app"`
}
SysCompanyAppUpdateResponse struct{}
SysCompanyAppSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
SysCompanyAppSearchResponse{
List []SysCompanyAppItem `json:"list"`
Total int64 `json:"total"`
}
SysCompanyAppItem struct{
}
)
// logic CRUD
// Save
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.SysCompanyApp
//)
//// 唯一判断
//dm = NewDomainSysCompanyApp(req.SysCompanyApp)
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.SysCompanyAppRepository.Insert(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("保存失败")
//}
////resp = &types.SysCompanyAppSaveResponse{}
//return
//func NewDomainSysCompanyApp(item types.SysCompanyAppItem) *domain.SysCompanyApp {
// return &domain.SysCompanyApp{
// }
//}
//
//func NewTypesSysCompanyApp(item *domain.SysCompanyApp) types.SysCompanyAppItem {
// return types.SysCompanyAppItem{
// Id: item.Id,
// }
//}
// Get
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.SysCompanyApp
//)
//// 货号唯一
//if dm, err = l.svcCtx.SysCompanyAppRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//resp = &types.SysCompanyAppGetResponse{
// SysCompanyApp: NewTypesSysCompanyApp(dm),
//}
//return
// Delete
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.SysCompanyApp
//)
//if dm, err = l.svcCtx.SysCompanyAppRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// if dm, err = l.svcCtx.SysCompanyAppRepository.Delete(l.ctx, conn, dm); err != nil {
// return err
// }
// return nil
//}, true); err != nil {
// return nil, xerr.NewErrMsgErr("移除失败", err)
//}
//return
// Search
//var (
// conn = l.svcCtx.DefaultDBConn()
// dms []*domain.SysCompanyApp
// total int64
//)
//
//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
// WithKV("", "")
//total, dms, err = l.svcCtx.SysCompanyAppRepository.Find(l.ctx, conn, queryOptions)
//list := make([]types.SysCompanyAppItem, 0)
//for i := range dms {
// list = append(list, NewTypesSysCompanyApp(dms[i]))
//}
//resp = &types.SysCompanyAppSearchResponse{
// List: list,
// Total: total,
//}
//return
// Update
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.SysCompanyApp
//)
//if dm, err = l.svcCtx.SysCompanyAppRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//// 不可编辑判断
//// 赋值
//// 更新
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.SysCompanyAppRepository.UpdateWithVersion(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("更新失败")
//}
//resp = &types.SysCompanyAppUpdateResponse{}
//return
... ...
syntax = "proto3";
option go_package ="./pb";
package pb;
message SysCompanyAppGetReq {
int64 Id = 1;
}
message SysCompanyAppGetResp{
SysCompanyAppItem SysCompanyApp = 1;
}
message SysCompanyAppSaveReq {
}
message SysCompanyAppSaveResp{
}
message SysCompanyAppDeleteReq {
int64 Id = 1;
}
message SysCompanyAppDeleteResp{
}
message SysCompanyAppUpdateReq {
int64 Id = 1;
}
message SysCompanyAppUpdateResp{
}
message SysCompanyAppSearchReq {
int64 PageNumber = 1;
int64 PageSize = 2;
}
message SysCompanyAppSearchResp{
repeated SysCompanyAppItem List =1;
int64 Total =2;
}
message SysCompanyAppItem {
}
service SysCompanyAppService {
rpc SysCompanyAppGet(SysCompanyAppGetReq) returns(SysCompanyAppGetResp);
rpc SysCompanyAppSave(SysCompanyAppSaveReq) returns(SysCompanyAppSaveResp);
rpc SysCompanyAppDelete(SysCompanyAppDeleteReq) returns(SysCompanyAppDeleteResp);
rpc SysCompanyAppUpdate(SysCompanyAppUpdateReq) returns(SysCompanyAppUpdateResp);
rpc SysCompanyAppSearch(SysCompanyAppSearchReq) returns(SysCompanyAppSearchResp);
}
... ...
... ... @@ -17,7 +17,7 @@ service Core {
post /system/app/search (SystemAppSearchRequest) returns (SystemAppSearchResponse)
@doc "应用-设置配置"
@handler systemAppSetConfig
get /system/app/set_config (SystemAppSetConfigRequest) returns (SystemAppSetConfigResponse)
post /system/app/set_config (SystemAppSetConfigRequest) returns (SystemAppSetConfigResponse)
}
type (
... ... @@ -52,14 +52,17 @@ type (
VisibleFlag int `json:"visibleFlag,omitempty"` // 1:全员可见 2:部分可见
VisibleUsers []int64 `json:"visibleUsers,omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表
Sort int `json:"sort,omitempty"` // 排序
HasAuth bool `json:"hasAuth"` // true:用户有权限 false:用户无权限
}
)
// 应用-设置配置
type(
SystemAppSetConfigRequest{
VisibleFlag int `json:"visibleFlag"` // 1:全员可见 2:部分可见
VisibleUsers []int64 `json:"visibleUsers"` // 可见的用户 所有用户:空 部分用户:用户ID列表
AppId int64 `json:"id"` // 公司应用ID
VisibleFlag int `json:"visibleFlag"` // 1:全员可见 2:部分可见
VisibleUsers []int64 `json:"visibleUsers"` // 可见的用户 所有用户:空 部分用户:用户ID列表
VisibleDepartments []int64 `json:"visibleDepartments"` // 可见的部门 部门ID列表
}
SystemAppSetConfigResponse{
SystemApp SystemAppItem `json:"app"`
... ...
... ... @@ -2,7 +2,94 @@ syntax = "v1"
type(
Role{
Id int64 `json:"id"` // 角色ID
Name string `json:"name"` // 角色名称
Id int64 `json:"id,optional,omitempty"` // 角色ID
Name string `json:"name,optional,omitempty"` // 角色名称
Menus []Menu `json:"menus,optional,omitempty"` // 菜单列表
AuthUsers []User `json:"users,optional,omitempty"` // 拥护该角色的用户列表 user_id 列表
AuthRange int `json:"authRange,optional,omitempty,option=0|1|2"` // 权限范围(1:全部权限 2:部分权限)
UpdatedAt int64 `json:"updatedAt,optional,omitempty"` // 更新时间
}
)
@server(
prefix: v1/system
group: role
middleware: LogRequest
jwt: SystemAuth
)
service Core {
@doc "角色-详情"
@handler systemRoleGet
get /role/:id (RoleGetRequest) returns (RoleGetResponse)
@doc "角色-保存"
@handler systemRoleSave
post /role (RoleSaveRequest) returns (RoleSaveResponse)
@doc "角色-删除"
@handler systemRoleDelete
delete /role/:id (RoleDeleteRequest) returns (RoleDeleteResponse)
@doc "角色-更新"
@handler systemRoleUpdate
put /role/:id (RoleUpdateRequest) returns (RoleUpdateResponse)
@doc "角色-搜索"
@handler systemRoleSearch
post /role/search (RoleSearchRequest) returns (RoleSearchResponse)
@doc "菜单-列表"
@handler systemMenuList
post /menu/list (MenuListRequest) returns (MenuListResponse)
}
type (
RoleGetRequest {
Id int64 `path:"id"`
}
RoleGetResponse struct{
Role Role `json:"role"`
}
RoleSaveRequest struct{
Role Role `json:"role"`
}
RoleSaveResponse struct{}
RoleDeleteRequest struct{
Id int64 `path:"id"`
}
RoleDeleteResponse struct{}
RoleUpdateRequest struct{
Id int64 `path:"id"`
Role Role `json:"role"`
}
RoleUpdateResponse struct{}
RoleSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
RoleName string `json:"rolename,optional"` // 角色名称
UserName string `json:"userName,optional"` // 用户名称
}
RoleSearchResponse{
List []Role `json:"list"`
Total int64 `json:"total"`
}
)
// 菜单列表
type(
MenuListRequest{
}
MenuListResponse{
List []Menu `json:"list"`
}
Menu{
Id int64 `json:"id,optional,omitempty"` // 菜单ID
ParentId int64 `json:"parentId,optional"` // 父级ID
Name string `json:"name,optional,omitempty"` // 菜单名称
Code string `json:"code,optional,omitempty"` // 菜单编码
MenuType string `json:"menuType,optional,omitempty"` // 菜单类型 (目录catalog、菜单menu、按钮button)
Icon string `json:"icon,optional,omitempty"` // 图标
Sort int64 `json:"sort,optional,omitempty"` // 排序
}
)
\ No newline at end of file
... ...
... ... @@ -34,16 +34,39 @@ service Core {
@doc "系统用户信息"
@handler systemAuthUserInfo
post /auth/user_info(UserInfoRequest) returns (UserInfoResponse)
@doc "修改用户信息"
@handler systemAuthEditUserInfo
post /auth/edit_user_info(EditUserInfoRequest) returns (UserInfoResponse)
@doc "修改密码"
@handler systemAuthChangePassword
post /auth/change_password(ChangePasswordRequest) returns (ChangePasswordResponse)
@doc "重置密码"
@handler systemAuthResetPassword
post /auth/reset_password(ResetPasswordRequest) returns (ResetPasswordResponse)
@doc "系统用户信息"
@handler systemAuthSwitchCompany
post /auth/switch_company(SwitchCompanyRequest) returns (AuthLoginResponse)
}
@server(
prefix: v1
group: user
middleware: LogRequest
jwt: SystemAuth
)
service Core {
@doc "公司用户列表"
@handler userCompanyUsers
post /user/company_users(CompanyUsersRequest) returns (CompanyUsersResponse)
}
type(
User{
Id int64 `json:"id"` // 用户ID
Name string `json:"name"` // 用户名称
Phone string `json:"phone,optional,omitempty"` // 用户手机号
Id int64 `json:"id,optional"` // 用户ID
Name string `json:"name,optional"` // 用户名称
Phone string `json:"phone,optional,omitempty"` // 用户手机号
Avatar string `json:"avatar,optional,omitempty"`// 头像
}
)
... ... @@ -81,17 +104,71 @@ type(
EmployeeId int64 `json:"employeeId,optional"`
}
UserInfoResponse{
Id int64 `json:"id"` // 用户ID
Name string `json:"name"` // 用户名称
Phone string `json:"phone"` // 用户手机号
EmployeeInfo *Employee `json:"employeeInfo"` // 职员信息
Company *Company `json:"company"` // 当前公司信息
CompanyList []Company `json:"companies"` // 拥有的公司
Id int64 `json:"id"` // 用户ID
Avatar string `json:"avatar"` // 头像
Name string `json:"name"` // 用户名称
Phone string `json:"phone"` // 用户手机号
Accounts []AccountInfo `json:"accounts"` // 账号列表
Apps []SystemAppItem `json:"apps"` // 应用列表
Menus []Menu `json:"menus"` // 有权限的菜单
}
AccountInfo{
//EmployeeId int64 `json:"employeeId"` // 职员ID
Company Company `json:"company"` // 公司
Selected bool `json:"selected"` // 当前选择的账号
}
)
// 修改用户信息
type(
EditUserInfoRequest{
Avatar *string `json:"avatar,optional"` // 头像
Name *string `json:"name,optional"` // 用户名称
Phone *string `json:"phone,optional"` // 用户手机号
//Password *string `json:"password,optional"` // 密码base64((MD5))
}
// UserInfoResponse{
//
// }
)
// 修改密码
type(
ChangePasswordRequest{
OldPassword string `json:"oldPassword,optional"` // 旧密码
NewPassword string `json:"newPassword"` // 新密码
ConfirmPassword string `json:"confirmPassword"` // 确认密码
}
ChangePasswordResponse{
}
)
// 重置密码
type(
ResetPasswordRequest{
Code string `json:"code"` // 验证码
NewPassword string `json:"newPassword"` // 新密码
ConfirmPassword string `json:"confirmPassword"` // 确认密码
}
ResetPasswordResponse{
}
)
// 切换公司请求
type(
SwitchCompanyRequest{
CompanyId int64 `json:"companyId"` // 公司ID
CompanyId int64 `json:"companyId,string"` // 公司ID
}
)
// 公司用户搜索
type(
CompanyUsersRequest{
}
CompanyUsersResponse{
List []User `json:"list"` // 用户列表
}
)
\ No newline at end of file
... ...
... ... @@ -15,6 +15,34 @@
"application/json"
],
"paths": {
"v1/auth/change_password": {
"post": {
"summary": "修改密码",
"operationId": "systemAuthChangePassword",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChangePasswordResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChangePasswordRequest"
}
}
],
"requestBody": {},
"tags": [
"auth"
]
}
},
"v1/auth/company_sign_up": {
"post": {
"summary": "公司注册",
... ... @@ -43,6 +71,34 @@
]
}
},
"v1/auth/edit_user_info": {
"post": {
"summary": "修改用户信息",
"operationId": "systemAuthEditUserInfo",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/UserInfoResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/EditUserInfoRequest"
}
}
],
"requestBody": {},
"tags": [
"auth"
]
}
},
"v1/auth/login": {
"post": {
"summary": "系统用户登录",
... ... @@ -71,6 +127,62 @@
]
}
},
"v1/auth/reset_password": {
"post": {
"summary": "重置密码",
"operationId": "systemAuthResetPassword",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ResetPasswordResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ResetPasswordRequest"
}
}
],
"requestBody": {},
"tags": [
"auth"
]
}
},
"v1/auth/switch_company": {
"post": {
"summary": "系统用户信息",
"operationId": "systemAuthSwitchCompany",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/AuthLoginResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SwitchCompanyRequest"
}
}
],
"requestBody": {},
"tags": [
"auth"
]
}
},
"v1/auth/user_info": {
"post": {
"summary": "系统用户信息",
... ... @@ -781,9 +893,202 @@
"employee"
]
}
},
"v1/system/menu/list": {
"post": {
"summary": "菜单-列表",
"operationId": "systemMenuList",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MenuListResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MenuListRequest"
}
}
],
"requestBody": {},
"tags": [
"role"
]
}
},
"v1/system/role": {
"post": {
"summary": "角色-保存",
"operationId": "systemRoleSave",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/RoleSaveResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RoleSaveRequest"
}
}
],
"requestBody": {},
"tags": [
"role"
]
}
},
"v1/system/role/search": {
"post": {
"summary": "角色-搜索",
"operationId": "systemRoleSearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/RoleSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RoleSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"role"
]
}
},
"v1/system/role/{id}": {
"get": {
"summary": "角色-详情",
"operationId": "systemRoleGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/RoleGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"role"
]
},
"delete": {
"summary": "角色-删除",
"operationId": "systemRoleDelete",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/RoleDeleteResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RoleDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"role"
]
},
"put": {
"summary": "角色-更新",
"operationId": "systemRoleUpdate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/RoleUpdateResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RoleUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"role"
]
}
}
},
"definitions": {
"AccountInfo": {
"type": "object",
"properties": {
"company": {
"$ref": "#/definitions/Company",
"description": " 公司"
},
"selected": {
"type": "boolean",
"format": "boolean",
"description": " 当前选择的账号"
}
},
"title": "AccountInfo",
"required": [
"company",
"selected"
]
},
"AuthLoginRequest": {
"type": "object",
"properties": {
... ... @@ -821,6 +1126,32 @@
"token"
]
},
"ChangePasswordRequest": {
"type": "object",
"properties": {
"oldPassword": {
"type": "string",
"description": " 旧密码"
},
"newPassword": {
"type": "string",
"description": " 新密码"
},
"confirmPassword": {
"type": "string",
"description": " 确认密码"
}
},
"title": "ChangePasswordRequest",
"required": [
"newPassword",
"confirmPassword"
]
},
"ChangePasswordResponse": {
"type": "object",
"title": "ChangePasswordResponse"
},
"Company": {
"type": "object",
"properties": {
... ... @@ -1175,6 +1506,24 @@
"type": "object",
"title": "DepartmentUpdateResponse"
},
"EditUserInfoRequest": {
"type": "object",
"properties": {
"avatar": {
"$ref": "#/definitions/string",
"description": " 头像"
},
"name": {
"$ref": "#/definitions/string",
"description": " 用户名称"
},
"phone": {
"$ref": "#/definitions/string",
"description": " 用户手机号"
}
},
"title": "EditUserInfoRequest"
},
"Employee": {
"type": "object",
"properties": {
... ... @@ -1182,6 +1531,10 @@
"type": "integer",
"format": "int64"
},
"userId": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string",
"description": " 姓名"
... ... @@ -1237,6 +1590,7 @@
"title": "Employee",
"required": [
"id",
"userId",
"name",
"code",
"phone",
... ... @@ -1255,16 +1609,14 @@
"employeeList": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
"type": "string"
},
"description": " 职员列表"
},
"departments": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
"type": "string"
},
"description": " 部门列表"
}
... ... @@ -1374,7 +1726,10 @@
"description": " 按部门过滤"
}
},
"title": "EmployeeSearchRequest"
"title": "EmployeeSearchRequest",
"required": [
"departmentId"
]
},
"EmployeeSearchResponse": {
"type": "object",
... ... @@ -1463,6 +1818,98 @@
"name"
]
},
"Menu": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 菜单ID"
},
"parentId": {
"type": "integer",
"format": "int64",
"description": " 父级ID"
},
"name": {
"type": "string",
"description": " 菜单名称"
},
"code": {
"type": "string",
"description": " 菜单编码"
},
"menuType": {
"type": "string",
"description": " 菜单类型 (目录catalog、菜单menu、按钮button)"
},
"icon": {
"type": "string",
"description": " 图标"
},
"sort": {
"type": "integer",
"format": "int64",
"description": " 排序"
}
},
"title": "Menu",
"required": [
"id",
"parentId",
"name",
"code",
"menuType",
"icon",
"sort"
]
},
"MenuListRequest": {
"type": "object",
"title": "MenuListRequest"
},
"MenuListResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/Menu"
}
}
},
"title": "MenuListResponse",
"required": [
"list"
]
},
"ResetPasswordRequest": {
"type": "object",
"properties": {
"code": {
"type": "string",
"description": " 验证码"
},
"newPassword": {
"type": "string",
"description": " 新密码"
},
"confirmPassword": {
"type": "string",
"description": " 确认密码"
}
},
"title": "ResetPasswordRequest",
"required": [
"code",
"newPassword",
"confirmPassword"
]
},
"ResetPasswordResponse": {
"type": "object",
"title": "ResetPasswordResponse"
},
"Role": {
"type": "object",
"properties": {
... ... @@ -1474,12 +1921,179 @@
"name": {
"type": "string",
"description": " 角色名称"
},
"menus": {
"type": "array",
"items": {
"$ref": "#/definitions/Menu"
},
"description": " 菜单列表"
},
"users": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
},
"description": " 拥护该角色的用户列表 user_id 列表"
},
"authRange": {
"type": "integer",
"format": "int32",
"description": " 权限范围(1:全部权限 2:部分权限)"
},
"updatedAt": {
"type": "integer",
"format": "int64",
"description": " 更新时间"
}
},
"title": "Role",
"required": [
"id",
"name"
"name",
"menus",
"users",
"authRange",
"updatedAt"
]
},
"RoleDeleteRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "RoleDeleteRequest",
"required": [
"id"
]
},
"RoleDeleteResponse": {
"type": "object",
"title": "RoleDeleteResponse"
},
"RoleGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "RoleGetRequest",
"required": [
"id"
]
},
"RoleGetResponse": {
"type": "object",
"properties": {
"role": {
"$ref": "#/definitions/Role"
}
},
"title": "RoleGetResponse",
"required": [
"role"
]
},
"RoleSaveRequest": {
"type": "object",
"properties": {
"role": {
"$ref": "#/definitions/Role"
}
},
"title": "RoleSaveRequest",
"required": [
"role"
]
},
"RoleSaveResponse": {
"type": "object",
"title": "RoleSaveResponse"
},
"RoleSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
},
"rolename": {
"type": "string",
"description": " 角色名称"
},
"userName": {
"type": "string",
"description": " 用户名称"
}
},
"title": "RoleSearchRequest",
"required": [
"page",
"size"
]
},
"RoleSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/Role"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "RoleSearchResponse",
"required": [
"list",
"total"
]
},
"RoleUpdateRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"role": {
"$ref": "#/definitions/Role"
}
},
"title": "RoleUpdateRequest",
"required": [
"id",
"role"
]
},
"RoleUpdateResponse": {
"type": "object",
"title": "RoleUpdateResponse"
},
"SwitchCompanyRequest": {
"type": "object",
"properties": {
"companyId": {
"type": "integer",
"format": "int64",
"description": " 公司ID"
}
},
"title": "SwitchCompanyRequest",
"required": [
"companyId"
]
},
"SystemAppGetRequest": {
... ... @@ -1714,13 +2328,16 @@
"phone": {
"type": "string",
"description": " 用户手机号"
},
"avatar": {
"type": "string",
"description": " 头像"
}
},
"title": "User",
"required": [
"id",
"name",
"phone"
"phone",
"avatar"
]
},
"UserInfoRequest": {
... ... @@ -1749,6 +2366,10 @@
"format": "int64",
"description": " 用户ID"
},
"avatar": {
"type": "string",
"description": " 头像"
},
"name": {
"type": "string",
"description": " 用户名称"
... ... @@ -1757,30 +2378,29 @@
"type": "string",
"description": " 用户手机号"
},
"employeeInfo": {
"$ref": "#/definitions/Employee",
"description": " 职员信息"
},
"company": {
"$ref": "#/definitions/Company",
"description": " 当前公司信息"
"accounts": {
"type": "array",
"items": {
"$ref": "#/definitions/AccountInfo"
},
"description": " 账号列表"
},
"companies": {
"apps": {
"type": "array",
"items": {
"$ref": "#/definitions/Company"
"$ref": "#/definitions/SystemAppItem"
},
"description": " 拥有的公司"
"description": " 应用列表"
}
},
"title": "UserInfoResponse",
"required": [
"id",
"avatar",
"name",
"phone",
"employeeInfo",
"company",
"companies"
"accounts",
"apps"
]
}
},
... ...
... ... @@ -14,5 +14,6 @@ func Migrate(db *gorm.DB) {
models.SysUserDepartment{},
models.SysApp{},
models.SysCompanyApp{},
models.SysRole{},
)
}
... ...
... ... @@ -8,20 +8,21 @@ import (
)
type SysCompanyApp struct {
Id int64 // 唯一标识
CompanyId int64 // 公司表ID
AppId int64 // 应用ID
Status int // 1:启用、2:停用
VisibleFlag int // 1:全员可见 2:部分可见
VisibleUsers []int64 `gorm:"type:jsonb;serializer:json"` // 可见的用户 所有用户:空 部分用户:用户ID列表
VisibleGroups []int64 `gorm:"type:jsonb;serializer:json"` // 可见的用户组 所有用户:空 部分用户:用户ID列表
AppConfig domain.AppConfig `gorm:"type:jsonb;serializer:json"` // 应用配置
Sort int // 排序
CreatedAt int64
UpdatedAt int64
DeletedAt int64
Version int
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
Id int64 // 唯一标识
CompanyId int64 // 公司表ID
AppId int64 // 应用ID
Status int // 1:启用、2:停用
VisibleFlag int // 1:全员可见 2:部分可见
VisibleUsers []int64 `gorm:"type:jsonb;serializer:json"` // 可见的用户 所有用户:空 部分用户:用户ID列表
VisibleGroups []int64 `gorm:"type:jsonb;serializer:json"` // 可见的用户组 所有用户:空 部分用户:用户ID列表
VisibleDepartments []int64 `gorm:"type:jsonb;serializer:json"` // 可见的部门 部门ID列表
AppConfig domain.AppConfig `gorm:"type:jsonb;serializer:json"` // 应用配置
Sort int // 排序
CreatedAt int64
UpdatedAt int64
DeletedAt int64
Version int
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
}
func (m *SysCompanyApp) TableName() string {
... ...
... ... @@ -13,6 +13,7 @@ type SysRole struct {
Name string // 公司名称
Menus []int64 `gorm:"type:jsonb;serializer:json"` // 菜单列表
AuthUsers []int64 `gorm:"type:jsonb;serializer:json"` // 拥护该角色的用户列表
AuthRange int
CreatedAt int64
UpdatedAt int64
DeletedAt int64
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -169,7 +170,7 @@ func (repository *SysRoleRepository) FindByEmployee(ctx context.Context, conn tr
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Where("company_id = ?", companyId).Where("auth_users @> '[?]'", userId).Order("id desc")
tx = tx.Model(&ms).Where("company_id = ?", companyId).Where(fmt.Sprintf("auth_users @> '[%d]'", userId)).Order("id desc")
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -6,19 +6,20 @@ import (
)
type SysCompanyApp struct {
Id int64 // 唯一标识
CompanyId int64 `json:",omitempty"` // 公司表ID
AppId int64 `json:",omitempty"` // 应用ID
Status int `json:",omitempty"` // 1:启用、2:停用
VisibleFlag int `json:",omitempty"` // 1:全员可见 2:部分可见
VisibleUsers []int64 `json:",omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表
VisibleGroups []int64 `json:",omitempty"` // 可见的用户组 所有用户:空 部分用户:用户ID列表
AppConfig AppConfig `json:",omitempty"` // 应用配置
Sort int `json:",omitempty"` // 排序
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
Id int64 // 唯一标识
CompanyId int64 `json:",omitempty"` // 公司表ID
AppId int64 `json:",omitempty"` // 应用ID
Status int `json:",omitempty"` // 1:启用、2:停用
VisibleFlag int `json:",omitempty"` // 1:全员可见 2:部分可见
VisibleUsers []int64 `json:",omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表
VisibleDepartments []int64 `json:",omitempty"` // 可见的部门 部门ID列表
VisibleGroups []int64 `json:",omitempty"` // 可见的用户组 所有用户:空 部分用户:用户ID列表
AppConfig AppConfig `json:",omitempty"` // 应用配置
Sort int `json:",omitempty"` // 排序
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
}
type SysCompanyAppRepository interface {
... ...
... ... @@ -9,9 +9,10 @@ import (
type SysRole struct {
Id int64 `json:",omitempty"` // 唯一标识
CompanyId int64 `json:"companyId"` // 公司ID
Name string `json:",omitempty"` // 公司名称
Name string `json:",omitempty"` // 角色名称
Menus []int64 `json:",omitempty"` // 菜单列表
AuthUsers []int64 `json:",omitempty"` // 拥护该角色的用户列表
AuthRange int `json:",omitempty"` // 权限范围(1:全部权限 2:部分权限)
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
... ... @@ -58,24 +59,39 @@ type SysMenu struct {
Version int `json:"version,omitempty"`
}
const (
AuthRangeAll = 1 // 全部权限
AuthRangePart = 2 // 部分权限
)
var DefaultMenus []*SysMenu = []*SysMenu{
NewMenu(10, "工作台", "SYSTEM_WORKBENCH", 0, 1),
//NewMenu(10, "工作台", "SYSTEM_WORKBENCH", 0, 1),
//NewMenu(40, "通知公告", "SYSTEM_NOTICE", 0, 1),
//NewMenu(60, "系统日志", "SYSTEM_LOG", 0, 1),
NewMenu(20, "组织架构", "SYSTEM_ORGANIZATION", 0, 2),
NewMenu(21, "成员", "SYSTEM_ORGANIZATION_EMPLOYEE", 20, 1),
NewMenu(22, "部门", "SYSTEM_ORGANIZATION_DEPARTMENT", 20, 2),
NewMenu(22, "用户组", "SYSTEM_ORGANIZATION_GROUP", 20, 3),
NewMenu(21, "成员与部门", "SYSTEM_ORGANIZATION_EMPLOYEE-DEPARTMENT", 20, 1),
//NewMenu(22, "部门", "SYSTEM_ORGANIZATION_DEPARTMENT", 20, 2),
//NewMenu(22, "用户组", "SYSTEM_ORGANIZATION_GROUP", 20, 3),
NewMenu(30, "应用管理", "SYSTEM_APP-MANAGER", 0, 3),
NewMenu(31, "应用中心", "SYSTEM_APP-MANAGER_APP", 30, 1),
NewMenu(31, "应用中心", "SYSTEM_APP-MANAGER_APP-CENTER", 30, 1),
NewMenu(32, "应用配置", "SYSTEM_APP-MANAGER_APP-CENTER_SET", 30, 1).WithMenuTypeButton(),
NewMenu(50, "企业设置", "SYSTEM_COMPANY-SETTING", 0, 5),
NewMenu(50, "企业设置", "SYSTEM_COMPANY-SETTING", 0, 4),
NewMenu(51, "企业信息", "SYSTEM_COMPANY-SETTING_INFO", 50, 1),
NewMenu(52, "管理员权限", "SYSTEM_COMPANY-SETTING_ADMIN-AUTH", 50, 2),
}
func FineOneMenu(ctx context.Context, conn transaction.Conn, menuId int64) (*SysMenu, error) {
for _, menu := range DefaultMenus {
if menu.Id == menuId {
return menu, nil
}
}
return nil, ErrNotFound
}
func NewMenu(id int64, name, code string, pid int64, sort int64) *SysMenu {
return &SysMenu{
Id: id,
... ... @@ -83,5 +99,11 @@ func NewMenu(id int64, name, code string, pid int64, sort int64) *SysMenu {
Code: code,
ParentId: pid,
Sort: sort,
MenuType: "menu",
}
}
func (m *SysMenu) WithMenuTypeButton() *SysMenu {
m.MenuType = "button"
return m
}
... ...
... ... @@ -31,6 +31,7 @@ type SysUserRepository interface {
FindOneByPhone(ctx context.Context, conn transaction.Conn, phone string) (*SysUser, error)
FindOneUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*SysUser, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*SysUser, error)
//FindByCompany(ctx context.Context, conn transaction.Conn, companyId int64,queryOptions map[string]interface{}) (int64, []*SysUser, error)
}
func NewDomainSysUser(phone string, name string, password string) *SysUser {
... ...