Ver código fonte

Merge branch 'master' of http://192.168.3.207:10080/qmx/datatag

Jianghan 5 anos atrás
pai
commit
d658d1ea75

+ 0 - 0
src/models/o_rules.go → src/models/rules.go


+ 115 - 0
src/models/rules_es.go

@@ -0,0 +1,115 @@
+package models
+
+
+
+type QueryObjecct struct {
+	Query struct {
+		Bool struct {
+			Must    []interface{} `json:"must,omitempty"`
+			MustNot []interface{} `json:"must_not,omitempty"`
+			Should  []interface{} `json:"should,omitempty"`
+		} `json:"bool"`
+	} `json:"query"`
+	Size int `json:"-"`
+}
+
+//通用匹配 Must
+type MustObject struct {
+	//省市县
+	AreaCityDistrict *AreaCityDistrict `json:"term,omitempty"`
+	//一级分类、二级分类
+	ToptypeSubtype *ToptypeSubtype `json:"terms,omitempty"`
+	//时间范围
+	Publishtime *Publishtime `json:"range,omitempty"`
+	//字段是或否存在
+	ExistfieldsObject *ExistfieldsObject `json:"constant_score,omitempty"`
+}
+
+//时间范围
+type Publishtime struct {
+	//查询时间
+	PublishtimeObject struct {
+		Gte int `json:"gte"`
+		Lt  int `json:"lt"`
+	} `json:"publishtime,omitempty"`
+}
+
+//省市县
+type AreaCityDistrict struct {
+	Area     string `json:"area,omitempty"`
+	City     string `json:"city,omitempty"`
+	District string `json:"district,omitempty"`
+}
+
+//一级分类、二级分类
+type ToptypeSubtype struct {
+	Toptype []string `json:"toptype,omitempty"`
+	Subtype []string `json:"subtype,omitempty"`
+}
+
+//字段存在 存在放MustNot,字符串为空忽略
+type ExistfieldsObject struct {
+	Filter struct {
+		Missing struct {
+			Field []string `json:"field,omitempty"`
+		} `json:"missing,omitempty"`
+	} `json:"filter,omitempty"`
+}
+
+//全局附加词 should
+type GlobaladdkeyObject struct {
+	MatchPhrase *MatchPhrase `json:"match_phrase,omitempty"`
+}
+
+//全局排除词 must_not
+type GlobalnotkeyObject struct {
+	MatchPhrase *MatchPhrase `json:"match_phrase,omitempty"`
+}
+
+//匹配方式
+type MatchPhrase struct {
+	Title       string `json:"title,omitempty"`
+	Detail      string `json:"detail,omitempty"`
+	Purchasing  string `json:"purchasing,omitempty"`
+	Attachments string `json:"attachments,omitempty"`
+	Projectname string `json:"projectname,omitempty"`
+}
+
+//关键词 should
+type MatchkeyObject struct {
+	MatchPhrase *MatchPhrase `json:"match_phrase"`
+}
+
+//附件词 should
+type AddkeyObject struct {
+	MatchPhrase *MatchPhrase `json:"match_phrase"`
+}
+
+//排除词 must_not
+type NotkeyObject struct {
+	MatchPhrase *MatchPhrase `json:"match_phrase"`
+}
+
+//采购单位行业 should
+type BuyerclassObject struct {
+	Terms struct {
+		Buyerclass []string `json:"buyerclass,omitempty"`
+	} `json:"terms,omitempty"`
+}
+
+//公告行业二级 should
+type SubscopeclassObject struct {
+	Terms struct {
+		Subscopeclass []string `json:"s_subscopeclass,omitempty"`
+	} `json:"terms,omitempty"`
+}
+
+//xf should
+type NewObject struct {
+	Bool struct {
+		Must    []interface{} `json:"must,omitempty"`
+		MustNot []interface{} `json:"must_not,omitempty"`
+		Should  []interface{} `json:"should,omitempty"`
+	} `json:"bool,omitempty"`
+}
+

+ 41 - 0
src/models/tag.go

@@ -0,0 +1,41 @@
+package models
+
+import "gopkg.in/mgo.v2/bson"
+
+type Tag struct {
+	Id                 bson.ObjectId `bson:"_id"`
+	Scustomername      string        `json:"s_customername" bson:"s_customername"`
+	Stagname           string        `json:"s_tagname" bson:"s_tagname"`
+	Ssalesperson       string        `json:"s_salesperson" bson:"s_salesperson"`
+	Istarttime         int           `json:"i_starttime" bson:"i_starttime"`
+	Iendtime           int           `json:"i_endtime" bson:"i_endtime"`
+	Sarea              string        `json:"s_area" bson:"s_area"`
+	Scity              string        `json:"s_city" bson:"s_city"`
+	Sdistrict          string        `json:"s_district" bson:"s_district"`
+	Sglobaladdkey      string        `json:"s_globaladdkey" bson:"s_globaladdkey"`
+	Sglobaladdkeymatch string        `json:"s_globaladdkeymatch" bson:"s_globaladdkeymatch"`
+	Sglobalnotkey      string        `json:"s_globalnotkey" bson:"s_globalnotkey"`
+	Sglobalnotkeymatch string        `json:"s_globalnotkeymatch" bson:"s_globalnotkeymatch"`
+	Orules             []struct {
+		Smatchkey      string `json:"s_matchkey" bson:"s_matchkey"`
+		Snotkey        string `json:"s_notkey" bson:"s_notkey"`
+		Snotkeymatch   string `json:"s_notkeymatch" bson:"s_notkeymatch"`
+		Saddkey        string `json:"s_addkey" bson:"s_addkey"`
+		Saddkeymatch   string `json:"s_addkeymatch" bson:"s_addkeymatch"`
+		Stoptype       string `json:"s_toptype" bson:"s_toptype"`
+		Ssubtype       string `json:"s_subtype" bson:"s_subtype"`
+		Stopscopeclass string `json:"s_topscopeclass" bson:"s_topscopeclass"`
+		Ssubscopeclass string `json:"s_subscopeclass" bson:"s_subscopeclass"`
+		Sbuyerclass    string `json:"s_buyerclass" bson:"s_buyerclass"`
+	} `json:"o_rules" bson:"s_buyerclass"`
+	Sexistfields   string `json:"s_existfields" bson:"s_existfields"`
+	Imaxnum        int    `json:"i_maxnum" bson:"i_maxnum"`
+	Iextfieldstype int    `json:"i_extfieldstype" bson:"i_extfieldstype"`
+	Sesquery       string `json:"s_esquery" bson:"s_esquery"`
+	Iesquerytype   int    `json:"i_esquerytype" bson:"i_esquerytype"`
+	Sdataid        string `json:"s_dataid" bson:"s_dataid"`
+	Icreatetime    int    `json:"i_createtime" bson:"i_createtime"`
+	Iupdatetime    int    `json:"i_updatetime" bson:"i_updatetime"`
+	Screateuser    string `json:"s_createuser" bson:"s_createuser"`
+	Supdateuser    string `json:"s_updateuser" bson:"s_updateuser"`
+}

+ 31 - 15
src/service/import_rules_service.go

@@ -5,14 +5,13 @@ import (
 	"github.com/go-xweb/xweb"
 	"gopkg.in/mgo.v2/bson"
 	"io/ioutil"
-	qu "qfw/util"
 	"util"
 )
 
 type ImportRulesService struct {
 	*xweb.Action
-	importfile xweb.Mapper `xweb:"/service/importfile"` //导入文件excel
-
+	importfile   xweb.Mapper `xweb:"/service/importfile"`   //导入文件excel
+	esgeneration xweb.Mapper `xweb:"/service/esgeneration"` //es generation
 }
 
 func (f *ImportRulesService) Importfile() {
@@ -39,23 +38,40 @@ func (f *ImportRulesService) Importfile() {
 
 //更新xlsx db
 func updateDbXf(id string, rdata map[string]interface{}) (rid string, err error) {
-	m := util.Mgo.GetMgoConn()
-	defer m.Close()
-	var err1 error
+	var err1 bool
 	if id == "" {
 		objectId := bson.NewObjectId()
-		rdata["_id"]=objectId
+		rdata["_id"] = objectId
 		id = objectId.Hex()
-		err1 = m.DB(qu.ObjToString(util.Sysconfig["dbname"])).C("tags").Insert(rdata)
-	} else if bson.IsObjectIdHex(id){
+		err1 = util.Mgo.SaveByOriID("tags",rdata)
+	} else if bson.IsObjectIdHex(id) {
 		tmpid := bson.ObjectIdHex(id)
-		err1 = m.DB(qu.ObjToString(util.Sysconfig["dbname"])).C("tags").Update(bson.M{"_id": tmpid}, bson.M{"$set": rdata})
-	}else {
-		return "",errors.New("id err")
+		err1 = util.Mgo.Update("tags",bson.M{"_id": tmpid}, bson.M{"$set": rdata},false,false)
+	} else {
+		return "", errors.New("id err")
 	}
-	if err1 != nil {
-		return "", err1
+	if !err1  {
+		return "", errors.New("Insert or Update err")
 	} else {
-		return id, err1
+		return id, nil
+	}
+}
+
+func (f *ImportRulesService) Esgeneration() {
+	if f.Method() == "POST" {
+		_id := f.GetString("_id")
+		tmp := make(map[string]string)
+		if bson.IsObjectIdHex(_id) {
+			data, _ := util.Mgo.FindOne("tags", `{"_id":"`+_id+`"}`)
+			if nil != data && len(*data) > 0 {
+				//esstr := util.Utiltags(*data)
+				//tmp["data"] = esstr
+			} else {
+				tmp["err"] = "id no found"
+			}
+		} else {
+			tmp["err"] = "id err"
+		}
+		f.ServeJson(tmp)
 	}
 }

+ 2 - 1
src/service/privateservice.go

@@ -1,7 +1,6 @@
 package service
 
 import (
-	"io/ioutil"
 	qu "qfw/util"
 	"strings"
 
@@ -24,6 +23,8 @@ type Service struct {
 	//rule
 	ruleList   xweb.Mapper `xweb:"/service/rule/list"`   //规则列表
 	ruleCreate xweb.Mapper `xweb:"/service/rule/create"` //规则新建
+
+	//importfile xweb.Mapper `xweb:"/service/importfile"` //导入文件excel
 }
 
 //规则列表

+ 17 - 0
src/util/utiltag.go

@@ -0,0 +1,17 @@
+package util
+
+import (
+	"encoding/json"
+	"models"
+)
+
+func Utiltags(tag map[string]interface{}) string {
+	
+	QueryObjecct := models.QueryObjecct{}
+
+
+
+
+	esbytes, _ := json.Marshal(QueryObjecct)
+	return string(esbytes)
+}