|
@@ -8,10 +8,11 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ "app.yhyue.com/moapp/jypkg/public"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/mozillazg/go-pinyin"
|
|
|
"jy/src/jfw/config"
|
|
|
- "jy/src/jfw/modules/bigmember/src/db"
|
|
|
"math/rand"
|
|
|
"sort"
|
|
|
"strings"
|
|
@@ -68,7 +69,7 @@ func getDetail(pid string, equity int) map[string]interface{} {
|
|
|
codeContent = common.If(equity == 1, "登陆后解锁会员查看", "(付费展示)").(string)
|
|
|
}
|
|
|
//基本信息
|
|
|
- dataDetail := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT
|
|
|
+ dataDetail := public.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT
|
|
|
a.projectname,
|
|
|
a.lasttime,
|
|
|
a.firsttime,
|
|
@@ -112,7 +113,7 @@ WHERE
|
|
|
detail["project_scale"] = config.Seoconfig["nzjConstructionContent"]
|
|
|
}
|
|
|
//项目进展
|
|
|
- follRecord := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT a.publishtime,CONCAT('进展', a.follow_num) AS follow,CONCAT(a.title,'-',b.name) as remark,a.jybxhref FROM dwd_f_nzj_follw_record a
|
|
|
+ follRecord := public.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT a.publishtime,CONCAT('进展', a.follow_num) AS follow,CONCAT(a.title,'-',b.name) as remark,a.jybxhref FROM dwd_f_nzj_follw_record a
|
|
|
LEFT JOIN d_nzj_project_stage_code b on a.project_stage_code = b.code WHERE proposed_id = '%s'
|
|
|
ORDER BY publishtime DESC `, pid))
|
|
|
if follRecord != nil && len(*follRecord) > 0 {
|
|
@@ -127,14 +128,14 @@ ORDER BY publishtime DESC `, pid))
|
|
|
|
|
|
var ids []string
|
|
|
//获取企业主题id
|
|
|
- entId := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT name_id FROM dwd_f_nzj_ent WHERE proposed_id = '%s' ORDER BY identity_type DESC , createtime ASC`, pid))
|
|
|
+ entId := public.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT name_id FROM dwd_f_nzj_ent WHERE proposed_id = '%s' ORDER BY identity_type DESC , createtime ASC`, pid))
|
|
|
if entId != nil && len(*entId) > 0 {
|
|
|
for _, v := range *entId {
|
|
|
ids = append(ids, fmt.Sprintf(`"%s"`, common.InterfaceToStr(v["name_id"])))
|
|
|
}
|
|
|
connection := make(map[RemovalKey]map[string]interface{})
|
|
|
var data []map[string]interface{}
|
|
|
- nzjContact := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_nzj_contact WHERE name_id in (%s) ORDER BY createtime DESC `, strings.Join(ids, ",")))
|
|
|
+ nzjContact := public.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_nzj_contact WHERE name_id in (%s) ORDER BY createtime DESC `, strings.Join(ids, ",")))
|
|
|
if nzjContact != nil && len(*nzjContact) > 0 {
|
|
|
for _, v := range *nzjContact {
|
|
|
v["lasttime"] = v["createtime"]
|
|
@@ -147,7 +148,7 @@ ORDER BY publishtime DESC `, pid))
|
|
|
}
|
|
|
if equity > 3 {
|
|
|
//企业联系人
|
|
|
- entContact := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT * FROM dws_f_ent_contact WHERE name_id in (%s)`, strings.Join(ids, ",")))
|
|
|
+ entContact := public.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT * FROM dws_f_ent_contact WHERE name_id in (%s)`, strings.Join(ids, ",")))
|
|
|
if entContact != nil && len(*entContact) > 0 {
|
|
|
for _, v := range *entContact {
|
|
|
v["lasttime"] = v["createtime"]
|
|
@@ -165,7 +166,7 @@ ORDER BY publishtime DESC `, pid))
|
|
|
data = append(data, m)
|
|
|
}
|
|
|
//私有联系人用户
|
|
|
- userContact := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_user_contact_record WHERE name_id in (%s) `, strings.Join(ids, ",")))
|
|
|
+ userContact := public.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_user_contact_record WHERE name_id in (%s) `, strings.Join(ids, ",")))
|
|
|
if userContact != nil && len(*userContact) > 0 {
|
|
|
for _, m := range *userContact {
|
|
|
data = append(data, m)
|
|
@@ -321,7 +322,7 @@ func nzjEmptySearch(pageNum, pageSize int) (int64, *[]map[string]interface{}) {
|
|
|
ds := common.ObjArrToMapArr(data)[(pageNum-1)*pageSize : pageNum*pageSize]
|
|
|
return common.Int64All(len(ds)), &ds
|
|
|
} //获取
|
|
|
- dataArr := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_nzj_baseinfo ORDER BY lasttime DESC LIMIT %v`, config.Sysconfig["nzjLimit"]))
|
|
|
+ dataArr := public.BaseMysql.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_nzj_baseinfo ORDER BY lasttime DESC LIMIT %v`, config.Sysconfig["nzjLimit"]))
|
|
|
if dataArr != nil && len(*dataArr) > 0 {
|
|
|
redis.Put("newother", nzjRedisKey, *dataArr, 3600*24)
|
|
|
}
|
|
@@ -354,6 +355,15 @@ func nzjEquity(session *httpsession.Session) int {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+type BuyerAggregations struct {
|
|
|
+ CountByBuyer struct {
|
|
|
+ Buckets []struct {
|
|
|
+ Key string `json:"key"`
|
|
|
+ DocCount int `json:"doc_count"`
|
|
|
+ } `json:"buckets"`
|
|
|
+ } `json:"count_by_buyer"`
|
|
|
+}
|
|
|
+
|
|
|
// 新首页 热门中标
|
|
|
func NewHotEnt(isWinner bool) (data []map[string]interface{}) {
|
|
|
seed := time.Now().UnixNano()
|
|
@@ -378,7 +388,7 @@ func NewHotEnt(isWinner bool) (data []map[string]interface{}) {
|
|
|
HAVING LENGTH(ent_Id) > 9
|
|
|
ORDER BY count DESC
|
|
|
LIMIT 50;`, pType)
|
|
|
- portraitRecord := db.Mysql.SelectBySql(sql)
|
|
|
+ portraitRecord := public.Mysql.SelectBySql(sql)
|
|
|
if portraitRecord != nil && len(*portraitRecord) > 0 {
|
|
|
if isWinner {
|
|
|
var winners []string
|
|
@@ -389,7 +399,7 @@ func NewHotEnt(isWinner bool) (data []map[string]interface{}) {
|
|
|
winnerRes := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"terms":{"_id":["%s"]}},"_source":[%s],"size":%d}`, strings.Join(winners, `","`), `"_id","company_name"`, len(winners)))
|
|
|
if winnerRes != nil && len(*winnerRes) > 0 {
|
|
|
for _, v := range *winnerRes {
|
|
|
- winnerMap[common.InterfaceToStr(v["v"])] = v["company_name"]
|
|
|
+ winnerMap[common.InterfaceToStr(v["_id"])] = v["company_name"]
|
|
|
}
|
|
|
for _, v := range *portraitRecord {
|
|
|
if winnerMap[common.InterfaceToStr(v["ent_Id"])] != nil {
|
|
@@ -398,6 +408,59 @@ func NewHotEnt(isWinner bool) (data []map[string]interface{}) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ var buyers []string
|
|
|
+ var buyerName []string
|
|
|
+ for _, v := range *portraitRecord {
|
|
|
+ buyerName = append(buyerName, fmt.Sprintf(`"%s"`, common.InterfaceToStr(v["ent_Id"])))
|
|
|
+ buyers = append(buyers, common.InterfaceToStr(v["ent_Id"]))
|
|
|
+ }
|
|
|
+ buyerMap := make(map[string]map[string]interface{})
|
|
|
+ //采购单位基本信息
|
|
|
+ buyerRes := elastic.Get("buyer", "buyer", fmt.Sprintf(`{"query":{"terms":{"buyer_name":["%s"]}},"_source":[%s],"size":%d}`, strings.Join(buyers, `","`), `"province","city","buyer_name","buyerclass"`, len(buyers)))
|
|
|
+ if buyerRes != nil && len(*buyerRes) > 0 {
|
|
|
+ for _, v := range *buyerRes {
|
|
|
+ buyerMap[common.InterfaceToStr(v["buyer_name"])] = v
|
|
|
+ }
|
|
|
+ for _, v := range *portraitRecord {
|
|
|
+ if vs := buyerMap[common.InterfaceToStr(v["ent_Id"])]; vs != nil {
|
|
|
+ //`"province","city","buyer_name","company_name","buyerclass"`
|
|
|
+ v["province"] = vs["province"]
|
|
|
+ v["city"] = vs["city"]
|
|
|
+ v["buyerclass"] = vs["buyerclass"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //采购单位标讯数
|
|
|
+ buyerCountMap := make(map[string]int)
|
|
|
+ buyerSql := fmt.Sprintf(`{"query": {"bool": {"must": [{"terms": {"buyer": [%s]}},{"range": {"publishtime": {"gte": %d,"lte": %d}}}]}},
|
|
|
+ "aggs": {"count_by_buyer": {"terms": {"field": "buyer","size": %d}}},"size": 0}`, strings.Join(buyerName, ","), time.Now().AddDate(-3, 0, 0).Unix(), time.Now().Unix(), len(buyerName))
|
|
|
+ buyerAggs, _, _ := elastic.GetAggs("bidding", "bidding", buyerSql)
|
|
|
+ if buyerAggs != nil && len(buyerAggs) > 0 {
|
|
|
+ var thisRow BuyerAggregations
|
|
|
+ for name, object := range buyerAggs {
|
|
|
+ bArr, err := object.MarshalJSON()
|
|
|
+ if len(bArr) == 0 || err != nil {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if name == "count_by_buyer" {
|
|
|
+ _ = json.Unmarshal(bArr, &thisRow.CountByBuyer)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, bucket := range thisRow.CountByBuyer.Buckets {
|
|
|
+ buyerCountMap[bucket.Key] = bucket.DocCount
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range *portraitRecord {
|
|
|
+ if vs := buyerMap[common.InterfaceToStr(v["ent_Id"])]; vs != nil {
|
|
|
+ //`"province","city","buyer_name","company_name","buyerclass"`
|
|
|
+ v["province"] = vs["province"]
|
|
|
+ v["city"] = vs["city"]
|
|
|
+ v["buyerclass"] = vs["buyerclass"]
|
|
|
+ }
|
|
|
+ v["count"] = buyerCountMap[common.InterfaceToStr(v["ent_Id"])]
|
|
|
+ }
|
|
|
}
|
|
|
redis.Put("newother", redidsKey, *portraitRecord, 3600*24*7)
|
|
|
if len(*portraitRecord) > 10 {
|
|
@@ -407,6 +470,155 @@ func NewHotEnt(isWinner bool) (data []map[string]interface{}) {
|
|
|
data = *portraitRecord
|
|
|
}
|
|
|
}
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// "last_years_count", "last_one_years_count", "last_two_years_count", "last_three_years_count"
|
|
|
+type Aggregations struct {
|
|
|
+ TopCities struct {
|
|
|
+ Buckets []struct {
|
|
|
+ Key string `json:"key"`
|
|
|
+ LastYearsCount struct {
|
|
|
+ DocCount int `json:"doc_count"`
|
|
|
+ } `json:"last_years_count"`
|
|
|
+ LastOneYearCount struct {
|
|
|
+ DocCount int `json:"doc_count"`
|
|
|
+ } `json:"last_one_years_count"`
|
|
|
+ LastTwoYearsCount struct {
|
|
|
+ DocCount int `json:"doc_count"`
|
|
|
+ } `json:"last_two_years_count"`
|
|
|
+ LastThreeYearsCount struct {
|
|
|
+ DocCount int `json:"doc_count"`
|
|
|
+ } `json:"last_three_years_count"`
|
|
|
+ } `json:"buckets"`
|
|
|
+ } `json:"top_cities"`
|
|
|
+}
|
|
|
+
|
|
|
+// HotIndustryAndRegion 热门行业/地区年度招标趋势
|
|
|
+func HotIndustryAndRegion(ind string) (dataArr []map[string]interface{}) {
|
|
|
+ redisKey := fmt.Sprintf("hotIndustryAndRegion_%s", ind)
|
|
|
+ redisData, _ := redis.Get("newother", redisKey).([]interface{})
|
|
|
+ if redisData != nil && len(redisData) > 0 {
|
|
|
+ dataArr = common.ObjArrToMapArr(redisData)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
+ var thisRow Aggregations
|
|
|
+ var industrys, _ = config.Seoconfig["industry"].(map[string]interface{})
|
|
|
+ var names, _ = industrys[hanLetter(ind)].(map[string]interface{})
|
|
|
+ if len(names) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var subscopeclass []string
|
|
|
+ for _, v := range strings.Split(common.InterfaceToStr(names["NAME"]), ",") {
|
|
|
+ subscopeclass = append(subscopeclass, fmt.Sprintf(`"%s"`, v))
|
|
|
+ }
|
|
|
+ rangeTime, st, et := HotTimeFmt()
|
|
|
+ esHotQuery := fmt.Sprintf(`{
|
|
|
+ "size": 0,"query": {"bool": {"must": [{"range": {"firsttime": {"gte": %d,"lte": %d}}},{"terms": {"subscopeclass": [%s]}}]}},
|
|
|
+ "aggs": {"top_cities": {"terms": {"field": "area","size": %d},"aggs": {%s}}}}`, st, et, strings.Join(subscopeclass, ","), common.IntAll(config.Seoconfig["top_cities"]), strings.Join(rangeTime, ","))
|
|
|
+ res, _, _ := elastic.GetAggs("projectset", "projectset", esHotQuery)
|
|
|
+ if res != nil && len(res) > 0 {
|
|
|
+ for name, object := range res {
|
|
|
+ bArr, err := object.MarshalJSON()
|
|
|
+ if len(bArr) == 0 || err != nil {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if name == "top_cities" {
|
|
|
+ _ = json.Unmarshal(bArr, &thisRow.TopCities)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tm := time.Now()
|
|
|
+ for _, bucket := range thisRow.TopCities.Buckets {
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["area"] = bucket.Key
|
|
|
+ var yearArr []map[string]interface{}
|
|
|
+ if bucket.LastYearsCount.DocCount > 0 {
|
|
|
+ year1 := map[string]interface{}{
|
|
|
+ "year": tm.AddDate(-1, 0, 0).Year(),
|
|
|
+ "count": bucket.LastYearsCount.DocCount,
|
|
|
+ }
|
|
|
+ yearArr = append(yearArr, year1)
|
|
|
+ }
|
|
|
+
|
|
|
+ year2 := map[string]interface{}{
|
|
|
+ "year": tm.AddDate(-2, 0, 0).Year(),
|
|
|
+ "count": bucket.LastOneYearCount.DocCount,
|
|
|
+ }
|
|
|
+ yearArr = append(yearArr, year2)
|
|
|
+ year3 := map[string]interface{}{
|
|
|
+ "year": tm.AddDate(-3, 0, 0).Year(),
|
|
|
+ "count": bucket.LastTwoYearsCount.DocCount,
|
|
|
+ }
|
|
|
+ yearArr = append(yearArr, year3)
|
|
|
+ year4 := map[string]interface{}{
|
|
|
+ "year": tm.AddDate(-4, 0, 0).Year(),
|
|
|
+ "count": bucket.LastThreeYearsCount.DocCount,
|
|
|
+ }
|
|
|
+ yearArr = append(yearArr, year4)
|
|
|
+ data["yearArr"] = yearArr
|
|
|
+ dataArr = append(dataArr, data)
|
|
|
+ }
|
|
|
+ redis.Put("newother", redisKey, dataArr, 3600*24*7)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func hanLetter(han string) string {
|
|
|
+ // 创建拼音转换器
|
|
|
+ p := pinyin.NewArgs()
|
|
|
+
|
|
|
+ // 设置拼音转换器的样式
|
|
|
+ p.Style = pinyin.Initials
|
|
|
+
|
|
|
+ // 转换汉字为拼音
|
|
|
+ pinyinStr := pinyin.Pinyin(han, p)
|
|
|
+
|
|
|
+ // 提取首字母并转为大写
|
|
|
+ var initials []string
|
|
|
+ for _, p1 := range pinyinStr {
|
|
|
+ initials = append(initials, strings.ToUpper(string(p1[0])))
|
|
|
+ }
|
|
|
+ return strings.Join(initials, "")
|
|
|
+}
|
|
|
+
|
|
|
+func HotTimeFmt() (rangeTime []string, sta, ent int64) {
|
|
|
+ staTime := time.Now().AddDate(-3, 0, 0)
|
|
|
+ sta = time.Date(staTime.Year(), time.January, 1, 0, 0, 0, 0, staTime.Location()).Unix()
|
|
|
+ ent = time.Date(time.Now().Year(), time.January, 1, 0, 0, 0, 0, time.Now().Location()).Unix()
|
|
|
+
|
|
|
+ timeArr := []string{"last_years_count", "last_one_years_count", "last_two_years_count", "last_three_years_count"}
|
|
|
+ tm := time.Now()
|
|
|
+ for i := 1; i <= 3; i++ {
|
|
|
+ st := tm.AddDate(-i, 0, 0)
|
|
|
+ yearStart := time.Date(st.Year(), time.January, 1, 0, 0, 0, 0, st.Location()).Unix()
|
|
|
+ // 计算年尾时间戳
|
|
|
+ yearEnd := time.Date(st.Year(), time.December, 31, 23, 59, 59, 0, st.Location()).Unix()
|
|
|
+ rangeTime = append(rangeTime, fmt.Sprintf(`"%s": {
|
|
|
+ "filter": {
|
|
|
+ "range": {
|
|
|
+ "firsttime": {
|
|
|
+ "gte": %d,
|
|
|
+ "lte": %d
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },`, timeArr[i], yearStart, yearEnd))
|
|
|
+ }
|
|
|
+ if time.Now().Month() > time.June { // 统计今年数据
|
|
|
+ ent = time.Now().Unix()
|
|
|
+ yearStart := time.Date(tm.Year(), time.January, 1, 0, 0, 0, 0, tm.Location()).Unix()
|
|
|
+ // 计算年尾时间戳
|
|
|
+ rangeTime = append(rangeTime, fmt.Sprintf(`"%s": {
|
|
|
+ "filter": {
|
|
|
+ "range": {
|
|
|
+ "firsttime": {
|
|
|
+ "gte": %d,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },`, timeArr[0], yearStart))
|
|
|
+ }
|
|
|
return
|
|
|
}
|