作者 tangxvhui
正在显示 31 个修改的文件 包含 1813 行增加26 行删除
... ... @@ -669,6 +669,148 @@
]
}
},
"v1/system/account": {
"post": {
"summary": "系统新增账号",
"operationId": "systemUserAccountSave",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserAccountSaveResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemUserAccountSaveRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/system/account/enable": {
"post": {
"summary": "系统启用/禁用账号",
"operationId": "systemUserAccountEnable",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserAccountEnableResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemUserAccountEnableRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/system/account/search": {
"post": {
"summary": "系统搜索账号",
"operationId": "systemUserAccountSearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserAccountSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemUserAccountSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/system/account/{id}": {
"get": {
"summary": "系统账号详情",
"operationId": "systemUserAccountGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserAccountGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"user"
]
},
"put": {
"summary": "系统更新账号",
"operationId": "systemUserAccountUpdate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserAccountUpdateResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemUserAccountUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/system/article/search": {
"post": {
"summary": "管理后台获取文章列表",
... ... @@ -1078,6 +1220,120 @@
]
}
},
"v1/system/user/search": {
"post": {
"summary": "搜索用户",
"operationId": "systemUserSearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemUserSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/system/user/statistics": {
"post": {
"summary": "用户统计",
"operationId": "systemUserStatistics",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/UserStatisticsResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UserStatisticsRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/system/user/{id}": {
"get": {
"summary": "用户详情",
"operationId": "systemUserGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"user"
]
},
"put": {
"summary": "更新用户",
"operationId": "systemUserUpdate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SystemUserUpdateResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SystemUserUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/user/mylike": {
"post": {
"summary": "我点赞的文章或评论",
... ... @@ -2810,6 +3066,26 @@
"position"
]
},
"StatisticsItem": {
"type": "object",
"properties": {
"itemFlag": {
"type": "integer",
"format": "int32",
"description": " 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳"
},
"value": {
"type": "number",
"format": "double",
"description": " 统计值"
}
},
"title": "StatisticsItem",
"required": [
"itemFlag",
"value"
]
},
"SystemArticleGetRequest": {
"type": "object",
"properties": {
... ... @@ -3055,32 +3331,308 @@
"list"
]
},
"SystemUserInfoRequest": {
"type": "object",
"title": "SystemUserInfoRequest"
},
"SystemUserInfoResponse": {
"SystemUser": {
"type": "object",
"properties": {
"userId": {
"id": {
"type": "integer",
"format": "int64"
"format": "int64",
"description": " 用户ID"
},
"userName": {
"type": "string"
"name": {
"type": "string",
"description": " 名称"
},
"avatar": {
"type": "string"
"type": "string",
"description": " 头像"
},
"companyId": {
"type": "integer",
"format": "int64"
"phone": {
"type": "string",
"description": " 手机号 唯一"
},
"companyName": {
"type": "string"
}
},
"title": "SystemUserInfoResponse",
"position": {
"type": "string",
"description": " 职位"
},
"enable": {
"type": "integer",
"format": "int32",
"description": " 启用状态 1:启用 2:禁用"
},
"departments": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 所属部门"
},
"accountFrom": {
"type": "string",
"description": " 账号来源 后台新增、扫码注册"
},
"createdAt": {
"type": "integer",
"format": "int64",
"description": " 注册时间"
},
"roles": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 角色"
},
"rolesDesc": {
"type": "string",
"description": " 角色描述"
},
"departmentsDesc": {
"type": "string",
"description": " 部门描述"
}
},
"title": "SystemUser",
"required": [
"id",
"name",
"avatar",
"phone",
"position",
"enable",
"departments",
"accountFrom",
"createdAt",
"roles",
"rolesDesc",
"departmentsDesc"
]
},
"SystemUserAccountEnableRequest": {
"type": "object",
"properties": {
"userIds": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 用户ID列表"
},
"status": {
"type": "integer",
"format": "int32",
"description": " 状态 1:启用 2:禁用"
}
},
"title": "SystemUserAccountEnableRequest",
"required": [
"userIds",
"status"
]
},
"SystemUserAccountEnableResponse": {
"type": "object",
"title": "SystemUserAccountEnableResponse"
},
"SystemUserAccountGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "SystemUserAccountGetRequest",
"required": [
"id"
]
},
"SystemUserAccountGetResponse": {
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/SystemUser"
}
},
"title": "SystemUserAccountGetResponse",
"required": [
"user"
]
},
"SystemUserAccountSaveRequest": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": " 名称"
},
"phone": {
"type": "string",
"description": " 手机号 唯一"
},
"enable": {
"type": "integer",
"format": "int32",
"description": " 启用状态 1:启用 2:禁用"
},
"roles": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 角色"
}
},
"title": "SystemUserAccountSaveRequest",
"required": [
"name",
"phone",
"enable",
"roles"
]
},
"SystemUserAccountSaveResponse": {
"type": "object",
"title": "SystemUserAccountSaveResponse"
},
"SystemUserAccountSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string",
"description": " 名称"
},
"phone": {
"type": "string",
"description": " 手机号 唯一"
},
"roleId": {
"type": "integer",
"format": "int64",
"description": " 角色权限"
},
"enable": {
"type": "integer",
"format": "int32",
"description": " 启用状态 1:启用 2:禁用"
},
"beginTime": {
"type": "integer",
"format": "int64",
"description": " 注册日期-开始"
},
"endTime": {
"type": "integer",
"format": "int64",
"description": " 注册日期-结束"
}
},
"title": "SystemUserAccountSearchRequest",
"required": [
"page",
"size"
]
},
"SystemUserAccountSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/SystemUser"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "SystemUserAccountSearchResponse",
"required": [
"list",
"total"
]
},
"SystemUserAccountUpdateRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "SystemUserAccountUpdateRequest",
"required": [
"id"
]
},
"SystemUserAccountUpdateResponse": {
"type": "object",
"title": "SystemUserAccountUpdateResponse"
},
"SystemUserGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "SystemUserGetRequest",
"required": [
"id"
]
},
"SystemUserGetResponse": {
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/SystemUser"
}
},
"title": "SystemUserGetResponse",
"required": [
"user"
]
},
"SystemUserInfoRequest": {
"type": "object",
"title": "SystemUserInfoRequest"
},
"SystemUserInfoResponse": {
"type": "object",
"properties": {
"userId": {
"type": "integer",
"format": "int64"
},
"userName": {
"type": "string"
},
"avatar": {
"type": "string"
},
"companyId": {
"type": "integer",
"format": "int64"
},
"companyName": {
"type": "string"
}
},
"title": "SystemUserInfoResponse",
"required": [
"userId",
"userName",
... ... @@ -3089,6 +3641,101 @@
"companyName"
]
},
"SystemUserSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string",
"description": " 名称"
},
"phone": {
"type": "string",
"description": " 手机号 唯一"
},
"position": {
"type": "string",
"description": " 职位"
},
"enable": {
"type": "integer",
"format": "int32",
"description": " 启用状态 1:启用 2:禁用"
},
"departmentId": {
"type": "integer",
"format": "int64",
"description": " 所属部门"
}
},
"title": "SystemUserSearchRequest",
"required": [
"page",
"size"
]
},
"SystemUserSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/SystemUser"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "SystemUserSearchResponse",
"required": [
"list",
"total"
]
},
"SystemUserUpdateRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"avatar": {
"type": "string",
"description": " 头像"
},
"position": {
"type": "string",
"description": " 职位"
},
"departments": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 所属部门"
}
},
"title": "SystemUserUpdateRequest",
"required": [
"id",
"position",
"departments"
]
},
"SystemUserUpdateResponse": {
"type": "object",
"title": "SystemUserUpdateResponse"
},
"TagCreateRequest": {
"type": "object",
"properties": {
... ... @@ -3548,6 +4195,40 @@
"name"
]
},
"UserStatisticsRequest": {
"type": "object",
"properties": {
"userId": {
"type": "integer",
"format": "int64"
},
"itemFlag": {
"type": "integer",
"format": "int32",
"description": " 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳"
}
},
"title": "UserStatisticsRequest",
"required": [
"userId",
"itemFlag"
]
},
"UserStatisticsResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/StatisticsItem"
}
}
},
"title": "UserStatisticsResponse",
"required": [
"list"
]
},
"WhichUserLikeArticle": {
"type": "object",
"properties": {
... ...
... ... @@ -215,6 +215,36 @@ service Core {
@doc "系统用户信息"
@handler systemUserInfo
post /system/user/info(SystemUserInfoRequest) returns (SystemUserInfoResponse)
@doc "用户统计"
@handler systemUserStatistics
post /system/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
@doc "用户详情"
@handler systemUserGet
get /system/user/:id (SystemUserGetRequest) returns (SystemUserGetResponse)
@doc "更新用户"
@handler systemUserUpdate
put /system/user/:id (SystemUserUpdateRequest) returns (SystemUserUpdateResponse)
@doc "搜索用户"
@handler systemUserSearch
post /system/user/search (SystemUserSearchRequest) returns (SystemUserSearchResponse)
@doc "系统账号详情"
@handler systemUserAccountGet
get /system/account/:id (SystemUserAccountGetRequest) returns (SystemUserAccountGetResponse)
@doc "系统新增账号"
@handler systemUserAccountSave
post /system/account (SystemUserAccountSaveRequest) returns (SystemUserAccountSaveResponse)
@doc "系统启用/禁用账号"
@handler systemUserAccountEnable
post /system/account/enable (SystemUserAccountEnableRequest) returns (SystemUserAccountEnableResponse)
@doc "系统更新账号"
@handler systemUserAccountUpdate
put /system/account/:id (SystemUserAccountUpdateRequest) returns (SystemUserAccountUpdateResponse)
@doc "系统搜索账号"
@handler systemUserAccountSearch
post /system/account/search (SystemUserAccountSearchRequest) returns (SystemUserAccountSearchResponse)
}
type(
... ... @@ -228,4 +258,101 @@ type(
CompanyId int64 `json:"companyId"`
CompanyName string `json:"companyName"`
}
UserStatisticsRequest{
UserId int64 `json:"userId"`
ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
}
UserStatisticsResponse{
List []StatisticsItem `json:"list"`
}
StatisticsItem{
ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
Value float64 `json:"value"` // 统计值
}
SystemUserGetRequest {
Id int64 `path:"id"`
}
SystemUserGetResponse struct{
User SystemUser `json:"user"`
}
SystemUser struct{
Id int64 `json:"id"` // 用户ID
Name string `json:"name"` // 名称
Avatar string `json:"avatar"` // 头像
Phone string `json:"phone"` // 手机号 唯一
Position string `json:"position"` // 职位
Enable int `json:"enable"` // 启用状态 1:启用 2:禁用
Departments []int64 `json:"departments"` // 所属部门
AccountFrom string `json:"accountFrom"` // 账号来源 后台新增、扫码注册
CreatedAt int64 `json:"createdAt"` // 注册时间
Roles []int64 `json:"roles"` // 角色
RolesDesc string `json:"rolesDesc"` // 角色描述
DepartmentsDesc string `json:"departmentsDesc"` // 部门描述
}
SystemUserUpdateRequest struct{
Id int64 `path:"id"`
Avatar string `json:"avatar,optional"` // 头像
Position string `json:"position"` // 职位
Departments []int64 `json:"departments"` // 所属部门
}
SystemUserUpdateResponse struct{}
SystemUserSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
Name string `json:"name,optional"` // 名称
Phone string `json:"phone,optional"` // 手机号 唯一
Position string `json:"position,optional"` // 职位
Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用
DepartmentId int64 `json:"departmentId,optional"` // 所属部门
}
SystemUserSearchResponse{
List []SystemUser `json:"list"`
Total int64 `json:"total"`
}
SystemUserAccountGetRequest {
Id int64 `path:"id"`
}
SystemUserAccountGetResponse struct{
User SystemUser `json:"user"`
}
SystemUserAccountSaveRequest struct{
Name string `json:"name"` // 名称
Phone string `json:"phone"` // 手机号 唯一
Enable int `json:"enable"` // 启用状态 1:启用 2:禁用
Roles []int64 `json:"roles"` // 角色
}
SystemUserAccountSaveResponse struct{
}
SystemUserAccountEnableRequest struct{
UserIds []int64 `json:"userIds"` // 用户ID列表
Status int `json:"status"` // 状态 1:启用 2:禁用
}
SystemUserAccountEnableResponse struct{
}
SystemUserAccountUpdateRequest struct{
Id int64 `path:"id"`
}
SystemUserAccountUpdateResponse struct{}
SystemUserAccountSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
Name string `json:"name,optional"` // 名称
Phone string `json:"phone,optional"` // 手机号 唯一
RoleId int64 `json:"roleId,optional"` // 角色权限
Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用
BeginTime int64 `json:"beginTime,optional"` // 注册日期-开始
EndTime int64 `json:"endTime,optional"` // 注册日期-结束
}
SystemUserAccountSearchResponse{
List []SystemUser `json:"list"`
Total int64 `json:"total"`
}
)
\ No newline at end of file
... ...
... ... @@ -164,6 +164,51 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/system/user/info",
Handler: user.SystemUserInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/user/statistics",
Handler: user.SystemUserStatisticsHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/system/user/:id",
Handler: user.SystemUserGetHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/system/user/:id",
Handler: user.SystemUserUpdateHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/user/search",
Handler: user.SystemUserSearchHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/system/account/:id",
Handler: user.SystemUserAccountGetHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/account",
Handler: user.SystemUserAccountSaveHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/account/enable",
Handler: user.SystemUserAccountEnableHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/system/account/:id",
Handler: user.SystemUserAccountUpdateHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/account/search",
Handler: user.SystemUserAccountSearchHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserAccountEnableHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserAccountEnableRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserAccountEnableLogic(r.Context(), svcCtx)
resp, err := l.SystemUserAccountEnable(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserAccountGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserAccountGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserAccountGetLogic(r.Context(), svcCtx)
resp, err := l.SystemUserAccountGet(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserAccountSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserAccountSaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserAccountSaveLogic(r.Context(), svcCtx)
resp, err := l.SystemUserAccountSave(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserAccountSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserAccountSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserAccountSearchLogic(r.Context(), svcCtx)
resp, err := l.SystemUserAccountSearch(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserAccountUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserAccountUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserAccountUpdateLogic(r.Context(), svcCtx)
resp, err := l.SystemUserAccountUpdate(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserGetLogic(r.Context(), svcCtx)
resp, err := l.SystemUserGet(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func SystemUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewSystemUserInfoLogic(r.Context(), svcCtx)
resp, err := l.SystemUserInfo(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserSearchLogic(r.Context(), svcCtx)
resp, err := l.SystemUserSearch(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserStatisticsRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserStatisticsLogic(r.Context(), svcCtx)
resp, err := l.SystemUserStatistics(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemUserUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemUserUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewSystemUserUpdateLogic(r.Context(), svcCtx)
resp, err := l.SystemUserUpdate(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -75,6 +75,7 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini
AccountFrom: domain.AccountFromQr,
Departments: make([]int64, 0),
}
user.WithName(name)
if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil {
return err
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserAccountEnableLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserAccountEnableLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserAccountEnableLogic {
return &SystemUserAccountEnableLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserAccountEnableLogic) SystemUserAccountEnable(req *types.SystemUserAccountEnableRequest) (resp *types.SystemUserAccountEnableResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
users []*domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if _, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().MustWithKV("ids", req.UserIds).WithFindOnly()); err != nil {
return nil, xerr.NewErrMsgErr("公司不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
for _, user := range users {
if user.Enable == req.Status {
continue
}
user.Enable = req.Status
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
return err
}
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("更新启用状态失败", err)
}
return
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserAccountGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserAccountGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserAccountGetLogic {
return &SystemUserAccountGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserAccountGetLogic) SystemUserAccountGet(req *types.SystemUserAccountGetRequest) (resp *types.SystemUserAccountGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
departments []*domain.Department
roles []*domain.Role
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("公司不存在", err)
}
if userToken.CompanyId != user.CompanyId {
return nil, xerr.NewErrMsgErr("无权限访问改用户", err)
}
if len(user.Departments) > 0 {
_, departments, err = l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().MustWithKV("ids", user.Departments))
if err != nil {
return nil, xerr.NewErrMsgErr("获取账号详情失败", err)
}
}
if len(user.Roles) > 0 {
_, roles, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().MustWithKV("ids", user.Roles))
if err != nil {
return nil, xerr.NewErrMsgErr("获取账号详情失败", err)
}
}
departmentsDesc := domain.Values(departments, func(item *domain.Department) string {
return item.Name
})
rolesDesc := domain.Values(roles, func(item *domain.Role) string {
return item.Name
})
item := NewSystemUser(user)
item.DepartmentsDesc = strings.Join(departmentsDesc, "、")
item.RolesDesc = strings.Join(rolesDesc, "、")
resp = &types.SystemUserAccountGetResponse{
User: item,
}
return
}
func NewSystemUser(item *domain.User) types.SystemUser {
result := types.SystemUser{
Id: item.Id,
Name: item.Name,
Avatar: item.Avatar,
Phone: item.Phone,
Position: item.Position,
Enable: item.Enable,
Departments: item.Departments,
Roles: item.Roles,
AccountFrom: item.AccountFrom,
CreatedAt: item.CreatedAt,
}
return result
}
... ...
package user
import (
"context"
"fmt"
"github.com/pkg/errors"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserAccountSaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserAccountSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserAccountSaveLogic {
return &SystemUserAccountSaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserAccountSaveLogic) SystemUserAccountSave(req *types.SystemUserAccountSaveRequest) (resp *types.SystemUserAccountSaveResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
company *domain.Company
user *domain.User
name = fmt.Sprintf("用户%s", tool.Krand(6, tool.KC_RAND_KIND_NUM))
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if req.Name != "" {
name = req.Name
}
if company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId); err != nil {
return nil, xerr.NewErrMsgErr("公司不存在", err)
}
if user, err = l.svcCtx.UserRepository.FindOneByCompanyIdAndPhone(l.ctx, conn, company.Id, req.Phone, []int{domain.UserAuditStatusWait, domain.UserAuditStatusPassed}); err != nil {
if errors.Is(err, domain.ErrNotFound) {
err = nil
}
}
if err != nil {
return nil, xerr.NewErrMsgErr("申请失败", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
user = &domain.User{
CompanyId: company.Id,
Phone: req.Phone,
Name: name,
Flag: domain.UserCommon,
Enable: req.Enable,
Roles: make([]int64, 0),
Follower: make([]int64, 0),
Following: make([]int64, 0),
AccountFrom: domain.AccountFromMr,
Departments: make([]int64, 0),
AuditStatus: domain.UserAuditStatusPassed,
}
user.WithName(name)
for _, roleId := range req.Roles {
user.AddRole(roleId)
}
if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("添加用户失败", err)
}
resp = &types.SystemUserAccountSaveResponse{}
return
}
... ...
package user
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserAccountSearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserAccountSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserAccountSearchLogic {
return &SystemUserAccountSearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserAccountSearchLogic) SystemUserAccountSearch(req *types.SystemUserAccountSearchRequest) (resp *types.SystemUserAccountSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
users []*domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
total int64
departmentMap = make(map[int64]*domain.Department)
roleMap = make(map[int64]*domain.Role)
)
queryOptions := domain.IndexCompanyId(userToken.CompanyId)().WithOffsetLimit(req.Page, req.Size).WithOrder("id desc").
WithKV("likeName", req.Name).
WithKV("likePhone", req.Phone).
WithKV("roleId", req.RoleId).
WithKV("enable", req.Enable).
WithKV("beginTime", req.BeginTime).
WithKV("endTime", req.EndTime)
if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil {
return nil, xerr.NewErr(err)
}
resp = &types.SystemUserAccountSearchResponse{
Total: total,
List: make([]types.SystemUser, 0),
}
lo.ForEach(users, func(item *domain.User, index int) {
var departments []string
for _, id := range item.Departments {
if department, _ := domain.LazyLoad(departmentMap, l.ctx, conn, id, l.svcCtx.DepartmentRepository.FindOne); department != nil {
departments = append(departments, department.Name)
}
}
var roles []string
for _, id := range item.Roles {
if role, _ := domain.LazyLoad(roleMap, l.ctx, conn, id, l.svcCtx.RoleRepository.FindOne); role != nil {
roles = append(roles, role.Name)
}
}
user := NewSystemUser(item)
user.RolesDesc = strings.Join(roles, "、")
user.DepartmentsDesc = strings.Join(departments, "、")
resp.List = append(resp.List, user)
})
return
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserAccountUpdateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserAccountUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserAccountUpdateLogic {
return &SystemUserAccountUpdateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserAccountUpdateLogic) SystemUserAccountUpdate(req *types.SystemUserAccountUpdateRequest) (resp *types.SystemUserAccountUpdateResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strings"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserGetLogic {
return &SystemUserGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserGetLogic) SystemUserGet(req *types.SystemUserGetRequest) (resp *types.SystemUserGetResponse, err error) {
var (
user *domain.User
conn = l.svcCtx.DefaultDBConn()
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
var roles []*domain.Role
if len(user.Roles) > 0 {
_, roles, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().MustWithKV("ids", user.Roles))
if err != nil {
return nil, xerr.NewErrMsgErr("获取账号详情失败", err)
}
}
rolesDesc := domain.Values(roles, func(item *domain.Role) string {
return item.Name
})
userItem := NewSystemUser(user)
userItem.RolesDesc = strings.Join(rolesDesc, "、")
resp = &types.SystemUserGetResponse{
User: userItem,
}
return
}
... ...
... ... @@ -2,7 +2,6 @@ package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -24,7 +23,6 @@ func NewSystemUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sy
}
func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (resp *types.SystemUserInfoResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package user
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserSearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserSearchLogic {
return &SystemUserSearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserSearchLogic) SystemUserSearch(req *types.SystemUserSearchRequest) (resp *types.SystemUserSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
users []*domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
total int64
roleMap = make(map[int64]*domain.Role)
)
queryOptions := domain.IndexCompanyId(userToken.CompanyId)().WithOffsetLimit(req.Page, req.Size).WithOrder("id desc").
WithKV("likeName", req.Name).
WithKV("likePhone", req.Phone).
WithKV("likePosition", req.Position).
WithKV("enable", req.Enable).
WithKV("departmentId", req.DepartmentId)
if total, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOptions); err != nil {
return nil, xerr.NewErr(err)
}
resp = &types.SystemUserSearchResponse{
Total: total,
List: make([]types.SystemUser, 0),
}
lo.ForEach(users, func(item *domain.User, index int) {
var roles []string
for _, id := range item.Roles {
if role, _ := domain.LazyLoad(roleMap, l.ctx, conn, id, l.svcCtx.RoleRepository.FindOne); role != nil {
roles = append(roles, role.Name)
}
}
user := NewSystemUser(item)
user.RolesDesc = strings.Join(roles, "、")
resp.List = append(resp.List, user)
})
return
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserStatisticsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserStatisticsLogic {
return &SystemUserStatisticsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserStatisticsLogic) SystemUserStatistics(req *types.UserStatisticsRequest) (resp *types.UserStatisticsResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemUserUpdateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUserUpdateLogic {
return &SystemUserUpdateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemUserUpdateLogic) SystemUserUpdate(req *types.SystemUserUpdateRequest) (resp *types.SystemUserUpdateResponse, err error) {
var (
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
user *domain.User
conn = l.svcCtx.DefaultDBConn()
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
if user.CompanyId != userToken.CompanyId {
return nil, xerr.NewErrMsgErr("无权限更改", err)
}
user.Avatar = req.Avatar
user.Position = req.Position
user.Departments = req.Departments
user.WithName(user.Name)
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("更新用户信息失败", err)
}
resp = &types.SystemUserUpdateResponse{}
return
}
... ...
... ... @@ -339,6 +339,117 @@ type SystemUserInfoResponse struct {
CompanyName string `json:"companyName"`
}
type UserStatisticsRequest struct {
UserId int64 `json:"userId"`
ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
}
type UserStatisticsResponse struct {
List []StatisticsItem `json:"list"`
}
type StatisticsItem struct {
ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
Value float64 `json:"value"` // 统计值
}
type SystemUserGetRequest struct {
Id int64 `path:"id"`
}
type SystemUserGetResponse struct {
User SystemUser `json:"user"`
}
type SystemUser struct {
Id int64 `json:"id"` // 用户ID
Name string `json:"name"` // 名称
Avatar string `json:"avatar"` // 头像
Phone string `json:"phone"` // 手机号 唯一
Position string `json:"position"` // 职位
Enable int `json:"enable"` // 启用状态 1:启用 2:禁用
Departments []int64 `json:"departments"` // 所属部门
AccountFrom string `json:"accountFrom"` // 账号来源 后台新增、扫码注册
CreatedAt int64 `json:"createdAt"` // 注册时间
Roles []int64 `json:"roles"` // 角色
RolesDesc string `json:"rolesDesc"` // 角色描述
DepartmentsDesc string `json:"departmentsDesc"` // 部门描述
}
type SystemUserUpdateRequest struct {
Id int64 `path:"id"`
Avatar string `json:"avatar,optional"` // 头像
Position string `json:"position"` // 职位
Departments []int64 `json:"departments"` // 所属部门
}
type SystemUserUpdateResponse struct {
}
type SystemUserSearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
Name string `json:"name,optional"` // 名称
Phone string `json:"phone,optional"` // 手机号 唯一
Position string `json:"position,optional"` // 职位
Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用
DepartmentId int64 `json:"departmentId,optional"` // 所属部门
}
type SystemUserSearchResponse struct {
List []SystemUser `json:"list"`
Total int64 `json:"total"`
}
type SystemUserAccountGetRequest struct {
Id int64 `path:"id"`
}
type SystemUserAccountGetResponse struct {
User SystemUser `json:"user"`
}
type SystemUserAccountSaveRequest struct {
Name string `json:"name"` // 名称
Phone string `json:"phone"` // 手机号 唯一
Enable int `json:"enable"` // 启用状态 1:启用 2:禁用
Roles []int64 `json:"roles"` // 角色
}
type SystemUserAccountSaveResponse struct {
}
type SystemUserAccountEnableRequest struct {
UserIds []int64 `json:"userIds"` // 用户ID列表
Status int `json:"status"` // 状态 1:启用 2:禁用
}
type SystemUserAccountEnableResponse struct {
}
type SystemUserAccountUpdateRequest struct {
Id int64 `path:"id"`
}
type SystemUserAccountUpdateResponse struct {
}
type SystemUserAccountSearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
Name string `json:"name,optional"` // 名称
Phone string `json:"phone,optional"` // 手机号 唯一
RoleId int64 `json:"roleId,optional"` // 角色权限
Enable int `json:"enable,optional"` // 启用状态 1:启用 2:禁用
BeginTime int64 `json:"beginTime,optional"` // 注册日期-开始
EndTime int64 `json:"endTime,optional"` // 注册日期-结束
}
type SystemUserAccountSearchResponse struct {
List []SystemUser `json:"list"`
Total int64 `json:"total"`
}
type CompanySearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
... ...
... ... @@ -14,6 +14,7 @@ type User struct {
Roles []int64 `gorm:"type:jsonb;serializer:json"` // 角色
Flag int // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
Name string // 名称
PinYinName string
Avatar string // 头像
Phone string // 手机号 唯一
Position string // 职位
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -141,7 +142,7 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id asc")
tx = tx.Model(&ms)
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
... ... @@ -154,6 +155,34 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con
if v, ok := queryOptions["auditStatus"]; ok {
tx.Where("audit_status in (?)", v)
}
// 列表查询条件
if v, ok := queryOptions["likeName"]; ok {
tx.Where("name like ? ", fmt.Sprintf("%%%v%%", v))
}
if v, ok := queryOptions["likePhone"]; ok {
tx.Where("phone like ? ", fmt.Sprintf("%%%v%%", v))
}
if v, ok := queryOptions["departmentId"]; ok {
tx.Where(fmt.Sprintf("departments @>'[%v]'", v))
}
if v, ok := queryOptions["roleId"]; ok {
tx.Where(fmt.Sprintf("roles @>'[%v]'", v))
}
if v, ok := queryOptions["enable"]; ok {
tx.Where("enable = ?", v)
}
if v, ok := queryOptions["beginTime"]; ok {
tx.Where("created_at >= ?", v)
}
if v, ok := queryOptions["endTime"]; ok {
tx.Where("created_at < ?", v)
}
if v, ok := queryOptions["orderBy"]; ok {
tx.Order(v)
} else {
tx.Order("id asc")
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -64,6 +64,10 @@ func (options QueryOptions) WithFindOnly() QueryOptions {
options["findOnly"] = true
return options
}
func (options QueryOptions) WithOrder(order string) QueryOptions {
options["orderBy"] = order
return options
}
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) {
if v, ok := source[k]; ok {
... ... @@ -77,6 +81,15 @@ func LazyLoad[K comparable, T any](source map[K]T, ctx context.Context, conn tra
}
}
func Values[T any, V any](list []T, each func(item T) V) []V {
var result []V
for _, item := range list {
value := each(item)
result = append(result, value)
}
return result
}
/*************** 索引函数 ****************/
func IndexCompanyId(companyId int64) IndexQueryOptionFunc {
return func() QueryOptions {
... ...
... ... @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
)
type User struct {
... ... @@ -14,6 +15,7 @@ type User struct {
Roles []int64 `json:"roleId,omitempty"` // 角色
Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
Name string `json:"name,omitempty"` // 名称
PinYinName string `json:"pin_yin_name"` // 拼音名
Avatar string `json:"avatar,omitempty"` // 头像
Phone string `json:"phone,omitempty"` // 手机号 唯一
Position string `json:"position,omitempty"` // 职位
... ... @@ -111,6 +113,7 @@ func (m *User) AddRole(roleId int64) {
return
}
m.Roles = append(m.Roles, roleId)
m.Flag = lo.Ternary(len(m.Roles) > 0, UserAdmin, UserCommon)
}
// RemoveRole 移除角色
... ... @@ -121,6 +124,12 @@ func (m *User) RemoveRole(roleId int64) {
m.Roles = lo.Without(m.Roles, roleId)
}
func (m *User) WithName(name string) *User {
m.Name = name
m.PinYinName = tool.ToPinYin(name, " ")
return m
}
type (
LoginCreator interface {
WechatLogin(r WechatLoginRequest) (*LoginInfo, error)
... ...
... ... @@ -72,6 +72,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mozillazg/go-pinyin v0.20.0 // indirect
github.com/onsi/gomega v1.26.0 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
... ...
package tool
import (
"github.com/mozillazg/go-pinyin"
"strings"
)
func ToPinYin(hans string, sep string) string {
a := pinyin.NewArgs()
tmp := pinyin.Pinyin(hans, a)
result := make([]string, 0)
for i := range tmp {
result = append(result, tmp[i]...)
}
py := strings.Join(result, sep)
if len(py) == 0 {
return strings.ToLower(hans)
}
return py
}
... ...