xuzhiheng 4 gadi atpakaļ
vecāks
revīzija
a37e8ef4d6
3 mainītis faili ar 230 papildinājumiem un 10 dzēšanām
  1. 64 5
      service/projectDetail.go
  2. 78 5
      service/projects.go
  3. 88 0
      sword_base/utils/stringutil.go

+ 64 - 5
service/projectDetail.go

@@ -5,6 +5,7 @@ import (
 	"sfbase/core"
 	"sfbase/utils"
 	"sfis/db"
+	"strings"
 )
 
 var SE = utils.SimpleEncrypt{Key: "topJYBX2019"}
@@ -12,7 +13,7 @@ var SE = utils.SimpleEncrypt{Key: "topJYBX2019"}
 func ProjectDetailData(id string) (data []map[string]interface{}, httpStatus int, err error) {
 	httpStatus = 200
 	_query := `{"query":{"bool":{"must":[{"term":{"id":"%s"}}],"must_not":[],"should":[]}},"_source":[%s]}`
-	fields := `"_id","s_winner","projectname","projectcode","buyer","buyertel","buyerperson","jgtime","zbtime","bidamount","budget","buyerclass","area","city","sourceinfourl"`
+	fields := `"_id","s_winner","projectname","projectcode","buyer","buyertel","buyerperson","jgtime","zbtime","bidamount","budget","buyerclass","area","city","bidstatus","package1","list"`
 	query := fmt.Sprintf(_query, id, fields)
 	INDEX := core.GetStringConf("es.project.index")
 	TYPE := core.GetStringConf("es.project.itype")
@@ -21,10 +22,68 @@ func ProjectDetailData(id string) (data []map[string]interface{}, httpStatus int
 		return nil, 200, err
 	}
 	if infos != nil && len(*infos) > 0 {
-		data = *infos
-		for _, val := range data {
-			val["project_id"] = SE.EncodeString(utils.ObjToString(val["_id"]))
-			delete(val, "_id")
+		for _, i := range *infos {
+			if i["list"] != nil {
+				bidStatusStr := "中标、成交、流标、废标、合同"
+				subStr := "中标、成交、合同"
+				subStrs := "招标、邀标、询价、竞谈、竞价、单一"
+				publish := int64(0)
+				if listArr, ok := i["list"].([]interface{}); ok {
+					if utils.ObjToString(i["bidstatus"]) == "招标" {
+						for _, v := range listArr {
+							if vs, oks := v.(map[string]interface{}); oks {
+								if strings.Contains(subStrs, utils.ObjToString(vs["subrtype"])) {
+									publishs := publish
+									publish = utils.Int64All(vs["publishtime"])
+									if publishs > publish {
+										publish = publishs
+									}
+								}
+							}
+						}
+					} else if strings.Contains(bidStatusStr, utils.ObjToString(i["bidstatus"])) {
+						for _, v := range listArr {
+							if vs, oks := v.(map[string]interface{}); oks {
+								if strings.Contains(subStr, utils.ObjToString(vs["subrtype"])) {
+									publishs := publish
+									publish = utils.Int64All(vs["publishtime"])
+									if publishs > publish {
+										publish = publishs
+									}
+								}
+							}
+						}
+					}
+					for _, v := range listArr {
+						if vs, oks := v.(map[string]interface{}); oks {
+							publishs := utils.Int64All(vs["publishtime"])
+							if publishs == publish {
+								i["url"] = vs["href"]
+								infoid := utils.ObjToString(vs["infoid"])
+								i["jyUrl"] = `https://www.jianyu360.com/article/content/` + utils.CommonEncodeArticle("content", infoid) + `.html`
+							}
+						}
+					}
+				}
+			}
+			dataMap := map[string]interface{}{
+				"projectId":   SE.EncodeString(utils.ObjToString(i["_id"])),
+				"projectName": i["projectname"],
+				"winner":      i["s_winner"],
+				"projectCode": i["projectcode"],
+				"buyer":       i["buyer"],
+				"buyerPerson": i["buyerperson"],
+				"buyerTel":    i["buyertel"],
+				"buyerClass":  i["buyerclass"],
+				"tenderDate":  i["zbtime"],
+				"bidDate":     i["jgtime"],
+				"bidAmount":   i["bidamount"],
+				"budget":      i["budget"],
+				"province":    i["area"],
+				"city":        i["city"],
+				"package":     i["package1"],
+			}
+			data = append(data, dataMap)
 		}
 	}
 	return data, httpStatus, nil

+ 78 - 5
service/projects.go

@@ -9,6 +9,7 @@ import (
 	"sfbase/utils"
 	"sfis/db"
 	"sfis/model"
+
 	"strconv"
 	"strings"
 	"time"
@@ -19,7 +20,7 @@ import (
 var (
 	pjt_count    = 100
 	pjt_field    = `"_id","jgtime","zbtime","projectname","buyer","buyerclass"`
-	pjt_fields   = `"_id","area","city","bidamount","budget","zbtime","jgtime","projectname","projectcode","s_winner","buyer","buyerclass","buyerperson","buyertel","sourceinfourl"`
+	pjt_fields   = `"_id","area","city","bidamount","budget","zbtime","jgtime","projectname","projectcode","s_winner","buyer","buyerclass","buyerperson","buyertel","package1","list","bidstatus"`
 	pjt_sort     = `{"jgtime":-1}`
 	query        = `{"query": {"bool": {"must":[%s],"should":[%s],"minimum_should_match": 1}}}`
 	query_string = `{"constant_score": {"boost": 2,"query": {"match_phrase": {"projectname.pname": {"analyzer": "my_ngram","query": "%s","slop": 6}}}}},{"multi_match": {"query": "%s","fields": ["projectname.pname"],"analyzer": "ik","minimum_should_match": "100%%"}}`
@@ -86,10 +87,82 @@ func ProjectListData(productId int, appid, projectName, winner, times string, is
 		err = errors.New("查询失败")
 		return
 	} else if repl != nil && len(*repl) > 0 {
-		data = *repl
-		for _, i := range data {
-			i["project_id"] = SE.EncodeString(utils.ObjToString(i["_id"]))
-			delete(i, "_id")
+		for _, i := range *repl {
+			if isDetail {
+				if i["list"] != nil {
+					bidStatusStr := "中标、成交、流标、废标、合同"
+					subStr := "中标、成交、合同"
+					subStrs := "招标、邀标、询价、竞谈、竞价、单一"
+					publish := int64(0)
+					if listArr, ok := i["list"].([]interface{}); ok {
+						if utils.ObjToString(i["bidstatus"]) == "招标" {
+							for _, v := range listArr {
+								if vs, oks := v.(map[string]interface{}); oks {
+									if strings.Contains(subStrs, utils.ObjToString(vs["subrtype"])) {
+										publishs := publish
+										publish = utils.Int64All(vs["publishtime"])
+										if publishs > publish {
+											publish = publishs
+										}
+									}
+								}
+							}
+						} else if strings.Contains(bidStatusStr, utils.ObjToString(i["bidstatus"])) {
+							for _, v := range listArr {
+								if vs, oks := v.(map[string]interface{}); oks {
+									if strings.Contains(subStr, utils.ObjToString(vs["subrtype"])) {
+										publishs := publish
+										publish = utils.Int64All(vs["publishtime"])
+										if publishs > publish {
+											publish = publishs
+										}
+									}
+								}
+							}
+						}
+						for _, v := range listArr {
+							if vs, oks := v.(map[string]interface{}); oks {
+								publishs := utils.Int64All(vs["publishtime"])
+								if publishs == publish {
+									i["url"] = vs["href"]
+									infoid := utils.ObjToString(vs["infoid"])
+									i["jyUrl"] = `https://www.jianyu360.com/article/content/` + utils.CommonEncodeArticle("content", infoid) + `.html`
+								}
+							}
+						}
+					}
+				}
+				dataMap := map[string]interface{}{
+					"projectId":   SE.EncodeString(utils.ObjToString(i["_id"])),
+					"projectName": i["projectname"],
+					"winner":      i["s_winner"],
+					"projectCode": i["projectcode"],
+					"buyer":       i["buyer"],
+					"buyerPerson": i["buyerperson"],
+					"buyerTel":    i["buyertel"],
+					"buyerClass":  i["buyerclass"],
+					"tenderDate":  i["zbtime"],
+					"bidDate":     i["jgtime"],
+					"bidAmount":   i["bidamount"],
+					"budget":      i["budget"],
+					"province":    i["area"],
+					"city":        i["city"],
+					"package":     i["package1"],
+					"url":         i["url"],
+					"jyUrl":       i["jyUrl"],
+				}
+				data = append(data, dataMap)
+			} else {
+				dataMap := map[string]interface{}{
+					"projectId":   SE.EncodeString(utils.ObjToString(i["_id"])),
+					"projectName": i["projectname"],
+					"buyer":       i["buyer"],
+					"buyerClass":  i["buyerclass"],
+					"tenderDate":  i["zbtime"],
+					"bidDate":     i["jgtime"],
+				}
+				data = append(data, dataMap)
+			}
 		}
 	}
 	return

+ 88 - 0
sword_base/utils/stringutil.go

@@ -8,6 +8,7 @@ import (
 	"io"
 	"math/big"
 	"math/rand"
+	"net/url"
 	"strconv"
 	"strings"
 	"time"
@@ -196,6 +197,93 @@ func ObjArrToMapArr(old []interface{}) []map[string]interface{} {
 	}
 }
 
+func Int64All(num interface{}) int64 {
+	if i, ok := num.(int64); ok {
+		return int64(i)
+	} else if i0, ok0 := num.(int32); ok0 {
+		return int64(i0)
+	} else if i1, ok1 := num.(float64); ok1 {
+		return int64(i1)
+	} else if i2, ok2 := num.(int); ok2 {
+		return int64(i2)
+	} else if i3, ok3 := num.(float32); ok3 {
+		return int64(i3)
+	} else if i4, ok4 := num.(string); ok4 {
+		i64, _ := strconv.ParseInt(i4, 10, 64)
+		//in, _ := strconv.Atoi(i4)
+		return i64
+	} else if i5, ok5 := num.(int16); ok5 {
+		return int64(i5)
+	} else if i6, ok6 := num.(int8); ok6 {
+		return int64(i6)
+	} else if i7, ok7 := num.(*big.Int); ok7 {
+		in, _ := strconv.ParseInt(fmt.Sprint(i7), 10, 64)
+		return int64(in)
+	} else if i8, ok8 := num.(*big.Float); ok8 {
+		in, _ := strconv.ParseInt(fmt.Sprint(i8), 10, 64)
+		return int64(in)
+	} else {
+		return 0
+	}
+}
+
+func Float64All(num interface{}) float64 {
+	if i, ok := num.(float64); ok {
+		return float64(i)
+	} else if i0, ok0 := num.(int32); ok0 {
+		return float64(i0)
+	} else if i1, ok1 := num.(int64); ok1 {
+		return float64(i1)
+	} else if i2, ok2 := num.(int); ok2 {
+		return float64(i2)
+	} else if i3, ok3 := num.(float32); ok3 {
+		return float64(i3)
+	} else if i4, ok4 := num.(string); ok4 {
+		in, _ := strconv.ParseFloat(i4, 64)
+		return in
+	} else if i5, ok5 := num.(int16); ok5 {
+		return float64(i5)
+	} else if i6, ok6 := num.(int8); ok6 {
+		return float64(i6)
+	} else if i6, ok6 := num.(uint); ok6 {
+		return float64(i6)
+	} else if i6, ok6 := num.(uint8); ok6 {
+		return float64(i6)
+	} else if i6, ok6 := num.(uint16); ok6 {
+		return float64(i6)
+	} else if i6, ok6 := num.(uint32); ok6 {
+		return float64(i6)
+	} else if i6, ok6 := num.(uint64); ok6 {
+		return float64(i6)
+	} else if i7, ok7 := num.(*big.Float); ok7 {
+		in, _ := strconv.ParseFloat(fmt.Sprint(i7), 64)
+		return float64(in)
+	} else if i8, ok8 := num.(*big.Int); ok8 {
+		in, _ := strconv.ParseFloat(fmt.Sprint(i8), 64)
+		return float64(in)
+	} else {
+		return 0
+	}
+}
+
+//通用加密
+func CommonEncodeArticle(stype string, keys ...string) (id string) {
+	//正文
+	var SE = &SimpleEncrypt{Key: "topnet2015topnet2015"}
+	var SE2 = &SimpleEncrypt{Key: "2017jianyu"}
+	if stype == "content" {
+		id = BEncodeArticleId2ByCheck("A", SE, SE2, keys...)
+	}
+	return
+}
+
+//短地址加密,二次加密带校验和
+func BEncodeArticleId2ByCheck(h string, s1, s2 *SimpleEncrypt, keys ...string) string {
+	kstr := strings.Join(keys, ",")
+	kstr = s1.EncodeStringByCheck(kstr)
+	return url.QueryEscape(h + GetLetterRandom(2) + s2.EncodeStringByCheck(kstr))
+}
+
 /**
 产生一般订单编号方法
 */