作者 庄敏学

用户增加保存职位

不能预览此文件类型
@@ -4,11 +4,11 @@ type SavePositionCommand struct { @@ -4,11 +4,11 @@ type SavePositionCommand struct {
4 //职位ID 4 //职位ID
5 Id int64 `json:"id"` 5 Id int64 `json:"id"`
6 //公司ID 6 //公司ID
7 - CompanyId int64 `json:"companyId"` 7 + CompanyId int64 `json:"company_id"`
8 //职位名称 8 //职位名称
9 Name string `json:"name"` 9 Name string `json:"name"`
10 //父级职位ID 10 //父级职位ID
11 - ParentId int64 `json:"parentId"` 11 + ParentId int64 `json:"parent_id"`
12 //职位路径 12 //职位路径
13 Path string `json:"path"` 13 Path string `json:"path"`
14 //职位层级 14 //职位层级
@@ -12,4 +12,25 @@ type SaveUserCommand struct { @@ -12,4 +12,25 @@ type SaveUserCommand struct {
12 UserDepartments []struct { 12 UserDepartments []struct {
13 DepartmentId int `json:"department_id" ` 13 DepartmentId int `json:"department_id" `
14 } `json:"user_departments"` //用户的组织ids 14 } `json:"user_departments"` //用户的组织ids
  15 + UserPositions []struct {
  16 + PositionId int `json:"position_id"`
  17 + CompanyId int64 `json:"company_id"`
  18 + UserId int64 `json:"user_id"`
  19 + } `json:"user_positions"`
  20 +}
  21 +
  22 +func (saveUserCommand *SaveUserCommand) DepartmentIds() []int {
  23 + ids := make([]int, 0)
  24 + for _, v := range saveUserCommand.UserDepartments {
  25 + ids = append(ids, v.DepartmentId)
  26 + }
  27 + return ids
  28 +}
  29 +
  30 +func (saveUserCommand *SaveUserCommand) PositionIds() []int {
  31 + ids := make([]int, 0)
  32 + for _, v := range saveUserCommand.UserPositions {
  33 + ids = append(ids, v.PositionId)
  34 + }
  35 + return ids
15 } 36 }
@@ -83,10 +83,6 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error { @@ -83,10 +83,6 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
83 defer func() { 83 defer func() {
84 _ = transactionContext.RollbackTransaction() 84 _ = transactionContext.RollbackTransaction()
85 }() 85 }()
86 - departmentIds := make([]int, 0)  
87 - for _, v := range param.UserDepartments {  
88 - departmentIds = append(departmentIds, v.DepartmentId)  
89 - }  
90 nowTime := time.Now() 86 nowTime := time.Now()
91 newUser := domain.User{ 87 newUser := domain.User{
92 Id: param.Id, 88 Id: param.Id,
@@ -94,7 +90,8 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error { @@ -94,7 +90,8 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
94 AvatarUrl: param.Avatar, 90 AvatarUrl: param.Avatar,
95 CompanyId: param.CompanyId, 91 CompanyId: param.CompanyId,
96 AdminType: param.AdminType, 92 AdminType: param.AdminType,
97 - DepartmentId: departmentIds, 93 + DepartmentId: param.DepartmentIds(),
  94 + PositionId: param.PositionIds(),
98 Name: param.Name, 95 Name: param.Name,
99 Email: param.Email, 96 Email: param.Email,
100 Status: param.Status, 97 Status: param.Status,
@@ -156,8 +153,8 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error @@ -156,8 +153,8 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error
156 newUser.AdminType = param.AdminType 153 newUser.AdminType = param.AdminType
157 newUser.Name = param.Name 154 newUser.Name = param.Name
158 newUser.Status = param.Status 155 newUser.Status = param.Status
159 - newUser.PositionId = make([]int, 0)  
160 - newUser.DepartmentId = make([]int, 0) 156 + newUser.PositionId = param.PositionIds()
  157 + newUser.DepartmentId = param.DepartmentIds()
161 158
162 newUser.UpdatedAt = nowTime 159 newUser.UpdatedAt = nowTime
163 if len(userList) > 0 { 160 if len(userList) > 0 {
1 package repository 1 package repository
2 2
3 import ( 3 import (
4 - "time"  
5 -  
6 "github.com/go-pg/pg/v10" 4 "github.com/go-pg/pg/v10"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
@@ -65,13 +63,11 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme @@ -65,13 +63,11 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme
65 } 63 }
66 64
67 func (repo *DepartmentRepository) Remove(ids []int64) error { 65 func (repo *DepartmentRepository) Remove(ids []int64) error {
68 - nowTime := time.Now()  
69 tx := repo.transactionContext.PgTx 66 tx := repo.transactionContext.PgTx
70 uModel := models.Department{} 67 uModel := models.Department{}
71 _, err := tx.Model(&uModel). 68 _, err := tx.Model(&uModel).
72 - Set("delete_at", nowTime).  
73 Where("id in (?)", pg.In(ids)). 69 Where("id in (?)", pg.In(ids)).
74 - Update() 70 + Delete()
75 return err 71 return err
76 } 72 }
77 73
@@ -94,8 +94,7 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai @@ -94,8 +94,7 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai
94 func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*domain.User, error) { 94 func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*domain.User, error) {
95 tx := repo.transactionContext.PgTx 95 tx := repo.transactionContext.PgTx
96 userModel := []models.User{} 96 userModel := []models.User{}
97 - query := tx.Model(&userModel).Where("delete_at is null").  
98 - Limit(20) 97 + query := tx.Model(&userModel).Limit(20)
99 if v, ok := queryOptions["id"]; ok { 98 if v, ok := queryOptions["id"]; ok {
100 query.Where("id=?", v) 99 query.Where("id=?", v)
101 } 100 }