|
@@ -0,0 +1,208 @@
|
|
|
|
+package models
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "eta_gn/eta_task/global"
|
|
|
|
+ "eta_gn/eta_task/utils"
|
|
|
|
+ "time"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ // 事件类型-事件库
|
|
|
|
+ KnowledgeResourceTypeEvent = iota
|
|
|
|
+ // 事件-政策库
|
|
|
|
+ KnowledgeResourceTypePolicy
|
|
|
|
+ // 事件-报告库
|
|
|
|
+ KnowledgeResourceTypeReport
|
|
|
|
+ // 事件类型-知识库
|
|
|
|
+ KnowledgeResourceTypeKnow
|
|
|
|
+ // 事件-观点库
|
|
|
|
+ KnowledgeResourceTypeOpinion
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ // 未发布
|
|
|
|
+ KnowledgeResourceStateUnpublished = iota
|
|
|
|
+ // 已发布
|
|
|
|
+ KnowledgeResourceStatePublished
|
|
|
|
+ // 待审批
|
|
|
|
+ KnowledgeResourceStatePending
|
|
|
|
+ // 已驳回
|
|
|
|
+ KnowledgeResourceStateRejected
|
|
|
|
+ // 已通过
|
|
|
|
+ KnowledgeResourceStateApproved
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type KnowledgeResourceFile struct {
|
|
|
|
+ KnowledgeResourceFileId int `gorm:"column:knowledge_resource_file_id;primaryKey;autoIncrement"`
|
|
|
|
+ KnowledgeResourceId int `gorm:"column:knowledge_resource_id"`
|
|
|
|
+ FileUrl string `gorm:"column:file_url"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k KnowledgeResourceFile) TableName() string {
|
|
|
|
+ return "knowledge_resource_file"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type KnowledgeResource struct {
|
|
|
|
+ KnowledgeResourceId int `gorm:"column:knowledge_resource_id;;primaryKey;autoIncrement"`
|
|
|
|
+ ResourceType int `gorm:"column:resource_type;"`
|
|
|
|
+ ClassifyId int `gorm:"column:classify_id"`
|
|
|
|
+ Title string `gorm:"column:title;"`
|
|
|
|
+ CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
|
|
|
|
+ ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
|
|
|
|
+ State int `gorm:"column:state" description:"0:未发布;1:已发布;2:待审批;3:已驳回;4:已通过"`
|
|
|
|
+ Content string `gorm:"column:content"`
|
|
|
|
+ ResourceCode string `gorm:"column:resource_code"`
|
|
|
|
+ AdminId int `gorm:"column:admin_id" description:"创建者账号"`
|
|
|
|
+ AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
|
|
|
|
+ SourceFrom string `gorm:"column:source_from"`
|
|
|
|
+ TagId int `gorm:"column:tag_id;default:0;NOT NULL"`
|
|
|
|
+ StartTime *time.Time `gorm:"column:start_time"`
|
|
|
|
+ EndTime *time.Time `gorm:"column:end_time"`
|
|
|
|
+ IsFile int `gorm:"column:is_file;default:0;NOT NULL"`
|
|
|
|
+ FileUrl string `gorm:"column:file_url"`
|
|
|
|
+ OutId int `gorm:"column:out_id" description:"外部系统ID"`
|
|
|
|
+ IsDelete int `gorm:"column:is_delete;default:0;NOT NULL"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k KnowledgeResource) TableName() string {
|
|
|
|
+ return "knowledge_resource"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeResource) BatchCreate(item []*KnowledgeResource) (err error) {
|
|
|
|
+ return global.DmSQL["rddp"].CreateInBatches(item, utils.MultiAddNum).Error
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeResource) Create(fileUrl []string) (err error) {
|
|
|
|
+ tx := global.DmSQL["rddp"].Begin()
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ tx.Rollback()
|
|
|
|
+ } else {
|
|
|
|
+ tx.Commit()
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ err = tx.Create(k).Error
|
|
|
|
+ if len(fileUrl) > 0 {
|
|
|
|
+ addFile := make([]*KnowledgeResourceFile, 0, len(fileUrl))
|
|
|
|
+ for _, url := range fileUrl {
|
|
|
|
+ file := new(KnowledgeResourceFile)
|
|
|
|
+ file.KnowledgeResourceId = k.KnowledgeResourceId
|
|
|
|
+ file.FileUrl = url
|
|
|
|
+ addFile = append(addFile, file)
|
|
|
|
+ }
|
|
|
|
+ err = tx.CreateInBatches(addFile, utils.MultiAddNum).Error
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeResource) Update(cols []string) error {
|
|
|
|
+ return global.DmSQL["rddp"].Model(k).Select(cols).Updates(k).Error
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeResource) GetBatchKnowledgeResourceByOutIds(id []int, resourceType int) (item []*KnowledgeResource, err error) {
|
|
|
|
+ if len(id) == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ sql := "SELECT * FROM knowledge_resource WHERE out_id IN (?) AND resource_type = ?"
|
|
|
|
+ err = global.DmSQL["rddp"].Raw(sql, id, resourceType).Find(&item).Error
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// GetKnowledgeResourceByOutId 根据外部系统ID获取知识资源
|
|
|
|
+func (k *KnowledgeResource) GetKnowledgeResourceByOutId(outId int) (item *KnowledgeResource, err error) {
|
|
|
|
+ sql := "SELECT * FROM knowledge_resource WHERE out_id = ?"
|
|
|
|
+ err = global.DmSQL["rddp"].Raw(sql, outId).First(&item).Error
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeResource) GetKnowledgeCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
|
+ sql := "SELECT COUNT(*) FROM knowledge_resource WHERE 1=1 "
|
|
|
|
+ if condition != "" {
|
|
|
|
+ sql += condition
|
|
|
|
+ }
|
|
|
|
+ err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type KnowledgeClassify struct {
|
|
|
|
+ ClassifyId int `gorm:"primaryKey;column:classify_id"`
|
|
|
|
+ ClassifyName string `gorm:"column:classify_name;default:'';type:varchar(125);not null"` // 注意:varchar的默认长度可能需要根据实际情况调整
|
|
|
|
+ Sort int `gorm:"column:sort;default:0;type:tinyint"`
|
|
|
|
+ ParentId int `gorm:"column:parent_id;default:0;type:int"`
|
|
|
|
+ CreateTime time.Time `gorm:"column:create_time;default:CURRENT_TIMESTAMP"`
|
|
|
|
+ ModifyTime time.Time `gorm:"column:modify_time;default:CURRENT_TIMESTAMP"`
|
|
|
|
+ Enabled int `gorm:"column:enabled;default:1;type:tinyint"`
|
|
|
|
+ Level int `gorm:"column:level;default:0;type:bigint"`
|
|
|
|
+ ResourceType int `gorm:"column:resource_type;default:0;not null;type:tinyint"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k KnowledgeClassify) TableName() string {
|
|
|
|
+ return "knowledge_classify"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeClassify) Create() error {
|
|
|
|
+ return global.DmSQL["rddp"].Create(k).Error
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeClassify) GetClassifyByNameTypeAndParentId(classifyName string, resourceType, parentId int) (items *KnowledgeClassify, err error) {
|
|
|
|
+ sql := "SELECT * FROM knowledge_classify WHERE classify_name = ? AND resource_type = ? AND parent_id = ?"
|
|
|
|
+ err = global.DmSQL["rddp"].Raw(sql, classifyName, resourceType, parentId).First(&items).Error
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeClassify) GetClassifysByNameAndType(classifyName string, resourceType int) (item *KnowledgeClassify, err error) {
|
|
|
|
+ sql := "SELECT * FROM knowledge_classify WHERE classify_name = ? AND resource_type = ?"
|
|
|
|
+ err = global.DmSQL["rddp"].Raw(sql, classifyName, resourceType).Find(&item).Error
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (k *KnowledgeClassify) GetChildClassifyIdByNamePath(classifyNameFirst string, classifyNameSecond string, classifyNameThird string) (id int, err error) {
|
|
|
|
+ sql := `SELECT
|
|
|
|
+ c3.classify_id AS id
|
|
|
|
+ FROM knowledge_classify c1
|
|
|
|
+ JOIN knowledge_classify c2 ON c2.parent_id = c1.classify_id
|
|
|
|
+ AND c2.classify_name = ?
|
|
|
|
+ AND c2.level = 2
|
|
|
|
+ JOIN knowledge_classify c3 ON c3.parent_id = c2.classify_id
|
|
|
|
+ AND c3.classify_name = ?
|
|
|
|
+ AND c3.level = 3
|
|
|
|
+ WHERE c1.classify_name = ?
|
|
|
|
+ AND c1.level = 1 `
|
|
|
|
+ err = global.DmSQL["rddp"].Raw(sql, classifyNameSecond, classifyNameThird, classifyNameFirst).Scan(&id).Error
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type EtaBridgeKnowledgeResourceResp struct {
|
|
|
|
+ Code int `json:"code" description:"状态码"`
|
|
|
|
+ Msg string `json:"msg" description:"提示信息"`
|
|
|
|
+ Data MarketOverviewResp `json:"data" description:"返回数据"`
|
|
|
|
+ ErrMsg string `json:"-" description:"错误信息"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type MarketOverviewResp struct {
|
|
|
|
+ Code string `json:"code"`
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
+ Time string `json:"time"`
|
|
|
|
+ Data struct {
|
|
|
|
+ Result bool `json:"result"`
|
|
|
|
+ Total int `json:"total"`
|
|
|
|
+ Records []MarketOverviewRecord `json:"records"`
|
|
|
|
+ } `json:"data"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type MarketOverviewRecord struct {
|
|
|
|
+ Category string `json:"CATEGORY"`
|
|
|
|
+ Content string `json:"CONTENT"`
|
|
|
|
+ CreateOriginTime string `json:"CREATE_ORIGIN_TIME"`
|
|
|
|
+ CreateTime string `json:"CREATE_TIME"`
|
|
|
|
+ DataDate string `json:"DATA_DATE"`
|
|
|
|
+ DataSource string `json:"DATA_SOURCE"`
|
|
|
|
+ DataSourceCode string `json:"DATA_SOURCE_CODE"`
|
|
|
|
+ Des string `json:"DES"`
|
|
|
|
+ Id int `json:"ID"`
|
|
|
|
+ IsValidData int `json:"IS_VALID_DATA"`
|
|
|
|
+ Person string `json:"PERSON"`
|
|
|
|
+ Title string `json:"TITLE"`
|
|
|
|
+ UpdateOriginTime string `json:"UPDATE_ORIGIN_TIME"`
|
|
|
|
+ UpdateTime string `json:"UPDATE_TIME"`
|
|
|
|
+}
|