作者 庄敏学

用户增加保存职位

不能预览此文件类型
... ... @@ -4,11 +4,11 @@ type SavePositionCommand struct {
//职位ID
Id int64 `json:"id"`
//公司ID
CompanyId int64 `json:"companyId"`
CompanyId int64 `json:"company_id"`
//职位名称
Name string `json:"name"`
//父级职位ID
ParentId int64 `json:"parentId"`
ParentId int64 `json:"parent_id"`
//职位路径
Path string `json:"path"`
//职位层级
... ...
... ... @@ -12,4 +12,25 @@ type SaveUserCommand struct {
UserDepartments []struct {
DepartmentId int `json:"department_id" `
} `json:"user_departments"` //用户的组织ids
UserPositions []struct {
PositionId int `json:"position_id"`
CompanyId int64 `json:"company_id"`
UserId int64 `json:"user_id"`
} `json:"user_positions"`
}
func (saveUserCommand *SaveUserCommand) DepartmentIds() []int {
ids := make([]int, 0)
for _, v := range saveUserCommand.UserDepartments {
ids = append(ids, v.DepartmentId)
}
return ids
}
func (saveUserCommand *SaveUserCommand) PositionIds() []int {
ids := make([]int, 0)
for _, v := range saveUserCommand.UserPositions {
ids = append(ids, v.PositionId)
}
return ids
}
... ...
... ... @@ -83,10 +83,6 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
defer func() {
_ = transactionContext.RollbackTransaction()
}()
departmentIds := make([]int, 0)
for _, v := range param.UserDepartments {
departmentIds = append(departmentIds, v.DepartmentId)
}
nowTime := time.Now()
newUser := domain.User{
Id: param.Id,
... ... @@ -94,7 +90,8 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
AvatarUrl: param.Avatar,
CompanyId: param.CompanyId,
AdminType: param.AdminType,
DepartmentId: departmentIds,
DepartmentId: param.DepartmentIds(),
PositionId: param.PositionIds(),
Name: param.Name,
Email: param.Email,
Status: param.Status,
... ... @@ -156,8 +153,8 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error
newUser.AdminType = param.AdminType
newUser.Name = param.Name
newUser.Status = param.Status
newUser.PositionId = make([]int, 0)
newUser.DepartmentId = make([]int, 0)
newUser.PositionId = param.PositionIds()
newUser.DepartmentId = param.DepartmentIds()
newUser.UpdatedAt = nowTime
if len(userList) > 0 {
... ...
package repository
import (
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
... ... @@ -65,13 +63,11 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme
}
func (repo *DepartmentRepository) Remove(ids []int64) error {
nowTime := time.Now()
tx := repo.transactionContext.PgTx
uModel := models.Department{}
_, err := tx.Model(&uModel).
Set("delete_at", nowTime).
Where("id in (?)", pg.In(ids)).
Update()
Delete()
return err
}
... ...
... ... @@ -94,8 +94,7 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai
func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*domain.User, error) {
tx := repo.transactionContext.PgTx
userModel := []models.User{}
query := tx.Model(&userModel).Where("delete_at is null").
Limit(20)
query := tx.Model(&userModel).Limit(20)
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
... ...