作者 tangxvhui

Merge branch 'dev' into dev-tangxvhui

正在显示 27 个修改的文件 包含 1372 行增加83 行删除
... ... @@ -33,6 +33,364 @@
]
}
},
"v1/mini/company/search": {
"post": {
"summary": "公司搜索",
"operationId": "miniCompanySearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/CompanySearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/CompanySearchRequest"
}
}
],
"requestBody": {},
"tags": [
"company"
]
}
},
"v1/mini/message/business": {
"post": {
"summary": "业务消息",
"operationId": "miniBusiness",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MessageBusinessResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MessageBusinessRequest"
}
}
],
"requestBody": {},
"tags": [
"message"
]
}
},
"v1/mini/message/system": {
"post": {
"summary": "系统消息",
"operationId": "miniSystem",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MessageBusinessResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MessageSystemRequest"
}
}
],
"requestBody": {},
"tags": [
"message"
]
}
},
"v1/mini/user/apply-join-company": {
"post": {
"summary": "用户申请加入公司",
"operationId": "miniUserApplyJoinCompany",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MiniUserApplyJoinCompanyResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniUserApplyJoinCompanyRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/audit": {
"post": {
"summary": "用户审核",
"operationId": "miniUserAudit",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniUserAuditRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/audit-list": {
"post": {
"summary": "用户审核列表",
"operationId": "miniUserAuditList",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/UserSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UserSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/department-users": {
"post": {
"summary": "部门用户列表",
"operationId": "miniUserDepartmentUsers",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MiniUserInfoResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniUserDepartmentUsersRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/follow": {
"post": {
"summary": "关注",
"operationId": "miniUserFollow",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/FollowRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/follower": {
"post": {
"summary": "关注我的人",
"operationId": "miniUserFollower",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/UserSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UserSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/following": {
"post": {
"summary": "我关注的人",
"operationId": "miniUserFollowing",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/UserSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UserSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/info": {
"post": {
"summary": "用户信息",
"operationId": "miniUserInfo",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MiniUserInfoResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniUserInfoRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/login": {
"post": {
"summary": "用户登录",
"operationId": "miniUserLogin",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MiniUserLoginResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MiniUserLoginRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/mini/user/unfollow": {
"post": {
"summary": "取消关注",
"operationId": "miniUserUnFollow",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/FollowRequest"
}
}
],
"requestBody": {},
"tags": [
"user"
]
}
},
"v1/system/comment": {
"get": {
"summary": "系统评论",
... ... @@ -50,6 +408,34 @@
"comment"
]
}
},
"v1/system/company/search": {
"post": {
"summary": "公司搜索",
"operationId": "systemCompanySearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/CompanySearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/CompanySearchRequest"
}
}
],
"requestBody": {},
"tags": [
"company"
]
}
}
},
"definitions": {
... ... @@ -75,6 +461,651 @@
"required": [
"list"
]
},
"Company": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 唯一标识"
},
"name": {
"type": "string",
"description": " 名称"
},
"code": {
"type": "string",
"description": " 编码(搜索使用,4位字母数字)"
},
"logo": {
"type": "string",
"description": " 公司LOGO"
}
},
"title": "Company",
"required": [
"id",
"name",
"code",
"logo"
]
},
"CompanySearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
},
"userId": {
"type": "integer",
"format": "int64",
"description": " 按用户搜索"
},
"code": {
"type": "string",
"description": " 按编码搜索"
}
},
"title": "CompanySearchRequest",
"required": [
"page",
"size"
]
},
"CompanySearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/Company"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "CompanySearchResponse",
"required": [
"list",
"total"
]
},
"Department": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 部门ID"
},
"companyId": {
"type": "integer",
"format": "int64",
"description": " 公司ID"
},
"parentId": {
"type": "integer",
"format": "int64",
"description": " 父级ID"
},
"name": {
"type": "string",
"description": " 部门名称"
}
},
"title": "Department",
"required": [
"id",
"companyId",
"parentId",
"name"
]
},
"FollowRequest": {
"type": "object",
"properties": {
"userId": {
"type": "integer",
"format": "int64"
}
},
"title": "FollowRequest",
"required": [
"userId"
]
},
"MessageBusinessItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"companyId": {
"type": "integer",
"format": "int64",
"description": " 公司ID"
},
"type": {
"type": "integer",
"format": "int32",
"description": " 分类 (1回复 2点赞 3被采纳)"
},
"optType": {
"type": "integer",
"format": "int32",
"description": " 操作类型(1针对文章、1针对评论、2针对圆桌)"
},
"triggerId": {
"type": "integer",
"format": "int64",
"description": " 触发者ID"
},
"recipientId": {
"type": "integer",
"format": "int64",
"description": " 接收者ID"
},
"articleId": {
"type": "integer",
"format": "int64",
"description": " 文章ID"
},
"commentId": {
"type": "integer",
"format": "int64",
"description": " 评论ID"
},
"discussionId": {
"type": "integer",
"format": "int64",
"description": " 圆桌ID"
},
"discussionOpinionId": {
"type": "integer",
"format": "int64",
"description": " 观点ID"
},
"content": {
"type": "string",
"description": " 消息内容"
},
"createdAt": {
"type": "integer",
"format": "int64",
"description": " 创建时间"
},
"userTrigger": {
"$ref": "#/definitions/User",
"description": " 触发者"
}
},
"title": "MessageBusinessItem",
"required": [
"id",
"companyId",
"type",
"optType",
"triggerId",
"recipientId",
"articleId",
"commentId",
"discussionId",
"discussionOpinionId",
"content",
"createdAt",
"userTrigger"
]
},
"MessageBusinessRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
}
},
"title": "MessageBusinessRequest",
"required": [
"page",
"size"
]
},
"MessageBusinessResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/MessageBusinessItem"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "MessageBusinessResponse",
"required": [
"list",
"total"
]
},
"MessageSystemItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " ID"
},
"type": {
"type": "integer",
"format": "int32",
"description": " 系统分类"
},
"title": {
"type": "string",
"description": " 标题"
},
"content": {
"type": "string",
"description": " 内容"
}
},
"title": "MessageSystemItem",
"required": [
"id",
"type",
"title",
"content"
]
},
"MessageSystemRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
}
},
"title": "MessageSystemRequest",
"required": [
"page",
"size"
]
},
"MessageSystemResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/MessageSystemItem"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "MessageSystemResponse",
"required": [
"list",
"total"
]
},
"MiniUserApplyJoinCompanyRequest": {
"type": "object",
"properties": {
"phone": {
"type": "string"
},
"code": {
"type": "string"
}
},
"title": "MiniUserApplyJoinCompanyRequest",
"required": [
"phone",
"code"
]
},
"MiniUserApplyJoinCompanyResponse": {
"type": "object",
"title": "MiniUserApplyJoinCompanyResponse"
},
"MiniUserAuditRequest": {
"type": "object",
"properties": {
"userId": {
"type": "integer",
"format": "int64",
"description": " 用户ID"
},
"status": {
"type": "integer",
"format": "int32",
"description": " 审核状态 1:审核通过 2:拒绝"
}
},
"title": "MiniUserAuditRequest",
"required": [
"userId",
"status"
]
},
"MiniUserDepartmentUsersRequest": {
"type": "object",
"title": "MiniUserDepartmentUsersRequest"
},
"MiniUserDepartmentUsersResponse": {
"type": "object",
"properties": {
"departments": {
"type": "array",
"items": {
"$ref": "#/definitions/Department"
}
},
"users": {
"type": "array",
"items": {
"$ref": "#/definitions/UserItem"
}
}
},
"title": "MiniUserDepartmentUsersResponse",
"required": [
"departments",
"users"
]
},
"MiniUserInfoRequest": {
"type": "object",
"title": "MiniUserInfoRequest"
},
"MiniUserInfoResponse": {
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/UserItem",
"description": " 用户信息"
},
"totalArticle": {
"type": "integer",
"format": "int64",
"description": " 累计信息发布"
},
"totalLoved": {
"type": "integer",
"format": "int64",
"description": " 累计收到的赞"
},
"totalAccepted": {
"type": "integer",
"format": "int64",
"description": " 累计被采纳"
}
},
"title": "MiniUserInfoResponse",
"required": [
"user",
"totalArticle",
"totalLoved",
"totalAccepted"
]
},
"MiniUserLoginRequest": {
"type": "object",
"properties": {
"loginType": {
"type": "string",
"description": " 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login"
},
"wechatAuthcode": {
"type": "string",
"description": " 微信登录 授权码"
},
"wechatEncryptedData": {
"type": "string",
"description": " 微信登录 加密数据"
},
"wechatIV": {
"type": "string",
"description": " 微信登录 加密算法初始向量"
},
"phone": {
"type": "string",
"description": " 手机号"
},
"password": {
"type": "string",
"description": " 密码"
},
"smsCode": {
"type": "string",
"description": " 短信验证码"
}
},
"title": "MiniUserLoginRequest",
"required": [
"loginType"
]
},
"MiniUserLoginResponse": {
"type": "object",
"properties": {
"token": {
"type": "string",
"description": " x-token"
},
"phone": {
"type": "string",
"description": " 手机号"
},
"message": {
"type": "string",
"description": " 失败消息(审核中,注册成功等待审核)"
},
"success": {
"type": "boolean",
"format": "boolean",
"description": " 成功标识"
}
},
"title": "MiniUserLoginResponse",
"required": [
"token",
"phone",
"message",
"success"
]
},
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"companyId": {
"type": "integer",
"format": "int64",
"description": " 公司ID"
},
"departmentId": {
"type": "integer",
"format": "int64",
"description": " 部门ID"
},
"name": {
"type": "string",
"description": " 名称"
},
"avatar": {
"type": "string",
"description": " 头像"
},
"position": {
"type": "string",
"description": " 职位"
}
},
"title": "User",
"required": [
"id",
"companyId",
"departmentId",
"name",
"avatar",
"position"
]
},
"UserItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 用户ID"
},
"companyId": {
"type": "integer",
"format": "int64",
"description": " 公司ID"
},
"departmentId": {
"type": "integer",
"format": "int64",
"description": " 部门ID"
},
"roleId": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 角色"
},
"flag": {
"type": "integer",
"format": "int32",
"description": " 标识 1:管理员 2:普通用户 (有绑定角色是管理员)"
},
"name": {
"type": "string",
"description": " 名称"
},
"avatar": {
"type": "string",
"description": " 头像"
},
"phone": {
"type": "string",
"description": " 手机号 唯一"
},
"position": {
"type": "string",
"description": " 职位"
},
"enable": {
"type": "integer",
"format": "int32",
"description": " 启用状态 1:启用 2:禁用"
},
"auditStatus": {
"type": "integer",
"format": "int32",
"description": " 审核状态 0:待审核 1:审核通过 2:拒绝"
},
"followers": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 关注我的人 (冗余)"
},
"following": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 我关注的人 (冗余)"
}
},
"title": "UserItem",
"required": [
"id",
"companyId",
"departmentId",
"roleId",
"flag",
"name",
"avatar",
"phone",
"position",
"enable",
"auditStatus",
"followers",
"following"
]
},
"UserSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
},
"auditFlag": {
"$ref": "#/definitions/int",
"description": " 按审核状态 0:待审核 1:审核通过 2:拒绝"
}
},
"title": "UserSearchRequest"
},
"UserSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/UserItem"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "UserSearchResponse",
"required": [
"list",
"total"
]
}
},
"securityDefinitions": {
... ...
... ... @@ -88,6 +88,7 @@ type(
}
MiniUserAuditRequest{
UserId int64 `json:"userId"` // 用户ID
Status int `json:"status"` // 审核状态 1:审核通过 2:拒绝
}
MiniUserDepartmentUsersRequest{
... ... @@ -97,6 +98,7 @@ type(
Users []*UserItem `json:"users"`
}
UserItem {
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
Roles []int64 `json:"roleId,omitempty"` // 角色
... ...
package company
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniCompanySearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := company.NewMiniCompanySearchLogic(r.Context(), svcCtx)
resp, err := l.MiniCompanySearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package company
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func SystemCompanySearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := company.NewSystemCompanySearchLogic(r.Context(), svcCtx)
resp, err := l.SystemCompanySearch(&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"
... ... @@ -19,10 +20,6 @@ func MiniUserApplyJoinCompanyHandler(svcCtx *svc.ServiceContext) http.HandlerFun
l := user.NewMiniUserApplyJoinCompanyLogic(r.Context(), svcCtx)
resp, err := l.MiniUserApplyJoinCompany(&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"
... ... @@ -19,10 +20,6 @@ func MiniUserAuditHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserAuditLogic(r.Context(), svcCtx)
err := l.MiniUserAudit(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
result.HttpResult(r, w, struct{}{}, 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 MiniUserAuditListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserAuditListLogic(r.Context(), svcCtx)
resp, err := l.MiniUserAuditList(&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"
... ... @@ -19,10 +20,6 @@ func MiniUserDepartmentUsersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
l := user.NewMiniUserDepartmentUsersLogic(r.Context(), svcCtx)
resp, err := l.MiniUserDepartmentUsers(&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"
... ... @@ -19,10 +20,6 @@ func MiniUserFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserFollowLogic(r.Context(), svcCtx)
err := l.MiniUserFollow(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
result.HttpResult(r, w, struct{}{}, 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 MiniUserFollowerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserFollowerLogic(r.Context(), svcCtx)
resp, err := l.MiniUserFollower(&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"
... ... @@ -19,10 +20,6 @@ func MiniUserFollowingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserFollowingLogic(r.Context(), svcCtx)
resp, err := l.MiniUserFollowing(&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"
... ... @@ -19,10 +20,6 @@ func MiniUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserInfoLogic(r.Context(), svcCtx)
resp, err := l.MiniUserInfo(&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"
... ... @@ -19,10 +20,6 @@ func MiniUserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserLoginLogic(r.Context(), svcCtx)
resp, err := l.MiniUserLogin(&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"
... ... @@ -19,10 +20,6 @@ func MiniUserUnFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserUnFollowLogic(r.Context(), svcCtx)
err := l.MiniUserUnFollow(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
result.HttpResult(r, w, struct{}{}, err)
}
}
... ...
... ... @@ -2,6 +2,10 @@ package user
import (
"context"
"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/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"
... ... @@ -24,7 +28,46 @@ func NewMiniUserApplyJoinCompanyLogic(ctx context.Context, svcCtx *svc.ServiceCo
}
func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.MiniUserApplyJoinCompanyRequest) (resp *types.MiniUserApplyJoinCompanyResponse, err error) {
// todo: add your logic here and delete this line
var (
conn = l.svcCtx.DefaultDBConn()
company *domain.Company
user *domain.User
)
if company, err = l.svcCtx.CompanyRepository.FindOneByCode(l.ctx, conn, req.Code); 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 user != nil {
if user.AuditStatus == domain.UserAuditStatusWait {
return nil, xerr.NewErrMsgErr("已申请,待审核中", err)
}
if user.AuditStatus == domain.UserAuditStatusPassed {
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,
Enable: domain.UserEnable,
Roles: make([]int64, 0),
Follower: make([]int64, 0),
Following: make([]int64, 0),
}
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.MiniUserApplyJoinCompanyResponse{}
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,5 @@ func NewMiniUserAuditListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *MiniUserAuditListLogic) MiniUserAuditList(req *types.UserSearchRequest) (resp *types.UserSearchResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -2,6 +2,9 @@ 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/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"
... ... @@ -23,8 +26,24 @@ func NewMiniUserAuditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Min
}
}
func (l *MiniUserAuditLogic) MiniUserAudit(req *types.MiniUserAuditRequest) error {
// todo: add your logic here and delete this line
func (l *MiniUserAuditLogic) MiniUserAudit(req *types.MiniUserAuditRequest) (err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId); err != nil {
return xerr.NewErrMsgErr("用户不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if err = user.Audit(req.Status); err != nil {
return err
}
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
return err
}
return nil
}, true); err != nil {
return xerr.NewErrMsgErr("审核失败", err)
}
return nil
}
... ...
... ... @@ -2,6 +2,9 @@ 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"
"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 +27,19 @@ func NewMiniUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
}
func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp *types.MiniUserInfoResponse, err error) {
// todo: add your logic here and delete this line
var (
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
user *domain.User
conn = l.svcCtx.DefaultDBConn()
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
resp = &types.MiniUserInfoResponse{
User: &types.UserItem{
Id: user.Id,
Name: user.Name,
},
}
return
}
... ...
... ... @@ -2,6 +2,13 @@ package user
import (
"context"
"fmt"
"github.com/silenceper/wechat/v2"
"github.com/silenceper/wechat/v2/cache"
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"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"
... ... @@ -24,7 +31,106 @@ func NewMiniUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Min
}
func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (resp *types.MiniUserLoginResponse, err error) {
// todo: add your logic here and delete this line
var (
loginInfo *domain.LoginInfo
token string
loginCreator domain.LoginCreator = WXStuClientLogin{l: l}
)
switch req.LoginType {
case domain.LoginTypeWechatLogin:
loginInfo, err = loginCreator.WechatLogin(domain.WechatLoginRequest{Code: req.WechatAuthCode, EncryptedData: req.WechatEncryptedData, IV: req.WechatIV})
case domain.LoginTypeWechatPhoneLogin:
loginInfo, err = loginCreator.WechatPhoneLogin(domain.WechatLoginRequest{Code: req.WechatAuthCode, EncryptedData: req.WechatEncryptedData, IV: req.WechatIV})
case domain.LoginTypePhoneSmsCodeLogin:
loginInfo, err = loginCreator.PhoneSmsCodeLogin(req.Phone, req.SmsCode)
case domain.LoginTypePhonePasswordLogin:
loginInfo, err = loginCreator.PhonePasswordLogin(req.Phone, req.Password)
}
if err != nil {
return
}
var userJwtToken = tool.UserToken{}
if loginInfo.User != nil {
userJwtToken.UserId = loginInfo.User.Id
userJwtToken.CompanyId = loginInfo.User.CompanyId
userJwtToken.ClientType = "mini"
}
token, err = userJwtToken.GenerateToken(l.svcCtx.Config.MiniAuth.AccessSecret, l.svcCtx.Config.MiniAuth.AccessExpire)
if err != nil {
return nil, xerr.NewErrMsgErr("登录失败", err)
}
resp = &types.MiniUserLoginResponse{
Token: token,
Phone: loginInfo.Phone,
Success: true,
}
if loginInfo.User == nil {
resp.Success = false
}
return
}
type WXStuClientLogin struct {
l *MiniUserLoginLogic
}
func (c WXStuClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.LoginInfo, error) {
code := r.Code
miniprogram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{
AppID: c.l.svcCtx.Config.Wechat.AppID,
AppSecret: c.l.svcCtx.Config.Wechat.AppSecret,
Cache: cache.NewMemory(),
})
authResult, err := miniprogram.GetAuth().GetPhoneNumber(code)
if err != nil || authResult.ErrCode != 0 || authResult.PhoneInfo.PhoneNumber == "" {
return nil, xerr.NewCodeErrMsg(xerr.ErrWxMiniAuthFailError, nil, fmt.Sprintf("发起授权请求失败1 err : %v , code : %s , authResult : %+v", err, code, authResult))
}
var (
users []*domain.User
phone = authResult.PhoneInfo.PhoneNumber
)
conn := c.l.svcCtx.DefaultDBConn()
_, users, err = c.l.svcCtx.UserRepository.Find(c.l.ctx, conn, domain.NewQueryOptions().
MustWithKV("phone", phone).
MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
if err != nil {
return nil, err
}
response := &domain.LoginInfo{
Phone: phone,
}
if len(users) != 0 {
response.User = users[0]
}
return response, nil
}
func (c WXStuClientLogin) WechatLogin(r domain.WechatLoginRequest) (*domain.LoginInfo, error) {
return nil, nil
}
func (c WXStuClientLogin) PhonePasswordLogin(phone string, password string) (*domain.LoginInfo, error) {
panic("implement me")
}
func (c WXStuClientLogin) PhoneSmsCodeLogin(phone string, code string) (*domain.LoginInfo, error) {
var (
users []*domain.User
err error
)
conn := c.l.svcCtx.DefaultDBConn()
_, users, err = c.l.svcCtx.UserRepository.Find(c.l.ctx, conn, domain.NewQueryOptions().
MustWithKV("phone", phone).
MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}).
WithFindOnly())
if err != nil {
return nil, err
}
response := &domain.LoginInfo{
Phone: phone,
}
if len(users) != 0 {
response.User = users[0]
}
return response, nil
}
... ...
... ... @@ -165,6 +165,7 @@ type MiniUserApplyJoinCompanyResponse struct {
type MiniUserAuditRequest struct {
UserId int64 `json:"userId"` // 用户ID
Status int `json:"status"` // 审核状态 1:审核通过 2:拒绝
}
type MiniUserDepartmentUsersRequest struct {
... ... @@ -176,6 +177,7 @@ type MiniUserDepartmentUsersResponse struct {
}
type UserItem struct {
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
Roles []int64 `json:"roleId,omitempty"` // 角色
... ...
... ... @@ -111,6 +111,25 @@ func (repository *CompanyRepository) FindOne(ctx context.Context, conn transacti
return repository.ModelToDomainModel(m)
}
func (repository *CompanyRepository) FindOneByCode(ctx context.Context, conn transaction.Conn, code string) (*domain.Company, error) {
var (
err error
tx = conn.DB()
m = new(models.Company)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("code = ?", code).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
if _, err = repository.Query(queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *CompanyRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Company, error) {
var (
tx = conn.DB()
... ...
... ... @@ -111,6 +111,28 @@ func (repository *UserRepository) FindOne(ctx context.Context, conn transaction.
return repository.ModelToDomainModel(m)
}
func (repository *UserRepository) FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*domain.User, error) {
var (
err error
tx = conn.DB()
m = new(models.User)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).
Where("company_id = ?", companyId).
Where("phone = ?", phone).
Where("audit_status in (?)", status).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
if _, err = repository.Query(queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *UserRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.User, error) {
var (
tx = conn.DB()
... ... @@ -120,6 +142,12 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["phone"]; ok {
tx.Where("phone = ?", v)
}
if v, ok := queryOptions["auditStatus"]; ok {
tx.Where("audit_status in (?)", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -23,6 +23,7 @@ type CompanyRepository interface {
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Company) (*Company, error)
Delete(ctx context.Context, conn transaction.Conn, dm *Company) (*Company, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Company, error)
FindOneByCode(ctx context.Context, conn transaction.Conn, code string) (*Company, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Company, error)
}
... ...
... ... @@ -2,6 +2,8 @@ package domain
import (
"context"
"fmt"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
... ... @@ -32,6 +34,7 @@ type UserRepository interface {
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *User) (*User, error)
Delete(ctx context.Context, conn transaction.Conn, dm *User) (*User, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*User, error)
FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*User, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error)
}
... ... @@ -41,3 +44,51 @@ func (m *User) Identify() interface{} {
}
return m.Id
}
const (
UserAuditStatusWait = 0 // 审核中
UserAuditStatusPassed = 1 // 审核通过
UserAuditStatusReject = 2 // 审核拒绝
)
const (
LoginTypeWechatLogin string = "wechat-login" // 微信登录
LoginTypeWechatPhoneLogin string = "wechat-phone-login" // 微信手机号登录
LoginTypePhonePasswordLogin string = "phone-password-login" // 手机密码登录
LoginTypePhoneSmsCodeLogin string = "phone-sms-code-login" // 手机验证码登录
)
const (
UserEnable = 1
UserDisable = 2
)
func (m *User) Audit(status int) error {
if !lo.Contains([]int{UserAuditStatusWait, UserAuditStatusPassed, UserAuditStatusReject}, status) {
return fmt.Errorf("unknown status:%d", status)
}
if m.AuditStatus != UserAuditStatusWait {
return fmt.Errorf("用户不是在待审核状态")
}
m.AuditStatus = status
return nil
}
type (
LoginCreator interface {
WechatLogin(r WechatLoginRequest) (*LoginInfo, error)
PhonePasswordLogin(phone string, password string) (*LoginInfo, error)
PhoneSmsCodeLogin(phone string, code string) (*LoginInfo, error)
WechatPhoneLogin(r WechatLoginRequest) (*LoginInfo, error)
}
WechatLoginRequest struct {
Code string // 授权码
EncryptedData string // 包括敏感数据在内的完整用户信息的加密数据
IV string // 加密算法的初始向量
}
LoginInfo struct {
User *User
Phone string
Message string
}
)
... ...
... ... @@ -7,6 +7,8 @@ require (
github.com/jinzhu/copier v0.4.0
github.com/jinzhu/now v1.1.5
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.38.1
github.com/silenceper/wechat/v2 v2.1.4
github.com/stretchr/testify v1.8.4
github.com/tiptok/gocomm v1.0.14
github.com/zeromicro/go-zero v1.5.5
... ... @@ -21,6 +23,7 @@ require (
github.com/Shopify/sarama v1.37.2 // indirect
github.com/beego/beego/v2 v2.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
... ... @@ -30,6 +33,7 @@ require (
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/garyburd/redigo v1.6.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
... ... @@ -80,12 +84,16 @@ require (
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.4.0 // indirect
github.com/tidwall/gjson v1.14.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.14.0 // indirect
... ... @@ -100,6 +108,7 @@ require (
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
... ...
... ... @@ -9,8 +9,8 @@ import (
)
var (
CtxKeyJwtUserId = "userId"
CtxKeyJwtCompanyId = "companyId"
CtxKeyJwtUserId = "UserId"
CtxKeyJwtCompanyId = "CompanyId"
)
func GetInt64FromCtx(ctx context.Context, key string) int64 {
... ... @@ -58,8 +58,8 @@ func GetUserTokenFromCtx(ctx context.Context) UserToken {
}
type UserToken struct {
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
UserId int64
CompanyId int64
}
func (tk UserToken) GenerateToken(secret string, expire int64) (string, error) {
... ...
... ... @@ -21,13 +21,15 @@ func HttpResult(r *http.Request, w http.ResponseWriter, resp interface{}, err er
}
//错误返回
errCode := xerr.ServerCommonError
errMsg := "服务器开小差啦,稍后再来试一试"
internalErr := ""
causeErr := errors.Cause(err)
var (
errCode = xerr.ServerCommonError
errMsg = "服务器开小差啦,稍后再来试一试"
internalErr = ""
causeErr = errors.Cause(err)
)
codeError := &xerr.CodeError{}
if ok := errors.As(causeErr, codeError); ok { // 自定义错误类型
codeError, ok := causeErr.(*xerr.CodeError)
if ok { // 自定义错误类型
errCode = codeError.GetErrCode()
errMsg = codeError.GetErrMsg()
if codeError.InternalError != nil {
... ...