正在显示
16 个修改的文件
包含
296 行增加
和
53 行删除
不能预览此文件类型
@@ -97,9 +97,9 @@ func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) er | @@ -97,9 +97,9 @@ func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) er | ||
97 | AdminType: param.User.AdminType, | 97 | AdminType: param.User.AdminType, |
98 | Name: param.User.Name, | 98 | Name: param.User.Name, |
99 | Status: param.User.Status, | 99 | Status: param.User.Status, |
100 | - UpdateAt: nowTime, | ||
101 | - DeleteAt: nil, | ||
102 | - CreateAt: nowTime, | 100 | + UpdatedAt: nowTime, |
101 | + DeletedAt: nil, | ||
102 | + CreatedAt: nowTime, | ||
103 | } | 103 | } |
104 | companyRepo := factory.CreateCompanyRepository(map[string]interface{}{ | 104 | companyRepo := factory.CreateCompanyRepository(map[string]interface{}{ |
105 | "transactionContext": transactionContext, | 105 | "transactionContext": transactionContext, |
@@ -172,7 +172,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | @@ -172,7 +172,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | ||
172 | newUser = userList[0] | 172 | newUser = userList[0] |
173 | } else { | 173 | } else { |
174 | newUser = &domain.User{ | 174 | newUser = &domain.User{ |
175 | - CreateAt: nowTime, | 175 | + CreatedAt: nowTime, |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
@@ -189,7 +189,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | @@ -189,7 +189,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | ||
189 | newUser.AdminType = param.User.AdminType | 189 | newUser.AdminType = param.User.AdminType |
190 | newUser.Name = param.User.Name | 190 | newUser.Name = param.User.Name |
191 | newUser.Status = param.User.Status | 191 | newUser.Status = param.User.Status |
192 | - newUser.UpdateAt = nowTime | 192 | + newUser.UpdatedAt = nowTime |
193 | if len(companyList) > 0 { | 193 | if len(companyList) > 0 { |
194 | _, err = companyRepo.Update(newCompany) | 194 | _, err = companyRepo.Update(newCompany) |
195 | if err != nil { | 195 | if err != nil { |
@@ -287,7 +287,7 @@ func (srv SyncDataCompanyService) changeAdmin(param *command.ChangeAdminCommand) | @@ -287,7 +287,7 @@ func (srv SyncDataCompanyService) changeAdmin(param *command.ChangeAdminCommand) | ||
287 | //修改旧管理员 为普通用户 | 287 | //修改旧管理员 为普通用户 |
288 | for i := range userList { | 288 | for i := range userList { |
289 | userList[i].AdminType = domain.UserTypeCommon | 289 | userList[i].AdminType = domain.UserTypeCommon |
290 | - userList[i].UpdateAt = time.Now() | 290 | + userList[i].UpdatedAt = time.Now() |
291 | _, err := userRepo.Update(userList[i]) | 291 | _, err := userRepo.Update(userList[i]) |
292 | if err != nil { | 292 | if err != nil { |
293 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 293 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -305,7 +305,7 @@ func (srv SyncDataCompanyService) changeAdmin(param *command.ChangeAdminCommand) | @@ -305,7 +305,7 @@ func (srv SyncDataCompanyService) changeAdmin(param *command.ChangeAdminCommand) | ||
305 | //修改为管理员用户 | 305 | //修改为管理员用户 |
306 | for i := range userList2 { | 306 | for i := range userList2 { |
307 | userList[i].AdminType = domain.UserTypeManager | 307 | userList[i].AdminType = domain.UserTypeManager |
308 | - userList[i].UpdateAt = time.Now() | 308 | + userList[i].UpdatedAt = time.Now() |
309 | _, err := userRepo.Update(userList[i]) | 309 | _, err := userRepo.Update(userList[i]) |
310 | if err != nil { | 310 | if err != nil { |
311 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 311 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -57,6 +57,14 @@ func CreateDepartmentRepository(options map[string]interface{}) domain.Departmen | @@ -57,6 +57,14 @@ func CreateDepartmentRepository(options map[string]interface{}) domain.Departmen | ||
57 | return repository.NewDepartmentRepository(transactionContext) | 57 | return repository.NewDepartmentRepository(transactionContext) |
58 | } | 58 | } |
59 | 59 | ||
60 | +func CreatePositionRepository(options map[string]interface{}) domain.PositionRepository { | ||
61 | + var transactionContext *pg.TransactionContext | ||
62 | + if value, ok := options["transactionContext"]; ok { | ||
63 | + transactionContext = value.(*pg.TransactionContext) | ||
64 | + } | ||
65 | + return repository.NewPositionRepository(transactionContext) | ||
66 | +} | ||
67 | + | ||
60 | func CreateRoleRepository(options map[string]interface{}) domain.RoleRepository { | 68 | func CreateRoleRepository(options map[string]interface{}) domain.RoleRepository { |
61 | var transactionContext *pg.TransactionContext | 69 | var transactionContext *pg.TransactionContext |
62 | if value, ok := options["transactionContext"]; ok { | 70 | if value, ok := options["transactionContext"]; ok { |
1 | +package command | ||
2 | + | ||
3 | +type SavePositionCommand struct { | ||
4 | + //职位ID | ||
5 | + Id int64 `json:"id"` | ||
6 | + //公司ID | ||
7 | + CompanyId int64 `json:"companyId"` | ||
8 | + //职位名称 | ||
9 | + Name string `json:"name"` | ||
10 | + //父级职位ID | ||
11 | + ParentId int64 `json:"parentId"` | ||
12 | + //职位路径 | ||
13 | + Path string `json:"path"` | ||
14 | + //职位层级 | ||
15 | + Level int `json:"level"` | ||
16 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/position/command" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
9 | +) | ||
10 | + | ||
11 | +type SyncDataPositionService struct{} | ||
12 | + | ||
13 | +func (service SyncDataPositionService) FromBusinessAdmin(param *domain.MessageBody) error { | ||
14 | + var err error | ||
15 | + switch param.Action { | ||
16 | + //新增-编辑职位 | ||
17 | + case "add", "edit": | ||
18 | + createPositionCommand := &command.SavePositionCommand{} | ||
19 | + err = json.Unmarshal(param.Data, createPositionCommand) | ||
20 | + if err != nil { | ||
21 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
22 | + } | ||
23 | + err = service.CreateOrUpdatePosition(createPositionCommand) | ||
24 | + //批量删除职位 | ||
25 | + case "batchDelete": | ||
26 | + batchDeletePositionCommand := &command.BatchDeletePositionCommand{} | ||
27 | + err = json.Unmarshal(param.Data, batchDeletePositionCommand) | ||
28 | + if err != nil { | ||
29 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
30 | + } | ||
31 | + err = service.BatchDeletePosition(batchDeletePositionCommand) | ||
32 | + } | ||
33 | + return err | ||
34 | +} | ||
35 | + | ||
36 | +// CreateOrUpdatePosition 新增职位 | ||
37 | +func (service SyncDataPositionService) CreateOrUpdatePosition(positionCommand *command.SavePositionCommand) error { | ||
38 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
39 | + if err != nil { | ||
40 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
41 | + } | ||
42 | + if err := transactionContext.StartTransaction(); err != nil { | ||
43 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
44 | + } | ||
45 | + defer func() { | ||
46 | + _ = transactionContext.RollbackTransaction() | ||
47 | + }() | ||
48 | + positionRepository := factory.CreatePositionRepository(map[string]interface{}{ | ||
49 | + "transactionContext": transactionContext, | ||
50 | + }) | ||
51 | + position := &domain.Position{ | ||
52 | + Id: positionCommand.Id, | ||
53 | + CompanyId: positionCommand.CompanyId, | ||
54 | + Name: positionCommand.Name, | ||
55 | + ParentId: positionCommand.ParentId, | ||
56 | + Path: positionCommand.Path, | ||
57 | + Level: positionCommand.Level, | ||
58 | + } | ||
59 | + pdm, _ := positionRepository.FindOne(map[string]interface{}{"id": position.Id}) | ||
60 | + if pdm.Id > 0 { | ||
61 | + _, err = positionRepository.Update(position) | ||
62 | + } else { | ||
63 | + _, err = positionRepository.Insert(position) | ||
64 | + } | ||
65 | + if err != nil { | ||
66 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
67 | + } | ||
68 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
69 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
70 | + } | ||
71 | + return nil | ||
72 | +} | ||
73 | + | ||
74 | +// BatchDeletePosition 批量删除职位 | ||
75 | +func (service SyncDataPositionService) BatchDeletePosition(batchDeletePositionCommand *command.BatchDeletePositionCommand) error { | ||
76 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
77 | + if err != nil { | ||
78 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
79 | + } | ||
80 | + if err := transactionContext.StartTransaction(); err != nil { | ||
81 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
82 | + } | ||
83 | + defer func() { | ||
84 | + _ = transactionContext.RollbackTransaction() | ||
85 | + }() | ||
86 | + positionRepository := factory.CreatePositionRepository(map[string]interface{}{ | ||
87 | + "transactionContext": transactionContext, | ||
88 | + }) | ||
89 | + err = positionRepository.Remove(batchDeletePositionCommand.Ids) | ||
90 | + if err != nil { | ||
91 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
92 | + } | ||
93 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
94 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
95 | + } | ||
96 | + return nil | ||
97 | +} |
@@ -8,6 +8,7 @@ type SaveUserCommand struct { | @@ -8,6 +8,7 @@ type SaveUserCommand struct { | ||
8 | AdminType int `json:"admin_type"` // 1普通员工 2 主管理员 | 8 | AdminType int `json:"admin_type"` // 1普通员工 2 主管理员 |
9 | Name string `json:"name"` // 用户姓名 | 9 | Name string `json:"name"` // 用户姓名 |
10 | Status int `json:"status"` // 用户状态(1正常 2禁用) | 10 | Status int `json:"status"` // 用户状态(1正常 2禁用) |
11 | + Email string `json:"email"` // 邮箱 | ||
11 | UserDepartments []struct { | 12 | UserDepartments []struct { |
12 | DepartmentId int `json:"department_id" ` | 13 | DepartmentId int `json:"department_id" ` |
13 | } `json:"user_departments"` //用户的组织ids | 14 | } `json:"user_departments"` //用户的组织ids |
@@ -83,7 +83,7 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error { | @@ -83,7 +83,7 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error { | ||
83 | defer func() { | 83 | defer func() { |
84 | _ = transactionContext.RollbackTransaction() | 84 | _ = transactionContext.RollbackTransaction() |
85 | }() | 85 | }() |
86 | - var departmentIds []int | 86 | + departmentIds := make([]int, 0) |
87 | for _, v := range param.UserDepartments { | 87 | for _, v := range param.UserDepartments { |
88 | departmentIds = append(departmentIds, v.DepartmentId) | 88 | departmentIds = append(departmentIds, v.DepartmentId) |
89 | } | 89 | } |
@@ -96,10 +96,10 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error { | @@ -96,10 +96,10 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error { | ||
96 | AdminType: param.AdminType, | 96 | AdminType: param.AdminType, |
97 | DepartmentId: departmentIds, | 97 | DepartmentId: departmentIds, |
98 | Name: param.Name, | 98 | Name: param.Name, |
99 | + Email: param.Email, | ||
99 | Status: param.Status, | 100 | Status: param.Status, |
100 | - UpdateAt: nowTime, | ||
101 | - DeleteAt: nil, | ||
102 | - CreateAt: nowTime, | 101 | + UpdatedAt: nowTime, |
102 | + CreatedAt: nowTime, | ||
103 | } | 103 | } |
104 | userRepo := factory.CreateUserRepository(map[string]interface{}{ | 104 | userRepo := factory.CreateUserRepository(map[string]interface{}{ |
105 | "transactionContext": transactionContext, | 105 | "transactionContext": transactionContext, |
@@ -146,7 +146,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error | @@ -146,7 +146,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error | ||
146 | newUser = userList[0] | 146 | newUser = userList[0] |
147 | } else { | 147 | } else { |
148 | newUser = &domain.User{ | 148 | newUser = &domain.User{ |
149 | - CreateAt: nowTime, | 149 | + CreatedAt: nowTime, |
150 | } | 150 | } |
151 | } | 151 | } |
152 | newUser.Id = param.Id | 152 | newUser.Id = param.Id |
@@ -159,7 +159,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error | @@ -159,7 +159,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error | ||
159 | newUser.PositionId = make([]int, 0) | 159 | newUser.PositionId = make([]int, 0) |
160 | newUser.DepartmentId = make([]int, 0) | 160 | newUser.DepartmentId = make([]int, 0) |
161 | 161 | ||
162 | - newUser.UpdateAt = nowTime | 162 | + newUser.UpdatedAt = nowTime |
163 | if len(userList) > 0 { | 163 | if len(userList) > 0 { |
164 | _, err = userRepo.Update(newUser) | 164 | _, err = userRepo.Update(newUser) |
165 | if err != nil { | 165 | if err != nil { |
@@ -290,7 +290,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro | @@ -290,7 +290,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro | ||
290 | editUserList[i].Name = mVal.Name | 290 | editUserList[i].Name = mVal.Name |
291 | editUserList[i].Status = mVal.Status | 291 | editUserList[i].Status = mVal.Status |
292 | editUserList[i].CompanyId = mVal.CompanyId | 292 | editUserList[i].CompanyId = mVal.CompanyId |
293 | - editUserList[i].UpdateAt = nowTime | 293 | + editUserList[i].UpdatedAt = nowTime |
294 | _, err = userRepo.Update(editUserList[i]) | 294 | _, err = userRepo.Update(editUserList[i]) |
295 | if err != nil { | 295 | if err != nil { |
296 | return err | 296 | return err |
@@ -308,9 +308,9 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro | @@ -308,9 +308,9 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro | ||
308 | AdminType: param.AddUsers[i].AdminType, | 308 | AdminType: param.AddUsers[i].AdminType, |
309 | Name: param.AddUsers[i].Name, | 309 | Name: param.AddUsers[i].Name, |
310 | Status: param.AddUsers[i].Status, | 310 | Status: param.AddUsers[i].Status, |
311 | - UpdateAt: nowTime, | ||
312 | - DeleteAt: nil, | ||
313 | - CreateAt: nowTime, | 311 | + UpdatedAt: nowTime, |
312 | + DeletedAt: nil, | ||
313 | + CreatedAt: nowTime, | ||
314 | } | 314 | } |
315 | _, err := userRepo.Insert(&tempUser) | 315 | _, err := userRepo.Insert(&tempUser) |
316 | if err != nil { | 316 | if err != nil { |
pkg/domain/position.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +type Position struct { | ||
4 | + //职位ID | ||
5 | + Id int64 `json:"id"` | ||
6 | + //公司ID | ||
7 | + CompanyId int64 `json:"companyId"` | ||
8 | + //职位名称 | ||
9 | + Name string `json:"name"` | ||
10 | + //父级职位ID | ||
11 | + ParentId int64 `json:"parentId"` | ||
12 | + //职位路径 | ||
13 | + Path string `json:"path"` | ||
14 | + //职位层级 | ||
15 | + Level int `json:"level"` | ||
16 | +} | ||
17 | + | ||
18 | +type PositionRepository interface { | ||
19 | + Insert(position *Position) (*Position, error) | ||
20 | + Update(position *Position) (*Position, error) | ||
21 | + Remove(ids []int64) error | ||
22 | + FindOne(queryOption map[string]interface{}) (*Position, error) | ||
23 | +} |
@@ -13,9 +13,9 @@ type User struct { | @@ -13,9 +13,9 @@ type User struct { | ||
13 | Status int // 用户状态(1正常 2禁用) | 13 | Status int // 用户状态(1正常 2禁用) |
14 | DepartmentId []int // 用户归属的部门 | 14 | DepartmentId []int // 用户归属的部门 |
15 | PositionId []int //用户职位 | 15 | PositionId []int //用户职位 |
16 | - UpdateAt time.Time // 更新时间 | ||
17 | - DeleteAt *time.Time | ||
18 | - CreateAt time.Time | 16 | + UpdatedAt time.Time // 更新时间 |
17 | + DeletedAt *time.Time | ||
18 | + CreatedAt time.Time | ||
19 | } | 19 | } |
20 | 20 | ||
21 | // 1普通员工 2 主管理员 | 21 | // 1普通员工 2 主管理员 |
@@ -33,7 +33,7 @@ func init() { | @@ -33,7 +33,7 @@ func init() { | ||
33 | &models.ReceivedMessage{}, | 33 | &models.ReceivedMessage{}, |
34 | &models.Role{}, | 34 | &models.Role{}, |
35 | &models.RoleUser{}, | 35 | &models.RoleUser{}, |
36 | - &models.Positions{}, | 36 | + &models.Position{}, |
37 | } | 37 | } |
38 | for _, model := range tables { | 38 | for _, model := range tables { |
39 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | 39 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ |
pkg/infrastructure/pg/models/position.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +type Position struct { | ||
6 | + tableName struct{} `pg:"position"` | ||
7 | + //职位ID | ||
8 | + Id int64 `pg:",pk"` | ||
9 | + //公司ID | ||
10 | + CompanyId int64 `comment:"公司ID"` | ||
11 | + //职位名称 | ||
12 | + Name string `comment:"职位名称"` | ||
13 | + //父级职位ID | ||
14 | + ParentId int64 `comment:"父级职位ID" pg:",use_zero"` | ||
15 | + //职位路径 | ||
16 | + Path string `comment:"职位路径"` | ||
17 | + //职位层级 | ||
18 | + Level int `comment:"职位层级" pg:",use_zero"` | ||
19 | + //创建时间 | ||
20 | + CreatedAt time.Time `comment:"创建时间" pg:"default:now()"` | ||
21 | + //更新时间 | ||
22 | + UpdatedAt time.Time `comment:"更新时间" pg:"default:now()"` | ||
23 | + //删除时间 | ||
24 | + DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"` | ||
25 | +} |
1 | -package models | ||
2 | - | ||
3 | -import "time" | ||
4 | - | ||
5 | -type Positions struct { | ||
6 | - Id int64 //ID | ||
7 | - CompanyId int64 //公司ID | ||
8 | - Name string //职位名称 | ||
9 | - ParentId int64 `pg:",use_zero"` //父级职位 | ||
10 | - Path string //职位路径 | ||
11 | - Level int `pg:",use_zero"` //层级 | ||
12 | - Remarks string //备注 | ||
13 | - CreatedAt time.Time | ||
14 | - UpdatedAt time.Time | ||
15 | - DeletedAt *time.Time `pg:",soft_delete"` | ||
16 | -} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
8 | + "time" | ||
9 | +) | ||
10 | + | ||
11 | +type PositionRepository struct { | ||
12 | + transactionContext *pgTransaction.TransactionContext | ||
13 | +} | ||
14 | + | ||
15 | +func NewPositionRepository(tx *pgTransaction.TransactionContext) *PositionRepository { | ||
16 | + return &PositionRepository{ | ||
17 | + transactionContext: tx, | ||
18 | + } | ||
19 | +} | ||
20 | + | ||
21 | +// Insert 新增职位 | ||
22 | +func (repository *PositionRepository) Insert(position *domain.Position) (*domain.Position, error) { | ||
23 | + model := &models.Position{ | ||
24 | + Id: position.Id, | ||
25 | + CompanyId: position.CompanyId, | ||
26 | + Name: position.Name, | ||
27 | + ParentId: position.ParentId, | ||
28 | + Path: position.Path, | ||
29 | + Level: position.Level, | ||
30 | + } | ||
31 | + _, err := repository.transactionContext.PgTx.Model(model).Insert() | ||
32 | + return position, err | ||
33 | +} | ||
34 | + | ||
35 | +// Update 更新 | ||
36 | +func (repository *PositionRepository) Update(position *domain.Position) (*domain.Position, error) { | ||
37 | + model := &models.Position{ | ||
38 | + Id: position.Id, | ||
39 | + CompanyId: position.CompanyId, | ||
40 | + Name: position.Name, | ||
41 | + ParentId: position.ParentId, | ||
42 | + Path: position.Path, | ||
43 | + Level: position.Level, | ||
44 | + UpdatedAt: time.Now(), | ||
45 | + } | ||
46 | + _, err := repository.transactionContext.PgTx.Model(model).WherePK().Update() | ||
47 | + return position, err | ||
48 | +} | ||
49 | + | ||
50 | +// Remove 删除 | ||
51 | +func (repository *PositionRepository) Remove(ids []int64) error { | ||
52 | + _, err := repository.transactionContext.PgTx.Model(&models.Position{}).Where("id in (?)", pg.In(ids)).Delete() | ||
53 | + return err | ||
54 | +} | ||
55 | + | ||
56 | +func (repository *PositionRepository) FindOne(queryOption map[string]interface{}) (*domain.Position, error) { | ||
57 | + position := &models.Position{} | ||
58 | + query := repository.transactionContext.PgTx.Model(position) | ||
59 | + if id, ok := queryOption["id"]; ok { | ||
60 | + query.Where("id = ?", id) | ||
61 | + } | ||
62 | + err := query.First() | ||
63 | + if err != nil { | ||
64 | + return nil, err | ||
65 | + } | ||
66 | + return repository.transferToDomain(position), nil | ||
67 | +} | ||
68 | + | ||
69 | +func (repository *PositionRepository) transferToDomain(model *models.Position) *domain.Position { | ||
70 | + return &domain.Position{ | ||
71 | + Id: model.Id, | ||
72 | + CompanyId: model.CompanyId, | ||
73 | + Name: model.Name, | ||
74 | + ParentId: model.ParentId, | ||
75 | + Path: model.Path, | ||
76 | + Level: model.Level, | ||
77 | + } | ||
78 | +} |
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" |
@@ -30,9 +28,9 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { | @@ -30,9 +28,9 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { | ||
30 | AdminType: user.AdminType, | 28 | AdminType: user.AdminType, |
31 | Name: user.Name, | 29 | Name: user.Name, |
32 | Status: user.Status, | 30 | Status: user.Status, |
33 | - UpdatedAt: user.UpdateAt, | ||
34 | - CreatedAt: user.CreateAt, | ||
35 | - DeletedAt: user.DeleteAt, | 31 | + UpdatedAt: user.UpdatedAt, |
32 | + CreatedAt: user.CreatedAt, | ||
33 | + DeletedAt: user.DeletedAt, | ||
36 | } | 34 | } |
37 | tx := repo.transactionContext.PgTx | 35 | tx := repo.transactionContext.PgTx |
38 | _, err := tx.Model(&userModel).Insert() | 36 | _, err := tx.Model(&userModel).Insert() |
@@ -53,9 +51,9 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { | @@ -53,9 +51,9 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { | ||
53 | Name: user.Name, | 51 | Name: user.Name, |
54 | Email: user.Email, | 52 | Email: user.Email, |
55 | Status: user.Status, | 53 | Status: user.Status, |
56 | - UpdatedAt: user.UpdateAt, | ||
57 | - CreatedAt: user.CreateAt, | ||
58 | - DeletedAt: user.DeleteAt, | 54 | + UpdatedAt: user.UpdatedAt, |
55 | + CreatedAt: user.CreatedAt, | ||
56 | + DeletedAt: user.DeletedAt, | ||
59 | } | 57 | } |
60 | tx := repo.transactionContext.PgTx | 58 | tx := repo.transactionContext.PgTx |
61 | _, err := tx.Model(&userModel).WherePK().Update() | 59 | _, err := tx.Model(&userModel).WherePK().Update() |
@@ -66,13 +64,9 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { | @@ -66,13 +64,9 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { | ||
66 | } | 64 | } |
67 | 65 | ||
68 | func (repo *UserRepository) Remove(userId []int64) error { | 66 | func (repo *UserRepository) Remove(userId []int64) error { |
69 | - nowTime := time.Now() | ||
70 | tx := repo.transactionContext.PgTx | 67 | tx := repo.transactionContext.PgTx |
71 | uModel := models.User{} | 68 | uModel := models.User{} |
72 | - _, err := tx.Model(&uModel). | ||
73 | - Set("delete_at", nowTime). | ||
74 | - Where("id in (?)", pg.In(userId)). | ||
75 | - Update() | 69 | + _, err := tx.Model(&uModel).Where("id in (?)", pg.In(userId)).Delete() |
76 | return err | 70 | return err |
77 | } | 71 | } |
78 | 72 | ||
@@ -145,8 +139,8 @@ func (repo *UserRepository) TransformToUserDomain(user *models.User) *domain.Use | @@ -145,8 +139,8 @@ func (repo *UserRepository) TransformToUserDomain(user *models.User) *domain.Use | ||
145 | Name: user.Name, | 139 | Name: user.Name, |
146 | Email: user.Email, | 140 | Email: user.Email, |
147 | Status: user.Status, | 141 | Status: user.Status, |
148 | - UpdateAt: user.UpdatedAt, | ||
149 | - CreateAt: user.CreatedAt, | ||
150 | - DeleteAt: user.DeletedAt, | 142 | + UpdatedAt: user.UpdatedAt, |
143 | + CreatedAt: user.CreatedAt, | ||
144 | + DeletedAt: user.DeletedAt, | ||
151 | } | 145 | } |
152 | } | 146 | } |
@@ -2,6 +2,7 @@ package handle | @@ -2,6 +2,7 @@ package handle | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | 4 | "encoding/json" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/position/service" | ||
5 | "strconv" | 6 | "strconv" |
6 | 7 | ||
7 | "github.com/Shopify/sarama" | 8 | "github.com/Shopify/sarama" |
@@ -87,6 +88,17 @@ func SyncDataBusinessAdmin(msgData *sarama.ConsumerMessage) error { | @@ -87,6 +88,17 @@ func SyncDataBusinessAdmin(msgData *sarama.ConsumerMessage) error { | ||
87 | }) | 88 | }) |
88 | return err | 89 | return err |
89 | } | 90 | } |
91 | + case "position": | ||
92 | + positionSrv := service.SyncDataPositionService{} | ||
93 | + err = positionSrv.FromBusinessAdmin(&msgBody) | ||
94 | + if err != nil { | ||
95 | + log.Logger.Error("处理position消息失败"+err.Error(), map[string]interface{}{ | ||
96 | + "module": msgBody.Module, | ||
97 | + "action": msgBody.Action, | ||
98 | + "data": string(msgBody.Data), | ||
99 | + }) | ||
100 | + return err | ||
101 | + } | ||
90 | } | 102 | } |
91 | err = msgRepo.SaveMessage(&receivedMsg) | 103 | err = msgRepo.SaveMessage(&receivedMsg) |
92 | if err != nil { | 104 | if err != nil { |
-
请 注册 或 登录 后发表评论