jiaojiao7 4 жил өмнө
parent
commit
23864ee9bd

+ 3 - 3
api/v1/projects.go

@@ -35,7 +35,7 @@ func getProjectsList(c *gin.Context) {
 	p := gin.H{
 		"projectName": projectName,
 		"winner":      winner,
-		"bidTime":    bidTime,
+		"bidTime":     bidTime,
 	}
 	bs, _ := json.Marshal(p)
 	param := string(bs)
@@ -47,7 +47,6 @@ func getProjectsList(c *gin.Context) {
 	}
 }
 
-
 //获取项目列表及详情接口
 func getProjectsListDetail(c *gin.Context) {
 	productID := c.MustGet("productID").(int)
@@ -72,7 +71,8 @@ func getProjectDetail(c *gin.Context) {
 	productID := c.MustGet("productID").(int)
 	appID := c.MustGet("appID").(string)
 	requestIP := c.MustGet("requestIP").(string)
-	id := c.PostForm("project_id")
+	_id := c.PostForm("project_id")
+	id := service.SE.DecodeString(_id)
 	p := gin.H{
 		"id": id,
 	}

+ 8 - 1
service/projectDetail.go

@@ -3,19 +3,26 @@ package service
 import (
 	"fmt"
 	"sfbase/core"
+	"sfbase/utils"
 	"sfis/db"
 )
 
+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 := `"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","sourceinfourl"`
 	query := fmt.Sprintf(_query, id, fields)
 	INDEX := core.GetStringConf("es.project.index")
 	TYPE := core.GetStringConf("es.project.itype")
 	infos := db.Es.Get(INDEX, TYPE, query)
 	if infos != nil && len(*infos) > 0 {
 		data = *infos
+		for _, val := range data {
+			val["project_id"] = SE.EncodeString(utils.ObjToString(val["_id"]))
+			delete(val, "_id")
+		}
 	}
 	return data, httpStatus, nil
 }

+ 1 - 3
service/projects.go

@@ -75,8 +75,6 @@ func ProjectListData(projectName, winner, times string, isDetail bool) (data []m
 	INDEX := core.GetStringConf("es.project.index")
 	TYPE := core.GetStringConf("es.project.itype")
 	Es := db.GetEs()
-	global.Logger.Info("INDEX " + INDEX)
-	global.Logger.Info("TYPE " + TYPE)
 	fields := ""
 	if isDetail {
 		fields = pjt_fields
@@ -108,7 +106,7 @@ func GetAllByNgram(Es *elastic.Elastic, index, itype, qstr, findfields, order, f
 		if start > -1 {
 			qstr = qstr[:len(qstr)-1] + `,"from":` + strconv.Itoa(start) + `,"size":` + strconv.Itoa(limit) + "}"
 		}
-		global.Logger.Info("GetAllByNgram:" + qstr)
+		global.Logger.Info("GetAllByNgram方法es查询语句:" + qstr)
 		return Es.Get(index, itype, qstr)
 	} else {
 		return nil

+ 9 - 0
sword_base/utils/stringutil.go

@@ -139,3 +139,12 @@ func GetRandom(n int) string {
 	}
 	return string(b)
 }
+
+func ObjToString(old interface{}) string {
+	if nil == old {
+		return ""
+	} else {
+		r, _ := old.(string)
+		return r
+	}
+}

+ 2 - 1
test/project/project_test.go

@@ -17,6 +17,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"
+	SE = utils.SimpleEncrypt{Key: "topJYBX2019"}
 )
 
 func Test_ProjectListApi(t *testing.T) {
@@ -77,7 +78,7 @@ func Test_ProjectDetails(t *testing.T) {
 	appID := "sfPQRYRQMAAwcGBwYBCgcA"
 	secretKey := "a8Iws4mE"
 	data := make(url.Values)
-	projectId := "5f6b4e12499cb0822d39c68f"
+	projectId := SE.EncodeString("5f6b4e12499cb0822d39c68f")
 	data["project_id"] = []string{projectId}
 	data["app_id"] = []string{appID}
 	now := time.Now().Unix()

+ 0 - 1
utils/cost_by_left_num.go

@@ -36,7 +36,6 @@ func costByLeftNum(getData func() ([]map[string]interface{}, int, error), appID
 	} else {
 		err = errors.New("剩余量不足")
 	}
-	log.Println("1111111", err)
 	return datas, err
 }