|
@@ -2,9 +2,11 @@ package entity
|
|
|
|
|
|
import (
|
|
|
"config"
|
|
|
+ "ent/util"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
qutil "qfw/util"
|
|
|
+ "qfw/util/elastic"
|
|
|
"qfw/util/mysql"
|
|
|
"qfw/util/redis"
|
|
|
"strings"
|
|
@@ -21,8 +23,8 @@ const (
|
|
|
PowerCacheDb = "other"
|
|
|
PortraitRecordTable = "portrait_record"
|
|
|
PortraitWinnerRecordTimes = "entnichePortraitRecordTimes_%s_%s"
|
|
|
- UsePortraitWinnerVisited = "entnichePortraitVisited_%s_%d_%s"
|
|
|
- CacheDateForMat = "200601"
|
|
|
+ UsePortraitWinnerVisited = "entnichePortraitVisited_%s_%d_%s"
|
|
|
+ CacheDateForMat = "200601"
|
|
|
)
|
|
|
|
|
|
//大会员
|
|
@@ -227,6 +229,45 @@ func (this *Portrait) BuyerPortraitData(screen *PortraitScreen, flag string) (ma
|
|
|
return buyerPortraitData, nil
|
|
|
}
|
|
|
|
|
|
+func (this *Portrait) GetBuyerNewMsgExport(pwp *PortraitProjectScreen) ([]string, error) {
|
|
|
+ return pwp.GetBuyerListIds()
|
|
|
+}
|
|
|
+
|
|
|
+type dataExportKeywords struct {
|
|
|
+ Keyword string `json:"keyword"` //关键词
|
|
|
+}
|
|
|
+
|
|
|
+//SaveExportRecord 保存数据到出记录
|
|
|
+func (this *Portrait) SaveExportRecord(pwp *PortraitProjectScreen, ids []string, ent, flag string) (string, error) {
|
|
|
+ var keyWords []dataExportKeywords
|
|
|
+ for _, k := range pwp.Screen.KeyWordArr {
|
|
|
+ keyWords = append(keyWords, dataExportKeywords{Keyword: k})
|
|
|
+ }
|
|
|
+ saveMap := map[string]interface{}{
|
|
|
+ "s_userid": this.UserId,
|
|
|
+ "comeinfrom": flag,
|
|
|
+ "comeintime": time.Now().Unix(),
|
|
|
+ "selectIds": ids,
|
|
|
+ "area": qutil.If(pwp.Screen.Area != "", strings.Split(pwp.Screen.Area, ","), nil),
|
|
|
+ "publishtime": fmt.Sprintf("%d_%d", pwp.Screen.PareStartTime, pwp.Screen.PareEndTime),
|
|
|
+ "industry": qutil.If(pwp.Screen.ScopeClass != "", strings.Split(pwp.Screen.ScopeClass, ","), nil),
|
|
|
+ "keywords": keyWords,
|
|
|
+ "selectType": pwp.Screen.ShowMatch,
|
|
|
+ }
|
|
|
+ if flag == "winnerPortrait" {
|
|
|
+ if entName := getEntNameById(ent); entName != "" {
|
|
|
+ saveMap["winner"] = []string{entName}
|
|
|
+ }
|
|
|
+ } else if flag == "buyerPortrait" {
|
|
|
+ saveMap["buyer"] = []string{ent}
|
|
|
+ }
|
|
|
+
|
|
|
+ if _id := util.MQFW.Save("export_search", saveMap); _id != "" {
|
|
|
+ return qutil.SE.Encode2Hex(_id), nil
|
|
|
+ }
|
|
|
+ return "", fmt.Errorf("选择导出异常")
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
SubVipPortraitUsage 画像使用情况查询
|
|
|
mysql 数据库链接
|
|
@@ -247,7 +288,7 @@ func GetUsageNum(mysql *mysql.Mysql, queryDate time.Time, searchValue string, us
|
|
|
usage = redis.GetInt(PowerCacheDb, key)
|
|
|
if usage == 0 && mysql != nil { //当缓存中无值时查询mysql中使用量
|
|
|
usage = int(mysql.CountBySql(fmt.Sprintf("select count(id) from %s where ent_id =? and user_id=? and p_type =? and year(create_time)=? and month(create_time)=?",
|
|
|
- PortraitRecordTable), searchValue, userId, 2,queryDate.Year(), int(queryDate.Month())))
|
|
|
+ PortraitRecordTable), searchValue, userId, 2, queryDate.Year(), int(queryDate.Month())))
|
|
|
redis.Put(PowerCacheDb, key, usage, 24*60*60*31)
|
|
|
}
|
|
|
return
|
|
@@ -255,16 +296,16 @@ func GetUsageNum(mysql *mysql.Mysql, queryDate time.Time, searchValue string, us
|
|
|
|
|
|
//GetPortraitRecordTimesRedisKey 获取画像使用数量key
|
|
|
func GetPortraitRecordTimesRedisKey(userId string) string {
|
|
|
- return fmt.Sprintf(PortraitWinnerRecordTimes,userId, time.Now().Format(CacheDateForMat))
|
|
|
+ return fmt.Sprintf(PortraitWinnerRecordTimes, userId, time.Now().Format(CacheDateForMat))
|
|
|
}
|
|
|
-func isVisitEnt(mysql *mysql.Mysql, searchValue string, userId string,queryDate time.Time) bool {
|
|
|
+func isVisitEnt(mysql *mysql.Mysql, searchValue string, userId string, queryDate time.Time) bool {
|
|
|
//有浏览记录
|
|
|
cacheKey := GetPortraitVisitedRedisKey(searchValue, userId)
|
|
|
if exists, err := redis.Exists(PowerCacheDb, cacheKey); err == nil && exists {
|
|
|
return true
|
|
|
}
|
|
|
-if mysql.CountBySql(fmt.Sprintf("select count(id) from %s where ent_id =? and user_id=? and p_type = ? and year(create_time)=? and month(create_time)=? ",
|
|
|
- PortraitRecordTable), searchValue, userId, 1,queryDate.Year(), int(queryDate.Month())) == 1 {
|
|
|
+ if mysql.CountBySql(fmt.Sprintf("select count(id) from %s where ent_id =? and user_id=? and p_type = ? and year(create_time)=? and month(create_time)=? ",
|
|
|
+ PortraitRecordTable), searchValue, userId, 1, queryDate.Year(), int(queryDate.Month())) == 1 {
|
|
|
|
|
|
redis.Incr(PowerCacheDb, cacheKey)
|
|
|
return true
|
|
@@ -273,8 +314,8 @@ if mysql.CountBySql(fmt.Sprintf("select count(id) from %s where ent_id =? and
|
|
|
}
|
|
|
|
|
|
//GetPortraitVisitedRedisKey 画像是否浏览过key
|
|
|
-func GetPortraitVisitedRedisKey(searchValue string, userId string ) string {
|
|
|
- return fmt.Sprintf(UsePortraitWinnerVisited,userId,int(time.Now().Month()), searchValue,)
|
|
|
+func GetPortraitVisitedRedisKey(searchValue string, userId string) string {
|
|
|
+ return fmt.Sprintf(UsePortraitWinnerVisited, userId, int(time.Now().Month()), searchValue)
|
|
|
}
|
|
|
|
|
|
func SubVipPortraitTimesCheck(mysql *mysql.Mysql, searchValue string, ent_id string) error {
|
|
@@ -310,3 +351,12 @@ func SubVipPortraitTimesCheck(mysql *mysql.Mysql, searchValue string, ent_id str
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func getEntNameById(entId string) (entName string) {
|
|
|
+ r := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query": {"term": {"_id": "%s"}},"_source": ["name"],"size": %d}`, entId, 1))
|
|
|
+ if r == nil || len(*r) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ entName, _ = (*r)[0]["name"].(string)
|
|
|
+ return
|
|
|
+}
|