|
@@ -28,7 +28,7 @@ func init() {
|
|
|
_id := c.PostForm("_id")
|
|
|
company_name := c.PostForm("company_name")
|
|
|
alias := c.PostForm("alias")
|
|
|
- history_name := strings.ReplaceAll(c.PostForm("history_name"),";",";")
|
|
|
+ history_name := strings.ReplaceAll(c.PostForm("history_name"), ";", ";")
|
|
|
area_code := c.PostForm("area_code")
|
|
|
province := c.PostForm("province")
|
|
|
city := c.PostForm("city")
|
|
@@ -36,11 +36,11 @@ func init() {
|
|
|
capital := c.PostForm("capital")
|
|
|
company_address := c.PostForm("company_address")
|
|
|
business_scope := c.PostForm("business_scope")
|
|
|
- wechat_accounts := strings.ReplaceAll(c.PostForm("wechat_accounts"),";",";")
|
|
|
+ wechat_accounts := strings.ReplaceAll(c.PostForm("wechat_accounts"), ";", ";")
|
|
|
website := c.PostForm("website")
|
|
|
contact := c.PostForm("contact")
|
|
|
- contacts := make([]map[string]interface{},0)
|
|
|
- jsonerr :=json.Unmarshal([]byte(contact),&contacts)
|
|
|
+ contacts := make([]map[string]interface{}, 0)
|
|
|
+ jsonerr := json.Unmarshal([]byte(contact), &contacts)
|
|
|
if strings.TrimSpace(company_name) == "" {
|
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
|
return
|
|
@@ -50,11 +50,7 @@ func init() {
|
|
|
e := make(map[string]interface{})
|
|
|
e["company_name"] = company_name
|
|
|
e["alias"] = alias
|
|
|
- if len(history_name)>0{
|
|
|
- e["history_name"] = strings.Split(history_name,";")
|
|
|
- }else {
|
|
|
- e["history_name"] =[]string{}
|
|
|
- }
|
|
|
+ e["history_name"] = history_name
|
|
|
e["area_code"] = area_code
|
|
|
e["province"] = province
|
|
|
e["city"] = city
|
|
@@ -62,18 +58,18 @@ func init() {
|
|
|
e["capital"] = capitalfloat
|
|
|
e["company_address"] = company_address
|
|
|
e["business_scope"] = business_scope
|
|
|
- if len(wechat_accounts)>0{
|
|
|
- e["wechat_accounts"] = strings.Split(wechat_accounts,";")
|
|
|
- }else {
|
|
|
+ if len(wechat_accounts) > 0 {
|
|
|
+ e["wechat_accounts"] = strings.Split(wechat_accounts, ";")
|
|
|
+ } else {
|
|
|
e["wechat_accounts"] = []string{}
|
|
|
}
|
|
|
e["website"] = website
|
|
|
if jsonerr != nil {
|
|
|
e["contact"] = []map[string]interface{}{}
|
|
|
- }else {
|
|
|
- for k,v := range contacts{
|
|
|
- if v["updatetime"] == nil{
|
|
|
- contacts[k]["updatetime"]=time.Now().Unix()
|
|
|
+ } else {
|
|
|
+ for k, v := range contacts {
|
|
|
+ if v["updatetime"] == nil {
|
|
|
+ contacts[k]["updatetime"] = time.Now().Unix()
|
|
|
}
|
|
|
}
|
|
|
e["contact"] = contacts
|
|
@@ -82,11 +78,11 @@ func init() {
|
|
|
if bson.IsObjectIdHex(_id) {
|
|
|
//更新
|
|
|
sid = _id
|
|
|
- delete(e,"_id")
|
|
|
- delete(e,"company_name")
|
|
|
+ delete(e, "_id")
|
|
|
+ delete(e, "company_name")
|
|
|
//转换失败不更新
|
|
|
- if jsonerr!= nil {
|
|
|
- delete(e,"contact")
|
|
|
+ if jsonerr != nil {
|
|
|
+ delete(e, "contact")
|
|
|
}
|
|
|
tmpb := Mgo.Update(util.ElasticClientDB, bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": e}, false, false)
|
|
|
//更新es
|
|
@@ -97,27 +93,27 @@ func init() {
|
|
|
Id(sid).Doc(e).Refresh(true).Do()
|
|
|
if err != nil {
|
|
|
log.Println("update qyk err:", err)
|
|
|
- c.JSON(200, gin.H{"rep": 500, "err":"更新es错误"})
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err": "更新es错误"})
|
|
|
return
|
|
|
}
|
|
|
- }else {
|
|
|
- c.JSON(200, gin.H{"rep": 500, "err":"更新mongo错误"})
|
|
|
+ } else {
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err": "更新mongo错误"})
|
|
|
return
|
|
|
}
|
|
|
c.JSON(200, gin.H{"rep": 200, "updateid": sid})
|
|
|
} else {
|
|
|
//不存在直接保存新数据
|
|
|
sid = Mgo.Save(util.ElasticClientDB, e)
|
|
|
- if sid == ""{
|
|
|
- c.JSON(200, gin.H{"rep": 500,"err":"保存mongo出错"})
|
|
|
+ if sid == "" {
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err": "保存mongo出错"})
|
|
|
return
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
delete(e, "_id")
|
|
|
qykredis := util.QykRedisPool.Conn()
|
|
|
defer qykredis.Close()
|
|
|
- if saveRedis:=qykredis.Set(company_name,sid,0);saveRedis.Err()!= nil{
|
|
|
- log.Println("保存redis 错误",saveRedis.Err())
|
|
|
- c.JSON(200, gin.H{"rep": 500,"err":"保存reids出错"})
|
|
|
+ if saveRedis := qykredis.Set(company_name, sid, 0); saveRedis.Err() != nil {
|
|
|
+ log.Println("保存redis 错误", saveRedis.Err())
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err": "保存reids出错"})
|
|
|
return
|
|
|
}
|
|
|
escon := elastic.GetEsConn()
|
|
@@ -150,7 +146,7 @@ func init() {
|
|
|
escon := elastic.GetEsConn()
|
|
|
defer elastic.DestoryEsConn(escon)
|
|
|
res, err := escon.Search(util.ElasticClientIndex).
|
|
|
- Type(util.ElasticClientType).Source(`{"query": {"match_phrase":{"company_name":"`+search+`"}}}`).
|
|
|
+ Type(util.ElasticClientType).Source(`{"query": {"match_phrase":{"company_name":"` + search + `"}}}`).
|
|
|
//Query( elastic.NewMatchPhraseQuery("company_name", search)).
|
|
|
Size(limit).
|
|
|
From(start).
|
|
@@ -160,7 +156,7 @@ func init() {
|
|
|
c.JSON(500, gin.H{"data": []map[string]interface{}{}, "recordsFiltered": 0, "recordsTotal": 0})
|
|
|
return
|
|
|
}
|
|
|
- if res.Hits != nil{
|
|
|
+ if res.Hits != nil {
|
|
|
tmps := make([]map[string]interface{}, 0)
|
|
|
for _, v := range res.Hits.Hits {
|
|
|
tmp := make(map[string]interface{})
|
|
@@ -176,7 +172,7 @@ func init() {
|
|
|
//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})
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
c.JSON(200, gin.H{"data": []map[string]interface{}{}, "recordsFiltered": 0, "recordsTotal": 0})
|
|
|
}
|
|
|
}
|
|
@@ -187,15 +183,15 @@ func init() {
|
|
|
company_name := c.PostForm("company_name")
|
|
|
if bson.IsObjectIdHex(_id) {
|
|
|
delisok := Mgo.Del(util.ElasticClientDB, bson.M{"_id": bson.ObjectIdHex(_id)})
|
|
|
- if !delisok{
|
|
|
- c.JSON(200, gin.H{"rep": 500,"err":"删除mongo错误"})
|
|
|
+ if !delisok {
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err": "删除mongo错误"})
|
|
|
return
|
|
|
}
|
|
|
qykredis := util.QykRedisPool.Conn()
|
|
|
defer qykredis.Close()
|
|
|
- if del := qykredis.Del(company_name);del.Err()!=nil{
|
|
|
- log.Println("delete qyk err:", del.Err(),company_name)
|
|
|
- c.JSON(200, gin.H{"rep": 500,"err":"删除redis错误"})
|
|
|
+ if del := qykredis.Del(company_name); del.Err() != nil {
|
|
|
+ log.Println("delete qyk err:", del.Err(), company_name)
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err": "删除redis错误"})
|
|
|
return
|
|
|
}
|
|
|
escon := elastic.GetEsConn()
|
|
@@ -203,12 +199,12 @@ func init() {
|
|
|
_, err := escon.Delete().Index(util.ElasticClientIndex).Type(util.ElasticClientType).Id(_id).Refresh(true).Do()
|
|
|
if err != nil {
|
|
|
log.Println("delete qyk err:", err)
|
|
|
- c.JSON(200, gin.H{"rep": 500,"err":"删除es错误"})
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err": "删除es错误"})
|
|
|
return
|
|
|
}
|
|
|
c.JSON(200, gin.H{"rep": 200, "data": delisok})
|
|
|
} else {
|
|
|
- c.JSON(200, gin.H{"rep": 400,"err":"参数错误"})
|
|
|
+ c.JSON(200, gin.H{"rep": 400, "err": "参数错误"})
|
|
|
}
|
|
|
})
|
|
|
//queryById
|