作者 郑周

Merge branch 'dev-zhengzhou' into test

@@ -27,7 +27,7 @@ func main() { @@ -27,7 +27,7 @@ func main() {
27 func startNodeTask() { 27 func startNodeTask() {
28 go func() { 28 go func() {
29 nodeTaskService := serviceTask.NewNodeTaskService() 29 nodeTaskService := serviceTask.NewNodeTaskService()
30 - for { 30 +
31 var duration time.Duration 31 var duration time.Duration
32 if constant.Env == "prd" { 32 if constant.Env == "prd" {
33 duration = time.Minute * 5 33 duration = time.Minute * 5
@@ -35,10 +35,12 @@ func startNodeTask() { @@ -35,10 +35,12 @@ func startNodeTask() {
35 duration = time.Minute * 1 35 duration = time.Minute * 1
36 } 36 }
37 timer := time.NewTimer(duration) 37 timer := time.NewTimer(duration)
  38 + for {
38 <-timer.C 39 <-timer.C
39 if err := nodeTaskService.SendEvaluationNode(); err != nil { 40 if err := nodeTaskService.SendEvaluationNode(); err != nil {
40 log.Logger.Error(err.Error()) 41 log.Logger.Error(err.Error())
41 } 42 }
  43 + timer.Reset(duration) // 重置定时
42 } 44 }
43 }() 45 }()
44 } 46 }
@@ -31,3 +31,20 @@ func TestFontToken(t *testing.T) { @@ -31,3 +31,20 @@ func TestFontToken(t *testing.T) {
31 } 31 }
32 fmt.Println(userAuth.CreateAccessToken()) 32 fmt.Println(userAuth.CreateAccessToken())
33 } 33 }
  34 +
  35 +func TestOtherAccountToken(t *testing.T) {
  36 + domain.JWTExpiresSecond = 3600 * 24 * 365
  37 + userAuth := &domain.UserAuth{
  38 + UserId: 3422174102828544,
  39 + CompanyId: 8,
  40 + Phone: "17708397664",
  41 + PlatformId: 28,
  42 + Name: "杨欢",
  43 + AdminType: 1,
  44 + }
  45 +
  46 + tk, _ := userAuth.CreateAccessToken()
  47 + t.Log(tk)
  48 +
  49 + //fmt.Println(userAuth.CreateAccessToken())
  50 +}
  1 +package adapter
  2 +
  3 +type DepartmentAdapter struct {
  4 + Id int64 `comment:"部门ID" json:"id"`
  5 + Name string `comment:"部门名称" json:"name"`
  6 + CompanyId int64 `comment:"公司ID" json:"companyId"`
  7 + ParentId int64 `comment:"父级ID" json:"parentId"`
  8 + Departments []*DepartmentAdapter `comment:"子部门" json:"departments"`
  9 + UserTotal int `comment:"部门用户总数量(包含子部门)" json:"userTotal"`
  10 +}
  1 +package command
  2 +
  3 +import "github.com/beego/beego/v2/core/validation"
  4 +
  5 +// QueryDepartmentCommand 查询公司的所有部门和人数
  6 +type QueryDepartmentCommand struct {
  7 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  8 +}
  9 +
  10 +func (in *QueryDepartmentCommand) Valid(*validation.Validation) {
  11 +
  12 +}
  1 +package department
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/department/adapter"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/department/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  8 +)
  9 +
  10 +type SDepartmentService struct{}
  11 +
  12 +func NewDepartmentService() *SDepartmentService {
  13 + newService := &SDepartmentService{}
  14 + return newService
  15 +}
  16 +
  17 +func (ds *SDepartmentService) ListAndCount(in *command.QueryDepartmentCommand) (interface{}, error) {
  18 + transactionContext, err := factory.ValidateStartTransaction(in)
  19 + if err != nil {
  20 + return nil, err
  21 + }
  22 + defer func() {
  23 + transactionContext.RollbackTransaction()
  24 + }()
  25 + departmentRepository := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
  26 + userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  27 + companyRepository := factory.CreateCompanyRepository(map[string]interface{}{"transactionContext": transactionContext})
  28 +
  29 + departments, err := departmentRepository.FindAll(in.CompanyId)
  30 + if err != nil {
  31 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  32 + }
  33 +
  34 + adapters := make([]*adapter.DepartmentAdapter, 0)
  35 + mapDep := map[int64]*adapter.DepartmentAdapter{}
  36 + mapDepNum := map[int64]int{}
  37 + // 已经按等级Level升序排序, 1级> 2级> ...
  38 + for i := range departments {
  39 +
  40 + apt := &adapter.DepartmentAdapter{
  41 + Id: departments[i].Id,
  42 + Name: departments[i].Name,
  43 + CompanyId: departments[i].CompanyId,
  44 + ParentId: departments[i].ParentId,
  45 + Departments: make([]*adapter.DepartmentAdapter, 0),
  46 + }
  47 + mapDep[apt.Id] = apt
  48 +
  49 + // 一级节点
  50 + if apt.ParentId == 0 {
  51 + adapters = append(adapters, apt)
  52 + } else {
  53 + // 上级节点若存在,加到上级的子节点
  54 + if parent, ok := mapDep[apt.ParentId]; ok {
  55 + parent.Departments = append(parent.Departments, apt)
  56 + }
  57 + }
  58 +
  59 + // 所有部门ID
  60 + mapDepNum[apt.Id] = 0
  61 + }
  62 +
  63 + // 获取公司信息
  64 + company, err := companyRepository.FindOne(map[string]interface{}{"id": in.CompanyId})
  65 + if err != nil {
  66 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  67 + }
  68 +
  69 + // 获取所有用户
  70 + userCount, users, err := userRepository.Find(map[string]interface{}{"companyId": in.CompanyId})
  71 + if err != nil {
  72 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  73 + }
  74 +
  75 + for i := range users {
  76 + v := users[i]
  77 + // 注.如果用户部门下挂到公司下,顶级公司数量暂时使用所有用户数量(userCount)
  78 + for _, depId := range v.DepartmentId {
  79 + if count, ok := mapDepNum[int64(depId)]; ok {
  80 + mapDepNum[int64(depId)] = count + 1 // 部门数量 + 1
  81 + }
  82 + }
  83 + }
  84 +
  85 + // 计算部门下的用户总数量
  86 + ds.calculateChildTotal(mapDepNum, adapters)
  87 +
  88 + // 创建顶级部门(公司)
  89 + top := make([]*adapter.DepartmentAdapter, 0)
  90 + top = append(top, &adapter.DepartmentAdapter{
  91 + Id: 0,
  92 + Name: company.Name,
  93 + CompanyId: company.Id,
  94 + ParentId: 0,
  95 + Departments: adapters,
  96 + UserTotal: userCount, // 公司下的所有用户
  97 + })
  98 +
  99 + if err := transactionContext.CommitTransaction(); err != nil {
  100 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  101 + }
  102 + return map[string]interface{}{"list": top}, nil
  103 +}
  104 +
  105 +// 计算子部门总量
  106 +func (ds *SDepartmentService) calculateChildTotal(mapDepNum map[int64]int, departments []*adapter.DepartmentAdapter) int {
  107 + var total = 0
  108 + for i := range departments {
  109 + // 子部门总数量
  110 + var childTotal = ds.calculateChildTotal(mapDepNum, departments[i].Departments)
  111 + // 当前部门数量
  112 + if count, ok := mapDepNum[departments[i].Id]; ok {
  113 + childTotal += count
  114 + }
  115 + // 更新部门数量
  116 + departments[i].UserTotal = childTotal
  117 +
  118 + total += childTotal
  119 + }
  120 + return total
  121 +}
@@ -4,3 +4,10 @@ type ListUserQuery struct { @@ -4,3 +4,10 @@ type ListUserQuery struct {
4 CompanyId int64 `json:"companyId"` // 公司ID 4 CompanyId int64 `json:"companyId"` // 公司ID
5 Name string `json:"name"` // 用户姓名 5 Name string `json:"name"` // 用户姓名
6 } 6 }
  7 +
  8 +type ListByDepartmentQuery struct {
  9 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  10 + DepartmentId int64 `cname:"部门ID" json:"departmentId"`
  11 + PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
  12 + PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
  13 +}
@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 10
11 type UserService struct{} 11 type UserService struct{}
12 12
13 -func (service *UserService) ListUsers(listUserQuery *query.ListUserQuery) (interface{}, error) { 13 +func (us *UserService) ListUsers(listUserQuery *query.ListUserQuery) (interface{}, error) {
14 transactionContext, err := factory.CreateTransactionContext(nil) 14 transactionContext, err := factory.CreateTransactionContext(nil)
15 if err != nil { 15 if err != nil {
16 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 16 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -21,9 +21,7 @@ func (service *UserService) ListUsers(listUserQuery *query.ListUserQuery) (inter @@ -21,9 +21,7 @@ func (service *UserService) ListUsers(listUserQuery *query.ListUserQuery) (inter
21 defer func() { 21 defer func() {
22 _ = transactionContext.RollbackTransaction() 22 _ = transactionContext.RollbackTransaction()
23 }() 23 }()
24 - userRepo := factory.CreateUserRepository(map[string]interface{}{  
25 - "transactionContext": transactionContext,  
26 - }) 24 + userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
27 count, list, err := userRepo.Find(map[string]interface{}{ 25 count, list, err := userRepo.Find(map[string]interface{}{
28 "companyId": listUserQuery.CompanyId, 26 "companyId": listUserQuery.CompanyId,
29 "name": listUserQuery.Name, 27 "name": listUserQuery.Name,
@@ -37,3 +35,27 @@ func (service *UserService) ListUsers(listUserQuery *query.ListUserQuery) (inter @@ -37,3 +35,27 @@ func (service *UserService) ListUsers(listUserQuery *query.ListUserQuery) (inter
37 } 35 }
38 return tool_funs.SimpleWrapGridMap(int64(count), list), nil 36 return tool_funs.SimpleWrapGridMap(int64(count), list), nil
39 } 37 }
  38 +
  39 +func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interface{}, error) {
  40 + transactionContext, err := factory.ValidateStartTransaction(in)
  41 + if err != nil {
  42 + return nil, err
  43 + }
  44 + defer func() {
  45 + transactionContext.RollbackTransaction()
  46 + }()
  47 +
  48 + userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  49 + inMap := tool_funs.SimpleStructToMap(in)
  50 + if in.DepartmentId == 0 {
  51 + delete(inMap, "departmentId") // 删除部门ID字段
  52 + }
  53 + count, list, err := userRepo.Find(inMap)
  54 + if err != nil {
  55 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  56 + }
  57 + if err := transactionContext.CommitTransaction(); err != nil {
  58 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  59 + }
  60 + return tool_funs.SimpleWrapGridMap(int64(count), list), nil
  61 +}
@@ -21,4 +21,5 @@ type DepartmentRepository interface { @@ -21,4 +21,5 @@ type DepartmentRepository interface {
21 Remove(ids []int64) error 21 Remove(ids []int64) error
22 FindOne(queryOptions map[string]interface{}) (*Department, error) 22 FindOne(queryOptions map[string]interface{}) (*Department, error)
23 Find(queryOptions map[string]interface{}) (int, []*Department, error) 23 Find(queryOptions map[string]interface{}) (int, []*Department, error)
  24 + FindAll(companyId int64) ([]*Department, error)
24 } 25 }
@@ -12,8 +12,9 @@ type User struct { @@ -12,8 +12,9 @@ type User struct {
12 Email string `json:"email"` // 邮箱 12 Email string `json:"email"` // 邮箱
13 Status int `json:"status"` // 用户状态(1正常 2禁用) 13 Status int `json:"status"` // 用户状态(1正常 2禁用)
14 DepartmentId []int `json:"departmentId"` // 用户归属的部门 14 DepartmentId []int `json:"departmentId"` // 用户归属的部门
15 - PositionId []int `json:"PositionId"` //用户职位  
16 - EntryTime string `json:"entryTime"` //入职日期 15 + PositionId []int `json:"PositionId"` // 用户职位
  16 + EntryTime string `json:"entryTime"` // 入职日期
  17 + ParentId int64 `json:"parentId"` // 上级ID
17 UpdatedAt time.Time `json:"updatedAt"` // 更新时间 18 UpdatedAt time.Time `json:"updatedAt"` // 更新时间
18 DeletedAt *time.Time `json:"deletedAt"` 19 DeletedAt *time.Time `json:"deletedAt"`
19 CreatedAt time.Time `json:"createdAt"` 20 CreatedAt time.Time `json:"createdAt"`
@@ -15,6 +15,7 @@ type User struct { @@ -15,6 +15,7 @@ type User struct {
15 DepartmentId []int // 用户归属的部门 15 DepartmentId []int // 用户归属的部门
16 PositionId []int // 用户职位 16 PositionId []int // 用户职位
17 EntryTime string //入职日期 17 EntryTime string //入职日期
  18 + ParentId int64 `pg:",use_zero"` // 上级ID
18 CreatedAt time.Time // 创建时间 19 CreatedAt time.Time // 创建时间
19 UpdatedAt time.Time // 更新时间 20 UpdatedAt time.Time // 更新时间
20 DeletedAt *time.Time `pg:",soft_delete"` // 删除时间 21 DeletedAt *time.Time `pg:",soft_delete"` // 删除时间
@@ -117,6 +117,27 @@ func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int @@ -117,6 +117,27 @@ func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int
117 return cnt, resultList, nil 117 return cnt, resultList, nil
118 } 118 }
119 119
  120 +func (repo *DepartmentRepository) FindAll(companyId int64) ([]*domain.Department, error) {
  121 + tx := repo.transactionContext.PgTx
  122 + var departmentModels []models.Department
  123 +
  124 + query := tx.Model(&departmentModels).Where("deleted_at isnull") // 不为空
  125 + if companyId > 0 {
  126 + query.Where("company_id=?", companyId)
  127 + }
  128 + query.Order("level ASC") // 按等级升序
  129 + err := query.Select()
  130 + if err != nil {
  131 + return nil, err
  132 + }
  133 + var list []*domain.Department
  134 + for i := range departmentModels {
  135 + result := repo.TransformToCompanyDomain(&departmentModels[i])
  136 + list = append(list, result)
  137 + }
  138 + return list, nil
  139 +}
  140 +
120 func (repo *DepartmentRepository) TransformToCompanyDomain(u *models.Department) *domain.Department { 141 func (repo *DepartmentRepository) TransformToCompanyDomain(u *models.Department) *domain.Department {
121 return &domain.Department{ 142 return &domain.Department{
122 Id: u.Id, 143 Id: u.Id,
@@ -34,6 +34,7 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { @@ -34,6 +34,7 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) {
34 DepartmentId: user.DepartmentId, 34 DepartmentId: user.DepartmentId,
35 PositionId: user.PositionId, 35 PositionId: user.PositionId,
36 EntryTime: user.EntryTime, 36 EntryTime: user.EntryTime,
  37 + ParentId: user.ParentId,
37 CreatedAt: user.CreatedAt, 38 CreatedAt: user.CreatedAt,
38 UpdatedAt: user.UpdatedAt, 39 UpdatedAt: user.UpdatedAt,
39 DeletedAt: user.DeletedAt, 40 DeletedAt: user.DeletedAt,
@@ -60,6 +61,7 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { @@ -60,6 +61,7 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) {
60 DepartmentId: user.DepartmentId, 61 DepartmentId: user.DepartmentId,
61 PositionId: user.PositionId, 62 PositionId: user.PositionId,
62 EntryTime: user.EntryTime, 63 EntryTime: user.EntryTime,
  64 + ParentId: user.ParentId,
63 CreatedAt: user.CreatedAt, 65 CreatedAt: user.CreatedAt,
64 UpdatedAt: user.UpdatedAt, 66 UpdatedAt: user.UpdatedAt,
65 DeletedAt: user.DeletedAt, 67 DeletedAt: user.DeletedAt,
@@ -103,7 +105,7 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai @@ -103,7 +105,7 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai
103 func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*domain.User, error) { 105 func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*domain.User, error) {
104 tx := repo.transactionContext.PgTx 106 tx := repo.transactionContext.PgTx
105 userModel := []models.User{} 107 userModel := []models.User{}
106 - query := tx.Model(&userModel) 108 + query := tx.Model(&userModel).Where("deleted_at isnull")
107 if v, ok := queryOptions["id"]; ok { 109 if v, ok := queryOptions["id"]; ok {
108 query.Where("id=?", v) 110 query.Where("id=?", v)
109 } 111 }
@@ -122,14 +124,27 @@ func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*d @@ -122,14 +124,27 @@ func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*d
122 if v, ok := queryOptions["status"]; ok { 124 if v, ok := queryOptions["status"]; ok {
123 query.Where("status=?", v) 125 query.Where("status=?", v)
124 } 126 }
  127 + if v, ok := queryOptions["departmentId"]; ok {
  128 + query.Where(`department_id @>'[?]'`, v)
  129 + }
125 if v, ok := queryOptions["name"].(string); ok && len(v) > 0 { 130 if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
126 query.Where("name like ?", fmt.Sprintf("%%%v%%", v)) 131 query.Where("name like ?", fmt.Sprintf("%%%v%%", v))
127 } 132 }
128 if v, ok := queryOptions["offset"]; ok { 133 if v, ok := queryOptions["offset"]; ok {
129 - query.Offset(v.(int)) 134 + if value, ok := v.(int); ok {
  135 + query.Offset(value)
  136 + } else if value, ok := v.(int64); ok {
  137 + query.Offset(int(value))
  138 + }
  139 + //query.Offset(v.(int))
130 } 140 }
131 if v, ok := queryOptions["limit"]; ok { 141 if v, ok := queryOptions["limit"]; ok {
132 - query.Limit(v.(int)) 142 + if value, ok := v.(int); ok {
  143 + query.Limit(value)
  144 + } else if value, ok := v.(int64); ok {
  145 + query.Limit(int(value))
  146 + }
  147 + //query.Limit(v.(int))
133 } 148 }
134 cnt, err := query.SelectAndCount() 149 cnt, err := query.SelectAndCount()
135 if err != nil { 150 if err != nil {
@@ -156,6 +171,7 @@ func (repo *UserRepository) TransformToUserDomain(user *models.User) *domain.Use @@ -156,6 +171,7 @@ func (repo *UserRepository) TransformToUserDomain(user *models.User) *domain.Use
156 DepartmentId: user.DepartmentId, 171 DepartmentId: user.DepartmentId,
157 PositionId: user.PositionId, 172 PositionId: user.PositionId,
158 EntryTime: user.EntryTime, 173 EntryTime: user.EntryTime,
  174 + ParentId: user.ParentId,
159 UpdatedAt: user.UpdatedAt, 175 UpdatedAt: user.UpdatedAt,
160 DeletedAt: user.DeletedAt, 176 DeletedAt: user.DeletedAt,
161 CreatedAt: user.CreatedAt, 177 CreatedAt: user.CreatedAt,
  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/web/beego"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/department"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/department/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
  9 +)
  10 +
  11 +type DepartmentController struct {
  12 + beego.BaseController
  13 +}
  14 +
  15 +func (controller *DepartmentController) ListAndCount() {
  16 + dService := department.NewDepartmentService()
  17 +
  18 + in := &command.QueryDepartmentCommand{}
  19 + if err := controller.Unmarshal(in); err != nil {
  20 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  21 + } else {
  22 + ua := middlewares.GetUser(controller.Ctx)
  23 + in.CompanyId = ua.CompanyId
  24 + controller.Response(dService.ListAndCount(in))
  25 + }
  26 +}
@@ -413,6 +413,9 @@ func (c *StaffAssessController) QueryMemberPerformanceIndicator() { @@ -413,6 +413,9 @@ func (c *StaffAssessController) QueryMemberPerformanceIndicator() {
413 if user := middlewares.GetUser(c.Ctx); user != nil { 413 if user := middlewares.GetUser(c.Ctx); user != nil {
414 in.CompanyId = int(user.CompanyId) 414 in.CompanyId = int(user.CompanyId)
415 in.OperatorId = int(user.UserId) 415 in.OperatorId = int(user.UserId)
  416 +
  417 + //in.CompanyId = int(8) // 杨欢测试数据 周期ID=1612638113870385152 公司ID=8 用户ID=3422174102828544
  418 + //in.OperatorId = int(3422174102828544)
416 } 419 }
417 c.Response(srv.QueryMemberPerformanceIndicator(in)) 420 c.Response(srv.QueryMemberPerformanceIndicator(in))
418 } 421 }
1 package controllers 1 package controllers
2 2
3 import ( 3 import (
  4 + "github.com/linmadan/egglib-go/core/application"
4 "github.com/linmadan/egglib-go/web/beego" 5 "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"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
8 ) 10 )
9 11
10 type UserController struct { 12 type UserController struct {
@@ -20,3 +22,14 @@ func (controller *UserController) ListUsers() { @@ -20,3 +22,14 @@ func (controller *UserController) ListUsers() {
20 resp, err := (&user.UserService{}).ListUsers(listUserQuery) 22 resp, err := (&user.UserService{}).ListUsers(listUserQuery)
21 controller.Response(resp, err) 23 controller.Response(resp, err)
22 } 24 }
  25 +
  26 +func (controller *UserController) ListByDepartment() {
  27 + in := &query.ListByDepartmentQuery{}
  28 + if err := controller.Unmarshal(in); err != nil {
  29 + controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
  30 + } else {
  31 + ua := middlewares.GetUser(controller.Ctx)
  32 + in.CompanyId = ua.CompanyId
  33 + controller.Response((&user.UserService{}).ListByDepartment(in))
  34 + }
  35 +}
  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/department",
  12 + web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
  13 + web.NSRouter("/list-count", &controllers.DepartmentController{}, "Post:ListAndCount"),
  14 + )
  15 + web.AddNamespace(ns)
  16 +}
@@ -11,6 +11,7 @@ func init() { @@ -11,6 +11,7 @@ func init() {
11 ns := web.NewNamespace("/v1/users", 11 ns := web.NewNamespace("/v1/users",
12 web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()), 12 web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
13 web.NSRouter("/search", &controllers.UserController{}, "Post:ListUsers"), 13 web.NSRouter("/search", &controllers.UserController{}, "Post:ListUsers"),
  14 + web.NSRouter("/list-dep", &controllers.UserController{}, "Post:ListByDepartment"),
14 ) 15 )
15 web.AddNamespace(ns) 16 web.AddNamespace(ns)
16 } 17 }
  1 +ALTER TABLE "public"."user" ADD COLUMN "parent_id" int8 DEFAULT 0;
  2 +COMMENT ON COLUMN "public"."user"."parent_id" IS '上级ID';