|
@@ -1,11 +1,16 @@
|
|
package audit
|
|
package audit
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "context"
|
|
|
|
+ "encoding/json"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
"gopkg.in/mgo.v2/bson"
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
|
+ "gopkg.in/olivere/elastic.v5"
|
|
. "jy/admin"
|
|
. "jy/admin"
|
|
"jy/clear"
|
|
"jy/clear"
|
|
. "jy/mongodbutil"
|
|
. "jy/mongodbutil"
|
|
|
|
+ "jy/util"
|
|
|
|
+ "log"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -33,28 +38,49 @@ func init() {
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ capitalfloat :=clear.ObjToMoney([]interface{}{capital, ""})[0]
|
|
e := make(map[string]interface{})
|
|
e := make(map[string]interface{})
|
|
e["company_name"] = company_name
|
|
e["company_name"] = company_name
|
|
e["alias"] = alias
|
|
e["alias"] = alias
|
|
e["province"] = province
|
|
e["province"] = province
|
|
e["city"] = city
|
|
e["city"] = city
|
|
e["district"] = district
|
|
e["district"] = district
|
|
- e["capital"] = clear.ObjToMoney([]interface{}{capital, ""})[0]
|
|
|
|
|
|
+ e["capital"] = capitalfloat
|
|
e["company_address"] = company_address
|
|
e["company_address"] = company_address
|
|
var sid string
|
|
var sid string
|
|
if strings.TrimSpace(_id) != "" && bson.IsObjectIdHex(_id) {
|
|
if strings.TrimSpace(_id) != "" && bson.IsObjectIdHex(_id) {
|
|
sid = _id
|
|
sid = _id
|
|
- Mgo.Update("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": bson.M{
|
|
|
|
|
|
+ tmpb := Mgo.Update("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": bson.M{
|
|
"company_name": company_name,
|
|
"company_name": company_name,
|
|
"alias": alias,
|
|
"alias": alias,
|
|
"province": province,
|
|
"province": province,
|
|
"city": city,
|
|
"city": city,
|
|
"district": district,
|
|
"district": district,
|
|
- "capital": capital,
|
|
|
|
|
|
+ "capital": capitalfloat,
|
|
"company_address": company_address,
|
|
"company_address": company_address,
|
|
}}, false, false)
|
|
}}, false, false)
|
|
|
|
+ if tmpb{
|
|
|
|
+ _,err := util.ElasticClient.Update().Index(util.ElasticClientIndex).Type(util.ElasticClientType).
|
|
|
|
+ Id(sid).Doc(map[string]interface{}{
|
|
|
|
+ "company_name": company_name,
|
|
|
|
+ "alias": alias,
|
|
|
|
+ "province": province,
|
|
|
|
+ "city": city,
|
|
|
|
+ "district": district,
|
|
|
|
+ "capital": capitalfloat,
|
|
|
|
+ "company_address": company_address,
|
|
|
|
+ }).Refresh("true").Do(context.TODO())
|
|
|
|
+ if err != nil{
|
|
|
|
+ log.Println("update qyk err:",err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
sid = Mgo.Save("enterprise_qyxy", e)
|
|
sid = Mgo.Save("enterprise_qyxy", e)
|
|
|
|
+ delete(e,"_id")
|
|
|
|
+ _,err :=util.ElasticClient.Index().Index(util.ElasticClientIndex).Type(util.ElasticClientType).Id(sid).BodyJson(e).Refresh("true").Do(context.TODO())
|
|
|
|
+ if err != nil{
|
|
|
|
+ log.Println("save qyk err:",err)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
c.JSON(200, gin.H{"rep": 200, "saveid": sid})
|
|
c.JSON(200, gin.H{"rep": 200, "saveid": sid})
|
|
})
|
|
})
|
|
@@ -65,12 +91,39 @@ func init() {
|
|
limitstr, _ := c.GetPostForm("length")
|
|
limitstr, _ := c.GetPostForm("length")
|
|
start, _ := strconv.Atoi(startstr)
|
|
start, _ := strconv.Atoi(startstr)
|
|
limit, _ := strconv.Atoi(limitstr)
|
|
limit, _ := strconv.Atoi(limitstr)
|
|
|
|
+ if limit < 1 {
|
|
|
|
+ limit = 10
|
|
|
|
+ }
|
|
if search == "" {
|
|
if search == "" {
|
|
c.JSON(200, gin.H{"data": []map[string]interface{}{}, "recordsFiltered": 0, "recordsTotal": 0})
|
|
c.JSON(200, gin.H{"data": []map[string]interface{}{}, "recordsFiltered": 0, "recordsTotal": 0})
|
|
} else {
|
|
} else {
|
|
- count := Mgo.Count("enterprise_qyxy", bson.M{"company_name": bson.M{"$regex": bson.RegEx{search, "i"}}})
|
|
|
|
- data, _ := Mgo.Find("enterprise_qyxy", bson.M{"company_name": bson.M{"$regex": bson.RegEx{search, "i"}}}, `{"_id":-1}`, nil, false, start, limit)
|
|
|
|
- c.JSON(200, gin.H{"data": data, "recordsFiltered": count, "recordsTotal": count})
|
|
|
|
|
|
+ //log.Println(util.ElasticClientIndex, util.ElasticClientType, search)
|
|
|
|
+ res, err := util.ElasticClient.Search(util.ElasticClientIndex).
|
|
|
|
+ Type(util.ElasticClientType).
|
|
|
|
+ Query( elastic.NewMatchPhraseQuery("company_name", search)).
|
|
|
|
+ Size(limit).
|
|
|
|
+ From(start).
|
|
|
|
+ Do(context.TODO())
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println(err)
|
|
|
|
+ c.JSON(500, gin.H{"data": []map[string]interface{}{}, "recordsFiltered": 0, "recordsTotal": 0})
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ tmps := make([]map[string]interface{}, 0)
|
|
|
|
+ for _, v := range res.Hits.Hits {
|
|
|
|
+ tmp := make(map[string]interface{})
|
|
|
|
+ err := json.Unmarshal(*v.Source, &tmp)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println(err)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ tmp["_id"] = v.Id
|
|
|
|
+ //log.Println(tmp)
|
|
|
|
+ tmps = append(tmps, tmp)
|
|
|
|
+ }
|
|
|
|
+ //count := Mgo.Count("enterprise_qyxy", bson.M{"company_name": bson.M{"$regex": bson.RegEx{search, "i"}}})
|
|
|
|
+ //data, _ := Mgo.Find("enterprise_qyxy", bson.M{"company_name": bson.M{"$regex": bson.RegEx{search, "i"}}}, `{"_id":-1}`, nil, false, start, limit)
|
|
|
|
+ c.JSON(200, gin.H{"data": tmps, "recordsFiltered": res.Hits.TotalHits, "recordsTotal": res.Hits.TotalHits})
|
|
}
|
|
}
|
|
})
|
|
})
|
|
//delete
|
|
//delete
|
|
@@ -78,6 +131,10 @@ func init() {
|
|
_id := c.PostForm("_id")
|
|
_id := c.PostForm("_id")
|
|
if bson.IsObjectIdHex(_id) {
|
|
if bson.IsObjectIdHex(_id) {
|
|
delisok := Mgo.Del("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)})
|
|
delisok := Mgo.Del("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)})
|
|
|
|
+ _,err := util.ElasticClient.Delete().Index(util.ElasticClientIndex).Type(util.ElasticClientType).Id(_id).Refresh("true").Do(context.TODO())
|
|
|
|
+ if err != nil{
|
|
|
|
+ log.Println("delete qyk err:",err)
|
|
|
|
+ }
|
|
c.JSON(200, gin.H{"rep": 200, "data": delisok})
|
|
c.JSON(200, gin.H{"rep": 200, "data": delisok})
|
|
} else {
|
|
} else {
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
@@ -101,6 +158,14 @@ func init() {
|
|
//log.Println(_id,industrys)
|
|
//log.Println(_id,industrys)
|
|
if bson.IsObjectIdHex(_id) {
|
|
if bson.IsObjectIdHex(_id) {
|
|
b := Mgo.Update("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": bson.M{"industry": industrys}}, false, false)
|
|
b := Mgo.Update("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": bson.M{"industry": industrys}}, false, false)
|
|
|
|
+ if b {
|
|
|
|
+ _,err := util.ElasticClient.Update().Index(util.ElasticClientIndex).Type(util.ElasticClientType).Id(_id).Doc(map[string]interface{}{
|
|
|
|
+ "industry":industrys,
|
|
|
|
+ }).Refresh("true").Do(context.TODO())
|
|
|
|
+ if err != nil{
|
|
|
|
+ log.Println("update yqk industry err :",err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
c.JSON(200, gin.H{"rep": 200, "data": b})
|
|
c.JSON(200, gin.H{"rep": 200, "data": b})
|
|
} else {
|
|
} else {
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
@@ -124,10 +189,10 @@ func init() {
|
|
for i, v := range contact_types {
|
|
for i, v := range contact_types {
|
|
contacts[i]["contact_type"] = v
|
|
contacts[i]["contact_type"] = v
|
|
}
|
|
}
|
|
- for i,v := range phones{
|
|
|
|
|
|
+ for i, v := range phones {
|
|
contacts[i]["phone"] = v
|
|
contacts[i]["phone"] = v
|
|
}
|
|
}
|
|
- for i,v := range topscopeclasss{
|
|
|
|
|
|
+ for i, v := range topscopeclasss {
|
|
contacts[i]["topscopeclass"] = v
|
|
contacts[i]["topscopeclass"] = v
|
|
contacts[i]["updatetime"] = time.Now().Unix()
|
|
contacts[i]["updatetime"] = time.Now().Unix()
|
|
}
|
|
}
|
|
@@ -135,15 +200,17 @@ func init() {
|
|
// log.Println(k,v)
|
|
// log.Println(k,v)
|
|
//}
|
|
//}
|
|
b := Mgo.Update("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": bson.M{"contact": contacts}}, false, false)
|
|
b := Mgo.Update("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": bson.M{"contact": contacts}}, false, false)
|
|
|
|
+ if b {
|
|
|
|
+ _,err := util.ElasticClient.Update().Index(util.ElasticClientIndex).Type(util.ElasticClientType).Id(_id).Doc(map[string]interface{}{
|
|
|
|
+ "contact":contacts,
|
|
|
|
+ }).Refresh("true").Do(context.TODO())
|
|
|
|
+ if err != nil{
|
|
|
|
+ log.Println("update yqk contact err :",err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
c.JSON(200, gin.H{"rep": 200, "data": b})
|
|
c.JSON(200, gin.H{"rep": 200, "data": b})
|
|
} else {
|
|
} else {
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
}
|
|
}
|
|
- //if bson.IsObjectIdHex(_id) {
|
|
|
|
- // b := Mgo.Update("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": bson.M{"industry": industrys}}, false, false)
|
|
|
|
- // c.JSON(200, gin.H{"rep": 200, "data": b})
|
|
|
|
- //} else {
|
|
|
|
- // c.JSON(200, gin.H{"rep": 400})
|
|
|
|
- //}
|
|
|
|
})
|
|
})
|
|
}
|
|
}
|