作者 yangfu

标签分类修改

正在显示 48 个修改的文件 包含 2147 行增加66 行删除
... ... @@ -10,3 +10,4 @@ import "core/article_type.api"
import "core/article.api"
import "core/role.api"
import "core/department.api"
import "core/article_category.api"
\ No newline at end of file
... ...
... ... @@ -333,6 +333,32 @@
]
}
},
"v1/mini/article_backup/{id}": {
"get": {
"summary": "小程序获取文章的编辑记录",
"operationId": "MiniGetArticleBackup",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MiniGetArticleBackupResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"article"
]
}
},
"v1/mini/article_comment": {
"post": {
"summary": "小程序填写文章的评论",
... ... @@ -766,7 +792,7 @@
"v1/mini/homepage/user_beliked": {
"post": {
"summary": "个人主页-获赞的列表",
"operationId": "miniHomepageUserBeliked",
"operationId": "miniHomepageUserBeLiked",
"responses": {
"200": {
"description": "A successful response.",
... ... @@ -1915,6 +1941,170 @@
]
}
},
"v1/system/article_category": {
"post": {
"summary": "标签分类保存",
"operationId": "articleCategorySave",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ArticleCategorySaveResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ArticleCategorySaveRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/system/article_category/options": {
"get": {
"summary": "标签分类下拉列表",
"operationId": "articleCategoryOptions",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/CategoryOptionsResponse"
}
}
},
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/system/article_category/search": {
"post": {
"summary": "标签分类搜索",
"operationId": "articleCategorySearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ArticleCategorySearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ArticleCategorySearchRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/system/article_category/{id}": {
"get": {
"summary": "标签分类详情",
"operationId": "articleCategoryGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ArticleCategoryGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"tags"
]
},
"delete": {
"summary": "标签分类删除",
"operationId": "articleCategoryDelete",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ArticleCategoryDeleteResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ArticleCategoryDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
},
"put": {
"summary": "标签分类更新",
"operationId": "articleCategoryUpdate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ArticleCategoryUpdateResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ArticleCategoryUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/system/article_comment/edit": {
"post": {
"summary": "管理后台变更评论",
... ... @@ -2323,6 +2513,34 @@
]
}
},
"v1/system/company/visible_switch": {
"post": {
"summary": "公司可见开关",
"operationId": "systemCompanyVisibleSwitch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/CompanyVisibleSwitchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/CompanyVisibleSwitchRequest"
}
}
],
"requestBody": {},
"tags": [
"company"
]
}
},
"v1/system/department/add": {
"post": {
"summary": "部门-新增",
... ... @@ -2875,6 +3093,162 @@
"company"
]
},
"ArticleCategoryDeleteRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "ArticleCategoryDeleteRequest",
"required": [
"id"
]
},
"ArticleCategoryDeleteResponse": {
"type": "object",
"title": "ArticleCategoryDeleteResponse"
},
"ArticleCategoryGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "ArticleCategoryGetRequest",
"required": [
"id"
]
},
"ArticleCategoryGetResponse": {
"type": "object",
"properties": {
"category": {
"$ref": "#/definitions/ArticleCategoryItem"
}
},
"title": "ArticleCategoryGetResponse",
"required": [
"category"
]
},
"ArticleCategoryItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 唯一标识"
},
"companyId": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"sortBy": {
"type": "integer",
"format": "int32",
"description": " 排序"
},
"enable": {
"type": "integer",
"format": "int32",
"description": " 启用状态 1:启用 2:禁用"
},
"other": {
"type": "string",
"description": " 其他备注说明"
}
},
"title": "ArticleCategoryItem",
"required": [
"companyId",
"name",
"sortBy",
"enable",
"other"
]
},
"ArticleCategorySaveRequest": {
"type": "object",
"properties": {
"category": {
"$ref": "#/definitions/ArticleCategoryItem"
}
},
"title": "ArticleCategorySaveRequest",
"required": [
"category"
]
},
"ArticleCategorySaveResponse": {
"type": "object",
"title": "ArticleCategorySaveResponse"
},
"ArticleCategorySearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
}
},
"title": "ArticleCategorySearchRequest",
"required": [
"page",
"size"
]
},
"ArticleCategorySearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/ArticleCategoryItem"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "ArticleCategorySearchResponse",
"required": [
"list",
"total"
]
},
"ArticleCategoryUpdateRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"category": {
"$ref": "#/definitions/ArticleCategoryItem"
}
},
"title": "ArticleCategoryUpdateRequest",
"required": [
"id",
"category"
]
},
"ArticleCategoryUpdateResponse": {
"type": "object",
"title": "ArticleCategoryUpdateResponse"
},
"ArticleCommentAndReply": {
"type": "object",
"properties": {
... ... @@ -3224,6 +3598,70 @@
"code"
]
},
"CategoryOptionValue": {
"type": "object",
"properties": {
"label": {
"type": "string",
"description": " 名称"
},
"value": {
"type": "integer",
"format": "int64",
"description": " 分类ID"
}
},
"title": "CategoryOptionValue",
"required": [
"label",
"value"
]
},
"CategoryOptions": {
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int64",
"description": " 分类ID"
},
"label": {
"type": "string",
"description": " 分组名称"
}
},
"title": "CategoryOptions",
"required": [
"value",
"label"
]
},
"CategoryOptionsRequest": {
"type": "object",
"properties": {
"": {
"type": "integer",
"format": "int64",
"description": " 公司ID"
}
},
"title": "CategoryOptionsRequest"
},
"CategoryOptionsResponse": {
"type": "object",
"properties": {
"options": {
"type": "array",
"items": {
"$ref": "#/definitions/CategoryOptions"
}
}
},
"title": "CategoryOptionsResponse",
"required": [
"options"
]
},
"CommentAtWho": {
"type": "object",
"properties": {
... ... @@ -3405,6 +3843,24 @@
"total"
]
},
"CompanyVisibleSwitchRequest": {
"type": "object",
"properties": {
"visible": {
"type": "boolean",
"format": "boolean",
"description": " 可见性 true:可被搜索 false:不可被搜索"
}
},
"title": "CompanyVisibleSwitchRequest",
"required": [
"visible"
]
},
"CompanyVisibleSwitchResponse": {
"type": "object",
"title": "CompanyVisibleSwitchResponse"
},
"Department": {
"type": "object",
"properties": {
... ... @@ -3808,12 +4264,31 @@
"type": "string"
}
},
"videos": {
"type": "array",
"items": {
"$ref": "#/definitions/Video"
}
},
"changeField": {
"type": "array",
"items": {
"type": "string"
}
},
"createdAt": {
"type": "integer",
"format": "int64"
},
"location": {
"$ref": "#/definitions/Location"
},
"action": {
"type": "string"
},
"show": {
"type": "integer",
"format": "int32"
}
},
"title": "MiniArticleBackupItem",
... ... @@ -3822,8 +4297,12 @@
"title",
"content",
"images",
"videos",
"changeField",
"createdAt",
"location"
"location",
"action",
"show"
]
},
"MiniArticleBackupSearchRequest": {
... ... @@ -4991,6 +5470,84 @@
"type": "object",
"title": "MiniEditUserInfoResponse"
},
"MiniGetArticleBackupRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"": {
"type": "integer",
"format": "int64",
"description": " 服务端自动获取"
}
},
"title": "MiniGetArticleBackupRequest",
"required": [
"id"
]
},
"MiniGetArticleBackupResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"title": {
"type": "string"
},
"content": {
"type": "string"
},
"images": {
"type": "array",
"items": {
"type": "string"
}
},
"videos": {
"type": "array",
"items": {
"$ref": "#/definitions/Video"
}
},
"changeField": {
"type": "array",
"items": {
"type": "string"
}
},
"createdAt": {
"type": "integer",
"format": "int64"
},
"location": {
"$ref": "#/definitions/Location"
},
"action": {
"type": "string"
},
"show": {
"type": "integer",
"format": "int32"
}
},
"title": "MiniGetArticleBackupResponse",
"required": [
"id",
"title",
"content",
"images",
"videos",
"changeField",
"createdAt",
"location",
"action",
"show"
]
},
"MiniGetArticleCommentRequest": {
"type": "object",
"properties": {
... ... @@ -5114,6 +5671,9 @@
"size": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string"
}
},
"title": "MiniHomePageUserFollowerSearchRequest",
... ... @@ -5210,10 +5770,14 @@
"format": "int32",
"description": " 数量"
},
"orderByHotScore": {
"orderByKey": {
"type": "string",
"default": "desc",
"description": " 热度排序 升序 asc 降序 desc"
"description": " 按规则排序 (热度:HotScore All:时间排序 Time:时间排序)"
},
"orderByValue": {
"type": "string",
"description": " 排序值 升序 asc 降序 desc"
},
"keywords": {
"type": "string",
... ... @@ -5224,7 +5788,7 @@
"format": "int64",
"description": " 开始时间"
},
"beginTime": {
"endTime": {
"type": "integer",
"format": "int64",
"description": " 结束时间"
... ... @@ -5234,7 +5798,8 @@
"required": [
"authorId",
"size",
"orderByHotScore"
"orderByKey",
"orderByValue"
]
},
"MiniHomepageUserNewsResposne": {
... ... @@ -5250,12 +5815,17 @@
"type": "integer",
"format": "int64",
"description": " 最后文章ID"
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "MiniHomepageUserNewsResposne",
"required": [
"list",
"lastArticleId"
"lastArticleId",
"total"
]
},
"MiniListArticleCommentRequest": {
... ... @@ -7247,6 +7817,10 @@
"type": "integer",
"format": "int32",
"description": "每页行数"
},
"orderMode": {
"type": "string",
"description": "排序方式"
}
},
"title": "SystemArticleSearchRequest",
... ... @@ -7353,7 +7927,6 @@
"title": "SystemArticleUpdateRequest",
"required": [
"id",
"template",
"section",
"title",
"images",
... ... @@ -8584,9 +9157,14 @@
"TagOptions": {
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int64",
"description": " 分类ID"
},
"label": {
"type": "string",
"description": " 分名称"
"description": " 分名称"
},
"options": {
"type": "array",
... ... @@ -8597,6 +9175,7 @@
},
"title": "TagOptions",
"required": [
"value",
"label",
"options"
]
... ...
@server(
prefix: v1/system
group: tags
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
@doc "标签分类详情"
@handler articleCategoryGet
get /article_category/:id (ArticleCategoryGetRequest) returns (ArticleCategoryGetResponse)
@doc "标签分类保存"
@handler articleCategorySave
post /article_category (ArticleCategorySaveRequest) returns (ArticleCategorySaveResponse)
@doc "标签分类删除"
@handler articleCategoryDelete
delete /article_category/:id (ArticleCategoryDeleteRequest) returns (ArticleCategoryDeleteResponse)
@doc "标签分类更新"
@handler articleCategoryUpdate
put /article_category/:id (ArticleCategoryUpdateRequest) returns (ArticleCategoryUpdateResponse)
@doc "标签分类搜索"
@handler articleCategorySearch
post /article_category/search (ArticleCategorySearchRequest) returns (ArticleCategorySearchResponse)
@doc "标签分类下拉列表"
@handler articleCategoryOptions
get /article_category/options (CategoryOptionsRequest) returns (CategoryOptionsResponse)
}
@server(
prefix: v1/system
group: tags
)
service Core {
@doc "标签分类初始化"
@handler articleCategoryInit
get /article_category/init
}
type (
ArticleCategoryGetRequest {
Id int64 `path:"id"`
}
ArticleCategoryGetResponse struct{
ArticleCategory ArticleCategoryItem `json:"category"`
}
ArticleCategorySaveRequest struct{
ArticleCategory ArticleCategoryItem `json:"category"`
}
ArticleCategorySaveResponse struct{}
ArticleCategoryDeleteRequest struct{
Id int64 `path:"id"`
}
ArticleCategoryDeleteResponse struct{}
ArticleCategoryUpdateRequest struct{
Id int64 `path:"id"`
ArticleCategory ArticleCategoryItem `json:"category"`
}
ArticleCategoryUpdateResponse struct{}
ArticleCategorySearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
ArticleCategorySearchResponse{
List []ArticleCategoryItem `json:"list"`
Total int64 `json:"total"`
}
ArticleCategoryItem struct{
Id int64 `json:"id,optional"` // 唯一标识
CompanyId int64 `json:"companyId,optional,omitempty"`
Name string `json:"name"`
SortBy int `json:"sortBy,optional,omitempty"` // 排序
Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用
Other string `json:"other,optional,omitempty"` // 其他备注说明
}
)
//标签下拉列表
type (
CategoryOptionsRequest {
CompanyId int64 `path:",optional"` // 公司ID
}
CategoryOptionsResponse {
Options []CategoryOptions `json:"options"`
}
CategoryOptions {
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分组名称
//Options []CategoryOptionValue `json:"options,omitempty"`
}
CategoryOptionValue {
Label string `json:"label"` // 名称
Value int64 `json:"value"` // 分类ID
}
)
\ No newline at end of file
... ...
... ... @@ -46,10 +46,11 @@ type (
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
//Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` //排序
CategoryId int64 `json:"categoryId"` // 标签Id
}
TagCreateResponse {
... ... @@ -64,7 +65,8 @@ type (
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
//Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签Id
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` // 排序
... ... @@ -86,6 +88,7 @@ type (
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签分类Id
Remark string `json:"remark"` // 备注
Other string `json:"other"`
SortBy int `json:"sortBy,optional"` // 排序
... ... @@ -99,7 +102,7 @@ type (
Size int `json:"size"`
CompanyId int64 `json:",optional"`
TagName string `json:"tagName,optional"`
Category string `json:"category,optional"`
CategoryId int64 `json:"categoryId,optional"`
Remark string `json:"remark,optional"`
}
TagListResponse {
... ... @@ -111,9 +114,11 @@ type (
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签分类Id
Remark string `json:"remark"` // 备注
CreatedAt int64 `json:"createdAt"`
SortBy int `json:"sortBy,optional"` // 排序
Removeable bool `json:"removeable,optional"` // 可删除
}
)
... ... @@ -137,7 +142,8 @@ type (
Options []TagOptions `json:"options"`
}
TagOptions {
Label string `json:"label"` // 分组名称
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分类名称
Options []TagOptionValue `json:"options"`
}
TagOptionValue {
... ...
... ... @@ -41,6 +41,10 @@ service Core {
jwt : SystemAuth
)
service Core {
@doc "公司可见开关"
@handler systemCompanyVisibleSwitch
post /system/company/visible_switch(CompanyVisibleSwitchRequest) returns (CompanyVisibleSwitchResponse)
@doc "公司搜索"
@handler systemCompanySearch
post /system/company/search(CompanySearchRequest) returns (CompanySearchResponse)
... ... @@ -70,6 +74,13 @@ type (
Logo string `json:"logo,omitempty"` // 公司LOGO
JoinedFlag int `json:"joinedFlag"` // 已加入标识(1:已加入 其他:未加入)
}
CompanyVisibleSwitchRequest{
Visible bool `json:"visible"` // 可见性 true:可被搜索 false:不可被搜索
}
CompanyVisibleSwitchResponse{
}
)
// 公司职位搜索
... ...
... ... @@ -2,7 +2,7 @@ Name: discuss
Host: 0.0.0.0
Port: 8081
Verbose: false
Migrate: false
Migrate: true
Timeout: 30000
# CertFile: ./key/fjmaimaimai.com_bundle.crt
# KeyFile: ./key/fjmaimaimai.com.key
... ...
package company
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/company"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemCompanyVisibleSwitchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CompanyVisibleSwitchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := company.NewSystemCompanyVisibleSwitchLogic(r.Context(), svcCtx)
resp, err := l.SystemCompanyVisibleSwitch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -445,6 +445,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/system/company/visible_switch",
Handler: company.SystemCompanyVisibleSwitchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/system/company/search",
Handler: company.SystemCompanySearchHandler(serverCtx),
},
... ... @@ -678,4 +683,55 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/article_category/:id",
Handler: tags.ArticleCategoryGetHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_category",
Handler: tags.ArticleCategorySaveHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article_category/:id",
Handler: tags.ArticleCategoryDeleteHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/article_category/:id",
Handler: tags.ArticleCategoryUpdateHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_category/search",
Handler: tags.ArticleCategorySearchHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_category/options",
Handler: tags.ArticleCategoryOptionsHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1/system"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/article_category/init",
Handler: tags.ArticleCategoryInitHandler(serverCtx),
},
},
rest.WithPrefix("/v1/system"),
)
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func ArticleCategoryDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategoryDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategoryDeleteLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategoryDelete(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func ArticleCategoryGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategoryGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategoryGetLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategoryGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
)
func ArticleCategoryInitHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := tags.NewArticleCategoryInitLogic(r.Context(), svcCtx)
err := l.ArticleCategoryInit()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func ArticleCategoryOptionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CategoryOptionsRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategoryOptionsLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategoryOptions(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func ArticleCategorySaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategorySaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategorySaveLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategorySave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func ArticleCategorySearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategorySearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategorySearchLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategorySearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func ArticleCategoryUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ArticleCategoryUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewArticleCategoryUpdateLogic(r.Context(), svcCtx)
resp, err := l.ArticleCategoryUpdate(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -47,10 +47,15 @@ func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest)
countDataMap[val.TagId] = val
}
tagCategory := []string{}
tagCount := []types.ArticleTagCount{}
_, categoryList, _ := l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, req.CompanyId, domain.NewQueryOptions().MustWithKV("enable", 1))
tagCount := make([]types.ArticleTagCount, 0)
tagCategory := domain.Values(categoryList, func(item *domain.ArticleCategory) string {
return item.Name
})
categoryMap := lo.KeyBy(categoryList, func(item *domain.ArticleCategory) int64 {
return item.Id
})
for _, val := range allTags {
tagCategory = append(tagCategory, val.Category)
m := types.ArticleTagCount{
TagCategory: val.Category,
TagId: val.Id,
... ... @@ -65,9 +70,13 @@ func (l *MiniShowHomePageLogic) MiniShowHomePage(req *types.MiniHomePageRequest)
m.TotalArticle = count.TotalArticle
m.ReadArticle = count.ReadArticle
}
if v, ok := categoryMap[val.CategoryId]; ok {
m.TagCategory = v.Name
} else {
continue
}
tagCount = append(tagCount, m)
}
tagCategory = lo.Uniq(tagCategory)
resp = &types.MiniHomePageResponse{
TagCategory: tagCategory,
Tags: tagCount,
... ...
... ... @@ -91,6 +91,10 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
if lo.Contains(companyJoiningList, company.Id) {
company.JoinedFlag = 0
}
// 过滤掉不可见且未加入的企业。
if company.JoinedFlag != 1 && item.Visible == 0 {
return
}
resp.List = append(resp.List, company)
})
resp.Total = total
... ...
... ... @@ -38,6 +38,7 @@ func (l *MiniCompanySearchLogic) MiniCompanySearch(req *types.CompanySearchReque
if req.Code != "" {
queryOptions.WithKV("code", req.Code)
}
queryOptions.MustWithKV("visible", 1)
total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
... ...
package company
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemCompanyVisibleSwitchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemCompanyVisibleSwitchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemCompanyVisibleSwitchLogic {
return &SystemCompanyVisibleSwitchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemCompanyVisibleSwitchLogic) SystemCompanyVisibleSwitch(req *types.CompanyVisibleSwitchRequest) (resp *types.CompanyVisibleSwitchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
company *domain.Company
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if company, err = l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, userToken.CompanyId); err != nil {
return nil, xerr.NewErrMsg("设置失败")
}
company.Visible = lo.Ternary(req.Visible, 1, 0)
if company, err = l.svcCtx.CompanyRepository.UpdateWithVersion(l.ctx, conn, company); err != nil {
return nil, xerr.NewErrMsg("设置失败")
}
resp = &types.CompanyVisibleSwitchResponse{}
return
}
... ...
package tags
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategoryDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryDeleteLogic {
return &ArticleCategoryDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryDeleteLogic) ArticleCategoryDelete(req *types.ArticleCategoryDeleteRequest) (resp *types.ArticleCategoryDeleteResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package tags
import (
"context"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategoryGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryGetLogic {
return &ArticleCategoryGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryGetLogic) ArticleCategoryGet(req *types.ArticleCategoryGetRequest) (resp *types.ArticleCategoryGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ArticleCategory
)
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
resp = &types.ArticleCategoryGetResponse{
ArticleCategory: NewTypesArticleCategory(dm),
}
return
}
... ...
package tags
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"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"
)
type ArticleCategoryInitLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryInitLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryInitLogic {
return &ArticleCategoryInitLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryInitLogic) ArticleCategoryInit() error {
var (
conn = l.svcCtx.DefaultDBConn()
companyList []*domain.Company
categoryList = []*domain.ArticleCategory{
{
Name: "机会风险",
SortBy: 1,
Enable: 1,
Other: "",
},
{
Name: "紧急重要",
SortBy: 2,
Enable: 2,
Other: "",
},
}
dm *domain.ArticleCategory
err error
)
_, companyList, _ = l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions())
for _, company := range companyList {
for _, category := range categoryList {
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, company.Id, category.Name); err == nil && dm != nil {
continue
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
articleCategory := &domain.ArticleCategory{
Name: category.Name,
SortBy: category.SortBy,
Enable: category.Enable,
Other: category.Other,
CompanyId: company.Id,
}
articleCategory, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, articleCategory)
if err != nil {
return err
}
_, tagList, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, company.Id, domain.NewQueryOptions().WithKV("category", articleCategory.Name))
for _, tag := range tagList {
if tag.CategoryId != 0 {
continue
}
tag.CategoryId = articleCategory.Id
if _, err = l.svcCtx.ArticleTagRepository.UpdateWithVersion(l.ctx, conn, tag); err != nil {
break
}
}
logx.Info(fmt.Sprintf("初始化 公司:%v(%d) 标签分类:%v(%d) 标签数:%v", company.Name, company.Id, articleCategory.Name, articleCategory.Id, len(tagList)))
return err
}, true); err != nil {
return xerr.NewErrMsg("保存失败")
}
}
}
return nil
}
... ...
package tags
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/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategoryOptionsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryOptionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryOptionsLogic {
return &ArticleCategoryOptionsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryOptionsLogic) ArticleCategoryOptions(req *types.CategoryOptionsRequest) (resp *types.CategoryOptionsResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ArticleCategory
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().WithKV("enable", 1)
_, dms, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, userToken.CompanyId, queryOptions)
list := make([]types.CategoryOptions, 0)
for _, item := range dms {
list = append(list, types.CategoryOptions{
Label: item.Name,
Value: item.Id,
})
}
resp = &types.CategoryOptionsResponse{
Options: list,
}
return
}
... ...
package tags
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategorySaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategorySaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategorySaveLogic {
return &ArticleCategorySaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategorySaveLogic) ArticleCategorySave(req *types.ArticleCategorySaveRequest) (resp *types.ArticleCategorySaveResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ArticleCategory
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
// 唯一判断
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, userToken.CompanyId, req.ArticleCategory.Name); err == nil && dm != nil {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在分类`%s`", dm.Name))
}
dm = NewDomainArticleCategory(req.ArticleCategory)
dm.CompanyId = userToken.CompanyId
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("保存失败")
}
resp = &types.ArticleCategorySaveResponse{}
return
}
func NewDomainArticleCategory(item types.ArticleCategoryItem) *domain.ArticleCategory {
return &domain.ArticleCategory{
Name: item.Name,
Enable: item.Enable,
SortBy: item.SortBy,
Other: item.Other,
}
}
func NewTypesArticleCategory(item *domain.ArticleCategory) types.ArticleCategoryItem {
return types.ArticleCategoryItem{
Id: item.Id,
Name: item.Name,
Enable: item.Enable,
SortBy: item.SortBy,
Other: item.Other,
}
}
... ...
package tags
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/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategorySearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategorySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategorySearchLogic {
return &ArticleCategorySearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategorySearchLogic) ArticleCategorySearch(req *types.ArticleCategorySearchRequest) (resp *types.ArticleCategorySearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ArticleCategory
total int64
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
total, dms, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, userToken.CompanyId, queryOptions)
list := make([]types.ArticleCategoryItem, 0)
for _, item := range dms {
list = append(list, NewTypesArticleCategory(item))
}
resp = &types.ArticleCategorySearchResponse{
List: list,
Total: total,
}
return
}
... ...
package tags
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ArticleCategoryUpdateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewArticleCategoryUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleCategoryUpdateLogic {
return &ArticleCategoryUpdateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ArticleCategoryUpdateLogic) ArticleCategoryUpdate(req *types.ArticleCategoryUpdateRequest) (resp *types.ArticleCategoryUpdateResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ArticleCategory
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 不可编辑判断
if dm.Name != req.ArticleCategory.Name {
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, userToken.CompanyId, req.ArticleCategory.Name); err == nil && dm != nil {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在分类`%s`", dm.Name))
}
}
// 赋值
dm.Name = req.ArticleCategory.Name
dm.SortBy = req.ArticleCategory.SortBy
dm.Enable = req.ArticleCategory.Enable
dm.Other = req.ArticleCategory.Other
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ArticleCategoryUpdateResponse{}
return
}
... ...
... ... @@ -30,18 +30,24 @@ func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateT
// 创建标签
func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.TagCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
var (
conn = l.svcCtx.DefaultDBConn()
articleCategory *domain.ArticleCategory
)
if articleCategory, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.CategoryId); err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
//检查重复
cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, map[string]interface{}{
"name": req.Name,
"category": req.Category,
"categoryId": req.CategoryId,
"countOnly": true,
})
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
if cnt > 0 {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name))
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", articleCategory.Name, req.Name))
}
newTag := &domain.ArticleTag{
... ... @@ -53,15 +59,17 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
Version: 0,
Image: domain.Image{},
Name: req.Name,
Category: req.Category,
Category: articleCategory.Name,
CategoryId: articleCategory.Id,
Remark: req.Remark,
Other: req.Other,
SortBy: int64(req.SortBy),
DataFrom: 1,
}
err = newTag.SetCategory(req.Category)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
//err = newTag.SetCategory(req.Category)
//if err != nil {
// return nil, xerr.NewErrMsgErr("添加标签失败", err)
//}
if len(req.Image) > 0 {
//获取图片的尺寸大小
fInfo, _ := oss.GetImageInfo(req.Image)
... ...
... ... @@ -33,6 +33,9 @@ func (l *DeleteTagLogic) DeleteTag(req *types.TagDeleteRequest) (resp *types.Tag
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("删除标签失败")
}
if oldTag.DataFrom == 0 {
return nil, xerr.NewErrMsg("系统标签不可删除")
}
_, err = l.svcCtx.ArticleTagRepository.Delete(l.ctx, conn, oldTag)
if err != nil {
return nil, xerr.NewErrMsg("删除标签失败")
... ...
... ... @@ -30,21 +30,26 @@ func NewEditTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditTagLo
// 编辑标签
func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
var (
conn = l.svcCtx.DefaultDBConn()
articleCategory *domain.ArticleCategory
)
//检查重复
queryOptions := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("name", req.Name).
MustWithKV("category", req.Category).
MustWithKV("categoryId", req.CategoryId).
WithOffsetLimit(1, 1)
if articleCategory, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.CategoryId); err != nil {
return nil, xerr.NewErrMsgErr("标签分类不存在失败", err)
}
_, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("修改标签失败", err)
}
if len(tagList) > 0 {
if tagList[0].Id != req.Id {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name))
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", articleCategory.Name, req.Name))
}
}
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
... ... @@ -66,15 +71,16 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe
Height: h,
}
}
oldTag.Category = req.Category
oldTag.Name = req.Name
oldTag.Remark = req.Remark
oldTag.Other = req.Other
oldTag.SortBy = int64(req.SortBy)
err = oldTag.SetCategory(req.Category)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
oldTag.CategoryId = articleCategory.Id
oldTag.Category = articleCategory.Name
//err = oldTag.SetCategory(req.Category)
//if err != nil {
// return nil, xerr.NewErrMsgErr("添加标签失败", err)
//}
oldTag, err = l.svcCtx.ArticleTagRepository.Update(l.ctx, conn, oldTag)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
... ...
... ... @@ -39,6 +39,7 @@ func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetRespon
Image: oldTag.Image.Url,
Name: oldTag.Name,
Category: oldTag.Category,
CategoryId: oldTag.CategoryId,
Remark: oldTag.Remark,
Other: oldTag.Other,
SortBy: int(oldTag.SortBy),
... ...
... ... @@ -24,11 +24,14 @@ func NewSearchTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchT
}
func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagListResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
var (
conn = l.svcCtx.DefaultDBConn()
categoryMap = make(map[int64]*domain.ArticleCategory)
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
if len(req.Category) > 0 {
queryOptions = queryOptions.MustWithKV("category", "%"+req.Category+"%")
if req.CategoryId > 0 {
queryOptions = queryOptions.MustWithKV("categoryId", req.CategoryId)
}
if len(req.TagName) > 0 {
queryOptions = queryOptions.MustWithKV("name", "%"+req.TagName+"%")
... ... @@ -51,9 +54,14 @@ func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagLi
Image: tagList[i].Image.Url,
Name: tagList[i].Name,
Category: tagList[i].Category,
CategoryId: tagList[i].CategoryId,
Remark: tagList[i].Remark,
CreatedAt: tagList[i].CreatedAt,
SortBy: int(tagList[i].SortBy),
Removeable: tagList[i].DataFrom != 0,
}
if category, _ := domain.LazyLoad(categoryMap, l.ctx, conn, tagList[i].CategoryId, l.svcCtx.ArticleCategoryRepository.FindOne); category != nil {
resp.List[i].Category = category.Name
}
}
return resp, nil
... ...
... ... @@ -3,6 +3,7 @@ package user
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"strconv"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -109,11 +110,23 @@ func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
// 初始设置文章标签
queryOption := domain.NewQueryOptions().WithCountOnly()
conn := l.svcCtx.DefaultDBConn()
cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, companyId, queryOption)
if err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
categoryList := []*domain.ArticleCategory{
{
Name: "机会风险",
SortBy: 1,
Enable: 1,
Other: "",
CompanyId: companyId,
},
{
Name: "紧急重要",
SortBy: 2,
Enable: 1,
Other: "",
CompanyId: companyId,
},
}
if cnt == 0 {
articleTags := []*domain.ArticleTag{
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/test/20231115/object/index_imp_01.png", Width: 0, Height: 0},
... ... @@ -168,11 +181,37 @@ func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
Name: "小机会低风险", Category: "机会风险", Remark: "全员警戒马上解决", SortBy: 13,
},
}
cnt, _, err := l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, companyId, queryOption)
if cnt == 0 {
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
for _, category := range categoryList {
category, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, category)
if err != nil {
return err
}
}
cnt, _, err = l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, companyId, queryOption)
if err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
}
for _, tag := range articleTags {
for _, category := range categoryList {
if category.Name == tag.Category {
tag.CategoryId = category.Id
}
}
}
if cnt == 0 {
err = l.svcCtx.ArticleTagRepository.CreateInBatches(l.ctx, conn, articleTags)
if err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
}
}
return nil
}, true); err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
}
}
return nil
}
... ...
... ... @@ -33,6 +33,7 @@ type ServiceContext struct {
ArticleRepository domain.ArticleRepository
ArticleSectionRepository domain.ArticleSectionRepository
ArticleTagRepository domain.ArticleTagRepository
ArticleCategoryRepository domain.ArticleCategoryRepository
ArticleAndTagRepository domain.ArticleAndTagRepository
CompanyRepository domain.CompanyRepository
... ... @@ -98,6 +99,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
UserRepository: repository.NewUserRepository(cache.NewCachedRepository(mlCache)),
UserReadArticleRepository: repository.NewUserReadArticleRepository(cache.NewCachedRepository(mlCache)),
ArticleTagRepository: repository.NewArticleTagRepository(cache.NewCachedRepository(mlCache)),
ArticleCategoryRepository: repository.NewArticleCategoryRepository(cache.NewCachedRepository(mlCache)),
UserRoleRepository: repository.NewUserRoleRepository(cache.NewCachedRepository(mlCache)),
}
}
... ...
... ... @@ -351,10 +351,10 @@ type TagCreateRequest struct {
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` //排序
CategoryId int64 `json:"categoryId"` // 标签Id
}
type TagCreateResponse struct {
... ... @@ -366,7 +366,7 @@ type TagEditRequest struct {
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签Id
Remark string `json:"remark,optional"` // 备注
Other string `json:"other,optional"`
SortBy int `json:"sortBy,optional"` // 排序
... ... @@ -386,6 +386,7 @@ type TagGetResponse struct {
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签分类Id
Remark string `json:"remark"` // 备注
Other string `json:"other"`
SortBy int `json:"sortBy,optional"` // 排序
... ... @@ -396,7 +397,7 @@ type TagListRequest struct {
Size int `json:"size"`
CompanyId int64 `json:",optional"`
TagName string `json:"tagName,optional"`
Category string `json:"category,optional"`
CategoryId int64 `json:"categoryId,optional"`
Remark string `json:"remark,optional"`
}
... ... @@ -410,9 +411,11 @@ type TagItem struct {
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类
CategoryId int64 `json:"categoryId"` // 标签分类Id
Remark string `json:"remark"` // 备注
CreatedAt int64 `json:"createdAt"`
SortBy int `json:"sortBy,optional"` // 排序
Removeable bool `json:"removeable,optional"` // 可删除
}
type TagDeleteRequest struct {
... ... @@ -433,7 +436,8 @@ type TagOptionsResponse struct {
}
type TagOptions struct {
Label string `json:"label"` // 分组名称
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分类名称
Options []TagOptionValue `json:"options"`
}
... ... @@ -862,6 +866,13 @@ type Company struct {
JoinedFlag int `json:"joinedFlag"` // 已加入标识(1:已加入 其他:未加入)
}
type CompanyVisibleSwitchRequest struct {
Visible bool `json:"visible"` // 可见性 true:可被搜索 false:不可被搜索
}
type CompanyVisibleSwitchResponse struct {
}
type CompanyPositionsSearchRequest struct {
}
... ... @@ -1494,3 +1505,70 @@ type DepartmentListResponse struct {
List []Department `json:"list"`
Total int64 `json:"total"`
}
type ArticleCategoryGetRequest struct {
Id int64 `path:"id"`
}
type ArticleCategoryGetResponse struct {
ArticleCategory ArticleCategoryItem `json:"category"`
}
type ArticleCategorySaveRequest struct {
ArticleCategory ArticleCategoryItem `json:"category"`
}
type ArticleCategorySaveResponse struct {
}
type ArticleCategoryDeleteRequest struct {
Id int64 `path:"id"`
}
type ArticleCategoryDeleteResponse struct {
}
type ArticleCategoryUpdateRequest struct {
Id int64 `path:"id"`
ArticleCategory ArticleCategoryItem `json:"category"`
}
type ArticleCategoryUpdateResponse struct {
}
type ArticleCategorySearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type ArticleCategorySearchResponse struct {
List []ArticleCategoryItem `json:"list"`
Total int64 `json:"total"`
}
type ArticleCategoryItem struct {
Id int64 `json:"id,optional"` // 唯一标识
CompanyId int64 `json:"companyId,optional,omitempty"`
Name string `json:"name"`
SortBy int `json:"sortBy,optional,omitempty"` // 排序
Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用
Other string `json:"other,optional,omitempty"` // 其他备注说明
}
type CategoryOptionsRequest struct {
CompanyId int64 `path:",optional"` // 公司ID
}
type CategoryOptionsResponse struct {
Options []CategoryOptions `json:"options"`
}
type CategoryOptions struct {
Value int64 `json:"value"` // 分类ID
Label string `json:"label"` // 分组名称
}
type CategoryOptionValue struct {
Label string `json:"label"` // 名称
Value int64 `json:"value"` // 分类ID
}
... ...
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
email: "email"
version: "v1"
)
@server(
prefix: article_category/v1
group: article_category
jwt: JwtAuth
)
service Core {
@doc "详情"
@handler article_categoryGet
get /article_category/:id (ArticleCategoryGetRequest) returns (ArticleCategoryGetResponse)
@doc "保存"
@handler article_categorySave
post /article_category (ArticleCategorySaveRequest) returns (ArticleCategorySaveResponse)
@doc "删除"
@handler article_categoryDelete
delete /article_category/:id (ArticleCategoryDeleteRequest) returns (ArticleCategoryDeleteResponse)
@doc "更新"
@handler article_categoryUpdate
put /article_category/:id (ArticleCategoryUpdateRequest) returns (ArticleCategoryUpdateResponse)
@doc "搜索"
@handler article_categorySearch
post /article_category/search (ArticleCategorySearchRequest) returns (ArticleCategorySearchResponse)
}
type (
ArticleCategoryGetRequest {
Id int64 `path:"id"`
}
ArticleCategoryGetResponse struct{
ArticleCategory ArticleCategoryItem `json:"article_category"`
}
ArticleCategorySaveRequest struct{
ArticleCategory ArticleCategoryItem `json:"article_category"`
}
ArticleCategorySaveResponse struct{}
ArticleCategoryDeleteRequest struct{
Id int64 `path:"id"`
}
ArticleCategoryDeleteResponse struct{}
ArticleCategoryUpdateRequest struct{
Id int64 `path:"id"`
ArticleCategory ArticleCategoryItem `json:"article_category"`
}
ArticleCategoryUpdateResponse struct{}
ArticleCategorySearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
ArticleCategorySearchResponse{
List []ArticleCategoryItem `json:"list"`
Total int64 `json:"total"`
}
ArticleCategoryItem struct{
}
)
// logic CRUD
// Save
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ArticleCategory
//)
//// 唯一判断
//dm = NewDomainArticleCategory(req.ArticleCategory)
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("保存失败")
//}
////resp = &types.ArticleCategorySaveResponse{}
//return
//func NewDomainArticleCategory(item types.ArticleCategoryItem) *domain.ArticleCategory {
// return &domain.ArticleCategory{
// }
//}
//
//func NewTypesArticleCategory(item *domain.ArticleCategory) types.ArticleCategoryItem {
// return types.ArticleCategoryItem{
// Id: item.Id,
// }
//}
// Get
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ArticleCategory
//)
//// 货号唯一
//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//resp = &types.ArticleCategoryGetResponse{
// ArticleCategory: NewTypesArticleCategory(dm),
//}
//return
// Delete
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ArticleCategory
//)
//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// if dm, err = l.svcCtx.ArticleCategoryRepository.Delete(l.ctx, conn, dm); err != nil {
// return err
// }
// return nil
//}, true); err != nil {
// return nil, xerr.NewErrMsgErr("移除失败", err)
//}
//return
// Search
//var (
// conn = l.svcCtx.DefaultDBConn()
// dms []*domain.ArticleCategory
// total int64
//)
//
//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
// WithKV("", "")
//total, dms, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, queryOptions)
//list := make([]types.ArticleCategoryItem, 0)
//for i := range dms {
// list = append(list, NewTypesArticleCategory(dms[i]))
//}
//resp = &types.ArticleCategorySearchResponse{
// List: list,
// Total: total,
//}
//return
// Update
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ArticleCategory
//)
//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//// 不可编辑判断
//// 赋值
//// 更新
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("更新失败")
//}
//resp = &types.ArticleCategoryUpdateResponse{}
//return
... ...
syntax = "proto3";
option go_package ="./pb";
package pb;
message ArticleCategoryGetReq {
int64 Id = 1;
}
message ArticleCategoryGetResp{
ArticleCategoryItem User = 1;
}
message ArticleCategorySaveReq {
}
message ArticleCategorySaveResp{
}
message ArticleCategoryDeleteReq {
int64 Id = 1;
}
message ArticleCategoryDeleteResp{
}
message ArticleCategoryUpdateReq {
int64 Id = 1;
}
message ArticleCategoryUpdateResp{
}
message ArticleCategorySearchReq {
int64 PageNumber = 1;
int64 PageSize = 2;
}
message ArticleCategorySearchResp{
repeated ArticleCategoryItem List =1;
int64 Total =2;
}
message ArticleCategoryItem {
}
service ArticleCategoryService {
rpc ArticleCategoryGet(ArticleCategoryGetReq) returns(ArticleCategoryGetResp);
rpc ArticleCategorySave(ArticleCategorySaveReq) returns(ArticleCategorySaveResp);
rpc ArticleCategoryDelete(ArticleCategoryDeleteReq) returns(ArticleCategoryDeleteResp);
rpc ArticleCategoryUpdate(ArticleCategoryUpdateReq) returns(ArticleCategoryUpdateResp);
rpc ArticleCategorySearch(ArticleCategorySearchReq) returns(ArticleCategorySearchResp);
}
... ...
... ... @@ -7,23 +7,24 @@ import (
func Migrate(db *gorm.DB) {
modelsList := []interface{}{
&models.Article{},
&models.ArticleSection{},
&models.ArticleBackup{},
&models.ArticleDraft{},
&models.ArticleComment{},
&models.ArticleTag{},
&models.UserLoveFlag{},
&models.UserReadArticle{},
&models.User{},
&models.UserRole{},
&models.Role{},
&models.Company{},
&models.UserFollow{},
&models.MessageSystem{},
&models.MessageBusiness{},
&models.Department{},
&models.ArticleAndTag{},
//&models.Article{},
//&models.ArticleSection{},
//&models.ArticleBackup{},
//&models.ArticleDraft{},
//&models.ArticleComment{},
//&models.ArticleTag{},
//&models.UserLoveFlag{},
//&models.UserReadArticle{},
//&models.User{},
//&models.UserRole{},
//&models.Role{},
//&models.Company{},
//&models.UserFollow{},
//&models.MessageSystem{},
//&models.MessageBusiness{},
//&models.Department{},
//&models.ArticleAndTag{},
&models.ArticleCategory{},
}
db.AutoMigrate(modelsList...)
... ...
package models
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type ArticleCategory struct {
Id int64 // 唯一标识
CompanyId int64
Name string
SortBy int
Enable int
Other string
CreatedAt int64
UpdatedAt int64
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
DeletedAt int64
Version int
}
func (m *ArticleCategory) TableName() string {
return "article_category"
}
func (m *ArticleCategory) BeforeCreate(tx *gorm.DB) (err error) {
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *ArticleCategory) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = time.Now().Unix()
return
}
func (m *ArticleCategory) CacheKeyFunc() string {
if m.Id == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}
func (m *ArticleCategory) CacheKeyFuncByObject(obj interface{}) string {
if v, ok := obj.(*ArticleCategory); ok {
return v.CacheKeyFunc()
}
return ""
}
func (m *ArticleCategory) CachePrimaryKeyFunc() string {
if len("") == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}
... ...
... ... @@ -24,6 +24,8 @@ type ArticleTag struct {
Category string // 标签分类
SortBy int64 // 顺序
Other string // 其他
CategoryId int64 // 标签分类ID
DataFrom int // 来源 0:系统初始化 1:用户自动添加(可删除)
}
func (m *ArticleTag) TableName() string {
... ...
... ... @@ -12,7 +12,7 @@ type Company struct {
Name string // 名称
Code string `gorm:"uniqueIndex:idx_company_code"` // 编码(搜索使用,4位字母数字)
Logo string // 公司LOGO
Visible int
CreatedAt int64
UpdatedAt int64
DeletedAt int64
... ...
package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models"
"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"
"gorm.io/gorm"
)
type ArticleCategoryRepository struct {
*cache.CachedRepository
}
func (repository *ArticleCategoryRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.ArticleCategory) (*domain.ArticleCategory, error) {
var (
err error
m = &models.ArticleCategory{}
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
if tx = tx.Model(m).Save(m); tx.Error != nil {
return nil, tx.Error
}
dm.Id = m.Id
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ArticleCategory) (*domain.ArticleCategory, error) {
var (
err error
m *models.ArticleCategory
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.ArticleCategory) (*domain.ArticleCategory, error) {
var (
err error
m *models.ArticleCategory
tx = transaction.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
oldVersion := dm.Version
m.Version += 1
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
if tx.RowsAffected == 0 {
return nil, domain.ErrUpdateFail
}
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ArticleCategory) (*domain.ArticleCategory, error) {
var (
tx = conn.DB()
m = &models.ArticleCategory{Id: dm.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
tx = tx.Where("id = ?", m.Id).Delete(m)
return m, tx.Error
}
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return dm, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.ArticleCategory, error) {
var (
err error
tx = conn.DB()
m = new(models.ArticleCategory)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.ArticleCategory)
cacheModel.Id = id
if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *ArticleCategoryRepository) FindOneByName(ctx context.Context, conn transaction.Conn, companyId int64, name string) (*domain.ArticleCategory, error) {
var (
err error
tx = conn.DB()
m = new(models.ArticleCategory)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("company_id = ?", companyId).Where("name = ?", name).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 *ArticleCategoryRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.ArticleCategory, error) {
var (
tx = conn.DB()
ms []*models.ArticleCategory
dms = make([]*domain.ArticleCategory, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Where("company_id = ?", companyId)
if v, ok := queryOptions["enable"]; ok {
tx.Where("enable = ?", v)
}
tx.Order("sort_by asc").Order("id asc")
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return total, dms, nil
}
func (repository *ArticleCategoryRepository) ModelToDomainModel(from *models.ArticleCategory) (*domain.ArticleCategory, error) {
to := &domain.ArticleCategory{}
err := copier.Copy(to, from)
return to, err
}
func (repository *ArticleCategoryRepository) DomainModelToModel(from *domain.ArticleCategory) (*models.ArticleCategory, error) {
to := &models.ArticleCategory{}
err := copier.Copy(to, from)
return to, err
}
func NewArticleCategoryRepository(cache *cache.CachedRepository) domain.ArticleCategoryRepository {
return &ArticleCategoryRepository{CachedRepository: cache}
}
... ...
... ... @@ -152,6 +152,9 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
if v, ok := queryOptions["category"]; ok {
tx = tx.Where("category like ?", v)
}
if v, ok := queryOptions["categoryId"]; ok {
tx = tx.Where("category_id = ?", v)
}
if v, ok := queryOptions["ids"]; ok {
tx = tx.Where("id in (?)", v)
}
... ...
... ... @@ -144,6 +144,9 @@ func (repository *CompanyRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["ids"]; ok {
tx.Where("id in (?)", v)
}
if v, ok := queryOptions["visible"]; ok {
tx.Where("visible = ?", v)
}
if v, ok := queryOptions["excludeIds"]; ok {
tx.Where("id not in (?)", v)
}
... ...
package domain
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
type ArticleCategory struct {
Id int64 // 唯一标识
CompanyId int64 `json:"companyId"`
Name string `json:"name"`
SortBy int `json:"sortBy"` // 排序
Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用
Other string `json:"other"` // 其他备注说明
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
}
type ArticleCategoryRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleCategory) (*ArticleCategory, error)
Update(ctx context.Context, conn transaction.Conn, dm *ArticleCategory) (*ArticleCategory, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleCategory) (*ArticleCategory, error)
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleCategory) (*ArticleCategory, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleCategory, error)
FindOneByName(ctx context.Context, conn transaction.Conn, companyId int64, name string) (*ArticleCategory, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*ArticleCategory, error)
}
func (m *ArticleCategory) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
... ...
... ... @@ -19,6 +19,8 @@ type ArticleTag struct {
Image Image `json:"image"` // 图片
Name string `json:"name"` // 标签名称
Category string `json:"category"` // 标签分类 [紧急重要]、[机会风险]
CategoryId int64 `json:"categoryId"` // 标签分类ID
DataFrom int `json:"dataFrom"` // 来源 0:系统初始化 1:用户自动添加(可删除)
Remark string `json:"remark"` // 备注
SortBy int64 `json:"sortBy"` // 顺序
Other string `json:"other"` //
... ...
... ... @@ -10,7 +10,7 @@ type Company struct {
Name string `json:"name,omitempty"` // 名称
Code string `json:"code,omitempty"` // 编码(搜索使用,4位字母数字)
Logo string `json:"logo,omitempty"` // 公司LOGO
Visible int `json:"visible,omitempty"` // 可见的 1:可见 0:不可见
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
... ...
... ... @@ -27,3 +27,8 @@ CREATE TABLE `user_follow` (
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `article_category` (
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
\ No newline at end of file
... ...
-- 增加字段
alter table article_tag add column category_id int8;
alter table article_tag add column data_from int2;
alter table company add column visible int2;
-- 更新数据
update article_tag set data_from = 0;
update company set visible = 0;
\ No newline at end of file
... ...