优化文档相关
This commit is contained in:
@@ -69,6 +69,9 @@ func (c *BackendOaDocumentController) oaDocFail(err error) {
|
||||
status, code, msg = 404, 404, err.Error()
|
||||
case services.ErrDocLinkDuplicate:
|
||||
status, code, msg = 409, 409, err.Error()
|
||||
case services.ErrDocCategorySystem, services.ErrDocCategorySystemLocked,
|
||||
services.ErrDocCategoryNameKept:
|
||||
status, code, msg = 403, 403, err.Error()
|
||||
default:
|
||||
msg = err.Error()
|
||||
}
|
||||
@@ -95,14 +98,15 @@ func (c *BackendOaDocumentController) oaDocActor(claims *jwtutil.Claims) service
|
||||
|
||||
// ---------------- 分类 ----------------
|
||||
|
||||
// Categories GET /backend/oa/document/categories 分类树(含文档数量)
|
||||
// Categories GET /backend/oa/document/categories?scope=shared|personal 文档分类树(含各分类文档数量)
|
||||
func (c *BackendOaDocumentController) Categories() {
|
||||
claims, err := c.oaDocClaims()
|
||||
if err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
}
|
||||
tree, err := services.OaDocCategoryTree(c.oaDocActor(claims))
|
||||
scope := strings.TrimSpace(c.GetString("scope"))
|
||||
tree, err := services.OaDocCategoryTree(c.oaDocActor(claims), scope)
|
||||
if err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
@@ -118,6 +122,7 @@ func (c *BackendOaDocumentController) CreateCategory() {
|
||||
return
|
||||
}
|
||||
var body struct {
|
||||
Scope string `json:"scope"`
|
||||
ParentID uint64 `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
Remark string `json:"remark"`
|
||||
@@ -126,7 +131,8 @@ func (c *BackendOaDocumentController) CreateCategory() {
|
||||
if !c.oaDocParseBody(&body) {
|
||||
return
|
||||
}
|
||||
item, err := services.OaDocCategoryCreate(claims.TenantId, body.ParentID, body.Name, body.Remark, body.Sort)
|
||||
item, err := services.OaDocCategoryCreate(
|
||||
c.oaDocActor(claims), body.Scope, body.ParentID, body.Name, body.Remark, body.Sort)
|
||||
if err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
@@ -169,7 +175,7 @@ func (c *BackendOaDocumentController) UpdateCategory() {
|
||||
if body.Sort != nil {
|
||||
sort = *body.Sort
|
||||
}
|
||||
item, err := services.OaDocCategoryUpdate(claims.TenantId, id, name, remark, sort, parentID)
|
||||
item, err := services.OaDocCategoryUpdate(c.oaDocActor(claims), id, name, remark, sort, parentID)
|
||||
if err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
@@ -188,7 +194,7 @@ func (c *BackendOaDocumentController) DeleteCategory() {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := services.OaDocCategoryDelete(claims.TenantId, id); err != nil {
|
||||
if err := services.OaDocCategoryDelete(c.oaDocActor(claims), id); err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
}
|
||||
@@ -211,13 +217,19 @@ func (c *BackendOaDocumentController) List() {
|
||||
docType, _ := c.GetInt("doc_type", -1)
|
||||
star, _ := c.GetInt("star", -1)
|
||||
categoryID, _ := c.GetUint64("category_id")
|
||||
visibility, _ := c.GetInt("visibility", -1)
|
||||
mine := strings.TrimSpace(c.GetString("mine")) == "1"
|
||||
scope := strings.TrimSpace(c.GetString("scope"))
|
||||
|
||||
actor := c.oaDocActor(claims)
|
||||
list, total, err := services.OaDocList(actor, services.OaDocListParams{
|
||||
Actor: actor,
|
||||
Scope: scope,
|
||||
Keyword: strings.TrimSpace(c.GetString("keyword")),
|
||||
CategoryID: categoryID,
|
||||
Uncategorized: strings.TrimSpace(c.GetString("uncategorized")) == "1",
|
||||
Visibility: visibility,
|
||||
Mine: mine,
|
||||
Status: status,
|
||||
DocType: docType,
|
||||
Tag: strings.TrimSpace(c.GetString("tag")),
|
||||
@@ -232,14 +244,15 @@ func (c *BackendOaDocumentController) List() {
|
||||
c.oaDocOk(map[string]interface{}{"list": list, "total": total})
|
||||
}
|
||||
|
||||
// Stats GET /backend/oa/document/stats 文档库概览
|
||||
// Stats GET /backend/oa/document/stats?scope=shared|personal|all 文档库概览
|
||||
func (c *BackendOaDocumentController) Stats() {
|
||||
claims, err := c.oaDocClaims()
|
||||
if err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
}
|
||||
stats, err := services.OaDocStats(c.oaDocActor(claims))
|
||||
scope := strings.TrimSpace(c.GetString("scope"))
|
||||
stats, err := services.OaDocStats(c.oaDocActor(claims), scope)
|
||||
if err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
@@ -266,6 +279,25 @@ func (c *BackendOaDocumentController) Detail() {
|
||||
c.oaDocOk(item)
|
||||
}
|
||||
|
||||
// Content GET /backend/oa/document/content/:id 读取在线文档的编辑源(不累加查看次数)
|
||||
func (c *BackendOaDocumentController) Content() {
|
||||
claims, err := c.oaDocClaims()
|
||||
if err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
}
|
||||
id, ok := c.oaDocID()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := services.OaDocGet(c.oaDocActor(claims), id)
|
||||
if err != nil {
|
||||
c.oaDocFail(err)
|
||||
return
|
||||
}
|
||||
c.oaDocOk(map[string]interface{}{"content": item.Content})
|
||||
}
|
||||
|
||||
// Create POST /backend/oa/document/create
|
||||
func (c *BackendOaDocumentController) Create() {
|
||||
claims, err := c.oaDocClaims()
|
||||
@@ -406,10 +438,10 @@ func (c *BackendOaDocumentController) Download() {
|
||||
return
|
||||
}
|
||||
c.oaDocOk(map[string]interface{}{
|
||||
"id": item.ID,
|
||||
"title": item.Title,
|
||||
"file_url": item.FileURL,
|
||||
"file_name": item.FileName,
|
||||
"id": item.ID,
|
||||
"title": item.Title,
|
||||
"file_url": item.FileURL,
|
||||
"file_name": item.FileName,
|
||||
"download_count": item.DownCount,
|
||||
})
|
||||
}
|
||||
@@ -605,38 +637,44 @@ func (c *BackendOaDocumentController) oaDocParseSaveBody() (services.OaDocSavePa
|
||||
var body struct {
|
||||
CategoryID *uint64 `json:"category_id"`
|
||||
Title string `json:"title"`
|
||||
FileID uint64 `json:"file_id"`
|
||||
FileURL string `json:"file_url"`
|
||||
FileName string `json:"file_name"`
|
||||
Ext string `json:"ext"`
|
||||
Size uint64 `json:"size"`
|
||||
Tags string `json:"tags"`
|
||||
Summary string `json:"summary"`
|
||||
Status *int8 `json:"status"`
|
||||
Version int `json:"version"`
|
||||
OwnerID uint64 `json:"owner_id"`
|
||||
OwnerName string `json:"owner_name"`
|
||||
IsStar *int8 `json:"is_star"`
|
||||
Visibility *int8 `json:"visibility"`
|
||||
FileID uint64 `json:"file_id"`
|
||||
FileURL string `json:"file_url"`
|
||||
FileName string `json:"file_name"`
|
||||
Ext string `json:"ext"`
|
||||
Size uint64 `json:"size"`
|
||||
Tags string `json:"tags"`
|
||||
Summary string `json:"summary"`
|
||||
Content *string `json:"content"`
|
||||
Status *int8 `json:"status"`
|
||||
Version int `json:"version"`
|
||||
OwnerID uint64 `json:"owner_id"`
|
||||
OwnerName string `json:"owner_name"`
|
||||
IsStar *int8 `json:"is_star"`
|
||||
Visibility *int8 `json:"visibility"`
|
||||
}
|
||||
if !c.oaDocParseBody(&body) {
|
||||
return services.OaDocSaveParams{}, false
|
||||
}
|
||||
params := services.OaDocSaveParams{
|
||||
Title: body.Title,
|
||||
FileID: body.FileID,
|
||||
FileURL: body.FileURL,
|
||||
FileName: body.FileName,
|
||||
Ext: body.Ext,
|
||||
Size: body.Size,
|
||||
Tags: body.Tags,
|
||||
Summary: body.Summary,
|
||||
Version: body.Version,
|
||||
OwnerID: body.OwnerID,
|
||||
OwnerName: body.OwnerName,
|
||||
Title: body.Title,
|
||||
FileID: body.FileID,
|
||||
FileURL: body.FileURL,
|
||||
FileName: body.FileName,
|
||||
Ext: body.Ext,
|
||||
Size: body.Size,
|
||||
Tags: body.Tags,
|
||||
Summary: body.Summary,
|
||||
Version: body.Version,
|
||||
OwnerID: body.OwnerID,
|
||||
OwnerName: body.OwnerName,
|
||||
}
|
||||
if body.Content != nil {
|
||||
params.SetContent = true
|
||||
params.Content = *body.Content
|
||||
}
|
||||
if body.Visibility != nil {
|
||||
params.Visibility = *body.Visibility
|
||||
params.SetVisibility = true
|
||||
}
|
||||
if body.CategoryID != nil {
|
||||
params.SetCategory = true
|
||||
|
||||
Reference in New Issue
Block a user