作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !30
... ... @@ -199,13 +199,22 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error {
oldCompany, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
Id: data.Company.Id,
})
if err != nil {
return fmt.Errorf("获取公司数据失败,%s", err)
}
_, oldCompanyAdmins, err = userRespository.Find(domain.UsersFindQuery{
CompanyId: data.Company.Id,
AdminType: domain.UserIsAdmin,
})
if err != nil {
return fmt.Errorf("获取公司admin数据失败,%s", err)
}
newUser, err = userRespository.FindOne(domain.UsersFindOneQuery{
Id: data.User.Id,
})
if err != nil {
return fmt.Errorf("获取用户数据失败,%s,data.user.id=%d", err, data.User.Id)
}
applets := []domain.CompanyApplets{}
for _, v := range data.Company.Applets {
app := domain.CompanyApplets{
... ...
... ... @@ -265,33 +265,66 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro
}
for i := range datas {
data := datas[i]
var oldUser domain.Users
oldUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{
var (
oldUser *domain.Users
userExist bool
)
oldUser, userExist, err = usersRepository.FindOneWithExist(domain.UsersFindOneQuery{
Id: data.Id,
})
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
_ = oldUser.Update(map[string]interface{}{
"CompanyId": data.CompanyId,
"Name": data.Name,
"Sex": data.Sex,
"JobNum": data.JobNum,
"Phone": data.Phone,
"PrivatePhone": data.PrivatePhone,
"Email": data.Email,
"ExtensionNum": data.ExtensionNum,
"Workspace": data.WorkSpace,
"Status": data.Status,
"Avatar": data.Avatar,
"Remarks": data.Remarks,
"ChargeStatus": data.ChargeStatus,
"EntryTime": entryTime,
"AdminType": data.AdminType,
})
if err = usersRepository.Edit(&oldUser); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
if !userExist {
//不存在可更新数据,执行添加数据的操作
newUser := domain.Users{
Id: data.Id,
CompanyId: data.CompanyId,
OpenId: data.OpenId,
Name: data.Name,
Sex: data.Sex,
JobNum: data.JobNum,
Phone: data.Phone,
PrivatePhone: data.PrivatePhone,
Email: data.Email,
ExtensionNum: data.ExtensionNum,
Workspace: data.WorkSpace,
Status: data.Status,
Avatar: data.Avatar,
Remarks: data.Remarks,
ChargeStatus: data.ChargeStatus,
Permission: []domain.AdminPermissionBase{}, //初始化权限
AccessPartners: []domain.Partner{}, //默认初始化
AdminType: data.AdminType,
IsSenior: 2,
}
newUser.EntryTime, _ = time.Parse("2006-01-02", data.EntryTime)
if err = usersRepository.Add(&newUser); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
continue
} else {
entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
_ = oldUser.Update(map[string]interface{}{
"CompanyId": data.CompanyId,
"Name": data.Name,
"Sex": data.Sex,
"JobNum": data.JobNum,
"Phone": data.Phone,
"PrivatePhone": data.PrivatePhone,
"Email": data.Email,
"ExtensionNum": data.ExtensionNum,
"Workspace": data.WorkSpace,
"Status": data.Status,
"Avatar": data.Avatar,
"Remarks": data.Remarks,
"ChargeStatus": data.ChargeStatus,
"EntryTime": entryTime,
"AdminType": data.AdminType,
})
if err = usersRepository.Edit(oldUser); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
err = transactionContext.CommitTransaction()
... ...
... ... @@ -6,6 +6,7 @@ import (
//PlatformAction 企业平台数据同步服务 动作接口设定
type SyncAction interface {
//DoAction(执行的动作,数据)
DoAction(string, []byte) error
}
... ...
... ... @@ -172,5 +172,8 @@ type UsersRepository interface {
Edit(*Users) error
Remove([]int64) error
FindOne(queryOptions UsersFindOneQuery) (Users, error)
//FindOneWithExist 查询一个用户,
//当数据不存在时不返回错误,替代的是返回bool,true表示数据存在,false表示数据不存在
FindOneWithExist(queryOptions UsersFindOneQuery) (*Users, bool, error)
Find(queryOptions UsersFindQuery) (int, []Users, error)
}
... ...
... ... @@ -124,7 +124,7 @@ func (repository *ColumnSettingRepository) Find(queryOptions map[string]interfac
columnSettings := make([]*domain.ColumnSetting, 0)
query := tx.Model(&columnSettingModels)
if ids, ok := queryOptions["ids"]; ok {
query = query.Where("column_setting.uid IN (?)", pg.In(ids.(int64)))
query = query.Where("column_setting.uid IN (?)", pg.In(ids.([]int64)))
}
if uid, ok := queryOptions["uid"]; ok {
query = query.Where("column_setting.uid = ?", uid)
... ...
... ... @@ -5,6 +5,7 @@ import (
"fmt"
"time"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
... ... @@ -153,6 +154,47 @@ func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery
return reponsitory.transformPgModelToDomainModel(&m)
}
//FindOneWithExist 查询一个用户,
//当数据不存在时不返回错误,替代的是返回bool,true表示数据存在,false表示数据不存在
func (reponsitory UsersRepository) FindOneWithExist(queryOptions domain.UsersFindOneQuery) (*domain.Users, bool, error) {
var (
err error
tx = reponsitory.transactionContext.PgTx
m models.Users
hasCondition bool
)
query := tx.Model(&m)
query = query.Where("delete_at ISNULL")
if queryOptions.Id > 0 {
hasCondition = true
query = query.Where("id=?", queryOptions.Id)
}
if len(queryOptions.Phone) > 0 {
hasCondition = true
query = query.Where("phone=?", queryOptions.Phone)
}
if queryOptions.CompanyId > 0 {
hasCondition = true
query = query.Where("company_id=?", queryOptions.CompanyId)
}
if queryOptions.OpenId > 0 {
hasCondition = true
query = query.Where("open_id=?", queryOptions.OpenId)
}
if !hasCondition {
return nil, false, errors.New("UsersRepository.FindOne 必须要有查询条件")
}
err = query.First()
if err != nil && err == pg.ErrNoRows {
return nil, false, nil
}
if err != nil {
return nil, false, err
}
searchResult, err := reponsitory.transformPgModelToDomainModel(&m)
return &searchResult, true, err
}
func (reponsitory UsersRepository) Find(queryOption domain.UsersFindQuery) (int, []domain.Users, error) {
db := reponsitory.transactionContext.PgTx
usersModels := []models.Users{}
... ...