industrial_management.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  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. //合并产业关联的标的
  389. listSubjcet, err := models.GetThemeHeatSubjectList("")
  390. if err != nil {
  391. return
  392. }
  393. industrialIdArr := make([]int, 0)
  394. for k, v := range list {
  395. list[k].Source = 1
  396. if fllowMap[v.IndustrialManagementId] > 0 {
  397. list[k].IsFollow = 1
  398. }
  399. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  400. if _, ok := mapindustrialId[v.IndustrialManagementId]; !ok {
  401. continue
  402. }
  403. videoSimple, au, e := GetindustryVideo(user, v.IndustrialManagementId)
  404. if e != nil {
  405. err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
  406. return
  407. }
  408. if videoSimple != nil && videoSimple.Id > 0 {
  409. v.IndustryVideo = videoSimple
  410. }
  411. v.AuthInfo = au
  412. }
  413. if len(industrialIdArr) > 0 {
  414. //合并产业关联的标的
  415. listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
  416. if err != nil {
  417. return
  418. }
  419. mapIndustrial := make(map[string]int)
  420. for _, v := range listSubjcet {
  421. for k2, v2 := range list {
  422. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  423. list[k2].IndustrialSubjectList = append(list[k2].IndustrialSubjectList, v)
  424. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
  425. }
  426. }
  427. }
  428. }
  429. mapUPdateTime := make(map[int]string)
  430. articleIdArr := make([]int, 0)
  431. //获取这些产业下最新更新的文章
  432. listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
  433. if err != nil && err.Error() != utils.ErrNoRow() {
  434. return
  435. }
  436. for _, v := range listUpdateTime {
  437. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  438. articleIdArr = append(articleIdArr, v.ArticleId)
  439. }
  440. //时间线的更新时间
  441. // maptimelineUPdateTime := make(map[int]string)
  442. listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialIdArr)
  443. if err != nil && err.Error() != utils.ErrNoRow() {
  444. return
  445. }
  446. for _, v := range listtimelinePublishdate {
  447. if mapUPdateTime[v.IndustrialManagementId] != "" {
  448. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  449. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  450. }
  451. }
  452. }
  453. //产品内测的更新时间线
  454. listtProductInterior, err := models.GetNewProductInteriorByIndustrialIds(industrialIdArr)
  455. if err != nil && err.Error() != utils.ErrNoRow() {
  456. return
  457. }
  458. for _, v := range listtProductInterior {
  459. if mapUPdateTime[v.IndustrialManagementId] != "" {
  460. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  461. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  462. }
  463. }
  464. }
  465. //mapHistroyArticleId := make(map[int]int)
  466. //if userId > 0 {
  467. // listArticleHistory, e := models.GetUserToArticleHistory(userId, articleIdArr)
  468. // if e != nil && e.Error() != utils.ErrNoRow() {
  469. // err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
  470. // return
  471. // }
  472. // for _, v := range listArticleHistory {
  473. // mapHistroyArticleId[v.ArticleId] = v.ArticleId
  474. // }
  475. //}
  476. var industrialIds string
  477. for _, id := range industrialIdArr {
  478. industrialIds += strconv.Itoa(id) + ","
  479. }
  480. industrialIds = strings.TrimRight(industrialIds, ",")
  481. articleList, err := models.GetReportIndustrialReadNumList(userId, industrialIds, user.CreatedTime)
  482. mapHistroyindustrialId := make(map[int]int)
  483. for _, v := range articleList {
  484. mapHistroyindustrialId[v.IndustrialManagementId] = v.Readnum
  485. }
  486. nowTime := time.Now().Local()
  487. threeMonBefore := nowTime.AddDate(0, -3, 0)
  488. //查询用户今天是否看过时间线
  489. //haveMorningMeeting := false
  490. //var morningMeetingTime string
  491. recrodList, err := models.GetCygxTimelineLogCount(user.UserId, industrialIdArr)
  492. if err != nil && err.Error() != utils.ErrNoRow() {
  493. return
  494. }
  495. var industrialManagementIdstr string
  496. industrialIdMap := make(map[string]time.Time)
  497. for _, v := range recrodList {
  498. industrialManagementIdstr = strconv.Itoa(v.IndustrialManagementId)
  499. industrialIdMap[industrialManagementIdstr] = v.ModifyTime
  500. //industrialManagementIdstr = strings.TrimLeft(v.Parameter, "PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=")
  501. //if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
  502. // if createTime.Before(v.CreateTime) {
  503. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  504. // }
  505. //} else {
  506. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  507. //}
  508. }
  509. mmList, err := models.GetCygxMorningMeetingReviewsListByIndustrialIds(industrialIds)
  510. if err != nil {
  511. return
  512. }
  513. morningMeetingTimeMap := make(map[int]time.Time)
  514. for _, v := range mmList {
  515. morningMeetingTimeMap[v.IndustryId] = v.CreateTime
  516. }
  517. timeLineRedMap := make(map[int]bool, 0)
  518. for _, industrialId := range industrialIdArr {
  519. if createTime, ok := industrialIdMap[strconv.Itoa(industrialId)]; ok {
  520. if createTime.Before(morningMeetingTimeMap[industrialId]) {
  521. timeLineRedMap[industrialId] = true
  522. }
  523. }
  524. }
  525. hotMapindustrial, err := IndustrialManagementHotMapGropuPermission()
  526. if err != nil {
  527. return
  528. }
  529. for k, v := range list {
  530. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  531. list[k].IsHot = hotMapindustrial[v.IndustrialManagementId]
  532. if userId > 0 {
  533. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  534. if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] {
  535. if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  536. list[k].IsRed = true
  537. }
  538. }
  539. } else {
  540. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  541. list[k].IsRed = true
  542. }
  543. list[k].IsFollow = 0
  544. }
  545. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  546. if userId > 0 {
  547. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  548. if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] {
  549. if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  550. list[k].IsRed = true
  551. }
  552. }
  553. } else {
  554. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  555. list[k].IsRed = true
  556. }
  557. list[k].IsFollow = 0
  558. }
  559. // 关联报告发布时间均在3个月内则标记New
  560. if v.MinReportTime != "" {
  561. t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
  562. if e != nil {
  563. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  564. return
  565. }
  566. if t.After(threeMonBefore) {
  567. list[k].IsNew = true
  568. }
  569. }
  570. }
  571. items = list
  572. return
  573. }
  574. // HandleIndustryList预处理产业列表字段
  575. func HandleIndustryListResource(list []*models.IndustrialManagement, user *models.WxUserItem, resource string) (items []*models.IndustrialManagement, err error) {
  576. userId := user.UserId
  577. fllowList, err := models.GetUserFllowIndustrialList(userId)
  578. if err != nil {
  579. return
  580. }
  581. fllowMap := make(map[int]int)
  582. if len(fllowList) > 0 {
  583. for _, v := range fllowList {
  584. fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
  585. }
  586. }
  587. hotMap, e := IndustrialManagementHotMapGropuPermission()
  588. if e != nil {
  589. err = errors.New("获取hot标签失败,IndustrialManagementHotMapGropuPermission " + e.Error())
  590. return
  591. }
  592. var condition string
  593. var pars []interface{}
  594. articleTypeIds, _ := GetYanXuanArticleTypeIds()
  595. //给默认值
  596. if resource != "Yx" {
  597. resource = "Hz"
  598. }
  599. if articleTypeIds != "" {
  600. if resource == "Yx" {
  601. condition = ` AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) `
  602. } else {
  603. condition = ` AND a.article_type_id NOT IN (` + articleTypeIds + `) `
  604. }
  605. }
  606. mapindustrialId, e := GetMicroRoadshowVideoMap()
  607. if e != nil {
  608. err = e
  609. return
  610. }
  611. //合并产业关联的标的
  612. listSubjcet, err := models.GetThemeHeatSubjectList("")
  613. if err != nil {
  614. return
  615. }
  616. industrialIdArr := make([]int, 0)
  617. for k, v := range list {
  618. list[k].Source = 1
  619. if fllowMap[v.IndustrialManagementId] > 0 {
  620. list[k].IsFollow = 1
  621. }
  622. v.IsHot = hotMap[v.IndustrialManagementId]
  623. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  624. if _, ok := mapindustrialId[v.IndustrialManagementId]; !ok {
  625. continue
  626. }
  627. videoSimple, au, e := GetindustryVideo(user, v.IndustrialManagementId)
  628. if e != nil {
  629. err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
  630. return
  631. }
  632. if videoSimple != nil && videoSimple.Id > 0 {
  633. v.IndustryVideo = videoSimple
  634. }
  635. v.AuthInfo = au
  636. v.PublishDate = v.UpdateTime
  637. }
  638. if len(industrialIdArr) > 0 {
  639. //合并产业关联的标的
  640. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)`
  641. pars = append(pars, industrialIdArr)
  642. listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialIdcondition(pars, conditionSubject)
  643. if err != nil {
  644. return
  645. }
  646. mapIndustrial := make(map[string]int)
  647. for _, v := range listSubjcet {
  648. for k2, v2 := range list {
  649. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  650. list[k2].IndustrialSubjectList = append(list[k2].IndustrialSubjectList, v)
  651. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
  652. }
  653. }
  654. }
  655. }
  656. //获取产业关联的的文章用户是否阅读
  657. mapIndustrialArticleHistory, err := GetUserArticleHistoryIndustrialNewPublishDate(user, industrialIdArr, articleTypeIds, resource)
  658. if err != nil {
  659. err = errors.New("获取产业关联的的文章用户是否阅读失败 " + err.Error())
  660. return
  661. }
  662. mapUPdateTime := make(map[int]string)
  663. articleIdArr := make([]int, 0)
  664. //获取这些产业下最新更新的文章
  665. var conditionindustrial string
  666. var parsindustrial []interface{}
  667. var industrialIds string
  668. if len(industrialIdArr) > 0 {
  669. conditionindustrial = condition + ` AND mg.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)`
  670. parsindustrial = append(parsindustrial, industrialIdArr)
  671. listUpdateTime, e := models.GetNewArticleDetailByIndustrialIdscondition(parsindustrial, conditionindustrial)
  672. if e != nil && e.Error() != utils.ErrNoRow() {
  673. err = errors.New("GetNewArticleDetailByIndustrialIds Err " + e.Error())
  674. return
  675. }
  676. for _, v := range listUpdateTime {
  677. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  678. articleIdArr = append(articleIdArr, v.ArticleId)
  679. }
  680. //时间线的更新时间
  681. // maptimelineUPdateTime := make(map[int]string)
  682. listtimelinePublishdate, e := models.GetTimeLineReportIndustrialPublishdateList(industrialIdArr)
  683. if e != nil && e.Error() != utils.ErrNoRow() {
  684. err = e
  685. return
  686. }
  687. for _, v := range listtimelinePublishdate {
  688. if mapUPdateTime[v.IndustrialManagementId] != "" {
  689. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  690. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  691. }
  692. }
  693. }
  694. //产品内测的更新时间线
  695. listtProductInterior, e := models.GetNewProductInteriorByIndustrialIds(industrialIdArr)
  696. if e != nil && e.Error() != utils.ErrNoRow() {
  697. err = e
  698. return
  699. }
  700. for _, v := range listtProductInterior {
  701. if mapUPdateTime[v.IndustrialManagementId] != "" {
  702. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  703. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  704. }
  705. }
  706. }
  707. for _, id := range industrialIdArr {
  708. industrialIds += strconv.Itoa(id) + ","
  709. }
  710. industrialIds = strings.TrimRight(industrialIds, ",")
  711. articleList, e := models.GetReportIndustrialReadNumList(userId, industrialIds, user.CreatedTime)
  712. if e != nil && e.Error() != utils.ErrNoRow() {
  713. err = e
  714. return
  715. }
  716. mapHistroyindustrialId := make(map[int]int)
  717. for _, v := range articleList {
  718. mapHistroyindustrialId[v.IndustrialManagementId] = v.Readnum
  719. }
  720. }
  721. nowTime := time.Now().Local()
  722. threeMonBefore := nowTime.AddDate(0, -3, 0)
  723. //查询用户今天是否看过时间线
  724. //haveMorningMeeting := false
  725. //var morningMeetingTime string
  726. recrodList, err := models.GetCygxTimelineLogCount(user.UserId, industrialIdArr)
  727. if err != nil && err.Error() != utils.ErrNoRow() {
  728. return
  729. }
  730. var industrialManagementIdstr string
  731. industrialIdMap := make(map[string]time.Time)
  732. for _, v := range recrodList {
  733. //fmt.Println(v.Router)
  734. //sliceindustrial := strings.Split(v.Router, "=")
  735. //industrialManagementIdstr = strings.TrimLeft(v.Router, utils.TIME_LINE_ROUTE)
  736. industrialManagementIdstr = strconv.Itoa(v.IndustrialManagementId)
  737. industrialIdMap[industrialManagementIdstr] = v.ModifyTime
  738. //fmt.Println(industrialManagementIdstr)
  739. //if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
  740. // if createTime.Before(v.CreateTime) {
  741. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  742. // }
  743. //} else {
  744. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  745. //}
  746. }
  747. morningMeetingTimeMap := make(map[int]time.Time)
  748. if industrialIds != "" {
  749. mmList, e := models.GetCygxMorningMeetingReviewsListByIndustrialIds(industrialIds)
  750. if e != nil {
  751. err = e
  752. return
  753. }
  754. for _, v := range mmList {
  755. morningMeetingTimeMap[v.IndustryId] = v.CreateTime
  756. }
  757. }
  758. timeLineRedMap := make(map[int]bool, 0)
  759. for _, industrialId := range industrialIdArr {
  760. //if createTime, ok := industrialIdMap[strconv.Itoa(industrialId)]; ok {
  761. // if createTime.Before(morningMeetingTimeMap[industrialId]) {
  762. // timeLineRedMap[industrialId] = true
  763. // }
  764. //}
  765. if industrialIdMap[strconv.Itoa(industrialId)].Before(morningMeetingTimeMap[industrialId]) {
  766. timeLineRedMap[industrialId] = true
  767. }
  768. }
  769. //fmt.Println(industrialIdMap["90"])
  770. //fmt.Println(timeLineRedMap[90])
  771. //fmt.Println(mapIndustrialArticleHistory[90])
  772. for k, v := range list {
  773. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  774. if userId > 0 {
  775. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  776. if mapIndustrialArticleHistory[v.IndustrialManagementId] || timeLineRedMap[v.IndustrialManagementId] {
  777. //if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] {
  778. if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  779. list[k].IsRed = true
  780. }
  781. }
  782. } else {
  783. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  784. list[k].IsRed = true
  785. }
  786. list[k].IsFollow = 1
  787. }
  788. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  789. if resource == "Yx" {
  790. list[k].IsRed = false
  791. }
  792. // 关联报告发布时间均在3个月内则标记New
  793. if v.MinReportTime != "" {
  794. t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
  795. if e != nil {
  796. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  797. return
  798. }
  799. if t.After(threeMonBefore) {
  800. list[k].IsNew = true
  801. }
  802. }
  803. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  804. v.Source = 2
  805. } else {
  806. v.Source = 1
  807. }
  808. if v.TimeLineData == "" {
  809. v.ListTimeLine = make([]models.TimeLineReportResp, 0)
  810. } else {
  811. if err = json.Unmarshal([]byte(v.TimeLineData), &v.ListTimeLine); err != nil {
  812. e = errors.New("Unmarshal, Err: " + e.Error())
  813. return
  814. }
  815. }
  816. }
  817. items = list
  818. return
  819. }
  820. func HandleIndustryListHzAndYx(list []*models.IndustrialManagement, user *models.WxUserItem, resource string) (items []*models.IndustrialManagement, err error) {
  821. var listHz []*models.IndustrialManagement
  822. var lisYx []*models.IndustrialManagement
  823. for _, v := range list {
  824. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  825. lisYx = append(lisYx, v)
  826. } else {
  827. listHz = append(listHz, v)
  828. }
  829. }
  830. listHz, err = HandleIndustryListResource(listHz, user, "Hz")
  831. if err != nil {
  832. return
  833. }
  834. lisYx, err = HandleIndustryListResource(lisYx, user, "Yx")
  835. if err != nil {
  836. return
  837. }
  838. maplistHz := make(map[int]*models.IndustrialManagement)
  839. maplistYx := make(map[int]*models.IndustrialManagement)
  840. for _, v := range listHz {
  841. maplistHz[v.IndustrialManagementId] = v
  842. }
  843. for _, v := range lisYx {
  844. maplistYx[v.IndustrialManagementId] = v
  845. }
  846. for _, v := range list {
  847. if maplistHz[v.IndustrialManagementId] != nil {
  848. items = append(items, maplistHz[v.IndustrialManagementId])
  849. }
  850. if maplistYx[v.IndustrialManagementId] != nil {
  851. items = append(items, maplistYx[v.IndustrialManagementId])
  852. }
  853. }
  854. return
  855. }
  856. // 通过文章ID获取文章所关联的产业
  857. func GetArticleIndustrialByArticleId(articleIds []int) (itemMap map[int][]*models.IndustrialManagementResp, err error) {
  858. lenarticleIds := len(articleIds)
  859. if lenarticleIds == 0 {
  860. return
  861. }
  862. var condition string
  863. var pars []interface{}
  864. condition = ` AND mg.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
  865. pars = append(pars, articleIds)
  866. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  867. if err != nil {
  868. return
  869. }
  870. industrialMap := make(map[int][]*models.IndustrialManagementResp)
  871. if len(industrialList) > 0 {
  872. for _, v := range industrialList {
  873. item := new(models.IndustrialManagementResp)
  874. item.IndustrialManagementId = v.IndustrialManagementId
  875. item.IndustryName = v.IndustryName
  876. item.ChartPermissionId = v.ChartPermissionId
  877. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  878. }
  879. }
  880. itemMap = industrialMap
  881. return
  882. }
  883. func GetArticleTypeMap() (nameMapResp map[int]string, buttonStyleMapResp map[int]string, err error) {
  884. condition := " AND is_show_yanx = 1 "
  885. list, e := models.GetCygxArticleTypeListCondition(condition)
  886. if e != nil {
  887. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  888. return
  889. }
  890. nameMap := make(map[int]string)
  891. buttonStyleMap := make(map[int]string)
  892. if len(list) > 0 {
  893. for _, v := range list {
  894. nameMap[v.ArticleTypeId] = v.ArticleTypeName
  895. buttonStyleMap[v.ArticleTypeId] = v.ButtonStyle
  896. }
  897. }
  898. nameMapResp = nameMap
  899. buttonStyleMapResp = buttonStyleMap
  900. return
  901. }
  902. // IndustrialManagementHotMapGropuPermission获取近一个月报告阅读数量最多的产业信息 根据行业分组
  903. func IndustrialManagementHotMapGropuPermission() (mapResp map[int]bool, err error) {
  904. var topCond string
  905. var topPars []interface{}
  906. toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  907. if err != nil {
  908. return
  909. }
  910. mapPermission := make(map[int][]*models.IndustrialManagement)
  911. mapPermissionMax := make(map[int]int)
  912. for _, v := range toplist {
  913. item := new(models.IndustrialManagement)
  914. item.ChartPermissionId = v.ChartPermissionId
  915. item.IndustrialManagementId = v.IndustrialManagementId
  916. item.ArticleReadNum = v.ArticleReadNum
  917. mapPermission[v.ChartPermissionId] = append(mapPermission[v.ChartPermissionId], item)
  918. }
  919. for k, v := range mapPermission {
  920. for _, item := range v {
  921. //mapPermissionMax[k] = item.ArticleReadNum
  922. if item.ArticleReadNum > mapPermissionMax[k] {
  923. mapPermissionMax[k] = item.ArticleReadNum
  924. }
  925. }
  926. }
  927. mapResp = make(map[int]bool, 0)
  928. for _, v := range toplist {
  929. if v.ArticleReadNum == mapPermissionMax[v.ChartPermissionId] {
  930. mapResp[v.IndustrialManagementId] = true
  931. }
  932. }
  933. return
  934. }
  935. // GetLyjhTypeMap 获取路演精华对应分类ID
  936. func GetLyjhTypeMap() (mapResp map[int]int, err error) {
  937. defer func() {
  938. if err != nil {
  939. go utils.SendAlarmMsg("获取路演精华对应分类ID失败 ErrMsg:"+err.Error(), 2)
  940. }
  941. }()
  942. condition := " AND match_type_name = '路演精华' "
  943. var pars []interface{}
  944. list, e := models.GetReportMappingList(condition, pars)
  945. if e != nil && e.Error() != utils.ErrNoRow() {
  946. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  947. return
  948. }
  949. mapResp = make(map[int]int, 0)
  950. if len(list) > 0 {
  951. for _, v := range list {
  952. mapResp[v.CategoryId] = v.CategoryId
  953. }
  954. }
  955. return
  956. }
  957. // GetLyjhArticleMap 获取路演精华对应文章ID
  958. func GetLyjhArticleMap() (mapResp map[int]bool, err error) {
  959. defer func() {
  960. if err != nil {
  961. go utils.SendAlarmMsg("获取路演精华对应文章ID失败 ErrMsg:"+err.Error(), 2)
  962. }
  963. }()
  964. condition := " AND match_type_name = '路演精华' "
  965. var pars []interface{}
  966. list, e := models.GetReportMappingList(condition, pars)
  967. if e != nil && e.Error() != utils.ErrNoRow() {
  968. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  969. return
  970. }
  971. var categoryId []int
  972. mapResp = make(map[int]bool, 0)
  973. if len(list) > 0 {
  974. for _, v := range list {
  975. categoryId = append(categoryId, v.CategoryId)
  976. }
  977. }
  978. lencategoryId := len(categoryId)
  979. if lencategoryId > 0 {
  980. pars = make([]interface{}, 0)
  981. condition = ` AND a.category_id IN (` + utils.GetOrmInReplace(lencategoryId) + `)`
  982. pars = append(pars, categoryId)
  983. listArticle, e := models.GetHomeList(condition, pars, 0, 1000)
  984. if e != nil && e.Error() != utils.ErrNoRow() {
  985. err = errors.New("GetResourceDataList, Err: " + e.Error())
  986. return
  987. }
  988. for _, v := range listArticle {
  989. mapResp[v.ArticleId] = true
  990. }
  991. }
  992. return
  993. }
  994. // 获取所有的产业id与名称的map关联
  995. func GetIndustrialManagementRespMap() (itemMap map[int]string, err error) {
  996. defer func() {
  997. if err != nil {
  998. go utils.SendAlarmMsg("GetIndustrialManagementRespMap ErrMsg:"+err.Error(), 2)
  999. }
  1000. }()
  1001. var condition string
  1002. var pars []interface{}
  1003. itemMap = make(map[int]string, 0)
  1004. industrialList, e := models.GetIndustrialManagementRepList(condition, pars, 0, 999999)
  1005. if e != nil {
  1006. err = errors.New("GetIndustrialManagementRepList, Err: " + e.Error())
  1007. return
  1008. }
  1009. if len(industrialList) > 0 {
  1010. for _, v := range industrialList {
  1011. itemMap[v.IndustrialManagementId] = v.IndustryName
  1012. }
  1013. }
  1014. return
  1015. }
  1016. // 获取所有的标的id与名称的map关联
  1017. func GetCygxIndustrialSubjectMap() (itemMap map[int]string, err error) {
  1018. defer func() {
  1019. if err != nil {
  1020. go utils.SendAlarmMsg("GetCygxIndustrialSubjectMap ErrMsg:"+err.Error(), 2)
  1021. }
  1022. }()
  1023. var condition string
  1024. var pars []interface{}
  1025. itemMap = make(map[int]string, 0)
  1026. list, e := models.GetCygxIndustrialSubjectListCondition(condition, pars)
  1027. if e != nil {
  1028. err = errors.New("GetIndustrialManagementRepList, Err: " + e.Error())
  1029. return
  1030. }
  1031. if len(list) > 0 {
  1032. for _, v := range list {
  1033. itemMap[v.IndustrialSubjectId] = v.SubjectName
  1034. }
  1035. }
  1036. return
  1037. }
  1038. //func init() {
  1039. // UpdateIndustrialManagementOneMonthFollowNum()
  1040. //}
  1041. // UpdateIndustrialManagementOneMonthFollowNum 更新产业近一个月被关注的数量
  1042. func UpdateIndustrialManagementOneMonthFollowNum(cont context.Context) (err error) {
  1043. //var err error
  1044. defer func() {
  1045. if err != nil {
  1046. fmt.Println(err)
  1047. go utils.SendAlarmMsg("UpdateIndustrialManagementOneMonthFollowNum ErrMsg:"+err.Error(), 2)
  1048. }
  1049. }()
  1050. listNum, e := models.GetIndustrialManagementOneMonthFollowNum()
  1051. if e != nil {
  1052. err = errors.New("GetIndustrialManagementOneMonthFollowNum, Err: " + e.Error())
  1053. return
  1054. }
  1055. e = models.UpdateIndustrialManagementInit() //初始化每月产业用户关注数量
  1056. if e != nil {
  1057. err = errors.New("UpdateIndustrialManagementInit, Err: " + e.Error())
  1058. return
  1059. }
  1060. var items []*models.CygxIndustryFllowNumResp
  1061. for _, v := range listNum {
  1062. item := new(models.CygxIndustryFllowNumResp)
  1063. item.IndustrialManagementId = v.IndustrialManagementId
  1064. item.Total = v.Total
  1065. items = append(items, item)
  1066. //一次最多插入五百条
  1067. if len(items)%500 == 0 {
  1068. e = models.UpdateIndustrialManagementOneMonthFollowNumMulti(items)
  1069. if e != nil {
  1070. err = errors.New("UpdateIndustrialManagementOneMonthFollowNumMulti, Err: " + e.Error())
  1071. return
  1072. }
  1073. }
  1074. }
  1075. if len(items) > 0 {
  1076. e = models.UpdateIndustrialManagementOneMonthFollowNumMulti(items)
  1077. if e != nil {
  1078. err = errors.New("UpdateIndustrialManagementOneMonthFollowNumMulti, Err: " + e.Error())
  1079. return
  1080. }
  1081. }
  1082. return
  1083. }
  1084. //func init_14-2() {
  1085. // //IndustrialManagementTimeLineDateList3(127)
  1086. //
  1087. // list, err := models.IndustrialManagementAll()
  1088. // if err != nil {
  1089. // fmt.Println("Error marshaling to JSON:", err)
  1090. // return
  1091. // }
  1092. // fmt.Println(len(list))
  1093. // for k, v := range list {
  1094. // fmt.Println(k)
  1095. // time.Sleep(200 * time.Millisecond)
  1096. // if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  1097. // continue
  1098. // }
  1099. // IndustrialManagementTimeLineDateList3(v.IndustrialManagementId)
  1100. // }
  1101. //}
  1102. //func init() {
  1103. // init_14_2()
  1104. //}
  1105. //初始化文章搜索匹配内容
  1106. //func init_14_2() {
  1107. // //IndustrialManagementTimeLineDateList3(127)
  1108. // var conditionContent string
  1109. // var parsContent []interface{}
  1110. //
  1111. // conditionContent = " AND source = 'article' "
  1112. // list, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, 99999)
  1113. // if e != nil && e.Error() != utils.ErrNoRow() {
  1114. // fmt.Println(e)
  1115. // return
  1116. // }
  1117. //
  1118. // var itemsUpdate []*models.CygxArticle
  1119. // for k, v := range list {
  1120. // fmt.Println(k)
  1121. // item := new(models.CygxArticle)
  1122. // item.ArticleId = v.SourceId
  1123. // item.ArticleSearchContent = v.SearchContent
  1124. // itemsUpdate = append(itemsUpdate, item)
  1125. // }
  1126. // e = models.UpdateCygxCygxArticleBillMulti(itemsUpdate)
  1127. // if e != nil && e.Error() != utils.ErrNoRow() {
  1128. // fmt.Println(e)
  1129. // return
  1130. // }
  1131. // fmt.Println("end")
  1132. //}
  1133. // 时间线关联文章的三条数据
  1134. func IndustrialManagementTimeLineDateList3(industrialManagementId int) (err error) {
  1135. defer func() {
  1136. if err != nil {
  1137. fmt.Println(err)
  1138. go utils.SendAlarmMsg("修改时间线关联文章的三条数据信息失败"+err.Error(), 2)
  1139. }
  1140. }()
  1141. list, e := models.GetTimeLineReportIndustrialList(0, industrialManagementId, 0, 3)
  1142. if e != nil {
  1143. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  1144. return
  1145. }
  1146. type TimeLineReportItem struct {
  1147. Title string `description:"标题"`
  1148. PublishDate string `description:"发布时间"`
  1149. }
  1150. var listData []*TimeLineReportItem
  1151. for _, v := range list {
  1152. item := new(TimeLineReportItem)
  1153. if v.Resource == 3 {
  1154. item.Title, _ = extractTextBeforePeriodOrNewline(v.Content)
  1155. fmt.Println("Title", item.Title)
  1156. } else {
  1157. item.Title = v.Title
  1158. }
  1159. item.PublishDate = utils.TimeRemoveHms2(v.PublishTime)
  1160. listData = append(listData, item)
  1161. }
  1162. jsonData, err := json.Marshal(listData)
  1163. if err != nil {
  1164. fmt.Println("Error marshaling to JSON:", err)
  1165. return
  1166. }
  1167. err = models.UpdateIndustrialManagementTimeLineData(industrialManagementId, string(jsonData))
  1168. return err
  1169. }
  1170. func extractTextBeforePeriodOrNewline(htmlContent string) (string, error) {
  1171. var builder strings.Builder
  1172. reader := strings.NewReader(htmlContent)
  1173. z := html.NewTokenizer(reader)
  1174. for {
  1175. tokenType := z.Next()
  1176. switch tokenType {
  1177. case html.ErrorToken:
  1178. // End of document
  1179. return builder.String(), nil
  1180. case html.TextToken:
  1181. text := string(z.Text())
  1182. //fmt.Println("text", text)
  1183. if idx := strings.Index(text, "。"); idx != -1 {
  1184. builder.WriteString(text[:idx+len("。")])
  1185. return builder.String(), nil
  1186. } else {
  1187. return text, nil
  1188. }
  1189. builder.WriteString(text)
  1190. }
  1191. }
  1192. }
  1193. // 处理产业管理时间线相关内容的数据
  1194. func UpdateIndustrialManagementTimeLineDateList3ByRedis() (err error) {
  1195. for {
  1196. utils.Rc.Brpop(utils.CYGX_ARTICLE_TIME_LINE_KEY, func(b []byte) {
  1197. var log models.IndustrialManagementCount
  1198. if err := json.Unmarshal(b, &log); err != nil {
  1199. fmt.Println("json unmarshal wrong!")
  1200. go utils.SendAlarmMsg("处理产业管理时间线相关内容的数据处理Redis队列消息失败: UpdateIndustrialManagementTimeLineDateList3ByRedis "+err.Error()+string(b), 2)
  1201. }
  1202. IndustrialManagementTimeLineDateList3(log.IndustrialManagementId)
  1203. })
  1204. }
  1205. }
  1206. //func init_14_2() {
  1207. //SELECT * FROM cygx_resource_data WHERE source_id IN (SELECT article_id FROM cygx_article WHERE series_name IN ('行业深度','季度策略') ) AND source = 'article'
  1208. //}