industrial_management.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // 修改标签状态
  13. func UpdateIndustrialManagementLabel(cont context.Context) (err error) {
  14. defer func() {
  15. if err != nil {
  16. fmt.Println("修改失败,Err:", err.Error())
  17. }
  18. }()
  19. fmt.Println("修改状态0000")
  20. go models.UpdateIndustrialIsNewLabel()
  21. list, err := models.GetIndustrialMorethan10()
  22. if err != nil {
  23. return err
  24. }
  25. if len(list) == 0 {
  26. return
  27. }
  28. var idStr string
  29. for _, v := range list {
  30. idStr += v.IndustrialManagementId + ","
  31. }
  32. idStr = strings.TrimRight(idStr, ",")
  33. go models.UpdateIndustrialIsDeepLabel(idStr)
  34. //fmt.Println(idStr)
  35. //go models.UpdateActivitySattusToComplete()
  36. fmt.Println("修改状态完成")
  37. return
  38. }
  39. // 修改状态
  40. func UpdateIndustrialManagementSubjectNnames() (err error) {
  41. defer func() {
  42. if err != nil {
  43. fmt.Println("修改失败,Err:", err.Error())
  44. }
  45. }()
  46. fmt.Println("修改产业关联标的")
  47. list, err := models.GetIndustrialManagementIds()
  48. if err != nil {
  49. return err
  50. }
  51. for _, v := range list {
  52. //fmt.Println(v.IndustrialManagementId)
  53. var nameSub string
  54. listSub, errdSub := models.GetcygxIndustrialSubject(v.IndustrialManagementId)
  55. if errdSub != nil {
  56. return errdSub
  57. }
  58. for _, v2 := range listSub {
  59. fmt.Println(v2.SubjectName)
  60. nameSub += v2.SubjectName + ","
  61. }
  62. nameSub += v.IndustryName
  63. go models.UpdateIndustrialManagementSubjectNames(nameSub, v.IndustrialManagementId)
  64. }
  65. if len(list) == 0 {
  66. return
  67. }
  68. fmt.Println("修改状态完成")
  69. return
  70. }
  71. func ChageIndustrialArticleNum(cont context.Context) (err error) {
  72. IndustrialHzArticleNumUpdate()
  73. IndustrialYxArticleNumUpdate()
  74. IndustrialActivityNumUpdate()
  75. return
  76. }
  77. //func init() {
  78. // IndustrialHzArticleNumUpdate()
  79. // IndustrialYxArticleNumUpdate()
  80. // IndustrialActivityNumUpdate()
  81. //}
  82. // 更改弘则对应的报告关联产业近一个月的阅读量
  83. func IndustrialHzArticleNumUpdate() (err error) {
  84. defer func() {
  85. if err != nil {
  86. //fmt.Println(err)
  87. go utils.SendAlarmMsg("更改弘则对应的报告关联产业近一个月的阅读量失败"+err.Error(), 2)
  88. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"更改弘则对应的报告关联产业近一个月的阅读量失败失败提醒", err.Error(), utils.EmailSendToUsers)
  89. }
  90. }()
  91. err = models.UpdateIndustrialManagementArtticleReadNum()
  92. if err != nil {
  93. return
  94. }
  95. articleTypeIds, err := GetYanXuanArticleTypeIds()
  96. if err != nil {
  97. return
  98. }
  99. var condition string
  100. if articleTypeIds == "" {
  101. return
  102. }
  103. condition = ` AND a.article_type_id NOT IN (` + articleTypeIds + `) `
  104. list, err := models.GetIndustrialManagementArtHistoryCount(condition)
  105. if err != nil {
  106. return
  107. }
  108. for _, v := range list {
  109. err = models.UpdateIndustrialManagementArtReadNum(v.Count, v.IndustrialManagementId)
  110. if err != nil {
  111. return
  112. }
  113. }
  114. return err
  115. }
  116. // 更改研选对应的报告关联产业近一个月的阅读量
  117. func IndustrialYxArticleNumUpdate() (err error) {
  118. defer func() {
  119. if err != nil {
  120. //fmt.Println(err)
  121. go utils.SendAlarmMsg("更改研选对应的报告关联产业近一个月的阅读量失败"+err.Error(), 2)
  122. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"更改研选对应的报告关联产业近一个月的阅读量失败提醒", err.Error(), utils.EmailSendToUsers)
  123. }
  124. }()
  125. articleTypeIds, err := GetYanXuanArticleTypeIds()
  126. if err != nil {
  127. return
  128. }
  129. var condition string
  130. if articleTypeIds == "" {
  131. return
  132. }
  133. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  134. list, err := models.GetIndustrialManagementArtHistoryCount(condition)
  135. if err != nil {
  136. return
  137. }
  138. for _, v := range list {
  139. err = models.UpdateIndustrialManagementArtYanXuanReadNum(v.Count, v.IndustrialManagementId)
  140. if err != nil {
  141. return
  142. }
  143. }
  144. return err
  145. }
  146. // 更改活动关联产业近一个月的到会量
  147. func IndustrialActivityNumUpdate() (err error) {
  148. defer func() {
  149. if err != nil {
  150. //fmt.Println(err)
  151. go utils.SendAlarmMsg("更改活动关联产业近一个月的到会量失败"+err.Error(), 2)
  152. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"更改活动关联产业近一个月的到会量失败", err.Error(), utils.EmailSendToUsers)
  153. }
  154. }()
  155. list, err := models.GetIndustrialManagementActivityHistoryCount()
  156. if err != nil {
  157. return
  158. }
  159. for _, v := range list {
  160. err = models.UpdateIndustrialManagementActivityNum(v.Count, v.IndustrialManagementId)
  161. if err != nil {
  162. return
  163. }
  164. }
  165. return err
  166. }
  167. func ReportBillboardUpdate(cont context.Context) (err error) {
  168. //修改产业关注数量
  169. go IndustryFllowCountUpdate()
  170. //修改文章收藏数量
  171. go ArticleCollectCountUpdate()
  172. return
  173. }
  174. // 修改产业关注数量
  175. func IndustryFllowCountUpdate() (err error) {
  176. defer func() {
  177. if err != nil {
  178. go utils.SendAlarmMsg("修改产业关注数量信息失败"+err.Error(), 2)
  179. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  180. }
  181. }()
  182. fllowList, err := models.GetUserFllowIndustrialCountList()
  183. if err != nil {
  184. return
  185. }
  186. for _, v := range fllowList {
  187. err = models.UpdateIndustrialManagementFllowNum(v.Num, v.IndustrialManagementId)
  188. if err != nil {
  189. return
  190. }
  191. }
  192. return err
  193. }
  194. // 修改文章收藏数量
  195. func ArticleCollectCountUpdate() (err error) {
  196. defer func() {
  197. if err != nil {
  198. go utils.SendAlarmMsg("修改文章收藏数量信息失败"+err.Error(), 2)
  199. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改文章收藏数量信息失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  200. }
  201. }()
  202. collectList, err := models.GetUserArticleCollectList()
  203. if err != nil {
  204. return
  205. }
  206. for _, v := range collectList {
  207. err = models.UpdateArticleCollectCountNum(v.Num, v.ArticleId)
  208. if err != nil {
  209. return
  210. }
  211. }
  212. return err
  213. }
  214. // 根据行业处理所选的全部赛道字段
  215. func DoXzsChooseSend(chartPermissionName string) string {
  216. var allIn string
  217. if chartPermissionName == utils.YI_YAO_NAME {
  218. allIn = "all_in_yi_yao"
  219. } else if chartPermissionName == utils.XIAO_FEI_NAME {
  220. allIn = "all_in_xiao_fei"
  221. } else if chartPermissionName == utils.KE_JI_NAME {
  222. allIn = "all_in_ke_ji"
  223. } else if chartPermissionName == utils.ZHI_ZAO_NAME {
  224. allIn = "all_in_zhi_zao"
  225. } else if chartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  226. allIn = "all_in_yan_xuan"
  227. }
  228. return allIn
  229. }
  230. // 行业关注或者取消关注的时候,对于用户全部赛道的影响
  231. func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error) {
  232. defer func() {
  233. if err != nil {
  234. fmt.Println(err)
  235. go utils.SendAlarmMsg("修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败"+err.Error(), 2)
  236. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  237. }
  238. }()
  239. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  240. if err != nil {
  241. return err
  242. }
  243. categoryinfo, err := models.GetChartPermissionById(detail.ChartPermissionId)
  244. if err != nil {
  245. return err
  246. }
  247. var allIn string
  248. allIn = DoXzsChooseSend(categoryinfo.PermissionName)
  249. if allIn != "" {
  250. //如果取消关注就把该赛道设置为非全部赛道
  251. if count == 1 {
  252. err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 0, uid)
  253. if err != nil {
  254. return err
  255. }
  256. } else {
  257. //医药、消费、科技、智造、研选下的产业赛道
  258. mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  259. industrialList, err := models.GetindustrialManagement()
  260. if err != nil {
  261. return err
  262. }
  263. for _, v := range industrialList {
  264. mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  265. }
  266. fllowNum, err := models.GetCountCygxIndustryFllowByUidAndChartPermissionId(uid, detail.ChartPermissionId)
  267. if err != nil {
  268. return err
  269. }
  270. if fllowNum == len(mapIndustrial[detail.ChartPermissionId]) {
  271. err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 1, uid)
  272. if err != nil {
  273. return err
  274. }
  275. }
  276. }
  277. }
  278. return err
  279. }
  280. //func init() {
  281. //IndustryFllowUserLabel(136, 16, 5660)
  282. //UserLabelLogReduce()
  283. //}
  284. // GetIndustryNewLabelMap 获取产业【新】标签Map
  285. func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
  286. labelMap = make(map[int]bool, 0)
  287. industryIdLen := len(industryIds)
  288. if industryIdLen == 0 {
  289. return
  290. }
  291. // 获取产业关联的报告最早发布时间及最近的发布时间
  292. var timeCond string
  293. var timePars []interface{}
  294. timeCond += ` AND b.publish_status = 1`
  295. if industryIdLen > 0 {
  296. timeCond += ` AND a.industrial_management_id IN (` + utils.GetOrmInReplace(industryIdLen) + `)`
  297. timePars = append(timePars, industryIds)
  298. }
  299. //只要弘则报告,不要研选报告
  300. timeCond += ` AND b.article_id < ? `
  301. timePars = append(timePars, utils.SummaryArticleId)
  302. industryTimeList, e := models.GetIndustryArticleMinMaxPublishTime(timeCond, timePars)
  303. if e != nil {
  304. err = errors.New("获取产业文章最大最小发布时间失败, Err: " + e.Error())
  305. return
  306. }
  307. // 判断产业是否为新
  308. nowTime := time.Now().Local()
  309. threeMonthBefore := nowTime.AddDate(0, -3, 0)
  310. nullTime, _ := time.ParseInLocation(utils.FormatDateTime, "0001-01-01 00:00:00", time.Local)
  311. industryMap := make(map[int]*models.IndustryArticleMinMaxPublishTime, 0)
  312. for i := range industryTimeList {
  313. industryMap[industryTimeList[i].IndustrialManagementId] = industryTimeList[i]
  314. }
  315. for i := range industryIds {
  316. iid := industryIds[i]
  317. item := industryMap[iid]
  318. if item != nil {
  319. // 最早发布时间为空 / 最早发布时间在三个月前之后
  320. if item.MinPublishTime.Equal(nullTime) || (item.MinPublishTime.After(threeMonthBefore)) {
  321. labelMap[iid] = true
  322. }
  323. } else {
  324. // 产业无报告, 则为新产业
  325. labelMap[iid] = true
  326. }
  327. }
  328. return
  329. }
  330. //func init() {
  331. // GetIndustrialManagementArticleNewPublishData()
  332. //}
  333. // 批量修改获取产业关联文章的最新发布时间
  334. func GetIndustrialManagementArticleNewPublishData() (err error) {
  335. defer func() {
  336. if err != nil {
  337. go utils.SendAlarmMsg("批量修改获取产业关联文章的最新发布时间"+"GetIndustrialManagementArticleNewPublishData ErrMsg:"+err.Error(), 2)
  338. }
  339. }()
  340. articleNewPublishDataList, e := models.GetIndustrialManagementArticleNewPublishData()
  341. if e != nil {
  342. err = errors.New("获取客户剩余报名次数失败 GetIndustrialManagementArticleNewPublishData, Err: " + e.Error())
  343. return
  344. }
  345. mapUPdateTime := make(map[int]string)
  346. var industrialManagementIds []int
  347. for _, v := range articleNewPublishDataList {
  348. if v.IndustrialManagementId > 0 {
  349. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  350. }
  351. mapUPdateTime[v.IndustrialManagementId] = v.UpdateTime
  352. }
  353. //时间线的更新时间
  354. listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialManagementIds)
  355. if err != nil && err.Error() != utils.ErrNoRow() {
  356. return
  357. }
  358. for _, v := range listtimelinePublishdate {
  359. if mapUPdateTime[v.IndustrialManagementId] != "" {
  360. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  361. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  362. }
  363. }
  364. }
  365. err = models.UpdateIndustrialManagementArticleNewPublishData(mapUPdateTime)
  366. return
  367. }
  368. // HandleIndustryList预处理产业列表字段
  369. func HandleIndustryList(list []*models.IndustrialManagement, user *models.WxUserItem) (items []*models.IndustrialManagement, err error) {
  370. userId := user.UserId
  371. fllowList, err := models.GetUserFllowIndustrialList(userId)
  372. if err != nil {
  373. return
  374. }
  375. fllowMap := make(map[int]int)
  376. if len(fllowList) > 0 {
  377. for _, v := range fllowList {
  378. fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
  379. }
  380. }
  381. mapindustrialId, e := GetMicroRoadshowVideoMap()
  382. if e != nil {
  383. err = e
  384. return
  385. }
  386. //合并产业关联的标的
  387. listSubjcet, err := models.GetThemeHeatSubjectList("")
  388. if err != nil {
  389. return
  390. }
  391. industrialIdArr := make([]int, 0)
  392. for k, v := range list {
  393. list[k].Source = 1
  394. if fllowMap[v.IndustrialManagementId] > 0 {
  395. list[k].IsFollow = 1
  396. }
  397. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  398. if _, ok := mapindustrialId[v.IndustrialManagementId]; !ok {
  399. continue
  400. }
  401. videoSimple, au, e := GetindustryVideo(user, v.IndustrialManagementId)
  402. if e != nil {
  403. err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
  404. return
  405. }
  406. if videoSimple != nil && videoSimple.Id > 0 {
  407. v.IndustryVideo = videoSimple
  408. }
  409. v.AuthInfo = au
  410. }
  411. if len(industrialIdArr) > 0 {
  412. //合并产业关联的标的
  413. listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
  414. if err != nil {
  415. return
  416. }
  417. mapIndustrial := make(map[string]int)
  418. for _, v := range listSubjcet {
  419. for k2, v2 := range list {
  420. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  421. list[k2].IndustrialSubjectList = append(list[k2].IndustrialSubjectList, v)
  422. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
  423. }
  424. }
  425. }
  426. }
  427. mapUPdateTime := make(map[int]string)
  428. articleIdArr := make([]int, 0)
  429. //获取这些产业下最新更新的文章
  430. listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
  431. if err != nil && err.Error() != utils.ErrNoRow() {
  432. return
  433. }
  434. for _, v := range listUpdateTime {
  435. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  436. articleIdArr = append(articleIdArr, v.ArticleId)
  437. }
  438. //时间线的更新时间
  439. // maptimelineUPdateTime := make(map[int]string)
  440. listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialIdArr)
  441. if err != nil && err.Error() != utils.ErrNoRow() {
  442. return
  443. }
  444. for _, v := range listtimelinePublishdate {
  445. if mapUPdateTime[v.IndustrialManagementId] != "" {
  446. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  447. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  448. }
  449. }
  450. }
  451. //产品内测的更新时间线
  452. listtProductInterior, err := models.GetNewProductInteriorByIndustrialIds(industrialIdArr)
  453. if err != nil && err.Error() != utils.ErrNoRow() {
  454. return
  455. }
  456. for _, v := range listtProductInterior {
  457. if mapUPdateTime[v.IndustrialManagementId] != "" {
  458. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  459. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  460. }
  461. }
  462. }
  463. //mapHistroyArticleId := make(map[int]int)
  464. //if userId > 0 {
  465. // listArticleHistory, e := models.GetUserToArticleHistory(userId, articleIdArr)
  466. // if e != nil && e.Error() != utils.ErrNoRow() {
  467. // err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
  468. // return
  469. // }
  470. // for _, v := range listArticleHistory {
  471. // mapHistroyArticleId[v.ArticleId] = v.ArticleId
  472. // }
  473. //}
  474. var industrialIds string
  475. for _, id := range industrialIdArr {
  476. industrialIds += strconv.Itoa(id) + ","
  477. }
  478. industrialIds = strings.TrimRight(industrialIds, ",")
  479. articleList, err := models.GetReportIndustrialReadNumList(userId, industrialIds, user.CreatedTime)
  480. mapHistroyindustrialId := make(map[int]int)
  481. for _, v := range articleList {
  482. mapHistroyindustrialId[v.IndustrialManagementId] = v.Readnum
  483. }
  484. nowTime := time.Now().Local()
  485. threeMonBefore := nowTime.AddDate(0, -3, 0)
  486. //查询用户今天是否看过时间线
  487. //haveMorningMeeting := false
  488. //var morningMeetingTime string
  489. recrodList, err := models.GetCygxTimelineLogCount(user.UserId, industrialIdArr)
  490. if err != nil && err.Error() != utils.ErrNoRow() {
  491. return
  492. }
  493. var industrialManagementIdstr string
  494. industrialIdMap := make(map[string]time.Time)
  495. for _, v := range recrodList {
  496. industrialManagementIdstr = strconv.Itoa(v.IndustrialManagementId)
  497. industrialIdMap[industrialManagementIdstr] = v.ModifyTime
  498. //industrialManagementIdstr = strings.TrimLeft(v.Parameter, "PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=")
  499. //if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
  500. // if createTime.Before(v.CreateTime) {
  501. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  502. // }
  503. //} else {
  504. // industrialIdMap[industrialManagementIdstr] = v.CreateTime
  505. //}
  506. }
  507. mmList, err := models.GetCygxMorningMeetingReviewsListByIndustrialIds(industrialIds)
  508. if err != nil {
  509. return
  510. }
  511. morningMeetingTimeMap := make(map[int]time.Time)
  512. for _, v := range mmList {
  513. morningMeetingTimeMap[v.IndustryId] = v.CreateTime
  514. }
  515. timeLineRedMap := make(map[int]bool, 0)
  516. for _, industrialId := range industrialIdArr {
  517. if createTime, ok := industrialIdMap[strconv.Itoa(industrialId)]; ok {
  518. if createTime.Before(morningMeetingTimeMap[industrialId]) {
  519. timeLineRedMap[industrialId] = true
  520. }
  521. }
  522. }
  523. hotMapindustrial, err := IndustrialManagementHotMapGropuPermission()
  524. if err != nil {
  525. return
  526. }
  527. for k, v := range list {
  528. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  529. list[k].IsHot = hotMapindustrial[v.IndustrialManagementId]
  530. if userId > 0 {
  531. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  532. if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] {
  533. if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  534. list[k].IsRed = true
  535. }
  536. }
  537. } else {
  538. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  539. list[k].IsRed = true
  540. }
  541. list[k].IsFollow = 0
  542. }
  543. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  544. if userId > 0 {
  545. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  546. if mapHistroyindustrialId[v.IndustrialManagementId] == 0 || timeLineRedMap[v.IndustrialManagementId] {
  547. if user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  548. list[k].IsRed = true
  549. }
  550. }
  551. } else {
  552. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  553. list[k].IsRed = true
  554. }
  555. list[k].IsFollow = 0
  556. }
  557. // 关联报告发布时间均在3个月内则标记New
  558. if v.MinReportTime != "" {
  559. t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
  560. if e != nil {
  561. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  562. return
  563. }
  564. if t.After(threeMonBefore) {
  565. list[k].IsNew = true
  566. }
  567. }
  568. }
  569. items = list
  570. return
  571. }
  572. // 通过文章ID获取文章所关联的产业
  573. func GetArticleIndustrialByArticleId(articleIds []int) (itemMap map[int][]*models.IndustrialManagementResp, err error) {
  574. lenarticleIds := len(articleIds)
  575. if lenarticleIds == 0 {
  576. return
  577. }
  578. var condition string
  579. var pars []interface{}
  580. condition = ` AND mg.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
  581. pars = append(pars, articleIds)
  582. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  583. if err != nil {
  584. return
  585. }
  586. industrialMap := make(map[int][]*models.IndustrialManagementResp)
  587. if len(industrialList) > 0 {
  588. for _, v := range industrialList {
  589. item := new(models.IndustrialManagementResp)
  590. item.IndustrialManagementId = v.IndustrialManagementId
  591. item.IndustryName = v.IndustryName
  592. item.ChartPermissionId = v.ChartPermissionId
  593. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  594. }
  595. }
  596. itemMap = industrialMap
  597. return
  598. }
  599. func GetArticleTypeMap() (nameMapResp map[int]string, buttonStyleMapResp map[int]string, err error) {
  600. condition := " AND is_show_yanx = 1 "
  601. list, e := models.GetCygxArticleTypeListCondition(condition)
  602. if e != nil {
  603. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  604. return
  605. }
  606. nameMap := make(map[int]string)
  607. buttonStyleMap := make(map[int]string)
  608. if len(list) > 0 {
  609. for _, v := range list {
  610. nameMap[v.ArticleTypeId] = v.ArticleTypeName
  611. buttonStyleMap[v.ArticleTypeId] = v.ButtonStyle
  612. }
  613. }
  614. nameMapResp = nameMap
  615. buttonStyleMapResp = buttonStyleMap
  616. return
  617. }
  618. // IndustrialManagementHotMapGropuPermission获取近一个月报告阅读数量最多的产业信息 根据行业分组
  619. func IndustrialManagementHotMapGropuPermission() (mapResp map[int]bool, err error) {
  620. var topCond string
  621. var topPars []interface{}
  622. toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
  623. if err != nil {
  624. return
  625. }
  626. mapPermission := make(map[int][]*models.IndustrialManagement)
  627. mapPermissionMax := make(map[int]int)
  628. for _, v := range toplist {
  629. item := new(models.IndustrialManagement)
  630. item.ChartPermissionId = v.ChartPermissionId
  631. item.IndustrialManagementId = v.IndustrialManagementId
  632. item.ArticleReadNum = v.ArticleReadNum
  633. mapPermission[v.ChartPermissionId] = append(mapPermission[v.ChartPermissionId], item)
  634. }
  635. for k, v := range mapPermission {
  636. for _, item := range v {
  637. //mapPermissionMax[k] = item.ArticleReadNum
  638. if item.ArticleReadNum > mapPermissionMax[k] {
  639. mapPermissionMax[k] = item.ArticleReadNum
  640. }
  641. }
  642. }
  643. mapResp = make(map[int]bool, 0)
  644. for _, v := range toplist {
  645. if v.ArticleReadNum == mapPermissionMax[v.ChartPermissionId] {
  646. mapResp[v.IndustrialManagementId] = true
  647. }
  648. }
  649. return
  650. }
  651. // GetLyjhTypeMap 获取路演精华对应分类ID
  652. func GetLyjhTypeMap() (mapResp map[int]int, err error) {
  653. defer func() {
  654. if err != nil {
  655. go utils.SendAlarmMsg("获取路演精华对应分类ID失败 ErrMsg:"+err.Error(), 2)
  656. }
  657. }()
  658. condition := " AND match_type_name = '路演精华' "
  659. var pars []interface{}
  660. list, e := models.GetReportMappingList(condition, pars)
  661. if e != nil && e.Error() != utils.ErrNoRow() {
  662. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  663. return
  664. }
  665. mapResp = make(map[int]int, 0)
  666. if len(list) > 0 {
  667. for _, v := range list {
  668. mapResp[v.CategoryId] = v.CategoryId
  669. }
  670. }
  671. return
  672. }
  673. // GetLyjhArticleMap 获取路演精华对应文章ID
  674. func GetLyjhArticleMap() (mapResp map[int]bool, err error) {
  675. defer func() {
  676. if err != nil {
  677. go utils.SendAlarmMsg("获取路演精华对应文章ID失败 ErrMsg:"+err.Error(), 2)
  678. }
  679. }()
  680. condition := " AND match_type_name = '路演精华' "
  681. var pars []interface{}
  682. list, e := models.GetReportMappingList(condition, pars)
  683. if e != nil && e.Error() != utils.ErrNoRow() {
  684. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  685. return
  686. }
  687. var categoryId []int
  688. mapResp = make(map[int]bool, 0)
  689. if len(list) > 0 {
  690. for _, v := range list {
  691. categoryId = append(categoryId, v.CategoryId)
  692. }
  693. }
  694. lencategoryId := len(categoryId)
  695. if lencategoryId > 0 {
  696. pars = make([]interface{}, 0)
  697. condition = ` AND a.category_id IN (` + utils.GetOrmInReplace(lencategoryId) + `)`
  698. pars = append(pars, categoryId)
  699. listArticle, e := models.GetHomeList(condition, pars, 0, 1000)
  700. if e != nil && e.Error() != utils.ErrNoRow() {
  701. err = errors.New("GetResourceDataList, Err: " + e.Error())
  702. return
  703. }
  704. for _, v := range listArticle {
  705. mapResp[v.ArticleId] = true
  706. }
  707. }
  708. return
  709. }
  710. // 获取所有的产业id与名称的map关联
  711. func GetIndustrialManagementRespMap() (itemMap map[int]string, err error) {
  712. defer func() {
  713. if err != nil {
  714. go utils.SendAlarmMsg("GetIndustrialManagementRespMap ErrMsg:"+err.Error(), 2)
  715. }
  716. }()
  717. var condition string
  718. var pars []interface{}
  719. itemMap = make(map[int]string, 0)
  720. industrialList, e := models.GetIndustrialManagementRepList(condition, pars, 0, 999999)
  721. if e != nil {
  722. err = errors.New("GetIndustrialManagementRepList, Err: " + e.Error())
  723. return
  724. }
  725. if len(industrialList) > 0 {
  726. for _, v := range industrialList {
  727. itemMap[v.IndustrialManagementId] = v.IndustryName
  728. }
  729. }
  730. return
  731. }
  732. // 获取所有的标的id与名称的map关联
  733. func GetCygxIndustrialSubjectMap() (itemMap map[int]string, err error) {
  734. defer func() {
  735. if err != nil {
  736. go utils.SendAlarmMsg("GetCygxIndustrialSubjectMap ErrMsg:"+err.Error(), 2)
  737. }
  738. }()
  739. var condition string
  740. var pars []interface{}
  741. itemMap = make(map[int]string, 0)
  742. list, e := models.GetCygxIndustrialSubjectListCondition(condition, pars)
  743. if e != nil {
  744. err = errors.New("GetIndustrialManagementRepList, Err: " + e.Error())
  745. return
  746. }
  747. if len(list) > 0 {
  748. for _, v := range list {
  749. itemMap[v.IndustrialSubjectId] = v.SubjectName
  750. }
  751. }
  752. return
  753. }
  754. //func init() {
  755. // UpdateIndustrialManagementOneMonthFollowNum()
  756. //}
  757. // UpdateIndustrialManagementOneMonthFollowNum 更新产业近一个月被关注的数量
  758. func UpdateIndustrialManagementOneMonthFollowNum(cont context.Context) (err error) {
  759. //var err error
  760. defer func() {
  761. if err != nil {
  762. fmt.Println(err)
  763. go utils.SendAlarmMsg("UpdateIndustrialManagementOneMonthFollowNum ErrMsg:"+err.Error(), 2)
  764. }
  765. }()
  766. listNum, e := models.GetIndustrialManagementOneMonthFollowNum()
  767. if e != nil {
  768. err = errors.New("GetIndustrialManagementOneMonthFollowNum, Err: " + e.Error())
  769. return
  770. }
  771. e = models.UpdateIndustrialManagementInit() //初始化每月产业用户关注数量
  772. if e != nil {
  773. err = errors.New("UpdateIndustrialManagementInit, Err: " + e.Error())
  774. return
  775. }
  776. var items []*models.CygxIndustryFllowNumResp
  777. for _, v := range listNum {
  778. item := new(models.CygxIndustryFllowNumResp)
  779. item.IndustrialManagementId = v.IndustrialManagementId
  780. item.Total = v.Total
  781. items = append(items, item)
  782. //一次最多插入五百条
  783. if len(items)%500 == 0 {
  784. e = models.UpdateIndustrialManagementOneMonthFollowNumMulti(items)
  785. if e != nil {
  786. err = errors.New("UpdateIndustrialManagementOneMonthFollowNumMulti, Err: " + e.Error())
  787. return
  788. }
  789. }
  790. }
  791. if len(items) > 0 {
  792. e = models.UpdateIndustrialManagementOneMonthFollowNumMulti(items)
  793. if e != nil {
  794. err = errors.New("UpdateIndustrialManagementOneMonthFollowNumMulti, Err: " + e.Error())
  795. return
  796. }
  797. }
  798. return
  799. }