industrial_management.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_mfyx/models"
  5. "hongze/hongze_mfyx/utils"
  6. "time"
  7. )
  8. // GetIndustryNewLabelMap 获取产业【新】标签Map
  9. func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
  10. labelMap = make(map[int]bool, 0)
  11. industryIdLen := len(industryIds)
  12. if industryIdLen == 0 {
  13. return
  14. }
  15. // 获取产业关联的报告最早发布时间及最近的发布时间
  16. var timeCond string
  17. var timePars []interface{}
  18. timeCond += ` AND b.publish_status = 1`
  19. if industryIdLen > 0 {
  20. timeCond += ` AND a.industrial_management_id IN (` + utils.GetOrmInReplace(industryIdLen) + `)`
  21. timePars = append(timePars, industryIds)
  22. }
  23. //只要弘则报告,不要研选报告
  24. timeCond += ` AND b.article_id < ? `
  25. timePars = append(timePars, utils.SummaryArticleId)
  26. industryTimeList, e := models.GetIndustryArticleMinMaxPublishTime(timeCond, timePars)
  27. if e != nil {
  28. err = errors.New("获取产业文章最大最小发布时间失败, Err: " + e.Error())
  29. return
  30. }
  31. // 判断产业是否为新
  32. nowTime := time.Now().Local()
  33. threeMonthBefore := nowTime.AddDate(0, -3, 0)
  34. nullTime, _ := time.ParseInLocation(utils.FormatDateTime, "0001-01-01 00:00:00", time.Local)
  35. industryMap := make(map[int]*models.IndustryArticleMinMaxPublishTime, 0)
  36. for i := range industryTimeList {
  37. industryMap[industryTimeList[i].IndustrialManagementId] = industryTimeList[i]
  38. }
  39. for i := range industryIds {
  40. iid := industryIds[i]
  41. item := industryMap[iid]
  42. if item != nil {
  43. // 最早发布时间为空 / 最早发布时间在三个月前之后
  44. if item.MinPublishTime.Equal(nullTime) || (item.MinPublishTime.After(threeMonthBefore)) {
  45. labelMap[iid] = true
  46. }
  47. } else {
  48. // 产业无报告, 则为新产业
  49. labelMap[iid] = true
  50. }
  51. }
  52. return
  53. }
  54. // 通过文章ID获取文章所关联的产业
  55. func GetArticleIndustrialByArticleId(articleIds []int) (itemMap map[int][]*models.IndustrialManagementResp, err error) {
  56. lenarticleIds := len(articleIds)
  57. if lenarticleIds == 0 {
  58. return
  59. }
  60. var condition string
  61. var pars []interface{}
  62. condition = ` AND mg.article_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `)`
  63. pars = append(pars, articleIds)
  64. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  65. if err != nil {
  66. return
  67. }
  68. industrialMap := make(map[int][]*models.IndustrialManagementResp)
  69. if len(industrialList) > 0 {
  70. for _, v := range industrialList {
  71. item := new(models.IndustrialManagementResp)
  72. item.IndustrialManagementId = v.IndustrialManagementId
  73. item.IndustryName = v.IndustryName
  74. item.ChartPermissionId = v.ChartPermissionId
  75. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  76. }
  77. }
  78. itemMap = industrialMap
  79. return
  80. }
  81. func GetArticleTypeMap() (nameMapResp map[int]string, buttonStyleMapResp map[int]string, err error) {
  82. condition := " AND is_show_yanx = 1 "
  83. list, e := models.GetCygxArticleTypeListCondition(condition)
  84. if e != nil {
  85. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  86. return
  87. }
  88. nameMap := make(map[int]string)
  89. buttonStyleMap := make(map[int]string)
  90. if len(list) > 0 {
  91. for _, v := range list {
  92. nameMap[v.ArticleTypeId] = v.ArticleTypeName
  93. buttonStyleMap[v.ArticleTypeId] = v.ButtonStyle
  94. }
  95. }
  96. nameMapResp = nameMap
  97. buttonStyleMapResp = buttonStyleMap
  98. return
  99. }
  100. // GetLyjhTypeMap 获取路演精华对应分类ID
  101. func GetLyjhTypeMap() (mapResp map[int]int, err error) {
  102. defer func() {
  103. if err != nil {
  104. go utils.SendAlarmMsg("获取路演精华对应分类ID失败 ErrMsg:"+err.Error(), 2)
  105. }
  106. }()
  107. condition := " AND match_type_name = '路演精华' "
  108. var pars []interface{}
  109. list, e := models.GetReportMappingList(condition, pars)
  110. if e != nil && e.Error() != utils.ErrNoRow() {
  111. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  112. return
  113. }
  114. mapResp = make(map[int]int, 0)
  115. if len(list) > 0 {
  116. for _, v := range list {
  117. mapResp[v.CategoryId] = v.CategoryId
  118. }
  119. }
  120. return
  121. }
  122. // GetLyjhArticleMap 获取路演精华对应文章ID
  123. func GetLyjhArticleMap() (mapResp map[int]bool, err error) {
  124. defer func() {
  125. if err != nil {
  126. go utils.SendAlarmMsg("获取路演精华对应文章ID失败 ErrMsg:"+err.Error(), 2)
  127. }
  128. }()
  129. condition := " AND match_type_name = '路演精华' "
  130. var pars []interface{}
  131. list, e := models.GetReportMappingList(condition, pars)
  132. if e != nil && e.Error() != utils.ErrNoRow() {
  133. err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
  134. return
  135. }
  136. var categoryId []int
  137. mapResp = make(map[int]bool, 0)
  138. if len(list) > 0 {
  139. for _, v := range list {
  140. categoryId = append(categoryId, v.CategoryId)
  141. }
  142. }
  143. lencategoryId := len(categoryId)
  144. if lencategoryId > 0 {
  145. pars = make([]interface{}, 0)
  146. condition = ` AND a.category_id IN (` + utils.GetOrmInReplace(lencategoryId) + `)`
  147. pars = append(pars, categoryId)
  148. listArticle, e := models.GetHomeList(condition, pars, 0, 1000)
  149. if e != nil && e.Error() != utils.ErrNoRow() {
  150. err = errors.New("GetResourceDataList, Err: " + e.Error())
  151. return
  152. }
  153. for _, v := range listArticle {
  154. mapResp[v.ArticleId] = true
  155. }
  156. }
  157. return
  158. }
  159. // 行业关注或者取消关注的时候,对于用户全部赛道的影响
  160. func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error) {
  161. defer func() {
  162. if err != nil {
  163. go utils.SendAlarmMsg("修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败"+err.Error(), 2)
  164. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  165. }
  166. }()
  167. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  168. if err != nil {
  169. return err
  170. }
  171. categoryinfo, err := models.GetChartPermissionById(detail.ChartPermissionId)
  172. if err != nil {
  173. return err
  174. }
  175. var allIn string
  176. allIn = DoXzsChooseSend(categoryinfo.PermissionName)
  177. if allIn != "" {
  178. //如果取消关注就把该赛道设置为非全部赛道
  179. if count == 1 {
  180. err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 0, uid)
  181. if err != nil {
  182. return err
  183. }
  184. } else {
  185. //医药、消费、科技、智造、研选下的产业赛道
  186. mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  187. industrialList, err := models.GetindustrialManagement()
  188. if err != nil {
  189. return err
  190. }
  191. for _, v := range industrialList {
  192. mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  193. }
  194. fllowNum, err := models.GetCountCygxIndustryFllowByUidAndChartPermissionId(uid, detail.ChartPermissionId)
  195. if err != nil {
  196. return err
  197. }
  198. if fllowNum == len(mapIndustrial[detail.ChartPermissionId]) {
  199. err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 1, uid)
  200. if err != nil {
  201. return err
  202. }
  203. }
  204. }
  205. }
  206. return err
  207. }
  208. // 根据行业处理所选的全部赛道字段
  209. func DoXzsChooseSend(chartPermissionName string) string {
  210. var allIn string
  211. if chartPermissionName == utils.YI_YAO_NAME {
  212. allIn = "all_in_yi_yao"
  213. } else if chartPermissionName == utils.XIAO_FEI_NAME {
  214. allIn = "all_in_xiao_fei"
  215. } else if chartPermissionName == utils.KE_JI_NAME {
  216. allIn = "all_in_ke_ji"
  217. } else if chartPermissionName == utils.ZHI_ZAO_NAME {
  218. allIn = "all_in_zhi_zao"
  219. } else if chartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  220. allIn = "all_in_yan_xuan"
  221. }
  222. return allIn
  223. }