|
@@ -1,10 +1,14 @@
|
|
|
package audit
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
. "jy/admin"
|
|
|
+ "jy/clear"
|
|
|
. "jy/mongodbutil"
|
|
|
+ "jy/util"
|
|
|
"log"
|
|
|
qu "qfw/util"
|
|
|
+ "qfw/util/elastic"
|
|
|
redis "qfw/util/redis"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -23,7 +27,8 @@ func init() {
|
|
|
Admin.POST("/audit/addsave", AddSave) //新增
|
|
|
Admin.POST("/audit/auditsave", AuditSave) //保存
|
|
|
Admin.POST("/audit/alldel", AllDel) //批量删除
|
|
|
-
|
|
|
+ Admin.POST("/audit/allaudit", AllAudit) //批量审核
|
|
|
+ Admin.POST("/audit/datasave", DataSave) //标准库数据审核
|
|
|
}
|
|
|
|
|
|
func AuditData(c *gin.Context) {
|
|
@@ -58,6 +63,7 @@ func AllDel(c *gin.Context) {
|
|
|
}
|
|
|
c.JSON(200, gin.H{"rep": true})
|
|
|
}
|
|
|
+
|
|
|
func AuditOneField(c *gin.Context) {
|
|
|
field, _ := c.GetPostForm("field")
|
|
|
coll, _ := c.GetPostForm("coll")
|
|
@@ -83,10 +89,216 @@ func AuditOneField(c *gin.Context) {
|
|
|
for k, d := range *data {
|
|
|
d["num"] = k + 1 + page*10
|
|
|
d["topscopeclass"] = strings.Join(qu.ObjArrToStringArr(d["topscopeclass"].([]interface{})), ",")
|
|
|
+ d["text"] = d[field]
|
|
|
}
|
|
|
c.JSON(200, gin.H{"data": data, "recordsFiltered": count, "recordsTotal": count})
|
|
|
}
|
|
|
|
|
|
+func AllAudit(c *gin.Context) {
|
|
|
+ field, _ := c.GetPostForm("field")
|
|
|
+ coll, _ := c.GetPostForm("coll")
|
|
|
+ ids, _ := c.GetPostForm("ids")
|
|
|
+ idsArr := strings.Split(ids, ",")
|
|
|
+ log.Println("Audit Ids:", idsArr)
|
|
|
+ names, _ := c.GetPostForm("names")
|
|
|
+ namesArr := strings.Split(names, ",")
|
|
|
+ if len(idsArr) != len(namesArr) {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "数据错误"})
|
|
|
+ } else { //批量审核
|
|
|
+ SaveDb := ""
|
|
|
+ FieldBd := 0
|
|
|
+ ElasticClientIndex := ""
|
|
|
+ ElasticClientType := ""
|
|
|
+ RedisName := util.QYK_RedisName
|
|
|
+ if field == "winner" {
|
|
|
+ SaveDb = util.ElasticClientDB
|
|
|
+ FieldBd = util.WinnerDB
|
|
|
+ ElasticClientIndex = util.ElasticClientIndex
|
|
|
+ ElasticClientType = util.ElasticClientType
|
|
|
+ } else if field == "buyer" {
|
|
|
+ SaveDb = util.ElasticClientBuyerDB
|
|
|
+ FieldBd = util.BuyerDB
|
|
|
+ ElasticClientIndex = util.ElasticClientBuyerIndex
|
|
|
+ ElasticClientType = util.ElasticClientBuyerType
|
|
|
+ } else {
|
|
|
+ SaveDb = util.ElasticClientAgencyDB
|
|
|
+ FieldBd = util.AgencyDB
|
|
|
+ ElasticClientIndex = util.ElasticClientAgencyIndex
|
|
|
+ ElasticClientType = util.ElasticClientAgencyType
|
|
|
+ }
|
|
|
+ //redis
|
|
|
+ qykredis := redis.RedisPool[RedisName].Get()
|
|
|
+ defer qykredis.Close()
|
|
|
+ //es
|
|
|
+ escon := elastic.GetEsConn()
|
|
|
+ defer elastic.DestoryEsConn(escon)
|
|
|
+ for i, name := range namesArr {
|
|
|
+ e := make(map[string]interface{})
|
|
|
+ e["comeintime"] = time.Now().Unix()
|
|
|
+ if field == "winner" {
|
|
|
+ e["company_name"] = name
|
|
|
+ } else if field == "buyer" {
|
|
|
+ e["buyer_name"] = name
|
|
|
+ } else {
|
|
|
+ e["agency_name"] = name
|
|
|
+ }
|
|
|
+ sid := Mgo.Save(SaveDb, e)
|
|
|
+ if sid == "" {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "保存mongo出错"})
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ if _, err := qykredis.Do("SELECT", FieldBd); err != nil {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "select redis出错"})
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ if _, saveRedisErr := qykredis.Do("SET", name, sid); saveRedisErr != nil {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "保存redis出错"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _, err := escon.Index().Index(ElasticClientIndex).Type(ElasticClientType).Id(sid).BodyJson(e).Refresh(true).Do()
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "更新es错误"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除标记数据
|
|
|
+ coll, _ := c.GetPostForm("coll")
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "_id": qu.StringTOBsonId(idsArr[i]),
|
|
|
+ }
|
|
|
+ b := Mgo.Del(coll, query)
|
|
|
+ if !b {
|
|
|
+ log.Println("Del Audit Data Error coll:", coll, " field:", field, " id:", idsArr[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+func DataSave(c *gin.Context) {
|
|
|
+ SaveDb := ""
|
|
|
+ FieldBd := 0
|
|
|
+ ElasticClientIndex := ""
|
|
|
+ ElasticClientType := ""
|
|
|
+ RedisName := util.QYK_RedisName
|
|
|
+ //企业名称
|
|
|
+ e := make(map[string]interface{})
|
|
|
+ field, _ := c.GetPostForm("field")
|
|
|
+ name, _ := c.GetPostForm("name")
|
|
|
+ address, _ := c.GetPostForm("address")
|
|
|
+ if field == "winner" {
|
|
|
+ SaveDb = util.ElasticClientDB
|
|
|
+ FieldBd = util.WinnerDB
|
|
|
+ ElasticClientIndex = util.ElasticClientIndex
|
|
|
+ ElasticClientType = util.ElasticClientType
|
|
|
+ capital, _ := c.GetPostForm("capital")
|
|
|
+ capitalfloat := clear.ObjToMoney([]interface{}{capital, ""})[0]
|
|
|
+ business_scope, _ := c.GetPostForm("business_scope")
|
|
|
+ e["capital"] = capitalfloat
|
|
|
+ e["business_scope"] = business_scope
|
|
|
+ e["company_name"] = name
|
|
|
+ e["company_address"] = address
|
|
|
+ } else if field == "buyer" {
|
|
|
+ SaveDb = util.ElasticClientBuyerDB
|
|
|
+ FieldBd = util.BuyerDB
|
|
|
+ ElasticClientIndex = util.ElasticClientBuyerIndex
|
|
|
+ ElasticClientType = util.ElasticClientBuyerType
|
|
|
+ buyerclass, _ := c.GetPostForm("buyerclass")
|
|
|
+ ranks, _ := c.GetPostForm("ranks")
|
|
|
+ buyer_type, _ := c.GetPostForm("type")
|
|
|
+ e["buyerclass"] = buyerclass
|
|
|
+ e["ranks"] = ranks
|
|
|
+ e["type"] = buyer_type
|
|
|
+ e["buyer_name"] = name
|
|
|
+ e["address"] = address
|
|
|
+ } else {
|
|
|
+ SaveDb = util.ElasticClientAgencyDB
|
|
|
+ FieldBd = util.AgencyDB
|
|
|
+ ElasticClientIndex = util.ElasticClientAgencyIndex
|
|
|
+ ElasticClientType = util.ElasticClientAgencyType
|
|
|
+ ranks, _ := c.GetPostForm("ranks")
|
|
|
+ agency_type, _ := c.GetPostForm("type")
|
|
|
+ e["ranks"] = ranks
|
|
|
+ e["type"] = agency_type
|
|
|
+ e["agency_name"] = name
|
|
|
+ e["address"] = address
|
|
|
+ }
|
|
|
+ //历史名称
|
|
|
+ history_name, _ := c.GetPostForm("history_name")
|
|
|
+ history_name = strings.ReplaceAll(history_name, ";", ";")
|
|
|
+ e["history_name"] = history_name
|
|
|
+ //城市信息
|
|
|
+ area_code, _ := c.GetPostForm("area_code")
|
|
|
+ province, _ := c.GetPostForm("province")
|
|
|
+ city, _ := c.GetPostForm("city")
|
|
|
+ district, _ := c.GetPostForm("district")
|
|
|
+ e["area_code"] = area_code
|
|
|
+ e["province"] = province
|
|
|
+ e["city"] = city
|
|
|
+ e["district"] = district
|
|
|
+ //公众号
|
|
|
+ wechat_accounts, _ := c.GetPostForm("wechat_accounts")
|
|
|
+ wechat_accounts = strings.ReplaceAll(wechat_accounts, ";", ";")
|
|
|
+ if len(wechat_accounts) > 0 {
|
|
|
+ e["wechat_accounts"] = strings.Split(wechat_accounts, ";")
|
|
|
+ } else {
|
|
|
+ e["wechat_accounts"] = []string{}
|
|
|
+ }
|
|
|
+ //网址
|
|
|
+ website, _ := c.GetPostForm("website")
|
|
|
+ e["website"] = website
|
|
|
+ //联系人
|
|
|
+ contact, _ := c.GetPostForm("contact")
|
|
|
+ contacts := make([]map[string]interface{}, 0)
|
|
|
+ jsonerr := json.Unmarshal([]byte(contact), &contacts)
|
|
|
+ if jsonerr != nil {
|
|
|
+ e["contact"] = []map[string]interface{}{}
|
|
|
+ } else {
|
|
|
+ for k, v := range contacts {
|
|
|
+ if v["updatetime"] == nil {
|
|
|
+ contacts[k]["updatetime"] = time.Now().Unix()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e["contact"] = contacts
|
|
|
+ }
|
|
|
+ //入库时间
|
|
|
+ e["comeintime"] = time.Now().Unix()
|
|
|
+ //新数据保存
|
|
|
+ sid := Mgo.Save(SaveDb, e)
|
|
|
+ if sid == "" {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "保存mongo出错"})
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ qykredis := redis.RedisPool[RedisName].Get()
|
|
|
+ defer qykredis.Close()
|
|
|
+ if _, err := qykredis.Do("SELECT", FieldBd); err != nil {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "select redis出错"})
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ if _, saveRedisErr := qykredis.Do("SET", name, sid); saveRedisErr != nil {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "保存redis出错"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ escon := elastic.GetEsConn()
|
|
|
+ defer elastic.DestoryEsConn(escon)
|
|
|
+ _, err := escon.Index().Index(ElasticClientIndex).Type(ElasticClientType).Id(sid).BodyJson(e).Refresh(true).Do()
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, gin.H{"rep": false, "msg": "更新es错误"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除标记数据
|
|
|
+ coll, _ := c.GetPostForm("coll")
|
|
|
+ _id, _ := c.GetPostForm("_id")
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "_id": qu.StringTOBsonId(_id),
|
|
|
+ }
|
|
|
+ b := Mgo.Del(coll, query)
|
|
|
+ if !b {
|
|
|
+ log.Println("Del Audit Data Error coll:", coll, " field:", field, " id:", _id)
|
|
|
+ }
|
|
|
+ c.JSON(200, gin.H{"rep": true, "msg": "保存成功"})
|
|
|
+}
|
|
|
func BuyerClass(c *gin.Context) {
|
|
|
data, _ := Mgo.Find("classify", `{"i_type":1}`, `{"_id":-1}`, `{"s_name":1,"child":1}`, false, -1, -1)
|
|
|
c.JSON(200, gin.H{"data": data})
|