article.go 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "github.com/PuerkitoBio/goquery"
  8. "hongze/hongze_cygx/models"
  9. "hongze/hongze_cygx/models/company"
  10. "hongze/hongze_cygx/utils"
  11. "html"
  12. "net/url"
  13. "regexp"
  14. "sort"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. func GetReportContentTextSub(content string) (contentSub string, err error) {
  20. content = html.UnescapeString(content)
  21. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  22. docText := doc.Text()
  23. bodyRune := []rune(docText)
  24. bodyRuneLen := len(bodyRune)
  25. if bodyRuneLen > 200 {
  26. bodyRuneLen = 200
  27. }
  28. body := string(bodyRune[:bodyRuneLen])
  29. contentSub = body
  30. contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
  31. return
  32. }
  33. func GetAnnotationTextSub(content string) (contentSub string) {
  34. contentSub = strings.Replace(content, "<p class=\"ql-align-justify\">", "&nbsp;", -1)
  35. contentSub = strings.Replace(contentSub, "</p>", "", -1)
  36. return
  37. }
  38. func GetReportContentTextSubNew(content string) (contentSub string, err error) {
  39. content = html.UnescapeString(content)
  40. doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(content))
  41. if errdoc != nil {
  42. err = errdoc
  43. return
  44. }
  45. docText := doc.Text()
  46. bodyRune := []rune(docText)
  47. bodyRuneLen := len(bodyRune)
  48. body := string(bodyRune[:bodyRuneLen])
  49. contentSub = body
  50. contentSub = strings.Replace(contentSub, "Powered by Froala Editor", "", -1)
  51. contentSub = strings.Replace(contentSub, " ", "", -1)
  52. contentSub = strings.Replace(contentSub, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sanered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  53. return
  54. }
  55. func FixArticleImgUrl(body string) (contentSub string, err error) {
  56. r := strings.NewReader(string(body))
  57. doc, err := goquery.NewDocumentFromReader(r)
  58. if err != nil {
  59. fmt.Println(err)
  60. }
  61. doc.Find("img").Each(func(i int, s *goquery.Selection) {
  62. src, _ := s.Attr("src")
  63. if i == 0 && src != "" {
  64. contentSub = src
  65. }
  66. })
  67. return
  68. }
  69. func SynchronizationArtclehistory() {
  70. fmt.Println("同步开始")
  71. list, err := models.GetArticleHistoryList()
  72. if err != nil {
  73. fmt.Println("获取列表失败", err)
  74. }
  75. fmt.Println(len(list))
  76. for _, v := range list {
  77. //endDate := v.ModifyTime.Add(+time.Minute * 10).Format(utils.FormatDateTime)
  78. //detail, err := models.GetNewArticleHistoryRecordNewpv(v.UserId, v.ArticleId, endDate)
  79. //if err != nil && err.Error() != utils.ErrNoRow() {
  80. // fmt.Println("获取信息失败", err)
  81. //}
  82. v.OutType = 1
  83. //fmt.Println(v.Id)
  84. //if detail == nil {
  85. // _, err = models.AddCygxArticleViewRecordNewpv(v)
  86. // if err != nil {
  87. // fmt.Println("新增失败", err)
  88. // }
  89. //} else {
  90. // err = models.UpdateCygxArticleViewRecordNewpvList(v, v.StopTime)
  91. // if err != nil {
  92. // fmt.Println("修改失败", err)
  93. // }
  94. //}
  95. newId, err := models.AddCygxArticleViewRecordNewpv(v)
  96. fmt.Println("新增", newId)
  97. if err != nil {
  98. fmt.Println("新增失败", err)
  99. }
  100. }
  101. fmt.Println("同步结束")
  102. }
  103. // UserViewRedisData 阅读数据
  104. type UserViewRedisData struct {
  105. Mobile string `json:"mobile"`
  106. Email string `json:"email"`
  107. RealName string `json:"real_name"`
  108. CompanyName string `json:"company_name"`
  109. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  110. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  111. CompanyId int `json:"company_id" description:"客户id"`
  112. UserId int `json:"user_id" description:"用户id"`
  113. ReportId int `json:"report_id" description:"报告id"`
  114. StopTime int `json:"stop_time" description:"停留时间"`
  115. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  116. OutId int `json:"out_id" description:"记录ID"`
  117. }
  118. type ReportViewRecord struct {
  119. Id int `orm:"column(id);pk"`
  120. //UserId int `json:"user_id" description:"用户ID"`
  121. //ReportId int `description:"报告id"`
  122. //Mobile string `description:"手机号"`
  123. //Email string `description:"邮箱"`
  124. //RealName string `description:"用户实际姓名"`
  125. //CompanyName string `description:"公司名称"`
  126. //CreateTime time.Time `description:"创建时间"`
  127. //StopTime int `json:"stop_time" description:"停留时间"`
  128. //ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  129. //OutId int `json:"out_id" description:"记录ID"`
  130. Mobile string `json:"mobile"`
  131. Email string `json:"email"`
  132. RealName string `json:"real_name"`
  133. CompanyName string `json:"company_name"`
  134. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  135. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  136. CompanyId int `json:"company_id" description:"客户id"`
  137. UserId int `json:"user_id" description:"用户id"`
  138. ReportId int `json:"report_id" description:"报告id"`
  139. StopTime int `json:"stop_time" description:"停留时间"`
  140. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  141. OutId int `json:"out_id" description:"章节ID"`
  142. }
  143. // PushViewRecordNewRedisData 阅读数据加入到redis
  144. func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
  145. data := &UserViewRedisData{
  146. Mobile: reportViewRecord.Mobile,
  147. UserId: reportViewRecord.UserId,
  148. Email: reportViewRecord.Email,
  149. RealName: reportViewRecord.RealName,
  150. CompanyName: reportViewRecord.CompanyName,
  151. ViewTime: reportViewRecord.ViewTime,
  152. ProductId: 2,
  153. CompanyId: companyId,
  154. ReportId: reportViewRecord.ReportId,
  155. StopTime: reportViewRecord.StopTime,
  156. ReportChapterId: reportViewRecord.ReportChapterId,
  157. OutId: reportViewRecord.OutId,
  158. }
  159. if utils.Re == nil {
  160. err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
  161. if err != nil {
  162. fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
  163. }
  164. return true
  165. }
  166. return false
  167. }
  168. // 获取策略平台报告阅读数据
  169. func GetCeLueArticlePv(cont context.Context) (err error) {
  170. //func GetCeLueArticlePv() (err error) {
  171. defer func() {
  172. if err != nil {
  173. go utils.SendAlarmMsg("同步策略平台阅读数据失败"+err.Error(), 2)
  174. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  175. }
  176. }()
  177. startTime := time.Now().Add(-time.Minute * 12).Format("2006-01-02 15:04:05")
  178. endTime := time.Now().Format("2006-01-02 15:04:05")
  179. requestUrl := utils.ApiUrl + "backend/statistics_access?take=1000&skip=0&sort=ASC&mode=all&"
  180. encodeData := url.Values{}
  181. encodeData.Add("start_dt", startTime)
  182. encodeData.Add("end_dt", endTime)
  183. encodeStr := encodeData.Encode()
  184. requestUrl += encodeStr
  185. authorization := utils.ApiAuthorization
  186. body, err := PublicGetDate(requestUrl, authorization)
  187. if err != nil {
  188. return
  189. }
  190. var chartResult models.CeLueArticleResultApi
  191. err = json.Unmarshal(body, &chartResult)
  192. if err != nil {
  193. fmt.Println(err)
  194. return err
  195. }
  196. mapMobileArticleId := make(map[string]int)
  197. //获取当天阅读记录
  198. listPv, err := models.GetArticleHistoryRecordAllList()
  199. if err != nil && err.Error() != utils.ErrNoRow() {
  200. fmt.Println("获取当天阅读记录失败", err)
  201. return err
  202. }
  203. if len(listPv) > 0 {
  204. for _, v := range listPv {
  205. mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
  206. }
  207. }
  208. var celueHistoryIds []int
  209. var mobiles []string
  210. for _, v := range chartResult.Data {
  211. celueHistoryIds = append(celueHistoryIds, v.CelueHistoryId)
  212. mobiles = append(mobiles, v.Mobile)
  213. }
  214. listcelueHistory, e := models.GetCeLueArticleListByIds(celueHistoryIds)
  215. if e != nil {
  216. err = errors.New("GetCeLueArticleListByIds, Err: " + e.Error())
  217. return
  218. }
  219. mapCelueHistoryIds := make(map[int]int)
  220. for _, v := range listcelueHistory {
  221. mapCelueHistoryIds[v.CelueHistoryId] = v.CelueHistoryId
  222. }
  223. listMobileCompany, e := company.GetCompanyProductListByMobiles(mobiles)
  224. if e != nil {
  225. err = errors.New("GetCompanyProductListByMobiles, Err: " + e.Error())
  226. return
  227. }
  228. mapUserCompany := make(map[string]*company.CompanyProductUser)
  229. for _, v := range listMobileCompany {
  230. mapUserCompany[v.Mobile] = v
  231. }
  232. var celueArticleHistoryItems []*models.CygxCelueArticleHistoryRecord
  233. var allRecordItems []*models.CygxArticleHistoryRecordAll
  234. for _, v := range chartResult.Data {
  235. articleId, _ := strconv.Atoi(v.ArticleId)
  236. if articleId == 0 {
  237. continue
  238. }
  239. //fmt.Println(v.ArticleId)
  240. item := new(models.CygxCelueArticleHistoryRecord)
  241. item.CelueHistoryId = v.CelueHistoryId
  242. item.Mobile = v.Mobile
  243. item.ArticleId = v.ArticleId
  244. if v.CompanyName != nil {
  245. item.CompanyName = v.CompanyName.RealName
  246. }
  247. if v.CrmUser != nil {
  248. item.RealName = v.CrmUser.RealName
  249. }
  250. if mapUserCompany[v.Mobile] != nil {
  251. mapUser := mapUserCompany[v.Mobile]
  252. item.CompanyName = mapUser.CompanyName
  253. item.CompanyStatus = mapUser.Status
  254. item.SellerName = mapUser.SellerName
  255. }
  256. item.CreateDateApi = time.Now()
  257. t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
  258. item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
  259. //email=?,company_id=?,company_name=?,user_id=?,real_name=?
  260. if mapCelueHistoryIds[v.CelueHistoryId] == 0 {
  261. celueArticleHistoryItems = append(celueArticleHistoryItems, item)
  262. //写入记录到总的统计表
  263. record := new(models.CygxArticleHistoryRecordAll)
  264. record.ArticleId = articleId
  265. record.CelueHistoryId = item.CelueHistoryId
  266. record.CreateTime = item.CreateTime
  267. record.ModifyTime = time.Now()
  268. record.CreateDateApi = time.Now()
  269. if mapUserCompany[v.Mobile] != nil {
  270. mapUser := mapUserCompany[v.Mobile]
  271. record.Mobile = mapUser.Mobile
  272. record.CompanyName = mapUser.CompanyName
  273. record.CompanyStatus = mapUser.Status
  274. record.SellerName = mapUser.SellerName
  275. record.CompanyId = mapUser.CompanyId
  276. record.RealName = mapUser.RealName
  277. record.UserId = mapUser.UserId
  278. record.Email = mapUser.Email
  279. }
  280. record.Platfor = 2
  281. record.Source = "CELUE"
  282. if mapMobileArticleId[fmt.Sprint(item.Mobile, "_", item.ArticleId)] == articleId {
  283. record.IsDel = 1
  284. }
  285. allRecordItems = append(allRecordItems, record)
  286. }
  287. //count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
  288. //if err != nil && err.Error() != utils.ErrNoRow() {
  289. // return err
  290. //}
  291. //if count == 0 {
  292. // _, err := models.AddCeLueArticle(item, mapMobileArticleId)
  293. // if err != nil {
  294. // fmt.Println(err)
  295. // return err
  296. // }
  297. //}
  298. }
  299. if len(celueArticleHistoryItems) > 0 {
  300. e = models.AddCygxArticleHistoryRecordAllMulti(celueArticleHistoryItems, allRecordItems)
  301. if e != nil {
  302. err = errors.New("AddCygxArticleHistoryRecordAllMulti, Err: " + e.Error())
  303. return
  304. }
  305. }
  306. //处理同步过来的阅读记录所属用户
  307. //var condition string
  308. //condition = ` AND create_time > ` + "'" + startTime + "'"
  309. //listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
  310. //if err != nil {
  311. // fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
  312. //}
  313. //for _, v := range listArticlePv {
  314. // if v.Mobile != "" {
  315. // user, err := models.GetWxUserItemByMobile(v.Mobile)
  316. // if err != nil && err.Error() != utils.ErrNoRow() {
  317. // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  318. // }
  319. // if user != nil {
  320. // err = models.UpdateCygxArticleHistoryRecordAll(user)
  321. // if err != nil {
  322. // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
  323. // }
  324. // }
  325. // }
  326. //}
  327. return
  328. }
  329. func GetArticleListByApi(cont context.Context) (err error) {
  330. defer func() {
  331. if err != nil {
  332. //fmt.Println("GetArticleListByApi Err:" + err.Error())
  333. go utils.SendAlarmMsg("同步策略平台数据失败", 2)
  334. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  335. }
  336. }()
  337. listUpdateArticle, err := models.GetArticleCeluePushList()
  338. if err != nil && err.Error() != utils.ErrNoRow() {
  339. return err
  340. }
  341. //如果长度为零就不处理
  342. if len(listUpdateArticle) == 0 {
  343. return err
  344. }
  345. for _, v := range listUpdateArticle {
  346. // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
  347. err = HandleArticleListByApi(v.ArticleId)
  348. if err != nil {
  349. utils.FileLog.Info("HandleArticleListByApi", err.Error())
  350. }
  351. }
  352. return
  353. }
  354. // 获取策略平台推送过来的文章并更新
  355. func UpdateArticleByRedis() (err error) {
  356. for {
  357. utils.Rc.Brpop(utils.CYGX_ARTICLE_UPDATE_KEY, func(b []byte) {
  358. var log models.CygxArticleCeluePushRedis
  359. if err := json.Unmarshal(b, &log); err != nil {
  360. fmt.Println("json unmarshal wrong!")
  361. go utils.SendAlarmMsg("获取策略平台推送过来的文章并更新处理Redis队列消息失败:"+err.Error()+string(b), 2)
  362. }
  363. // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
  364. err = HandleArticleListByApi(log.ArticleId)
  365. if err != nil {
  366. utils.FileLog.Info("HandleArticleListByApi", err.Error())
  367. }
  368. })
  369. }
  370. }
  371. // 处理同步过来的文章
  372. func HandleArticleListByApi(artcleId int) (err error) {
  373. defer func() {
  374. if err != nil {
  375. go utils.SendAlarmMsg("处理同步过来的文章失败"+"HandleArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
  376. }
  377. }()
  378. var clueApiUrl string
  379. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
  380. fmt.Println(clueApiUrl)
  381. authorization := utils.ApiAuthorization
  382. body, err := PublicGetDate(clueApiUrl, authorization)
  383. if err != nil {
  384. fmt.Println(err)
  385. return
  386. }
  387. var articleResultDate models.ArticleDetailResultApi
  388. err = json.Unmarshal(body, &articleResultDate)
  389. if err != nil {
  390. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  391. return err
  392. }
  393. item := new(models.CygxShanghaiCompanyLog)
  394. item.CreateTime = time.Now()
  395. item.Url = clueApiUrl
  396. item.Body = ""
  397. item.Result = string(body)
  398. go models.AddCygxShanghaiCompanyLog(item)
  399. go models.UpdateCygxArticleCeluePush(artcleId)
  400. articleResult := articleResultDate.Data
  401. exitMap := make(map[int]int)
  402. categoryIdMap := make(map[int]int)
  403. classMap := make(map[int]int)
  404. reportMap := make(map[int]int)
  405. summaryMap := make(map[int]int)
  406. listMap, err := models.GetArticleApiMap()
  407. if err != nil {
  408. fmt.Println("GetlistMap Err:", err.Error())
  409. return err
  410. }
  411. openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
  412. if err != nil {
  413. fmt.Println(err)
  414. return err
  415. }
  416. fmt.Println(openIdList)
  417. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  418. for _, v := range listMap {
  419. exitMap[v.SeriesId] = v.OldId
  420. categoryIdMap[v.SeriesId] = v.OldIdMap
  421. if v.IsClass == 1 {
  422. classMap[v.OldId] = 1
  423. }
  424. if v.IsReport == 1 {
  425. reportMap[v.OldId] = 1
  426. }
  427. if v.IsSummary == 1 {
  428. summaryMap[v.OldId] = 1
  429. }
  430. }
  431. var list []*models.Tactics2
  432. var listArticleData []*models.CygxArticleData
  433. var listAuthor []*models.CygxArticleAuthor
  434. //如果是英文报告 ,或者香港类型那么则不同步 publish_area :all 全部 ;hk 香港
  435. if articleResult.TypeId == 9 || articleResult.PublishArea != "all" {
  436. // 如果是英文报告,或者是香港报告就进行删除处理
  437. err = models.UpdateArticlePublish(artcleId, 0)
  438. if err != nil {
  439. fmt.Println("UpdateArticlePublish Err:", err.Error())
  440. return err
  441. }
  442. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  443. return
  444. }
  445. var cover string
  446. if articleResult.Series.Name == "图解市场" {
  447. cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
  448. } else if articleResult.Series.Name == "行业深度" {
  449. cover = articleResult.Cover
  450. }
  451. fmt.Println(cover)
  452. //return
  453. //状态等于 2 跟 4 的进行同步 IsActive 为false 软删除的也不同步
  454. if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
  455. articleResult.PublishDate = time.Date(articleResult.PublishDate.Year(), articleResult.PublishDate.Month(), articleResult.PublishDate.Day(), articleResult.PublishDate.Hour(), articleResult.PublishDate.Minute(), articleResult.PublishDate.Second(), articleResult.PublishDate.Nanosecond(), time.Local)
  456. item := new(models.Tactics2)
  457. itemArticleData := new(models.CygxArticleData)
  458. itemArticleData.ArticleId = articleResult.ArticleId
  459. itemArticleData.Cover = articleResult.Cover
  460. itemArticleData.CreateTime = time.Now()
  461. listArticleData = append(listArticleData, itemArticleData)
  462. itemAuthor := new(models.CygxArticleAuthor)
  463. item.ArticleId = articleResult.ArticleId
  464. item.Title = articleResult.Title
  465. item.TitleEn = articleResult.TitleEn
  466. item.File = articleResult.File
  467. if articleResult.Frequency == "日度" {
  468. item.UpdateFrequency = "daily"
  469. } else if articleResult.Frequency == "周度" {
  470. item.UpdateFrequency = "weekly"
  471. } else if articleResult.Frequency == "月度" {
  472. item.UpdateFrequency = "monthly"
  473. } else if articleResult.Frequency == "季度" {
  474. item.UpdateFrequency = "quarterly"
  475. } else if articleResult.Frequency == "年度" {
  476. item.UpdateFrequency = "yearly"
  477. } else {
  478. item.UpdateFrequency = "unknow"
  479. }
  480. item.CreateDate = articleResult.CreateDate
  481. item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
  482. item.PublishStatus = 1
  483. item.Body = articleResult.Content.Body
  484. item.Abstract = articleResult.Content.Abstract
  485. item.Annotation = articleResult.Content.Annotation
  486. item.CategoryName = articleResult.Industry.Name
  487. item.CategoryId = categoryIdMap[articleResult.SeriesId]
  488. item.CategoryIdTwo = exitMap[articleResult.SeriesId]
  489. item.SubCategoryName = articleResult.Series.Name
  490. item.Cover = cover
  491. //{
  492. // //这两种情况特殊处理
  493. // if articleResult.Field.Name == "宏观利率" {
  494. // item.CategoryId = 10070
  495. // item.CategoryIdTwo = item.CategoryId
  496. // }
  497. // if articleResult.Field.Name == "信用" {
  498. // item.CategoryId = 10082
  499. // item.CategoryIdTwo = item.CategoryId
  500. // }
  501. //}
  502. if len(articleResult.Stock) > 0 {
  503. var stock string
  504. for _, vS := range articleResult.Stock {
  505. stock += vS + "/"
  506. }
  507. stock = strings.TrimRight(stock, "/")
  508. item.Stock = stock
  509. }
  510. item.FieldName = articleResult.Field.Name
  511. item.SeriesName = articleResult.Series.Name
  512. item.TypeName = articleResult.Type.Name
  513. item.UpdateDate = articleResult.UpdateDate
  514. item.CeLueFieldId = articleResult.Field.Id
  515. list = append(list, item)
  516. itemAuthor.ArticleId = articleResult.ArticleId
  517. itemAuthor.Name = articleResult.Author.Name
  518. itemAuthor.Mobile = articleResult.Author.PhoneNumber
  519. fmt.Println(articleResult.Cover)
  520. listAuthor = append(listAuthor, itemAuthor)
  521. } else {
  522. // 如果这篇文章没有发布,那么就不作处理。
  523. err = models.UpdateArticlePublish(artcleId, 0)
  524. if err != nil {
  525. fmt.Println("UpdateArticlePublish Err:", err.Error())
  526. return err
  527. }
  528. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  529. //go UpdateResourceData(artcleId, "article", "delete", time.Now().Format(utils.FormatDateTime))
  530. return
  531. }
  532. //同步作者
  533. for _, v := range listAuthor {
  534. var count int
  535. count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  536. if err != nil {
  537. fmt.Println("GetActivityAuthorCount Err:", err.Error())
  538. return err
  539. }
  540. if count == 0 {
  541. _, err = models.AddCygxActivityAuthor(v)
  542. if err != nil {
  543. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  544. return err
  545. }
  546. }
  547. }
  548. fmt.Println("同步文章条数:", len(list))
  549. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  550. if err != nil {
  551. fmt.Println("GetTacticsList Err:", err.Error())
  552. return err
  553. }
  554. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  555. if errMatch != nil {
  556. fmt.Println("GetTacticsList Err:", errMatch.Error())
  557. return err
  558. }
  559. //mapCategoryIdSet := make(map[int]int)
  560. //for _, vMatch := range listGetMatchTypeName {
  561. // mapCategoryIdSet[vMatch.CategoryId] = vMatch.CategoryIdSet
  562. //}
  563. fmt.Println("list len:", len(list))
  564. noSummaryArticleIds := "3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470" //非纪要库类型的文章ID
  565. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  566. for k, v := range list {
  567. //同步匹配类型
  568. matchTypeName := ""
  569. for _, vMatch := range listGetMatchTypeName {
  570. if v.CategoryId == vMatch.CategoryId {
  571. matchTypeName = vMatch.MatchTypeName
  572. }
  573. }
  574. //是否属于纪要库的数据
  575. //if _, has := summaryMap[v.CategoryId]; has {
  576. // v.IsSummary = 1
  577. //}
  578. if v.TypeName == "纪要" {
  579. v.IsSummary = 1
  580. }
  581. //排除不属于纪要库类型的文章
  582. for _, vArt := range listNoSummaryArticleIds {
  583. vArtInt, _ := strconv.Atoi(vArt)
  584. if v.ArticleId == vArtInt {
  585. v.IsSummary = 0
  586. }
  587. }
  588. if _, has := reportMap[v.CategoryIdTwo]; has {
  589. v.IsReport = 1
  590. if _, ok := classMap[v.CategoryIdTwo]; ok {
  591. v.IsClass = 1
  592. v.ReportType = 1 //是否属于行业报告
  593. } else {
  594. v.ReportType = 2 //是否属于产业报告
  595. }
  596. }
  597. v.Department = "弘则权益研究"
  598. //判断是否已经存在
  599. if v.ArticleId < 0 {
  600. fmt.Println("AddCygxArticle Err:")
  601. return err
  602. }
  603. var count int
  604. count, err = models.GetArticleCountById(v.ArticleId)
  605. if err != nil && err.Error() != utils.ErrNoRow() {
  606. fmt.Println("AddCygxArticle Err:", err.Error())
  607. return err
  608. }
  609. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  610. expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
  611. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  612. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  613. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  614. v.Body = strings.Replace(v.Body, "):", "", -1)
  615. }
  616. var titleNew string
  617. titleNew = v.Title
  618. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  619. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  620. if v.UpdateFrequency == "daily" {
  621. var daystr string
  622. daystr = strconv.Itoa(v.PublishDate.Day())
  623. if len(daystr) == 1 {
  624. daystr = "0" + daystr
  625. }
  626. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  627. } else if v.UpdateFrequency == "weekly" {
  628. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  629. }
  630. }
  631. //策略周度思考,医药周报,消费周报,消费周度思考,科技前言(周报)、智造精粹、智造本周荟 标题处理
  632. if v.CategoryId == 80 || v.CategoryId == 52 || v.CategoryId == 10074 || v.CategoryId == 1008 || v.CategoryId == 10071 || v.CategoryId == 10073 || v.CategoryId == 50 {
  633. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  634. }
  635. //类型是综述报告的,不区分是什么系列,统一归类到对应产业的路演精华
  636. if articleResult.Type.Name == "综述报告" {
  637. detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
  638. if err != nil && err.Error() != utils.ErrNoRow() {
  639. return err
  640. }
  641. v.CategoryId = detailCategory.CategoryId
  642. matchTypeName = "路演精华"
  643. if v.IsClass == 0 {
  644. v.IsSummary = 0
  645. }
  646. }
  647. var chartPermissionId int
  648. var chartPermissionName string
  649. categoryDetail, _ := models.GetdetailByCategoryIdPush(v.CategoryId)
  650. if categoryDetail != nil {
  651. chartPermissionId = categoryDetail.ChartPermissionId
  652. chartPermissionName = categoryDetail.ChartPermissionName
  653. }
  654. if count > 0 {
  655. fmt.Println(k, v.ArticleId, "edit")
  656. articleIfoOld, e := models.GetArticleDetailTestById(v.ArticleId)
  657. if e != nil {
  658. err = e
  659. return
  660. }
  661. bodyTextOld, _ := GetReportContentTextSubNew(articleIfoOld.Body)
  662. bodyText, _ := GetReportContentTextSubNew(v.Body)
  663. var isCustom bool
  664. updateParams := make(map[string]interface{})
  665. //updateParams["Title"] = v.Title
  666. updateParams["Title"] = titleNew
  667. updateParams["TitleEn"] = v.TitleEn
  668. updateParams["UpdateFrequency"] = v.UpdateFrequency
  669. updateParams["CreateDate"] = v.CreateDate
  670. updateParams["PublishDate"] = v.PublishDate
  671. //updateParams["Body"] = html.EscapeString(v.Body)
  672. updateParams["Body"] = html.EscapeString(bodyReturn)
  673. updateParams["BodyText"] = bodyText
  674. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  675. updateParams["CategoryName"] = v.CategoryName
  676. for _, vCustom := range listCustomArticle {
  677. if v.ArticleId == vCustom.ArticleId {
  678. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  679. isCustom = true
  680. }
  681. }
  682. if isCustom == false {
  683. updateParams["CategoryId"] = v.CategoryId
  684. updateParams["MatchTypeName"] = matchTypeName
  685. updateParams["IsSummary"] = v.IsSummary
  686. updateParams["IsReport"] = v.IsReport
  687. updateParams["ReportType"] = v.ReportType
  688. updateParams["SubCategoryName"] = v.SubCategoryName
  689. }
  690. //updateParams["CategoryId"] = v.CategoryId
  691. updateParams["PublishStatus"] = 1
  692. updateParams["ExpertBackground"] = expertContentStr
  693. updateParams["ExpertNumber"] = expertNumStr
  694. updateParams["InterviewDate"] = interviewDateStr
  695. //updateParams["IsClass"] = v.IsClass
  696. v.Department = "弘则权益研究"
  697. updateParams["Department"] = v.Department
  698. updateParams["FileLink"] = v.File
  699. updateParams["Stock"] = v.Stock
  700. updateParams["FieldName"] = v.FieldName
  701. updateParams["SeriesName"] = v.SeriesName
  702. updateParams["Annotation"] = v.Annotation
  703. updateParams["TypeName"] = v.TypeName
  704. updateParams["ModifyTimeByCl"] = v.UpdateDate
  705. updateParams["CeLueFieldId"] = v.CeLueFieldId
  706. updateParams["Cover"] = v.Cover
  707. updateParams["ChartPermissionId"] = chartPermissionId
  708. updateParams["ChartPermissionName"] = chartPermissionName
  709. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  710. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  711. if err != nil {
  712. fmt.Println("UpdateByExpr Err:" + err.Error())
  713. return err
  714. }
  715. if len(bodyText)-len(bodyTextOld) > 100 {
  716. //fmt.Println("触发推送规则")
  717. //更新字数大于一百字触发推送规则
  718. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  719. UpdateArticleResourceData(v.ArticleId) //把数据写入 cygx_resource_data 表
  720. //go UpdateResourceData(v.ArticleId, "article", "update", time.Now().Format(utils.FormatDateTime))
  721. } else {
  722. models.UpdatecygxResourceDatasearchTitle(v.Title, v.ArticleId)
  723. }
  724. } else {
  725. fmt.Println(k, v.ArticleId, "add")
  726. item := new(models.CygxArticle)
  727. articleIdInt := v.ArticleId
  728. item.ArticleId = articleIdInt
  729. //item.Title = v.Title
  730. item.Title = titleNew
  731. item.TitleEn = v.TitleEn
  732. item.UpdateFrequency = v.UpdateFrequency
  733. item.CreateDate = v.CreateDate
  734. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  735. //item.Body = html.EscapeString(v.Body)
  736. item.Body = html.EscapeString(bodyReturn)
  737. item.Abstract = html.EscapeString(v.Abstract)
  738. item.CategoryName = v.CategoryName
  739. item.SubCategoryName = v.SubCategoryName
  740. item.CategoryId = v.CategoryId
  741. item.CategoryIdTwo = v.CategoryIdTwo
  742. item.PublishStatus = 1
  743. item.ExpertBackground = expertContentStr
  744. item.ExpertNumber = expertNumStr
  745. item.InterviewDate = interviewDateStr
  746. item.Department = v.Department
  747. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  748. item.IsClass = v.IsClass
  749. item.IsSummary = v.IsSummary
  750. item.IsReport = v.IsReport
  751. item.ReportType = v.ReportType
  752. item.FileLink = v.File
  753. item.MatchTypeName = matchTypeName
  754. item.Stock = v.Stock
  755. item.FieldName = v.FieldName
  756. item.SeriesName = v.SeriesName
  757. item.Annotation = v.Annotation
  758. item.TypeName = v.TypeName
  759. item.ModifyTimeByCl = v.UpdateDate
  760. item.CeLueFieldId = v.CeLueFieldId
  761. item.Cover = v.Cover
  762. item.ChartPermissionId = chartPermissionId
  763. item.ChartPermissionName = chartPermissionName
  764. item.Cover = v.Cover
  765. item.CreateTime = time.Now()
  766. newId, err := models.AddCygxArticles(item)
  767. if err != nil {
  768. fmt.Println("AddCygxArticle Err:", err.Error())
  769. return err
  770. }
  771. //go UpdateResourceData(v.ArticleId, "article", "add", time.Now().Format(utils.FormatDateTime))
  772. UpdateArticleResourceData(v.ArticleId) //把数据写入 cygx_resource_data 表
  773. //fmt.Println(newId)
  774. //报告自动归类,以及推送相关模板消息
  775. if v.ReportType == 2 {
  776. var subjectStr string
  777. var industrialManagementIdStr string
  778. var industrialSubjectIdStr string
  779. var keyword1 string
  780. var keyword2 string
  781. var keyword3 string
  782. var keyword4 string
  783. sliceSubjects := strings.Split(v.Stock, "/")
  784. mapManagementForSubject := make(map[string]string)
  785. mapIndustrialId := make(map[int]int)
  786. if len(sliceSubjects) > 0 {
  787. for _, vSubject := range sliceSubjects {
  788. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  789. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  790. subject := sliceXiahuaxian[0]
  791. subjectStr += "'" + subject + "',"
  792. }
  793. //获取该产业下所对应的行业图片
  794. detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
  795. if errCategory != nil {
  796. fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
  797. return err
  798. }
  799. subjectStr = strings.TrimRight(subjectStr, ",")
  800. if subjectStr != "" {
  801. listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
  802. if err != nil {
  803. fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
  804. return err
  805. }
  806. subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
  807. subjectStr = strings.Replace(subjectStr, "'", "", -1)
  808. subjectStr = "【" + subjectStr + "】"
  809. if len(listIndustrial) > 0 {
  810. for _, vIndustrial := range listIndustrial {
  811. if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
  812. industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
  813. }
  814. mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
  815. industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
  816. mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
  817. if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
  818. go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
  819. }
  820. }
  821. industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
  822. industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
  823. if industrialManagementIdStr != "" {
  824. err = models.ReportArticleClassificationEditNew(int(newId), industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
  825. if err != nil {
  826. fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
  827. return err
  828. }
  829. }
  830. var peoductName string
  831. for mk, mv := range mapManagementForSubject {
  832. peoductName += "【" + mk + "--" + strings.TrimRight(mv, "/") + "】"
  833. }
  834. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  835. keyword2 = "已自动关联至以下产业和标的:" + peoductName
  836. keyword3 = v.Title
  837. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  838. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  839. for _, vIndustrial := range listIndustrial {
  840. IndustrialManagementTimeLineDateList3(vIndustrial.IndustrialManagementId) // 更新时间线报告内容
  841. }
  842. } else {
  843. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  844. keyword2 = "未归类"
  845. keyword3 = v.Title
  846. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  847. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  848. go models.UpdateIsClassFail(artcleId)
  849. }
  850. }
  851. }
  852. }
  853. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  854. }
  855. if v.CategoryName == utils.ZHOU_QI_NAME {
  856. UpdateCygxZhouqiArticleMapTime(v.FieldName) //更新周期对应分类下所管理文章的更新时间
  857. }
  858. //【公司调研】系列纪要发布/更新后 end
  859. //查研观向6.9模板消息推送规则
  860. //但是如果报告的发布时间是在10天以前的,公众号就不推送了
  861. //if time.Now().AddDate(0, 0, -10).Before(articleResult.PublishDate.Add(time.Hour * 8)) {
  862. // go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  863. //}
  864. }
  865. go models.UpdateCygxArticleCeluePush(artcleId)
  866. AddComprehensiveArticle(artcleId) // 同步到综合页面的搜索引擎
  867. AddComprehensiveIndustrialSource("Hz", artcleId) // 同步到综合页面的搜索引擎(添加产业资源包)
  868. GetSummarytoEs(artcleId) // 同步到ES搜索引擎
  869. GetIndustrialManagementArticleNewPublishData()
  870. if len(listArticleData) > 0 {
  871. for _, v := range listArticleData {
  872. count, err := models.GetCygxArticleDataCount(v.ArticleId)
  873. if err != nil {
  874. fmt.Println("GetCygxArticleDataCount Err:", err.Error())
  875. return err
  876. }
  877. if count == 0 {
  878. _, err := models.AddCygxArticleData(v)
  879. if err != nil {
  880. fmt.Println("AddCygxArticleData Err:", err.Error())
  881. return err
  882. }
  883. }
  884. //} else {
  885. // updateParams := make(map[string]interface{})
  886. // updateParams["Cover"] = v.Cover
  887. // whereParam := map[string]interface{}{"article_id": v.ArticleId}
  888. // err = models.UpdateByExpr(models.CygxArticleData{}, whereParam, updateParams)
  889. // if err != nil {
  890. // fmt.Println("UpdateByExpr CygxArticleData Err:" + err.Error())
  891. // return err
  892. // }
  893. //}
  894. }
  895. }
  896. AddCygxReportMappingCategoryGroupByArticleId(artcleId)
  897. return err
  898. }
  899. //func init() {
  900. // DoArticleOnenIdWxTemplateMsg(8112)
  901. //}
  902. // 过滤策略平台报告,研选报告重复推送,以及权限勾选的推送
  903. func DoArticleOnenIdWxTemplateMsg(articleId int) {
  904. var err error
  905. //策略平台同步过来的文章ID,做微信模板消息推送,同一篇报告12小时只推送一次
  906. cacheKey := fmt.Sprint(utils.CACHE_KEY_ARTICLE_ID_TEMPLATE, ":ArticleId", articleId)
  907. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  908. if ttlTime > 0 {
  909. fmt.Println(ttlTime)
  910. return
  911. }
  912. defer func() {
  913. if err != nil {
  914. go utils.SendAlarmMsg("过滤策略平台报告,研选报告重复推送,以及权限勾选的推送失败 DoArticleOnenIdWxTemplateMsg ErrMsg:"+err.Error(), 2)
  915. fmt.Println(err)
  916. }
  917. }()
  918. //获取文章详情
  919. articleInfo, e := models.GetArticleDetailById(articleId)
  920. if e != nil {
  921. err = errors.New("GetArticleDetailById, Err: " + e.Error())
  922. return
  923. }
  924. articleInfo.Abstract, _ = GetReportContentTextSub(articleInfo.Abstract)
  925. var chartPermissionId int
  926. //固收的权限,暂时当策略的逻辑一样处理
  927. var chartPermissionName string
  928. var permissionName string
  929. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  930. if e != nil {
  931. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  932. return
  933. }
  934. permissionName = reportMapDetail.ChartPermissionName
  935. if reportMapDetail.ChartPermissionId == utils.CE_LUE_ID {
  936. chartPermissionId = utils.CE_LUE_ID
  937. } else if reportMapDetail.ChartPermissionId == utils.GU_SHOU_ID_CHART {
  938. chartPermissionId = utils.GU_SHOU_ID_CHART
  939. } else {
  940. if reportMapDetail.PermissionType == 1 {
  941. chartPermissionName = reportMapDetail.ChartPermissionName + "(主观)"
  942. } else {
  943. chartPermissionName = reportMapDetail.ChartPermissionName + "(客观)"
  944. }
  945. chartPermissionDetail, e := models.GetChartPermissionByRemark(chartPermissionName)
  946. if e != nil {
  947. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  948. return
  949. }
  950. chartPermissionId = chartPermissionDetail.ChartPermissionId
  951. }
  952. //文章关联的产业
  953. var industryName string
  954. var industrialManagementId string
  955. if chartPermissionId == utils.CE_LUE_ID || chartPermissionId == utils.GU_SHOU_ID_CHART {
  956. industryName = reportMapDetail.SubCategoryName
  957. }
  958. // 获取所有有权的用户的 openid
  959. //mapOpenidPower := make(map[int]string)
  960. permissionIdList := make([]string, 0)
  961. var condition string
  962. var pars []interface{}
  963. slicepermissionId := strings.Split(strconv.Itoa(chartPermissionId), ",")
  964. if len(slicepermissionId) > 0 {
  965. for _, v := range slicepermissionId {
  966. if v == strconv.Itoa(utils.GU_SHOU_ID_CHART) {
  967. v = strconv.Itoa(utils.CE_LUE_ID)
  968. }
  969. permissionIdList = append(permissionIdList, v)
  970. }
  971. condition += ` AND p.chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
  972. pars = append(pars, permissionIdList)
  973. }
  974. openidPowerListMobile, e := models.GetCygxUserRecordPower(condition, pars)
  975. if e != nil {
  976. err = errors.New("GetCygxUserRecordPower, Err: " + e.Error())
  977. return
  978. }
  979. //获取拒绝接收推送的的用户的 openid
  980. mapOpenidRefuset := make(map[int]string)
  981. openidRefusetList, e := models.GetCygxUserRefusetOpenid()
  982. if e != nil {
  983. err = errors.New("GetCygxUserRefusetOpenid, Err: " + e.Error())
  984. return
  985. }
  986. for _, v := range openidRefusetList {
  987. mapOpenidRefuset[v.UserId] = v.OpenId
  988. }
  989. var mobileArr []string
  990. for _, v := range openidPowerListMobile {
  991. mobileArr = append(mobileArr, v.Mobile)
  992. }
  993. openidPowerList, err := models.GetWxOpenIdByMobileSliceList(mobileArr)
  994. if e != nil {
  995. err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error())
  996. return
  997. }
  998. //四大行业的行业综述报告,对所有开通了对应行业权限的客户都推送。
  999. if articleInfo.ReportType == 1 && permissionName != utils.CE_LUE_NAME && permissionName != utils.GU_SHOU_NAME && permissionName != utils.ZHOU_QI_NAME {
  1000. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1001. //openIditem := new(models.OpenIdList)
  1002. var openIdArr []string
  1003. for _, item := range openidPowerList {
  1004. if mapOpenidRefuset[item.UserId] != "" {
  1005. continue // 拒绝消息推送的用户不接收模版消息
  1006. }
  1007. openIdArr = append(openIdArr, item.OpenId)
  1008. }
  1009. go SendWxMsgWithArticleUpdateList(keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIdArr, articleId)
  1010. return
  1011. }
  1012. //for _, v := range openidPowerList {
  1013. // mapOpenidPower[v.UserId] = v.OpenId
  1014. //}
  1015. if permissionName == utils.CE_LUE_NAME || permissionName == utils.GU_SHOU_NAME {
  1016. celueListUninterested, e := models.GetCygxXzsChooseCategoryListFollowType(articleInfo.CategoryId, 3)
  1017. if e != nil {
  1018. err = errors.New("GetCygxXzsChooseCategoryListFollowType " + e.Error())
  1019. return
  1020. }
  1021. mapUninterestedClue := make(map[int]string)
  1022. for _, v := range celueListUninterested {
  1023. mapUninterestedClue[v.UserId] = "_"
  1024. mapOpenidRefuset[v.UserId] = "_" //归类成拒绝推送的人
  1025. }
  1026. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1027. var openIdArr []string
  1028. for _, item := range openidPowerList {
  1029. if mapOpenidRefuset[item.UserId] != "" {
  1030. continue // 拒绝消息推送的用户不接收模版消息
  1031. }
  1032. openIdArr = append(openIdArr, item.OpenId)
  1033. }
  1034. go SendWxMsgWithArticleUpdateList(keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIdArr, articleId)
  1035. return
  1036. } else if permissionName == utils.ZHOU_QI_NAME {
  1037. if articleInfo.SeriesName == "" {
  1038. articleInfo.SeriesName = articleInfo.FieldName
  1039. }
  1040. zhouqiListUninterested, e := models.GetCygxXzsChooseCategoryZhouqiListFollowType(articleInfo.FieldName, articleInfo.SeriesName, 3)
  1041. if e != nil {
  1042. err = errors.New("GetCygxXzsChooseCategoryListFollowType " + e.Error())
  1043. return
  1044. }
  1045. mapUninterestedClue := make(map[int]string)
  1046. for _, v := range zhouqiListUninterested {
  1047. mapUninterestedClue[v.UserId] = "_"
  1048. mapOpenidRefuset[v.UserId] = "_" //归类成拒绝推送的人
  1049. }
  1050. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1051. var openIdArr []string
  1052. for _, item := range openidPowerList {
  1053. if mapOpenidRefuset[item.UserId] != "" {
  1054. continue // 拒绝消息推送的用户不接收模版消息
  1055. }
  1056. openIdArr = append(openIdArr, item.OpenId)
  1057. }
  1058. go SendWxMsgWithArticleUpdateList(keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIdArr, articleId)
  1059. return
  1060. } else {
  1061. //if articleInfo.ReportType == 2 {
  1062. detailIndustryNameList, e := models.GetIndustrialManagemenDetailByAaticleID(articleId)
  1063. if e != nil {
  1064. err = errors.New("GetIndustrialManagemenDetailByAaticleID, Err: " + e.Error())
  1065. return
  1066. }
  1067. //如果不存在关联的产业则不推送
  1068. if len(detailIndustryNameList) == 0 {
  1069. return
  1070. } else {
  1071. var industrialIds []int
  1072. for _, v := range detailIndustryNameList {
  1073. industrialIds = append(industrialIds, v.IndustrialManagementId)
  1074. }
  1075. var conditionFollow string
  1076. var parsFollow []interface{}
  1077. //根据产业关注ID,获取用户不感兴趣的产业信息
  1078. conditionFollow = " AND industrial_management_id IN (" + utils.GetOrmInReplace(len(industrialIds)) + ") AND follow_type = 3 "
  1079. parsFollow = append(parsFollow, industrialIds)
  1080. userFllowListUninterested, e := models.GetCygxIndustryFllowListByCon(conditionFollow, parsFollow)
  1081. if e != nil {
  1082. err = errors.New("GetCygxIndustryFllowList, Err: " + e.Error())
  1083. return
  1084. }
  1085. var userFllowNum = make(map[int]int)
  1086. for _, v := range userFllowListUninterested {
  1087. userFllowNum[v.UserId]++
  1088. //如果活动对应的产业数量,跟用户不感兴趣的产业数量一致,就不做推送
  1089. if userFllowNum[v.UserId] == len(detailIndustryNameList) {
  1090. mapOpenidRefuset[v.UserId] = "_"
  1091. }
  1092. }
  1093. }
  1094. for _, v := range detailIndustryNameList {
  1095. industryName += v.IndustryName + ","
  1096. industrialManagementId += strconv.Itoa(v.IndustrialManagementId) + ","
  1097. }
  1098. industryName = strings.TrimRight(industryName, ",")
  1099. industrialManagementId = strings.TrimRight(industrialManagementId, ",")
  1100. //}
  1101. keyword1 := fmt.Sprint("【", industryName, "】有报告发布/更新")
  1102. keyword2 := articleInfo.Title
  1103. keyword3 := time.Now().Format(utils.FormatDateTime)
  1104. keyword4 := articleInfo.Abstract
  1105. sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1106. var appointmentList []*models.CygxAppointment
  1107. var mapOpenidSubjectId = make(map[int]string) //预约相关纪要的用户
  1108. if sliceSubjectId != "" {
  1109. appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1110. if e != nil {
  1111. err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1112. return
  1113. }
  1114. var userIds []string
  1115. if len(appointmentList) > 0 {
  1116. for _, v := range appointmentList {
  1117. userIds = append(userIds, strconv.Itoa(v.UserId))
  1118. }
  1119. userIdstr := strings.Join(userIds, ",")
  1120. openIdLists, e := models.GetOpenIdByUserIds(userIdstr)
  1121. if e != nil {
  1122. err = errors.New("GetOpenIdByUserIds, Err: " + e.Error())
  1123. return
  1124. }
  1125. keyword1 = industryName
  1126. var openIdArr []string
  1127. for _, item := range openIdLists {
  1128. if mapOpenidRefuset[item.UserId] != "" {
  1129. continue // 拒绝消息推送的用户不接收模版消息
  1130. }
  1131. openIdArr = append(openIdArr, item.OpenId)
  1132. mapOpenidSubjectId[item.UserId] = "_"
  1133. }
  1134. go SendWxMsgWithArticleUpdateList(industryName, keyword2, keyword3, keyword4, openIdArr, articleId)
  1135. }
  1136. }
  1137. var openIdArr2 []string
  1138. for _, item := range openidPowerList {
  1139. if mapOpenidRefuset[item.UserId] != "" || mapOpenidSubjectId[item.UserId] != "" {
  1140. continue // 拒绝消息推送的用户不接收模版消息
  1141. }
  1142. openIdArr2 = append(openIdArr2, item.OpenId)
  1143. }
  1144. go SendWxMsgWithArticleUpdateList(keyword1, keyword2, keyword3, keyword4, openIdArr2, articleId)
  1145. }
  1146. ////获取关注这个文章对应产业的用户的 openid
  1147. //mapOpenidFllow := make(map[int]string)
  1148. //if chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID_CHART && chartPermissionId != utils.ZHOU_QI_ID {
  1149. // openidFllowListMobile, e := models.GetCygxUserFllowOpenid(articleId)
  1150. // if e != nil {
  1151. // err = errors.New("GetCygxUserFllowOpenid, Err: " + e.Error())
  1152. // return
  1153. // }
  1154. //
  1155. // var mobileArrFllow []string
  1156. // for _, v := range openidFllowListMobile {
  1157. // mobileArrFllow = append(mobileArrFllow, v.Mobile)
  1158. // }
  1159. //
  1160. // openidFllowList, e := models.GetWxOpenIdByMobileSliceList(mobileArrFllow)
  1161. // if e != nil {
  1162. // err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error())
  1163. // return
  1164. // }
  1165. //
  1166. // for _, v := range openidFllowList {
  1167. // mapOpenidFllow[v.UserId] = v.OpenId
  1168. // }
  1169. //}
  1170. //
  1171. ////获取提交过推送规则的用户的 openid
  1172. //mapUserIdChooseSend := make(map[int]int)
  1173. //mapUserIdChooseSendTypeNoPermission := make(map[int]int)
  1174. //chooseSendtList, e := models.GetCygxXzsChooseSend()
  1175. //if e != nil {
  1176. // err = errors.New("GetCygxXzsChooseSend, Err: " + e.Error())
  1177. // return
  1178. //}
  1179. //for _, v := range chooseSendtList {
  1180. // mapUserIdChooseSend[v.UserId] = v.UserId
  1181. // if v.IsRefuse == 1 {
  1182. // continue
  1183. // }
  1184. // //获取选择主客观赛道的用户
  1185. // if reportMapDetail.PermissionType == 1 {
  1186. // if v.IsSubjective == 1 {
  1187. // mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1188. // }
  1189. // } else {
  1190. // if v.IsObjective == 1 {
  1191. // mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1192. // }
  1193. // }
  1194. //}
  1195. ////已经推送了的openid
  1196. //mapOpenidPushed := make(map[int]string)
  1197. //
  1198. //keyword2 := articleInfo.Title
  1199. //keyword3 := time.Now().Format(utils.FormatDateTime)
  1200. //keyword4 := articleInfo.Abstract
  1201. //mapAlreadySend := make(map[int]int)
  1202. //
  1203. //sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1204. //var appointmentList []*models.CygxAppointment
  1205. //if sliceSubjectId != "" {
  1206. // appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1207. // if e != nil {
  1208. // err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1209. // return
  1210. // }
  1211. // //var userIds []string
  1212. // //if len(appointmentList) > 0 {
  1213. // // for _, v := range appointmentList {
  1214. // // //fmt.Println("mapActivityUserId:", v.UserId)
  1215. // // userIds = append(userIds, strconv.Itoa(v.UserId))
  1216. // // mapActivityUserId[v.UserId] += v.ActivityName + ","
  1217. // // }
  1218. // // userIdstr := strings.Join(userIds, ",")
  1219. // // openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
  1220. // // if err != nil {
  1221. // // fmt.Println("GetOpenIdByUserIds Err:", err.Error())
  1222. // // return err
  1223. // // }
  1224. // // for _, item := range openIdLists {
  1225. // // //first := "您预约的调研,有关联的纪要发布/更新了"
  1226. // // //keyword1 := industryName
  1227. // // openIditem := new(models.OpenIdList)
  1228. // // openIditem.OpenId = item.OpenId
  1229. // // openIditem.UserId = item.UserId
  1230. // // if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1231. // // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1232. // // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1233. // // fmt.Println("AlreadySend:", openIditem.UserId)
  1234. // // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1235. // // }
  1236. // // }
  1237. // //}
  1238. //}
  1239. ////如果是策略就按照策略的推送方式来写
  1240. //if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME || reportMapDetail.ChartPermissionName == utils.GU_SHOU_NAME {
  1241. // //获取提交过推送规则的用户的 openid
  1242. // mapUserFllowCeLue := make(map[int]string)
  1243. // userFllowCeLueList, e := models.GetCygxUserFllowCeLueOpenid(articleInfo.CategoryId)
  1244. // if e != nil {
  1245. // err = errors.New("GetCygxUserFllowCeLueOpenid, Err: " + e.Error())
  1246. // return
  1247. // }
  1248. // for _, v := range userFllowCeLueList {
  1249. // mapUserFllowCeLue[v.UserId] = v.OpenId
  1250. // }
  1251. // for k, v := range mapOpenidPower {
  1252. // if mapOpenidPushed[k] != "" {
  1253. // continue
  1254. // }
  1255. // openIditem := new(models.OpenIdList)
  1256. // openIditem.UserId = k
  1257. // openIditem.OpenId = v
  1258. // first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1259. // keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1260. // mapActivityUserId := make(map[int]string)
  1261. // if articleInfo.ReportType == 2 {
  1262. // sliceSubjectId, _ = models.GetSubjectIds(articleId)
  1263. // if sliceSubjectId != "" {
  1264. // appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1265. // if e != nil {
  1266. // err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1267. // return
  1268. // }
  1269. // var userIds []string
  1270. // if len(appointmentList) > 0 {
  1271. // for _, v := range appointmentList {
  1272. // //fmt.Println("mapActivityUserId:", v.UserId)
  1273. // userIds = append(userIds, strconv.Itoa(v.UserId))
  1274. // mapActivityUserId[v.UserId] += v.ActivityName + ","
  1275. // }
  1276. // userIdstr := strings.Join(userIds, ",")
  1277. // openIdLists, e := models.GetOpenIdByUserIds(userIdstr)
  1278. // appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1279. // if e != nil {
  1280. // err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1281. // return
  1282. // }
  1283. // for _, item := range openIdLists {
  1284. // first = "您预约的调研,有关联的纪要发布/更新了"
  1285. // keyword1 = industryName
  1286. // openIditem = new(models.OpenIdList)
  1287. // openIditem.OpenId = item.OpenId
  1288. // openIditem.UserId = item.UserId
  1289. // if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1290. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1291. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1292. // fmt.Println("AlreadySend:", openIditem.UserId)
  1293. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1294. // }
  1295. // }
  1296. // }
  1297. // }
  1298. // }
  1299. // _, ok := mapAlreadySend[openIditem.UserId]
  1300. // //如果有权限而且小助手没有提交过信息的 就做正常推送
  1301. // if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1302. // fmt.Println("1:", articleId)
  1303. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1304. // }
  1305. // //如果小助手勾选了对应的权限信息 就做正常推送
  1306. // if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" && !ok {
  1307. // fmt.Println("2:", articleId)
  1308. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1309. // }
  1310. // }
  1311. //} else {
  1312. // for k, v := range mapOpenidPower {
  1313. // if mapOpenidPushed[k] != "" {
  1314. // continue
  1315. // }
  1316. // mapUserIdChooseSendType := make(map[int]int)
  1317. // for _, vS := range chooseSendtList {
  1318. // if vS.IsRefuse == 1 {
  1319. // continue
  1320. // }
  1321. // //获取选择主客观赛道的用户
  1322. // if reportMapDetail.PermissionType == 1 {
  1323. // if vS.IsSubjective == 1 {
  1324. // mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1325. // }
  1326. // } else if reportMapDetail.PermissionType == 2 {
  1327. // if vS.IsObjective == 1 {
  1328. // mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1329. // }
  1330. // } else {
  1331. // if vS.IsSubjective == 1 || vS.IsObjective == 1 {
  1332. // mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1333. // }
  1334. // }
  1335. // }
  1336. // openIditem := new(models.OpenIdList)
  1337. // openIditem.UserId = k
  1338. // openIditem.OpenId = v
  1339. // first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1340. // keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1341. // mapActivityUserId := make(map[int]string)
  1342. // if articleInfo.ReportType == 2 {
  1343. // keyword1 = fmt.Sprint("【", industryName, "】有报告发布/更新")
  1344. // //sliceSubjectId, _ = models.GetSubjectIds(articleId)
  1345. // if sliceSubjectId != "" {
  1346. // //appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1347. // //if e != nil {
  1348. // // err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1349. // // return
  1350. // //}
  1351. // var userIds []string
  1352. // if len(appointmentList) > 0 {
  1353. // for _, v := range appointmentList {
  1354. // //fmt.Println("mapActivityUserId:", v.UserId)
  1355. // userIds = append(userIds, strconv.Itoa(v.UserId))
  1356. // mapActivityUserId[v.UserId] += v.ActivityName + ","
  1357. // }
  1358. // userIdstr := strings.Join(userIds, ",")
  1359. // openIdLists, e := models.GetOpenIdByUserIds(userIdstr)
  1360. // if e != nil {
  1361. // err = errors.New("GetOpenIdByUserIds, Err: " + e.Error())
  1362. // return
  1363. // }
  1364. // for _, item := range openIdLists {
  1365. // //first := "您预约的调研,有关联的纪要发布/更新了"
  1366. // //keyword1 := industryName
  1367. // openIditem := new(models.OpenIdList)
  1368. // openIditem.OpenId = item.OpenId
  1369. // openIditem.UserId = item.UserId
  1370. // if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1371. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1372. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1373. // fmt.Println("AlreadySend:", openIditem.UserId)
  1374. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1375. // }
  1376. // }
  1377. // }
  1378. // }
  1379. // }
  1380. //
  1381. // //如果有权限而且小助手没有提交过信息的 就做正常推送
  1382. // _, ok := mapAlreadySend[openIditem.UserId]
  1383. // if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1384. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1385. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1386. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1387. // }
  1388. // //如果小助手勾选了对应的权限信息 就做正常推送
  1389. // if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" && mapUserIdChooseSendType[openIditem.UserId] > 0 && !ok {
  1390. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1391. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1392. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1393. // }
  1394. // }
  1395. //}
  1396. utils.Rc.Put(cacheKey, articleId, time.Hour*12)
  1397. return
  1398. }
  1399. // GetSpecialArticleDetailUserPower 处理用户查看专项调研文章详情的权限
  1400. func GetSpecialArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
  1401. userType, _, e := GetUserType(user.CompanyId)
  1402. if e != nil {
  1403. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  1404. return
  1405. }
  1406. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  1407. if userType == 1 || userType == 2 {
  1408. havePower = true
  1409. return
  1410. }
  1411. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  1412. if e != nil {
  1413. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1414. return
  1415. }
  1416. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  1417. if e != nil {
  1418. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  1419. return
  1420. }
  1421. if reportMapDetail == nil {
  1422. err = errors.New("GetdetailByCategoryIdP,获取详情失败, ")
  1423. return
  1424. }
  1425. fmt.Println(permissionStr)
  1426. //如果没有对应的升级权限,则返回
  1427. if !strings.Contains(permissionStr, reportMapDetail.ChartPermissionName) {
  1428. return
  1429. } else {
  1430. havePower = true
  1431. }
  1432. return
  1433. }
  1434. // HandleArticleCategoryImg 预处理文章的封面图片
  1435. func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeArticle, err error) {
  1436. //研选的五张图片
  1437. detailResearch, e := models.GetConfigByCode("category_research_img_url")
  1438. if e != nil {
  1439. err = errors.New("获取研选的五张图片失败" + e.Error())
  1440. return
  1441. }
  1442. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  1443. //对应分类的所图片
  1444. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  1445. if err != nil {
  1446. err = errors.New("获取对应分类的所图片失败" + err.Error())
  1447. return
  1448. }
  1449. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  1450. mapCategoryUrl := make(map[string]string)
  1451. var categoryId string
  1452. var imgUrlChart string
  1453. for _, v := range categoryUrlList {
  1454. vslice := strings.Split(v, "_")
  1455. categoryId = vslice[0]
  1456. imgUrlChart = vslice[len(vslice)-1]
  1457. mapCategoryUrl[categoryId] = imgUrlChart
  1458. }
  1459. mapChartPerssion := make(map[string]string)
  1460. reportMappingList, err := models.GetReportMappingStrategyAll()
  1461. if err != nil {
  1462. err = errors.New("GetReportMappingStrategyAll err" + err.Error())
  1463. return
  1464. }
  1465. for _, v := range reportMappingList {
  1466. mapChartPerssion[strconv.Itoa(v.CategoryId)] = v.ChartPermissionName
  1467. }
  1468. for k, v := range list {
  1469. list[k].Abstract, _ = GetReportContentTextSub(v.Abstract)
  1470. item := list[k]
  1471. //如果文章一开始的内容是图片,优先展示第一张图片
  1472. if list[k].Annotation == "" {
  1473. imgurl, _ := FixArticleImgUrl(html.UnescapeString(list[k].Body))
  1474. if imgurl != "" {
  1475. list[k].BodyHtml = imgurl
  1476. }
  1477. }
  1478. //newBody, _ := GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
  1479. list[k].Annotation = ArticleAnnotation(item)
  1480. list[k].Body = ""
  1481. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  1482. list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
  1483. //如果是研选系列的任意取五张图片的中的一张
  1484. if v.CategoryId == "0" || v.ArticleId > utils.SummaryArticleId {
  1485. knum := v.ArticleId % 5
  1486. list[k].ImgUrlPc = researchList[knum]
  1487. } else {
  1488. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  1489. }
  1490. list[k].ArticleResponse = 4 // 默认展示核心观点
  1491. //ArticleResponse int `description:"报告类型 0:啥也不是,1研选报告,2:研选纪要,3:研选沙龙,4;核心观点"`
  1492. if list[k].ArticleId >= utils.SummaryArticleId {
  1493. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  1494. list[k].IsNeedJump = true
  1495. list[k].ArticleResponse = 1
  1496. //if v.IsReport == 1 {
  1497. // list[k].ArticleResponse = 1
  1498. //} else if v.ArticleTypeName == "纪要" {
  1499. // list[k].ArticleResponse = 2
  1500. //} else if v.ArticleTypeName == "观点" {
  1501. // list[k].ArticleResponse = 3
  1502. //} else if v.ArticleTypeName == "沙龙" {
  1503. // list[k].ArticleResponse = 3
  1504. //} else if v.ArticleTypeName == "路演精华" {
  1505. // list[k].ArticleResponse = 1
  1506. //}
  1507. }
  1508. list[k].Source = 1
  1509. //添加行业默认图片
  1510. if v.ImgUrlPc == "" {
  1511. if v.ChartPermissionName == utils.YI_YAO_NAME {
  1512. list[k].ImgUrlPc = utils.YI_YAO_OTHER_IMG
  1513. } else if v.ChartPermissionName == utils.XIAO_FEI_NAME {
  1514. list[k].ImgUrlPc = utils.XIAO_FEI_OTHER_IMG
  1515. } else if v.ChartPermissionName == utils.KE_JI_NAME {
  1516. list[k].ImgUrlPc = utils.KE_JI_OTHER_IMG
  1517. } else if v.ChartPermissionName == utils.ZHI_ZAO_NAME {
  1518. list[k].ImgUrlPc = utils.ZHI_ZAO_OTHER_IMG
  1519. }
  1520. }
  1521. //是不是研选报告
  1522. if v.ArticleTypeId > 0 {
  1523. list[k].IsResearch = true
  1524. }
  1525. }
  1526. articleIds := make([]int, 0)
  1527. for i := range list {
  1528. articleIds = append(articleIds, list[i].ArticleId)
  1529. }
  1530. articleMapPv := GetArticleHistoryByArticleId(articleIds) //文章Pv
  1531. // 报告关联产业信息
  1532. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  1533. if len(articleIds) > 0 {
  1534. var industryCond string
  1535. var industryPars []interface{}
  1536. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1537. industryPars = append(industryPars, articleIds)
  1538. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  1539. if e != nil {
  1540. err = errors.New("GetIndustrialListByarticleId" + e.Error())
  1541. return
  1542. }
  1543. for i := range industryList {
  1544. v := industryList[i]
  1545. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  1546. ArticleId: v.ArticleId,
  1547. IndustrialManagementId: v.IndustrialManagementId,
  1548. IndustryName: v.IndustryName,
  1549. ChartPermissionId: v.ChartPermissionId,
  1550. })
  1551. }
  1552. }
  1553. for k, v := range list {
  1554. if len(industryMap[v.ArticleId]) > 0 {
  1555. list[k].List = industryMap[v.ArticleId]
  1556. } else {
  1557. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  1558. }
  1559. v.Pv = articleMapPv[v.ArticleId]
  1560. if v.Pv > 999 {
  1561. list[k].Pv = 999
  1562. }
  1563. }
  1564. if len(list) == 0 {
  1565. list = make([]*models.HomeArticle, 0)
  1566. }
  1567. items = list
  1568. return
  1569. }
  1570. // 处理核心观点的展示规则
  1571. func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
  1572. if item.ArticleId >= utils.SummaryArticleId {
  1573. item.Annotation = YxArticleAnnotation(item)
  1574. }
  1575. if item.Annotation != "" {
  1576. annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  1577. annotation = strings.Replace(item.Annotation, "&nbsp;", "", -1)
  1578. } else {
  1579. return
  1580. }
  1581. bodyText, _ := GetReportContentTextSubNew(annotation)
  1582. if bodyText == "" {
  1583. return
  1584. }
  1585. if annotation != "" {
  1586. annotation = html.UnescapeString(annotation)
  1587. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1588. docText := doc.Text()
  1589. mapDoc := make(map[int]string)
  1590. var mapSort []int
  1591. p := doc.Find("p")
  1592. p.Each(func(tk int, pd *goquery.Selection) {
  1593. pdText := pd.Text()
  1594. pdText = strings.Replace(pdText, " ", "", -1)
  1595. if pdText != "" {
  1596. textLen := strings.Index(docText, pdText)
  1597. mapDoc[(strings.Index(docText, pdText))] = pdText
  1598. mapSort = append(mapSort, textLen)
  1599. }
  1600. })
  1601. li := doc.Find("li")
  1602. li.Each(func(tk int, li *goquery.Selection) {
  1603. liText := li.Text()
  1604. liText = strings.Replace(liText, " ", "", -1)
  1605. if liText != "" {
  1606. textLen := strings.Index(docText, liText)
  1607. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1608. mapSort = append(mapSort, textLen)
  1609. }
  1610. })
  1611. ul := doc.Find("ul")
  1612. ul.Each(func(tk int, ul *goquery.Selection) {
  1613. ulText := ul.Text()
  1614. ulText = strings.Replace(ulText, " ", "", -1)
  1615. if ulText != "" {
  1616. textLen := strings.Index(docText, ulText)
  1617. mapDoc[(strings.Index(docText, ulText))] = ulText
  1618. mapSort = append(mapSort, textLen)
  1619. }
  1620. })
  1621. if len(mapSort) == 0 {
  1622. return
  1623. } else {
  1624. //排序
  1625. sort.Ints(mapSort)
  1626. var annotationHtml string
  1627. for _, vSort := range mapSort {
  1628. for k, v := range mapDoc {
  1629. if k == vSort && v != "" {
  1630. annotationHtml += v + "<br>"
  1631. }
  1632. }
  1633. }
  1634. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1635. annotationHtml = "<p>" + annotationHtml + "</p>"
  1636. annotation = annotationHtml
  1637. }
  1638. }
  1639. return
  1640. }
  1641. // 处理核心观点的展示规则
  1642. func AnnotationHtml(bodyText string) (annotation string) {
  1643. if bodyText == "" {
  1644. return
  1645. }
  1646. annotation = bodyText
  1647. annotation = html.UnescapeString(annotation)
  1648. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1649. docText := doc.Text()
  1650. mapDoc := make(map[int]string)
  1651. var mapSort []int
  1652. p := doc.Find("p")
  1653. p.Each(func(tk int, pd *goquery.Selection) {
  1654. pdText := pd.Text()
  1655. //pdText = strings.Replace(pdText, " ", "", -1)
  1656. if pdText != "" {
  1657. textLen := strings.Index(docText, pdText)
  1658. mapDoc[(strings.Index(docText, pdText))] = pdText
  1659. mapSort = append(mapSort, textLen)
  1660. }
  1661. })
  1662. li := doc.Find("li")
  1663. li.Each(func(tk int, li *goquery.Selection) {
  1664. liText := li.Text()
  1665. liText = strings.Replace(liText, " ", "", -1)
  1666. if liText != "" {
  1667. textLen := strings.Index(docText, liText)
  1668. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1669. mapSort = append(mapSort, textLen)
  1670. }
  1671. })
  1672. ul := doc.Find("ul")
  1673. ul.Each(func(tk int, ul *goquery.Selection) {
  1674. ulText := ul.Text()
  1675. ulText = strings.Replace(ulText, " ", "", -1)
  1676. if ulText != "" {
  1677. textLen := strings.Index(docText, ulText)
  1678. mapDoc[(strings.Index(docText, ulText))] = ulText
  1679. mapSort = append(mapSort, textLen)
  1680. }
  1681. })
  1682. section := doc.Find("section")
  1683. section.Each(func(tk int, section *goquery.Selection) {
  1684. sectionText := section.Text()
  1685. sectionText = strings.Replace(sectionText, " ", "", -1)
  1686. if sectionText != "" {
  1687. textLen := strings.Index(docText, sectionText)
  1688. mapDoc[(strings.Index(docText, sectionText))] = sectionText
  1689. mapSort = append(mapSort, textLen)
  1690. }
  1691. })
  1692. if len(mapSort) == 0 {
  1693. return
  1694. } else {
  1695. //排序
  1696. sort.Ints(mapSort)
  1697. var annotationHtml string
  1698. for _, vSort := range mapSort {
  1699. for k, v := range mapDoc {
  1700. if k == vSort && v != "" {
  1701. annotationHtml += v + "<br>"
  1702. }
  1703. }
  1704. }
  1705. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1706. annotationHtml = "<p>" + annotationHtml + "</p>"
  1707. annotation = annotationHtml
  1708. }
  1709. return
  1710. }
  1711. // 处理产品内测展示规则
  1712. func ProductInteriorHtml(bodyText string) (annotation string) {
  1713. if bodyText == "" {
  1714. return
  1715. }
  1716. sliceBody := strings.Split(bodyText, "</p>")
  1717. annotation, _ = GetReportContentTextSub(sliceBody[0])
  1718. return
  1719. }
  1720. // 解析研选内容中的核心观点
  1721. func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
  1722. //如果不规范,就获取内容主体
  1723. if strings.Count(article.Body, "<hr") == 0 {
  1724. //如果内容不规范而且,还有图片,就把核心观点置空
  1725. if article.BodyHtml != "" {
  1726. return
  1727. }
  1728. annotation, _ = GetReportContentTextSub(article.Body)
  1729. return
  1730. }
  1731. body := strings.ReplaceAll(article.Body, "<strong>", "")
  1732. body = strings.ReplaceAll(body, "</strong>", "")
  1733. body = strings.ReplaceAll(body, "</ol>", "</div>")
  1734. body = strings.ReplaceAll(body, "<ol>", "<div>")
  1735. body = strings.ReplaceAll(body, "</li>", "</p>")
  1736. body = strings.ReplaceAll(body, "<li>", "<p>")
  1737. re, _ := regexp.Compile("<strong.*?>")
  1738. body = re.ReplaceAllString(body, "")
  1739. reLi, _ := regexp.Compile("<li.*?>")
  1740. body = reLi.ReplaceAllString(body, "")
  1741. var plus int
  1742. coreIndex := strings.Index(body, "核心观点:")
  1743. plus = 15
  1744. if coreIndex == -1 {
  1745. coreIndex = strings.Index(body, "核心观点:")
  1746. plus = 13
  1747. }
  1748. if coreIndex == -1 {
  1749. coreIndex = strings.Index(body, "核心观点")
  1750. plus = 12
  1751. }
  1752. if coreIndex == -1 {
  1753. coreIndex = strings.Index(body, "核心结论:")
  1754. plus = 15
  1755. }
  1756. if coreIndex == -1 {
  1757. coreIndex = strings.Index(body, "核心结论:")
  1758. plus = 13
  1759. }
  1760. if coreIndex == -1 {
  1761. coreIndex = strings.Index(body, "核心结论")
  1762. plus = 12
  1763. }
  1764. endIndex := strings.Index(body, "<hr")
  1765. if coreIndex != -1 && endIndex != -1 {
  1766. body = body[coreIndex+plus : endIndex]
  1767. }
  1768. annotation = body
  1769. return
  1770. }
  1771. // 通过接解析带有Md5的文章链接获取文章ID
  1772. func GetReportLinkToArticleid(reportLink string) (articleId int, err error) {
  1773. defer func() {
  1774. if err != nil {
  1775. go utils.SendAlarmMsg("通过接解析带有Md5的文章链接获取文章ID失败"+err.Error(), 2)
  1776. }
  1777. }()
  1778. var artMd5 string
  1779. //处理Md5的
  1780. strnum1 := strings.Index(reportLink, "id=")
  1781. if strnum1 > 0 {
  1782. sliceId := strings.Split(reportLink, "id=")
  1783. if len(sliceId) > 1 {
  1784. reportLink = sliceId[1]
  1785. sliceMd5Id := strings.Split(reportLink, "&")
  1786. artMd5 = sliceMd5Id[0]
  1787. }
  1788. if artMd5 != "" {
  1789. detail, errArt := models.GetArticleDetailByIdMd5(artMd5)
  1790. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  1791. err = errArt
  1792. return
  1793. }
  1794. if detail != nil {
  1795. articleId = detail.ArticleId
  1796. }
  1797. }
  1798. } else {
  1799. //处理活动的
  1800. linkList := strings.Split(reportLink, "/")
  1801. if linkList[len(linkList)-1] != "" {
  1802. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  1803. if linkArticleId > 0 {
  1804. articleInfo, errArt := models.GetArticleDetailById(linkArticleId)
  1805. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  1806. err = errArt
  1807. return
  1808. }
  1809. if articleInfo != nil {
  1810. articleId = articleInfo.ArticleId
  1811. }
  1812. }
  1813. }
  1814. }
  1815. return
  1816. }
  1817. // GetArticleStockMap 获取个股标签所对应的文章ID
  1818. func GetArticleStockMap() (mapResp map[string]int, err error) {
  1819. defer func() {
  1820. if err != nil {
  1821. go utils.SendAlarmMsg("获取个股标签所对应的文章ID失败"+err.Error(), 2)
  1822. }
  1823. }()
  1824. list, err := models.GetArticleStock()
  1825. if err != nil && err.Error() != utils.ErrNoRow() {
  1826. return
  1827. }
  1828. mapResp = make(map[string]int, 0)
  1829. if len(list) > 0 {
  1830. //一对一精准匹配
  1831. for _, v := range list {
  1832. sliceSubjects := strings.Split(v.Stock, "/")
  1833. if len(sliceSubjects) > 0 {
  1834. for _, vSubject := range sliceSubjects {
  1835. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  1836. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  1837. subject := sliceXiahuaxian[0]
  1838. mapResp[subject] = v.ArticleId
  1839. }
  1840. }
  1841. }
  1842. }
  1843. return
  1844. }
  1845. // GetAiQianYanArtilceList 获取AI前沿几篇文章
  1846. func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.ReportArticle, total int, err error) {
  1847. defer func() {
  1848. if err != nil {
  1849. go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
  1850. }
  1851. }()
  1852. var condition string
  1853. var pars []interface{}
  1854. condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1 ORDER BY publish_date DESC `
  1855. articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
  1856. if e != nil {
  1857. err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
  1858. return
  1859. }
  1860. total, e = models.GetCygxArticleCount(condition, pars)
  1861. if e != nil {
  1862. err = errors.New("GetCygxArticleCount, Err: " + e.Error())
  1863. return
  1864. }
  1865. for _, v := range articleList {
  1866. item := new(models.ReportArticle)
  1867. item.ArticleId = v.ArticleId
  1868. item.Title = v.Title
  1869. item.Abstract = v.Abstract
  1870. item.Annotation = v.Annotation
  1871. item.PublishDate = v.PublishDate
  1872. item.Resource = 1
  1873. item.CategoryId = strconv.Itoa(v.CategoryId)
  1874. item.Body = v.Body
  1875. items = append(items, item)
  1876. }
  1877. return
  1878. }
  1879. // 获取文章内部图表的第一张封面图
  1880. func GetArticleCoverByChartFirst(body string) (cover string) {
  1881. var err error
  1882. defer func() {
  1883. if err != nil {
  1884. fmt.Println(err)
  1885. go utils.SendAlarmMsg("获取文章内部图表的第一张封面图失败,Err:"+err.Error()+body, 3)
  1886. }
  1887. }()
  1888. var chartUrl string
  1889. var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
  1890. match := hrefRegexp.FindAllString(body, -1)
  1891. if match != nil {
  1892. for _, v := range match {
  1893. if strings.Contains(v, "charts/display") {
  1894. chartUrl = v
  1895. break
  1896. }
  1897. }
  1898. }
  1899. if chartUrl != "" {
  1900. urlSlice := strings.Split(chartUrl, "/")
  1901. lenurlSlice := len(urlSlice)
  1902. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  1903. if sourceId == 0 {
  1904. sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
  1905. }
  1906. if sourceId == 0 {
  1907. err = errors.New("新的图标链接无法解析" + chartUrl)
  1908. return
  1909. }
  1910. chartUrlApi := utils.ApiUrl + "charts/" + strconv.Itoa(sourceId)
  1911. authorization := utils.ApiAuthorization
  1912. body, e := PublicGetDate(chartUrlApi, authorization)
  1913. if e != nil {
  1914. err = errors.New("PublicGetDate" + err.Error())
  1915. return
  1916. }
  1917. var resultDate models.ChartResultDetailApi
  1918. e = json.Unmarshal(body, &resultDate)
  1919. if e != nil {
  1920. err = errors.New(" json.Unmarshal" + err.Error())
  1921. }
  1922. cover = resultDate.Data.Cover
  1923. }
  1924. return
  1925. }
  1926. // GetYxArticleIdMap 获取研选文章ID
  1927. func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
  1928. var err error
  1929. defer func() {
  1930. if err != nil {
  1931. go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
  1932. }
  1933. }()
  1934. var condition string
  1935. var pars []interface{}
  1936. condition = ` AND article_type_id > 0 `
  1937. if len(articleIds) > 0 {
  1938. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1939. pars = append(pars, articleIds)
  1940. }
  1941. articleList, e := models.GetArticleList(condition, pars)
  1942. if e != nil {
  1943. err = errors.New("GetArticleList, Err: " + e.Error())
  1944. return
  1945. }
  1946. mapResp = make(map[int]bool, 0)
  1947. for _, v := range articleList {
  1948. mapResp[v.ArticleId] = true
  1949. }
  1950. return
  1951. }
  1952. // GetUserArticleHistoryRecord 获取用户已经阅读的文章ID
  1953. func GetUserArticleHistoryRecord(user *models.WxUserItem) (articleIdMap map[int]bool, err error) {
  1954. var condition string
  1955. var pars []interface{}
  1956. condition = " AND user_id = ? "
  1957. pars = append(pars, user.UserId)
  1958. articleIdMap = make(map[int]bool, 0)
  1959. list, err := models.GetArticleHistoryRecord(condition, pars)
  1960. if err != nil && err.Error() != utils.ErrNoRow() {
  1961. return
  1962. }
  1963. for _, v := range list {
  1964. articleIdMap[v.ArticleId] = true
  1965. }
  1966. return
  1967. }
  1968. // GetUserArticleHistoryIndustrialNewPublishDate 获取产业关联的的文章用户是否阅读
  1969. func GetUserArticleHistoryIndustrialNewPublishDate(user *models.WxUserItem, industrialIdArr []int, articleTypeIds, resource string) (mapIndustrialArticleHistory map[int]bool, err error) {
  1970. if len(industrialIdArr) == 0 {
  1971. return
  1972. }
  1973. var condition string
  1974. var pars []interface{}
  1975. articleIdMap, err := GetUserArticleHistoryRecord(user)
  1976. if err != nil {
  1977. return
  1978. }
  1979. if resource == utils.REOURCE_YX {
  1980. condition = ` AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) `
  1981. } else {
  1982. condition = ` AND a.article_type_id = 0 AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId)
  1983. }
  1984. var startTime time.Time
  1985. if utils.StrTimeToTime(utils.OnlineTime).After(user.CreatedTime) {
  1986. startTime = utils.StrTimeToTime(utils.OnlineTime)
  1987. } else {
  1988. startTime = user.CreatedTime
  1989. }
  1990. condition += ` AND mg.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `) AND a.publish_date > ? `
  1991. pars = append(pars, industrialIdArr, startTime)
  1992. list, err := models.GetCygxIndustrialArticleGroupManagement(condition, pars)
  1993. if err != nil {
  1994. return
  1995. }
  1996. mapIndustrialArticle := make(map[int][]*models.CygxIndustrialArticleGroupManagementResp)
  1997. //mapIndustrialArticleMax := make(map[int]int, 0)
  1998. mapIndustrialArticleHistory = make(map[int]bool, 0)
  1999. //mapIndustrialArticleMaxTime := make(map[int]time.Time)
  2000. for _, v := range list {
  2001. item := new(models.CygxIndustrialArticleGroupManagementResp)
  2002. item.IndustrialManagementId = v.IndustrialManagementId
  2003. item.ArticleId = v.ArticleId
  2004. item.PublishDate = v.PublishDate
  2005. mapIndustrialArticle[v.IndustrialManagementId] = append(mapIndustrialArticle[v.IndustrialManagementId], item)
  2006. }
  2007. for k, v := range mapIndustrialArticle {
  2008. for _, item := range v {
  2009. if !articleIdMap[item.ArticleId] {
  2010. mapIndustrialArticleHistory[k] = true
  2011. }
  2012. }
  2013. }
  2014. return
  2015. }