knowledge_resource.go 12 KB

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