knowledge_resource.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. OutSource int `gorm:"column:out_source" description:"外部来源:0:内部 1:智力共享 2:数据节点"`
  97. ClassifyFullName string
  98. TagName string
  99. }
  100. type KnowledgeResourceListResp struct {
  101. List []*KnowledgeResourceList
  102. Paging *paging.PagingItem `description:"分页数据"`
  103. }
  104. func GetBatchKnowledgeResource(batchSize int, id int) (items []*KnowledgeResource, err error) {
  105. sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id>=? AND is_delete=0 ORDER BY knowledge_resource_id ASC LIMIT ?`
  106. pars := []interface{}{id, batchSize}
  107. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  108. return
  109. }
  110. func GetBatchKnowledgeResourceByCondition(condition string, pars []interface{}, batchSize int) (items []*KnowledgeResource, err error) {
  111. sql := `SELECT * FROM knowledge_resource WHERE is_delete=0 `
  112. if condition != "" {
  113. sql += condition
  114. }
  115. pars = append(pars, batchSize)
  116. sql += `ORDER BY knowledge_resource_id ASC LIMIT ?`
  117. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  118. return
  119. }
  120. func GetKnowledgeResourcePageList(condition string, pars []interface{}, sortCond string, startSize, pageSize int) (items []*KnowledgeResource, err error) {
  121. sql := `SELECT * FROM knowledge_resource WHERE 1=1 AND is_delete=0 `
  122. if condition != "" {
  123. sql += condition
  124. }
  125. if sortCond != "" {
  126. sql += sortCond
  127. } else {
  128. sql += `ORDER BY modify_time DESC `
  129. }
  130. sql += ` LIMIT ?,?`
  131. pars = append(pars, startSize)
  132. pars = append(pars, pageSize)
  133. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  134. return
  135. }
  136. func GetKnowledgeResourceIdList(condition string, pars []interface{}) (items []int, err error) {
  137. sql := `SELECT knowledge_resource_id FROM knowledge_resource WHERE 1=1 `
  138. if condition != "" {
  139. sql += condition
  140. }
  141. sql += `ORDER BY modify_time DESC`
  142. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  143. return
  144. }
  145. func GetKnowledgeResourceListCount(condition string, pars []interface{}) (count int, err error) {
  146. sql := `SELECT COUNT(1) AS count FROM knowledge_resource WHERE 1=1 AND is_delete=0 `
  147. if condition != "" {
  148. sql += condition
  149. }
  150. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  151. return
  152. }
  153. func GetKnowledgeResourcePageByIds(ids []int, startSize, pageSize int) (items []*KnowledgeResource, err error) {
  154. if len(ids) == 0 {
  155. return
  156. }
  157. sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id in (?) ORDER BY modify_time DESC LIMIT ?,?`
  158. err = global.DmSQL["rddp"].Raw(sql, ids, startSize, pageSize).Find(&items).Error
  159. return
  160. }
  161. func GetKnowledgeResourceByIds(ids []int) (items []*KnowledgeResource, err error) {
  162. if len(ids) == 0 {
  163. return
  164. }
  165. sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id in (?) ORDER BY start_time DESC`
  166. err = global.DmSQL["rddp"].Raw(sql, ids).Find(&items).Error
  167. return
  168. }
  169. // Delete逻辑删除
  170. func (m *KnowledgeResource) Delete(knowledgeResourceIds int) (err error) {
  171. sql := ` UPDATE knowledge_resource SET is_delete = 1 WHERE knowledge_resource_id =? `
  172. err = global.DmSQL["rddp"].Exec(sql, knowledgeResourceIds).Error
  173. return
  174. }
  175. func (m *KnowledgeResource) GetById(knowledgeResourceId int) (item *KnowledgeResource, err error) {
  176. sql := `SELECT * FROM knowledge_resource WHERE knowledge_resource_id =?`
  177. err = global.DmSQL["rddp"].Raw(sql, knowledgeResourceId).First(&item).Error
  178. return
  179. }
  180. type DeleteReq struct {
  181. KnowledgeResourceId int `description:"事件id"`
  182. ResourceType int
  183. }
  184. type AddReq struct {
  185. ResourceType int `gorm:"column:resource_type;"`
  186. ClassifyId int `gorm:"column:classify_id"`
  187. Title string `gorm:"column:title;"`
  188. State int `gorm:"column:state" description:"0:未发布;1:已发布"`
  189. Content string `gorm:"column:content"`
  190. SourceFrom string `gorm:"column:source_from"`
  191. TagId int `gorm:"column:tag_id;default:0;NOT NULL"`
  192. StartTime string `gorm:"column:start_time"`
  193. EndTime string `gorm:"column:end_time"`
  194. FileUrl []string `gorm:"column:file_url"`
  195. }
  196. type AddResp struct {
  197. KnowledgeResourceId int `description:"事件id"`
  198. ResourceCode string `description:"事件code"`
  199. }
  200. type PublicReq struct {
  201. KnowledgeResourceId int `description:"事件id"`
  202. }
  203. func (m *KnowledgeResource) Add(item *KnowledgeResource) (err error) {
  204. err = global.DmSQL["rddp"].Create(item).Error
  205. return
  206. }
  207. func (m *KnowledgeResource) AddWithFile(file []string) (err error) {
  208. tx := global.DmSQL["rddp"].Begin()
  209. defer func() {
  210. if err != nil {
  211. tx.Rollback()
  212. } else {
  213. tx.Commit()
  214. }
  215. }()
  216. err = tx.Create(m).Error
  217. if err != nil {
  218. return
  219. }
  220. if len(file) > 0 {
  221. fileList := make([]*KnowledgeResourceFile, len(file))
  222. for i, v := range file {
  223. fileList[i] = &KnowledgeResourceFile{
  224. KnowledgeResourceId: m.KnowledgeResourceId,
  225. FileUrl: v,
  226. }
  227. }
  228. err = tx.CreateInBatches(fileList, utils.MultiAddNum).Error
  229. if err != nil {
  230. return
  231. }
  232. }
  233. return
  234. }
  235. func (m *KnowledgeResource) AddBatch(item []*KnowledgeResource) (err error) {
  236. err = global.DmSQL["rddp"].CreateInBatches(item, 50).Error
  237. return
  238. }
  239. type EditReq struct {
  240. KnowledgeResourceId int64 `description:"事件id"`
  241. AddReq
  242. }
  243. type EditResp struct {
  244. KnowledgeResourceId int64 `description:"事件id"`
  245. ResourceCode string `description:"事件code"`
  246. }
  247. type SaveReportContent struct {
  248. Content string `description:"内容"`
  249. KnowledgeResourceId int `description:"事件id"`
  250. NoChange int `description:"内容是否未改变:1:内容未改变"`
  251. // 以下是智能研报相关
  252. ContentStruct string `description:"内容组件"`
  253. HeadImg string `description:"事件头图地址"`
  254. EndImg string `description:"事件尾图地址"`
  255. CanvasColor string `description:"画布颜色"`
  256. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史事件。0-不需要 1-需要"`
  257. HeadResourceId int `description:"版头资源ID"`
  258. EndResourceId int `description:"版尾资源ID"`
  259. }
  260. type SaveReportContentResp struct {
  261. KnowledgeResourceId int `description:"事件id"`
  262. }
  263. // SaveDayWeekReportReq 新增晨报周报请求体
  264. type SaveDayWeekReportReq struct {
  265. KnowledgeResourceId int `description:"事件ID"`
  266. Title string `description:"标题"`
  267. ReportType string `description:"一级分类ID"`
  268. Author string `description:"作者"`
  269. CreateTime string `description:"创建时间"`
  270. }
  271. func (m *KnowledgeResource) Update(cols []string) (err error) {
  272. err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
  273. return
  274. }
  275. func (m *KnowledgeResource) UpdateWithFile(cols, file []string) (err error) {
  276. tx := global.DmSQL["rddp"].Begin()
  277. defer func() {
  278. if err != nil {
  279. tx.Rollback()
  280. } else {
  281. tx.Commit()
  282. }
  283. }()
  284. err = tx.Select(cols).Updates(m).Error
  285. if err != nil {
  286. return
  287. }
  288. if len(file) > 0 {
  289. sql := `DELETE FROM knowledge_resource_file WHERE knowledge_resource_id =?`
  290. err = tx.Exec(sql, m.KnowledgeResourceId).Error
  291. if err != nil {
  292. return
  293. }
  294. fileList := make([]*KnowledgeResourceFile, len(file))
  295. for i, v := range file {
  296. fileList[i] = &KnowledgeResourceFile{
  297. KnowledgeResourceId: m.KnowledgeResourceId,
  298. FileUrl: v,
  299. }
  300. }
  301. err = tx.CreateInBatches(fileList, utils.MultiAddNum).Error
  302. if err != nil {
  303. return
  304. }
  305. }
  306. return
  307. }
  308. // MarkEditReport 标记编辑英文研报的请求数据
  309. type MarkEditReport struct {
  310. KnowledgeResourceId int `description:"研报id"`
  311. ReportChapterId int `description:"研报章节id"`
  312. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  313. }
  314. type MarkReportResp struct {
  315. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  316. Msg string `description:"提示信息"`
  317. Editor string `description:"编辑者姓名"`
  318. }
  319. type MarkReportItem struct {
  320. AdminId int `description:"编辑者ID"`
  321. Editor string `description:"编辑者姓名"`
  322. ReportClassifyNameFirst string
  323. }
  324. func (m *KnowledgeResource) AddMulti(items []*KnowledgeResource) (err error) {
  325. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  326. return
  327. }
  328. func (m *KnowledgeResource) GetSourceFrom(keyword string, resourceType int) (items []string, err error) {
  329. sql := fmt.Sprintf(`SELECT distinct source_from FROM %s WHERE 1=1 and resource_type=? `, m.TableName())
  330. if keyword != `` {
  331. sql += ` AND source_from LIKE '%` + keyword + `%'`
  332. }
  333. err = global.DmSQL["rddp"].Raw(sql, resourceType).Scan(&items).Error
  334. return
  335. }
  336. type KnowledgeResourceDetailView struct {
  337. *KnowledgeResourceDetail
  338. }
  339. type ResourceImportData struct {
  340. Title string `description:"标题"`
  341. StartDate string `description:"开始日期"`
  342. EndDate string `description:"开始时间"`
  343. StartTime string `description:"结束日期"`
  344. EndTime string `description:"结束时间"`
  345. Content string `description:"正文"`
  346. Tag string `description:"标签"`
  347. SourceFrom string `description:"来源"`
  348. ClassifyFirstName string `description:"一级分类"`
  349. ClassifySecondName string `description:"二级分类"`
  350. ClassifyThirdName string `description:"三级分类"`
  351. }
  352. type UpdateResourceResp struct {
  353. FileUrl string `description:"文件地址"`
  354. }
  355. type GetSourceFromResp struct {
  356. List []string `description:"来源列表"`
  357. }
  358. type GetAdminsResp struct {
  359. List []*GetAdminsRespItem `description:"添加人"`
  360. }
  361. type GetAdminsRespItem struct {
  362. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  363. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  364. }
  365. func (m *KnowledgeResource) GetAdmins(keyword string, resourceType int) (items []*GetAdminsRespItem, err error) {
  366. sql := fmt.Sprintf(`SELECT distinct admin_id, admin_real_name FROM %s WHERE 1=1 and resource_type=? `, m.TableName())
  367. if keyword != `` {
  368. sql += ` AND admin_real_name LIKE '%` + keyword + `%'`
  369. }
  370. err = global.DmSQL["rddp"].Raw(sql, resourceType).Scan(&items).Error
  371. return
  372. }
  373. // UpdateClassifySortByParentId 根据父类id更新排序
  374. func (m *KnowledgeResource) UpdateClassifyIdByIds(ids []int, classifyId int, resourceType int) (err error) {
  375. var pars []interface{}
  376. sql := ` UPDATE %s set classify_id =? WHERE resource_type=? AND knowledge_resource_id in (?) `
  377. pars = append(pars, classifyId, resourceType, ids)
  378. sql = fmt.Sprintf(sql, m.TableName())
  379. err = global.DmSQL["rddp"].Exec(sql, pars...).Error
  380. return
  381. }
  382. type BiDashboardResourceAddReq struct {
  383. BiDashboardDetailId int `description:"Bi看板详情"`
  384. KnowledgeResourceList []KnowledgeResourceMapItem `description:"知识资源id"`
  385. }
  386. type BiDashboardResourceAddResp struct {
  387. BiDashboardDetailId int `description:"Bi看板详情"`
  388. KnowledgeResourceList []*KnowledgeResourceList `description:"知识资源列表"`
  389. }
  390. type KnowledgeResourceMapItem struct {
  391. KnowledgeResourceId int
  392. ResourceType int
  393. }