221 lines
7.6 KiB
Go
221 lines
7.6 KiB
Go
package models
|
|
|
|
import (
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
)
|
|
|
|
type OaDocCategory struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Tid int `orm:"column(tid)" json:"tid"`
|
|
UserID uint64 `orm:"column(user_id);default(0)" json:"user_id"`
|
|
ParentID uint64 `orm:"column(parent_id);default(0)" json:"parent_id"`
|
|
Name string `orm:"column(name);size(128)" json:"name"`
|
|
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
|
Remark string `orm:"column(remark);size(255);default()" json:"remark"`
|
|
IsSystem int8 `orm:"column(is_system);default(0)" json:"is_system"`
|
|
Scope string `orm:"column(scope);size(16);default(shared)" json:"scope"`
|
|
IsDeleted int8 `orm:"column(is_deleted);default(0)" json:"is_deleted"`
|
|
|
|
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
|
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"update_time"`
|
|
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
|
}
|
|
|
|
func (m *OaDocCategory) TableName() string {
|
|
return "yz_backend_oa_doc_category"
|
|
}
|
|
|
|
type OaDoc struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Tid int `orm:"column(tid)" json:"tid"`
|
|
CategoryID uint64 `orm:"column(category_id);default(0)" json:"category_id"`
|
|
Title string `orm:"column(title);size(255)" json:"title"`
|
|
FileID uint64 `orm:"column(file_id);default(0)" json:"file_id"`
|
|
FileURL string `orm:"column(file_url);size(512);default()" json:"file_url"`
|
|
FileName string `orm:"column(file_name);size(255);default()" json:"file_name"`
|
|
Ext string `orm:"column(ext);size(16);default()" json:"ext"`
|
|
Size uint64 `orm:"column(size);default(0)" json:"size"`
|
|
DocType int8 `orm:"column(doc_type);default(0)" json:"doc_type"`
|
|
Tags string `orm:"column(tags);size(255);default()" json:"tags"`
|
|
Summary string `orm:"column(summary);size(1000);default()" json:"summary"`
|
|
Content string `orm:"column(content);type(longtext);null" json:"content,omitempty"`
|
|
IsOnline int8 `orm:"-" json:"is_online"`
|
|
Status int8 `orm:"column(status);default(0)" json:"status"`
|
|
Version int `orm:"column(version);default(1)" json:"version"`
|
|
IsStar int8 `orm:"column(is_star);default(0)" json:"is_star"`
|
|
OwnerID uint64 `orm:"column(owner_id);default(0)" json:"owner_id"`
|
|
OwnerName string `orm:"column(owner_name);size(100);default()" json:"owner_name"`
|
|
ViewCount int `orm:"column(view_count);default(0)" json:"view_count"`
|
|
DownCount int `orm:"column(download_count);default(0)" json:"download_count"`
|
|
CreatorID uint64 `orm:"column(creator_id);default(0)" json:"creator_id"`
|
|
CreatorName string `orm:"column(creator_name);size(100);default()" json:"creator_name"`
|
|
Visibility int8 `orm:"column(visibility);default(0)" json:"visibility"`
|
|
IsDeleted int8 `orm:"column(is_deleted);default(0)" json:"is_deleted"`
|
|
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
|
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"update_time"`
|
|
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
|
}
|
|
|
|
func (m *OaDoc) TableName() string {
|
|
return "yz_backend_oa_doc"
|
|
}
|
|
|
|
type OaDocLink struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Tid int `orm:"column(tid)" json:"tid"`
|
|
SourceID uint64 `orm:"column(source_id);default(0)" json:"source_id"`
|
|
TargetID uint64 `orm:"column(target_id);default(0)" json:"target_id"`
|
|
Relation string `orm:"column(relation);size(32);default(related)" json:"relation"`
|
|
Remark string `orm:"column(remark);size(255);default()" json:"remark"`
|
|
CreatorID uint64 `orm:"column(creator_id);default(0)" json:"creator_id"`
|
|
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
|
}
|
|
|
|
func (m *OaDocLink) TableName() string {
|
|
return "yz_backend_oa_doc_link"
|
|
}
|
|
|
|
type OaDocShare struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Tid int `orm:"column(tid)" json:"tid"`
|
|
DocID uint64 `orm:"column(doc_id);default(0)" json:"doc_id"`
|
|
ShareType int8 `orm:"column(share_type);default(0)" json:"share_type"`
|
|
TargetID uint64 `orm:"column(target_id);default(0)" json:"target_id"`
|
|
CreatorID uint64 `orm:"column(creator_id);default(0)" json:"creator_id"`
|
|
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
|
}
|
|
|
|
func (m *OaDocShare) TableName() string {
|
|
return "yz_backend_oa_doc_share"
|
|
}
|
|
|
|
const (
|
|
DocCategoryNormal int8 = 0
|
|
DocCategorySystem int8 = 1
|
|
)
|
|
|
|
const (
|
|
DocScopeAll = "all"
|
|
DocScopePersonal = "personal"
|
|
DocScopeShared = "shared"
|
|
)
|
|
|
|
const DocCategoryNameProject = "项目文档"
|
|
|
|
const docCategorySystemRemark = "系统内置分类,不可删除"
|
|
|
|
const (
|
|
DocTypeOther int8 = 0
|
|
DocTypeDoc int8 = 1
|
|
DocTypeSheet int8 = 2
|
|
DocTypeSlide int8 = 3
|
|
DocTypePDF int8 = 4
|
|
DocTypeImage int8 = 5
|
|
DocTypeZip int8 = 6
|
|
DocTypeVideo int8 = 7
|
|
DocTypeAudio int8 = 8
|
|
)
|
|
|
|
const (
|
|
DocStatusDraft int8 = 0
|
|
DocStatusPublish int8 = 1
|
|
DocStatusArchive int8 = 2
|
|
)
|
|
|
|
const (
|
|
DocRelationReference = "reference"
|
|
DocRelationRelated = "related"
|
|
DocRelationVersion = "version"
|
|
DocRelationBelong = "belong"
|
|
)
|
|
|
|
const (
|
|
DocVisibilityPublic int8 = 0
|
|
DocVisibilityPrivate int8 = 1
|
|
)
|
|
|
|
const (
|
|
DocShareTypeUser int8 = 0
|
|
DocShareTypeOrg int8 = 1
|
|
)
|
|
|
|
var extDocTypeMap = map[string]int8{
|
|
"doc": DocTypeDoc, "docx": DocTypeDoc, "txt": DocTypeDoc, "md": DocTypeDoc,
|
|
"rtf": DocTypeDoc, "wps": DocTypeDoc, "odt": DocTypeDoc,
|
|
"xls": DocTypeSheet, "xlsx": DocTypeSheet, "csv": DocTypeSheet, "ods": DocTypeSheet,
|
|
"ppt": DocTypeSlide, "pptx": DocTypeSlide, "odp": DocTypeSlide,
|
|
"pdf": DocTypePDF,
|
|
"jpg": DocTypeImage, "jpeg": DocTypeImage, "png": DocTypeImage,
|
|
"gif": DocTypeImage, "bmp": DocTypeImage, "webp": DocTypeImage, "svg": DocTypeImage,
|
|
"zip": DocTypeZip, "rar": DocTypeZip, "7z": DocTypeZip, "tar": DocTypeZip, "gz": DocTypeZip,
|
|
"mp4": DocTypeVideo, "webm": DocTypeVideo, "mov": DocTypeVideo, "avi": DocTypeVideo,
|
|
"mp3": DocTypeAudio, "wav": DocTypeAudio, "ogg": DocTypeAudio,
|
|
}
|
|
|
|
func DocTypeByExt(ext string) int8 {
|
|
if t, ok := extDocTypeMap[strings.ToLower(strings.TrimPrefix(strings.TrimSpace(ext), "."))]; ok {
|
|
return t
|
|
}
|
|
return DocTypeOther
|
|
}
|
|
|
|
var oaDocDefaultCategoryOnce sync.Map
|
|
|
|
func EnsureOaDocDefaultCategories(tid int) {
|
|
if Orm == nil || tid <= 0 {
|
|
return
|
|
}
|
|
if _, done := oaDocDefaultCategoryOnce.Load(tid); done {
|
|
return
|
|
}
|
|
if err := ensureOaDocProjectCategory(tid); err == nil {
|
|
oaDocDefaultCategoryOnce.Store(tid, struct{}{})
|
|
}
|
|
}
|
|
|
|
func ensureOaDocProjectCategory(tid int) error {
|
|
qs := Orm.QueryTable(new(OaDocCategory)).
|
|
Filter("tid", tid).
|
|
Filter("scope", DocScopeShared)
|
|
|
|
sysCount, err := qs.Filter("is_system", DocCategorySystem).Count()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if sysCount > 0 {
|
|
return nil
|
|
}
|
|
|
|
var existed []OaDocCategory
|
|
if _, err := qs.Filter("name", DocCategoryNameProject).
|
|
Filter("is_deleted", 0).
|
|
OrderBy("id").Limit(1).All(&existed); err != nil && err != orm.ErrNoRows {
|
|
return err
|
|
}
|
|
if len(existed) > 0 {
|
|
item := existed[0]
|
|
item.IsSystem = DocCategorySystem
|
|
if item.Remark == "" {
|
|
item.Remark = docCategorySystemRemark
|
|
}
|
|
_, err := Orm.Update(&item, "IsSystem", "Remark")
|
|
return err
|
|
}
|
|
|
|
_, err = Orm.Insert(&OaDocCategory{
|
|
Tid: tid,
|
|
ParentID: 0,
|
|
Name: DocCategoryNameProject,
|
|
Sort: 0,
|
|
Remark: docCategorySystemRemark,
|
|
IsSystem: DocCategorySystem,
|
|
Scope: DocScopeShared,
|
|
IsDeleted: 0,
|
|
})
|
|
return err
|
|
}
|