作者 唐旭辉

用户管理: 增加高管身份切换按钮

package command
import (
"errors"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type EditUserPermissionCommand struct {
Id int64 `json:"id"`
CompanyId int64 `json:"-"`
PermissionType []int64 `json:"permissionType"` //权限数据
CheckedPartner []int64 `json:"checkedPartner"` //可查看合伙人列表合伙人
IsSenior int8 `json:"isSenior"`
}
func (cmd EditUserPermissionCommand) Validate() error {
if cmd.IsSenior <= 0 {
return errors.New("是否是高管必填")
}
if !(cmd.IsSenior == domain.UserIsSeniorNo || cmd.IsSenior == domain.UserIsSeniorYes) {
return errors.New("是否是高管必填")
}
return nil
}
... ...
... ... @@ -383,6 +383,7 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList
"isAdmin": 0,
"status": 0,
"checkedPartner": []map[string]interface{}{},
"isSenior": userData.IsSenior,
}
if userData.IsSuperAdmin() {
result["isAdmin"] = 1
... ... @@ -433,6 +434,9 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = cmd.Validate(); err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
... ... @@ -501,9 +505,6 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
partners = append(partners, p)
}
for i := range permissionList {
// if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER && !usersData.IsSuperAdmin() {
// return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常")
// }
p := domain.AdminPermissionBase{
Id: permissionList[i].Id,
Code: permissionList[i].Code,
... ... @@ -512,6 +513,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
}
updateMap := map[string]interface{}{
"AccessPartners": partners,
"IsSenior": cmd.IsSenior,
}
if !usersData.IsSuperAdmin() {
updateMap["Permission"] = permissionsBase
... ...
... ... @@ -20,29 +20,36 @@ const (
UserIsAdmin int8 = 2
)
//Users.IsSenior 用户是否是公司高管【1:是】【2:否】
const (
UserIsSeniorYes int8 = 1
UserIsSeniorNo int8 = 2
)
//Users 企业平台的用户
type Users struct {
Id int64 //用户id
CompanyId int64 //公司id
OpenId int64 //统一用户中心
Name string //用户名称
Sex int8 //性别:【0:未知】【1:男】【2:女】
JobNum string //工号
Phone string //手机号,同账号
PrivatePhone string //私人手机号
Email string //邮件
ExtensionNum string //分机号
EntryTime time.Time //入职时间
Workspace string //工作地
Status int8 //状态:【1:正常】【 2:禁用】
Avatar string ///头像
Remarks string //备注
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
CreateAt time.Time
UpdateAt time.Time
Id int64 //用户id
CompanyId int64 //公司id
OpenId int64 //统一用户中心
Name string //用户名称
Sex int8 //性别:【0:未知】【1:男】【2:女】
JobNum string //工号
Phone string //手机号,同账号
PrivatePhone string //私人手机号
Email string //邮件
ExtensionNum string //分机号
EntryTime time.Time //入职时间
Workspace string //工作地
Status int8 //状态:【1:正常】【 2:禁用】
Avatar string ///头像
Remarks string //备注
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
CreateAt time.Time //
UpdateAt time.Time //
Permission []AdminPermissionBase //权限
AccessPartners []Partner
AdminType int8 //是否是公司负责人,即超级管理员 1普通用户 2主管理员
AccessPartners []Partner //
AdminType int8 //是否是公司负责人,即超级管理员 1普通用户 2主管理员
IsSenior int8 //是否是公司高管【1:是】【2:否】;用于确定是否可以拥有“可查看的合伙人”
}
//IsUsable 用户是否可用
... ... @@ -71,6 +78,17 @@ func (u Users) HasPermissionByCode(code string) bool {
return false
}
func (u *Users) SetIsSenior(senior int8) {
switch senior {
case UserIsSeniorYes:
u.IsSenior = senior
case UserIsSeniorNo:
u.IsSenior = senior
u.AccessPartners = make([]Partner, 0)
default:
}
}
func (u *Users) Update(m map[string]interface{}) error {
if v, ok := m["CompanyId"]; ok {
u.CompanyId = v.(int64)
... ... @@ -126,6 +144,10 @@ func (u *Users) Update(m map[string]interface{}) error {
if v, ok := m["AdminType"]; ok {
u.AdminType = v.(int8)
}
if v, ok := m["IsSenior"]; ok {
senior := v.(int8)
u.SetIsSenior(senior)
}
return nil
}
... ...
... ... @@ -29,6 +29,7 @@ type Users struct {
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
Permission []domain.AdminPermissionBase //权限
AccessPartners []domain.Partner //可查看的合伙人
IsSenior int8 //是否是公司高管【1:是】【2:否】;用于确定是否可以拥有“可查看的合伙人”
CreateAt time.Time
UpdateAt time.Time
DeleteAt time.Time
... ...
... ... @@ -48,6 +48,7 @@ func (repository UsersRepository) transformPgModelToDomainModel(m *models.Users)
Permission: m.Permission,
AccessPartners: m.AccessPartners,
AdminType: m.AdminType,
IsSenior: m.IsSenior,
}, nil
}
... ... @@ -78,6 +79,7 @@ func (reponsitory UsersRepository) Add(u *domain.Users) error {
Permission: u.Permission,
AccessPartners: u.AccessPartners,
AdminType: u.AdminType,
IsSenior: u.IsSenior,
}
_, err = tx.Model(m).Insert()
return err
... ... @@ -110,6 +112,7 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error {
Permission: u.Permission,
AccessPartners: u.AccessPartners,
AdminType: u.AdminType,
IsSenior: u.IsSenior,
}
_, err = tx.Model(m).WherePK().Update()
return err
... ...
... ... @@ -122,6 +122,7 @@ func (c *UserController) EditUserPermission() {
Id int64 `json:"id"`
PermissionType []int64 `json:"permissionType"`
CheckedPartner []int64 `json:"checkedPartner"` //合伙人
IsSenior int8 `json:"isSenior"` //是否是高管【1:是】【2:否】
}
var (
param UserDetailParam
... ... @@ -139,6 +140,7 @@ func (c *UserController) EditUserPermission() {
CompanyId: companyId,
PermissionType: param.PermissionType,
CheckedPartner: param.CheckedPartner,
IsSenior: param.IsSenior,
})
if err != nil {
c.ResponseError(err)
... ...