knowledge_resource.go 10 KB

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