作者 郑周

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

不能预览此文件类型
... ... @@ -142,6 +142,8 @@ func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmen
}
if len(param.ChargeUserIds) > 0 {
departmentList[i].ChargeUserIds = param.ChargeUserIds
} else {
departmentList[i].ChargeUserIds = make([]int64, 0)
}
continue
}
... ...
... ... @@ -8,6 +8,7 @@ type SaveUserCommand struct {
AdminType int `json:"admin_type"` // 1普通员工 2 主管理员
Name string `json:"name"` // 用户姓名
Status int `json:"status"` // 用户状态(1正常 2禁用)
EntryTime string `json:"entryTime"` //入职日期
Email string `json:"email"` // 邮箱
UserDepartments []struct {
DepartmentId int `json:"department_id" `
... ...
package query
type ListUserQuery struct {
CompanyId int64 `json:"companyId"` // 公司ID
Name string `json:"name"` // 用户姓名
}
... ...
... ... @@ -102,6 +102,7 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
Name: param.Name,
Email: param.Email,
Status: param.Status,
EntryTime: param.EntryTime,
UpdatedAt: nowTime,
CreatedAt: nowTime,
}
... ... @@ -160,6 +161,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error
newUser.AdminType = param.AdminType
newUser.Name = param.Name
newUser.Status = param.Status
newUser.EntryTime = param.EntryTime
newUser.PositionId = param.PositionIds()
newUser.DepartmentId = param.DepartmentIds()
... ... @@ -294,6 +296,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
editUserList[i].Name = mVal.Name
editUserList[i].Status = mVal.Status
editUserList[i].CompanyId = mVal.CompanyId
editUserList[i].EntryTime = mVal.EntryTime
editUserList[i].UpdatedAt = nowTime
_, err = userRepo.Update(editUserList[i])
if err != nil {
... ... @@ -312,6 +315,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
AdminType: param.AddUsers[i].AdminType,
Name: param.AddUsers[i].Name,
Status: param.AddUsers[i].Status,
EntryTime: param.AddUsers[i].EntryTime,
UpdatedAt: nowTime,
DeletedAt: nil,
CreatedAt: nowTime,
... ...
package user
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
)
type UserService struct{}
func (service *UserService) ListUsers(listUserQuery *query.ListUserQuery) (interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
count, list, err := userRepo.Find(map[string]interface{}{
"companyId": listUserQuery.CompanyId,
"name": listUserQuery.Name,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(count), list), nil
}
... ...
... ... @@ -3,19 +3,20 @@ package domain
import "time"
type User struct {
Id int64 // 用户Id
Account string // 用户账号
AvatarUrl string // 用户头像URL
CompanyId int64 // 公司编号
AdminType int // 1普通员工 2 主管理员
Name string // 用户姓名
Email string // 邮箱
Status int // 用户状态(1正常 2禁用)
DepartmentId []int // 用户归属的部门
PositionId []int //用户职位
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time
CreatedAt time.Time
Id int64 `json:"id"` // 用户Id
Account string `json:"account"` // 用户账号
AvatarUrl string `json:"avatarUrl"` // 用户头像URL
CompanyId int64 `json:"companyId"` // 公司编号
AdminType int `json:"adminType"` // 1普通员工 2 主管理员
Name string `json:"name"` // 用户姓名
Email string `json:"email"` // 邮箱
Status int `json:"status"` // 用户状态(1正常 2禁用)
DepartmentId []int `json:"departmentId"` // 用户归属的部门
PositionId []int `json:"PositionId"` //用户职位
EntryTime string `json:"entryTime"` //入职日期
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
DeletedAt *time.Time `json:"deletedAt"`
CreatedAt time.Time `json:"createdAt"`
}
// 1普通员工 2 主管理员
... ...
... ... @@ -14,6 +14,7 @@ type User struct {
Status int // 用户状态(1正常 2禁用)
DepartmentId []int // 用户归属的部门
PositionId []int // 用户职位
EntryTime string //入职日期
CreatedAt time.Time // 创建时间
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time `pg:",soft_delete"` // 删除时间
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type UserController struct {
beego.BaseController
}
// ListUsers 搜索用户
func (controller *UserController) ListUsers() {
listUserQuery := &query.ListUserQuery{}
_ = controller.Unmarshal(listUserQuery)
userAuth := controller.Ctx.Input.GetData(domain.UserAuth{}).(*domain.UserAuth)
listUserQuery.CompanyId = userAuth.CompanyId
resp, err := (&user.UserService{}).ListUsers(listUserQuery)
controller.Response(resp, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/users",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/search", &controllers.UserController{}, "Post:ListUsers"),
)
web.AddNamespace(ns)
}
... ...