xingzai hai 1 ano
pai
achega
6692d97abf

+ 190 - 0
controllers/report.go

@@ -1,7 +1,12 @@
 package controllers
 
 import (
+	"encoding/json"
 	"hongze/hongze_mfyx/models"
+	"hongze/hongze_mfyx/services"
+	"hongze/hongze_mfyx/utils"
+	"strconv"
+	"time"
 )
 
 // 报告
@@ -50,3 +55,188 @@ func (this *ReportController) IsShow() {
 	br.Success = true
 	br.Data = resp
 }
+
+// @Title 关注/取消关注产业
+// @Description 关注/取消关注 接口
+// @Param	request	body models.CygxIndustryFllowRep true "type json string"
+// @Success 200
+// @router /fllow [post]
+func (this *ReportController) Fllow() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	var req models.CygxIndustryFllowRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	industrialManagementId := req.IndustrialManagementId
+	var condition string
+	countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	if countIndustrial == 0 {
+		br.Msg = "产业不存在!"
+		br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
+		return
+	}
+	count, err := models.GetCountCygxIndustryFllow(uid, industrialManagementId, condition)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.CygxIndustryFllowResp)
+	countUser, err := models.GetCountCygxIndustryFllowByUid(uid)
+	if countUser == 0 {
+		resp.GoFollow = true
+	}
+	item := new(models.CygxIndustryFllow)
+	item.IndustrialManagementId = industrialManagementId
+	item.UserId = uid
+	item.Email = user.Email
+	item.Mobile = user.Mobile
+	item.RealName = user.RealName
+	item.Source = utils.REGISTER_PLATFORM
+	item.CompanyId = user.CompanyId
+	item.CompanyName = user.CompanyName
+	if count == 0 {
+		item.Type = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		_, err = models.AddCygxIndustryFllow(item)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,Err:" + err.Error()
+			return
+		}
+		resp.Status = 1
+	} else {
+		item.Type = 2
+		err = models.RemoveCygxIndustryFllow(uid, industrialManagementId)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "取消关注失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)       //处理是否关注全部赛道字段
+	go services.IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid) //处理用户标签
+	go services.AddCygxIndustryFllowLog(item)                                    //添加操作日志记录
+	br.Msg = "操作成功"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}
+
+// @Title 关注作者/取消关注作者
+// @Description 关注作者/取消关注作者 接口
+// @Param	request	body models.CygxArticleDepartmentId true "type json string"
+// @Success 200
+// @router /fllowDepartment [post]
+func (this *ReportController) FllowDepartment() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	var req models.CygxArticleDepartmentId
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	departmentId := req.DepartmentId
+	var condition string
+	countDepartment, err := models.GetDepartmentCount(departmentId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	if countDepartment == 0 {
+		br.Msg = "作者不存在!"
+		br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
+		return
+	}
+	countUser, err := models.GetArticleDepartmentFollowByUid(uid)
+	count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.CygxArticleDepartmentFollowResp)
+	if countUser == 0 {
+		resp.GoFollow = true
+	}
+	if count == 0 {
+		item := new(models.CygxArticleDepartmentFollow)
+		item.DepartmentId = departmentId
+		item.UserId = uid
+		item.Email = user.Email
+		item.Mobile = user.Mobile
+		item.RealName = user.RealName
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.Type = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		_, err = models.AddArticleDepartmentFollow(item)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,Err:" + err.Error()
+			return
+		}
+		resp.Status = 1
+	} else {
+		var doType int
+		condition = ` AND type = 1`
+		count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
+		if err != nil {
+			br.Msg = "操作失败!"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if count == 1 {
+			resp.Status = 2
+			doType = 2
+		} else {
+			resp.Status = 1
+			doType = 1
+		}
+		err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "取消关注失败,Err:" + err.Error()
+			return
+		}
+	}
+	br.Msg = "操作成功"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 1 - 1
controllers/yanxuan_special.go

@@ -118,7 +118,7 @@ func (this *BaseAuthMobileController) List() {
 			}
 			v.Tags += v.IndustryTags
 		}
-		if userId == 0 {
+		if sysUser.UserId == 0 {
 			v.Content = utils.InterceptHtmlLength(v.Content, 240) // 截取前80个字
 		}
 	}

+ 67 - 0
services/industrial_management.go

@@ -166,3 +166,70 @@ func GetLyjhArticleMap() (mapResp map[int]bool, err error) {
 	}
 	return
 }
+
+// 行业关注或者取消关注的时候,对于用户全部赛道的影响
+func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败"+err.Error(), 2)
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+	}()
+	detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
+	if err != nil {
+		return err
+	}
+	categoryinfo, err := models.GetChartPermissionById(detail.ChartPermissionId)
+	if err != nil {
+		return err
+	}
+	var allIn string
+	allIn = DoXzsChooseSend(categoryinfo.PermissionName)
+	if allIn != "" {
+		//如果取消关注就把该赛道设置为非全部赛道
+		if count == 1 {
+			err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 0, uid)
+			if err != nil {
+				return err
+			}
+		} else {
+			//医药、消费、科技、智造、研选下的产业赛道
+			mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
+			industrialList, err := models.GetindustrialManagement()
+			if err != nil {
+				return err
+			}
+			for _, v := range industrialList {
+				mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
+			}
+			fllowNum, err := models.GetCountCygxIndustryFllowByUidAndChartPermissionId(uid, detail.ChartPermissionId)
+			if err != nil {
+				return err
+			}
+			if fllowNum == len(mapIndustrial[detail.ChartPermissionId]) {
+				err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 1, uid)
+				if err != nil {
+					return err
+				}
+			}
+		}
+	}
+	return err
+}
+
+// 根据行业处理所选的全部赛道字段
+func DoXzsChooseSend(chartPermissionName string) string {
+	var allIn string
+	if chartPermissionName == utils.YI_YAO_NAME {
+		allIn = "all_in_yi_yao"
+	} else if chartPermissionName == utils.XIAO_FEI_NAME {
+		allIn = "all_in_xiao_fei"
+	} else if chartPermissionName == utils.KE_JI_NAME {
+		allIn = "all_in_ke_ji"
+	} else if chartPermissionName == utils.ZHI_ZAO_NAME {
+		allIn = "all_in_zhi_zao"
+	} else if chartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
+		allIn = "all_in_yan_xuan"
+	}
+	return allIn
+}

+ 31 - 0
services/industry_fllow.go

@@ -0,0 +1,31 @@
+package services
+
+import (
+	"fmt"
+	"hongze/hongze_mfyx/models"
+	"hongze/hongze_mfyx/utils"
+	"time"
+)
+
+// 添加用户关注,取消关注产业日志记录
+func AddCygxIndustryFllowLog(item *models.CygxIndustryFllow) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("添加用户关注,取消关注产业日志记录失败"+err.Error()+fmt.Sprint(item), 2)
+		}
+	}()
+	itemlog := new(models.CygxIndustryFllowLog)
+	itemlog.IndustrialManagementId = item.IndustrialManagementId
+	itemlog.UserId = item.UserId
+	itemlog.Email = item.Email
+	itemlog.Mobile = item.Mobile
+	itemlog.RealName = item.RealName
+	itemlog.CompanyId = item.CompanyId
+	itemlog.CompanyName = item.CompanyName
+	itemlog.Type = item.Type
+	itemlog.Source = utils.REGISTER_PLATFORM
+	itemlog.CreateTime = time.Now()
+	itemlog.ModifyTime = time.Now()
+	_, err = models.AddCygxIndustryFllowLog(itemlog)
+	return err
+}

+ 25 - 0
services/user_label.go

@@ -126,3 +126,28 @@ func ActivityUserLabelLogAdd(activityId int, mobileArr []string) (err error) {
 	}
 	return
 }
+
+// 添加用户2产业关注标签到Redis
+func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
+	var isFllow int
+	if count == 0 {
+		isFllow = 1
+	} else {
+		isFllow = 0
+	}
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+		if err != nil {
+			fmt.Println("RecordNewLogs LPush Err:" + err.Error())
+		}
+	}
+	return
+}

+ 1 - 0
utils/common.go

@@ -936,6 +936,7 @@ func ExtractText(body string) (result string, err error) {
 	return
 }
 func InterceptHtmlLength(body string, length int) (newbody string) {
+	fmt.Println(body)
 	re := regexp.MustCompile(`s*<p>(.*?)</p>`)
 	matches := re.FindAllStringSubmatch(body, 1)
 	// 提取匹配到的文本