liuxiaolong
2019-08-01 978757c6cd702684d736ddf733f1d718a8c67060
add es cache change
4个文件已修改
110 ■■■■■ 已修改文件
controllers/dbtableperson.go 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/dbtablesCon.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
discovery/server.go 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/EnableStatusControlService.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/dbtableperson.go
@@ -1,10 +1,12 @@
package controllers
import (
    "basic.com/pubsub/protomsg.git"
    "encoding/json"
    "log"
    "strconv"
    "time"
    "webserver/discovery"
    "webserver/extend/logger"
    "github.com/gin-gonic/gin"
@@ -14,6 +16,7 @@
    "webserver/extend/esutil"
    "webserver/extend/util"
    "webserver/models"
    esApi "basic.com/pubsub/esutil.git"
)
type DbPersonController struct {
@@ -60,6 +63,17 @@
    params := string(personbytes)
    logger.Debug("请求url:%s;\n 请求参数params:%s", url, params)
    data, _ := esutil.PutEsDataReq(url, params)
    if data["_id"] !=""{
        //通知比对进程缓存更新
        discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
            Type: protomsg.EsCacheChanged_T_DbTablePerson,
            PersonId: personId,
            TableId: []string{ dbperson.TableId },
            Feature: dbperson.FaceFeature,
            Action: protomsg.DbAction_Insert,
        })
    }
    //c.JSON(200, changeEsRespData(data, "添加人员成功"))
    result = changeEsRespData(data, "添加成功")
    return result
@@ -97,6 +111,23 @@
    result := changeEsRespData(data, "修改成功")
    if result["success"].(bool) {
        //code.Success.Message = "修改底库人员成功"
        if dbperson.Enable == 1 {
            discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
                Type: protomsg.EsCacheChanged_T_DbTablePerson,
                PersonId: dbperson.Id,
                TableId: []string{ dbperson.TableId },
                Feature: "",
                Action: protomsg.DbAction_Insert,
            })
        } else {
            discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
                Type: protomsg.EsCacheChanged_T_DbTablePerson,
                PersonId: dbperson.Id,
                TableId: []string{ dbperson.TableId },
                Feature: "",
                Action: protomsg.DbAction_Delete,
            })
        }
        util.ResponseFormat(c, code.Success, result["data"])
    } else {
        //code.ServiceInsideError.Message += result["msg"].(string)
@@ -127,6 +158,20 @@
    result := changeEsRespData(data, "删除成功")
    if result["success"].(bool) {
        //code.Success.Message = "删除底库人员成功"
        //通知比对进程,此人已删除
        dbperArr, e := esApi.Dbpersoninfosbyid([]string{uuid}, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport)
        if e ==nil && len(dbperArr) > 0{
            if dbperArr[0].TableId !=""{
                discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
                    Type: protomsg.EsCacheChanged_T_DbTablePerson,
                    PersonId: uuid,
                    TableId: []string{ dbperArr[0].TableId },
                    Feature: "",
                    Action: protomsg.DbAction_Delete,
                })
            }
        }
        util.ResponseFormat(c, code.Success, result["data"])
    } else {
        //code.ServiceInsideError.Message += result["msg"].(string)
@@ -158,6 +203,20 @@
    //result := changeEsRespData(data, "删除成功")
    if data["error"] == nil {
        //code.Success.Message = "删除底库人员成功"
        dbperArr, e := esApi.Dbpersoninfosbyid(uuids, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport)
        if e ==nil && len(dbperArr) > 0{
            for _,esPer :=range dbperArr {
                if esPer.TableId !=""{
                    discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
                        Type: protomsg.EsCacheChanged_T_DbTablePerson,
                        PersonId: esPer.Id,
                        TableId: []string{ esPer.TableId },
                        Feature: "",
                        Action: protomsg.DbAction_Delete,
                    })
                }
            }
        }
        util.ResponseFormat(c, code.Success, "删除底库人员成功")
    } else {
        //code.ServiceInsideError.Message += result["msg"].(string)
controllers/dbtablesCon.go
@@ -2,12 +2,14 @@
import (
    "basic.com/dbapi.git"
    "basic.com/pubsub/protomsg.git"
    "encoding/json"
    "fmt"
    "github.com/gin-gonic/gin"
    "github.com/satori/go.uuid"
    "log"
    "time"
    "webserver/discovery"
    "webserver/extend/code"
    "webserver/extend/config"
    "webserver/extend/esutil"
@@ -100,6 +102,23 @@
    result := changeEsRespData(data, "修改成功")
    if result["success"].(bool) {
        //code.Success.Message = "修改底库成功"
        if dbtable.Enable ==1 {
            discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
                Type: protomsg.EsCacheChanged_T_DbTable,
                PersonId: "",
                TableId: []string{ dbtable.Id },
                Feature: "",
                Action: protomsg.DbAction_Insert,
            })
        } else {
            discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
                Type: protomsg.EsCacheChanged_T_DbTable,
                PersonId: "",
                TableId: []string{ dbtable.Id },
                Feature: "",
                Action: protomsg.DbAction_Delete,
            })
        }
        util.ResponseFormat(c, code.Success, result["data"])
    } else {
        //code.ServiceInsideError.Message += result["msg"].(string)
discovery/server.go
@@ -3,10 +3,9 @@
import (
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/gopherdiscovery.git"
    "fmt"
    "github.com/gogo/protobuf/proto"
    "time"
    "webserver/extend/logger"
    "github.com/gogo/protobuf/proto"
)
const (
@@ -16,7 +15,7 @@
//启动discovery的server
var discoveryServer *gopherdiscovery.DiscoveryServer
var dbChangeChan chan *protomsg.DbChangeMessage
var dbChangeChan chan *protomsg.EsPersonCacheChange
func StartServer() {
    var clients []string
    var err error
@@ -34,7 +33,7 @@
    logger.Debug("err:",err)
    logger.Debug("clients: ",clients)
    dbChangeChan = make(chan *protomsg.DbChangeMessage)
    dbChangeChan = make(chan *protomsg.EsPersonCacheChange)
    for {
        select {
@@ -45,14 +44,14 @@
}
//广播数据库改变的msg
func publishMessage(msg *protomsg.DbChangeMessage) {
func publishMessage(msg *protomsg.EsPersonCacheChange) {
    sendBytes,err := proto.Marshal(msg)
    if err ==nil{
        discoveryServer.PublishMsg(string(sendBytes))
    }
}
func AddDbMessage(msg *protomsg.DbChangeMessage) {
    fmt.Println("MSG In")
func AddDbMessage(msg *protomsg.EsPersonCacheChange) {
    logger.Debug("MSG EsPersonCacheChange In")
    dbChangeChan<-msg
}
service/EnableStatusControlService.go
@@ -2,11 +2,13 @@
import (
    "basic.com/dbapi.git"
    "basic.com/pubsub/protomsg.git"
    "encoding/json"
    "fmt"
    "strconv"
    "strings"
    "time"
    "webserver/discovery"
    "webserver/extend/config"
    "webserver/extend/esutil"
    "webserver/extend/logger"
@@ -117,6 +119,23 @@
    }
    if middle > 0 {
        logger.Debug("修改成功")
        if flag {//生效的
            discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
                Type: protomsg.EsCacheChanged_T_DbTable,
                PersonId: "",
                TableId: id,
                Feature: "",
                Action: protomsg.DbAction_Insert,
            })
        } else {//失效的
            discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
                Type: protomsg.EsCacheChanged_T_DbTable,
                PersonId: "",
                TableId: id,
                Feature: "",
                Action: protomsg.DbAction_Insert,
            })
        }
        message = "修改成功"
    }
    return message