wanghuidong %!s(int64=4) %!d(string=hai) anos
pai
achega
1cb0e76d0e
Modificáronse 3 ficheiros con 38 adicións e 24 borrados
  1. 15 9
      api/v1/projects.go
  2. 10 3
      service/projects.go
  3. 13 12
      test/project/project_test.go

+ 15 - 9
api/v1/projects.go

@@ -2,16 +2,13 @@ package v1
 
 import (
 	"encoding/json"
+	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
 	"net/http"
 	"sfbase/global"
 	"sfis/middleware"
-	"sfis/model"
 	"sfis/service"
 	"sfis/utils"
-	"strconv"
-
-	"github.com/gin-gonic/gin"
 )
 
 /**
@@ -23,6 +20,7 @@ func ProjectApiRegister(router *gin.Engine) {
 	{
 		routerGroup.POST("/projectList", getProjectsList)
 		routerGroup.POST("/projectDetail", getProjectDetail)
+		routerGroup.POST("/projectListDetail", getProjectsListDetail)
 	}
 }
 
@@ -53,12 +51,20 @@ func getProjectsList(c *gin.Context) {
 	c.JSON(http.StatusOK, nil)
 }
 
-func projectList(projectName, winner, zbRq string) ([]interface{}, int, error) {
-	data := make([]interface{}, 0)
-	for i := 0; i < 10; i++ {
-		data = append(data, &model.Product{Name: "数据" + strconv.Itoa(i)})
+func projectList(name string, winner string, rq string) ([]interface{}, int, error) {
+	return nil, 0, nil
+}
+
+//获取项目列表及详情接口
+func getProjectsListDetail(c *gin.Context) {
+	winner := c.PostForm("s_winner")
+	global.Logger.Info("winner " + winner)
+	data := &map[string]interface{}{}
+	if winner != "" {
+		data = service.ProjectListData("", winner, "", true)
+
 	}
-	return data, 200, nil
+	c.JSON(http.StatusOK, data)
 }
 
 //获取项目详情

+ 10 - 3
service/projects.go

@@ -12,7 +12,8 @@ import (
 
 var (
 	pjt_count    = 100
-	pjt_field    = `"_id","area","city","bidamount","firsttime","projectname","s_winner","buyer","buyerclass"`
+	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_sort     = `{"firsttime":-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%%"}}`
@@ -22,7 +23,7 @@ var (
 	highlightStr = `%s: {"fragment_size": %d,"number_of_fragments": 1}`
 )
 
-func ProjectListData(projectName, winner, time string) (data *map[string]interface{}) {
+func ProjectListData(projectName, winner, time string, isDetail bool) (data *map[string]interface{}) {
 	global.Logger.Info("projectName " + projectName)
 	global.Logger.Info("winner " + winner)
 	global.Logger.Info("time " + time)
@@ -67,7 +68,13 @@ func ProjectListData(projectName, winner, time string) (data *map[string]interfa
 	Es := db.GetEs()
 	global.Logger.Info("INDEX " + INDEX)
 	global.Logger.Info("TYPE " + TYPE)
-	repl := GetAllByNgram(Es, INDEX, TYPE, qstr, "", pjt_sort, pjt_field, 0, pjt_count, 0, false)
+	fields := ""
+	if isDetail {
+		fields = pjt_fields
+	} else {
+		fields = pjt_field
+	}
+	repl := GetAllByNgram(Es, INDEX, TYPE, qstr, "", pjt_sort, fields, 0, pjt_count, 0, false)
 	if repl != nil && len(*repl) > 0 {
 		(*data)["data"] = repl
 	}

+ 13 - 12
test/project/project_test.go

@@ -16,6 +16,7 @@ import (
 
 var (
 	apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectList"
+	// apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectListDetail"
 )
 
 func Test_ProjectListApi(t *testing.T) {
@@ -64,23 +65,23 @@ func getData1(n int) {
 
 func getData() {
 	data := post(apiurl, map[string]string{
-		"name":   "河南大学",
-		"winner": "洛阳丹尼斯量贩有限公司",
-		"time":   "1545235200_1599014733",
+		"projectname": "河南大学",
+		"s_winner":    "洛阳丹尼斯量贩有限公司",
+		"jgtime":      "1545235200_1599014733",
 	})
 	log.Println(data)
 }
 
 //获取项目详情测试用例
-func Test_ProjectDetails(t *testing.T) {
-	data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
-		"projectid": "5f6b4e12499cb0822d39c68f",
-	})
-	res := map[string]interface{}{}
-	s, _ := json.Marshal(data)
-	json.Unmarshal(s, &res)
-	log.Println("数据:", res)
-}
+// func Test_ProjectDetails(t *testing.T) {
+// 	data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
+// 		"projectid": "5f6b4e12499cb0822d39c68f",
+// 	})
+// 	res := map[string]interface{}{}
+// 	s, _ := json.Marshal(data)
+// 	json.Unmarshal(s, &res)
+// 	log.Println("数据:", res)
+// }
 
 func post(url string, form map[string]string) (data map[string]interface{}) {
 	str := ""