作者 唐旭辉

修复:数据同步更换主管理员时, 当出现复数管理员不进行更新数据

... ... @@ -6,6 +6,8 @@ import (
"fmt"
"time"
"github.com/astaxie/beego/logs"
"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"
... ... @@ -340,16 +342,13 @@ func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdmin
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)
logs.Error(fmt.Sprintf("没有获得公司主管数据(admin_type=%d;company_id=%d)",
domain.UserIsAdmin, cmd.CompanyId))
}
if len(userList) > 1 {
e := fmt.Sprintf("存在复数公司主管数据(admin_type=%d;company_id=%d)",
domain.UserIsAdmin, cmd.CompanyId)
return lib.ThrowError(lib.BUSINESS_ERROR, e)
logs.Error(fmt.Sprintf("存在复数公司主管数据(admin_type=%d;company_id=%d)",
domain.UserIsAdmin, cmd.CompanyId))
}
oldSuperUser = userList[0]
newSuperUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{
CompanyId: cmd.CompanyId,
Phone: cmd.Phone,
... ... @@ -359,11 +358,19 @@ func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdmin
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())
for i := range userList {
err = userList[i].Update(map[string]interface{}{
"AdminType": domain.UserIsNotAdmin,
})
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
err = usersRepository.Edit(&userList[i])
if err != nil {
e := fmt.Sprintf("更新公司主管user数据(id=%d)失败:%s",
oldSuperUser.Id, err)
return lib.ThrowError(lib.BUSINESS_ERROR, e)
}
}
err = newSuperUser.Update(map[string]interface{}{
"AdminType": domain.UserIsAdmin,
... ... @@ -371,12 +378,6 @@ func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdmin
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
err = usersRepository.Edit(&oldSuperUser)
if err != nil {
e := fmt.Sprintf("更新公司主管user数据(id=%d)失败:%s",
oldSuperUser.Id, err)
return lib.ThrowError(lib.BUSINESS_ERROR, e)
}
err = usersRepository.Edit(&newSuperUser)
if err != nil {
e := fmt.Sprintf("更新公司主管user数据(id=%d)失败:%s",
... ...
... ... @@ -54,7 +54,7 @@ func (c *SyncDataController) CompanyAdminChance() {
return
}
syncEmployeeSrv := syncService.NewSyncEmployeeService(nil)
syncEmployeeSrv.ChangeSuperAdmin(param)
err = syncEmployeeSrv.ChangeSuperAdmin(param)
if err != nil {
logs.Error("变更公司的主管失败;%s", err)
}
... ...