Merge branch 'master' of http://101.43.70.124:3000/williamet/cas_tt_cloud_backend
This commit is contained in:
@ -86,7 +86,7 @@ func (a *Tenant) MemberBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
TenantID string `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
Password string `json:"password" form:"password"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
|
@ -76,6 +76,19 @@ func (a *User) Menu(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) Basic(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
TenantID string `json:"tenant_id" form:"tenant_id"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Basic(form.Mobile, (&api.IDStringForm{ID: form.TenantID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) Add(c *gin.Context) {
|
||||
form := &struct {
|
||||
userForm
|
||||
|
@ -20,6 +20,12 @@ type Account struct {
|
||||
type AccountHandle func(session *session.Admin, tenantID uint64) *Account
|
||||
|
||||
type (
|
||||
// loginHandleReturn 登陆操作返回信息
|
||||
loginHandleReturn struct {
|
||||
*model.SysUser
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
TenantIdentity model2.SysUserTenantIdentity
|
||||
}
|
||||
// AccountLoginParams 登陆参数
|
||||
AccountLoginParams struct {
|
||||
Account, Password, Captcha string
|
||||
@ -32,12 +38,12 @@ type (
|
||||
)
|
||||
|
||||
// loginHandle 登陆操作,1:账户密码登陆,2:短信验证登陆
|
||||
var loginHandle = map[int]func(params *AccountLoginParams, tenantID uint64) (*model.SysUser, error){
|
||||
var loginHandle = map[int]func(params *AccountLoginParams, tenantID uint64) (*loginHandleReturn, error){
|
||||
1: loginForPassword, 2: loginForSmsCaptcha,
|
||||
}
|
||||
|
||||
// loginForPassword 密码登陆
|
||||
func loginForPassword(params *AccountLoginParams, tenantID uint64) (*model.SysUser, error) {
|
||||
func loginForPassword(params *AccountLoginParams, tenantID uint64) (*loginHandleReturn, error) {
|
||||
if params.Password == "" {
|
||||
return nil, errors.New("操作错误,密码不可为空")
|
||||
}
|
||||
@ -53,11 +59,28 @@ func loginForPassword(params *AccountLoginParams, tenantID uint64) (*model.SysUs
|
||||
if !mSysUser.ValidatePassword(params.Password) {
|
||||
return nil, errors.New("操作错误,用户名或密码错误")
|
||||
}
|
||||
return mSysUser, nil
|
||||
out := &loginHandleReturn{SysUser: mSysUser, TenantIdentity: 0}
|
||||
|
||||
if !mSysUser.IsAdminUser() {
|
||||
// 查询用户租户信息
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
|
||||
if isExist, err = model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"},
|
||||
model2.NewWhere("uid", mSysUser.UUID),
|
||||
model2.NewWhere("tenant_id", tenantID)); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,无权限登陆此后台,请联系管理员")
|
||||
}
|
||||
|
||||
out.TenantID = tenantID
|
||||
out.TenantIdentity = mSysUserTenant.Identity
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// loginForSmsCaptcha 短信验证码登陆
|
||||
func loginForSmsCaptcha(params *AccountLoginParams, tenantID uint64) (*model.SysUser, error) {
|
||||
func loginForSmsCaptcha(params *AccountLoginParams, tenantID uint64) (*loginHandleReturn, error) {
|
||||
if params.Captcha == "" {
|
||||
return nil, errors.New("操作错误,验证码不可为空")
|
||||
}
|
||||
@ -68,15 +91,31 @@ func loginForSmsCaptcha(params *AccountLoginParams, tenantID uint64) (*model.Sys
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{
|
||||
"id", "uuid", "tenant_id", "name", "mobile", "is_admin", "status",
|
||||
}, model2.NewWhere("tenant_id", tenantID), model2.NewWhere("mobile", params.Account))
|
||||
"id", "uuid", "name", "mobile", "is_admin", "status",
|
||||
}, model2.NewWhere("mobile", params.Account))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,当前帐号信息不存在或已被删除")
|
||||
}
|
||||
return mSysUser, nil
|
||||
out := &loginHandleReturn{SysUser: mSysUser, TenantIdentity: 0}
|
||||
|
||||
if !mSysUser.IsAdminUser() {
|
||||
// 查询用户租户信息
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
|
||||
if isExist, err = model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"},
|
||||
model2.NewWhere("uid", mSysUser.UUID),
|
||||
model2.NewWhere("tenant_id", tenantID)); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,无权限登陆此后台,请联系管理员")
|
||||
}
|
||||
out.TenantID = tenantID
|
||||
out.TenantIdentity = mSysUserTenant.Identity
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Login 登录请求
|
||||
@ -99,6 +138,7 @@ func (c *Account) Login(mode int, params *AccountLoginParams, equipment, ip stri
|
||||
_session.Name = data.Name
|
||||
_session.Mobile = data.Mobile
|
||||
_session.IsAdmin = data.IsAdminUser()
|
||||
_session.IsSystemAdmin = data.TenantIdentity == model2.SysUserTenantIdentityForSystemAdmin
|
||||
|
||||
_uid := data.UUIDString()
|
||||
|
||||
|
@ -4,7 +4,9 @@ import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Member 人员信息
|
||||
@ -18,9 +20,7 @@ type (
|
||||
// MemberInfo 人员信息
|
||||
MemberInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Account string `json:"account"`
|
||||
Mobile string `json:"mobile"`
|
||||
*model.SysUserTenantBasic
|
||||
}
|
||||
// MemberParams 人员参数信息
|
||||
MemberParams struct {
|
||||
@ -30,50 +30,74 @@ type (
|
||||
|
||||
// Instance 人员信息
|
||||
func (c *Member) Instance(tenantID uint64) (*MemberInfo, error) {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "name", "account", "mobile"},
|
||||
model2.NewWhere("tenant_id", tenantID),
|
||||
model2.NewWhere("is_admin", model2.SysUserAdministratorForAdmin))
|
||||
out, err := mSysUserTenant.User(model2.NewWhere("u_t.tenant_id", tenantID),
|
||||
model2.NewWhere("u_t.identity", model2.SysUserTenantIdentityForSystemUser))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := new(MemberInfo)
|
||||
res := new(MemberInfo)
|
||||
|
||||
if !isExist {
|
||||
if out == nil && out.ID <= 0 {
|
||||
goto RETURNS
|
||||
}
|
||||
out.ID = mSysUser.GetEncodeID()
|
||||
out.Name = mSysUser.Name
|
||||
out.Account = mSysUser.Account
|
||||
out.Mobile = mSysUser.Mobile
|
||||
res.ID = out.GetEncodeID()
|
||||
res.SysUserTenantBasic = out
|
||||
RETURNS:
|
||||
return out, nil
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Member) Form(tenantID uint64, params *MemberParams) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "name", "account", "mobile"},
|
||||
model2.NewWhere("tenant_id", tenantID),
|
||||
model2.NewWhere("is_admin", model2.SysUserAdministratorForAdmin))
|
||||
var count int64
|
||||
|
||||
err := model2.Count(mSysUserTenant.SysUserTenant, &count, model2.NewWhere("tenant_id", tenantID),
|
||||
model2.NewWhere("identity", model2.SysUserTenantIdentityForSystemAdmin))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,当前平台已存在管理员")
|
||||
}
|
||||
mSysUser.TenantID = tenantID
|
||||
// 用户信息
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
// 查询手机号码是否存在
|
||||
isExist := false
|
||||
|
||||
if isExist, err = model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "name", "account", "mobile"},
|
||||
model2.NewWhere("mobile", params.Mobile)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if isExist {
|
||||
mSysUserTenant.TenantID = tenantID
|
||||
mSysUserTenant.UID = mSysUser.UUID
|
||||
mSysUserTenant.Identity = model2.SysUserTenantIdentityForSystemUser
|
||||
return model2.Create(mSysUserTenant.SysUserTenant)
|
||||
}
|
||||
if params.Password == "" {
|
||||
return errors.New("操作错误,密码不能为空")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysUser.Account = params.Mobile
|
||||
mSysUser.Name = params.Mobile
|
||||
mSysUser.Mobile = params.Mobile
|
||||
mSysUser.Password = params.Password
|
||||
mSysUser.IsAdmin = model2.SysUserAdministratorForAdmin
|
||||
mSysUser.Remark = "子平台管理员"
|
||||
|
||||
return model2.Create(mSysUser.SysUser)
|
||||
if err = model2.Create(mSysUser.SysUser, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUserTenant.TenantID = tenantID
|
||||
mSysUserTenant.UID = mSysUser.UUID
|
||||
mSysUserTenant.Identity = model2.SysUserTenantIdentityForSystemUser
|
||||
return model2.Create(mSysUserTenant.SysUserTenant, tx)
|
||||
})
|
||||
}
|
||||
|
||||
func NewMember() MemberHandle {
|
||||
|
@ -66,7 +66,7 @@ type InstanceForm struct {
|
||||
RoleIDs []uint64
|
||||
}
|
||||
|
||||
func (c *InstanceForm) sync(tx *gorm.DB, first bool, uid, tenantID uint64) error {
|
||||
func (c *InstanceForm) sync(tx *gorm.DB, first bool, userTenantID, tenantID uint64) error {
|
||||
var err error
|
||||
|
||||
mSysUserDepartment := model.NewSysUserDepartment()
|
||||
@ -74,26 +74,26 @@ func (c *InstanceForm) sync(tx *gorm.DB, first bool, uid, tenantID uint64) error
|
||||
|
||||
permission := service.NewPermission(
|
||||
service.WithAuthTenant(fmt.Sprintf("%d", tenantID)),
|
||||
service.WithAuthUser(fmt.Sprintf("%d", uid)),
|
||||
service.WithAuthUser(fmt.Sprintf("%d", userTenantID)),
|
||||
)
|
||||
if !first {
|
||||
if err = model2.DeleteWhere(mSysUserDepartment.SysUserDepartment, []*model2.ModelWhere{
|
||||
model2.NewWhere("uid", uid)}, tx); err != nil {
|
||||
model2.NewWhere("user_tenant_id", userTenantID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = model2.DeleteWhere(mSysUserRole.SysUserRole, []*model2.ModelWhere{
|
||||
model2.NewWhere("uid", uid)}, tx); err != nil {
|
||||
model2.NewWhere("user_tenant_id", userTenantID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
go utils.TryCatch(func() {
|
||||
if _, err = permission.DeleteRolesForUser(false); err != nil {
|
||||
logger.ErrorF("Casbin 删除用户【%d】权限错误:%v", uid, err)
|
||||
logger.ErrorF("Casbin 删除用户【%d】权限错误:%v", userTenantID, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
if c.DepartmentID > 0 {
|
||||
mSysUserDepartment.UID = uid
|
||||
mSysUserDepartment.UserTenantID = userTenantID
|
||||
mSysUserDepartment.DepartmentID = c.DepartmentID
|
||||
|
||||
if err = model2.Create(mSysUserDepartment.SysUserDepartment, tx); err != nil {
|
||||
@ -107,7 +107,7 @@ func (c *InstanceForm) sync(tx *gorm.DB, first bool, uid, tenantID uint64) error
|
||||
|
||||
for _, v := range c.RoleIDs {
|
||||
roles = append(roles, &model2.SysUserRole{
|
||||
UID: uid,
|
||||
UserTenantID: userTenantID,
|
||||
RoleID: v,
|
||||
})
|
||||
rolesIDs = append(rolesIDs, fmt.Sprintf("%d", v))
|
||||
@ -119,7 +119,7 @@ func (c *InstanceForm) sync(tx *gorm.DB, first bool, uid, tenantID uint64) error
|
||||
service.WithAuthRoles(rolesIDs)(permission)
|
||||
|
||||
if _, err = permission.AddRoleForUser(); err != nil {
|
||||
logger.ErrorF("Casbin 给予用户【%d】权限错误:%v", uid, err)
|
||||
logger.ErrorF("Casbin 给予用户【%d】权限错误:%v", userTenantID, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -143,7 +143,7 @@ func (c *Instance) Info() (*InstanceUserInfo, error) {
|
||||
|
||||
// Index 列表信息
|
||||
func (c *Instance) Index(name, mobile string, departmentIDs []uint64, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
where := []*model2.ModelWhere{model2.NewWhere("u.tenant_id", c.TenantID)}
|
||||
where := []*model2.ModelWhere{model2.NewWhere("u_t.tenant_id", c.TenantID)}
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("u.name", name))
|
||||
@ -157,11 +157,11 @@ func (c *Instance) Index(name, mobile string, departmentIDs []uint64, status, pa
|
||||
if status > 0 {
|
||||
where = append(where, model2.NewWhere("u.status", status))
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
var count int64
|
||||
|
||||
out, err := mSysUser.Users(page, pageSize, &count, where...)
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
|
||||
out, err := mSysUserTenant.Users(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -176,7 +176,6 @@ func (c *Instance) Index(name, mobile string, departmentIDs []uint64, status, pa
|
||||
UID: v.UUIDString(), Avatar: v.Avatar, Name: v.Name, Email: v.Email, Mobile: v.Mobile,
|
||||
},
|
||||
Account: v.Account, Gender: v.Gender.Gender, IsAdmin: v.IsAdmin, Status: v.Status, CreatedAt: v.CreatedAt,
|
||||
//Role: make([]*InstanceRoleInfo, 0),
|
||||
RoleIDs: make([]string, 0),
|
||||
Remark: v.Remark,
|
||||
}
|
||||
@ -195,10 +194,6 @@ func (c *Instance) Index(name, mobile string, departmentIDs []uint64, status, pa
|
||||
obj.ID = utils.StringToUnit64(v)
|
||||
roleIDs = append(roleIDs, obj.GetEncodeID())
|
||||
}
|
||||
//roles := &InstanceRoleInfo{
|
||||
// IDs: roleIDs,
|
||||
//Names: strings.Split(v.RoleNames, "&&"),
|
||||
//}
|
||||
data.RoleIDs = roleIDs
|
||||
}
|
||||
list = append(list, data)
|
||||
@ -206,25 +201,49 @@ func (c *Instance) Index(name, mobile string, departmentIDs []uint64, status, pa
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Basic 基本信息
|
||||
func (c *Instance) Basic(mobile string, tenantID uint64) (*model2.SysUser, error) {
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
_, err := mSysUser.GetByAccountOrMobile(mobile, tenantID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mSysUser.ID <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return mSysUser.SysUser, nil
|
||||
}
|
||||
|
||||
// Add 添加用户
|
||||
func (c *Instance) Add(params *InstanceForm) error {
|
||||
if !utils.ValidateMobile(params.Mobile) {
|
||||
return errors.New("操作错误,手机号码格式错误")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
// 查询登录账户或手机号码是否注册
|
||||
var count int64
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
|
||||
err := model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile),
|
||||
model2.NewWhere("tenant_id", c.TenantID))
|
||||
// 查询登录账户或手机号码是否注册
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "name"}, model2.NewWhere("mobile", params.Mobile))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
// 判断当前人员是否已经注册了租户身份
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mSysUserTenant.SysUserTenant, &count, model2.NewWhere("uid", mSysUser.UUID)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,当前手机号码已注册")
|
||||
}
|
||||
mSysUserTenant.TenantID = c.TenantID
|
||||
mSysUserTenant.UID = mSysUser.UUID
|
||||
|
||||
return model2.Create(mSysUserTenant.SysUserTenant)
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysUser.TenantID = c.TenantID
|
||||
mSysUser.Account = params.Account
|
||||
mSysUser.Name = params.Name
|
||||
mSysUser.Mobile = params.Mobile
|
||||
@ -237,8 +256,13 @@ func (c *Instance) Add(params *InstanceForm) error {
|
||||
if err = model2.Create(mSysUser.SysUser, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUserTenant.TenantID = c.TenantID
|
||||
mSysUserTenant.UID = mSysUser.UUID
|
||||
|
||||
if err = params.sync(tx, true, mSysUser.UUID, c.TenantID); err != nil {
|
||||
if err = model2.Create(mSysUserTenant.SysUserTenant, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = params.sync(tx, true, mSysUserTenant.ID, c.TenantID); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -247,26 +271,30 @@ func (c *Instance) Add(params *InstanceForm) error {
|
||||
|
||||
// Edit 修改用户信息
|
||||
func (c *Instance) Edit(params *InstanceForm) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = params.ID
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
mSysUserTenant.ID = params.ID
|
||||
|
||||
isExist, err := model2.First(mSysUser.SysUser)
|
||||
isExist, err := model2.First(mSysUserTenant.SysUserTenant)
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
|
||||
} else if c.TenantID > 0 && mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
if _, err = model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", mSysUserTenant.UID)); err != nil {
|
||||
return err
|
||||
}
|
||||
if mSysUser.Mobile != params.Mobile {
|
||||
if !utils.ValidateMobile(params.Mobile) {
|
||||
return errors.New("操作错误,手机号码格式错误")
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile),
|
||||
model2.NewWhere("tenant_id", c.TenantID)); err != nil {
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil {
|
||||
return nil
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,当前手机号码已注册")
|
||||
@ -282,7 +310,7 @@ func (c *Instance) Edit(params *InstanceForm) error {
|
||||
if err = model2.Updates(mSysUser.SysUser, mSysUser.SysUser, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = params.sync(tx, false, mSysUser.UUID, mSysUser.TenantID); err != nil {
|
||||
if err = params.sync(tx, false, mSysUserTenant.ID, c.TenantID); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -290,21 +318,23 @@ func (c *Instance) Edit(params *InstanceForm) error {
|
||||
}
|
||||
|
||||
func (c *Instance) Password(id uint64, password, repeatPwd string) error {
|
||||
//if password != repeatPwd {
|
||||
// return errors.New("操作错误,两次密码输入不一致")
|
||||
//}
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
mSysUserTenant.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"})
|
||||
isExist, err := model2.First(mSysUserTenant.SysUserTenant)
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
|
||||
} else if c.TenantID > 0 && mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
if _, err = model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"}, model2.NewWhere("uuid", mSysUserTenant.UID)); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUser.Password = password
|
||||
mSysUser.Pass()
|
||||
|
||||
@ -337,21 +367,33 @@ func (c *Person) PasswordEdit(oldPassword, password, repeatPwd string) error {
|
||||
}
|
||||
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
mSysUserTenant := model.NewSysUserTenant()
|
||||
mSysUserTenant.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"})
|
||||
isExist, err := model2.First(mSysUserTenant.SysUserTenant)
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
|
||||
} else if c.TenantID > 0 && mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
} else if mSysUser.IsAdminUser() {
|
||||
return errors.New("操作错误,超管用户不允许删除")
|
||||
}
|
||||
if err = model2.Delete(mSysUser.SysUser); err != nil {
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
if _, err = model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"}, model2.NewWhere("uuid", mSysUserTenant.UID)); err != nil {
|
||||
return err
|
||||
}
|
||||
err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
//if err = model2.Delete(mSysUser.SysUser, tx); err != nil {
|
||||
// return err
|
||||
//}
|
||||
if err = model2.Delete(mSysUserTenant.SysUserTenant, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccountAdmin, utils.UintToString(mSysUser.UUID))
|
||||
|
@ -19,13 +19,12 @@ func (c *Menu) Index() ([]*menu.Tree, error) {
|
||||
model2.SysMenuKindForCatalogue,
|
||||
model2.SysMenuKindForMenu,
|
||||
}
|
||||
|
||||
if c.IsAdmin {
|
||||
if c.TenantID > 0 {
|
||||
return menu.MenuForTenant(mSysMenu, c.TenantID, model2.NewWhereIn("m.kind", kinds))
|
||||
}
|
||||
return menu.MenuForSystem(mSysMenu, model2.NewWhereIn("kind", kinds))
|
||||
}
|
||||
if c.IsSystemAdmin {
|
||||
return menu.MenuForTenant(mSysMenu, c.TenantID, model2.NewWhereIn("m.kind", kinds))
|
||||
}
|
||||
return menu.MenuForUser(mSysMenu, c.TenantID, c.UID, model2.NewWhereIn("m.kind", kinds))
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,8 @@ func (m *SysUser) IsAdminUser() bool {
|
||||
|
||||
func (m *SysUser) GetByAccountOrMobile(account string, tenantID uint64) (bool, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "uuid", "tenant_id", "name", "mobile", "password", "salt", "is_admin", "status").
|
||||
Where("tenant_id = ?", tenantID).
|
||||
Select("id", "uuid", "name", "mobile", "password", "salt", "is_admin", "status").
|
||||
//Where("tenant_id = ?", tenantID).
|
||||
//Where("(email = ? OR mobile = ?)", account, account).
|
||||
Where("mobile = ?", account).
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
85
app/api/admin/model/sys_user_tenant.go
Normal file
85
app/api/admin/model/sys_user_tenant.go
Normal file
@ -0,0 +1,85 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysUserTenant struct {
|
||||
*model.SysUserTenant
|
||||
}
|
||||
|
||||
type (
|
||||
// SysUserTenantBasic 基本信息
|
||||
SysUserTenantBasic struct {
|
||||
model.Model
|
||||
Account string `json:"account"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
// SysUserTenantInfo 详细信息
|
||||
SysUserTenantInfo struct {
|
||||
*model.SysUser
|
||||
model.Model
|
||||
DepartmentID uint64 `json:"-"`
|
||||
DepartmentName string `json:"-"`
|
||||
RoleIDs string `json:"-"`
|
||||
RoleNames string `json:"-"`
|
||||
}
|
||||
)
|
||||
|
||||
// User 用户信息
|
||||
func (m *SysUserTenant) User(where ...*model.ModelWhere) (*SysUserTenantBasic, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u_t").
|
||||
Select("u_t.id", "u.account", "u.name", "u.mobile").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON u_t.uid = u.uuid", model.NewSysUser().TableName())).
|
||||
Where("u_t.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := new(SysUserTenantBasic)
|
||||
|
||||
err := db.Scan(out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Users 用户信息
|
||||
func (m *SysUserTenant) Users(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserTenantInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u_t").
|
||||
Select("u_t.id", "u.uuid", "u.account", "u.avatar", "u.name", "u.mobile", "u.gender",
|
||||
"u.is_admin", "u.status", "u.created_at", "d.id AS department_id", "d.name AS department_name",
|
||||
"u_r.role_ids", "u_r.role_names").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON u_t.uid = u.uuid", model.NewSysUser().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u_d ON u_t.id = u_d.user_tenant_id AND u_d.is_deleted = %d",
|
||||
model.NewSysUserDepartment().TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS d ON u_d.department_id = d.id",
|
||||
model.NewSysDepartment().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT user_tenant_id, GROUP_CONCAT(r.id SEPARATOR '&&') AS role_ids, GROUP_CONCAT(r.name SEPARATOR '&&') AS role_names "+
|
||||
"FROM %s AS u LEFT JOIN %s AS r ON u.role_id = r.id WHERE u.is_deleted = %d GROUP BY u.user_tenant_id) u_r ON u_t.id = u_r.user_tenant_id",
|
||||
model.NewSysUserRole().TableName(), model.NewSysRole().TableName(), model.DeleteStatusForNot)).
|
||||
Where("u_t.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysUserTenantInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("u_t.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysUserTenant() *SysUserTenant {
|
||||
return &SysUserTenant{model.NewSysUserTenant()}
|
||||
}
|
@ -43,7 +43,7 @@ type (
|
||||
}
|
||||
// patentForm 专利参数
|
||||
patentForm struct {
|
||||
Kind int `json:"kind" form:"kind" binding:"kind"`
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
FileUrl string `json:"file_url" form:"file_url"`
|
||||
ApplyCode string `json:"apply_code" form:"apply_code" binding:"required"`
|
||||
@ -56,7 +56,7 @@ type (
|
||||
Inventor string `json:"inventor" form:"inventor"`
|
||||
PrincipalClaim string `json:"principal_claim" form:"principal_claim"`
|
||||
Description string `json:"description" form:"description"`
|
||||
Status int `json:"status" form:"status" binding:"status"`
|
||||
Status int `json:"status" form:"status"`
|
||||
}
|
||||
// demandForm 需求参数
|
||||
demandForm struct {
|
||||
|
@ -22,6 +22,7 @@ type (
|
||||
PaperInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.TechnologyPaper
|
||||
Keywords []string `json:"keywords"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
PaperParams struct {
|
||||
@ -53,7 +54,8 @@ func (c *Paper) List(title string, page, pageSize int) (*controller.ReturnPages,
|
||||
list := make([]*PaperInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &PaperInfo{ID: v.GetEncodeID(), TechnologyPaper: v, Tags: v.GetTagAttribute()})
|
||||
list = append(list, &PaperInfo{ID: v.GetEncodeID(), TechnologyPaper: v, Keywords: v.GetKeywordAttribute(),
|
||||
Tags: v.GetTagAttribute()})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
@ -65,6 +65,15 @@ func (c *PatentParams) add(tenantID, uid uint64) error {
|
||||
return errors.New("操作错误,申请号或公开(公告)号已存在")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// 查询当前的专家信息
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
if isExist, err = model2.LastWhere(mUserExpert.UserExpert, []string{"id", "expert_id"}, model2.NewWhere("uid", uid),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,无专家信息")
|
||||
}
|
||||
mTechnologyPatent.Kind = model2.TechnologyPatentKind(c.Kind)
|
||||
mTechnologyPatent.Title = c.Title
|
||||
mTechnologyPatent.FileUrl = c.FileUrl
|
||||
@ -83,15 +92,6 @@ func (c *PatentParams) add(tenantID, uid uint64) error {
|
||||
if err = model2.Create(mTechnologyPatent.TechnologyPatent, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 查询当前的专家信息
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
if isExist, err = model2.LastWhere(mUserExpert.UserExpert, []string{"id", "expert_id"}, model2.NewWhere("uid", uid),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,无专家信息")
|
||||
}
|
||||
mTechnologyPatentExpert := model.NewTechnologyPatentExpert()
|
||||
mTechnologyPatentExpert.ExpertID = mUserExpert.ExpertID
|
||||
mTechnologyPatentExpert.PatentID = mTechnologyPatent.ID
|
||||
@ -215,7 +215,7 @@ func (c *Patent) List(kind int, title, applyCode, openCode, ipcCode string, page
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhereFindInSet("p.inventor", expert.Name)}
|
||||
|
||||
if kind <= 0 {
|
||||
if kind > 0 {
|
||||
where = append(where, model2.NewWhere("p.kind", kind))
|
||||
}
|
||||
if title != "" {
|
||||
|
@ -52,7 +52,7 @@ func (m *TechnologyPatent) IsExistParams(params map[string]interface{}) (bool, e
|
||||
|
||||
if len(params) > 0 {
|
||||
for k, v := range params {
|
||||
db = db.Or(fmt.Sprintf("%s = %v AND is_deleted = %d", k, v, model.DeleteStatusForNot))
|
||||
db = db.Or(fmt.Sprintf("'%s' = '%v' AND is_deleted = %d", k, v, model.DeleteStatusForNot))
|
||||
}
|
||||
}
|
||||
err := db.Count(&count).Error
|
||||
|
@ -18,14 +18,15 @@ type TechnologyPatentExpertInfo struct {
|
||||
ApplyCode string `json:"apply_code"`
|
||||
ApplyName string `json:"apply_name"`
|
||||
ApplyAt string `json:"apply_at"`
|
||||
Inventor string `json:"inventor"`
|
||||
Status model.TechnologyPatentStatus `json:"status"`
|
||||
CreatedAt time.Time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// Patent 专利信息
|
||||
func (m *TechnologyPatentExpert) Patent(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyPatentExpertInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u").
|
||||
Select("p.id", "p.title", "p.apply_code", "p.apply_name", "p.apply_at", "p.status", "p.created_at").
|
||||
Select("p.id", "p.title", "p.apply_code", "p.apply_name", "p.apply_at", "p.inventor", "p.status", "p.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS p ON u.patent_id = p.id", model.NewTechnologyPatent().TableName())).
|
||||
Where("u.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
|
1
app/api/enterprise/model/user_patent.go
Normal file
1
app/api/enterprise/model/user_patent.go
Normal file
@ -0,0 +1 @@
|
||||
package model
|
@ -13,7 +13,7 @@ type Config struct{}
|
||||
func (*Config) Index(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
Key string `json:"key" form:"key" binding:"required"`
|
||||
Key []string `json:"key" form:"key" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
|
@ -3,7 +3,7 @@ package model
|
||||
// SysUserDepartment 用户部门信息数据模型
|
||||
type SysUserDepartment struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
UserTenantID uint64 `gorm:"column:user_tenant_id;type:int;default:0;comment:用户租户ID" json:"-"`
|
||||
DepartmentID uint64 `gorm:"column:department_id;type:int;default:0;comment:部门ID" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
|
@ -2,7 +2,7 @@ package model
|
||||
|
||||
type SysUserRole struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
UserTenantID uint64 `gorm:"column:user_tenant_id;type:int;default:0;comment:用户租户ID" json:"-"`
|
||||
RoleID uint64 `gorm:"column:role_id;type:int;default:0;comment:角色ID" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
|
@ -1,16 +1,16 @@
|
||||
package model
|
||||
|
||||
// SysUserTenant 用户租户信息
|
||||
type SysUserTenant struct {
|
||||
Model
|
||||
ModelTenant
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
Department string `gorm:"column:department;type:varchar(100);default:'';comment:部门信息" json:"department"`
|
||||
Role string `gorm:"column:role;type:varchar(100);default:'';comment:角色信息" json:"role"`
|
||||
Identity SysUserTenantIdentity `gorm:"column:identity;type:tinyint(1);default:0;comment:用户身份(1:管理员,2:用户)" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
// SysUserTenantIdentity 用户租户身份信息
|
||||
type SysUserTenantIdentity int
|
||||
|
||||
const (
|
||||
|
@ -13,6 +13,7 @@ type Admin struct {
|
||||
Name string `json:"name"` // 名称
|
||||
Mobile string `json:"mobile"` // 手机号码
|
||||
IsAdmin bool `json:"is_admin"` // 是否超管
|
||||
IsSystemAdmin bool `json:"is_system_admin"` // 是否系统管理员
|
||||
}
|
||||
|
||||
func (this *Admin) SetToken(token string) {
|
||||
|
0
build_linux.sh
Normal file → Executable file
0
build_linux.sh
Normal file → Executable file
@ -230,6 +230,7 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
user := v1.Group("/user")
|
||||
{
|
||||
_api := new(api1.User)
|
||||
user.POST("/basic", _api.Basic)
|
||||
user.GET("/info", _api.Info)
|
||||
user.GET("/menu", _api.Menu)
|
||||
user.POST("/list", _api.List)
|
||||
@ -517,7 +518,7 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
||||
settledV1.POST("/agent", _api.Agent)
|
||||
}
|
||||
// Technology 技术管理
|
||||
technologyV1 := g.Group("/technology")
|
||||
technologyV1 := v1.Group("/technology")
|
||||
{
|
||||
_api := new(api3.Technology)
|
||||
technologyV1.POST("/paper", _api.Paper)
|
||||
|
@ -61,7 +61,7 @@ func NeedPermission(skipperURL ...SkipperURL) gin.HandlerFunc {
|
||||
value, _ := c.Get(config.TokenForSession)
|
||||
_session := value.(*session.Admin)
|
||||
|
||||
if _session.IsAdmin && _session.TenantID <= 0 {
|
||||
if _session.IsAdmin || _session.IsSystemAdmin {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@ -19,13 +20,14 @@ func TestArrayFlip(t *testing.T) {
|
||||
//d := a & b & c
|
||||
//t.Log(d)
|
||||
|
||||
a := make([]int, 5)
|
||||
t.Log(a)
|
||||
t.Log(a[4])
|
||||
a = append(a, []int{1, 2, 3, 4, 5, 6, 7, 8, 9}...)
|
||||
t.Log(a)
|
||||
t.Log(len(a))
|
||||
t.Log(cap(a))
|
||||
//a := make([]int, 5)
|
||||
//t.Log(a)
|
||||
//t.Log(a[4])
|
||||
//a = append(a, []int{1, 2, 3, 4, 5, 6, 7, 8, 9}...)
|
||||
//t.Log(a)
|
||||
//t.Log(len(a))
|
||||
//t.Log(cap(a))
|
||||
t.Log(math.Sqrt(4))
|
||||
}
|
||||
|
||||
func TestArrayStrings(t *testing.T) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
@ -107,3 +108,19 @@ func TestCode(t *testing.T) {
|
||||
t.Log(lengthOfLongestSubstring("dvdf"))
|
||||
|
||||
}
|
||||
|
||||
type ABC struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
func publish(src []*ABC) {
|
||||
src[1].Key = "测试"
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
src := []*ABC{&ABC{}, &ABC{}}
|
||||
publish(src)
|
||||
|
||||
_bytes, _ := json.Marshal(src)
|
||||
t.Log(string(_bytes))
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v2"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
@ -36,3 +37,23 @@ func TestNewFile(t *testing.T) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewOpenFile(t *testing.T) {
|
||||
file, err := os.Open("BizChat(1).db-shm")
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
_bytes := make([]byte, 0)
|
||||
|
||||
if _bytes, err = io.ReadAll(file); err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
t.Log(_bytes)
|
||||
|
||||
t.Log(string(_bytes[0:2]))
|
||||
}
|
||||
|
1
utils/handler.go
Normal file
1
utils/handler.go
Normal file
@ -0,0 +1 @@
|
||||
package utils
|
Reference in New Issue
Block a user