resource_data.go 8.9 KB

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