|
@@ -28,11 +28,19 @@ func init() {
|
|
|
_id := c.PostForm("_id")
|
|
|
company_name := c.PostForm("company_name")
|
|
|
alias := c.PostForm("alias")
|
|
|
+ history_name := strings.ReplaceAll(c.PostForm("history_name"),";",";")
|
|
|
+ area_code := c.PostForm("area_code")
|
|
|
province := c.PostForm("province")
|
|
|
city := c.PostForm("city")
|
|
|
district := c.PostForm("district")
|
|
|
capital := c.PostForm("capital")
|
|
|
company_address := c.PostForm("company_address")
|
|
|
+ business_scope := c.PostForm("business_scope")
|
|
|
+ wechat_accounts := strings.ReplaceAll(c.PostForm("wechat_accounts"),";",";")
|
|
|
+ website := c.PostForm("website")
|
|
|
+ contact := c.PostForm("contact")
|
|
|
+ contacts := make([]map[string]string,0)
|
|
|
+ jsonerr :=json.Unmarshal([]byte(contact),&contacts)
|
|
|
if strings.TrimSpace(company_name) == "" {
|
|
|
c.JSON(200, gin.H{"rep": 400})
|
|
|
return
|
|
@@ -42,53 +50,78 @@ 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["area_code"] = area_code
|
|
|
e["province"] = province
|
|
|
e["city"] = city
|
|
|
e["district"] = district
|
|
|
e["capital"] = capitalfloat
|
|
|
e["company_address"] = company_address
|
|
|
+ e["business_scope"] = business_scope
|
|
|
+ if len(wechat_accounts)>0{
|
|
|
+ e["wechat_accounts"] = strings.Split(business_scope,";")
|
|
|
+ }else {
|
|
|
+ e["wechat_accounts"] = []string{}
|
|
|
+ }
|
|
|
+ e["website"] = website
|
|
|
+ if jsonerr != nil {
|
|
|
+ e["contact"] = []map[string]string{}
|
|
|
+ }else {
|
|
|
+ e["contact"] = contacts
|
|
|
+ }
|
|
|
var sid string
|
|
|
- if strings.TrimSpace(_id) != "" && bson.IsObjectIdHex(_id) {
|
|
|
+ if bson.IsObjectIdHex(_id) {
|
|
|
+ //更新
|
|
|
sid = _id
|
|
|
- tmpb := Mgo.Update("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": bson.M{
|
|
|
- "company_name": company_name,
|
|
|
- "alias": alias,
|
|
|
- "province": province,
|
|
|
- "city": city,
|
|
|
- "district": district,
|
|
|
- "capital": capitalfloat,
|
|
|
- "company_address": company_address,
|
|
|
- }}, false, false)
|
|
|
+ delete(e,"_id")
|
|
|
+ delete(e,"company_name")
|
|
|
+ tmpb := Mgo.Update(util.ElasticClientDB, bson.M{"_id": bson.ObjectIdHex(_id)}, bson.M{"$set": e}, false, false)
|
|
|
//更新es
|
|
|
if tmpb {
|
|
|
escon := elastic.GetEsConn()
|
|
|
defer elastic.DestoryEsConn(escon)
|
|
|
_, err := escon.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()
|
|
|
+ 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错误"})
|
|
|
+ return
|
|
|
}
|
|
|
+ }else {
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err":"更新mongo错误"})
|
|
|
+ return
|
|
|
}
|
|
|
+ c.JSON(200, gin.H{"rep": 200, "updateid": sid})
|
|
|
} else {
|
|
|
//不存在直接保存新数据
|
|
|
- sid = Mgo.Save("enterprise_qyxy", e)
|
|
|
- delete(e, "_id")
|
|
|
- escon := elastic.GetEsConn()
|
|
|
- defer elastic.DestoryEsConn(escon)
|
|
|
- _, err := escon.Index().Index(util.ElasticClientIndex).Type(util.ElasticClientType).Id(sid).BodyJson(e).Refresh(true).Do()
|
|
|
- if err != nil {
|
|
|
- log.Println("save qyk err:", err)
|
|
|
+ sid = Mgo.Save(util.ElasticClientDB, e)
|
|
|
+ if sid == ""{
|
|
|
+ c.JSON(200, gin.H{"rep": 500,"err":"保存mongo出错"})
|
|
|
+ return
|
|
|
+ }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出错"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ escon := elastic.GetEsConn()
|
|
|
+ defer elastic.DestoryEsConn(escon)
|
|
|
+ _, err := escon.Index().Index(util.ElasticClientIndex).Type(util.ElasticClientType).Id(sid).BodyJson(e).Refresh(true).Do()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("save qyk err:", err)
|
|
|
+ c.JSON(200, gin.H{"rep": 500, "err": "更新es错误"})
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
+ c.JSON(200, gin.H{"rep": 200, "saveid": sid})
|
|
|
}
|
|
|
- c.JSON(200, gin.H{"rep": 200, "saveid": sid})
|
|
|
})
|
|
|
//列表查询
|
|
|
Admin.POST("/audit/query_qyk/list", func(c *gin.Context) {
|
|
@@ -142,17 +175,31 @@ func init() {
|
|
|
//delete
|
|
|
Admin.POST("/audit/qiyeku_info/deleteQyk", func(c *gin.Context) {
|
|
|
_id := c.PostForm("_id")
|
|
|
+ company_name := c.PostForm("company_name")
|
|
|
if bson.IsObjectIdHex(_id) {
|
|
|
- delisok := Mgo.Del("enterprise_qyxy", bson.M{"_id": bson.ObjectIdHex(_id)})
|
|
|
+ delisok := Mgo.Del(util.ElasticClientDB, bson.M{"_id": bson.ObjectIdHex(_id)})
|
|
|
+ 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错误"})
|
|
|
+ return
|
|
|
+ }
|
|
|
escon := elastic.GetEsConn()
|
|
|
defer elastic.DestoryEsConn(escon)
|
|
|
_, 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错误"})
|
|
|
+ return
|
|
|
}
|
|
|
c.JSON(200, gin.H{"rep": 200, "data": delisok})
|
|
|
} else {
|
|
|
- c.JSON(200, gin.H{"rep": 400})
|
|
|
+ c.JSON(200, gin.H{"rep": 400,"err":"参数错误"})
|
|
|
}
|
|
|
})
|
|
|
//queryById
|