Browse Source

feat:提交采购单位、中标企业列表

fuwencai 2 years ago
parent
commit
6ebba44519

+ 132 - 9
src/jfw/modules/app/src/app/front/ws.go

@@ -2,9 +2,11 @@ package front
 
 import (
 	qu "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	"app.yhyue.com/moapp/jybase/redis"
 	"app.yhyue.com/moapp/jypkg/public"
 	"fmt"
+	"github.com/pkg/errors"
 	"jy/src/jfw/modules/app/src/app/jyutil"
 	"log"
 	"strconv"
@@ -14,13 +16,21 @@ import (
 
 // 最后与tags合并后 删除
 var (
-	cacheTime        = 12 // * 60 * 60
-	mobileHref       = "/jyapp/tags/%s/%s"
-	infoTypeRedisKey = "mobile_seo_infoType_home"
-	areaRedisKey     = "mobile_seo_area_home"
-	hotAreaRedisKey  = "mobile_seo_hot_area"
-	hotArea          = "北京,山东,陕西,河南,广东"
-	label            = map[string]string{
+	cacheTime            = 1200 // * 60 * 60
+	mobileHref           = "/jyapp/tags/%s/%s"
+	infoTypeRedisKey     = "mobile_seo_infoType_home"
+	areaRedisKey         = "mobile_seo_area_home"
+	hotAreaRedisKey      = "mobile_seo_hot_area"
+	industryRedisKey     = "mobile_seo_industry"
+	industryLessRedisKey = "mobile_seo_industry_less"
+	buyerListRedisKey    = "mobile_seo_buyer_list_%d"
+	winnerListRedisKey   = "mobile_seo_winner_list_%d"
+	buyerListLimit       = 5000
+	winnerListLimit      = 5000
+	listPageSize         = 25
+
+	hotArea = "北京,山东,陕西,河南,广东"
+	label   = map[string]string{
 		"area":     "area",
 		"infoType": "it",
 		"industry": "indu",
@@ -300,8 +310,8 @@ type BiddingInfo struct {
 
 // GetIndustry 获取行业和行业下标的物
 func GetIndustry(industryHref string) (interface{}, interface{}) {
-	rediskey := fmt.Sprintf("app_index_getIndustry")
-	rediskey2 := fmt.Sprintf("app_index_getIndustry_less") // 少于5个字的
+	rediskey := fmt.Sprintf(industryRedisKey)
+	rediskey2 := fmt.Sprintf(industryLessRedisKey) // 少于5个字的
 	if l := redis.Get("seoCache", rediskey); l != nil {
 		l2 := redis.Get("seoCache", rediskey2)
 		return l, l2
@@ -377,3 +387,116 @@ func GetInsturyKeywords(idstr string) (name, class_1, class_2 string) {
 	}
 	return "", "", ""
 }
+
+// PutListCache
+func PutListCache(redisKey string, redisTimeout int, list []map[string]interface{}) {
+	if b := redis.Put("seoCache", redisKey, list, redisTimeout); !b {
+		log.Printf("保存缓存 redis 异常 key:%s", redisKey)
+	}
+
+}
+
+// GetEntInfoList 采购单位列表/企业列表
+// pageNum:页码
+// identityType :0 采购单位 1 企业
+func GetEntInfoList(pageNum int, identityType int) (list []interface{}) {
+	redisKeyNum := ""
+	redisKey := ""
+	var rs *[]map[string]interface{}
+	switch identityType {
+	case 0:
+		redisKeyNum = fmt.Sprintf(buyerListRedisKey, pageNum)
+		redisKey = buyerListRedisKey
+	case 1:
+		redisKeyNum = fmt.Sprintf(winnerListRedisKey, pageNum)
+		redisKey = winnerListRedisKey
+	}
+	//查缓存
+	if data, err := GetListCache(redisKeyNum); err == nil && len(data) > 0 {
+		return data
+	}
+	// 查数据
+	switch identityType {
+	case 0:
+		rs = selectBuyerInfo(buyerListLimit)
+	case 1:
+		rs = selectEntInfo(winnerListLimit)
+	}
+	if rs == nil || len(*rs) == 0 {
+		return []interface{}{}
+	}
+	for i := 0; i < len(*rs); i++ {
+		(*rs)[i]["id"] = encrypt.EncodeArticleId2ByCheck(qu.ObjToString((*rs)[i]["id"]))
+	}
+	// 存缓存
+	for i := 1; i <= len(*rs)/listPageSize; i++ {
+		tmpKey := fmt.Sprintf(redisKey, i)
+		start := (i - 1) * listPageSize
+		end := i * listPageSize
+		if end > len(*rs) {
+			end = len(*rs)
+		}
+		if i == pageNum {
+			list = qu.MapArrToObjArr((*rs)[start:end])
+		}
+		PutListCache(tmpKey, cacheTime, (*rs)[start:end])
+	}
+	return list
+}
+
+func GetListCache(redisKey string) (list []interface{}, err error) {
+	rs := redis.Get("seoCache", redisKey)
+	if rs == nil {
+		return nil, errors.New("未获取到")
+	}
+	if list, ok := rs.([]interface{}); ok {
+		return list, nil
+	}
+	return nil, errors.New("未获取到缓存信息")
+}
+
+// 获取最新的采购单位
+// limit: 数量
+func selectBuyerInfo(limit int) *[]map[string]interface{} {
+	//
+	//q := `select c. name, c.company_id as id,b.name as buyerclass,p.area as province,ca.city as city   from ( SELECT
+	//        name, company_id, area_code, city_code, name_id
+	//    FROM
+	//        dws_f_ent_baseinfo
+	//    WHERE   company_id!=''and
+	//        (identity_type & (1 << 0)) > 0 order by latest_time desc
+	//    LIMIT ?) c left join dws_f_ent_tags t on( t.name_id=c.name_id) left join code_buyerclass b on (b.code=t.labelvalues) left join code_area p on(p.code=c.area_code)
+	//    left join code_area ca on(ca.code=c.city_code)
+	//      where (identity_type &(1 << 0)) > 0`
+	// todo 测试环境排序字段还没有加 先用下面没有order by 的sql测
+	q := `select c. name, c.company_id as id,b.name as buyerclass,p.area as province,ca.city as city   from ( SELECT
+            name, company_id, area_code, city_code, name_id
+        FROM
+            dws_f_ent_baseinfo
+        WHERE   company_id!=''and
+            (identity_type & (1 << 0)) > 0
+        LIMIT ?) c left join dws_f_ent_tags t on( t.name_id=c.name_id) left join code_buyerclass b on (b.code=t.labelvalues) left join code_area p on(p.code=c.area_code)
+        left join code_area ca on(ca.code=c.city_code)
+          where (identity_type &(1 << 0)) > 0`
+	return public.GlobalCommonMysql.SelectBySql(q, limit)
+}
+
+// 获取最新的中标单位
+// limit: 数量
+func selectEntInfo(limit int) *[]map[string]interface{} {
+	//q := `  select c. name, c.company_id as id,c.address,cb.legal_person,cb.company_status,cb.capital  from ( SELECT
+	//name, company_id,address
+	//FROM
+	//    dws_f_ent_baseinfo
+	//WHERE   company_id!=''and
+	//    (identity_type & (1 << 1)) > 0  order by latest_time desc
+	//    LIMIT ?) c left join company_baseinfo cb on(cb.company_id=c.company_id) `
+	q := `  select c. name, c.company_id as id,c.address,cb.legal_person,cb.company_status,cb.capital  from ( SELECT
+    name, company_id,address
+    FROM
+       dws_f_ent_baseinfo
+    WHERE   company_id!=''and
+       (identity_type & (1 << 1)) > 0
+       LIMIT ?) c left join company_baseinfo cb on(cb.company_id=c.company_id) `
+	return public.GlobalCommonMysql.SelectBySql(q, limit)
+}

+ 9 - 1
src/jfw/modules/app/src/db.json

@@ -59,6 +59,14 @@
 	        "passWord": "=PDT49#80Z!RVv52_z",
 	        "maxOpenConns": 5,
 	        "maxIdleConns": 5
-      	}
+      	},
+      "globalCommon": {
+        "dBName": "global_common_data",
+        "address": "192.168.3.217:4000",
+        "userName": "root",
+        "passWord": "=PDT49#80Z!RVv52_z",
+        "maxOpenConns": 5,
+        "maxIdleConns": 5
+      }
     }
 }

+ 1 - 1
src/jfw/modules/app/src/go.mod

@@ -5,7 +5,7 @@ go 1.18
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20230718012114-37013054344b
 	app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545
-	app.yhyue.com/moapp/jypkg v0.0.0-20230731064332-8e42fae281a1
+	app.yhyue.com/moapp/jypkg v0.0.0-20230802005656-6379ddc03ee0
 	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.13
 	github.com/SKatiyar/qr v0.0.0-20151201054752-25b6bdf44e67
 	github.com/gogf/gf/v2 v2.3.1