resource_data.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/utils"
  6. "time"
  7. )
  8. type CygxResourceData struct {
  9. Id int `orm:"column(id);pk"`
  10. ChartPermissionId int `description:"行业ID"`
  11. SourceId int `description:"资源ID"`
  12. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  13. Title string `description:"标题"`
  14. Annotation string `description:"核心观点"`
  15. CreateTime time.Time `description:"创建时间"`
  16. PublishDate string `description:"发布时间"`
  17. Abstract string `description:"摘要"`
  18. SearchTag string `description:"搜索标签"`
  19. SearchTitle string `description:"搜索匹配用的标题"`
  20. SearchContent string `description:"搜索匹配用的内容"`
  21. SearchOrderTime string `description:"搜索排序时间"`
  22. TagName string `description:"标签名"`
  23. }
  24. // FICC研报小程序
  25. type FiccReportXcx struct {
  26. Source string `description:"资源类型"`
  27. Title string `description:"标题"`
  28. SecondTitle string `description:"副标题"`
  29. ImgUrl string `description:"背景图片"`
  30. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  31. Mobile string `description:"用户手机号"`
  32. SellerMobile string `description:"销售电话"`
  33. SellerName string `description:"销售姓名"`
  34. Appid string `description:"FICC研报小程序Appid"`
  35. SourceUrl string `description:"跳转资源地址"`
  36. ThirdCode string `description:"三方加密标识"`
  37. }
  38. type CygxResourceDataResp struct {
  39. Id int `orm:"column(id);pk"`
  40. BodyHighlight []string `description:"搜索高亮展示结果"`
  41. IsSummary int `description:"是否是纪要"`
  42. SourceId int `description:"资源ID"`
  43. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  44. PublishDate string `description:"发布时间"`
  45. Article *HomeArticle `description:"文章"`
  46. Newchart *HomeChartListResp `description:"图表"`
  47. Roadshow *MicroRoadShowPageList `description:"微路演"`
  48. Activity *ActivityDetail `description:"活动"`
  49. Activityvideo *MicroRoadShowPageList `description:"活动视频"`
  50. Activityvoice *MicroRoadShowPageList `description:"活动音频"`
  51. Activityspecial *CygxActivitySpecialDetail `description:"专项调研活动"`
  52. Researchsummary *CygxReportSelectionRep `description:"本周研究汇总"`
  53. Minutessummary *CygxReportSelectionRep `description:"上周纪要汇总"`
  54. Meetingreviewchapt *CygxMorningMeetingGatherDetailListResp `description:"晨会精华"`
  55. ProductInterior *CygxProductInteriorResp `description:"产品内测"`
  56. IndustrialResource *IndustrialManagementHotResp `description:"产业资源包"`
  57. ReportSelection *CygxReportSelectionRep `description:"重点公司(原报告精选)"`
  58. YanxuanSpecial *CygxYanxuanSpecialCenterResp `description:"研选专栏"`
  59. AskserieVideo *MicroRoadShowPageList `description:"活动音频"`
  60. FiccReport *HomeArticle `description:"FICC研报"`
  61. FiccReportXcx *FiccReportXcx `description:"FICC研报"`
  62. }
  63. // Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  64. type HomeResourceDataListResp struct {
  65. Paging *paging.PagingItem
  66. List []*CygxResourceDataResp `description:"列表"`
  67. }
  68. // 列表
  69. func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
  70. o := orm.NewOrm()
  71. sql := `SELECT * FROM cygx_resource_data WHERE 1= 1 `
  72. if condition != "" {
  73. sql += condition
  74. }
  75. sql += ` ORDER BY publish_date DESC , id DESC LIMIT ?,? `
  76. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  77. return
  78. }
  79. // 列表
  80. func GetResourceDataListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
  81. o := orm.NewOrm()
  82. sql := `SELECT * FROM cygx_resource_data WHERE 1= 1 `
  83. if condition != "" {
  84. sql += condition
  85. }
  86. sql += ` ORDER BY search_order_time DESC LIMIT ?,? `
  87. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  88. return
  89. }
  90. // 获取数量
  91. func GetResourceDataCount(condition string, pars []interface{}) (count int, err error) {
  92. sqlCount := `SELECT COUNT(1) AS count FROM cygx_resource_data WHERE 1= 1 ` + condition
  93. o := orm.NewOrm()
  94. err = o.Raw(sqlCount, pars).QueryRow(&count)
  95. return
  96. }
  97. // 添加
  98. func AddCygxResourceData(item *CygxResourceData) (lastId int64, err error) {
  99. o := orm.NewOrm()
  100. lastId, err = o.Insert(item)
  101. return
  102. }
  103. // 删除数据
  104. func DeleteResourceData(sourceId int, source string) (err error) {
  105. o := orm.NewOrm()
  106. sql := ` DELETE FROM cygx_resource_data WHERE source_id = ? AND source =? `
  107. _, err = o.Raw(sql, sourceId, source).Exec()
  108. return
  109. }
  110. // 修改数据
  111. func UpdateResourceData(sourceId int, source, publishDate string) (err error) {
  112. o := orm.NewOrm()
  113. sql := `UPDATE cygx_resource_data SET publish_date=? WHERE source_id=? AND source =? `
  114. _, err = o.Raw(sql, publishDate, sourceId, source).Exec()
  115. return
  116. }
  117. // 修改
  118. func UpdateResourceDataByItem(item *CygxResourceData) (err error) {
  119. o := orm.NewOrm()
  120. updateParams := make(map[string]interface{})
  121. updateParams["PublishDate"] = item.PublishDate
  122. updateParams["SearchTag"] = item.SearchTag
  123. updateParams["SearchTitle"] = item.SearchTitle
  124. updateParams["TagName"] = item.TagName
  125. updateParams["SearchContent"] = item.SearchContent
  126. updateParams["SearchOrderTime"] = item.SearchOrderTime
  127. ptrStructOrTableName := "cygx_resource_data"
  128. whereParam := map[string]interface{}{"source_id": item.SourceId, "source": item.Source}
  129. qs := o.QueryTable(ptrStructOrTableName)
  130. for expr, exprV := range whereParam {
  131. qs = qs.Filter(expr, exprV)
  132. }
  133. _, err = qs.Update(updateParams)
  134. if err != nil {
  135. return
  136. }
  137. return
  138. }
  139. // 批量删除
  140. func DeleteResourceDataList(condition string, pars []interface{}) (err error) {
  141. if condition == "" {
  142. return
  143. }
  144. o := orm.NewOrm()
  145. sql := `DELETE FROM cygx_resource_data WHERE 1=1 ` + condition
  146. _, err = o.Raw(sql, pars).Exec()
  147. return
  148. }
  149. // 获取数量
  150. func GetCygxReportSelectionBySourceAndId(sourceId int, source string) (count int, err error) {
  151. o := orm.NewOrm()
  152. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  153. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  154. return
  155. }
  156. // 通过ID跟资源获取详情
  157. func GetCygxResourceDataByIdAndSource(sourceId int, source string) (item *CygxResourceData, err error) {
  158. o := orm.NewOrm()
  159. sql := `SELECT * FROM cygx_resource_data WHERE source_id = ? AND source =? `
  160. err = o.Raw(sql, sourceId, source).QueryRow(&item)
  161. return
  162. }
  163. // 获取数量
  164. func GetCygxResourceDataBySourceAndIdCount(sourceId int, source string) (count int, err error) {
  165. o := orm.NewOrm()
  166. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  167. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  168. return
  169. }
  170. // 隐藏同步过来的报告
  171. func HideCygxResourceDataFiccReport(sourceIds []int) (err error) {
  172. lenArr := len(sourceIds)
  173. if lenArr == 0 {
  174. return
  175. }
  176. o := orm.NewOrm()
  177. to, err := o.Begin()
  178. if err != nil {
  179. return
  180. }
  181. defer func() {
  182. if err != nil {
  183. _ = to.Rollback()
  184. } else {
  185. _ = to.Commit()
  186. }
  187. }()
  188. //隐藏资源表
  189. sql := ` DELETE FROM cygx_resource_data WHERE source_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND source = ? `
  190. _, err = to.Raw(sql, sourceIds, utils.CYGX_OBJ_FICC_REPORT).Exec()
  191. if err != nil {
  192. return
  193. }
  194. //对应文章取消发布
  195. sql = ` UPDATE cygx_article SET publish_status= 0 WHERE report_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  196. _, err = to.Raw(sql, sourceIds).Exec()
  197. if err != nil {
  198. return
  199. }
  200. return
  201. }