|
@@ -2,30 +2,69 @@ package service
|
|
|
|
|
|
import (
|
|
import (
|
|
cm "app.yhyue.com/moapp/jybase/common"
|
|
cm "app.yhyue.com/moapp/jybase/common"
|
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
. "bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/entity"
|
|
. "bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/entity"
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/knowledgeclient"
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/knowledgeclient"
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/util"
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/knowledgeBase/rpc/knowledge/util"
|
|
|
|
+ "log"
|
|
|
|
+ "strconv"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
type CommonPhrasesService struct{}
|
|
type CommonPhrasesService struct{}
|
|
|
|
|
|
|
|
+var (
|
|
|
|
+ INDEX = "common_phrases"
|
|
|
|
+ TYPE = "common_phrases"
|
|
|
|
+)
|
|
|
|
+
|
|
// CommonPhrasesAdd 客服话术添加
|
|
// CommonPhrasesAdd 客服话术添加
|
|
-func (c *CommonPhrasesService) CommonPhrasesAdd(param *knowledgeclient.CommonPhrasesAddReq) (ok bool, msg string) {
|
|
|
|
|
|
+func (c *CommonPhrasesService) CommonPhrasesAdd(param *knowledgeclient.CommonPhrasesAddReq, segment string) (ok bool, msg string) {
|
|
ok = true
|
|
ok = true
|
|
msg = "操作成功"
|
|
msg = "操作成功"
|
|
- if param.Id > 0 {
|
|
|
|
- //编辑
|
|
|
|
|
|
+ //分词
|
|
|
|
+ keywords := ""
|
|
|
|
+ keywordsArr := util.HanlpGetNormalWords(param.Content, segment)
|
|
|
|
+ if len(keywordsArr) != 0 {
|
|
|
|
+ for _, val := range keywordsArr {
|
|
|
|
+ keywords += val + " "
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if keywords == "" {
|
|
|
|
+ keywords = param.Content
|
|
|
|
+ }
|
|
|
|
+ now := time.Now()
|
|
|
|
+ if param.Id > 0 { //编辑
|
|
updateData := map[string]interface{}{
|
|
updateData := map[string]interface{}{
|
|
"classify": param.Classify,
|
|
"classify": param.Classify,
|
|
"content": param.Content,
|
|
"content": param.Content,
|
|
"createPerson": param.EntUserId,
|
|
"createPerson": param.EntUserId,
|
|
- "createTime": time.Now().Local().Format(util.DateFullLayout),
|
|
|
|
|
|
+ "updateTime": time.Now().Local().Format(util.DateFullLayout),
|
|
|
|
+ "keywords": keywords,
|
|
}
|
|
}
|
|
- ok = Mysql.Update(util.COMMONPHRASES, map[string]interface{}{"id": param.Id}, updateData)
|
|
|
|
- if !ok {
|
|
|
|
- msg = "操作失败"
|
|
|
|
|
|
+ ok1 := Mysql.Update(util.COMMONPHRASES, map[string]interface{}{"id": param.Id}, updateData)
|
|
|
|
+ if ok1 {
|
|
|
|
+ query := `{"query":{"bool":{"must":[{"term":{"phrasesId":"` + strconv.Itoa(int(param.Id)) + `"}}],"must_not":[],"should":[]}},"from":0,"size":1,"sort":[],"facets":{}}`
|
|
|
|
+ //修改es数据
|
|
|
|
+ insertData := map[string]interface{}{
|
|
|
|
+ "entId": param.EntId,
|
|
|
|
+ "appId": param.AppId,
|
|
|
|
+ "classify": param.Classify,
|
|
|
|
+ "content": param.Content,
|
|
|
|
+ "createPerson": param.EntUserId,
|
|
|
|
+ "status": 0,
|
|
|
|
+ "createTime": now.Unix(),
|
|
|
|
+ "keywords": keywords,
|
|
|
|
+ "phrasesId": param.Id,
|
|
|
|
+ }
|
|
|
|
+ ok2 := elastic.Del(INDEX, TYPE, query)
|
|
|
|
+ ok3 := elastic.Save(INDEX, TYPE, insertData)
|
|
|
|
+ if !(ok2 && ok3) {
|
|
|
|
+ ok = false
|
|
|
|
+ msg = "操作失败"
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
insertData := map[string]interface{}{
|
|
insertData := map[string]interface{}{
|
|
"entId": param.EntId,
|
|
"entId": param.EntId,
|
|
@@ -34,12 +73,20 @@ func (c *CommonPhrasesService) CommonPhrasesAdd(param *knowledgeclient.CommonPhr
|
|
"content": param.Content,
|
|
"content": param.Content,
|
|
"createPerson": param.EntUserId,
|
|
"createPerson": param.EntUserId,
|
|
"status": 0,
|
|
"status": 0,
|
|
- "createTime": time.Now().Local().Format(util.DateFullLayout),
|
|
|
|
|
|
+ "createTime": now.Local().Format(util.DateFullLayout),
|
|
|
|
+ "keywords": keywords,
|
|
|
|
+ "updateTime": now.Format(util.DateFullLayout),
|
|
}
|
|
}
|
|
in := Mysql.Insert(util.COMMONPHRASES, insertData)
|
|
in := Mysql.Insert(util.COMMONPHRASES, insertData)
|
|
- if in < 0 {
|
|
|
|
- ok = false
|
|
|
|
- msg = "操作失败"
|
|
|
|
|
|
+ if in > -1 {
|
|
|
|
+ insertData["createTime"] = now.Unix()
|
|
|
|
+ insertData["phrasesId"] = in
|
|
|
|
+ delete(insertData, "updateTime")
|
|
|
|
+ ok := elastic.Save(INDEX, TYPE, insertData)
|
|
|
|
+ if !ok {
|
|
|
|
+ ok = false
|
|
|
|
+ msg = "操作失败"
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -62,7 +109,13 @@ func (c *CommonPhrasesService) CommonPhrasesInfo(id int64) (data *knowledgeclien
|
|
|
|
|
|
// CommonPhrasesDel 客服话术删除
|
|
// CommonPhrasesDel 客服话术删除
|
|
func (c *CommonPhrasesService) CommonPhrasesDel(id int64) bool {
|
|
func (c *CommonPhrasesService) CommonPhrasesDel(id int64) bool {
|
|
- ok := Mysql.Update(util.COMMONPHRASES, map[string]interface{}{"id": id}, map[string]interface{}{"status": 1})
|
|
|
|
|
|
+ ok := Mysql.Update(util.COMMONPHRASES, map[string]interface{}{"id": id}, map[string]interface{}{"status": 1, "updateTime": time.Now().Local().Format(util.DateFullLayout)})
|
|
|
|
+ if ok {
|
|
|
|
+ //删除es数据
|
|
|
|
+ query := `{"query":{"bool":{"must":[{"term":{"phrasesId":"` + strconv.Itoa(int(id)) + `"}}],"must_not":[],"should":[]}},"from":0,"size":1,"sort":[],"facets":{}}`
|
|
|
|
+ ok = elastic.Del(INDEX, TYPE, query)
|
|
|
|
+ log.Println(ok, "---------------")
|
|
|
|
+ }
|
|
return ok
|
|
return ok
|
|
}
|
|
}
|
|
|
|
|