Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev-zhuang
正在显示
38 个修改的文件
包含
651 行增加
和
373 行删除
| @@ -75,9 +75,11 @@ service Core { | @@ -75,9 +75,11 @@ service Core { | ||
| 75 | 75 | ||
| 76 | @doc "小程序首页数据展示" | 76 | @doc "小程序首页数据展示" |
| 77 | @handler MiniShowHomePage | 77 | @handler MiniShowHomePage |
| 78 | - get /show/home_page (MiniHomePageRequest) returns (MiniHomePageRespose) | ||
| 79 | - | 78 | + get /show/home_page (MiniHomePageRequest) returns (MiniHomePageResponse) |
| 80 | 79 | ||
| 80 | + @doc "小程序首页搜索文章" | ||
| 81 | + @handler MiniSearchArticlePage | ||
| 82 | + post /show/search_article (MiniSearchArticleRequest) returns (MiniSearchArticleResponse) | ||
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | // 管理后台接口 | 85 | // 管理后台接口 |
| @@ -53,9 +53,10 @@ type ( | @@ -53,9 +53,10 @@ type ( | ||
| 53 | CountLove int `json:"countLove"` // 点赞数量 | 53 | CountLove int `json:"countLove"` // 点赞数量 |
| 54 | CountComment int `json:"countComment"` // 评论数量 | 54 | CountComment int `json:"countComment"` // 评论数量 |
| 55 | CountRead int `json:"countRead"` // 浏览数量 | 55 | CountRead int `json:"countRead"` // 浏览数量 |
| 56 | - Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 56 | + Show int `json:"show"` // 评论的展示状态(1显示、2不显示) |
| 57 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) | 57 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) |
| 58 | MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) | 58 | MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) |
| 59 | + Tags []string `json:"tags"` //文章的标签 | ||
| 59 | } | 60 | } |
| 60 | ArticleSection { | 61 | ArticleSection { |
| 61 | Id int64 `json:"id"` //段落id | 62 | Id int64 `json:"id"` //段落id |
| @@ -314,14 +315,14 @@ type ( | @@ -314,14 +315,14 @@ type ( | ||
| 314 | TagGroup []ArticleTagGroup `json:"tagGroup"` | 315 | TagGroup []ArticleTagGroup `json:"tagGroup"` |
| 315 | } | 316 | } |
| 316 | ArticleTagGroup { | 317 | ArticleTagGroup { |
| 317 | - Group string `json:"group"` | 318 | + Category string `json:"category"` |
| 318 | Tags []ArticleTagItem `json:"tags"` | 319 | Tags []ArticleTagItem `json:"tags"` |
| 319 | } | 320 | } |
| 320 | ArticleTagItem { | 321 | ArticleTagItem { |
| 321 | - Id int64 `json:"id"` | ||
| 322 | - Group string `json:"group"` | ||
| 323 | - Name string `json:"name"` | ||
| 324 | - Image string `json:"image"` | 322 | + Id int64 `json:"id"` |
| 323 | + Category string `json:"category"` | ||
| 324 | + Name string `json:"name"` | ||
| 325 | + Image string `json:"image"` | ||
| 325 | } | 326 | } |
| 326 | ) | 327 | ) |
| 327 | 328 | ||
| @@ -480,11 +481,12 @@ type ( | @@ -480,11 +481,12 @@ type ( | ||
| 480 | CompanyId int64 `path:",optional"` | 481 | CompanyId int64 `path:",optional"` |
| 481 | UserId int64 `path:",optional"` | 482 | UserId int64 `path:",optional"` |
| 482 | } | 483 | } |
| 483 | - MiniHomePageRespose { | ||
| 484 | - Tags []ArticleTagCount `json:"tags"` | 484 | + MiniHomePageResponse { |
| 485 | + TagCategory []string `json:"tagCategory"` | ||
| 486 | + Tags []ArticleTagCount `json:"tags"` | ||
| 485 | } | 487 | } |
| 486 | ArticleTagCount { | 488 | ArticleTagCount { |
| 487 | - TagGroup string `json:"tagGroup"` // 标签分组 | 489 | + TagCategory string `json:"tagCategory"` // 标签分组 |
| 488 | TagId int64 `json:"tagId"` // 标签id | 490 | TagId int64 `json:"tagId"` // 标签id |
| 489 | TagImage string `json:"tagImage"` // 对应的图标 | 491 | TagImage string `json:"tagImage"` // 对应的图标 |
| 490 | TagName string `json:"tagName"` // 标签名称 | 492 | TagName string `json:"tagName"` // 标签名称 |
| @@ -492,4 +494,33 @@ type ( | @@ -492,4 +494,33 @@ type ( | ||
| 492 | TotalArticle int `json:"totalArticle"` // 总的文章数量 | 494 | TotalArticle int `json:"totalArticle"` // 总的文章数量 |
| 493 | ReadArticle int `json:"readArticle"` // 已读的标签数量 | 495 | ReadArticle int `json:"readArticle"` // 已读的标签数量 |
| 494 | } | 496 | } |
| 497 | +) | ||
| 498 | + | ||
| 499 | +//小程序首页搜索文章 | ||
| 500 | +type ( | ||
| 501 | + MiniSearchArticleRequest { | ||
| 502 | + Page int `json:"page"` | ||
| 503 | + Size int `json:"size"` | ||
| 504 | + CompanyId int64 `json:",optional"` | ||
| 505 | + UserId int64 `json:",optional"` | ||
| 506 | + TagGroup string `json:"tagGroup"` | ||
| 507 | + TagId int64 `json:"tagId"` | ||
| 508 | + BeginTime int64 `json:"beginTime"` | ||
| 509 | + EndTime int `json:"endTime"` | ||
| 510 | + SearchWord string `json:"searchWord"` | ||
| 511 | + } | ||
| 512 | + // | ||
| 513 | + MiniSearchArticleResponse { | ||
| 514 | + Total int `json:"total"` | ||
| 515 | + List []MiniSearchArticleItem `json:"list"` | ||
| 516 | + } | ||
| 517 | + // | ||
| 518 | + MiniSearchArticleItem{ | ||
| 519 | + ArticleId int64 `json:"articleId"` | ||
| 520 | + Title string `json:"title"` | ||
| 521 | + Author string `json:"author"` // 发布人 | ||
| 522 | + Images []string `json:"images"` | ||
| 523 | + CreatedAt int64 `json:"createdAt"` | ||
| 524 | + MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读] | ||
| 525 | + } | ||
| 495 | ) | 526 | ) |
| @@ -33,6 +33,9 @@ service Core { | @@ -33,6 +33,9 @@ service Core { | ||
| 33 | @doc "用户信息" | 33 | @doc "用户信息" |
| 34 | @handler miniUserInfo | 34 | @handler miniUserInfo |
| 35 | post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse) | 35 | post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse) |
| 36 | + @doc "用户统计" | ||
| 37 | + @handler miniUserStatistics | ||
| 38 | + post /mini/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse) | ||
| 36 | @doc "用户审核列表" | 39 | @doc "用户审核列表" |
| 37 | @handler miniUserAuditList | 40 | @handler miniUserAuditList |
| 38 | post /mini/user/audit-list (UserSearchRequest)returns(UserSearchResponse) | 41 | post /mini/user/audit-list (UserSearchRequest)returns(UserSearchResponse) |
| @@ -41,7 +44,10 @@ service Core { | @@ -41,7 +44,10 @@ service Core { | ||
| 41 | post /mini/user/audit (MiniUserAuditRequest) | 44 | post /mini/user/audit (MiniUserAuditRequest) |
| 42 | @doc "部门用户列表" | 45 | @doc "部门用户列表" |
| 43 | @handler miniUserDepartmentUsers | 46 | @handler miniUserDepartmentUsers |
| 44 | - post /mini/user/department-users (MiniUserDepartmentUsersRequest)returns (MiniUserInfoResponse) | 47 | + post /mini/user/department-users (MiniUserDepartmentUsersRequest) |
| 48 | + @doc "用户列表" | ||
| 49 | + @handler miniUsersList | ||
| 50 | + post /mini/user/user-list (MiniUsersListRequest) | ||
| 45 | @doc "关注我的人" | 51 | @doc "关注我的人" |
| 46 | @handler miniUserFollower | 52 | @handler miniUserFollower |
| 47 | post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse) | 53 | post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse) |
| @@ -105,6 +111,10 @@ type( | @@ -105,6 +111,10 @@ type( | ||
| 105 | Departments []*Department `json:"departments"` | 111 | Departments []*Department `json:"departments"` |
| 106 | Users []*UserItem `json:"users"` | 112 | Users []*UserItem `json:"users"` |
| 107 | } | 113 | } |
| 114 | + MiniUsersListRequest{ | ||
| 115 | + ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户) | ||
| 116 | + RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户 | ||
| 117 | + } | ||
| 108 | MiniUserFollowedSearchRequest{ | 118 | MiniUserFollowedSearchRequest{ |
| 109 | Page int `json:"page,optional"` | 119 | Page int `json:"page,optional"` |
| 110 | Size int `json:"size,optional"` | 120 | Size int `json:"size,optional"` |
| @@ -117,6 +127,7 @@ type( | @@ -117,6 +127,7 @@ type( | ||
| 117 | Id int64 `json:"id,omitempty"` // 用户ID | 127 | Id int64 `json:"id,omitempty"` // 用户ID |
| 118 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 128 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
| 119 | CompanyName string `json:"companyName,omitempty"` // 公司名称 | 129 | CompanyName string `json:"companyName,omitempty"` // 公司名称 |
| 130 | + CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码) | ||
| 120 | //DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID | 131 | //DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID |
| 121 | //Roles []int64 `json:"roleId,omitempty"` // 角色 | 132 | //Roles []int64 `json:"roleId,omitempty"` // 角色 |
| 122 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 133 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
| @@ -216,6 +227,9 @@ service Core { | @@ -216,6 +227,9 @@ service Core { | ||
| 216 | @doc "用户统计" | 227 | @doc "用户统计" |
| 217 | @handler systemUserStatistics | 228 | @handler systemUserStatistics |
| 218 | post /system/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse) | 229 | post /system/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse) |
| 230 | + @doc "用户列表" | ||
| 231 | + @handler systemUsersList | ||
| 232 | + post /system/user/user-list (MiniUsersListRequest) | ||
| 219 | 233 | ||
| 220 | @doc "用户详情" | 234 | @doc "用户详情" |
| 221 | @handler systemUserGet | 235 | @handler systemUserGet |
| 1 | +package article | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +func MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.MiniSearchArticleRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := article.NewMiniSearchArticlePageLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.MiniSearchArticlePage(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| @@ -3,26 +3,27 @@ package article | @@ -3,26 +3,27 @@ package article | ||
| 3 | import ( | 3 | import ( |
| 4 | "net/http" | 4 | "net/http" |
| 5 | 5 | ||
| 6 | - "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
| 10 | ) | 11 | ) |
| 11 | 12 | ||
| 13 | +// 展示小程序端首页的数据 | ||
| 12 | func MiniShowHomePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 14 | func MiniShowHomePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
| 13 | return func(w http.ResponseWriter, r *http.Request) { | 15 | return func(w http.ResponseWriter, r *http.Request) { |
| 14 | var req types.MiniHomePageRequest | 16 | var req types.MiniHomePageRequest |
| 15 | - if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | - httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | - return | ||
| 18 | - } | 17 | + // if err := httpx.Parse(r, &req); err != nil { |
| 18 | + // httpx.ErrorCtx(r.Context(), w, err) | ||
| 19 | + // return | ||
| 20 | + // } | ||
| 19 | 21 | ||
| 20 | l := article.NewMiniShowHomePageLogic(r.Context(), svcCtx) | 22 | l := article.NewMiniShowHomePageLogic(r.Context(), svcCtx) |
| 23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
| 24 | + req.UserId = token.UserId | ||
| 25 | + req.CompanyId = token.CompanyId | ||
| 21 | resp, err := l.MiniShowHomePage(&req) | 26 | resp, err := l.MiniShowHomePage(&req) |
| 22 | - if err != nil { | ||
| 23 | - httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | - } else { | ||
| 25 | - httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | - } | 27 | + result.HttpResult(r, w, resp, err) |
| 27 | } | 28 | } |
| 28 | } | 29 | } |
| @@ -159,6 +159,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -159,6 +159,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 159 | }, | 159 | }, |
| 160 | { | 160 | { |
| 161 | Method: http.MethodPost, | 161 | Method: http.MethodPost, |
| 162 | + Path: "/mini/user/statistics", | ||
| 163 | + Handler: user.MiniUserStatisticsHandler(serverCtx), | ||
| 164 | + }, | ||
| 165 | + { | ||
| 166 | + Method: http.MethodPost, | ||
| 162 | Path: "/mini/user/audit-list", | 167 | Path: "/mini/user/audit-list", |
| 163 | Handler: user.MiniUserAuditListHandler(serverCtx), | 168 | Handler: user.MiniUserAuditListHandler(serverCtx), |
| 164 | }, | 169 | }, |
| @@ -174,6 +179,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -174,6 +179,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 174 | }, | 179 | }, |
| 175 | { | 180 | { |
| 176 | Method: http.MethodPost, | 181 | Method: http.MethodPost, |
| 182 | + Path: "/mini/user/user-list", | ||
| 183 | + Handler: user.MiniUsersListHandler(serverCtx), | ||
| 184 | + }, | ||
| 185 | + { | ||
| 186 | + Method: http.MethodPost, | ||
| 177 | Path: "/mini/user/follower", | 187 | Path: "/mini/user/follower", |
| 178 | Handler: user.MiniUserFollowerHandler(serverCtx), | 188 | Handler: user.MiniUserFollowerHandler(serverCtx), |
| 179 | }, | 189 | }, |
| @@ -217,6 +227,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -217,6 +227,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 217 | Handler: user.SystemUserStatisticsHandler(serverCtx), | 227 | Handler: user.SystemUserStatisticsHandler(serverCtx), |
| 218 | }, | 228 | }, |
| 219 | { | 229 | { |
| 230 | + Method: http.MethodPost, | ||
| 231 | + Path: "/system/user/user-list", | ||
| 232 | + Handler: user.SystemUsersListHandler(serverCtx), | ||
| 233 | + }, | ||
| 234 | + { | ||
| 220 | Method: http.MethodGet, | 235 | Method: http.MethodGet, |
| 221 | Path: "/system/user/:id", | 236 | Path: "/system/user/:id", |
| 222 | Handler: user.SystemUserGetHandler(serverCtx), | 237 | Handler: user.SystemUserGetHandler(serverCtx), |
| @@ -379,6 +394,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -379,6 +394,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 379 | Path: "/show/home_page", | 394 | Path: "/show/home_page", |
| 380 | Handler: article.MiniShowHomePageHandler(serverCtx), | 395 | Handler: article.MiniShowHomePageHandler(serverCtx), |
| 381 | }, | 396 | }, |
| 397 | + { | ||
| 398 | + Method: http.MethodPost, | ||
| 399 | + Path: "/show/search_article", | ||
| 400 | + Handler: article.MiniSearchArticlePageHandler(serverCtx), | ||
| 401 | + }, | ||
| 382 | }, | 402 | }, |
| 383 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | 403 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), |
| 384 | rest.WithPrefix("/v1/mini"), | 404 | rest.WithPrefix("/v1/mini"), |
| 1 | +package user | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +func MiniUserStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 14 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 15 | + var req types.UserStatisticsRequest | ||
| 16 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 17 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 18 | + return | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + l := user.NewSystemUserStatisticsLogic(r.Context(), svcCtx) | ||
| 22 | + resp, err := l.SystemUserStatistics(&req) | ||
| 23 | + result.HttpResult(r, w, resp, err) | ||
| 24 | + } | ||
| 25 | +} |
| 1 | +package user | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +func MiniUsersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 14 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 15 | + var req types.MiniUsersListRequest | ||
| 16 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 17 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 18 | + return | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + l := user.NewMiniAtUsersListLogic(r.Context(), svcCtx) | ||
| 22 | + resp, err := l.MiniAtUsersList(&req) | ||
| 23 | + result.HttpResult(r, w, resp, err) | ||
| 24 | + } | ||
| 25 | +} |
| 1 | +package user | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +func SystemUsersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 14 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 15 | + var req types.MiniUsersListRequest | ||
| 16 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 17 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 18 | + return | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + l := user.NewMiniAtUsersListLogic(r.Context(), svcCtx) | ||
| 22 | + resp, err := l.MiniAtUsersList(&req) | ||
| 23 | + result.HttpResult(r, w, resp, err) | ||
| 24 | + } | ||
| 25 | +} |
| @@ -38,20 +38,20 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR | @@ -38,20 +38,20 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR | ||
| 38 | for _, val := range tagList { | 38 | for _, val := range tagList { |
| 39 | if m, ok := tagMap[val.Category]; ok { | 39 | if m, ok := tagMap[val.Category]; ok { |
| 40 | m = append(m, types.ArticleTagItem{ | 40 | m = append(m, types.ArticleTagItem{ |
| 41 | - Id: val.Id, | ||
| 42 | - Group: val.Category, | ||
| 43 | - Name: val.Name, | ||
| 44 | - Image: val.Image.Url, | 41 | + Id: val.Id, |
| 42 | + Category: val.Category, | ||
| 43 | + Name: val.Name, | ||
| 44 | + Image: val.Image.Url, | ||
| 45 | }) | 45 | }) |
| 46 | tagMap[val.Category] = m | 46 | tagMap[val.Category] = m |
| 47 | } else { | 47 | } else { |
| 48 | group = append(group, val.Category) | 48 | group = append(group, val.Category) |
| 49 | tagMap[val.Category] = []types.ArticleTagItem{ | 49 | tagMap[val.Category] = []types.ArticleTagItem{ |
| 50 | { | 50 | { |
| 51 | - Id: val.Id, | ||
| 52 | - Group: val.Category, | ||
| 53 | - Name: val.Name, | ||
| 54 | - Image: val.Image.Url, | 51 | + Id: val.Id, |
| 52 | + Category: val.Category, | ||
| 53 | + Name: val.Name, | ||
| 54 | + Image: val.Image.Url, | ||
| 55 | }, | 55 | }, |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| @@ -61,8 +61,8 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR | @@ -61,8 +61,8 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR | ||
| 61 | } | 61 | } |
| 62 | for i := range group { | 62 | for i := range group { |
| 63 | resp.TagGroup = append(resp.TagGroup, types.ArticleTagGroup{ | 63 | resp.TagGroup = append(resp.TagGroup, types.ArticleTagGroup{ |
| 64 | - Group: group[i], | ||
| 65 | - Tags: tagMap[group[i]], | 64 | + Category: group[i], |
| 65 | + Tags: tagMap[group[i]], | ||
| 66 | }) | 66 | }) |
| 67 | } | 67 | } |
| 68 | return resp, nil | 68 | return resp, nil |
| @@ -2,6 +2,7 @@ package article | @@ -2,6 +2,7 @@ package article | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "strconv" | ||
| 5 | "strings" | 6 | "strings" |
| 6 | "text/template" | 7 | "text/template" |
| 7 | 8 | ||
| @@ -9,6 +10,7 @@ import ( | @@ -9,6 +10,7 @@ import ( | ||
| 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" |
| 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 13 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss" | ||
| 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 14 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
| 13 | 15 | ||
| 14 | "github.com/samber/lo" | 16 | "github.com/samber/lo" |
| @@ -52,13 +54,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | @@ -52,13 +54,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | ||
| 52 | if len(req.Images) > 9 { | 54 | if len(req.Images) > 9 { |
| 53 | return nil, xerr.NewErrMsg("图片数量最多9张") | 55 | return nil, xerr.NewErrMsg("图片数量最多9张") |
| 54 | } | 56 | } |
| 55 | - //TODO 获取图片的尺寸大小 | 57 | + //获取图片的尺寸大小 |
| 56 | images := []domain.Image{} | 58 | images := []domain.Image{} |
| 57 | for _, val := range req.Images { | 59 | for _, val := range req.Images { |
| 60 | + fInfo, _ := oss.GetImageInfo(val) | ||
| 61 | + w, _ := strconv.Atoi(fInfo.ImageWidth.Value) | ||
| 62 | + h, _ := strconv.Atoi(fInfo.ImageHeight.Value) | ||
| 58 | images = append(images, domain.Image{ | 63 | images = append(images, domain.Image{ |
| 59 | Url: val, | 64 | Url: val, |
| 60 | - Width: 0, | ||
| 61 | - Height: 0, | 65 | + Width: w, |
| 66 | + Height: h, | ||
| 62 | }) | 67 | }) |
| 63 | } | 68 | } |
| 64 | 69 | ||
| @@ -157,7 +162,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | @@ -157,7 +162,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | ||
| 157 | CountLove: 0, | 162 | CountLove: 0, |
| 158 | CountComment: 0, | 163 | CountComment: 0, |
| 159 | CountRead: 0, | 164 | CountRead: 0, |
| 160 | - Show: 0, | 165 | + Show: domain.ArticleShowEnable, |
| 161 | Tags: []int64{}, | 166 | Tags: []int64{}, |
| 162 | } | 167 | } |
| 163 | if len(whoRead) > 0 { | 168 | if len(whoRead) > 0 { |
| @@ -38,9 +38,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -38,9 +38,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
| 38 | if articleInfo.CompanyId != req.CompanyId { | 38 | if articleInfo.CompanyId != req.CompanyId { |
| 39 | return nil, xerr.NewErrMsg("没有查看权限") | 39 | return nil, xerr.NewErrMsg("没有查看权限") |
| 40 | } | 40 | } |
| 41 | - | ||
| 42 | //TODO 检查可查看人 | 41 | //TODO 检查可查看人 |
| 43 | - | ||
| 44 | if articleInfo.Show == domain.ArticleShowDisable { | 42 | if articleInfo.Show == domain.ArticleShowDisable { |
| 45 | // 文章内容不显示 | 43 | // 文章内容不显示 |
| 46 | resp = &types.MiniArticleGetResponse{ | 44 | resp = &types.MiniArticleGetResponse{ |
| @@ -71,6 +69,14 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -71,6 +69,14 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
| 71 | meLoveFlag = 1 | 69 | meLoveFlag = 1 |
| 72 | } | 70 | } |
| 73 | } | 71 | } |
| 72 | + tags := []string{} | ||
| 73 | + if len(articleInfo.Tags) > 0 { | ||
| 74 | + queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("ids", articleInfo.Tags) | ||
| 75 | + _, tagList, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption) | ||
| 76 | + for _, val := range tagList { | ||
| 77 | + tags = append(tags, val.Name) | ||
| 78 | + } | ||
| 79 | + } | ||
| 74 | 80 | ||
| 75 | sortBy := domain.SortArticleSection(sectionList) | 81 | sortBy := domain.SortArticleSection(sectionList) |
| 76 | sort.Sort(sortBy) | 82 | sort.Sort(sortBy) |
| @@ -111,6 +117,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -111,6 +117,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
| 111 | Show: int(articleInfo.Show), | 117 | Show: int(articleInfo.Show), |
| 112 | Edit: 0, | 118 | Edit: 0, |
| 113 | MeLoveFlag: meLoveFlag, | 119 | MeLoveFlag: meLoveFlag, |
| 120 | + Tags: tags, | ||
| 114 | } | 121 | } |
| 115 | if articleInfo.CreatedAt != articleInfo.UpdatedAt { | 122 | if articleInfo.CreatedAt != articleInfo.UpdatedAt { |
| 116 | resp.Edit = 1 | 123 | resp.Edit = 1 |
| 1 | +package article | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 8 | + | ||
| 9 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type MiniSearchArticlePageLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic { | ||
| 19 | + return &MiniSearchArticlePageLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearchArticleRequest) (resp *types.MiniSearchArticleResponse, err error) { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return | ||
| 30 | +} |
| @@ -5,7 +5,10 @@ import ( | @@ -5,7 +5,10 @@ import ( | ||
| 5 | 5 | ||
| 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/svc" |
| 7 | "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/xerr" | ||
| 8 | 10 | ||
| 11 | + "github.com/samber/lo" | ||
| 9 | "github.com/zeromicro/go-zero/core/logx" | 12 | "github.com/zeromicro/go-zero/core/logx" |
| 10 | ) | 13 | ) |
| 11 | 14 | ||
| @@ -23,8 +26,47 @@ func NewMiniShowHomePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) * | @@ -23,8 +26,47 @@ func NewMiniShowHomePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) * | ||
| 23 | } | 26 | } |
| 24 | } | 27 | } |
| 25 | 28 | ||
| 26 | -func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageRespose, err error) { | ||
| 27 | - // todo: add your logic here and delete this line | 29 | +func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest) (resp *types.MiniHomePageResponse, err error) { |
| 30 | + // 获取所有的标签 | ||
| 31 | + var conn = l.svcCtx.DefaultDBConn() | ||
| 32 | + queryOption := domain.NewQueryOptions().WithFindOnly() | ||
| 33 | + _, allTags, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption) | ||
| 34 | + if err != nil { | ||
| 35 | + return nil, xerr.NewErrMsgErr("获取标签列表失败", err) | ||
| 36 | + } | ||
| 37 | + // 获取统计数据 | ||
| 38 | + countData, err := l.svcCtx.ArticleAndTagRepository.CountArticleReadGroupByTag(l.ctx, conn, req.UserId, req.CompanyId) | ||
| 39 | + if err != nil { | ||
| 40 | + return nil, xerr.NewErrMsgErr("获取文章汇总数量失败", err) | ||
| 41 | + } | ||
| 42 | + countDataMap := map[int64]*domain.CountArticleTagRead{} | ||
| 43 | + for _, val := range countData { | ||
| 44 | + countDataMap[val.TagId] = val | ||
| 45 | + } | ||
| 28 | 46 | ||
| 29 | - return | 47 | + tagCategory := []string{} |
| 48 | + tagCount := []types.ArticleTagCount{} | ||
| 49 | + for _, val := range allTags { | ||
| 50 | + tagCategory = append(tagCategory, val.Category) | ||
| 51 | + m := types.ArticleTagCount{ | ||
| 52 | + TagCategory: val.Category, | ||
| 53 | + TagId: val.Id, | ||
| 54 | + TagImage: val.Image.Url, | ||
| 55 | + TagName: val.Name, | ||
| 56 | + TagRemark: val.Remark, | ||
| 57 | + TotalArticle: 0, | ||
| 58 | + ReadArticle: 0, | ||
| 59 | + } | ||
| 60 | + if count, ok := countDataMap[val.Id]; ok { | ||
| 61 | + m.TotalArticle = count.TotalArticle | ||
| 62 | + m.ReadArticle = count.ReadArticle | ||
| 63 | + } | ||
| 64 | + tagCount = append(tagCount, m) | ||
| 65 | + } | ||
| 66 | + tagCategory = lo.Uniq(tagCategory) | ||
| 67 | + resp = &types.MiniHomePageResponse{ | ||
| 68 | + TagCategory: tagCategory, | ||
| 69 | + Tags: tagCount, | ||
| 70 | + } | ||
| 71 | + return resp, nil | ||
| 30 | } | 72 | } |
| @@ -2,6 +2,7 @@ package article | @@ -2,6 +2,7 @@ package article | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + | ||
| 5 | "github.com/samber/lo" | 6 | "github.com/samber/lo" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
| @@ -71,10 +72,10 @@ func (l *SystemGetArticleLogic) SystemGetArticle(req *types.SystemArticleGetRequ | @@ -71,10 +72,10 @@ func (l *SystemGetArticleLogic) SystemGetArticle(req *types.SystemArticleGetRequ | ||
| 71 | if err == nil && len(tags) > 0 { | 72 | if err == nil && len(tags) > 0 { |
| 72 | lo.ForEach(tags, func(tag *domain.ArticleTag, index int) { | 73 | lo.ForEach(tags, func(tag *domain.ArticleTag, index int) { |
| 73 | resp.Tags = append(resp.Tags, types.ArticleTagItem{ | 74 | resp.Tags = append(resp.Tags, types.ArticleTagItem{ |
| 74 | - Id: tag.Id, | ||
| 75 | - Group: tag.Category, | ||
| 76 | - Name: tag.Name, | ||
| 77 | - Image: tag.Image.Url, | 75 | + Id: tag.Id, |
| 76 | + Category: tag.Category, | ||
| 77 | + Name: tag.Name, | ||
| 78 | + Image: tag.Image.Url, | ||
| 78 | }) | 79 | }) |
| 79 | }) | 80 | }) |
| 80 | } | 81 | } |
| @@ -2,11 +2,14 @@ package article | @@ -2,11 +2,14 @@ package article | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "strconv" | ||
| 6 | + | ||
| 5 | "github.com/samber/lo" | 7 | "github.com/samber/lo" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | 8 | "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" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/gateway/authlib" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" |
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss" | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 13 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
| 11 | "strings" | 14 | "strings" |
| 12 | 15 | ||
| @@ -37,13 +40,16 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | @@ -37,13 +40,16 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | ||
| 37 | if err != nil { | 40 | if err != nil { |
| 38 | return nil, xerr.NewErrMsgErr("帖子不存在", err) | 41 | return nil, xerr.NewErrMsgErr("帖子不存在", err) |
| 39 | } | 42 | } |
| 40 | - //TODO 获取图片的尺寸大小 | 43 | + // 获取图片的尺寸大小 |
| 41 | images := []domain.Image{} | 44 | images := []domain.Image{} |
| 42 | for _, val := range req.Images { | 45 | for _, val := range req.Images { |
| 46 | + fInfo, _ := oss.GetImageInfo(val) | ||
| 47 | + w, _ := strconv.Atoi(fInfo.ImageWidth.Value) | ||
| 48 | + h, _ := strconv.Atoi(fInfo.ImageHeight.Value) | ||
| 43 | images = append(images, domain.Image{ | 49 | images = append(images, domain.Image{ |
| 44 | Url: val, | 50 | Url: val, |
| 45 | - Width: 0, | ||
| 46 | - Height: 0, | 51 | + Width: w, |
| 52 | + Height: h, | ||
| 47 | }) | 53 | }) |
| 48 | } | 54 | } |
| 49 | //检查文章可被哪些人查看 | 55 | //检查文章可被哪些人查看 |
| @@ -130,7 +130,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -130,7 +130,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 130 | CountReply: 0, | 130 | CountReply: 0, |
| 131 | CountUserLove: 0, | 131 | CountUserLove: 0, |
| 132 | CountAdminLove: 0, | 132 | CountAdminLove: 0, |
| 133 | - Show: 0, | 133 | + Show: domain.CommentShowEnable, |
| 134 | AtWho: []domain.UserSimple{}, | 134 | AtWho: []domain.UserSimple{}, |
| 135 | } | 135 | } |
| 136 | 136 |
| @@ -48,7 +48,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -48,7 +48,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 48 | var companyIdMap = map[int64]*domain.Company{} | 48 | var companyIdMap = map[int64]*domain.Company{} |
| 49 | var userIdMap = map[int64]*domain.User{} | 49 | var userIdMap = map[int64]*domain.User{} |
| 50 | var articleIdMap = map[int64]*domain.Article{} | 50 | var articleIdMap = map[int64]*domain.Article{} |
| 51 | - var commentIdMap = map[int64]*domain.Comment{} | 51 | + var commentIdMap = map[int64]*domain.ArticleComment{} |
| 52 | //var discussionIdMap = map[int64]int{} | 52 | //var discussionIdMap = map[int64]int{} |
| 53 | //var discussionOpinionIdMap = map[int64]int{} | 53 | //var discussionOpinionIdMap = map[int64]int{} |
| 54 | for _, item := range list { | 54 | for _, item := range list { |
| @@ -126,7 +126,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -126,7 +126,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 126 | 126 | ||
| 127 | // 获取评论 | 127 | // 获取评论 |
| 128 | if len(commentIds) > 0 { | 128 | if len(commentIds) > 0 { |
| 129 | - _, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | 129 | + _, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
| 130 | WithFindOnly(). | 130 | WithFindOnly(). |
| 131 | WithKV("ids", commentIds). | 131 | WithKV("ids", commentIds). |
| 132 | WithKV("limit", len(commentIds))) | 132 | WithKV("limit", len(commentIds))) |
| @@ -192,12 +192,12 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -192,12 +192,12 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 192 | } | 192 | } |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | - if _, ok := commentIdMap[item.CommentId]; ok { | 195 | + if v, ok := commentIdMap[item.CommentId]; ok { |
| 196 | to.Comment = &types.SimpleComment{ | 196 | to.Comment = &types.SimpleComment{ |
| 197 | - //Id: v.Id, | ||
| 198 | - //Title: v.Title, | ||
| 199 | - //CountLove: v.CountLove, | ||
| 200 | - //CountComment: v.CountComment, | 197 | + Id: v.Id, |
| 198 | + Content: v.Content, | ||
| 199 | + CountLove: v.CountUserLove, | ||
| 200 | + CountComment: v.CountReply, | ||
| 201 | } | 201 | } |
| 202 | } | 202 | } |
| 203 | 203 |
| @@ -3,10 +3,12 @@ package tags | @@ -3,10 +3,12 @@ package tags | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | "fmt" | 5 | "fmt" |
| 6 | + "strconv" | ||
| 6 | 7 | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 9 | "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 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss" | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
| 11 | 13 | ||
| 12 | "github.com/zeromicro/go-zero/core/logx" | 14 | "github.com/zeromicro/go-zero/core/logx" |
| @@ -41,8 +43,10 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag | @@ -41,8 +43,10 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag | ||
| 41 | if cnt > 0 { | 43 | if cnt > 0 { |
| 42 | return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name)) | 44 | return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name)) |
| 43 | } | 45 | } |
| 44 | - //TODO 获取图片的尺寸大小 | ||
| 45 | - | 46 | + //获取图片的尺寸大小 |
| 47 | + fInfo, _ := oss.GetImageInfo(req.Image) | ||
| 48 | + w, _ := strconv.Atoi(fInfo.ImageWidth.Value) | ||
| 49 | + h, _ := strconv.Atoi(fInfo.ImageHeight.Value) | ||
| 46 | newTag := &domain.ArticleTag{ | 50 | newTag := &domain.ArticleTag{ |
| 47 | Id: 0, | 51 | Id: 0, |
| 48 | CompanyId: req.CompanyId, | 52 | CompanyId: req.CompanyId, |
| @@ -52,8 +56,8 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag | @@ -52,8 +56,8 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag | ||
| 52 | Version: 0, | 56 | Version: 0, |
| 53 | Image: domain.Image{ | 57 | Image: domain.Image{ |
| 54 | Url: req.Image, | 58 | Url: req.Image, |
| 55 | - Width: 0, | ||
| 56 | - Height: 0, | 59 | + Width: w, |
| 60 | + Height: h, | ||
| 57 | }, | 61 | }, |
| 58 | Name: req.Name, | 62 | Name: req.Name, |
| 59 | Category: req.Category, | 63 | Category: req.Category, |
| @@ -3,10 +3,12 @@ package tags | @@ -3,10 +3,12 @@ package tags | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | "fmt" | 5 | "fmt" |
| 6 | + "strconv" | ||
| 6 | 7 | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 9 | "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 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss" | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
| 11 | 13 | ||
| 12 | "github.com/zeromicro/go-zero/core/logx" | 14 | "github.com/zeromicro/go-zero/core/logx" |
| @@ -52,11 +54,16 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe | @@ -52,11 +54,16 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe | ||
| 52 | if oldTag.CompanyId != req.CompanyId { | 54 | if oldTag.CompanyId != req.CompanyId { |
| 53 | return nil, xerr.NewErrMsg("修改标签失败") | 55 | return nil, xerr.NewErrMsg("修改标签失败") |
| 54 | } | 56 | } |
| 55 | - | ||
| 56 | - //TODO 获取图片的尺寸大小 | ||
| 57 | - | 57 | + //获取图片的尺寸大小 |
| 58 | + fInfo, _ := oss.GetImageInfo(req.Image) | ||
| 59 | + w, _ := strconv.Atoi(fInfo.ImageWidth.Value) | ||
| 60 | + h, _ := strconv.Atoi(fInfo.ImageHeight.Value) | ||
| 58 | oldTag.Category = req.Category | 61 | oldTag.Category = req.Category |
| 59 | - oldTag.Image.Url = req.Image | 62 | + oldTag.Image = domain.Image{ |
| 63 | + Url: req.Image, | ||
| 64 | + Width: w, | ||
| 65 | + Height: h, | ||
| 66 | + } | ||
| 60 | oldTag.Name = req.Name | 67 | oldTag.Name = req.Name |
| 61 | oldTag.Remark = req.Remark | 68 | oldTag.Remark = req.Remark |
| 62 | oldTag.Other = req.Other | 69 | oldTag.Other = req.Other |
| @@ -46,19 +46,19 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types. | @@ -46,19 +46,19 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types. | ||
| 46 | 46 | ||
| 47 | var userMap = make(map[int64]*domain.User) | 47 | var userMap = make(map[int64]*domain.User) |
| 48 | var articleMap = make(map[int64]*domain.Article) | 48 | var articleMap = make(map[int64]*domain.Article) |
| 49 | - var commentMap = make(map[int64]*domain.Comment) | 49 | + var commentMap = make(map[int64]*domain.ArticleComment) |
| 50 | 50 | ||
| 51 | lo.ForEach(list, func(item *domain.UserLoveFlag, index int) { | 51 | lo.ForEach(list, func(item *domain.UserLoveFlag, index int) { |
| 52 | var ( | 52 | var ( |
| 53 | user *domain.User | 53 | user *domain.User |
| 54 | article *domain.Article | 54 | article *domain.Article |
| 55 | - comment *domain.Comment | 55 | + comment *domain.ArticleComment |
| 56 | ) | 56 | ) |
| 57 | 57 | ||
| 58 | if item.CommentId != 0 { // 点赞评论 | 58 | if item.CommentId != 0 { // 点赞评论 |
| 59 | user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.CommentAuthor, l.svcCtx.UserRepository.FindOne) | 59 | user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.CommentAuthor, l.svcCtx.UserRepository.FindOne) |
| 60 | article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) | 60 | article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) |
| 61 | - comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.CommentRepository.FindOne) | 61 | + comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne) |
| 62 | } else { | 62 | } else { |
| 63 | user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ArticleAuthor, l.svcCtx.UserRepository.FindOne) | 63 | user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ArticleAuthor, l.svcCtx.UserRepository.FindOne) |
| 64 | article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) | 64 | article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) |
| @@ -70,7 +70,7 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types. | @@ -70,7 +70,7 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types. | ||
| 70 | return | 70 | return |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | -func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.Comment) types.MyLikeItem { | 73 | +func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyLikeItem { |
| 74 | item := types.MyLikeItem{ | 74 | item := types.MyLikeItem{ |
| 75 | UserId: love.UserId, | 75 | UserId: love.UserId, |
| 76 | ArticleId: love.ArticleId, | 76 | ArticleId: love.ArticleId, |
| @@ -101,10 +101,11 @@ func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain | @@ -101,10 +101,11 @@ func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain | ||
| 101 | 101 | ||
| 102 | if comment != nil { | 102 | if comment != nil { |
| 103 | item.Comment = &types.SimpleComment{ | 103 | item.Comment = &types.SimpleComment{ |
| 104 | - Id: comment.Id, | ||
| 105 | - //Content: comment.Content, | ||
| 106 | - //CountLove: comment.CountLove, | ||
| 107 | - //CountComment: comment.CountComment, | 104 | + Id: comment.Id, |
| 105 | + Content: comment.Content, | ||
| 106 | + CountLove: comment.CountUserLove, | ||
| 107 | + CountComment: comment.CountReply, | ||
| 108 | + Show: int(comment.Show), | ||
| 108 | } | 109 | } |
| 109 | } | 110 | } |
| 110 | 111 |
| @@ -42,14 +42,21 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * | @@ -42,14 +42,21 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp * | ||
| 42 | if _, roles, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(user.CompanyId)().MustWithKV("ids", user.Roles)); err != nil { | 42 | if _, roles, err = l.svcCtx.RoleRepository.Find(l.ctx, conn, domain.IndexCompanyId(user.CompanyId)().MustWithKV("ids", user.Roles)); err != nil { |
| 43 | return nil, xerr.NewErrMsgErr("角色不存在", err) | 43 | return nil, xerr.NewErrMsgErr("角色不存在", err) |
| 44 | } | 44 | } |
| 45 | + | ||
| 45 | resp = &types.MiniUserInfoResponse{ | 46 | resp = &types.MiniUserInfoResponse{ |
| 46 | User: &types.UserItem{ | 47 | User: &types.UserItem{ |
| 47 | - Id: user.Id, | ||
| 48 | - Name: user.Name, | 48 | + Id: user.Id, |
| 49 | + Name: user.Name, | ||
| 50 | + Avatar: user.Avatar, | ||
| 51 | + Position: user.Position, | ||
| 49 | }, | 52 | }, |
| 50 | Accounts: make([]types.Account, 0), | 53 | Accounts: make([]types.Account, 0), |
| 51 | Auths: make([]types.Auth, 0), | 54 | Auths: make([]types.Auth, 0), |
| 52 | } | 55 | } |
| 56 | + if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil { | ||
| 57 | + resp.User.CompanyName = company.Name | ||
| 58 | + resp.User.CompanyCode = company.Code | ||
| 59 | + } | ||
| 53 | _, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed})) | 60 | _, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed})) |
| 54 | if err != nil { | 61 | if err != nil { |
| 55 | return nil, xerr.NewErrMsgErr("用户不存在", err) | 62 | return nil, xerr.NewErrMsgErr("用户不存在", err) |
| 1 | +package user | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 8 | + | ||
| 9 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type MiniUserStatisticsLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewMiniUserStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniUserStatisticsLogic { | ||
| 19 | + return &MiniUserStatisticsLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *MiniUserStatisticsLogic) MiniUserStatistics(req *types.UserStatisticsRequest) (resp *types.UserStatisticsResponse, err error) { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return | ||
| 30 | +} |
| 1 | +package user | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "github.com/samber/lo" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 9 | + | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 12 | + | ||
| 13 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +type MiniAtUsersListLogic struct { | ||
| 17 | + logx.Logger | ||
| 18 | + ctx context.Context | ||
| 19 | + svcCtx *svc.ServiceContext | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func NewMiniAtUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniAtUsersListLogic { | ||
| 23 | + return &MiniAtUsersListLogic{ | ||
| 24 | + Logger: logx.WithContext(ctx), | ||
| 25 | + ctx: ctx, | ||
| 26 | + svcCtx: svcCtx, | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest) (resp interface{}, err error) { | ||
| 31 | + var ( | ||
| 32 | + conn = l.svcCtx.DefaultDBConn() | ||
| 33 | + article *domain.Article | ||
| 34 | + users []*domain.User | ||
| 35 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 36 | + onlyUsers []int64 | ||
| 37 | + ) | ||
| 38 | + if req.ArticleId != 0 { | ||
| 39 | + if article, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId); err != nil { | ||
| 40 | + return nil, xerr.NewErrMsgErr("用户列表获取失败", err) | ||
| 41 | + } | ||
| 42 | + if article.TargetUser == domain.ArticleTargetLimit && len(article.WhoRead) > 0 { | ||
| 43 | + onlyUsers = article.WhoRead | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + if _, users, err = l.svcCtx.UserRepository.FindDepartmentUsers(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().WithFindOnly()); err != nil { | ||
| 47 | + return nil, xerr.NewErrMsgErr("用户列表获取失败", err) | ||
| 48 | + } | ||
| 49 | + if len(onlyUsers) > 0 { | ||
| 50 | + onlyUsersMap := lo.KeyBy(onlyUsers, func(item int64) int64 { | ||
| 51 | + return item | ||
| 52 | + }) | ||
| 53 | + users = lo.Filter(users, func(item *domain.User, index int) bool { | ||
| 54 | + if _, ok := onlyUsersMap[item.Id]; ok { | ||
| 55 | + return false | ||
| 56 | + } | ||
| 57 | + return true | ||
| 58 | + }) | ||
| 59 | + } | ||
| 60 | + var list = make([]*domain.User, 0) | ||
| 61 | + lo.ForEach(users, func(item *domain.User, index int) { | ||
| 62 | + list = append(list, &domain.User{ | ||
| 63 | + Id: item.Id, | ||
| 64 | + Name: item.Name, | ||
| 65 | + PinYinName: item.PinYinName, | ||
| 66 | + }) | ||
| 67 | + }) | ||
| 68 | + return map[string]interface{}{ | ||
| 69 | + "list": list, | ||
| 70 | + }, nil | ||
| 71 | +} |
| 1 | +package user | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 8 | + | ||
| 9 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type SystemUsersListLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewSystemUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemUsersListLogic { | ||
| 19 | + return &SystemUsersListLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *SystemUsersListLogic) SystemUsersList(req *types.MiniUsersListRequest) error { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return nil | ||
| 30 | +} |
| @@ -29,7 +29,6 @@ type ServiceContext struct { | @@ -29,7 +29,6 @@ type ServiceContext struct { | ||
| 29 | ArticleAndTagRepository domain.ArticleAndTagRepository | 29 | ArticleAndTagRepository domain.ArticleAndTagRepository |
| 30 | 30 | ||
| 31 | CompanyRepository domain.CompanyRepository | 31 | CompanyRepository domain.CompanyRepository |
| 32 | - CommentRepository domain.CommentRepository // 待移除 | ||
| 33 | DepartmentRepository domain.DepartmentRepository | 32 | DepartmentRepository domain.DepartmentRepository |
| 34 | MessageBusinessRepository domain.MessageBusinessRepository | 33 | MessageBusinessRepository domain.MessageBusinessRepository |
| 35 | MessageSystemRepository domain.MessageSystemRepository | 34 | MessageSystemRepository domain.MessageSystemRepository |
| @@ -60,7 +59,6 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -60,7 +59,6 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
| 60 | ApiAuthService: apiAuth, | 59 | ApiAuthService: apiAuth, |
| 61 | LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, | 60 | LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, |
| 62 | 61 | ||
| 63 | - CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)), | ||
| 64 | ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), | 62 | ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), |
| 65 | ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), | 63 | ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), |
| 66 | ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)), | 64 | ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)), |
| @@ -375,6 +375,11 @@ type MiniUserDepartmentUsersResponse struct { | @@ -375,6 +375,11 @@ type MiniUserDepartmentUsersResponse struct { | ||
| 375 | Users []*UserItem `json:"users"` | 375 | Users []*UserItem `json:"users"` |
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | +type MiniUsersListRequest struct { | ||
| 379 | + ArticleId int64 `json:"articleId,optional"` // 按文章ID(返回文章可见的用户) | ||
| 380 | + RoleId int64 `json:"roleId,optional"` // 按角色角色关联的用户 | ||
| 381 | +} | ||
| 382 | + | ||
| 378 | type MiniUserFollowedSearchRequest struct { | 383 | type MiniUserFollowedSearchRequest struct { |
| 379 | Page int `json:"page,optional"` | 384 | Page int `json:"page,optional"` |
| 380 | Size int `json:"size,optional"` | 385 | Size int `json:"size,optional"` |
| @@ -389,6 +394,7 @@ type UserItem struct { | @@ -389,6 +394,7 @@ type UserItem struct { | ||
| 389 | Id int64 `json:"id,omitempty"` // 用户ID | 394 | Id int64 `json:"id,omitempty"` // 用户ID |
| 390 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 395 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
| 391 | CompanyName string `json:"companyName,omitempty"` // 公司名称 | 396 | CompanyName string `json:"companyName,omitempty"` // 公司名称 |
| 397 | + CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码) | ||
| 392 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | 398 | Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) |
| 393 | Name string `json:"name,omitempty"` // 名称 | 399 | Name string `json:"name,omitempty"` // 名称 |
| 394 | Avatar string `json:"avatar,omitempty"` // 头像 | 400 | Avatar string `json:"avatar,omitempty"` // 头像 |
| @@ -665,9 +671,10 @@ type MiniArticleGetResponse struct { | @@ -665,9 +671,10 @@ type MiniArticleGetResponse struct { | ||
| 665 | CountLove int `json:"countLove"` // 点赞数量 | 671 | CountLove int `json:"countLove"` // 点赞数量 |
| 666 | CountComment int `json:"countComment"` // 评论数量 | 672 | CountComment int `json:"countComment"` // 评论数量 |
| 667 | CountRead int `json:"countRead"` // 浏览数量 | 673 | CountRead int `json:"countRead"` // 浏览数量 |
| 668 | - Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 674 | + Show int `json:"show"` // 评论的展示状态(1显示、2不显示) |
| 669 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) | 675 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) |
| 670 | MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) | 676 | MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) |
| 677 | + Tags []string `json:"tags"` //文章的标签 | ||
| 671 | } | 678 | } |
| 672 | 679 | ||
| 673 | type ArticleSection struct { | 680 | type ArticleSection struct { |
| @@ -899,15 +906,15 @@ type MiniAllArticleTagResponse struct { | @@ -899,15 +906,15 @@ type MiniAllArticleTagResponse struct { | ||
| 899 | } | 906 | } |
| 900 | 907 | ||
| 901 | type ArticleTagGroup struct { | 908 | type ArticleTagGroup struct { |
| 902 | - Group string `json:"group"` | ||
| 903 | - Tags []ArticleTagItem `json:"tags"` | 909 | + Category string `json:"category"` |
| 910 | + Tags []ArticleTagItem `json:"tags"` | ||
| 904 | } | 911 | } |
| 905 | 912 | ||
| 906 | type ArticleTagItem struct { | 913 | type ArticleTagItem struct { |
| 907 | - Id int64 `json:"id"` | ||
| 908 | - Group string `json:"group"` | ||
| 909 | - Name string `json:"name"` | ||
| 910 | - Image string `json:"image"` | 914 | + Id int64 `json:"id"` |
| 915 | + Category string `json:"category"` | ||
| 916 | + Name string `json:"name"` | ||
| 917 | + Image string `json:"image"` | ||
| 911 | } | 918 | } |
| 912 | 919 | ||
| 913 | type SystemArticleGetRequest struct { | 920 | type SystemArticleGetRequest struct { |
| @@ -1053,12 +1060,13 @@ type MiniHomePageRequest struct { | @@ -1053,12 +1060,13 @@ type MiniHomePageRequest struct { | ||
| 1053 | UserId int64 `path:",optional"` | 1060 | UserId int64 `path:",optional"` |
| 1054 | } | 1061 | } |
| 1055 | 1062 | ||
| 1056 | -type MiniHomePageRespose struct { | ||
| 1057 | - Tags []ArticleTagCount `json:"tags"` | 1063 | +type MiniHomePageResponse struct { |
| 1064 | + TagCategory []string `json:"tagCategory"` | ||
| 1065 | + Tags []ArticleTagCount `json:"tags"` | ||
| 1058 | } | 1066 | } |
| 1059 | 1067 | ||
| 1060 | type ArticleTagCount struct { | 1068 | type ArticleTagCount struct { |
| 1061 | - TagGroup string `json:"tagGroup"` // 标签分组 | 1069 | + TagCategory string `json:"tagCategory"` // 标签分组 |
| 1062 | TagId int64 `json:"tagId"` // 标签id | 1070 | TagId int64 `json:"tagId"` // 标签id |
| 1063 | TagImage string `json:"tagImage"` // 对应的图标 | 1071 | TagImage string `json:"tagImage"` // 对应的图标 |
| 1064 | TagName string `json:"tagName"` // 标签名称 | 1072 | TagName string `json:"tagName"` // 标签名称 |
| @@ -1067,6 +1075,32 @@ type ArticleTagCount struct { | @@ -1067,6 +1075,32 @@ type ArticleTagCount struct { | ||
| 1067 | ReadArticle int `json:"readArticle"` // 已读的标签数量 | 1075 | ReadArticle int `json:"readArticle"` // 已读的标签数量 |
| 1068 | } | 1076 | } |
| 1069 | 1077 | ||
| 1078 | +type MiniSearchArticleRequest struct { | ||
| 1079 | + Page int `json:"page"` | ||
| 1080 | + Size int `json:"size"` | ||
| 1081 | + CompanyId int64 `json:",optional"` | ||
| 1082 | + UserId int64 `json:",optional"` | ||
| 1083 | + TagGroup string `json:"tagGroup"` | ||
| 1084 | + TagId int64 `json:"tagId"` | ||
| 1085 | + BeginTime int64 `json:"beginTime"` | ||
| 1086 | + EndTime int `json:"endTime"` | ||
| 1087 | + SearchWord string `json:"searchWord"` | ||
| 1088 | +} | ||
| 1089 | + | ||
| 1090 | +type MiniSearchArticleResponse struct { | ||
| 1091 | + Total int `json:"total"` | ||
| 1092 | + List []MiniSearchArticleItem `json:"list"` | ||
| 1093 | +} | ||
| 1094 | + | ||
| 1095 | +type MiniSearchArticleItem struct { | ||
| 1096 | + ArticleId int64 `json:"articleId"` | ||
| 1097 | + Title string `json:"title"` | ||
| 1098 | + Author string `json:"author"` // 发布人 | ||
| 1099 | + Images []string `json:"images"` | ||
| 1100 | + CreatedAt int64 `json:"createdAt"` | ||
| 1101 | + MeReadFlag int `json:"meReadFlag"` //已读标识 [0:未读] [1:已读] | ||
| 1102 | +} | ||
| 1103 | + | ||
| 1070 | type RoleGetRequest struct { | 1104 | type RoleGetRequest struct { |
| 1071 | Id int64 `path:"id"` | 1105 | Id int64 `path:"id"` |
| 1072 | } | 1106 | } |
| 1 | -package models | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "fmt" | ||
| 5 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 6 | - "gorm.io/gorm" | ||
| 7 | - "gorm.io/plugin/soft_delete" | ||
| 8 | - "time" | ||
| 9 | -) | ||
| 10 | - | ||
| 11 | -type Comment struct { | ||
| 12 | - Id int64 // 唯一标识 | ||
| 13 | - | ||
| 14 | - CreatedAt int64 `json:",omitempty"` | ||
| 15 | - UpdatedAt int64 `json:",omitempty"` | ||
| 16 | - DeletedAt int64 `json:",omitempty"` | ||
| 17 | - Version int `json:",omitempty"` | ||
| 18 | - IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` | ||
| 19 | -} | ||
| 20 | - | ||
| 21 | -func (m *Comment) TableName() string { | ||
| 22 | - return "t_comment" | ||
| 23 | -} | ||
| 24 | - | ||
| 25 | -func (m *Comment) BeforeCreate(tx *gorm.DB) (err error) { | ||
| 26 | - m.CreatedAt = time.Now().Unix() | ||
| 27 | - m.UpdatedAt = time.Now().Unix() | ||
| 28 | - return | ||
| 29 | -} | ||
| 30 | - | ||
| 31 | -func (m *Comment) BeforeUpdate(tx *gorm.DB) (err error) { | ||
| 32 | - m.UpdatedAt = time.Now().Unix() | ||
| 33 | - return | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -func (m *Comment) CacheKeyFunc() string { | ||
| 37 | - if m.Id == 0 { | ||
| 38 | - return "" | ||
| 39 | - } | ||
| 40 | - return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | -func (m *Comment) CacheKeyFuncByObject(obj interface{}) string { | ||
| 44 | - if v, ok := obj.(*Comment); ok { | ||
| 45 | - return v.CacheKeyFunc() | ||
| 46 | - } | ||
| 47 | - return "" | ||
| 48 | -} | ||
| 49 | - | ||
| 50 | -func (m *Comment) CachePrimaryKeyFunc() string { | ||
| 51 | - if len("") == 0 { | ||
| 52 | - return "" | ||
| 53 | - } | ||
| 54 | - return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
| 55 | -} |
| @@ -136,24 +136,23 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic | @@ -136,24 +136,23 @@ func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.Artic | ||
| 136 | // 以TagId作为分组,统计所有已有标签的文章和人员已读的文章 | 136 | // 以TagId作为分组,统计所有已有标签的文章和人员已读的文章 |
| 137 | func (repository *ArticleAndTagRepository) CountArticleReadGroupByTag(ctx context.Context, conn transaction.Conn, userId int64, companyId int64) ([]*domain.CountArticleTagRead, error) { | 137 | func (repository *ArticleAndTagRepository) CountArticleReadGroupByTag(ctx context.Context, conn transaction.Conn, userId int64, companyId int64) ([]*domain.CountArticleTagRead, error) { |
| 138 | 138 | ||
| 139 | - sqlStr := ` | ||
| 140 | --- 首页统计数据 | 139 | + sqlStr := `-- 首页统计数据 |
| 141 | with | 140 | with |
| 142 | -- 按查看权限查询文章 | 141 | -- 按查看权限查询文章 |
| 143 | -- 获取有标签的文章 | 142 | -- 获取有标签的文章 |
| 144 | -- 过滤出可展示的文章id | 143 | -- 过滤出可展示的文章id |
| 145 | t_article_and_tag_2 as ( | 144 | t_article_and_tag_2 as ( |
| 146 | - select article_and_tag.article_id , article_and_tag.tag_id | 145 | + select article_and_tag.article_id,article_and_tag.tag_id |
| 147 | from article_and_tag | 146 | from article_and_tag |
| 148 | join article on article_and_tag.article_id = article.id | 147 | join article on article_and_tag.article_id = article.id |
| 149 | where article.deleted_at=0 | 148 | where article.deleted_at=0 |
| 150 | - and article.company_id =1598224576532189184 | ||
| 151 | - and article."show" =0 | ||
| 152 | - and (article.target_user =0 or article.who_read @>'[1]') | 149 | + and article.company_id = ? |
| 150 | + and article."show" = ? | ||
| 151 | + and (article.target_user =0 or article.who_read @> ?) | ||
| 153 | ), | 152 | ), |
| 154 | -- 查询人员已查看的文章 | 153 | -- 查询人员已查看的文章 |
| 155 | t_user_read as( | 154 | t_user_read as( |
| 156 | - select user_read_article.article_id from user_read_article where user_read_article.user_id =1 | 155 | + select user_read_article.article_id from user_read_article where user_read_article.user_id = ? |
| 157 | ) | 156 | ) |
| 158 | -- 汇总统计 total_article 符合条件的文章总数,read_article 已浏览的数量 | 157 | -- 汇总统计 total_article 符合条件的文章总数,read_article 已浏览的数量 |
| 159 | select count(t_article_and_tag_2.article_id) as total_article ,count(t_user_read.article_id) as read_article, t_article_and_tag_2.tag_id | 158 | select count(t_article_and_tag_2.article_id) as total_article ,count(t_user_read.article_id) as read_article, t_article_and_tag_2.tag_id |
| @@ -163,6 +162,7 @@ group by t_article_and_tag_2.tag_id | @@ -163,6 +162,7 @@ group by t_article_and_tag_2.tag_id | ||
| 163 | ` | 162 | ` |
| 164 | condition := []interface{}{ | 163 | condition := []interface{}{ |
| 165 | companyId, | 164 | companyId, |
| 165 | + domain.ArticleShowEnable, | ||
| 166 | fmt.Sprintf("[%d]", userId), | 166 | fmt.Sprintf("[%d]", userId), |
| 167 | userId, | 167 | userId, |
| 168 | } | 168 | } |
| @@ -175,7 +175,6 @@ group by t_article_and_tag_2.tag_id | @@ -175,7 +175,6 @@ group by t_article_and_tag_2.tag_id | ||
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | var dm []*domain.CountArticleTagRead | 177 | var dm []*domain.CountArticleTagRead |
| 178 | - | ||
| 179 | for _, val := range m { | 178 | for _, val := range m { |
| 180 | dm = append(dm, &domain.CountArticleTagRead{ | 179 | dm = append(dm, &domain.CountArticleTagRead{ |
| 181 | TagId: val.TagId, | 180 | TagId: val.TagId, |
| @@ -279,11 +279,11 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con | @@ -279,11 +279,11 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con | ||
| 279 | article_comment.id , | 279 | article_comment.id , |
| 280 | (article_comment.count_reply +article_comment.count_user_love +article_comment.count_admin_love ) cnt | 280 | (article_comment.count_reply +article_comment.count_user_love +article_comment.count_admin_love ) cnt |
| 281 | from article_comment | 281 | from article_comment |
| 282 | - where top_id =0 and article_id =? and deleted_at=0 and show=0 and company_id=? | 282 | + where top_id =0 and article_id =? and deleted_at=0 and show= ? and company_id=? |
| 283 | order by cnt desc,article_comment.id desc | 283 | order by cnt desc,article_comment.id desc |
| 284 | limit 5 ` | 284 | limit 5 ` |
| 285 | db := conn.DB() | 285 | db := conn.DB() |
| 286 | - rows, err := db.Raw(sql1, articleId, companyId).Rows() | 286 | + rows, err := db.Raw(sql1, articleId, domain.CommentShowEnable, companyId).Rows() |
| 287 | if err != nil { | 287 | if err != nil { |
| 288 | return nil, err | 288 | return nil, err |
| 289 | } | 289 | } |
| @@ -278,27 +278,11 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor | @@ -278,27 +278,11 @@ func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepositor | ||
| 278 | return &ArticleRepository{CachedRepository: cache} | 278 | return &ArticleRepository{CachedRepository: cache} |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | -// -- 首页统计数据 | ||
| 282 | -// with | ||
| 283 | -// -- 按查看权限查询文章 | ||
| 284 | -// -- 获取有标签的文章 | ||
| 285 | -// -- 过滤出可展示的文章id | ||
| 286 | -// t_article_and_tag_2 as ( | ||
| 287 | -// select article_and_tag.article_id , article_and_tag.tag_id | ||
| 288 | -// from article_and_tag | ||
| 289 | -// join article on article_and_tag.article_id = article.id | ||
| 290 | -// where article.deleted_at=0 | ||
| 291 | -// and article.company_id =1598224576532189184 | ||
| 292 | -// and article."show" =0 | ||
| 293 | -// and (article.target_user =0 or article.who_read @>'[1]') | ||
| 294 | -// ), | ||
| 295 | -// -- 查询人员已查看的文章 | ||
| 296 | -// t_user_read as( | ||
| 297 | -// select user_read_article.article_id from user_read_article where user_read_article.user_id =1 | ||
| 298 | -// ) | ||
| 299 | -// -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量 | ||
| 300 | -// select count(t_article_and_tag_2.article_id) as cnt_1 ,count(t_user_read.article_id) as cnt_2, t_article_and_tag_2.tag_id | ||
| 301 | -// from t_article_and_tag_2 | ||
| 302 | -// left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id | ||
| 303 | -// group by t_article_and_tag_2.tag_id | ||
| 304 | -// ; | 281 | +// select * |
| 282 | +// from article | ||
| 283 | +// join article_and_tag on article.id = article_and_tag.article_id | ||
| 284 | +// where article."show" =1 | ||
| 285 | +// and article_and_tag.tag_id =any(select article_tag.id from article_tag where category ='分组三' ) | ||
| 286 | +// and article_and_tag.tag_id =0 | ||
| 287 | +// and article.created_at >=0 and article.created_at <=9000000000 | ||
| 288 | +// and article.title like '%%' |
| @@ -121,8 +121,7 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti | @@ -121,8 +121,7 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti | ||
| 121 | ) | 121 | ) |
| 122 | queryFunc := func() (interface{}, error) { | 122 | queryFunc := func() (interface{}, error) { |
| 123 | tx = tx.Model(&ms). | 123 | tx = tx.Model(&ms). |
| 124 | - Where("company_id=?", companyId). | ||
| 125 | - Order("id asc") | 124 | + Where("company_id=?", companyId).Order("sort_by asc").Order("id asc") |
| 126 | 125 | ||
| 127 | if v, ok := queryOptions["name"]; ok { | 126 | if v, ok := queryOptions["name"]; ok { |
| 128 | tx = tx.Where("name like ?", v) | 127 | tx = tx.Where("name like ?", v) |
| 1 | -package repository | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "context" | ||
| 5 | - "github.com/jinzhu/copier" | ||
| 6 | - "github.com/pkg/errors" | ||
| 7 | - "github.com/tiptok/gocomm/pkg/cache" | ||
| 8 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
| 9 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
| 10 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 11 | - "gorm.io/gorm" | ||
| 12 | -) | ||
| 13 | - | ||
| 14 | -type CommentRepository struct { | ||
| 15 | - *cache.CachedRepository | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -func (repository *CommentRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.Comment) (*domain.Comment, error) { | ||
| 19 | - var ( | ||
| 20 | - err error | ||
| 21 | - m = &models.Comment{} | ||
| 22 | - tx = conn.DB() | ||
| 23 | - ) | ||
| 24 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 25 | - return nil, err | ||
| 26 | - } | ||
| 27 | - if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
| 28 | - return nil, tx.Error | ||
| 29 | - } | ||
| 30 | - dm.Id = m.Id | ||
| 31 | - return repository.ModelToDomainModel(m) | ||
| 32 | - | ||
| 33 | -} | ||
| 34 | - | ||
| 35 | -func (repository *CommentRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.Comment) (*domain.Comment, error) { | ||
| 36 | - var ( | ||
| 37 | - err error | ||
| 38 | - m *models.Comment | ||
| 39 | - tx = conn.DB() | ||
| 40 | - ) | ||
| 41 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 42 | - return nil, err | ||
| 43 | - } | ||
| 44 | - queryFunc := func() (interface{}, error) { | ||
| 45 | - tx = tx.Model(m).Updates(m) | ||
| 46 | - return nil, tx.Error | ||
| 47 | - } | ||
| 48 | - if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 49 | - return nil, err | ||
| 50 | - } | ||
| 51 | - return repository.ModelToDomainModel(m) | ||
| 52 | -} | ||
| 53 | - | ||
| 54 | -func (repository *CommentRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.Comment) (*domain.Comment, error) { | ||
| 55 | - var ( | ||
| 56 | - err error | ||
| 57 | - m *models.Comment | ||
| 58 | - tx = transaction.DB() | ||
| 59 | - ) | ||
| 60 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 61 | - return nil, err | ||
| 62 | - } | ||
| 63 | - oldVersion := dm.Version | ||
| 64 | - m.Version += 1 | ||
| 65 | - queryFunc := func() (interface{}, error) { | ||
| 66 | - tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
| 67 | - if tx.RowsAffected == 0 { | ||
| 68 | - return nil, domain.ErrUpdateFail | ||
| 69 | - } | ||
| 70 | - return nil, tx.Error | ||
| 71 | - } | ||
| 72 | - if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 73 | - return nil, err | ||
| 74 | - } | ||
| 75 | - return repository.ModelToDomainModel(m) | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -func (repository *CommentRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.Comment) (*domain.Comment, error) { | ||
| 79 | - var ( | ||
| 80 | - tx = conn.DB() | ||
| 81 | - m = &models.Comment{Id: dm.Identify().(int64)} | ||
| 82 | - ) | ||
| 83 | - queryFunc := func() (interface{}, error) { | ||
| 84 | - tx = tx.Where("id = ?", m.Id).Delete(m) | ||
| 85 | - return m, tx.Error | ||
| 86 | - } | ||
| 87 | - if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 88 | - return dm, err | ||
| 89 | - } | ||
| 90 | - return repository.ModelToDomainModel(m) | ||
| 91 | -} | ||
| 92 | - | ||
| 93 | -func (repository *CommentRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.Comment, error) { | ||
| 94 | - var ( | ||
| 95 | - err error | ||
| 96 | - tx = conn.DB() | ||
| 97 | - m = new(models.Comment) | ||
| 98 | - ) | ||
| 99 | - queryFunc := func() (interface{}, error) { | ||
| 100 | - tx = tx.Model(m).Where("id = ?", id).First(m) | ||
| 101 | - if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
| 102 | - return nil, domain.ErrNotFound | ||
| 103 | - } | ||
| 104 | - return m, tx.Error | ||
| 105 | - } | ||
| 106 | - cacheModel := new(models.Comment) | ||
| 107 | - cacheModel.Id = id | ||
| 108 | - if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
| 109 | - return nil, err | ||
| 110 | - } | ||
| 111 | - return repository.ModelToDomainModel(m) | ||
| 112 | -} | ||
| 113 | - | ||
| 114 | -func (repository *CommentRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Comment, error) { | ||
| 115 | - var ( | ||
| 116 | - tx = conn.DB() | ||
| 117 | - ms []*models.Comment | ||
| 118 | - dms = make([]*domain.Comment, 0) | ||
| 119 | - total int64 | ||
| 120 | - ) | ||
| 121 | - queryFunc := func() (interface{}, error) { | ||
| 122 | - tx = tx.Model(&ms).Order("id desc") | ||
| 123 | - if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
| 124 | - return dms, tx.Error | ||
| 125 | - } | ||
| 126 | - return dms, nil | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - if _, err := repository.Query(queryFunc); err != nil { | ||
| 130 | - return 0, nil, err | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | - for _, item := range ms { | ||
| 134 | - if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
| 135 | - return 0, dms, err | ||
| 136 | - } else { | ||
| 137 | - dms = append(dms, dm) | ||
| 138 | - } | ||
| 139 | - } | ||
| 140 | - return total, dms, nil | ||
| 141 | -} | ||
| 142 | - | ||
| 143 | -func (repository *CommentRepository) ModelToDomainModel(from *models.Comment) (*domain.Comment, error) { | ||
| 144 | - to := &domain.Comment{} | ||
| 145 | - err := copier.Copy(to, from) | ||
| 146 | - return to, err | ||
| 147 | -} | ||
| 148 | - | ||
| 149 | -func (repository *CommentRepository) DomainModelToModel(from *domain.Comment) (*models.Comment, error) { | ||
| 150 | - to := &models.Comment{} | ||
| 151 | - err := copier.Copy(to, from) | ||
| 152 | - return to, err | ||
| 153 | -} | ||
| 154 | - | ||
| 155 | -func NewCommentRepository(cache *cache.CachedRepository) domain.CommentRepository { | ||
| 156 | - return &CommentRepository{CachedRepository: cache} | ||
| 157 | -} |
| @@ -25,7 +25,7 @@ type Article struct { | @@ -25,7 +25,7 @@ type Article struct { | ||
| 25 | CountLove int `json:"countLove"` // 点赞数量 | 25 | CountLove int `json:"countLove"` // 点赞数量 |
| 26 | CountComment int `json:"countComment"` // 评论数量 | 26 | CountComment int `json:"countComment"` // 评论数量 |
| 27 | CountRead int `json:"countRead"` // 浏览数量 | 27 | CountRead int `json:"countRead"` // 浏览数量 |
| 28 | - Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示) | 28 | + Show ArticleShow `json:"show"` // 评论的展示状态(1显示,2不显示、) |
| 29 | Tags []int64 `json:"tags"` // 定性标签 | 29 | Tags []int64 `json:"tags"` // 定性标签 |
| 30 | Summary string `json:"summary"` // 内容概要 | 30 | Summary string `json:"summary"` // 内容概要 |
| 31 | // ...more | 31 | // ...more |
| @@ -60,12 +60,12 @@ func (a ArticleTarget) Named() string { | @@ -60,12 +60,12 @@ func (a ArticleTarget) Named() string { | ||
| 60 | return "" | 60 | return "" |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | -// 文章的展示状态(0显示、1不显示) | 63 | +// 文章的展示状态(1显示,2不显示) |
| 64 | type ArticleShow int | 64 | type ArticleShow int |
| 65 | 65 | ||
| 66 | const ( | 66 | const ( |
| 67 | - ArticleShowEnable ArticleShow = 0 | ||
| 68 | - ArticleShowDisable ArticleShow = 1 | 67 | + ArticleShowEnable ArticleShow = 1 |
| 68 | + ArticleShowDisable ArticleShow = 2 | ||
| 69 | ) | 69 | ) |
| 70 | 70 | ||
| 71 | func (a ArticleShow) Named() string { | 71 | func (a ArticleShow) Named() string { |
| @@ -27,17 +27,17 @@ type ArticleComment struct { | @@ -27,17 +27,17 @@ type ArticleComment struct { | ||
| 27 | CountReply int `json:"countReply"` // 回复数量 | 27 | CountReply int `json:"countReply"` // 回复数量 |
| 28 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 | 28 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 |
| 29 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | 29 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 |
| 30 | - Show CommentShow `json:"showState"` // 评论的展示状态(0显示、1不显示) | 30 | + Show CommentShow `json:"showState"` // 评论的展示状态(1显示、2不显示) |
| 31 | AtWho []UserSimple `json:"atWho"` // 填写评论时@的人 | 31 | AtWho []UserSimple `json:"atWho"` // 填写评论时@的人 |
| 32 | // ...more | 32 | // ...more |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | -// 评论的展示状态(0显示、1不显示) | 35 | +// 评论的展示状态(1显示、2不显示) |
| 36 | type CommentShow int | 36 | type CommentShow int |
| 37 | 37 | ||
| 38 | const ( | 38 | const ( |
| 39 | - CommentShowEnable CommentShow = 0 | ||
| 40 | - CommentShowDisable CommentShow = 1 | 39 | + CommentShowEnable CommentShow = 1 |
| 40 | + CommentShowDisable CommentShow = 2 | ||
| 41 | ) | 41 | ) |
| 42 | 42 | ||
| 43 | func (show CommentShow) Named() string { | 43 | func (show CommentShow) Named() string { |
| 1 | -package domain | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "context" | ||
| 5 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
| 6 | -) | ||
| 7 | - | ||
| 8 | -type Comment struct { | ||
| 9 | - Id int64 // 唯一标识 | ||
| 10 | - | ||
| 11 | - CreatedAt int64 `json:",omitempty"` | ||
| 12 | - UpdatedAt int64 `json:",omitempty"` | ||
| 13 | - DeletedAt int64 `json:",omitempty"` | ||
| 14 | - Version int `json:",omitempty"` | ||
| 15 | -} | ||
| 16 | - | ||
| 17 | -type CommentRepository interface { | ||
| 18 | - Insert(ctx context.Context, conn transaction.Conn, dm *Comment) (*Comment, error) | ||
| 19 | - Update(ctx context.Context, conn transaction.Conn, dm *Comment) (*Comment, error) | ||
| 20 | - UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Comment) (*Comment, error) | ||
| 21 | - Delete(ctx context.Context, conn transaction.Conn, dm *Comment) (*Comment, error) | ||
| 22 | - FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Comment, error) | ||
| 23 | - Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Comment, error) | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -func (m *Comment) Identify() interface{} { | ||
| 27 | - if m.Id == 0 { | ||
| 28 | - return nil | ||
| 29 | - } | ||
| 30 | - return m.Id | ||
| 31 | -} |
pkg/tool/oss/ali_oss.go
0 → 100644
| 1 | +package oss | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "fmt" | ||
| 6 | + "image" | ||
| 7 | + _ "image/jpeg" | ||
| 8 | + "net/http" | ||
| 9 | + "strings" | ||
| 10 | + "time" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type FileInfo struct { | ||
| 14 | + FileSize struct { | ||
| 15 | + Value string | ||
| 16 | + } | ||
| 17 | + Format struct { | ||
| 18 | + Value string | ||
| 19 | + } | ||
| 20 | + ImageHeight struct { | ||
| 21 | + Value string | ||
| 22 | + } | ||
| 23 | + ImageWidth struct { | ||
| 24 | + Value string | ||
| 25 | + } | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func GetImageInfo(url string) (info FileInfo, err error) { | ||
| 29 | + //ok := strings.HasPrefix(url, "https://timeless-world.oss-cn-shenzhen.aliyuncs.com") | ||
| 30 | + ok := strings.HasPrefix(url, "http") | ||
| 31 | + if !ok { | ||
| 32 | + return | ||
| 33 | + } | ||
| 34 | + ok = strings.Contains(url, "aliyuncs") | ||
| 35 | + if !ok { | ||
| 36 | + return | ||
| 37 | + } | ||
| 38 | + apiUrl := url + `?x-oss-process=image/info` | ||
| 39 | + req, err := http.NewRequest(http.MethodGet, apiUrl, nil) | ||
| 40 | + if err != nil { | ||
| 41 | + return info, err | ||
| 42 | + } | ||
| 43 | + httpclient := http.Client{ | ||
| 44 | + Timeout: 5 * time.Second, | ||
| 45 | + } | ||
| 46 | + resp, err := httpclient.Do(req) | ||
| 47 | + if err != nil { | ||
| 48 | + return info, err | ||
| 49 | + } | ||
| 50 | + defer resp.Body.Close() | ||
| 51 | + if resp.StatusCode != http.StatusOK { | ||
| 52 | + return | ||
| 53 | + } | ||
| 54 | + jDecoder := json.NewDecoder(resp.Body) | ||
| 55 | + err = jDecoder.Decode(&info) | ||
| 56 | + if err != nil { | ||
| 57 | + return info, err | ||
| 58 | + } | ||
| 59 | + return info, nil | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +// 获取视频封面图 | ||
| 63 | +func GetVideoCover(videoUrl string) (coverUrl string, w int, h int, err error) { | ||
| 64 | + ok := strings.HasPrefix(videoUrl, "http") | ||
| 65 | + if !ok { | ||
| 66 | + return | ||
| 67 | + } | ||
| 68 | + ok = strings.Contains(videoUrl, "aliyuncs") | ||
| 69 | + if !ok { | ||
| 70 | + return | ||
| 71 | + } | ||
| 72 | + videoUrl = videoUrl + "?x-oss-process=video/snapshot,t_100,f_jpg,m_fast" | ||
| 73 | + httpclient := http.Client{ | ||
| 74 | + Timeout: 5 * time.Second, | ||
| 75 | + } | ||
| 76 | + res, err := httpclient.Get(videoUrl) | ||
| 77 | + if err != nil || res.StatusCode != http.StatusOK { | ||
| 78 | + return videoUrl, 600, 600, fmt.Errorf("获取图片失败:%s", err) | ||
| 79 | + } | ||
| 80 | + defer res.Body.Close() | ||
| 81 | + m, _, err := image.Decode(res.Body) | ||
| 82 | + if err != nil { | ||
| 83 | + return videoUrl, 600, 600, fmt.Errorf("获取图片失败:%s", err) | ||
| 84 | + } | ||
| 85 | + return videoUrl, m.Bounds().Dx(), m.Bounds().Dy(), nil | ||
| 86 | +} |
pkg/tool/oss/ali_oss_test.go
0 → 100644
| 1 | +package oss | ||
| 2 | + | ||
| 3 | +import "testing" | ||
| 4 | + | ||
| 5 | +func TestGetVideoCover(t *testing.T) { | ||
| 6 | + | ||
| 7 | + cover, w, h, err := GetVideoCover("https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20230913/object/1694587897_yYfG6TYTsGMCKETxdnTEhAQjXpYGD3MB.mp4") | ||
| 8 | + t.Logf("cover=%v, w=%v, h=%v, err=%v", cover, w, h, err) | ||
| 9 | +} |
-
请 注册 或 登录 后发表评论