resource_data.go 9.3 KB

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