正在显示
11 个修改的文件
包含
98 行增加
和
9 行删除
| @@ -2,11 +2,11 @@ package main | @@ -2,11 +2,11 @@ package main | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "flag" | 4 | "flag" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db" | ||
| 5 | "net/http" | 6 | "net/http" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| 8 | "github.com/zeromicro/go-zero/core/logx" | 9 | "github.com/zeromicro/go-zero/core/logx" |
| 9 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db" | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 11 | 11 | ||
| 12 | "github.com/golang-jwt/jwt/v4/request" | 12 | "github.com/golang-jwt/jwt/v4/request" |
| @@ -53,7 +53,9 @@ func main() { | @@ -53,7 +53,9 @@ func main() { | ||
| 53 | ctx := svc.NewServiceContext(c) | 53 | ctx := svc.NewServiceContext(c) |
| 54 | handler.RegisterHandlers(server, ctx) | 54 | handler.RegisterHandlers(server, ctx) |
| 55 | 55 | ||
| 56 | + if c.Migrate { | ||
| 56 | db.Migrate(ctx.DB) | 57 | db.Migrate(ctx.DB) |
| 58 | + } | ||
| 57 | 59 | ||
| 58 | logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port) | 60 | logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port) |
| 59 | server.Start() | 61 | server.Start() |
| @@ -100,17 +100,20 @@ type( | @@ -100,17 +100,20 @@ type( | ||
| 100 | UserItem { | 100 | UserItem { |
| 101 | Id int64 `json:"id,omitempty"` // 用户ID | 101 | Id int64 `json:"id,omitempty"` // 用户ID |
| 102 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 102 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
| 103 | - DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID | ||
| 104 | - Roles []int64 `json:"roleId,omitempty"` // 角色 | 103 | + CompanyName string `json:"companyName,omitempty"` // 公司名称 |
| 104 | + //DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID | ||
| 105 | + //Roles []int64 `json:"roleId,omitempty"` // 角色 | ||
| 105 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 106 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
| 106 | Name string `json:"name,omitempty"` // 名称 | 107 | Name string `json:"name,omitempty"` // 名称 |
| 107 | Avatar string `json:"avatar,omitempty"` // 头像 | 108 | Avatar string `json:"avatar,omitempty"` // 头像 |
| 108 | Phone string `json:"phone,omitempty"` // 手机号 唯一 | 109 | Phone string `json:"phone,omitempty"` // 手机号 唯一 |
| 109 | Position string `json:"position,omitempty"` // 职位 | 110 | Position string `json:"position,omitempty"` // 职位 |
| 110 | Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 | 111 | Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 |
| 111 | - AuditStatus int `json:"auditStatus,omitempty"` // 审核状态 0:待审核 1:审核通过 2:拒绝 | 112 | + AuditStatus *int `json:"auditStatus,omitempty"` // 审核状态 0:待审核 1:审核通过 2:拒绝 |
| 112 | Follower []int64 `json:"followers,omitempty"` // 关注我的人 (冗余) | 113 | Follower []int64 `json:"followers,omitempty"` // 关注我的人 (冗余) |
| 113 | Following []int64 `json:"following,omitempty"` // 我关注的人 (冗余) | 114 | Following []int64 `json:"following,omitempty"` // 我关注的人 (冗余) |
| 115 | + Departments []int64 `json:"departments,omitempty"` // 所属部门 | ||
| 116 | + AccountFrom string `json:"accountFrom,omitempty"` // 账号来源 后台新增、扫码注册 | ||
| 114 | } | 117 | } |
| 115 | Department struct { | 118 | Department struct { |
| 116 | Id int64 `json:"id,omitempty"` // 部门ID | 119 | Id int64 `json:"id,omitempty"` // 部门ID |
| @@ -12,4 +12,5 @@ type Config struct { | @@ -12,4 +12,5 @@ type Config struct { | ||
| 12 | Redis redis.RedisConf `json:",optional"` | 12 | Redis redis.RedisConf `json:",optional"` |
| 13 | SystemAuth config.Auth | 13 | SystemAuth config.Auth |
| 14 | MiniAuth config.Auth | 14 | MiniAuth config.Auth |
| 15 | + Migrate bool `json:",optional,default=true"` | ||
| 15 | } | 16 | } |
| @@ -3,8 +3,10 @@ package user | @@ -3,8 +3,10 @@ package user | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | "errors" | 5 | "errors" |
| 6 | + "fmt" | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool" | ||
| 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
| 9 | 11 | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| @@ -32,6 +34,7 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | @@ -32,6 +34,7 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | ||
| 32 | conn = l.svcCtx.DefaultDBConn() | 34 | conn = l.svcCtx.DefaultDBConn() |
| 33 | company *domain.Company | 35 | company *domain.Company |
| 34 | user *domain.User | 36 | user *domain.User |
| 37 | + name = fmt.Sprintf("用户%s", tool.Krand(6, tool.KC_RAND_KIND_NUM)) | ||
| 35 | ) | 38 | ) |
| 36 | if company, err = l.svcCtx.CompanyRepository.FindOneByCode(l.ctx, conn, req.Code); err != nil { | 39 | if company, err = l.svcCtx.CompanyRepository.FindOneByCode(l.ctx, conn, req.Code); err != nil { |
| 37 | return nil, xerr.NewErrMsgErr("公司不存在", err) | 40 | return nil, xerr.NewErrMsgErr("公司不存在", err) |
| @@ -52,14 +55,25 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | @@ -52,14 +55,25 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini | ||
| 52 | return nil, xerr.NewErrMsgErr("公司已申请", err) | 55 | return nil, xerr.NewErrMsgErr("公司已申请", err) |
| 53 | } | 56 | } |
| 54 | } | 57 | } |
| 58 | + queryOptions := domain.NewQueryOptions(). | ||
| 59 | + WithOffsetLimit(1, 1). | ||
| 60 | + MustWithKV("phone", req.Phone). | ||
| 61 | + MustWithKV("auditStatus", []int{domain.UserAuditStatusWait, domain.UserAuditStatusPassed}) | ||
| 62 | + if _, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); len(users) >= 1 { | ||
| 63 | + name = users[0].Name | ||
| 64 | + } | ||
| 55 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | 65 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { |
| 56 | user = &domain.User{ | 66 | user = &domain.User{ |
| 57 | CompanyId: company.Id, | 67 | CompanyId: company.Id, |
| 58 | Phone: req.Phone, | 68 | Phone: req.Phone, |
| 69 | + Name: name, | ||
| 70 | + Flag: domain.UserCommon, | ||
| 59 | Enable: domain.UserEnable, | 71 | Enable: domain.UserEnable, |
| 60 | Roles: make([]int64, 0), | 72 | Roles: make([]int64, 0), |
| 61 | Follower: make([]int64, 0), | 73 | Follower: make([]int64, 0), |
| 62 | Following: make([]int64, 0), | 74 | Following: make([]int64, 0), |
| 75 | + AccountFrom: domain.AccountFromQr, | ||
| 76 | + Departments: make([]int64, 0), | ||
| 63 | } | 77 | } |
| 64 | if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil { | 78 | if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil { |
| 65 | return err | 79 | return err |
| @@ -2,8 +2,12 @@ package user | @@ -2,8 +2,12 @@ package user | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "github.com/samber/lo" | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 7 | 11 | ||
| 8 | "github.com/zeromicro/go-zero/core/logx" | 12 | "github.com/zeromicro/go-zero/core/logx" |
| 9 | ) | 13 | ) |
| @@ -23,5 +27,39 @@ func NewMiniUserAuditListLogic(ctx context.Context, svcCtx *svc.ServiceContext) | @@ -23,5 +27,39 @@ func NewMiniUserAuditListLogic(ctx context.Context, svcCtx *svc.ServiceContext) | ||
| 23 | } | 27 | } |
| 24 | 28 | ||
| 25 | func (l *MiniUserAuditListLogic) MiniUserAuditList(req *types.UserSearchRequest) (resp *types.UserSearchResponse, err error) { | 29 | func (l *MiniUserAuditListLogic) MiniUserAuditList(req *types.UserSearchRequest) (resp *types.UserSearchResponse, err error) { |
| 30 | + var ( | ||
| 31 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 32 | + users []*domain.User | ||
| 33 | + conn = l.svcCtx.DefaultDBConn() | ||
| 34 | + total int64 | ||
| 35 | + companyMap = make(map[int64]*domain.Company) | ||
| 36 | + ) | ||
| 37 | + queryOptions := domain.NewQueryOptions(). | ||
| 38 | + WithOffsetLimit(req.Page, req.Size). | ||
| 39 | + MustWithKV("companyId", userToken.CompanyId) | ||
| 40 | + if req.AuditFlag != nil && *req.AuditFlag >= 0 { | ||
| 41 | + queryOptions.MustWithKV("auditStatus", []int{*req.AuditFlag}) | ||
| 42 | + } | ||
| 43 | + if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil { | ||
| 44 | + return nil, xerr.NewErrMsgErr("查询审核列表失败", err) | ||
| 45 | + } | ||
| 46 | + resp = &types.UserSearchResponse{Total: total} | ||
| 47 | + lo.ForEach(users, func(item *domain.User, index int) { | ||
| 48 | + company, _ := domain.LazyLoad(companyMap, l.ctx, conn, item.CompanyId, l.svcCtx.CompanyRepository.FindOne) | ||
| 49 | + resp.List = append(resp.List, NewUserItemSimple(item, company)) | ||
| 50 | + }) | ||
| 51 | + | ||
| 26 | return | 52 | return |
| 27 | } | 53 | } |
| 54 | + | ||
| 55 | +func NewUserItemSimple(user *domain.User, company *domain.Company) *types.UserItem { | ||
| 56 | + return &types.UserItem{ | ||
| 57 | + Id: user.Id, | ||
| 58 | + Name: user.Name, | ||
| 59 | + CompanyName: lo.Ternary(company != nil, company.Name, ""), | ||
| 60 | + Avatar: user.Avatar, | ||
| 61 | + Phone: user.Phone, | ||
| 62 | + Position: user.Position, | ||
| 63 | + AuditStatus: &user.AuditStatus, | ||
| 64 | + } | ||
| 65 | +} |
| @@ -179,17 +179,18 @@ type MiniUserDepartmentUsersResponse struct { | @@ -179,17 +179,18 @@ type MiniUserDepartmentUsersResponse struct { | ||
| 179 | type UserItem struct { | 179 | type UserItem struct { |
| 180 | Id int64 `json:"id,omitempty"` // 用户ID | 180 | Id int64 `json:"id,omitempty"` // 用户ID |
| 181 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 181 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
| 182 | - DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID | ||
| 183 | - Roles []int64 `json:"roleId,omitempty"` // 角色 | 182 | + CompanyName string `json:"companyName,omitempty"` // 公司名称 |
| 184 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 183 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
| 185 | Name string `json:"name,omitempty"` // 名称 | 184 | Name string `json:"name,omitempty"` // 名称 |
| 186 | Avatar string `json:"avatar,omitempty"` // 头像 | 185 | Avatar string `json:"avatar,omitempty"` // 头像 |
| 187 | Phone string `json:"phone,omitempty"` // 手机号 唯一 | 186 | Phone string `json:"phone,omitempty"` // 手机号 唯一 |
| 188 | Position string `json:"position,omitempty"` // 职位 | 187 | Position string `json:"position,omitempty"` // 职位 |
| 189 | Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 | 188 | Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 |
| 190 | - AuditStatus int `json:"auditStatus,omitempty"` // 审核状态 0:待审核 1:审核通过 2:拒绝 | 189 | + AuditStatus *int `json:"auditStatus,omitempty"` // 审核状态 0:待审核 1:审核通过 2:拒绝 |
| 191 | Follower []int64 `json:"followers,omitempty"` // 关注我的人 (冗余) | 190 | Follower []int64 `json:"followers,omitempty"` // 关注我的人 (冗余) |
| 192 | Following []int64 `json:"following,omitempty"` // 我关注的人 (冗余) | 191 | Following []int64 `json:"following,omitempty"` // 我关注的人 (冗余) |
| 192 | + Departments []int64 `json:"departments,omitempty"` // 所属部门 | ||
| 193 | + AccountFrom string `json:"accountFrom,omitempty"` // 账号来源 后台新增、扫码注册 | ||
| 193 | } | 194 | } |
| 194 | 195 | ||
| 195 | type Department struct { | 196 | type Department struct { |
| @@ -11,7 +11,6 @@ import ( | @@ -11,7 +11,6 @@ import ( | ||
| 11 | type User struct { | 11 | type User struct { |
| 12 | Id int64 // 唯一标识 | 12 | Id int64 // 唯一标识 |
| 13 | CompanyId int64 // 公司ID | 13 | CompanyId int64 // 公司ID |
| 14 | - DepartmentId int64 // 部门ID | ||
| 15 | Roles []int64 `gorm:"type:jsonb;serializer:json"` // 角色 | 14 | Roles []int64 `gorm:"type:jsonb;serializer:json"` // 角色 |
| 16 | Flag int // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 15 | Flag int // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
| 17 | Name string // 名称 | 16 | Name string // 名称 |
| @@ -22,6 +21,8 @@ type User struct { | @@ -22,6 +21,8 @@ type User struct { | ||
| 22 | AuditStatus int // 审核状态 0:待审核 1:审核通过 2:拒绝 | 21 | AuditStatus int // 审核状态 0:待审核 1:审核通过 2:拒绝 |
| 23 | Follower []int64 `gorm:"type:jsonb;serializer:json"` // 关注我的人 (冗余) | 22 | Follower []int64 `gorm:"type:jsonb;serializer:json"` // 关注我的人 (冗余) |
| 24 | Following []int64 `gorm:"type:jsonb;serializer:json"` // 我关注的人 (冗余) | 23 | Following []int64 `gorm:"type:jsonb;serializer:json"` // 我关注的人 (冗余) |
| 24 | + Departments []int64 `gorm:"type:jsonb;serializer:json"` // 所属部门 | ||
| 25 | + AccountFrom string // 账号来源 后台新增、扫码注册 | ||
| 25 | 26 | ||
| 26 | CreatedAt int64 | 27 | CreatedAt int64 |
| 27 | UpdatedAt int64 | 28 | UpdatedAt int64 |
| @@ -142,6 +142,9 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con | @@ -142,6 +142,9 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con | ||
| 142 | ) | 142 | ) |
| 143 | queryFunc := func() (interface{}, error) { | 143 | queryFunc := func() (interface{}, error) { |
| 144 | tx = tx.Model(&ms).Order("id desc") | 144 | tx = tx.Model(&ms).Order("id desc") |
| 145 | + if v, ok := queryOptions["companyId"]; ok { | ||
| 146 | + tx.Where("company_id = ?", v) | ||
| 147 | + } | ||
| 145 | if v, ok := queryOptions["phone"]; ok { | 148 | if v, ok := queryOptions["phone"]; ok { |
| 146 | tx.Where("phone = ?", v) | 149 | tx.Where("phone = ?", v) |
| 147 | } | 150 | } |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "context" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
| 4 | "reflect" | 6 | "reflect" |
| 5 | ) | 7 | ) |
| 6 | 8 | ||
| @@ -62,3 +64,15 @@ func (options QueryOptions) WithFindOnly() QueryOptions { | @@ -62,3 +64,15 @@ func (options QueryOptions) WithFindOnly() QueryOptions { | ||
| 62 | options["findOnly"] = true | 64 | options["findOnly"] = true |
| 63 | return options | 65 | return options |
| 64 | } | 66 | } |
| 67 | + | ||
| 68 | +func LazyLoad[K comparable, T any](source map[K]T, ctx context.Context, conn transaction.Conn, k K, load func(context.Context, transaction.Conn, K) (T, error)) (T, error) { | ||
| 69 | + if v, ok := source[k]; ok { | ||
| 70 | + return v, nil | ||
| 71 | + } | ||
| 72 | + if v, err := load(ctx, conn, k); err != nil { | ||
| 73 | + return v, err | ||
| 74 | + } else { | ||
| 75 | + source[k] = v | ||
| 76 | + return v, nil | ||
| 77 | + } | ||
| 78 | +} |
| @@ -21,7 +21,8 @@ type User struct { | @@ -21,7 +21,8 @@ type User struct { | ||
| 21 | AuditStatus int `json:"auditStatus,omitempty"` // 审核状态 0:待审核 1:审核通过 2:拒绝 | 21 | AuditStatus int `json:"auditStatus,omitempty"` // 审核状态 0:待审核 1:审核通过 2:拒绝 |
| 22 | Follower []int64 `json:"followers,omitempty"` // 关注我的人 (冗余) | 22 | Follower []int64 `json:"followers,omitempty"` // 关注我的人 (冗余) |
| 23 | Following []int64 `json:"following,omitempty"` // 我关注的人 (冗余) | 23 | Following []int64 `json:"following,omitempty"` // 我关注的人 (冗余) |
| 24 | - | 24 | + Departments []int64 `json:"departments,omitempty"` // 所属部门 |
| 25 | + AccountFrom string `json:"accountFrom,omitempty"` // 账号来源 后台新增、扫码注册 | ||
| 25 | CreatedAt int64 `json:"createdAt,omitempty"` | 26 | CreatedAt int64 `json:"createdAt,omitempty"` |
| 26 | UpdatedAt int64 `json:"updatedAt,omitempty"` | 27 | UpdatedAt int64 `json:"updatedAt,omitempty"` |
| 27 | DeletedAt int64 `json:"deletedAt,omitempty"` | 28 | DeletedAt int64 `json:"deletedAt,omitempty"` |
| @@ -63,6 +64,16 @@ const ( | @@ -63,6 +64,16 @@ const ( | ||
| 63 | UserDisable = 2 | 64 | UserDisable = 2 |
| 64 | ) | 65 | ) |
| 65 | 66 | ||
| 67 | +const ( | ||
| 68 | + AccountFromQr = "扫码注册" | ||
| 69 | + AccountFromMr = "后台新增" | ||
| 70 | +) | ||
| 71 | + | ||
| 72 | +const ( | ||
| 73 | + UserAdmin = 1 | ||
| 74 | + UserCommon = 2 | ||
| 75 | +) | ||
| 76 | + | ||
| 66 | func (m *User) Audit(status int) error { | 77 | func (m *User) Audit(status int) error { |
| 67 | if !lo.Contains([]int{UserAuditStatusWait, UserAuditStatusPassed, UserAuditStatusReject}, status) { | 78 | if !lo.Contains([]int{UserAuditStatusWait, UserAuditStatusPassed, UserAuditStatusReject}, status) { |
| 68 | return fmt.Errorf("unknown status:%d", status) | 79 | return fmt.Errorf("unknown status:%d", status) |
-
请 注册 或 登录 后发表评论