Sfoglia il codice sorgente

wip:招标动态导出

fuwencai 3 anni fa
parent
commit
37366ee932

+ 59 - 9
entniche/src/entity/portrait.go

@@ -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
+}

+ 24 - 0
entniche/src/entity/portrait_screen.go

@@ -396,3 +396,27 @@ func (pwp *PortraitProjectScreen) CommonPare(isWinner bool) (mustQueryArr []stri
 	}
 	return
 }
+
+//GetBuyerListIds 画像采购单位动态数据导出
+func (pwp *PortraitProjectScreen) GetBuyerListIds() (ids []string, err error) {
+	var newData *[]map[string]interface{}
+	//查询
+	newData, _, err = pwp.GetBuyerListSearch()
+	if newData == nil || len(*newData) == 0 {
+		err = fmt.Errorf("未查询到相关数据")
+		return
+	}
+	//获取到处项目最后一条bidding数据的id
+	for _, rowData := range *newData {
+		vs, _ := rowData["list"].([]interface{})
+		if len(vs) > 0 {
+			last := vs[len(vs)-1]
+			if lastObj, _ := last.(map[string]interface{}); lastObj != nil {
+				if idStr, _ := lastObj["infoid"].(string); idStr != "" {
+					ids = append(ids, idStr)
+				}
+			}
+		}
+	}
+	return
+}

+ 72 - 5
entniche/src/service/portrait/subvipPortraitAction.go

@@ -8,17 +8,20 @@ import (
 	"github.com/go-xweb/xweb"
 	"log"
 	qutil "qfw/util"
+	"strings"
 )
 
 //大会员画像接口
 type EntPortrait struct {
 	*xweb.Action
 	//采购单位画像
-	buyerNewMsg   xweb.Mapper `xweb:"/portrait/buyer/getNewMsg"`      //最新项目动态
-	buyerContacts xweb.Mapper `xweb:"/portrait/buyer/contacts"`       //采购项目联系方式
-	buyerPortrait xweb.Mapper `xweb:"/portrait/buyer/getData"`        //采购单位画像数据
-	buyerSelects  xweb.Mapper `xweb:"/portrait/buyer/selects"`        //采购单位画像可筛选项
-	portraitUsage xweb.Mapper `xweb:"/portrait/subVipPortrait/usage"` //超级订阅升级版画像浏览详情
+	buyerNewMsg       xweb.Mapper `xweb:"/portrait/buyer/getNewMsg"`       //最新项目动态
+	buyerContacts     xweb.Mapper `xweb:"/portrait/buyer/contacts"`        //采购项目联系方式
+	buyerPortrait     xweb.Mapper `xweb:"/portrait/buyer/getData"`         //采购单位画像数据
+	buyerSelects      xweb.Mapper `xweb:"/portrait/buyer/selects"`         //采购单位画像可筛选项
+	portraitUsage     xweb.Mapper `xweb:"/portrait/subVipPortrait/usage"`  //超级订阅升级版画像浏览详情
+	buyerNewMsgExport xweb.Mapper `xweb:"/portrait/buyer/getNewMsgExport"` //最新项目动态数据导出[筛选]
+
 }
 
 //采购单位画像-最新招标动态
@@ -217,3 +220,67 @@ func (this *EntPortrait) PortraitUsage() {
 	}
 	this.ServeJson(NewResult(rData, errMsg))
 }
+
+// 数据导出
+func (this *EntPortrait) BuyerNewMsgExport() {
+	userId := qutil.ObjToString(this.GetSession("userId"))
+	rData, errMsg := func() (interface{}, error) {
+		cepm, hasPower, err := entity.CreatePortraitManager(userId)
+		if err != nil {
+			return nil, err
+		}
+
+		buyerName := this.GetString("buyer")
+		if buyerName == "" {
+			return nil, fmt.Errorf("参数异常")
+		}
+		err = entity.SubVipPortraitTimesCheck(Mysql, buyerName, userId)
+		if err != nil {
+			return nil, err
+		}
+		//免费用户仅可查看三条记录
+		pps := &entity.PortraitProjectScreen{
+			Screen: &entity.PortraitScreen{
+				Ent:        buyerName,
+				Match:      this.GetString("match"),
+				ExactMatch: this.GetString("exactMatch") == "1",
+				MatchRange: this.GetString("matchRange"),
+				Area:       this.GetString("area"),
+				ScopeClass: this.GetString("scopeClass"),
+				TimeRange:  this.GetString("timeRange"),
+				HasPower:   hasPower,
+			},
+			IsExport: true,
+		}
+		ids := getSelectIds(this.GetString("selectIds"))
+		if ids == nil || len(ids) == 0 {
+			ids, err = cepm.GetBuyerNewMsgExport(pps)
+			if err != nil {
+				return nil, err
+			}
+		} else {
+			pps.CommonPare(false)
+		}
+		_id, err := cepm.SaveExportRecord(pps, ids, buyerName, "buyerPortrait")
+		if err != nil {
+			return nil, err
+		}
+		return _id, nil
+	}()
+	if errMsg != nil {
+		log.Printf("%s BuyerNewMsgExport获取采购单位最新招标信息出错:%s\n", userId, errMsg.Error())
+	}
+	this.ServeJson(NewResult(rData, errMsg))
+}
+func getSelectIds(selectIds string) (ids []string) {
+	if selectIds != "" { //选中导出
+		for _, encodeId := range strings.Split(selectIds, ",") {
+			if tmp := qutil.CommonDecodeArticle("content", encodeId); len(tmp) > 0 {
+				if id := tmp[0]; id != "" {
+					ids = append(ids, id)
+				}
+			}
+		}
+	}
+	return
+}