industrial_management.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "golang.org/x/net/html"
  8. "hongze/hongze_cygx/models"
  9. "hongze/hongze_cygx/utils"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. // 修改标签状态
  15. func UpdateIndustrialManagementLabel(cont context.Context) (err error) {
  16. defer func() {
  17. if err != nil {
  18. fmt.Println("修改失败,Err:", err.Error())
  19. }
  20. }()
  21. fmt.Println("修改状态0000")
  22. go models.UpdateIndustrialIsNewLabel()
  23. list, err := models.GetIndustrialMorethan10()
  24. if err != nil {
  25. return err
  26. }
  27. if len(list) == 0 {
  28. return
  29. }
  30. var idStr string
  31. for _, v := range list {
  32. idStr += v.IndustrialManagementId + ","
  33. }
  34. idStr = strings.TrimRight(idStr, ",")
  35. go models.UpdateIndustrialIsDeepLabel(idStr)
  36. //fmt.Println(idStr)
  37. //go models.UpdateActivitySattusToComplete()
  38. fmt.Println("修改状态完成")
  39. return
  40. }
  41. // 修改状态
  42. func UpdateIndustrialManagementSubjectNnames() (err error) {
  43. defer func() {
  44. if err != nil {
  45. fmt.Println("修改失败,Err:", err.Error())
  46. }
  47. }()
  48. fmt.Println("修改产业关联标的")
  49. list, err := models.GetIndustrialManagementIds()
  50. if err != nil {
  51. return err
  52. }
  53. for _, v := range list {
  54. //fmt.Println(v.IndustrialManagementId)
  55. var nameSub string
  56. listSub, errdSub := models.GetcygxIndustrialSubject(v.IndustrialManagementId)
  57. if errdSub != nil {
  58. return errdSub
  59. }
  60. for _, v2 := range listSub {
  61. fmt.Println(v2.SubjectName)
  62. nameSub += v2.SubjectName + ","
  63. }
  64. nameSub += v.IndustryName
  65. go models.UpdateIndustrialManagementSubjectNames(nameSub, v.IndustrialManagementId)
  66. }
  67. if len(list) == 0 {
  68. return
  69. }
  70. fmt.Println("修改状态完成")
  71. return
  72. }
  73. func ChageIndustrialArticleNum(cont context.Context) (err error) {
  74. IndustrialHzArticleNumUpdate()
  75. IndustrialYxArticleNumUpdate()
  76. IndustrialActivityNumUpdate()
  77. return
  78. }
  79. //func init() {
  80. // IndustrialHzArticleNumUpdate()
  81. // IndustrialYxArticleNumUpdate()
  82. // IndustrialActivityNumUpdate()
  83. //}
  84. // 更改弘则对应的报告关联产业近一个月的阅读量
  85. func IndustrialHzArticleNumUpdate() (err error) {
  86. defer func() {
  87. if err != nil {
  88. //fmt.Println(err)
  89. go utils.SendAlarmMsg("更改弘则对应的报告关联产业近一个月的阅读量失败"+err.Error(), 2)
  90. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"更改弘则对应的报告关联产业近一个月的阅读量失败失败提醒", err.Error(), utils.EmailSendToUsers)
  91. }
  92. }()
  93. err = models.UpdateIndustrialManagementArtticleReadNum()
  94. if err != nil {
  95. return
  96. }
  97. articleTypeIds, err := GetYanXuanArticleTypeIds()
  98. if err != nil {
  99. return
  100. }
  101. var condition string
  102. if articleTypeIds == "" {
  103. return
  104. }
  105. condition = ` AND a.article_type_id NOT IN (` + articleTypeIds + `) `
  106. list, err := models.GetIndustrialManagementArtHistoryCount(condition)
  107. if err != nil {
  108. return
  109. }
  110. for _, v := range list {
  111. err = models.UpdateIndustrialManagementArtReadNum(v.Count, v.IndustrialManagementId)
  112. if err != nil {
  113. return
  114. }
  115. }
  116. return err
  117. }
  118. // 更改研选对应的报告关联产业近一个月的阅读量
  119. func IndustrialYxArticleNumUpdate() (err error) {
  120. defer func() {
  121. if err != nil {
  122. //fmt.Println(err)
  123. go utils.SendAlarmMsg("更改研选对应的报告关联产业近一个月的阅读量失败"+err.Error(), 2)
  124. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"更改研选对应的报告关联产业近一个月的阅读量失败提醒", err.Error(), utils.EmailSendToUsers)
  125. }
  126. }()
  127. articleTypeIds, err := GetYanXuanArticleTypeIds()
  128. if err != nil {
  129. return
  130. }
  131. var condition string
  132. if articleTypeIds == "" {
  133. return
  134. }
  135. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  136. list, err := models.GetIndustrialManagementArtHistoryCount(condition)
  137. if err != nil {
  138. return
  139. }
  140. for _, v := range list {
  141. err = models.UpdateIndustrialManagementArtYanXuanReadNum(v.Count, v.IndustrialManagementId)
  142. if err != nil {
  143. return
  144. }
  145. }
  146. return err
  147. }
  148. // 更改活动关联产业近一个月的到会量
  149. func IndustrialActivityNumUpdate() (err error) {
  150. defer func() {
  151. if err != nil {
  152. //fmt.Println(err)
  153. go utils.SendAlarmMsg("更改活动关联产业近一个月的到会量失败"+err.Error(), 2)
  154. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"更改活动关联产业近一个月的到会量失败", err.Error(), utils.EmailSendToUsers)
  155. }
  156. }()
  157. list, err := models.GetIndustrialManagementActivityHistoryCount()
  158. if err != nil {
  159. return
  160. }
  161. for _, v := range list {
  162. err = models.UpdateIndustrialManagementActivityNum(v.Count, v.IndustrialManagementId)
  163. if err != nil {
  164. return
  165. }
  166. }
  167. return err
  168. }
  169. func ReportBillboardUpdate(cont context.Context) (err error) {
  170. //修改产业关注数量
  171. go IndustryFllowCountUpdate()
  172. //修改文章收藏数量
  173. go ArticleCollectCountUpdate()
  174. return
  175. }
  176. // 修改产业关注数量
  177. func IndustryFllowCountUpdate() (err error) {
  178. defer func() {
  179. if err != nil {
  180. go utils.SendAlarmMsg("修改产业关注数量信息失败"+err.Error(), 2)
  181. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  182. }
  183. }()
  184. fllowList, err := models.GetUserFllowIndustrialCountList()
  185. if err != nil {
  186. return
  187. }
  188. for _, v := range fllowList {
  189. err = models.UpdateIndustrialManagementFllowNum(v.Num, v.IndustrialManagementId)
  190. if err != nil {
  191. return
  192. }
  193. }
  194. return err
  195. }
  196. // 修改文章收藏数量
  197. func ArticleCollectCountUpdate() (err error) {
  198. defer func() {
  199. if err != nil {
  200. go utils.SendAlarmMsg("修改文章收藏数量信息失败"+err.Error(), 2)
  201. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改文章收藏数量信息失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  202. }
  203. }()
  204. collectList, err := models.GetUserArticleCollectList()
  205. if err != nil {
  206. return
  207. }
  208. for _, v := range collectList {
  209. err = models.UpdateArticleCollectCountNum(v.Num, v.ArticleId)
  210. if err != nil {
  211. return
  212. }
  213. }
  214. return err
  215. }
  216. // 根据行业处理所选的全部赛道字段
  217. func DoXzsChooseSend(chartPermissionName string) string {
  218. var allIn string
  219. if chartPermissionName == utils.YI_YAO_NAME {
  220. allIn = "all_in_yi_yao"
  221. } else if chartPermissionName == utils.XIAO_FEI_NAME {
  222. allIn = "all_in_xiao_fei"
  223. } else if chartPermissionName == utils.KE_JI_NAME {
  224. allIn = "all_in_ke_ji"
  225. } else if chartPermissionName == utils.ZHI_ZAO_NAME {
  226. allIn = "all_in_zhi_zao"
  227. } else if chartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  228. allIn = "all_in_yan_xuan"
  229. }
  230. return allIn
  231. }
  232. // 行业关注或者取消关注的时候,对于用户全部赛道的影响
  233. func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error) {
  234. defer func() {
  235. if err != nil {
  236. fmt.Println(err)
  237. go utils.SendAlarmMsg("修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败"+err.Error(), 2)
  238. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  239. }
  240. }()
  241. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  242. if err != nil {
  243. return err
  244. }
  245. categoryinfo, err := models.GetChartPermissionById(detail.ChartPermissionId)
  246. if err != nil {
  247. return err
  248. }
  249. var allIn string
  250. allIn = DoXzsChooseSend(categoryinfo.PermissionName)
  251. if allIn != "" {
  252. //如果取消关注就把该赛道设置为非全部赛道
  253. if count == 1 {
  254. err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 0, uid)
  255. if err != nil {
  256. return err
  257. }
  258. } else {
  259. //医药、消费、科技、智造、研选下的产业赛道
  260. mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  261. industrialList, err := models.GetindustrialManagement()
  262. if err != nil {
  263. return err
  264. }
  265. for _, v := range industrialList {
  266. mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  267. }
  268. fllowNum, err := models.GetCountCygxIndustryFllowByUidAndChartPermissionId(uid, detail.ChartPermissionId)
  269. if err != nil {
  270. return err
  271. }
  272. if fllowNum == len(mapIndustrial[detail.ChartPermissionId]) {
  273. err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 1, uid)
  274. if err != nil {
  275. return err
  276. }
  277. }
  278. }
  279. }
  280. return err
  281. }
  282. //func init() {
  283. //IndustryFllowUserLabel(136, 16, 5660)
  284. //UserLabelLogReduce()
  285. //}
  286. // GetIndustryNewLabelMap 获取产业【新】标签Map
  287. func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
  288. labelMap = make(map[int]bool, 0)
  289. industryIdLen := len(industryIds)
  290. if industryIdLen == 0 {
  291. return
  292. }
  293. // 获取产业关联的报告最早发布时间及最近的发布时间
  294. var timeCond string
  295. var timePars []interface{}
  296. timeCond += ` AND b.publish_status = 1`
  297. if industryIdLen > 0 {
  298. timeCond += ` AND a.industrial_management_id IN (` + utils.GetOrmInReplace(industryIdLen) + `)`
  299. timePars = append(timePars, industryIds)
  300. }
  301. //只要弘则报告,不要研选报告
  302. timeCond += ` AND b.article_id < ? `
  303. timePars = append(timePars, utils.SummaryArticleId)
  304. industryTimeList, e := models.GetIndustryArticleMinMaxPublishTime(timeCond, timePars)
  305. if e != nil {
  306. err = errors.New("获取产业文章最大最小发布时间失败, Err: " + e.Error())
  307. return
  308. }
  309. // 判断产业是否为新
  310. nowTime := time.Now().Local()
  311. threeMonthBefore := nowTime.AddDate(0, -3, 0)
  312. nullTime, _ := time.ParseInLocation(utils.FormatDateTime, "0001-01-01 00:00:00", time.Local)
  313. industryMap := make(map[int]*models.IndustryArticleMinMaxPublishTime, 0)
  314. for i := range industryTimeList {
  315. industryMap[industryTimeList[i].IndustrialManagementId] = industryTimeList[i]
  316. }
  317. for i := range industryIds {
  318. iid := industryIds[i]
  319. item := industryMap[iid]
  320. if item != nil {
  321. // 最早发布时间为空 / 最早发布时间在三个月前之后
  322. if item.MinPublishTime.Equal(nullTime) || (item.MinPublishTime.After(threeMonthBefore)) {
  323. labelMap[iid] = true
  324. }
  325. } else {
  326. // 产业无报告, 则为新产业
  327. labelMap[iid] = true
  328. }
  329. }
  330. return
  331. }
  332. //func init() {
  333. // GetIndustrialManagementArticleNewPublishData()
  334. //}
  335. // 批量修改获取产业关联文章的最新发布时间
  336. func GetIndustrialManagementArticleNewPublishData() (err error) {
  337. defer func() {
  338. if err != nil {
  339. go utils.SendAlarmMsg("批量修改获取产业关联文章的最新发布时间"+"GetIndustrialManagementArticleNewPublishData ErrMsg:"+err.Error(), 2)
  340. }
  341. }()
  342. articleNewPublishDataList, e := models.GetIndustrialManagementArticleNewPublishData()
  343. if e != nil {
  344. err = errors.New("获取客户剩余报名次数失败 GetIndustrialManagementArticleNewPublishData, Err: " + e.Error())
  345. return
  346. }
  347. mapUPdateTime := make(map[int]string)
  348. var industrialManagementIds []int
  349. for _, v := range articleNewPublishDataList {
  350. if v.IndustrialManagementId > 0 {
  351. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  352. }
  353. mapUPdateTime[v.IndustrialManagementId] = v.UpdateTime
  354. }
  355. //时间线的更新时间
  356. listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialManagementIds)
  357. if err != nil && err.Error() != utils.ErrNoRow() {
  358. return
  359. }
  360. for _, v := range listtimelinePublishdate {
  361. if mapUPdateTime[v.IndustrialManagementId] != "" {
  362. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  363. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  364. }
  365. }
  366. }
  367. err = models.UpdateIndustrialManagementArticleNewPublishData(mapUPdateTime)
  368. return
  369. }
  370. // HandleIndustryList预处理产业列表字段
  371. func HandleIndustryList(list []*models.IndustrialManagement, user *models.WxUserItem) (items []*models.IndustrialManagement, err error) {
  372. userId := user.UserId
  373. fllowList, err := models.GetUserFllowIndustrialList(userId)
  374. if err != nil {
  375. return
  376. }
  377. fllowMap := make(map[int]int)
  378. if len(fllowList) > 0 {
  379. for _, v := range fllowList {
  380. fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
  381. }
  382. }
  383. mapindustrialId, e := GetMicroRoadshowVideoMap()
  384. if e != nil {
  385. err = e
  386. return
  387. }
  388. followTypeMap := GetCygxIndustryFllowListTypeMapByMobile(user.Mobile) // 关注的对应状态
  389. //合并产业关联的标的
  390. listSubjcet, err := models.GetThemeHeatSubjectList("")
  391. if err != nil {
  392. return
  393. }
  394. industrialIdArr := make([]int, 0)
  395. for k, v := range list {
  396. list[k].Source = 1
  397. if fllowMap[v.IndustrialManagementId] > 0 {
  398. list[k].IsFollow = 1
  399. }
  400. list[k].FollowType = followTypeMap[v.IndustrialManagementId]
  401. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  402. if _, ok := mapindustrialId[v.IndustrialManagementId]; !ok {
  403. continue
  404. }
  405. videoSimple, au, e := GetindustryVideo(user, v.IndustrialManagementId)
  406. if e != nil {
  407. err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
  408. return
  409. }
  410. if videoSimple != nil && videoSimple.Id > 0 {
  411. v.IndustryVideo = videoSimple
  412. }
  413. v.AuthInfo = au
  414. }
  415. if len(industrialIdArr) > 0 {
  416. //合并产业关联的标的
  417. listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
  418. if err != nil {
  419. return
  420. }
  421. mapIndustrial := make(map[string]int)
  422. for _, v := range listSubjcet {
  423. for k2, v2 := range list {
  424. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  425. list[k2].IndustrialSubjectList = append(list[k2].IndustrialSubjectList, v)
  426. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
  427. }
  428. }
  429. }
  430. }
  431. mapUPdateTime := make(map[int]string)
  432. articleIdArr := make([]int, 0)
  433. //获取这些产业下最新更新的文章
  434. listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
  435. if err != nil && err.Error() != utils.ErrNoRow() {
  436. return
  437. }
  438. for _, v := range listUpdateTime {
  439. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  440. articleIdArr = append(articleIdArr, v.ArticleId)
  441. }
  442. //时间线的更新时间
  443. // maptimelineUPdateTime := make(map[int]string)
  444. listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialIdArr)
  445. if err != nil && err.Error() != utils.ErrNoRow() {
  446. return
  447. }
  448. for _, v := range listtimelinePublishdate {
  449. if mapUPdateTime[v.IndustrialManagementId] != "" {
  450. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  451. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  452. }
  453. }
  454. }
  455. //产品内测的更新时间线
  456. listtProductInterior, err := models.GetNewProductInteriorByIndustrialIds(industrialIdArr)
  457. if err != nil && err.Error() != utils.ErrNoRow() {
  458. return
  459. }
  460. for _, v := range listtProductInterior {
  461. if mapUPdateTime[v.IndustrialManagementId] != "" {
  462. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  463. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  464. }
  465. }
  466. }
  467. //mapHistroyArticleId := make(map[int]int)
  468. //if userId > 0 {
  469. // listArticleHistory, e := models.GetUserToArticleHistory(userId, articleIdArr)
  470. // if e != nil && e.Error() != utils.ErrNoRow() {
  471. // err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
  472. // return
  473. // }
  474. // for _, v := range listArticleHistory {
  475. // mapHistroyArticleId[v.ArticleId] = v.ArticleId
  476. // }
  477. //}
  478. var industrialIds string
  479. for _, id := range industrialIdArr {
  480. industrialIds += strconv.Itoa(id) + ","
  481. }
  482. industrialIds = strings.TrimRight(industrialIds, ",")
  483. articleList, err := models.GetReportIndustrialReadNumList(userId, industrialIds, user.CreatedTime)
  484. mapHistroyindustrialId := make(map[int]int)
  485. for _, v := range articleList {
  486. mapHistroyindustrialId[v.IndustrialManagementId] = v.Readnum
  487. }
  488. nowTime := time.Now().Local()
  489. threeMonBefore := nowTime.AddDate(0, -3, 0)
  490. //查询用户今天是否看过时间线
  491. //haveMorningMeeting := false
  492. //var morningMeetingTime string
  493. recrodList, err := models.GetCygxTimelineLogCount(user.UserId, industrialIdArr)
  494. if err != nil && err.Error() != utils.ErrNoRow() {
  495. return
  496. }
  497. var industrialManagementIdstr string
  498. industrialIdMap := make(map[string]time.Time)
  499. for _, v := range recrodList {
  500. industrialManagementIdstr = strconv.Itoa(v.IndustrialManagementId)
  501. industrialIdMap[industrialManagementIdstr] = v.ModifyTime
  502. //industrialManagementIdstr = strings.TrimLeft(v.Parameter, "PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=")
  503. //if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
  504. // if createTime.Before(v.CreateTime) {
  505. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  506. // }
  507. //} else {
  508. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  509. //}
  510. }
  511. mmList, err := models.GetCygxMorningMeetingReviewsListByIndustrialIds(industrialIds)
  512. if err != nil {
  513. return
  514. }
  515. morningMeetingTimeMap := make(map[int]time.Time)
  516. for _, v := range mmList {
  517. morningMeetingTimeMap[v.IndustryId] = v.CreateTime
  518. }
  519. timeLineRedMap := make(map[int]bool, 0)
  520. for _, industrialId := range industrialIdArr {
  521. if createTime, ok := industrialIdMap[strconv.Itoa(industrialId)]; ok {
  522. if createTime.Before(morningMeetingTimeMap[industrialId]) {
  523. timeLineRedMap[industrialId] = true
  524. }
  525. }
  526. }
  527. hotMapindustrial, err := IndustrialManagementHotMapGropuPermission()
  528. if err != nil {
  529. return
  530. }
  531. for k, v := range list {
  532. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  533. list[k].IsHot = hotMapindustrial[v.IndustrialManagementId]
  534. if userId > 0 {
  535. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  536. if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] {
  537. if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  538. list[k].IsRed = true
  539. }
  540. }
  541. } else {
  542. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  543. list[k].IsRed = true
  544. }
  545. list[k].IsFollow = 0
  546. }
  547. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  548. if userId > 0 {
  549. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  550. if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] {
  551. if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  552. list[k].IsRed = true
  553. }
  554. }
  555. } else {
  556. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  557. list[k].IsRed = true
  558. }
  559. list[k].IsFollow = 0
  560. }
  561. // 关联报告发布时间均在3个月内则标记New
  562. if v.MinReportTime != "" {
  563. t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
  564. if e != nil {
  565. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  566. return
  567. }
  568. if t.After(threeMonBefore) {
  569. list[k].IsNew = true
  570. }
  571. }
  572. }
  573. items = list
  574. return
  575. }
  576. // HandleIndustryList预处理产业列表字段
  577. func HandleIndustryListResource(list []*models.IndustrialManagement, user *models.WxUserItem, resource string) (items []*models.IndustrialManagement, err error) {
  578. userId := user.UserId
  579. fllowList, err := models.GetUserFllowIndustrialList(userId)
  580. if err != nil {
  581. return
  582. }
  583. fllowMap := make(map[int]int)
  584. if len(fllowList) > 0 {
  585. for _, v := range fllowList {
  586. fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
  587. }
  588. }
  589. hotMap, e := IndustrialManagementHotMapGropuPermission()
  590. if e != nil {
  591. err = errors.New("获取hot标签失败,IndustrialManagementHotMapGropuPermission " + e.Error())
  592. return
  593. }
  594. var condition string
  595. var pars []interface{}
  596. articleTypeIds, _ := GetYanXuanArticleTypeIds()
  597. //给默认值
  598. if resource != "Yx" {
  599. resource = "Hz"
  600. }
  601. if articleTypeIds != "" {
  602. if resource == "Yx" {
  603. condition = ` AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) `
  604. } else {
  605. condition = ` AND a.article_type_id NOT IN (` + articleTypeIds + `) `
  606. }
  607. }
  608. mapindustrialId, e := GetMicroRoadshowVideoMap()
  609. if e != nil {
  610. err = e
  611. return
  612. }
  613. //合并产业关联的标的
  614. listSubjcet, err := models.GetThemeHeatSubjectList("")
  615. if err != nil {
  616. return
  617. }
  618. industrialIdArr := make([]int, 0)
  619. for k, v := range list {
  620. list[k].Source = 1
  621. if fllowMap[v.IndustrialManagementId] > 0 {
  622. list[k].IsFollow = 1
  623. }
  624. v.IsHot = hotMap[v.IndustrialManagementId]
  625. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  626. if _, ok := mapindustrialId[v.IndustrialManagementId]; !ok {
  627. continue
  628. }
  629. videoSimple, au, e := GetindustryVideo(user, v.IndustrialManagementId)
  630. if e != nil {
  631. err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
  632. return
  633. }
  634. if videoSimple != nil && videoSimple.Id > 0 {
  635. v.IndustryVideo = videoSimple
  636. }
  637. v.AuthInfo = au
  638. }
  639. if len(industrialIdArr) > 0 {
  640. //合并产业关联的标的
  641. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)`
  642. pars = append(pars, industrialIdArr)
  643. listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialIdcondition(pars, conditionSubject)
  644. if err != nil {
  645. return
  646. }
  647. mapIndustrial := make(map[string]int)
  648. for _, v := range listSubjcet {
  649. for k2, v2 := range list {
  650. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  651. list[k2].IndustrialSubjectList = append(list[k2].IndustrialSubjectList, v)
  652. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
  653. }
  654. }
  655. }
  656. }
  657. //获取产业关联的的文章用户是否阅读
  658. mapIndustrialArticleHistory, err := GetUserArticleHistoryIndustrialNewPublishDate(user, industrialIdArr, articleTypeIds, resource)
  659. if err != nil {
  660. err = errors.New("获取产业关联的的文章用户是否阅读失败 " + err.Error())
  661. return
  662. }
  663. mapUPdateTime := make(map[int]string)
  664. articleIdArr := make([]int, 0)
  665. //获取这些产业下最新更新的文章
  666. var conditionindustrial string
  667. var parsindustrial []interface{}
  668. var industrialIds string
  669. if len(industrialIdArr) > 0 {
  670. conditionindustrial = condition + ` AND mg.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)`
  671. parsindustrial = append(parsindustrial, industrialIdArr)
  672. listUpdateTime, e := models.GetNewArticleDetailByIndustrialIdscondition(parsindustrial, conditionindustrial)
  673. if e != nil && e.Error() != utils.ErrNoRow() {
  674. err = errors.New("GetNewArticleDetailByIndustrialIds Err " + e.Error())
  675. return
  676. }
  677. for _, v := range listUpdateTime {
  678. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  679. articleIdArr = append(articleIdArr, v.ArticleId)
  680. }
  681. //时间线的更新时间
  682. // maptimelineUPdateTime := make(map[int]string)
  683. listtimelinePublishdate, e := models.GetTimeLineReportIndustrialPublishdateList(industrialIdArr)
  684. if e != nil && e.Error() != utils.ErrNoRow() {
  685. err = e
  686. return
  687. }
  688. for _, v := range listtimelinePublishdate {
  689. if mapUPdateTime[v.IndustrialManagementId] != "" {
  690. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  691. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  692. }
  693. }
  694. }
  695. //产品内测的更新时间线
  696. listtProductInterior, e := models.GetNewProductInteriorByIndustrialIds(industrialIdArr)
  697. if e != nil && e.Error() != utils.ErrNoRow() {
  698. err = e
  699. return
  700. }
  701. for _, v := range listtProductInterior {
  702. if mapUPdateTime[v.IndustrialManagementId] != "" {
  703. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  704. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  705. }
  706. }
  707. }
  708. for _, id := range industrialIdArr {
  709. industrialIds += strconv.Itoa(id) + ","
  710. }
  711. industrialIds = strings.TrimRight(industrialIds, ",")
  712. articleList, e := models.GetReportIndustrialReadNumList(userId, industrialIds, user.CreatedTime)
  713. if e != nil && e.Error() != utils.ErrNoRow() {
  714. err = e
  715. return
  716. }
  717. mapHistroyindustrialId := make(map[int]int)
  718. for _, v := range articleList {
  719. mapHistroyindustrialId[v.IndustrialManagementId] = v.Readnum
  720. }
  721. }
  722. nowTime := time.Now().Local()
  723. threeMonBefore := nowTime.AddDate(0, -3, 0)
  724. //查询用户今天是否看过时间线
  725. //haveMorningMeeting := false
  726. //var morningMeetingTime string
  727. recrodList, err := models.GetCygxTimelineLogCount(user.UserId, industrialIdArr)
  728. if err != nil && err.Error() != utils.ErrNoRow() {
  729. return
  730. }
  731. var industrialManagementIdstr string
  732. industrialIdMap := make(map[string]time.Time)
  733. for _, v := range recrodList {
  734. //fmt.Println(v.Router)
  735. //sliceindustrial := strings.Split(v.Router, "=")
  736. //industrialManagementIdstr = strings.TrimLeft(v.Router, utils.TIME_LINE_ROUTE)
  737. industrialManagementIdstr = strconv.Itoa(v.IndustrialManagementId)
  738. industrialIdMap[industrialManagementIdstr] = v.ModifyTime
  739. //fmt.Println(industrialManagementIdstr)
  740. //if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
  741. // if createTime.Before(v.CreateTime) {
  742. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  743. // }
  744. //} else {
  745. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  746. //}
  747. }
  748. morningMeetingTimeMap := make(map[int]time.Time)
  749. if industrialIds != "" {
  750. mmList, e := models.GetCygxMorningMeetingReviewsListByIndustrialIds(industrialIds)
  751. if e != nil {
  752. err = e
  753. return
  754. }
  755. for _, v := range mmList {
  756. morningMeetingTimeMap[v.IndustryId] = v.CreateTime
  757. }
  758. }
  759. timeLineRedMap := make(map[int]bool, 0)
  760. for _, industrialId := range industrialIdArr {
  761. //if createTime, ok := industrialIdMap[strconv.Itoa(industrialId)]; ok {
  762. // if createTime.Before(morningMeetingTimeMap[industrialId]) {
  763. // timeLineRedMap[industrialId] = true
  764. // }
  765. //}
  766. if industrialIdMap[strconv.Itoa(industrialId)].Before(morningMeetingTimeMap[industrialId]) {
  767. timeLineRedMap[industrialId] = true
  768. }
  769. }
  770. //fmt.Println(industrialIdMap["90"])
  771. //fmt.Println(timeLineRedMap[90])
  772. //fmt.Println(mapIndustrialArticleHistory[90])
  773. for k, v := range list {
  774. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  775. if userId > 0 {
  776. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  777. if mapIndustrialArticleHistory[v.IndustrialManagementId] || timeLineRedMap[v.IndustrialManagementId] {
  778. //if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] {
  779. if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  780. list[k].IsRed = true
  781. }
  782. }
  783. } else {
  784. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  785. list[k].IsRed = true
  786. }
  787. list[k].IsFollow = 1
  788. }
  789. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  790. if resource == "Yx" {
  791. list[k].IsRed = false
  792. }
  793. // 关联报告发布时间均在3个月内则标记New
  794. if v.MinReportTime != "" {
  795. t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
  796. if e != nil {
  797. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  798. return
  799. }
  800. if t.After(threeMonBefore) {
  801. list[k].IsNew = true
  802. }
  803. }
  804. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  805. v.Source = 2
  806. } else {
  807. v.Source = 1
  808. }
  809. if v.TimeLineData == "" {
  810. v.ListTimeLine = make([]models.TimeLineReportResp, 0)
  811. } else {
  812. if err = json.Unmarshal([]byte(v.TimeLineData), &v.ListTimeLine); err != nil {
  813. e = errors.New("Unmarshal, Err: " + e.Error())
  814. return
  815. }
  816. }
  817. }
  818. items = list
  819. return
  820. }
  821. func HandleIndustryListHzAndYx(list []*models.IndustrialManagement, user *models.WxUserItem, resource string) (items []*models.IndustrialManagement, err error) {
  822. var listHz []*models.IndustrialManagement
  823. var lisYx []*models.IndustrialManagement
  824. for _, v := range list {
  825. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  826. lisYx = append(lisYx, v)
  827. } else {
  828. listHz = append(listHz, v)
  829. }
  830. }
  831. listHz, err = HandleIndustryListResource(listHz, user, "Hz")
  832. if err != nil {
  833. return
  834. }
  835. lisYx, err = HandleIndustryListResource(lisYx, user, "Yx")
  836. if err != nil {
  837. return
  838. }
  839. maplistHz := make(map[int]*models.IndustrialManagement)
  840. maplistYx := make(map[int]*models.IndustrialManagement)
  841. for _, v := range listHz {
  842. maplistHz[v.IndustrialManagementId] = v
  843. }
  844. for _, v := range lisYx {
  845. maplistYx[v.IndustrialManagementId] = v
  846. }
  847. for _, v := range list {
  848. if maplistHz[v.IndustrialManagementId] != nil {
  849. items = append(items, maplistHz[v.IndustrialManagementId])
  850. }
  851. if maplistYx[v.IndustrialManagementId] != nil {
  852. items = append(items, maplistYx[v.IndustrialManagementId])
  853. }
  854. }
  855. return
  856. }
  857. // 通过文章ID获取文章所关联的产业
  858. func GetArticleIndustrialByArticleId(articleIds []int) (itemMap map[int][]*models.IndustrialManagementResp, err error) {
  859. lenarticleIds := len(articleIds)
  860. if lenarticleIds == 0 {
  861. return
  862. }
  863. var condition string
  864. var pars []interface{}
  865. condition = ` AND mg.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
  866. pars = append(pars, articleIds)
  867. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  868. if err != nil {
  869. return
  870. }
  871. industrialMap := make(map[int][]*models.IndustrialManagementResp)
  872. if len(industrialList) > 0 {
  873. for _, v := range industrialList {
  874. item := new(models.IndustrialManagementResp)
  875. item.IndustrialManagementId = v.IndustrialManagementId
  876. item.IndustryName = v.IndustryName
  877. item.ChartPermissionId = v.ChartPermissionId
  878. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  879. }
  880. }
  881. itemMap = industrialMap
  882. return
  883. }
  884. func GetArticleTypeMap() (nameMapResp map[int]string, buttonStyleMapResp map[int]string, err error) {
  885. condition := " AND is_show_yanx = 1 "
  886. list, e := models.GetCygxArticleTypeListCondition(condition)
  887. if e != nil {
  888. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  889. return
  890. }
  891. nameMap := make(map[int]string)
  892. buttonStyleMap := make(map[int]string)
  893. if len(list) > 0 {
  894. for _, v := range list {
  895. nameMap[v.ArticleTypeId] = v.ArticleTypeName
  896. buttonStyleMap[v.ArticleTypeId] = v.ButtonStyle
  897. }
  898. }
  899. nameMapResp = nameMap
  900. buttonStyleMapResp = buttonStyleMap
  901. return
  902. }
  903. // IndustrialManagementHotMapGropuPermission获取近一个月报告阅读数量最多的产业信息 根据行业分组
  904. func IndustrialManagementHotMapGropuPermission() (mapResp map[int]bool, err error) {
  905. var topCond string
  906. var topPars []interface{}
  907. toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  908. if err != nil {
  909. return
  910. }
  911. mapPermission := make(map[int][]*models.IndustrialManagement)
  912. mapPermissionMax := make(map[int]int)
  913. for _, v := range toplist {
  914. item := new(models.IndustrialManagement)
  915. item.ChartPermissionId = v.ChartPermissionId
  916. item.IndustrialManagementId = v.IndustrialManagementId
  917. item.ArticleReadNum = v.ArticleReadNum
  918. mapPermission[v.ChartPermissionId] = append(mapPermission[v.ChartPermissionId], item)
  919. }
  920. for k, v := range mapPermission {
  921. for _, item := range v {
  922. //mapPermissionMax[k] = item.ArticleReadNum
  923. if item.ArticleReadNum > mapPermissionMax[k] {
  924. mapPermissionMax[k] = item.ArticleReadNum
  925. }
  926. }
  927. }
  928. mapResp = make(map[int]bool, 0)
  929. for _, v := range toplist {
  930. if v.ArticleReadNum == mapPermissionMax[v.ChartPermissionId] {
  931. mapResp[v.IndustrialManagementId] = true
  932. }
  933. }
  934. return
  935. }
  936. // GetLyjhTypeMap 获取路演精华对应分类ID
  937. func GetLyjhTypeMap() (mapResp map[int]int, err error) {
  938. defer func() {
  939. if err != nil {
  940. go utils.SendAlarmMsg("获取路演精华对应分类ID失败 ErrMsg:"+err.Error(), 2)
  941. }
  942. }()
  943. condition := " AND match_type_name = '路演精华' "
  944. var pars []interface{}
  945. list, e := models.GetReportMappingList(condition, pars)
  946. if e != nil && e.Error() != utils.ErrNoRow() {
  947. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  948. return
  949. }
  950. mapResp = make(map[int]int, 0)
  951. if len(list) > 0 {
  952. for _, v := range list {
  953. mapResp[v.CategoryId] = v.CategoryId
  954. }
  955. }
  956. return
  957. }
  958. // GetLyjhArticleMap 获取路演精华对应文章ID
  959. func GetLyjhArticleMap() (mapResp map[int]bool, err error) {
  960. defer func() {
  961. if err != nil {
  962. go utils.SendAlarmMsg("获取路演精华对应文章ID失败 ErrMsg:"+err.Error(), 2)
  963. }
  964. }()
  965. condition := " AND match_type_name = '路演精华' "
  966. var pars []interface{}
  967. list, e := models.GetReportMappingList(condition, pars)
  968. if e != nil && e.Error() != utils.ErrNoRow() {
  969. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  970. return
  971. }
  972. var categoryId []int
  973. mapResp = make(map[int]bool, 0)
  974. if len(list) > 0 {
  975. for _, v := range list {
  976. categoryId = append(categoryId, v.CategoryId)
  977. }
  978. }
  979. lencategoryId := len(categoryId)
  980. if lencategoryId > 0 {
  981. pars = make([]interface{}, 0)
  982. condition = ` AND a.category_id IN (` + utils.GetOrmInReplace(lencategoryId) + `)`
  983. pars = append(pars, categoryId)
  984. listArticle, e := models.GetHomeList(condition, pars, 0, 1000)
  985. if e != nil && e.Error() != utils.ErrNoRow() {
  986. err = errors.New("GetResourceDataList, Err: " + e.Error())
  987. return
  988. }
  989. for _, v := range listArticle {
  990. mapResp[v.ArticleId] = true
  991. }
  992. }
  993. return
  994. }
  995. // 获取所有的产业id与名称的map关联
  996. func GetIndustrialManagementRespMap() (itemMap map[int]string, err error) {
  997. defer func() {
  998. if err != nil {
  999. go utils.SendAlarmMsg("GetIndustrialManagementRespMap ErrMsg:"+err.Error(), 2)
  1000. }
  1001. }()
  1002. var condition string
  1003. var pars []interface{}
  1004. itemMap = make(map[int]string, 0)
  1005. industrialList, e := models.GetIndustrialManagementRepList(condition, pars, 0, 999999)
  1006. if e != nil {
  1007. err = errors.New("GetIndustrialManagementRepList, Err: " + e.Error())
  1008. return
  1009. }
  1010. if len(industrialList) > 0 {
  1011. for _, v := range industrialList {
  1012. itemMap[v.IndustrialManagementId] = v.IndustryName
  1013. }
  1014. }
  1015. return
  1016. }
  1017. // 获取所有的标的id与名称的map关联
  1018. func GetCygxIndustrialSubjectMap() (itemMap map[int]string, err error) {
  1019. defer func() {
  1020. if err != nil {
  1021. go utils.SendAlarmMsg("GetCygxIndustrialSubjectMap ErrMsg:"+err.Error(), 2)
  1022. }
  1023. }()
  1024. var condition string
  1025. var pars []interface{}
  1026. itemMap = make(map[int]string, 0)
  1027. list, e := models.GetCygxIndustrialSubjectListCondition(condition, pars)
  1028. if e != nil {
  1029. err = errors.New("GetIndustrialManagementRepList, Err: " + e.Error())
  1030. return
  1031. }
  1032. if len(list) > 0 {
  1033. for _, v := range list {
  1034. itemMap[v.IndustrialSubjectId] = v.SubjectName
  1035. }
  1036. }
  1037. return
  1038. }
  1039. //func init() {
  1040. // UpdateIndustrialManagementOneMonthFollowNum()
  1041. //}
  1042. // UpdateIndustrialManagementOneMonthFollowNum 更新产业近一个月被关注的数量
  1043. func UpdateIndustrialManagementOneMonthFollowNum(cont context.Context) (err error) {
  1044. //var err error
  1045. defer func() {
  1046. if err != nil {
  1047. fmt.Println(err)
  1048. go utils.SendAlarmMsg("UpdateIndustrialManagementOneMonthFollowNum ErrMsg:"+err.Error(), 2)
  1049. }
  1050. }()
  1051. listNum, e := models.GetIndustrialManagementOneMonthFollowNum()
  1052. if e != nil {
  1053. err = errors.New("GetIndustrialManagementOneMonthFollowNum, Err: " + e.Error())
  1054. return
  1055. }
  1056. e = models.UpdateIndustrialManagementInit() //初始化每月产业用户关注数量
  1057. if e != nil {
  1058. err = errors.New("UpdateIndustrialManagementInit, Err: " + e.Error())
  1059. return
  1060. }
  1061. var items []*models.CygxIndustryFllowNumResp
  1062. for _, v := range listNum {
  1063. item := new(models.CygxIndustryFllowNumResp)
  1064. item.IndustrialManagementId = v.IndustrialManagementId
  1065. item.Total = v.Total
  1066. items = append(items, item)
  1067. //一次最多插入五百条
  1068. if len(items)%500 == 0 {
  1069. e = models.UpdateIndustrialManagementOneMonthFollowNumMulti(items)
  1070. if e != nil {
  1071. err = errors.New("UpdateIndustrialManagementOneMonthFollowNumMulti, Err: " + e.Error())
  1072. return
  1073. }
  1074. }
  1075. }
  1076. if len(items) > 0 {
  1077. e = models.UpdateIndustrialManagementOneMonthFollowNumMulti(items)
  1078. if e != nil {
  1079. err = errors.New("UpdateIndustrialManagementOneMonthFollowNumMulti, Err: " + e.Error())
  1080. return
  1081. }
  1082. }
  1083. return
  1084. }
  1085. // GetCygxIndustryFllowListTypeMapByMobile 根据手机号获取产业关注的信息
  1086. func GetCygxIndustryFllowListTypeMapByMobile(mobile string) (mapFollowTypeResp map[int]int) {
  1087. if mobile == "" {
  1088. return
  1089. }
  1090. var err error
  1091. defer func() {
  1092. if err != nil {
  1093. fmt.Println("err:", err)
  1094. go utils.SendAlarmMsg(fmt.Sprint("根据手机号获取产业关注的信息 失败,GetCygxIndustryFllowListTypeMapByMobile Err:"+err.Error()+"mobile", mobile), 3)
  1095. }
  1096. }()
  1097. mapFollowTypeResp = make(map[int]int, 0)
  1098. fllowList, e := models.GetCygxIndustryFllowListByMobile(mobile)
  1099. //策略的处理
  1100. if e != nil {
  1101. err = errors.New("GetUserFllowIndustrialList, Err: " + e.Error())
  1102. return
  1103. }
  1104. for _, v := range fllowList {
  1105. mapFollowTypeResp[v.IndustrialManagementId] = v.FollowType
  1106. }
  1107. return
  1108. }
  1109. //func init_14-2() {
  1110. // //IndustrialManagementTimeLineDateList3(127)
  1111. //
  1112. // list, err := models.IndustrialManagementAll()
  1113. // if err != nil {
  1114. // fmt.Println("Error marshaling to JSON:", err)
  1115. // return
  1116. // }
  1117. // fmt.Println(len(list))
  1118. // for k, v := range list {
  1119. // fmt.Println(k)
  1120. // time.Sleep(200 * time.Millisecond)
  1121. // if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  1122. // continue
  1123. // }
  1124. // IndustrialManagementTimeLineDateList3(v.IndustrialManagementId)
  1125. // }
  1126. //}
  1127. // 时间线关联文章的三条数据
  1128. func IndustrialManagementTimeLineDateList3(industrialManagementId int) (err error) {
  1129. defer func() {
  1130. if err != nil {
  1131. fmt.Println(err)
  1132. go utils.SendAlarmMsg("修改时间线关联文章的三条数据信息失败"+err.Error(), 2)
  1133. }
  1134. }()
  1135. list, e := models.GetTimeLineReportIndustrialList(0, industrialManagementId, 0, 3)
  1136. if e != nil {
  1137. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  1138. return
  1139. }
  1140. type TimeLineReportItem struct {
  1141. Title string `description:"标题"`
  1142. PublishDate string `description:"发布时间"`
  1143. }
  1144. var listData []*TimeLineReportItem
  1145. for _, v := range list {
  1146. item := new(TimeLineReportItem)
  1147. if v.Resource == 3 {
  1148. item.Title, _ = extractTextBeforePeriodOrNewline(v.Content)
  1149. fmt.Println("Title", item.Title)
  1150. } else {
  1151. item.Title = v.Title
  1152. }
  1153. item.PublishDate = utils.TimeRemoveHms2(v.PublishTime)
  1154. listData = append(listData, item)
  1155. }
  1156. jsonData, err := json.Marshal(listData)
  1157. if err != nil {
  1158. fmt.Println("Error marshaling to JSON:", err)
  1159. return
  1160. }
  1161. err = models.UpdateIndustrialManagementTimeLineData(industrialManagementId, string(jsonData))
  1162. return err
  1163. }
  1164. func extractTextBeforePeriodOrNewline(htmlContent string) (string, error) {
  1165. var builder strings.Builder
  1166. reader := strings.NewReader(htmlContent)
  1167. z := html.NewTokenizer(reader)
  1168. for {
  1169. tokenType := z.Next()
  1170. switch tokenType {
  1171. case html.ErrorToken:
  1172. // End of document
  1173. return builder.String(), nil
  1174. case html.TextToken:
  1175. text := string(z.Text())
  1176. //fmt.Println("text", text)
  1177. if idx := strings.Index(text, "。"); idx != -1 {
  1178. builder.WriteString(text[:idx+len("。")])
  1179. return builder.String(), nil
  1180. } else {
  1181. return text, nil
  1182. }
  1183. builder.WriteString(text)
  1184. }
  1185. }
  1186. }
  1187. //func init_14_2() {
  1188. //SELECT * FROM cygx_resource_data WHERE source_id IN (SELECT article_id FROM cygx_article WHERE series_name IN ('行业深度','季度策略') ) AND source = 'article'
  1189. //}