knowledge_resource.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. package knowledge
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "time"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. const (
  10. // 事件类型-事件库
  11. KnowledgeResourceTypeEvent = 0
  12. // 事件-政策库
  13. KnowledgeResourceTypePolicy = 1
  14. // 事件-报告库
  15. KnowledgeResourceTypeReport = 2
  16. // 事件类型-知识库
  17. KnowledgeResourceTypeKnow = 3
  18. // 事件-观点库
  19. KnowledgeResourceTypeOpinion = 4
  20. )
  21. const (
  22. // 未发布
  23. KnowledgeResourceStateUnpublished = iota
  24. // 已发布
  25. KnowledgeResourceStatePublished
  26. // 待审核
  27. KnowledgeResourceStatePending
  28. // 已驳回
  29. KnowledgeResourceStateRejected
  30. // 已通过
  31. KnowledgeResourceStatePassed
  32. )
  33. type KnowledgeResourceDetail struct {
  34. KnowledgeResourceId int `gorm:"column:knowledge_resource_id;;primaryKey;autoIncrement"`
  35. ResourceType int `gorm:"column:resource_type;"`
  36. ClassifyId int `gorm:"column:classify_id"`
  37. Title string `gorm:"column:title;"`
  38. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  39. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  40. State int `gorm:"column:state" description:"状态:0:未发布;1:已发布;2:待审核;3:已驳回;4:已通过"`
  41. Content string `gorm:"column:content"`
  42. ResourceCode string `gorm:"column:resource_code"`
  43. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  44. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  45. SourceFrom string `gorm:"column:source_from"`
  46. TagId int `gorm:"column:tag_id;default:0;NOT NULL"`
  47. StartTime *time.Time `gorm:"column:start_time"`
  48. EndTime *time.Time `gorm:"column:end_time"`
  49. IsFile int `gorm:"column:is_file;default:0;NOT NULL"`
  50. FileUrl []string `gorm:"column:file_url"`
  51. }
  52. type KnowledgeResource struct {
  53. KnowledgeResourceId int `gorm:"column:knowledge_resource_id;;primaryKey;autoIncrement"`
  54. ResourceType int `gorm:"column:resource_type;"`
  55. ClassifyId int `gorm:"column:classify_id"`
  56. Title string `gorm:"column:title;"`
  57. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  58. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  59. State int `gorm:"column:state" description:"状态:0:未发布;1:已发布;2:待审核;3:已驳回;4:已通过"`
  60. Content string `gorm:"column:content"`
  61. ResourceCode string `gorm:"column:resource_code"`
  62. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  63. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  64. SourceFrom string `gorm:"column:source_from"`
  65. TagId int `gorm:"column:tag_id;default:0;NOT NULL"`
  66. StartTime *time.Time `gorm:"column:start_time"`
  67. EndTime *time.Time `gorm:"column:end_time"`
  68. IsFile int `gorm:"column:is_file;default:0;NOT NULL"`
  69. FileUrl string `gorm:"column:file_url"`
  70. IsDelete int `gorm:"column:is_delete;default:0;NOT NULL"`
  71. OutSource int `gorm:"column:out_source" description:"外部来源:0:内部 1:智力共享 2:数据节点"`
  72. }
  73. func (m *KnowledgeResource) TableName() string {
  74. return "knowledge_resource"
  75. }
  76. // 查询列表
  77. func (m *KnowledgeResource) QueryList(condition string, pars []interface{}) (items []*KnowledgeResource, err error) {
  78. return
  79. }
  80. type KnowledgeResourceList struct {
  81. KnowledgeResourceId int `gorm:"column:knowledge_resource_id;;primaryKey;autoIncrement"`
  82. ResourceType int `gorm:"column:resource_type;"`
  83. ClassifyId int `gorm:"column:classify_id"`
  84. Title string `gorm:"column:title;"`
  85. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  86. ModifyTime string `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  87. State int `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  88. ResourceCode string `gorm:"column:resource_code"`
  89. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  90. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  91. SourceFrom string `gorm:"column:source_from"`
  92. TagId int `gorm:"column:tag_id;default:0;NOT NULL"`
  93. StartTime string `gorm:"column:start_time"`
  94. EndTime string `gorm:"column:end_time"`
  95. Content string `gorm:"-"`
  96. ClassifyFullName string
  97. TagName string
  98. }
  99. type KnowledgeResourceListResp struct {
  100. List []*KnowledgeResourceList
  101. Paging *paging.PagingItem `description:"分页数据"`
  102. }
  103. func GetBatchKnowledgeResource(batchSize int, id int) (items []*KnowledgeResource, err error) {
  104. sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id>=? AND is_delete=0 ORDER BY knowledge_resource_id ASC LIMIT ?`
  105. pars := []interface{}{id, batchSize}
  106. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  107. return
  108. }
  109. func GetBatchKnowledgeResourceByCondition(condition string, pars []interface{}, batchSize int) (items []*KnowledgeResource, err error) {
  110. sql := `SELECT * FROM knowledge_resource WHERE is_delete=0 `
  111. if condition != "" {
  112. sql += condition
  113. }
  114. pars = append(pars, batchSize)
  115. sql += `ORDER BY knowledge_resource_id ASC LIMIT ?`
  116. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  117. return
  118. }
  119. func GetKnowledgeResourcePageList(condition string, pars []interface{}, startSize, pageSize int) (items []*KnowledgeResource, err error) {
  120. sql := `SELECT * FROM knowledge_resource WHERE 1=1 AND is_delete=0 `
  121. if condition != "" {
  122. sql += condition
  123. }
  124. sql += `ORDER BY modify_time DESC LIMIT ?,?`
  125. pars = append(pars, startSize)
  126. pars = append(pars, pageSize)
  127. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  128. return
  129. }
  130. func GetKnowledgeResourceIdList(condition string, pars []interface{}) (items []int, err error) {
  131. sql := `SELECT knowledge_resource_id FROM knowledge_resource WHERE 1=1 `
  132. if condition != "" {
  133. sql += condition
  134. }
  135. sql += `ORDER BY modify_time DESC`
  136. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  137. return
  138. }
  139. func GetKnowledgeResourceListCount(condition string, pars []interface{}) (count int, err error) {
  140. sql := `SELECT COUNT(1) AS count FROM knowledge_resource WHERE 1=1 AND is_delete=0 `
  141. if condition != "" {
  142. sql += condition
  143. }
  144. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  145. return
  146. }
  147. func GetKnowledgeResourcePageByIds(ids []int, startSize, pageSize int) (items []*KnowledgeResource, err error) {
  148. if len(ids) == 0 {
  149. return
  150. }
  151. sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id in (?) ORDER BY modify_time DESC LIMIT ?,?`
  152. err = global.DmSQL["rddp"].Raw(sql, ids, startSize, pageSize).Find(&items).Error
  153. return
  154. }
  155. func GetKnowledgeResourceByIds(ids []int) (items []*KnowledgeResource, err error) {
  156. if len(ids) == 0 {
  157. return
  158. }
  159. sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id in (?) ORDER BY start_time DESC`
  160. err = global.DmSQL["rddp"].Raw(sql, ids).Find(&items).Error
  161. return
  162. }
  163. // Delete逻辑删除
  164. func (m *KnowledgeResource) Delete(knowledgeResourceIds int) (err error) {
  165. sql := ` UPDATE knowledge_resource SET is_delete = 1 WHERE knowledge_resource_id =? `
  166. err = global.DmSQL["rddp"].Exec(sql, knowledgeResourceIds).Error
  167. return
  168. }
  169. func (m *KnowledgeResource) GetById(knowledgeResourceId int) (item *KnowledgeResource, err error) {
  170. sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id =?`
  171. err = global.DmSQL["rddp"].Raw(sql, knowledgeResourceId).First(&item).Error
  172. return
  173. }
  174. type DeleteReq struct {
  175. KnowledgeResourceId int `description:"事件id"`
  176. ResourceType int
  177. }
  178. type AddReq struct {
  179. ResourceType int `gorm:"column:resource_type;"`
  180. ClassifyId int `gorm:"column:classify_id"`
  181. Title string `gorm:"column:title;"`
  182. State int `gorm:"column:state" description:"0:未发布;1:已发布"`
  183. Content string `gorm:"column:content"`
  184. SourceFrom string `gorm:"column:source_from"`
  185. TagId int `gorm:"column:tag_id;default:0;NOT NULL"`
  186. StartTime string `gorm:"column:start_time"`
  187. EndTime string `gorm:"column:end_time"`
  188. FileUrl string `gorm:"column:file_url"`
  189. }
  190. type AddResp struct {
  191. KnowledgeResourceId int `description:"事件id"`
  192. ResourceCode string `description:"事件code"`
  193. }
  194. type PublicReq struct {
  195. KnowledgeResourceId int `description:"事件id"`
  196. }
  197. func (m *KnowledgeResource) Add(item *KnowledgeResource) (err error) {
  198. err = global.DmSQL["rddp"].Create(item).Error
  199. return
  200. }
  201. func (m *KnowledgeResource) AddBatch(item []*KnowledgeResource) (err error) {
  202. err = global.DmSQL["rddp"].CreateInBatches(item, 50).Error
  203. return
  204. }
  205. type EditReq struct {
  206. KnowledgeResourceId int64 `description:"事件id"`
  207. AddReq
  208. }
  209. type EditResp struct {
  210. KnowledgeResourceId int64 `description:"事件id"`
  211. ResourceCode string `description:"事件code"`
  212. }
  213. type SaveReportContent struct {
  214. Content string `description:"内容"`
  215. KnowledgeResourceId int `description:"事件id"`
  216. NoChange int `description:"内容是否未改变:1:内容未改变"`
  217. // 以下是智能研报相关
  218. ContentStruct string `description:"内容组件"`
  219. HeadImg string `description:"事件头图地址"`
  220. EndImg string `description:"事件尾图地址"`
  221. CanvasColor string `description:"画布颜色"`
  222. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史事件。0-不需要 1-需要"`
  223. HeadResourceId int `description:"版头资源ID"`
  224. EndResourceId int `description:"版尾资源ID"`
  225. }
  226. type SaveReportContentResp struct {
  227. KnowledgeResourceId int `description:"事件id"`
  228. }
  229. // SaveDayWeekReportReq 新增晨报周报请求体
  230. type SaveDayWeekReportReq struct {
  231. KnowledgeResourceId int `description:"事件ID"`
  232. Title string `description:"标题"`
  233. ReportType string `description:"一级分类ID"`
  234. Author string `description:"作者"`
  235. CreateTime string `description:"创建时间"`
  236. }
  237. func (m *KnowledgeResource) Update(cols []string) (err error) {
  238. err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
  239. return
  240. }
  241. // MarkEditReport 标记编辑英文研报的请求数据
  242. type MarkEditReport struct {
  243. KnowledgeResourceId int `description:"研报id"`
  244. ReportChapterId int `description:"研报章节id"`
  245. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  246. }
  247. type MarkReportResp struct {
  248. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  249. Msg string `description:"提示信息"`
  250. Editor string `description:"编辑者姓名"`
  251. }
  252. type MarkReportItem struct {
  253. AdminId int `description:"编辑者ID"`
  254. Editor string `description:"编辑者姓名"`
  255. ReportClassifyNameFirst string
  256. }
  257. func (m *KnowledgeResource) AddMulti(items []*KnowledgeResource) (err error) {
  258. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  259. return
  260. }
  261. func (m *KnowledgeResource) GetSourceFrom(keyword string, resourceType int) (items []string, err error) {
  262. sql := fmt.Sprintf(`SELECT distinct source_from FROM %s WHERE 1=1 and resource_type=? `, m.TableName())
  263. if keyword != `` {
  264. sql += ` AND source_from LIKE '%` + keyword + `%'`
  265. }
  266. err = global.DmSQL["rddp"].Raw(sql, resourceType).Scan(&items).Error
  267. return
  268. }
  269. type KnowledgeResourceDetailView struct {
  270. *KnowledgeResourceDetail
  271. }
  272. type ResourceImportData struct {
  273. Title string `description:"标题"`
  274. StartDate string `description:"开始日期"`
  275. EndDate string `description:"开始时间"`
  276. StartTime string `description:"结束日期"`
  277. EndTime string `description:"结束时间"`
  278. Content string `description:"正文"`
  279. Tag string `description:"标签"`
  280. SourceFrom string `description:"来源"`
  281. ClassifyFirstName string `description:"一级分类"`
  282. ClassifySecondName string `description:"二级分类"`
  283. ClassifyThirdName string `description:"三级分类"`
  284. }
  285. type UpdateResourceResp struct {
  286. FileUrl string `description:"文件地址"`
  287. }
  288. type GetSourceFromResp struct {
  289. List []string `description:"来源列表"`
  290. }
  291. type GetAdminsResp struct {
  292. List []*GetAdminsRespItem `description:"添加人"`
  293. }
  294. type GetAdminsRespItem struct {
  295. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  296. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  297. }
  298. func (m *KnowledgeResource) GetAdmins(keyword string, resourceType int) (items []*GetAdminsRespItem, err error) {
  299. sql := fmt.Sprintf(`SELECT distinct admin_id, admin_real_name FROM %s WHERE 1=1 and resource_type=? `, m.TableName())
  300. if keyword != `` {
  301. sql += ` AND admin_real_name LIKE '%` + keyword + `%'`
  302. }
  303. err = global.DmSQL["rddp"].Raw(sql, resourceType).Scan(&items).Error
  304. return
  305. }
  306. // UpdateClassifySortByParentId 根据父类id更新排序
  307. func (m *KnowledgeResource) UpdateClassifyIdByIds(ids []int, classifyId int, resourceType int) (err error) {
  308. var pars []interface{}
  309. sql := ` UPDATE %s set classify_id =? WHERE resource_type=? AND knowledge_resource_id in (?) `
  310. pars = append(pars, classifyId, resourceType, ids)
  311. sql = fmt.Sprintf(sql, m.TableName())
  312. err = global.DmSQL["rddp"].Exec(sql, pars...).Error
  313. return
  314. }
  315. type BiDashboardResourceAddReq struct {
  316. BiDashboardDetailId int `description:"Bi看板详情"`
  317. KnowledgeResourceList []KnowledgeResourceMapItem `description:"知识资源id"`
  318. }
  319. type BiDashboardResourceAddResp struct {
  320. BiDashboardDetailId int `description:"Bi看板详情"`
  321. KnowledgeResourceList []*KnowledgeResourceList `description:"知识资源列表"`
  322. }
  323. type KnowledgeResourceMapItem struct {
  324. KnowledgeResourceId int
  325. ResourceType int
  326. }