knowledge_resource.go 9.9 KB

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