article.go 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102
  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. } else {
  840. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  841. keyword2 = "未归类"
  842. keyword3 = v.Title
  843. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  844. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  845. go models.UpdateIsClassFail(artcleId)
  846. }
  847. }
  848. }
  849. }
  850. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  851. }
  852. if v.CategoryName == utils.ZHOU_QI_NAME {
  853. UpdateCygxZhouqiArticleMapTime(v.FieldName) //更新周期对应分类下所管理文章的更新时间
  854. }
  855. //【公司调研】系列纪要发布/更新后 end
  856. //查研观向6.9模板消息推送规则
  857. //但是如果报告的发布时间是在10天以前的,公众号就不推送了
  858. //if time.Now().AddDate(0, 0, -10).Before(articleResult.PublishDate.Add(time.Hour * 8)) {
  859. // go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  860. //}
  861. }
  862. go models.UpdateCygxArticleCeluePush(artcleId)
  863. AddComprehensiveArticle(artcleId) // 同步到综合页面的搜索引擎
  864. AddComprehensiveIndustrialSource("Hz", artcleId) // 同步到综合页面的搜索引擎(添加产业资源包)
  865. GetSummarytoEs(artcleId) // 同步到ES搜索引擎
  866. GetIndustrialManagementArticleNewPublishData()
  867. if len(listArticleData) > 0 {
  868. for _, v := range listArticleData {
  869. count, err := models.GetCygxArticleDataCount(v.ArticleId)
  870. if err != nil {
  871. fmt.Println("GetCygxArticleDataCount Err:", err.Error())
  872. return err
  873. }
  874. if count == 0 {
  875. _, err := models.AddCygxArticleData(v)
  876. if err != nil {
  877. fmt.Println("AddCygxArticleData Err:", err.Error())
  878. return err
  879. }
  880. }
  881. //} else {
  882. // updateParams := make(map[string]interface{})
  883. // updateParams["Cover"] = v.Cover
  884. // whereParam := map[string]interface{}{"article_id": v.ArticleId}
  885. // err = models.UpdateByExpr(models.CygxArticleData{}, whereParam, updateParams)
  886. // if err != nil {
  887. // fmt.Println("UpdateByExpr CygxArticleData Err:" + err.Error())
  888. // return err
  889. // }
  890. //}
  891. }
  892. }
  893. AddCygxReportMappingCategoryGroupByArticleId(artcleId)
  894. return err
  895. }
  896. //func init() {
  897. // DoArticleOnenIdWxTemplateMsg(8112)
  898. //}
  899. // 过滤策略平台报告,研选报告重复推送,以及权限勾选的推送
  900. func DoArticleOnenIdWxTemplateMsg(articleId int) {
  901. var err error
  902. //策略平台同步过来的文章ID,做微信模板消息推送,同一篇报告12小时只推送一次
  903. cacheKey := fmt.Sprint(utils.CACHE_KEY_ARTICLE_ID_TEMPLATE, ":ArticleId", articleId)
  904. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  905. if ttlTime > 0 {
  906. fmt.Println(ttlTime)
  907. return
  908. }
  909. defer func() {
  910. if err != nil {
  911. go utils.SendAlarmMsg("过滤策略平台报告,研选报告重复推送,以及权限勾选的推送失败 DoArticleOnenIdWxTemplateMsg ErrMsg:"+err.Error(), 2)
  912. fmt.Println(err)
  913. }
  914. }()
  915. //获取文章详情
  916. articleInfo, e := models.GetArticleDetailById(articleId)
  917. if e != nil {
  918. err = errors.New("GetArticleDetailById, Err: " + e.Error())
  919. return
  920. }
  921. articleInfo.Abstract, _ = GetReportContentTextSub(articleInfo.Abstract)
  922. var chartPermissionId int
  923. //固收的权限,暂时当策略的逻辑一样处理
  924. var chartPermissionName string
  925. var permissionName string
  926. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  927. if e != nil {
  928. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  929. return
  930. }
  931. permissionName = reportMapDetail.ChartPermissionName
  932. if reportMapDetail.ChartPermissionId == utils.CE_LUE_ID {
  933. chartPermissionId = utils.CE_LUE_ID
  934. } else if reportMapDetail.ChartPermissionId == utils.GU_SHOU_ID_CHART {
  935. chartPermissionId = utils.GU_SHOU_ID_CHART
  936. } else {
  937. if reportMapDetail.PermissionType == 1 {
  938. chartPermissionName = reportMapDetail.ChartPermissionName + "(主观)"
  939. } else {
  940. chartPermissionName = reportMapDetail.ChartPermissionName + "(客观)"
  941. }
  942. chartPermissionDetail, e := models.GetChartPermissionByRemark(chartPermissionName)
  943. if e != nil {
  944. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  945. return
  946. }
  947. chartPermissionId = chartPermissionDetail.ChartPermissionId
  948. }
  949. //文章关联的产业
  950. var industryName string
  951. var industrialManagementId string
  952. if chartPermissionId == utils.CE_LUE_ID || chartPermissionId == utils.GU_SHOU_ID_CHART {
  953. industryName = reportMapDetail.SubCategoryName
  954. }
  955. // 获取所有有权的用户的 openid
  956. //mapOpenidPower := make(map[int]string)
  957. permissionIdList := make([]string, 0)
  958. var condition string
  959. var pars []interface{}
  960. slicepermissionId := strings.Split(strconv.Itoa(chartPermissionId), ",")
  961. if len(slicepermissionId) > 0 {
  962. for _, v := range slicepermissionId {
  963. if v == strconv.Itoa(utils.GU_SHOU_ID_CHART) {
  964. v = strconv.Itoa(utils.CE_LUE_ID)
  965. }
  966. permissionIdList = append(permissionIdList, v)
  967. }
  968. condition += ` AND p.chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
  969. pars = append(pars, permissionIdList)
  970. }
  971. openidPowerListMobile, e := models.GetCygxUserRecordPower(condition, pars)
  972. if e != nil {
  973. err = errors.New("GetCygxUserRecordPower, Err: " + e.Error())
  974. return
  975. }
  976. //获取拒绝接收推送的的用户的 openid
  977. mapOpenidRefuset := make(map[int]string)
  978. openidRefusetList, e := models.GetCygxUserRefusetOpenid()
  979. if e != nil {
  980. err = errors.New("GetCygxUserRefusetOpenid, Err: " + e.Error())
  981. return
  982. }
  983. for _, v := range openidRefusetList {
  984. mapOpenidRefuset[v.UserId] = v.OpenId
  985. }
  986. var mobileArr []string
  987. for _, v := range openidPowerListMobile {
  988. mobileArr = append(mobileArr, v.Mobile)
  989. }
  990. openidPowerList, err := models.GetWxOpenIdByMobileSliceList(mobileArr)
  991. if e != nil {
  992. err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error())
  993. return
  994. }
  995. //四大行业的行业综述报告,对所有开通了对应行业权限的客户都推送。
  996. if articleInfo.ReportType == 1 && permissionName != utils.CE_LUE_NAME && permissionName != utils.GU_SHOU_NAME && permissionName != utils.ZHOU_QI_NAME {
  997. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  998. //openIditem := new(models.OpenIdList)
  999. var openIdArr []string
  1000. for _, item := range openidPowerList {
  1001. if mapOpenidRefuset[item.UserId] != "" {
  1002. continue // 拒绝消息推送的用户不接收模版消息
  1003. }
  1004. openIdArr = append(openIdArr, item.OpenId)
  1005. }
  1006. go SendWxMsgWithArticleUpdateList(keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIdArr, articleId)
  1007. return
  1008. }
  1009. //for _, v := range openidPowerList {
  1010. // mapOpenidPower[v.UserId] = v.OpenId
  1011. //}
  1012. if permissionName == utils.CE_LUE_NAME || permissionName == utils.GU_SHOU_NAME {
  1013. celueListUninterested, e := models.GetCygxXzsChooseCategoryListFollowType(articleInfo.CategoryId, 3)
  1014. if e != nil {
  1015. err = errors.New("GetCygxXzsChooseCategoryListFollowType " + e.Error())
  1016. return
  1017. }
  1018. mapUninterestedClue := make(map[int]string)
  1019. for _, v := range celueListUninterested {
  1020. mapUninterestedClue[v.UserId] = "_"
  1021. mapOpenidRefuset[v.UserId] = "_" //归类成拒绝推送的人
  1022. }
  1023. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1024. var openIdArr []string
  1025. for _, item := range openidPowerList {
  1026. if mapOpenidRefuset[item.UserId] != "" {
  1027. continue // 拒绝消息推送的用户不接收模版消息
  1028. }
  1029. openIdArr = append(openIdArr, item.OpenId)
  1030. }
  1031. go SendWxMsgWithArticleUpdateList(keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIdArr, articleId)
  1032. return
  1033. } else if permissionName == utils.ZHOU_QI_NAME {
  1034. if articleInfo.SeriesName == "" {
  1035. articleInfo.SeriesName = articleInfo.FieldName
  1036. }
  1037. zhouqiListUninterested, e := models.GetCygxXzsChooseCategoryZhouqiListFollowType(articleInfo.FieldName, articleInfo.SeriesName, 3)
  1038. if e != nil {
  1039. err = errors.New("GetCygxXzsChooseCategoryListFollowType " + e.Error())
  1040. return
  1041. }
  1042. mapUninterestedClue := make(map[int]string)
  1043. for _, v := range zhouqiListUninterested {
  1044. mapUninterestedClue[v.UserId] = "_"
  1045. mapOpenidRefuset[v.UserId] = "_" //归类成拒绝推送的人
  1046. }
  1047. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1048. var openIdArr []string
  1049. for _, item := range openidPowerList {
  1050. if mapOpenidRefuset[item.UserId] != "" {
  1051. continue // 拒绝消息推送的用户不接收模版消息
  1052. }
  1053. openIdArr = append(openIdArr, item.OpenId)
  1054. }
  1055. go SendWxMsgWithArticleUpdateList(keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIdArr, articleId)
  1056. return
  1057. } else {
  1058. //if articleInfo.ReportType == 2 {
  1059. detailIndustryNameList, e := models.GetIndustrialManagemenDetailByAaticleID(articleId)
  1060. if e != nil {
  1061. err = errors.New("GetIndustrialManagemenDetailByAaticleID, Err: " + e.Error())
  1062. return
  1063. }
  1064. //如果不存在关联的产业则不推送
  1065. if len(detailIndustryNameList) == 0 {
  1066. return
  1067. } else {
  1068. var industrialIds []int
  1069. for _, v := range detailIndustryNameList {
  1070. industrialIds = append(industrialIds, v.IndustrialManagementId)
  1071. }
  1072. var conditionFollow string
  1073. var parsFollow []interface{}
  1074. //根据产业关注ID,获取用户不感兴趣的产业信息
  1075. conditionFollow = " AND industrial_management_id IN (" + utils.GetOrmInReplace(len(industrialIds)) + ") AND follow_type = 3 "
  1076. parsFollow = append(parsFollow, industrialIds)
  1077. userFllowListUninterested, e := models.GetCygxIndustryFllowListByCon(conditionFollow, parsFollow)
  1078. if e != nil {
  1079. err = errors.New("GetCygxIndustryFllowList, Err: " + e.Error())
  1080. return
  1081. }
  1082. var userFllowNum = make(map[int]int)
  1083. for _, v := range userFllowListUninterested {
  1084. userFllowNum[v.UserId]++
  1085. //如果活动对应的产业数量,跟用户不感兴趣的产业数量一致,就不做推送
  1086. if userFllowNum[v.UserId] == len(detailIndustryNameList) {
  1087. mapOpenidRefuset[v.UserId] = "_"
  1088. }
  1089. }
  1090. }
  1091. for _, v := range detailIndustryNameList {
  1092. industryName += v.IndustryName + ","
  1093. industrialManagementId += strconv.Itoa(v.IndustrialManagementId) + ","
  1094. }
  1095. industryName = strings.TrimRight(industryName, ",")
  1096. industrialManagementId = strings.TrimRight(industrialManagementId, ",")
  1097. //}
  1098. keyword1 := fmt.Sprint("【", industryName, "】有报告发布/更新")
  1099. keyword2 := articleInfo.Title
  1100. keyword3 := time.Now().Format(utils.FormatDateTime)
  1101. keyword4 := articleInfo.Abstract
  1102. sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1103. var appointmentList []*models.CygxAppointment
  1104. var mapOpenidSubjectId = make(map[int]string) //预约相关纪要的用户
  1105. if sliceSubjectId != "" {
  1106. appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1107. if e != nil {
  1108. err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1109. return
  1110. }
  1111. var userIds []string
  1112. if len(appointmentList) > 0 {
  1113. for _, v := range appointmentList {
  1114. userIds = append(userIds, strconv.Itoa(v.UserId))
  1115. }
  1116. userIdstr := strings.Join(userIds, ",")
  1117. openIdLists, e := models.GetOpenIdByUserIds(userIdstr)
  1118. if e != nil {
  1119. err = errors.New("GetOpenIdByUserIds, Err: " + e.Error())
  1120. return
  1121. }
  1122. keyword1 = industryName
  1123. var openIdArr []string
  1124. for _, item := range openIdLists {
  1125. if mapOpenidRefuset[item.UserId] != "" {
  1126. continue // 拒绝消息推送的用户不接收模版消息
  1127. }
  1128. openIdArr = append(openIdArr, item.OpenId)
  1129. mapOpenidSubjectId[item.UserId] = "_"
  1130. }
  1131. go SendWxMsgWithArticleUpdateList(industryName, keyword2, keyword3, keyword4, openIdArr, articleId)
  1132. }
  1133. }
  1134. var openIdArr2 []string
  1135. for _, item := range openidPowerList {
  1136. if mapOpenidRefuset[item.UserId] != "" || mapOpenidSubjectId[item.UserId] != "" {
  1137. continue // 拒绝消息推送的用户不接收模版消息
  1138. }
  1139. openIdArr2 = append(openIdArr2, item.OpenId)
  1140. }
  1141. go SendWxMsgWithArticleUpdateList(keyword1, keyword2, keyword3, keyword4, openIdArr2, articleId)
  1142. }
  1143. ////获取关注这个文章对应产业的用户的 openid
  1144. //mapOpenidFllow := make(map[int]string)
  1145. //if chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID_CHART && chartPermissionId != utils.ZHOU_QI_ID {
  1146. // openidFllowListMobile, e := models.GetCygxUserFllowOpenid(articleId)
  1147. // if e != nil {
  1148. // err = errors.New("GetCygxUserFllowOpenid, Err: " + e.Error())
  1149. // return
  1150. // }
  1151. //
  1152. // var mobileArrFllow []string
  1153. // for _, v := range openidFllowListMobile {
  1154. // mobileArrFllow = append(mobileArrFllow, v.Mobile)
  1155. // }
  1156. //
  1157. // openidFllowList, e := models.GetWxOpenIdByMobileSliceList(mobileArrFllow)
  1158. // if e != nil {
  1159. // err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error())
  1160. // return
  1161. // }
  1162. //
  1163. // for _, v := range openidFllowList {
  1164. // mapOpenidFllow[v.UserId] = v.OpenId
  1165. // }
  1166. //}
  1167. //
  1168. ////获取提交过推送规则的用户的 openid
  1169. //mapUserIdChooseSend := make(map[int]int)
  1170. //mapUserIdChooseSendTypeNoPermission := make(map[int]int)
  1171. //chooseSendtList, e := models.GetCygxXzsChooseSend()
  1172. //if e != nil {
  1173. // err = errors.New("GetCygxXzsChooseSend, Err: " + e.Error())
  1174. // return
  1175. //}
  1176. //for _, v := range chooseSendtList {
  1177. // mapUserIdChooseSend[v.UserId] = v.UserId
  1178. // if v.IsRefuse == 1 {
  1179. // continue
  1180. // }
  1181. // //获取选择主客观赛道的用户
  1182. // if reportMapDetail.PermissionType == 1 {
  1183. // if v.IsSubjective == 1 {
  1184. // mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1185. // }
  1186. // } else {
  1187. // if v.IsObjective == 1 {
  1188. // mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1189. // }
  1190. // }
  1191. //}
  1192. ////已经推送了的openid
  1193. //mapOpenidPushed := make(map[int]string)
  1194. //
  1195. //keyword2 := articleInfo.Title
  1196. //keyword3 := time.Now().Format(utils.FormatDateTime)
  1197. //keyword4 := articleInfo.Abstract
  1198. //mapAlreadySend := make(map[int]int)
  1199. //
  1200. //sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1201. //var appointmentList []*models.CygxAppointment
  1202. //if sliceSubjectId != "" {
  1203. // appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1204. // if e != nil {
  1205. // err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1206. // return
  1207. // }
  1208. // //var userIds []string
  1209. // //if len(appointmentList) > 0 {
  1210. // // for _, v := range appointmentList {
  1211. // // //fmt.Println("mapActivityUserId:", v.UserId)
  1212. // // userIds = append(userIds, strconv.Itoa(v.UserId))
  1213. // // mapActivityUserId[v.UserId] += v.ActivityName + ","
  1214. // // }
  1215. // // userIdstr := strings.Join(userIds, ",")
  1216. // // openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
  1217. // // if err != nil {
  1218. // // fmt.Println("GetOpenIdByUserIds Err:", err.Error())
  1219. // // return err
  1220. // // }
  1221. // // for _, item := range openIdLists {
  1222. // // //first := "您预约的调研,有关联的纪要发布/更新了"
  1223. // // //keyword1 := industryName
  1224. // // openIditem := new(models.OpenIdList)
  1225. // // openIditem.OpenId = item.OpenId
  1226. // // openIditem.UserId = item.UserId
  1227. // // if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1228. // // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1229. // // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1230. // // fmt.Println("AlreadySend:", openIditem.UserId)
  1231. // // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1232. // // }
  1233. // // }
  1234. // //}
  1235. //}
  1236. ////如果是策略就按照策略的推送方式来写
  1237. //if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME || reportMapDetail.ChartPermissionName == utils.GU_SHOU_NAME {
  1238. // //获取提交过推送规则的用户的 openid
  1239. // mapUserFllowCeLue := make(map[int]string)
  1240. // userFllowCeLueList, e := models.GetCygxUserFllowCeLueOpenid(articleInfo.CategoryId)
  1241. // if e != nil {
  1242. // err = errors.New("GetCygxUserFllowCeLueOpenid, Err: " + e.Error())
  1243. // return
  1244. // }
  1245. // for _, v := range userFllowCeLueList {
  1246. // mapUserFllowCeLue[v.UserId] = v.OpenId
  1247. // }
  1248. // for k, v := range mapOpenidPower {
  1249. // if mapOpenidPushed[k] != "" {
  1250. // continue
  1251. // }
  1252. // openIditem := new(models.OpenIdList)
  1253. // openIditem.UserId = k
  1254. // openIditem.OpenId = v
  1255. // first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1256. // keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1257. // mapActivityUserId := make(map[int]string)
  1258. // if articleInfo.ReportType == 2 {
  1259. // sliceSubjectId, _ = models.GetSubjectIds(articleId)
  1260. // if sliceSubjectId != "" {
  1261. // appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1262. // if e != nil {
  1263. // err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1264. // return
  1265. // }
  1266. // var userIds []string
  1267. // if len(appointmentList) > 0 {
  1268. // for _, v := range appointmentList {
  1269. // //fmt.Println("mapActivityUserId:", v.UserId)
  1270. // userIds = append(userIds, strconv.Itoa(v.UserId))
  1271. // mapActivityUserId[v.UserId] += v.ActivityName + ","
  1272. // }
  1273. // userIdstr := strings.Join(userIds, ",")
  1274. // openIdLists, e := models.GetOpenIdByUserIds(userIdstr)
  1275. // appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1276. // if e != nil {
  1277. // err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1278. // return
  1279. // }
  1280. // for _, item := range openIdLists {
  1281. // first = "您预约的调研,有关联的纪要发布/更新了"
  1282. // keyword1 = industryName
  1283. // openIditem = new(models.OpenIdList)
  1284. // openIditem.OpenId = item.OpenId
  1285. // openIditem.UserId = item.UserId
  1286. // if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1287. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1288. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1289. // fmt.Println("AlreadySend:", openIditem.UserId)
  1290. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1291. // }
  1292. // }
  1293. // }
  1294. // }
  1295. // }
  1296. // _, ok := mapAlreadySend[openIditem.UserId]
  1297. // //如果有权限而且小助手没有提交过信息的 就做正常推送
  1298. // if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1299. // fmt.Println("1:", articleId)
  1300. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1301. // }
  1302. // //如果小助手勾选了对应的权限信息 就做正常推送
  1303. // if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" && !ok {
  1304. // fmt.Println("2:", articleId)
  1305. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1306. // }
  1307. // }
  1308. //} else {
  1309. // for k, v := range mapOpenidPower {
  1310. // if mapOpenidPushed[k] != "" {
  1311. // continue
  1312. // }
  1313. // mapUserIdChooseSendType := make(map[int]int)
  1314. // for _, vS := range chooseSendtList {
  1315. // if vS.IsRefuse == 1 {
  1316. // continue
  1317. // }
  1318. // //获取选择主客观赛道的用户
  1319. // if reportMapDetail.PermissionType == 1 {
  1320. // if vS.IsSubjective == 1 {
  1321. // mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1322. // }
  1323. // } else if reportMapDetail.PermissionType == 2 {
  1324. // if vS.IsObjective == 1 {
  1325. // mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1326. // }
  1327. // } else {
  1328. // if vS.IsSubjective == 1 || vS.IsObjective == 1 {
  1329. // mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1330. // }
  1331. // }
  1332. // }
  1333. // openIditem := new(models.OpenIdList)
  1334. // openIditem.UserId = k
  1335. // openIditem.OpenId = v
  1336. // first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1337. // keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1338. // mapActivityUserId := make(map[int]string)
  1339. // if articleInfo.ReportType == 2 {
  1340. // keyword1 = fmt.Sprint("【", industryName, "】有报告发布/更新")
  1341. // //sliceSubjectId, _ = models.GetSubjectIds(articleId)
  1342. // if sliceSubjectId != "" {
  1343. // //appointmentList, e = models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1344. // //if e != nil {
  1345. // // err = errors.New("GetCygxAppointmentSummaryBySubjectId, Err: " + e.Error())
  1346. // // return
  1347. // //}
  1348. // var userIds []string
  1349. // if len(appointmentList) > 0 {
  1350. // for _, v := range appointmentList {
  1351. // //fmt.Println("mapActivityUserId:", v.UserId)
  1352. // userIds = append(userIds, strconv.Itoa(v.UserId))
  1353. // mapActivityUserId[v.UserId] += v.ActivityName + ","
  1354. // }
  1355. // userIdstr := strings.Join(userIds, ",")
  1356. // openIdLists, e := models.GetOpenIdByUserIds(userIdstr)
  1357. // if e != nil {
  1358. // err = errors.New("GetOpenIdByUserIds, Err: " + e.Error())
  1359. // return
  1360. // }
  1361. // for _, item := range openIdLists {
  1362. // //first := "您预约的调研,有关联的纪要发布/更新了"
  1363. // //keyword1 := industryName
  1364. // openIditem := new(models.OpenIdList)
  1365. // openIditem.OpenId = item.OpenId
  1366. // openIditem.UserId = item.UserId
  1367. // if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1368. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1369. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1370. // fmt.Println("AlreadySend:", openIditem.UserId)
  1371. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1372. // }
  1373. // }
  1374. // }
  1375. // }
  1376. // }
  1377. //
  1378. // //如果有权限而且小助手没有提交过信息的 就做正常推送
  1379. // _, ok := mapAlreadySend[openIditem.UserId]
  1380. // if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1381. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1382. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1383. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1384. // }
  1385. // //如果小助手勾选了对应的权限信息 就做正常推送
  1386. // if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" && mapUserIdChooseSendType[openIditem.UserId] > 0 && !ok {
  1387. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1388. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1389. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1390. // }
  1391. // }
  1392. //}
  1393. utils.Rc.Put(cacheKey, articleId, time.Hour*12)
  1394. return
  1395. }
  1396. // GetSpecialArticleDetailUserPower 处理用户查看专项调研文章详情的权限
  1397. func GetSpecialArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
  1398. userType, _, e := GetUserType(user.CompanyId)
  1399. if e != nil {
  1400. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  1401. return
  1402. }
  1403. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  1404. if userType == 1 || userType == 2 {
  1405. havePower = true
  1406. return
  1407. }
  1408. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  1409. if e != nil {
  1410. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1411. return
  1412. }
  1413. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  1414. if e != nil {
  1415. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  1416. return
  1417. }
  1418. if reportMapDetail == nil {
  1419. err = errors.New("GetdetailByCategoryIdP,获取详情失败, ")
  1420. return
  1421. }
  1422. fmt.Println(permissionStr)
  1423. //如果没有对应的升级权限,则返回
  1424. if !strings.Contains(permissionStr, reportMapDetail.ChartPermissionName) {
  1425. return
  1426. } else {
  1427. havePower = true
  1428. }
  1429. return
  1430. }
  1431. // HandleArticleCategoryImg 预处理文章的封面图片
  1432. func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeArticle, err error) {
  1433. //研选的五张图片
  1434. detailResearch, e := models.GetConfigByCode("category_research_img_url")
  1435. if e != nil {
  1436. err = errors.New("获取研选的五张图片失败" + e.Error())
  1437. return
  1438. }
  1439. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  1440. //对应分类的所图片
  1441. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  1442. if err != nil {
  1443. err = errors.New("获取对应分类的所图片失败" + err.Error())
  1444. return
  1445. }
  1446. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  1447. mapCategoryUrl := make(map[string]string)
  1448. var categoryId string
  1449. var imgUrlChart string
  1450. for _, v := range categoryUrlList {
  1451. vslice := strings.Split(v, "_")
  1452. categoryId = vslice[0]
  1453. imgUrlChart = vslice[len(vslice)-1]
  1454. mapCategoryUrl[categoryId] = imgUrlChart
  1455. }
  1456. mapChartPerssion := make(map[string]string)
  1457. reportMappingList, err := models.GetReportMappingStrategyAll()
  1458. if err != nil {
  1459. err = errors.New("GetReportMappingStrategyAll err" + err.Error())
  1460. return
  1461. }
  1462. for _, v := range reportMappingList {
  1463. mapChartPerssion[strconv.Itoa(v.CategoryId)] = v.ChartPermissionName
  1464. }
  1465. for k, v := range list {
  1466. list[k].Abstract, _ = GetReportContentTextSub(v.Abstract)
  1467. item := list[k]
  1468. //如果文章一开始的内容是图片,优先展示第一张图片
  1469. if list[k].Annotation == "" {
  1470. imgurl, _ := FixArticleImgUrl(html.UnescapeString(list[k].Body))
  1471. if imgurl != "" {
  1472. list[k].BodyHtml = imgurl
  1473. }
  1474. }
  1475. //newBody, _ := GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
  1476. list[k].Annotation = ArticleAnnotation(item)
  1477. list[k].Body = ""
  1478. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  1479. list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
  1480. //如果是研选系列的任意取五张图片的中的一张
  1481. if v.CategoryId == "0" || v.ArticleId > utils.SummaryArticleId {
  1482. knum := v.ArticleId % 5
  1483. list[k].ImgUrlPc = researchList[knum]
  1484. } else {
  1485. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  1486. }
  1487. list[k].ArticleResponse = 4 // 默认展示核心观点
  1488. //ArticleResponse int `description:"报告类型 0:啥也不是,1研选报告,2:研选纪要,3:研选沙龙,4;核心观点"`
  1489. if list[k].ArticleId >= utils.SummaryArticleId {
  1490. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  1491. list[k].IsNeedJump = true
  1492. list[k].ArticleResponse = 1
  1493. //if v.IsReport == 1 {
  1494. // list[k].ArticleResponse = 1
  1495. //} else if v.ArticleTypeName == "纪要" {
  1496. // list[k].ArticleResponse = 2
  1497. //} else if v.ArticleTypeName == "观点" {
  1498. // list[k].ArticleResponse = 3
  1499. //} else if v.ArticleTypeName == "沙龙" {
  1500. // list[k].ArticleResponse = 3
  1501. //} else if v.ArticleTypeName == "路演精华" {
  1502. // list[k].ArticleResponse = 1
  1503. //}
  1504. }
  1505. list[k].Source = 1
  1506. //添加行业默认图片
  1507. if v.ImgUrlPc == "" {
  1508. if v.ChartPermissionName == utils.YI_YAO_NAME {
  1509. list[k].ImgUrlPc = utils.YI_YAO_OTHER_IMG
  1510. } else if v.ChartPermissionName == utils.XIAO_FEI_NAME {
  1511. list[k].ImgUrlPc = utils.XIAO_FEI_OTHER_IMG
  1512. } else if v.ChartPermissionName == utils.KE_JI_NAME {
  1513. list[k].ImgUrlPc = utils.KE_JI_OTHER_IMG
  1514. } else if v.ChartPermissionName == utils.ZHI_ZAO_NAME {
  1515. list[k].ImgUrlPc = utils.ZHI_ZAO_OTHER_IMG
  1516. }
  1517. }
  1518. //是不是研选报告
  1519. if v.ArticleTypeId > 0 {
  1520. list[k].IsResearch = true
  1521. }
  1522. }
  1523. articleIds := make([]int, 0)
  1524. for i := range list {
  1525. articleIds = append(articleIds, list[i].ArticleId)
  1526. }
  1527. articleMapPv := GetArticleHistoryByArticleId(articleIds) //文章Pv
  1528. // 报告关联产业信息
  1529. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  1530. if len(articleIds) > 0 {
  1531. var industryCond string
  1532. var industryPars []interface{}
  1533. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1534. industryPars = append(industryPars, articleIds)
  1535. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  1536. if e != nil {
  1537. err = errors.New("GetIndustrialListByarticleId" + e.Error())
  1538. return
  1539. }
  1540. for i := range industryList {
  1541. v := industryList[i]
  1542. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  1543. ArticleId: v.ArticleId,
  1544. IndustrialManagementId: v.IndustrialManagementId,
  1545. IndustryName: v.IndustryName,
  1546. ChartPermissionId: v.ChartPermissionId,
  1547. })
  1548. }
  1549. }
  1550. for k, v := range list {
  1551. if len(industryMap[v.ArticleId]) > 0 {
  1552. list[k].List = industryMap[v.ArticleId]
  1553. } else {
  1554. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  1555. }
  1556. v.Pv = articleMapPv[v.ArticleId]
  1557. if v.Pv > 999 {
  1558. list[k].Pv = 999
  1559. }
  1560. }
  1561. if len(list) == 0 {
  1562. list = make([]*models.HomeArticle, 0)
  1563. }
  1564. items = list
  1565. return
  1566. }
  1567. // 处理核心观点的展示规则
  1568. func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
  1569. if item.ArticleId >= utils.SummaryArticleId {
  1570. item.Annotation = YxArticleAnnotation(item)
  1571. }
  1572. if item.Annotation != "" {
  1573. annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  1574. annotation = strings.Replace(item.Annotation, "&nbsp;", "", -1)
  1575. } else {
  1576. return
  1577. }
  1578. bodyText, _ := GetReportContentTextSubNew(annotation)
  1579. if bodyText == "" {
  1580. return
  1581. }
  1582. if annotation != "" {
  1583. annotation = html.UnescapeString(annotation)
  1584. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1585. docText := doc.Text()
  1586. mapDoc := make(map[int]string)
  1587. var mapSort []int
  1588. p := doc.Find("p")
  1589. p.Each(func(tk int, pd *goquery.Selection) {
  1590. pdText := pd.Text()
  1591. pdText = strings.Replace(pdText, " ", "", -1)
  1592. if pdText != "" {
  1593. textLen := strings.Index(docText, pdText)
  1594. mapDoc[(strings.Index(docText, pdText))] = pdText
  1595. mapSort = append(mapSort, textLen)
  1596. }
  1597. })
  1598. li := doc.Find("li")
  1599. li.Each(func(tk int, li *goquery.Selection) {
  1600. liText := li.Text()
  1601. liText = strings.Replace(liText, " ", "", -1)
  1602. if liText != "" {
  1603. textLen := strings.Index(docText, liText)
  1604. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1605. mapSort = append(mapSort, textLen)
  1606. }
  1607. })
  1608. ul := doc.Find("ul")
  1609. ul.Each(func(tk int, ul *goquery.Selection) {
  1610. ulText := ul.Text()
  1611. ulText = strings.Replace(ulText, " ", "", -1)
  1612. if ulText != "" {
  1613. textLen := strings.Index(docText, ulText)
  1614. mapDoc[(strings.Index(docText, ulText))] = ulText
  1615. mapSort = append(mapSort, textLen)
  1616. }
  1617. })
  1618. if len(mapSort) == 0 {
  1619. return
  1620. } else {
  1621. //排序
  1622. sort.Ints(mapSort)
  1623. var annotationHtml string
  1624. for _, vSort := range mapSort {
  1625. for k, v := range mapDoc {
  1626. if k == vSort && v != "" {
  1627. annotationHtml += v + "<br>"
  1628. }
  1629. }
  1630. }
  1631. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1632. annotationHtml = "<p>" + annotationHtml + "</p>"
  1633. annotation = annotationHtml
  1634. }
  1635. }
  1636. return
  1637. }
  1638. // 处理核心观点的展示规则
  1639. func AnnotationHtml(bodyText string) (annotation string) {
  1640. if bodyText == "" {
  1641. return
  1642. }
  1643. annotation = bodyText
  1644. annotation = html.UnescapeString(annotation)
  1645. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1646. docText := doc.Text()
  1647. mapDoc := make(map[int]string)
  1648. var mapSort []int
  1649. p := doc.Find("p")
  1650. p.Each(func(tk int, pd *goquery.Selection) {
  1651. pdText := pd.Text()
  1652. //pdText = strings.Replace(pdText, " ", "", -1)
  1653. if pdText != "" {
  1654. textLen := strings.Index(docText, pdText)
  1655. mapDoc[(strings.Index(docText, pdText))] = pdText
  1656. mapSort = append(mapSort, textLen)
  1657. }
  1658. })
  1659. li := doc.Find("li")
  1660. li.Each(func(tk int, li *goquery.Selection) {
  1661. liText := li.Text()
  1662. liText = strings.Replace(liText, " ", "", -1)
  1663. if liText != "" {
  1664. textLen := strings.Index(docText, liText)
  1665. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1666. mapSort = append(mapSort, textLen)
  1667. }
  1668. })
  1669. ul := doc.Find("ul")
  1670. ul.Each(func(tk int, ul *goquery.Selection) {
  1671. ulText := ul.Text()
  1672. ulText = strings.Replace(ulText, " ", "", -1)
  1673. if ulText != "" {
  1674. textLen := strings.Index(docText, ulText)
  1675. mapDoc[(strings.Index(docText, ulText))] = ulText
  1676. mapSort = append(mapSort, textLen)
  1677. }
  1678. })
  1679. section := doc.Find("section")
  1680. section.Each(func(tk int, section *goquery.Selection) {
  1681. sectionText := section.Text()
  1682. sectionText = strings.Replace(sectionText, " ", "", -1)
  1683. if sectionText != "" {
  1684. textLen := strings.Index(docText, sectionText)
  1685. mapDoc[(strings.Index(docText, sectionText))] = sectionText
  1686. mapSort = append(mapSort, textLen)
  1687. }
  1688. })
  1689. if len(mapSort) == 0 {
  1690. return
  1691. } else {
  1692. //排序
  1693. sort.Ints(mapSort)
  1694. var annotationHtml string
  1695. for _, vSort := range mapSort {
  1696. for k, v := range mapDoc {
  1697. if k == vSort && v != "" {
  1698. annotationHtml += v + "<br>"
  1699. }
  1700. }
  1701. }
  1702. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1703. annotationHtml = "<p>" + annotationHtml + "</p>"
  1704. annotation = annotationHtml
  1705. }
  1706. return
  1707. }
  1708. // 处理产品内测展示规则
  1709. func ProductInteriorHtml(bodyText string) (annotation string) {
  1710. if bodyText == "" {
  1711. return
  1712. }
  1713. sliceBody := strings.Split(bodyText, "</p>")
  1714. annotation, _ = GetReportContentTextSub(sliceBody[0])
  1715. return
  1716. }
  1717. // 解析研选内容中的核心观点
  1718. func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
  1719. //如果不规范,就获取内容主体
  1720. if strings.Count(article.Body, "<hr") == 0 {
  1721. //如果内容不规范而且,还有图片,就把核心观点置空
  1722. if article.BodyHtml != "" {
  1723. return
  1724. }
  1725. annotation, _ = GetReportContentTextSub(article.Body)
  1726. return
  1727. }
  1728. body := strings.ReplaceAll(article.Body, "<strong>", "")
  1729. body = strings.ReplaceAll(body, "</strong>", "")
  1730. body = strings.ReplaceAll(body, "</ol>", "</div>")
  1731. body = strings.ReplaceAll(body, "<ol>", "<div>")
  1732. body = strings.ReplaceAll(body, "</li>", "</p>")
  1733. body = strings.ReplaceAll(body, "<li>", "<p>")
  1734. re, _ := regexp.Compile("<strong.*?>")
  1735. body = re.ReplaceAllString(body, "")
  1736. reLi, _ := regexp.Compile("<li.*?>")
  1737. body = reLi.ReplaceAllString(body, "")
  1738. var plus int
  1739. coreIndex := strings.Index(body, "核心观点:")
  1740. plus = 15
  1741. if coreIndex == -1 {
  1742. coreIndex = strings.Index(body, "核心观点:")
  1743. plus = 13
  1744. }
  1745. if coreIndex == -1 {
  1746. coreIndex = strings.Index(body, "核心观点")
  1747. plus = 12
  1748. }
  1749. if coreIndex == -1 {
  1750. coreIndex = strings.Index(body, "核心结论:")
  1751. plus = 15
  1752. }
  1753. if coreIndex == -1 {
  1754. coreIndex = strings.Index(body, "核心结论:")
  1755. plus = 13
  1756. }
  1757. if coreIndex == -1 {
  1758. coreIndex = strings.Index(body, "核心结论")
  1759. plus = 12
  1760. }
  1761. endIndex := strings.Index(body, "<hr")
  1762. if coreIndex != -1 && endIndex != -1 {
  1763. body = body[coreIndex+plus : endIndex]
  1764. }
  1765. annotation = body
  1766. return
  1767. }
  1768. // 通过接解析带有Md5的文章链接获取文章ID
  1769. func GetReportLinkToArticleid(reportLink string) (articleId int, err error) {
  1770. defer func() {
  1771. if err != nil {
  1772. go utils.SendAlarmMsg("通过接解析带有Md5的文章链接获取文章ID失败"+err.Error(), 2)
  1773. }
  1774. }()
  1775. var artMd5 string
  1776. //处理Md5的
  1777. strnum1 := strings.Index(reportLink, "id=")
  1778. if strnum1 > 0 {
  1779. sliceId := strings.Split(reportLink, "id=")
  1780. if len(sliceId) > 1 {
  1781. reportLink = sliceId[1]
  1782. sliceMd5Id := strings.Split(reportLink, "&")
  1783. artMd5 = sliceMd5Id[0]
  1784. }
  1785. if artMd5 != "" {
  1786. detail, errArt := models.GetArticleDetailByIdMd5(artMd5)
  1787. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  1788. err = errArt
  1789. return
  1790. }
  1791. if detail != nil {
  1792. articleId = detail.ArticleId
  1793. }
  1794. }
  1795. } else {
  1796. //处理活动的
  1797. linkList := strings.Split(reportLink, "/")
  1798. if linkList[len(linkList)-1] != "" {
  1799. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  1800. if linkArticleId > 0 {
  1801. articleInfo, errArt := models.GetArticleDetailById(linkArticleId)
  1802. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  1803. err = errArt
  1804. return
  1805. }
  1806. if articleInfo != nil {
  1807. articleId = articleInfo.ArticleId
  1808. }
  1809. }
  1810. }
  1811. }
  1812. return
  1813. }
  1814. // GetArticleStockMap 获取个股标签所对应的文章ID
  1815. func GetArticleStockMap() (mapResp map[string]int, err error) {
  1816. defer func() {
  1817. if err != nil {
  1818. go utils.SendAlarmMsg("获取个股标签所对应的文章ID失败"+err.Error(), 2)
  1819. }
  1820. }()
  1821. list, err := models.GetArticleStock()
  1822. if err != nil && err.Error() != utils.ErrNoRow() {
  1823. return
  1824. }
  1825. mapResp = make(map[string]int, 0)
  1826. if len(list) > 0 {
  1827. //一对一精准匹配
  1828. for _, v := range list {
  1829. sliceSubjects := strings.Split(v.Stock, "/")
  1830. if len(sliceSubjects) > 0 {
  1831. for _, vSubject := range sliceSubjects {
  1832. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  1833. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  1834. subject := sliceXiahuaxian[0]
  1835. mapResp[subject] = v.ArticleId
  1836. }
  1837. }
  1838. }
  1839. }
  1840. return
  1841. }
  1842. // GetAiQianYanArtilceList 获取AI前沿几篇文章
  1843. func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.ReportArticle, total int, err error) {
  1844. defer func() {
  1845. if err != nil {
  1846. go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
  1847. }
  1848. }()
  1849. var condition string
  1850. var pars []interface{}
  1851. condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1 ORDER BY publish_date DESC `
  1852. articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
  1853. if e != nil {
  1854. err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
  1855. return
  1856. }
  1857. total, e = models.GetCygxArticleCount(condition, pars)
  1858. if e != nil {
  1859. err = errors.New("GetCygxArticleCount, Err: " + e.Error())
  1860. return
  1861. }
  1862. for _, v := range articleList {
  1863. item := new(models.ReportArticle)
  1864. item.ArticleId = v.ArticleId
  1865. item.Title = v.Title
  1866. item.Abstract = v.Abstract
  1867. item.Annotation = v.Annotation
  1868. item.PublishDate = v.PublishDate
  1869. item.Resource = 1
  1870. item.CategoryId = strconv.Itoa(v.CategoryId)
  1871. item.Body = v.Body
  1872. items = append(items, item)
  1873. }
  1874. return
  1875. }
  1876. // 获取文章内部图表的第一张封面图
  1877. func GetArticleCoverByChartFirst(body string) (cover string) {
  1878. var err error
  1879. defer func() {
  1880. if err != nil {
  1881. fmt.Println(err)
  1882. go utils.SendAlarmMsg("获取文章内部图表的第一张封面图失败,Err:"+err.Error()+body, 3)
  1883. }
  1884. }()
  1885. var chartUrl string
  1886. var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
  1887. match := hrefRegexp.FindAllString(body, -1)
  1888. if match != nil {
  1889. for _, v := range match {
  1890. if strings.Contains(v, "charts/display") {
  1891. chartUrl = v
  1892. break
  1893. }
  1894. }
  1895. }
  1896. if chartUrl != "" {
  1897. urlSlice := strings.Split(chartUrl, "/")
  1898. lenurlSlice := len(urlSlice)
  1899. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  1900. if sourceId == 0 {
  1901. sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
  1902. }
  1903. if sourceId == 0 {
  1904. err = errors.New("新的图标链接无法解析" + chartUrl)
  1905. return
  1906. }
  1907. chartUrlApi := utils.ApiUrl + "charts/" + strconv.Itoa(sourceId)
  1908. authorization := utils.ApiAuthorization
  1909. body, e := PublicGetDate(chartUrlApi, authorization)
  1910. if e != nil {
  1911. err = errors.New("PublicGetDate" + err.Error())
  1912. return
  1913. }
  1914. var resultDate models.ChartResultDetailApi
  1915. e = json.Unmarshal(body, &resultDate)
  1916. if e != nil {
  1917. err = errors.New(" json.Unmarshal" + err.Error())
  1918. }
  1919. cover = resultDate.Data.Cover
  1920. }
  1921. return
  1922. }
  1923. // GetYxArticleIdMap 获取研选文章ID
  1924. func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
  1925. var err error
  1926. defer func() {
  1927. if err != nil {
  1928. go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
  1929. }
  1930. }()
  1931. var condition string
  1932. var pars []interface{}
  1933. condition = ` AND article_type_id > 0 `
  1934. if len(articleIds) > 0 {
  1935. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1936. pars = append(pars, articleIds)
  1937. }
  1938. articleList, e := models.GetArticleList(condition, pars)
  1939. if e != nil {
  1940. err = errors.New("GetArticleList, Err: " + e.Error())
  1941. return
  1942. }
  1943. mapResp = make(map[int]bool, 0)
  1944. for _, v := range articleList {
  1945. mapResp[v.ArticleId] = true
  1946. }
  1947. return
  1948. }
  1949. // GetUserArticleHistoryRecord 获取用户已经阅读的文章ID
  1950. func GetUserArticleHistoryRecord(user *models.WxUserItem) (articleIdMap map[int]bool, err error) {
  1951. var condition string
  1952. var pars []interface{}
  1953. condition = " AND user_id = ? "
  1954. pars = append(pars, user.UserId)
  1955. articleIdMap = make(map[int]bool, 0)
  1956. list, err := models.GetArticleHistoryRecord(condition, pars)
  1957. if err != nil && err.Error() != utils.ErrNoRow() {
  1958. return
  1959. }
  1960. for _, v := range list {
  1961. articleIdMap[v.ArticleId] = true
  1962. }
  1963. return
  1964. }
  1965. // GetUserArticleHistoryIndustrialNewPublishDate 获取产业关联的的文章用户是否阅读
  1966. func GetUserArticleHistoryIndustrialNewPublishDate(user *models.WxUserItem, industrialIdArr []int, articleTypeIds, resource string) (mapIndustrialArticleHistory map[int]bool, err error) {
  1967. if len(industrialIdArr) == 0 {
  1968. return
  1969. }
  1970. var condition string
  1971. var pars []interface{}
  1972. articleIdMap, err := GetUserArticleHistoryRecord(user)
  1973. if err != nil {
  1974. return
  1975. }
  1976. if resource == utils.REOURCE_YX {
  1977. condition = ` AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) `
  1978. } else {
  1979. condition = ` AND a.article_type_id = 0 AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId)
  1980. }
  1981. var startTime time.Time
  1982. if utils.StrTimeToTime(utils.OnlineTime).After(user.CreatedTime) {
  1983. startTime = utils.StrTimeToTime(utils.OnlineTime)
  1984. } else {
  1985. startTime = user.CreatedTime
  1986. }
  1987. condition += ` AND mg.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `) AND a.publish_date > ? `
  1988. pars = append(pars, industrialIdArr, startTime)
  1989. list, err := models.GetCygxIndustrialArticleGroupManagement(condition, pars)
  1990. if err != nil {
  1991. return
  1992. }
  1993. mapIndustrialArticle := make(map[int][]*models.CygxIndustrialArticleGroupManagementResp)
  1994. //mapIndustrialArticleMax := make(map[int]int, 0)
  1995. mapIndustrialArticleHistory = make(map[int]bool, 0)
  1996. //mapIndustrialArticleMaxTime := make(map[int]time.Time)
  1997. for _, v := range list {
  1998. item := new(models.CygxIndustrialArticleGroupManagementResp)
  1999. item.IndustrialManagementId = v.IndustrialManagementId
  2000. item.ArticleId = v.ArticleId
  2001. item.PublishDate = v.PublishDate
  2002. mapIndustrialArticle[v.IndustrialManagementId] = append(mapIndustrialArticle[v.IndustrialManagementId], item)
  2003. }
  2004. for k, v := range mapIndustrialArticle {
  2005. for _, item := range v {
  2006. if !articleIdMap[item.ArticleId] {
  2007. mapIndustrialArticleHistory[k] = true
  2008. }
  2009. }
  2010. }
  2011. return
  2012. }