knowledge_resource.go 13 KB

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