瀏覽代碼

Merge branch 'cygx_6.0' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 2 年之前
父節點
當前提交
4b9f5f2dfa
共有 9 個文件被更改,包括 263 次插入35 次删除
  1. 2 2
      controllers/search.go
  2. 5 0
      controllers/user.go
  3. 2 1
      models/activity.go
  4. 12 11
      models/config.go
  5. 12 1
      models/send_company_user.go
  6. 10 16
      services/activity.go
  7. 164 0
      services/elastic.go
  8. 31 4
      services/send_company_user.go
  9. 25 0
      utils/email.go

+ 2 - 2
controllers/search.go

@@ -443,12 +443,12 @@ func (this *SearchController) ListHomeArtAndChart() {
 	var total int64
 	if listType == 1 || listType == 2 {
 		if orderColumn == "PublishDate" {
-			tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, user.UserId)
+			tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSortPage(indexName, keyWord, startSize, pageSize, user.UserId)
 			result = tmpResult
 			total = tmpTotal
 			err = tmpErr
 		} else {
-			tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, user.UserId, orderColumn)
+			tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySortPage(indexName, keyWord, startSize, pageSize, user.UserId, orderColumn)
 			result = tmpResult
 			total = tmpTotal
 			err = tmpErr

+ 5 - 0
controllers/user.go

@@ -111,6 +111,11 @@ func (this *UserController) Login() {
 		req.CountryCode = "86"
 	}
 	user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "绑定手机号失败:" + err.Error()
+		return
+	}
 	userId := user.UserId
 	var token string
 	tokenItem, err := models.GetTokenByOpenId(openId)

+ 2 - 1
models/activity.go

@@ -201,8 +201,9 @@ func GetActivityListByDateTime(startDate, endDate, activityIds string) (items []
 	sql := `SELECT * FROM cygx_activity WHERE activity_time > '` + startDate + `' AND activity_time < '` + endDate + `' `
 	activityIds = strings.TrimRight(activityIds, ",")
 	if activityIds != "" {
-		sql += ` AND activity_id IN (` + activityIds + `)  `
+		sql += ` AND activity_id  NOT IN (` + activityIds + `) `
 	}
+	sql += `  OR activity_id IN (SELECT config_value FROM cygx_config WHERE config_code = 'jin_meng_activity_id')`
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 12 - 11
models/config.go

@@ -39,17 +39,18 @@ func GetShowSustainable() (count int, err error) {
 
 // 通过报告精选来获取最新的推荐搜索词
 func GetHotSearch() (permission string, err error) {
-	sql := ` SELECT
-	GROUP_CONCAT(DISTINCT s.subject_name  ORDER BY rl.article_sun_id ASC  SEPARATOR ',') AS subject_name 
-FROM
-	cygx_report_selection_log AS rl
-	INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = rl.industrial_subject_id 
-WHERE
-	rl.article_id = (
-	SELECT
-		MAX( article_id ) 
-FROM
-	cygx_report_selection WHERE publish_status = 1)`
+	sql := `SELECT
+			GROUP_CONCAT( DISTINCT rl.subject_name ORDER BY rl.article_sun_id ASC SEPARATOR ',' ) AS subject_name 
+		FROM
+			cygx_report_selection_log AS rl 
+		WHERE
+			rl.article_id = (
+			SELECT
+				MAX( article_id ) 
+			FROM
+				cygx_report_selection 
+		WHERE
+			publish_status = 1)`
 	o := orm.NewOrm()
 	err = o.Raw(sql).QueryRow(&permission)
 	return

+ 12 - 1
models/send_company_user.go

@@ -40,7 +40,6 @@ type UserJson struct {
 	Level               string `json:"level"`             //职位等级(研究员、基金经理、部门总监)
 	IsMaker             string `json:"policymakers"`      //是否决策人(是、否)
 	CreatedTime         string `json:"create_time"`       //创建时间
-
 }
 type CompanyJsonList struct {
 	SyncData *[]CompanyJson `json:"sync_data"`
@@ -216,3 +215,15 @@ func GetSendUserList(condition string) (items []*UserJson, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+type WxUserOpLogResp struct {
+	CompanyId int `description:"客户ID"`
+}
+
+//获取指定时间内更新的用户
+func GetWxUserOpLog(createTime string) (items []*WxUserOpLogResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT company_id FROM wx_user_op_log WHERE  log_type IN ('add','edit') AND create_time >=  '` + createTime + `' AND company_id > 1 GROUP BY company_id `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 10 - 16
services/activity.go

@@ -651,12 +651,12 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 					fmt.Println("GetTacticsList Err:", err.Error())
 					return err
 				}
-				//fmt.Println("原来的", vAct.RoadshowTitle)
-				//fmt.Println("处理的", activityName)
 
 				needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
 				var mobileStr string
 				if len(list) > 0 {
+					fmt.Println("原来的", vAct.RoadshowTitle)
+					fmt.Println("处理的", activityName)
 					for _, v := range list {
 						if v.UserPhone != "" {
 							item := new(models.CygxActivityAttendanceDetail)
@@ -718,13 +718,6 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 						fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
 						return err
 					}
-					////添加报名日志
-					//err = models.AddCygxActivityMeetDetailLogOnline(needAddAttendanc, vAct.ActivityId)
-					//if err != nil {
-					//	fmt.Println("AddCygxActivityMeetDetailLogOnline Err:", err.Error())
-					//	return err
-					//}
-
 				}
 			}
 		}
@@ -738,11 +731,10 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 	}
 	//通过本地去找进门财经的数据
 	for _, vAct := range listActivity {
-		doTime := utils.TimeRemoveHms2(vAct.ActivityName)
+		doTime := utils.TimeRemoveHms2(vAct.ActivityTime)
 		findStartDate := doTime + " 00:00:00"
 		findEndDate := doTime + " 23:59:59"
-		var roadshowTitle string
-		nameSlice := strings.Split(vAct.ActivityName, "|")
+		nameSlice := strings.Split(vAct.ActivityName, "】")
 		//对于手动匹配到的活动数据也要更新
 		var activityName string
 		if len(nameSlice) > 1 {
@@ -751,18 +743,20 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 			} else {
 				activityName = nameSlice[len(nameSlice)-1]
 			}
-			//fmt.Println("原来的1", vAct.ActivityName)
-			//fmt.Println("处理的2", activityName)
-			activityName = nameSlice[len(nameSlice)-1]
+
+			//activityName = nameSlice[len(nameSlice)-1]
 			if activityName != "" {
-				list, err := models.GetRoadshowDataList(roadshowTitle, findStartDate, findEndDate)
+				list, err := models.GetRoadshowDataList(activityName, findStartDate, findEndDate)
 				if err != nil {
 					fmt.Println("GetTacticsList Err:", err.Error())
 					return err
 				}
+
 				needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
 				var mobileStr string
 				if len(list) > 0 {
+					fmt.Println("原来的1", vAct.ActivityName)
+					fmt.Println("处理的2", activityName)
 					for _, v := range list {
 						if v.UserPhone != "" {
 							item := new(models.CygxActivityAttendanceDetail)

+ 164 - 0
services/elastic.go

@@ -963,3 +963,167 @@ func EsSearchReport(indexName, keyWord string, startSize, pageSize, userId int)
 	total = int64(len(result))
 	return
 }
+
+//分页
+func EsMultiMatchFunctionScoreQueryTimeSortPage(indexName, keyWord string, startSize, pageSize, userId int) (result []*models.SearchItem, total int64, err error) {
+	client := utils.Client
+	keyWordArr, err := GetIndustryMapNameSliceV2(keyWord)
+	keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
+	boolquery := elastic.NewBoolQuery()
+	matchArr := make([]elastic.Query, 0)
+	n := 0
+	keyWordLen := len(keyWordArr)
+	if keyWordLen <= 0 {
+		keyWordArr = append(keyWordArr, keyWord)
+		keyWordLen = len(keyWordArr)
+	}
+	for _, v := range keyWordArr {
+		if v != "" {
+			multiMatch := elastic.NewMultiMatchQuery(v, "Title", "BodyText")
+			bodyFunctionQuery := elastic.NewFunctionScoreQuery()
+			bodyFunctionQuery.Query(multiMatch)
+			matchArr = append(matchArr, bodyFunctionQuery)
+		}
+		n++
+	}
+	boolquery.Should(matchArr...)
+	highlight := elastic.NewHighlight()
+	highlight = highlight.Fields(elastic.NewHighlighterField("Title"), elastic.NewHighlighterField("BodyText"))
+	highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
+	request := client.Search(indexName).Highlight(highlight).Sort("PublishDate", false).From(startSize).Size(pageSize).Query(boolquery)
+	searchByMatch, err := request.Do(context.Background())
+	if searchByMatch != nil {
+		if searchByMatch.Hits != nil {
+			for _, v := range searchByMatch.Hits.Hits {
+				articleJson, err := v.Source.MarshalJSON()
+				if err != nil {
+					return nil, 0, err
+				}
+				article := new(models.CygxArticleEs)
+				err = json.Unmarshal(articleJson, &article)
+				if err != nil {
+					return nil, 0, err
+				}
+				searchItem := new(models.SearchItem)
+				searchItem.ArticleId, _ = strconv.Atoi(v.Id)
+				if len(v.Highlight["BodyText"]) > 0 {
+					searchItem.Body = v.Highlight["BodyText"]
+				} else {
+					bodyRune := []rune(article.BodyText)
+					bodyRuneLen := len(bodyRune)
+					if bodyRuneLen > 100 {
+						bodyRuneLen = 100
+					}
+					body := string(bodyRune[:bodyRuneLen])
+					searchItem.Body = []string{body}
+				}
+				var title string
+				if len(v.Highlight["Title"]) > 0 {
+					title = v.Highlight["Title"][0]
+				} else {
+					title = article.Title
+				}
+				searchItem.Title = title
+				searchItem.PublishDate = article.PublishDate
+				searchItem.ExpertBackground = article.ExpertBackground
+				searchItem.CategoryId = article.CategoryId
+				result = append(result, searchItem)
+			}
+		}
+		total = searchByMatch.Hits.TotalHits.Value
+	}
+	return
+}
+
+func EsMultiMatchFunctionScoreQuerySortPage(indexName, keyWord string, startSize, pageSize, userId int, orderColumn string) (result []*models.SearchItem, total int64, err error) {
+	client := utils.Client
+	keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
+	keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
+
+	keyWordLen := len(keyWordArr)
+	if keyWordLen <= 0 {
+		keyWordArr = append(keyWordArr, keyWord)
+		keyWordLen = len(keyWordArr)
+	}
+	var keyWords string
+	for _, v := range keyWordArr {
+		keyWords += v + " "
+	}
+	// @Param   OrderColumn   query   int  true       "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
+	//keyWordWeight := GetWeight(keyWordLen)
+
+	matchArr := make([]elastic.Query, 0)
+	boolquery := elastic.NewBoolQuery()
+	bodyFunctionQuery := elastic.NewFunctionScoreQuery()
+	bodyFunctionQuery2 := elastic.NewFunctionScoreQuery()
+	bodyFunctionQuery3 := elastic.NewFunctionScoreQuery()
+	multiMatch := elastic.NewMultiMatchQuery(keyWords, "Title").Analyzer("ik_smart").Boost(100)
+	bodyFunctionQuery.Query(multiMatch)
+	matchArr = append(matchArr, bodyFunctionQuery)
+	multiMatch = elastic.NewMultiMatchQuery(keyWords, "BodyText").Analyzer("ik_smart").Boost(1)
+	bodyFunctionQuery2.Query(multiMatch)
+	matchArr = append(matchArr, bodyFunctionQuery2)
+	bodyFunctionQuery3.Query(multiMatch)
+	matchArr = append(matchArr, bodyFunctionQuery3)
+	boolquery.Should(matchArr...)
+	highlight := elastic.NewHighlight()
+	highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
+	highlight = highlight.Fields(elastic.NewHighlighterField("Title"), elastic.NewHighlighterField("BodyText"))
+	request := client.Search(indexName).Highlight(highlight).Sort("PublishDate", false).From(startSize).Size(pageSize).Query(boolquery)
+	if orderColumn == "Matching" {
+		request = client.Search(indexName).Highlight(highlight).From(startSize).Size(pageSize).Query(boolquery)
+	}
+	searchByMatch, err := request.Do(context.Background())
+	if err != nil {
+		return nil, 0, err
+	}
+	if searchByMatch != nil {
+		if searchByMatch.Hits != nil {
+			for _, v := range searchByMatch.Hits.Hits {
+				var isAppend bool
+				articleJson, err := v.Source.MarshalJSON()
+				if err != nil {
+					return nil, 0, err
+				}
+				article := new(models.CygxArticleEs)
+				err = json.Unmarshal(articleJson, &article)
+				if err != nil {
+					return nil, 0, err
+				}
+				searchItem := new(models.SearchItem)
+				searchItem.ArticleId, _ = strconv.Atoi(v.Id)
+				if len(v.Highlight["BodyText"]) > 0 {
+					searchItem.Body = v.Highlight["BodyText"]
+				} else {
+					bodyRune := []rune(article.BodyText)
+					bodyRuneLen := len(bodyRune)
+					if bodyRuneLen > 100 {
+						bodyRuneLen = 100
+					}
+					body := string(bodyRune[:bodyRuneLen])
+					searchItem.Body = []string{body}
+				}
+				var title string
+				if len(v.Highlight["Title"]) > 0 {
+					title = v.Highlight["Title"][0]
+				} else {
+					title = article.Title
+				}
+				searchItem.Title = title
+				searchItem.PublishDate = article.PublishDate
+				searchItem.ExpertBackground = article.ExpertBackground
+				searchItem.CategoryId = article.CategoryId
+				for _, v_result := range result {
+					if v_result.ArticleId == searchItem.ArticleId {
+						isAppend = true
+					}
+				}
+				if !isAppend {
+					result = append(result, searchItem)
+				}
+			}
+		}
+	}
+	total += searchByMatch.Hits.TotalHits.Value
+	return
+}

+ 31 - 4
services/send_company_user.go

@@ -116,6 +116,33 @@ func SendComapnyToShanghai(url, jsonCompany, postType string) (err error) {
 }
 
 func DotongbuShangHai(cont context.Context) (err error) {
+	var condition string
+	updateTime := time.Now().Add(-time.Hour * 30).Format("2006-01-02 15:04:05")
+	listUpdateUser, err := models.GetWxUserOpLog(updateTime)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return err
+	}
+	var companyIds string
+	if len(listUpdateUser) > 0 {
+		for _, v := range listUpdateUser {
+			companyIds += strconv.Itoa(v.CompanyId) + ","
+		}
+	}
+	condition = ` AND p.modify_time > ` + "'" + updateTime + "'"
+	//同30小时有变更的公司
+	go DotongbuShangHaApi(condition)
+
+	//原有的公司如果新增了也同步
+	companyIds = strings.TrimRight(companyIds, ",")
+	if companyIds != "" {
+		condition = ` AND c.company_id  IN (` + companyIds + ")"
+		go DotongbuShangHaApi(condition)
+	}
+	return
+}
+
+//func DotongbuShangHai(cont context.Context) (err error) {
+func DotongbuShangHaApi(condition string) (err error) {
 	var msg string
 	defer func() {
 		if err != nil {
@@ -123,10 +150,10 @@ func DotongbuShangHai(cont context.Context) (err error) {
 		}
 	}()
 	//同步24小时之前的数据到上海平台,为防止遗漏改成30小时
-	var condition string
-	updateTime := time.Now().Add(-time.Hour * 30).Format("2006-01-02 15:04:05")
-	condition = ` AND p.modify_time > ` + "'" + updateTime + "'"
-	fmt.Println(condition)
+
+	//updateTime := time.Now().Add(-time.Hour * 30).Format("2006-01-02 15:04:05")
+	//condition = ` AND p.modify_time > ` + "'" + updateTime + "'"
+	//fmt.Println(condition)
 	//获取token
 	url := "https://crm.hzinsights.com/openapi/v1/auth/getAccessToken?app_key=26945134&app_secret=b99cb2bdec70d20156000f664ec5ac30"
 	method := "GET"

+ 25 - 0
utils/email.go

@@ -1,12 +1,18 @@
 package utils
 
 import (
+	"encoding/json"
 	"fmt"
+	"github.com/rdlucklib/rdluck_tools/http"
 	"gopkg.in/gomail.v2"
 	"mime"
 	"strings"
 )
 
+var (
+	AlarmMsgUrl = "http://127.0.0.1:8606/api/alarm/send"
+)
+
 //发送邮件
 func SendEmail(title, content string, touser string) bool {
 	if RunMode == "debug" {
@@ -31,9 +37,28 @@ func SendEmail(title, content string, touser string) bool {
 	if err := d.DialAndSend(m); err != nil {
 		return false
 	}
+	go SendAlarmMsg(content, 1)
 	return true
 }
 
+//projectName-项目名称
+//runMode-运行模式
+//msgBody-消息内容
+//level:消息基本,1:提示消息,2:警告消息,3:严重错误信息,默认为1 提示消息
+func SendAlarmMsg(msgBody string, level int) {
+	params := make(map[string]interface{})
+	params["ProjectName"] = APPNAME
+	params["RunMode"] = RunMode
+	params["MsgBody"] = msgBody
+	params["Level"] = level
+	param, err := json.Marshal(params)
+	if err != nil {
+		FileLog.Info("SendAlarmMsg json.Marshal Err:" + err.Error())
+		return
+	}
+	http.Post(AlarmMsgUrl, string(param))
+}
+
 //发送邮件
 func SendEmailByHz(title, content string, touser string) (result bool, err error) {
 	//if RunMode == "debug" {