...
|
...
|
@@ -7,6 +7,7 @@ import ( |
|
|
"time"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/command"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
...
|
...
|
@@ -75,6 +76,13 @@ type ImportEmployeeData struct { |
|
|
//SyncEmployeeService 同步用户数据
|
|
|
type SyncEmployeeService struct{}
|
|
|
|
|
|
func NewSyncEmployeeService(option map[string]interface{}) *SyncEmployeeService {
|
|
|
syncEmployee := new(SyncEmployeeService)
|
|
|
return syncEmployee
|
|
|
}
|
|
|
|
|
|
var _ SyncAction = (*SyncEmployeeService)(nil)
|
|
|
|
|
|
func (service SyncEmployeeService) DoAction(action string, byteData []byte) error {
|
|
|
switch action {
|
|
|
case "add":
|
...
|
...
|
@@ -297,6 +305,82 @@ func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) e |
|
|
}
|
|
|
|
|
|
//ChangeAdmin 变更公司负责人,超级管理员
|
|
|
func (service SyncEmployeeService) ChangeAdmin() error {
|
|
|
func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdminCommand) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var usersRepository domain.UsersRepository
|
|
|
if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var (
|
|
|
oldSuperUser domain.Users
|
|
|
newSuperUser domain.Users
|
|
|
userList []domain.Users
|
|
|
)
|
|
|
_, userList, err = usersRepository.Find(map[string]interface{}{
|
|
|
"CompanyId": cmd.CompanyId,
|
|
|
"AdminType": domain.UserIsAdmin,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取用户(admin_type=%d;company_id=%d)数据失败:%s",
|
|
|
domain.UserIsAdmin, cmd.CompanyId, err.Error())
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
if len(userList) == 0 {
|
|
|
e := fmt.Sprintf("没有获得公司主管数据(admin_type=%d;company_id=%d)",
|
|
|
domain.UserIsAdmin, cmd.CompanyId)
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, e)
|
|
|
}
|
|
|
if len(userList) > 1 {
|
|
|
e := fmt.Sprintf("存在复数公司主管数据(admin_type=%d;company_id=%d)",
|
|
|
domain.UserIsAdmin, cmd.CompanyId)
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, e)
|
|
|
}
|
|
|
oldSuperUser = userList[0]
|
|
|
newSuperUser, err = usersRepository.FindOne(map[string]interface{}{
|
|
|
"CompanyId": cmd.CompanyId,
|
|
|
"Phone": cmd.Phone,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取公司用户数据(phone=%s;company_id=%d)",
|
|
|
cmd.Phone, cmd.CompanyId)
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, e)
|
|
|
}
|
|
|
err = oldSuperUser.Update(map[string]interface{}{
|
|
|
"AdminType": domain.UserIsNotAdmin,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
//提取到domain???
|
|
|
err = newSuperUser.Update(map[string]interface{}{
|
|
|
"AdminType": domain.UserIsAdmin,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
err = usersRepository.Edit(&oldSuperUser)
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("更新公司主管user数据(id=%d)",
|
|
|
oldSuperUser.Id)
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, e)
|
|
|
}
|
|
|
err = usersRepository.Edit(&newSuperUser)
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("更新公司主管user数据(id=%d)",
|
|
|
newSuperUser.Id)
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, e)
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return nil
|
|
|
} |
...
|
...
|
|