123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- package knowledge
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- const (
- // 事件类型-事件库
- KnowledgeResourceTypeEvent = 0
- // 事件-政策库
- KnowledgeResourceTypePolicy = 1
- // 事件-观点库
- KnowledgeResourceTypeOpinion = 2
- // 事件类型-知识库
- KnowledgeResourceTypeKnow = 3
- )
- 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:已发布;"`
- 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"`
- }
- func (m *KnowledgeResource) TableName() string {
- return "knowledge_resource"
- }
- // 查询列表
- func (m *KnowledgeResource) QueryList(condition string, pars []interface{}) (items []*KnowledgeResource, err error) {
- return
- }
- type KnowledgeResourceList 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 string `gorm:"column:create_time" description:"创建时间"`
- ModifyTime string `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
- State int `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
- 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 string `gorm:"column:start_time"`
- EndTime string `gorm:"column:end_time"`
- ClassifyFullName string
- TagName string
- }
- type KnowledgeResourceListResp struct {
- List []*KnowledgeResourceList
- Paging *paging.PagingItem `description:"分页数据"`
- }
- func GetKnowledgeResourcePageList(condition string, pars []interface{}, startSize, pageSize int) (items []*KnowledgeResource, err error) {
- sql := `SELECT * FROM knowledge_resource WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY modify_time DESC LIMIT ?,?`
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
- return
- }
- func GetKnowledgeResourceIdList(condition string, pars []interface{}) (items []int, err error) {
- sql := `SELECT knowledge_resource_id FROM knowledge_resource WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY modify_time DESC`
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
- return
- }
- func GetKnowledgeResourceListCount(condition string, pars []interface{}) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM knowledge_resource WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (m *KnowledgeResource) Delete(knowledgeResourceIds int) (err error) {
- sql := ` DELETE FROM knowledge_resource WHERE knowledge_resource_id =? `
- err = global.DmSQL["rddp"].Exec(sql, knowledgeResourceIds).Error
- return
- }
- func (m *KnowledgeResource) GetById(knowledgeResourceId int) (item *KnowledgeResource, err error) {
- sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id =?`
- err = global.DmSQL["rddp"].Raw(sql, knowledgeResourceId).First(&item).Error
- return
- }
- type DeleteReq struct {
- KnowledgeResourceId int `description:"事件id"`
- ResourceType int
- }
- type AddReq struct {
- ResourceType int `gorm:"column:resource_type;"`
- ClassifyId int `gorm:"column:classify_id"`
- Title string `gorm:"column:title;"`
- State int `gorm:"column:state" description:"0:未发布;1:已发布"`
- Content string `gorm:"column:content"`
- SourceFrom string `gorm:"column:source_from"`
- TagId int `gorm:"column:tag_id;default:0;NOT NULL"`
- StartTime string `gorm:"column:start_time"`
- EndTime string `gorm:"column:end_time"`
- FileUrl string `gorm:"column:file_url"`
- }
- type AddResp struct {
- KnowledgeResourceId int `description:"事件id"`
- ResourceCode string `description:"事件code"`
- }
- func (m *KnowledgeResource) Add(item *KnowledgeResource) (err error) {
- err = global.DmSQL["rddp"].Create(item).Error
- return
- }
- func (m *KnowledgeResource) AddBatch(item []*KnowledgeResource) (err error) {
- err = global.DmSQL["rddp"].CreateInBatches(item, 50).Error
- return
- }
- type EditReq struct {
- KnowledgeResourceId int64 `description:"事件id"`
- AddReq
- }
- type EditResp struct {
- KnowledgeResourceId int64 `description:"事件id"`
- ResourceCode string `description:"事件code"`
- }
- type SaveReportContent struct {
- Content string `description:"内容"`
- KnowledgeResourceId int `description:"事件id"`
- NoChange int `description:"内容是否未改变:1:内容未改变"`
- // 以下是智能研报相关
- ContentStruct string `description:"内容组件"`
- HeadImg string `description:"事件头图地址"`
- EndImg string `description:"事件尾图地址"`
- CanvasColor string `description:"画布颜色"`
- NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史事件。0-不需要 1-需要"`
- HeadResourceId int `description:"版头资源ID"`
- EndResourceId int `description:"版尾资源ID"`
- }
- type SaveReportContentResp struct {
- KnowledgeResourceId int `description:"事件id"`
- }
- // SaveDayWeekReportReq 新增晨报周报请求体
- type SaveDayWeekReportReq struct {
- KnowledgeResourceId int `description:"事件ID"`
- Title string `description:"标题"`
- ReportType string `description:"一级分类ID"`
- Author string `description:"作者"`
- CreateTime string `description:"创建时间"`
- }
- func (m *KnowledgeResource) Update(cols []string) (err error) {
- err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
- return
- }
- // MarkEditReport 标记编辑英文研报的请求数据
- type MarkEditReport struct {
- KnowledgeResourceId int `description:"研报id"`
- ReportChapterId int `description:"研报章节id"`
- Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
- }
- type MarkReportResp struct {
- Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
- Msg string `description:"提示信息"`
- Editor string `description:"编辑者姓名"`
- }
- type MarkReportItem struct {
- AdminId int `description:"编辑者ID"`
- Editor string `description:"编辑者姓名"`
- ReportClassifyNameFirst string
- }
- func (m *KnowledgeResource) AddMulti(items []*KnowledgeResource) (err error) {
- err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
- func (m *KnowledgeResource) GetSourceFrom(keyword string, resourceType int) (items []string, err error) {
- sql := fmt.Sprintf(`SELECT distinct source_from FROM %s WHERE 1=1 and resource_type=? `, m.TableName())
- if keyword != `` {
- sql += ` AND source_from LIKE '%` + keyword + `%'`
- }
- err = global.DmSQL["rddp"].Raw(sql, resourceType).Scan(&items).Error
- return
- }
- type KnowledgeResourceDetailView struct {
- *KnowledgeResource
- }
- type ResourceImportData struct {
- Title string `description:"标题"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"开始时间"`
- StartTime string `description:"结束日期"`
- EndTime string `description:"结束时间"`
- Content string `description:"正文"`
- Tag string `description:"标签"`
- SourceFrom string `description:"来源"`
- ClassifyFirstName string `description:"一级分类"`
- ClassifySecondName string `description:"二级分类"`
- ClassifyThirdName string `description:"三级分类"`
- }
- type UpdateResourceResp struct {
- FileUrl string `description:"文件地址"`
- }
- type GetSourceFromResp struct {
- List []string `description:"来源列表"`
- }
- type GetAdminsResp struct {
- List []*GetAdminsRespItem `description:"添加人"`
- }
- type GetAdminsRespItem struct {
- AdminId int `gorm:"column:admin_id" description:"创建者账号"`
- AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
- }
- func (m *KnowledgeResource) GetAdmins(keyword string, resourceType int) (items []*GetAdminsRespItem, err error) {
- sql := fmt.Sprintf(`SELECT distinct admin_id, admin_real_name FROM %s WHERE 1=1 and resource_type=? `, m.TableName())
- if keyword != `` {
- sql += ` AND admin_real_name LIKE '%` + keyword + `%'`
- }
- err = global.DmSQL["rddp"].Raw(sql, resourceType).Scan(&items).Error
- return
- }
- // UpdateClassifySortByParentId 根据父类id更新排序
- func (m *KnowledgeResource) UpdateClassifyIdByIds(ids []int, classifyId int, resourceType int) (err error) {
- var pars []interface{}
- sql := ` UPDATE %s set classify_id =? WHERE resource_type=? AND knowledge_resource_id in (?) `
- pars = append(pars, classifyId, resourceType, ids)
- sql = fmt.Sprintf(sql, m.TableName())
- err = global.DmSQL["rddp"].Exec(sql, pars...).Error
- return
- }
|