作者 郑周

Merge remote-tracking branch 'origin/test' into test

不能预览此文件类型
@@ -142,6 +142,8 @@ func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmen @@ -142,6 +142,8 @@ func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmen
142 } 142 }
143 if len(param.ChargeUserIds) > 0 { 143 if len(param.ChargeUserIds) > 0 {
144 departmentList[i].ChargeUserIds = param.ChargeUserIds 144 departmentList[i].ChargeUserIds = param.ChargeUserIds
  145 + } else {
  146 + departmentList[i].ChargeUserIds = make([]int64, 0)
145 } 147 }
146 continue 148 continue
147 } 149 }
@@ -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 + EntryTime string `json:"entryTime"` //入职日期
11 Email string `json:"email"` // 邮箱 12 Email string `json:"email"` // 邮箱
12 UserDepartments []struct { 13 UserDepartments []struct {
13 DepartmentId int `json:"department_id" ` 14 DepartmentId int `json:"department_id" `
  1 +package query
  2 +
  3 +type ListUserQuery struct {
  4 + CompanyId int64 `json:"companyId"` // 公司ID
  5 + Name string `json:"name"` // 用户姓名
  6 +}
@@ -102,6 +102,7 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error { @@ -102,6 +102,7 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
102 Name: param.Name, 102 Name: param.Name,
103 Email: param.Email, 103 Email: param.Email,
104 Status: param.Status, 104 Status: param.Status,
  105 + EntryTime: param.EntryTime,
105 UpdatedAt: nowTime, 106 UpdatedAt: nowTime,
106 CreatedAt: nowTime, 107 CreatedAt: nowTime,
107 } 108 }
@@ -160,6 +161,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error @@ -160,6 +161,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error
160 newUser.AdminType = param.AdminType 161 newUser.AdminType = param.AdminType
161 newUser.Name = param.Name 162 newUser.Name = param.Name
162 newUser.Status = param.Status 163 newUser.Status = param.Status
  164 + newUser.EntryTime = param.EntryTime
163 newUser.PositionId = param.PositionIds() 165 newUser.PositionId = param.PositionIds()
164 newUser.DepartmentId = param.DepartmentIds() 166 newUser.DepartmentId = param.DepartmentIds()
165 167
@@ -294,6 +296,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro @@ -294,6 +296,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
294 editUserList[i].Name = mVal.Name 296 editUserList[i].Name = mVal.Name
295 editUserList[i].Status = mVal.Status 297 editUserList[i].Status = mVal.Status
296 editUserList[i].CompanyId = mVal.CompanyId 298 editUserList[i].CompanyId = mVal.CompanyId
  299 + editUserList[i].EntryTime = mVal.EntryTime
297 editUserList[i].UpdatedAt = nowTime 300 editUserList[i].UpdatedAt = nowTime
298 _, err = userRepo.Update(editUserList[i]) 301 _, err = userRepo.Update(editUserList[i])
299 if err != nil { 302 if err != nil {
@@ -312,6 +315,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro @@ -312,6 +315,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
312 AdminType: param.AddUsers[i].AdminType, 315 AdminType: param.AddUsers[i].AdminType,
313 Name: param.AddUsers[i].Name, 316 Name: param.AddUsers[i].Name,
314 Status: param.AddUsers[i].Status, 317 Status: param.AddUsers[i].Status,
  318 + EntryTime: param.AddUsers[i].EntryTime,
315 UpdatedAt: nowTime, 319 UpdatedAt: nowTime,
316 DeletedAt: nil, 320 DeletedAt: nil,
317 CreatedAt: nowTime, 321 CreatedAt: nowTime,
  1 +package user
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/utils/tool_funs"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
  8 +)
  9 +
  10 +type UserService struct{}
  11 +
  12 +func (service *UserService) ListUsers(listUserQuery *query.ListUserQuery) (interface{}, error) {
  13 + transactionContext, err := factory.CreateTransactionContext(nil)
  14 + if err != nil {
  15 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  16 + }
  17 + if err := transactionContext.StartTransaction(); err != nil {
  18 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  19 + }
  20 + defer func() {
  21 + _ = transactionContext.RollbackTransaction()
  22 + }()
  23 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  24 + "transactionContext": transactionContext,
  25 + })
  26 + count, list, err := userRepo.Find(map[string]interface{}{
  27 + "companyId": listUserQuery.CompanyId,
  28 + "name": listUserQuery.Name,
  29 + })
  30 + if err != nil {
  31 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  32 + }
  33 + if err := transactionContext.CommitTransaction(); err != nil {
  34 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  35 + }
  36 + return tool_funs.SimpleWrapGridMap(int64(count), list), nil
  37 +}
@@ -3,19 +3,20 @@ package domain @@ -3,19 +3,20 @@ package domain
3 import "time" 3 import "time"
4 4
5 type User struct { 5 type User struct {
6 - Id int64 // 用户Id  
7 - Account string // 用户账号  
8 - AvatarUrl string // 用户头像URL  
9 - CompanyId int64 // 公司编号  
10 - AdminType int // 1普通员工 2 主管理员  
11 - Name string // 用户姓名  
12 - Email string // 邮箱  
13 - Status int // 用户状态(1正常 2禁用)  
14 - DepartmentId []int // 用户归属的部门  
15 - PositionId []int //用户职位  
16 - UpdatedAt time.Time // 更新时间  
17 - DeletedAt *time.Time  
18 - CreatedAt time.Time 6 + Id int64 `json:"id"` // 用户Id
  7 + Account string `json:"account"` // 用户账号
  8 + AvatarUrl string `json:"avatarUrl"` // 用户头像URL
  9 + CompanyId int64 `json:"companyId"` // 公司编号
  10 + AdminType int `json:"adminType"` // 1普通员工 2 主管理员
  11 + Name string `json:"name"` // 用户姓名
  12 + Email string `json:"email"` // 邮箱
  13 + Status int `json:"status"` // 用户状态(1正常 2禁用)
  14 + DepartmentId []int `json:"departmentId"` // 用户归属的部门
  15 + PositionId []int `json:"PositionId"` //用户职位
  16 + EntryTime string `json:"entryTime"` //入职日期
  17 + UpdatedAt time.Time `json:"updatedAt"` // 更新时间
  18 + DeletedAt *time.Time `json:"deletedAt"`
  19 + CreatedAt time.Time `json:"createdAt"`
19 } 20 }
20 21
21 // 1普通员工 2 主管理员 22 // 1普通员工 2 主管理员
@@ -14,6 +14,7 @@ type User struct { @@ -14,6 +14,7 @@ type User struct {
14 Status int // 用户状态(1正常 2禁用) 14 Status int // 用户状态(1正常 2禁用)
15 DepartmentId []int // 用户归属的部门 15 DepartmentId []int // 用户归属的部门
16 PositionId []int // 用户职位 16 PositionId []int // 用户职位
  17 + EntryTime string //入职日期
17 CreatedAt time.Time // 创建时间 18 CreatedAt time.Time // 创建时间
18 UpdatedAt time.Time // 更新时间 19 UpdatedAt time.Time // 更新时间
19 DeletedAt *time.Time `pg:",soft_delete"` // 删除时间 20 DeletedAt *time.Time `pg:",soft_delete"` // 删除时间
  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/web/beego"
  5 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  8 +)
  9 +
  10 +type UserController struct {
  11 + beego.BaseController
  12 +}
  13 +
  14 +// ListUsers 搜索用户
  15 +func (controller *UserController) ListUsers() {
  16 + listUserQuery := &query.ListUserQuery{}
  17 + _ = controller.Unmarshal(listUserQuery)
  18 + userAuth := controller.Ctx.Input.GetData(domain.UserAuth{}).(*domain.UserAuth)
  19 + listUserQuery.CompanyId = userAuth.CompanyId
  20 + resp, err := (&user.UserService{}).ListUsers(listUserQuery)
  21 + controller.Response(resp, err)
  22 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "github.com/linmadan/egglib-go/web/beego/filters"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
  8 +)
  9 +
  10 +func init() {
  11 + ns := web.NewNamespace("/v1/users",
  12 + web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
  13 + web.NSRouter("/search", &controllers.UserController{}, "Post:ListUsers"),
  14 + )
  15 + web.AddNamespace(ns)
  16 +}