knowledge_resource.go 14 KB

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