...
|
...
|
@@ -6,6 +6,7 @@ import ( |
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"github.com/astaxie/beego/logs"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
...
|
...
|
@@ -162,7 +163,8 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { |
|
|
companyRespository domain.CompanyRepository
|
|
|
userRespository domain.UsersRepository
|
|
|
oldCompany domain.Company
|
|
|
oldUser domain.Users
|
|
|
oldCompanyAdmins []domain.Users
|
|
|
newUser domain.Users
|
|
|
)
|
|
|
if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -177,7 +179,11 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { |
|
|
oldCompany, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
|
|
|
Id: data.Company.Id,
|
|
|
})
|
|
|
oldUser, err = userRespository.FindOne(domain.UsersFindOneQuery{
|
|
|
_, oldCompanyAdmins, err = userRespository.Find(domain.UsersFindQuery{
|
|
|
CompanyId: data.Company.Id,
|
|
|
AdminType: domain.UserIsAdmin,
|
|
|
})
|
|
|
newUser, err = userRespository.FindOne(domain.UsersFindOneQuery{
|
|
|
Id: data.User.Id,
|
|
|
})
|
|
|
oldCompany.Update(map[string]interface{}{
|
...
|
...
|
@@ -187,8 +193,29 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { |
|
|
"AdminCompanyId": data.Company.AdminCompanyId,
|
|
|
"Abbreviation": data.Company.Abbreviation,
|
|
|
})
|
|
|
entryTime, _ := time.Parse("2006-01-02", data.User.EntryTime)
|
|
|
oldUser.Update(map[string]interface{}{
|
|
|
for i := range oldCompanyAdmins {
|
|
|
oldCompanyAdmins[i].Update(map[string]interface{}{
|
|
|
"AdminType": domain.UserIsNotAdmin,
|
|
|
})
|
|
|
err = userRespository.Edit(&oldCompanyAdmins[i])
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("更新公司主管user数据(id=%d)失败:%s",
|
|
|
oldCompanyAdmins[i].Id, err)
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, e)
|
|
|
}
|
|
|
}
|
|
|
err = companyRespository.Edit(&oldCompany)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var entryTime time.Time
|
|
|
if len(data.User.EntryTime) > 0 {
|
|
|
entryTime, err = time.Parse("2006-01-02", data.User.EntryTime)
|
|
|
if err != nil {
|
|
|
logs.Error("Parse User.EntryTime 错误:%s", err)
|
|
|
}
|
|
|
}
|
|
|
newUser.Update(map[string]interface{}{
|
|
|
"CompanyId": data.User.CompanyId,
|
|
|
"OpenId": data.User.OpenId,
|
|
|
"Name": data.User.Name,
|
...
|
...
|
@@ -206,11 +233,7 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { |
|
|
"EntryTime": entryTime,
|
|
|
"AdminType": data.User.AdminType,
|
|
|
})
|
|
|
err = companyRespository.Edit(&oldCompany)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = userRespository.Edit(&oldUser)
|
|
|
err = userRespository.Edit(&newUser)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
|