敏感词过滤
This commit is contained in:
@@ -508,6 +508,14 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
|
|||||||
return skuNamesInfo, err
|
return skuNamesInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckHasSensitiveWord(word string) (bool, error) {
|
||||||
|
if hasSensitiveWord, sensitiveWord := dao.CheckHasSensitiveWord(word); hasSensitiveWord {
|
||||||
|
return true, errors.New(fmt.Sprintf("不能包含敏感词:[%s]", sensitiveWord))
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName string) (outSkuNameExt *model.SkuNameExt, err error) {
|
func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName string) (outSkuNameExt *model.SkuNameExt, err error) {
|
||||||
if skuNameExt.CategoryID == 0 {
|
if skuNameExt.CategoryID == 0 {
|
||||||
return nil, errors.New("CategoryID不能为空")
|
return nil, errors.New("CategoryID不能为空")
|
||||||
@@ -520,6 +528,10 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hasSensitiveWord, err := CheckHasSensitiveWord(skuNameExt.Name); hasSensitiveWord {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
dao.Begin(db)
|
dao.Begin(db)
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -615,13 +627,19 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
|
|||||||
return outSkuNameExt, err
|
return outSkuNameExt, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||||
skuName := &model.SkuName{}
|
skuName := &model.SkuName{}
|
||||||
skuName.ID = nameID
|
skuName.ID = nameID
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
if err = dao.GetEntity(db, skuName); err != nil {
|
if err = dao.GetEntity(db, skuName); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newSkuName := utils.Interface2String(payload["name"])
|
||||||
|
if hasSensitiveWord, err := CheckHasSensitiveWord(newSkuName); hasSensitiveWord {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
delete(payload, "isSpu")
|
delete(payload, "isSpu")
|
||||||
delete(payload, "ImgHashCode")
|
delete(payload, "ImgHashCode")
|
||||||
delete(payload, "ImgWeimob")
|
delete(payload, "ImgWeimob")
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package cms
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
|
||||||
@@ -403,6 +404,11 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
|||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
successList = batchedStoreSkuList
|
successList = batchedStoreSkuList
|
||||||
|
} else {
|
||||||
|
//handle error for sensitive words, if find, then insert to table sensitive_words
|
||||||
|
if sensitiveWords := GetSensitiveWords(singleStoreHandler, err.Error()); sensitiveWords != "" {
|
||||||
|
dao.InsertSensitiveWord(sensitiveWords)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(successList) > 0 {
|
if len(successList) > 0 {
|
||||||
updateStoreSku(dao.GetDB(), vendorID, successList, model.SyncFlagNewMask)
|
updateStoreSku(dao.GetDB(), vendorID, successList, model.SyncFlagNewMask)
|
||||||
@@ -569,3 +575,15 @@ func ClearRemoteStoreStuffAndSetNew(ctx *jxcontext.Context, parentTask tasksch.I
|
|||||||
}
|
}
|
||||||
return rootTask.ID, err
|
return rootTask.ID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSensitiveWords(singleStoreHandler partner.ISingleStoreStoreSkuHandler, str string) string {
|
||||||
|
var regFindKeyWords = singleStoreHandler.GetRegexp()
|
||||||
|
var subRegFindKeyWords = regexp.MustCompile(`[^\[\]\"\}]`)
|
||||||
|
findResult := regFindKeyWords.FindStringSubmatch(str)
|
||||||
|
if findResult != nil && len(findResult) > 1 {
|
||||||
|
findSubResult := subRegFindKeyWords.FindAllString(findResult[1], -1)
|
||||||
|
return strings.Join(findSubResult, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
32
business/model/dao/sensitive_words.go
Normal file
32
business/model/dao/sensitive_words.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetSensitiveWordList() (wordList []*model.SensitiveWords, err error) {
|
||||||
|
sql := `SELECT * FROM sensitive_words`
|
||||||
|
err = GetRows(nil, &wordList, sql)
|
||||||
|
return wordList, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func InsertSensitiveWord(word string) error {
|
||||||
|
return CreateEntity(nil, &model.SensitiveWords{Words: word})
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckHasSensitiveWord(str string) (bool, string) {
|
||||||
|
wordList, err := GetSensitiveWordList()
|
||||||
|
if err == nil {
|
||||||
|
for _, value := range wordList {
|
||||||
|
keyWord := value.Words
|
||||||
|
checkHas := strings.Contains(str, keyWord)
|
||||||
|
if checkHas {
|
||||||
|
return true, keyWord
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, ""
|
||||||
|
}
|
||||||
6
business/model/sensitive_words.go
Normal file
6
business/model/sensitive_words.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type SensitiveWords struct {
|
||||||
|
ID int `orm:"column(id)" json:"id"`
|
||||||
|
Words string `orm:"size(30);column(words);unique" json:"words"`
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package partner
|
|||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
"regexp"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
@@ -137,6 +137,8 @@ type ISingleStoreStoreSkuHandler interface {
|
|||||||
|
|
||||||
IsErrCategoryExist(err error) (isExist bool)
|
IsErrCategoryExist(err error) (isExist bool)
|
||||||
IsErrCategoryNotExist(err error) (isNotExist bool)
|
IsErrCategoryNotExist(err error) (isNotExist bool)
|
||||||
|
|
||||||
|
GetRegexp() *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildSkuName(skuID int, vendorSkuID string) (skuName *SkuNameInfo) {
|
func BuildSkuName(skuID int, vendorSkuID string) (skuName *SkuNameInfo) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package ebai
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
"regexp"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
@@ -387,3 +387,7 @@ func vendorSkuList2Jx(vendorSkuList []*ebaiapi.SkuInfo) (skuNameList []*partner.
|
|||||||
}
|
}
|
||||||
return skuNameList
|
return skuNameList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetRegexp() *regexp.Regexp {
|
||||||
|
return regexp.MustCompile(`商品名称中含有敏感词(\[.*\])`)
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package mtwm
|
package mtwm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
@@ -365,3 +366,7 @@ func vendorSkuList2Jx(appFoodList []*mtwmapi.AppFood) (skuNameList []*partner.Sk
|
|||||||
}
|
}
|
||||||
return skuNameList
|
return skuNameList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetRegexp() *regexp.Regexp {
|
||||||
|
return regexp.MustCompile(`包含敏感词:(\[.*\])`)
|
||||||
|
}
|
||||||
@@ -53,6 +53,7 @@ func Init() {
|
|||||||
orm.RegisterModel(&model.NewConfig{})
|
orm.RegisterModel(&model.NewConfig{})
|
||||||
|
|
||||||
orm.RegisterModel(&model.CasbinRule{})
|
orm.RegisterModel(&model.CasbinRule{})
|
||||||
|
orm.RegisterModel(&model.SensitiveWords{})
|
||||||
// create table
|
// create table
|
||||||
orm.RunSyncdb("default", false, true)
|
orm.RunSyncdb("default", false, true)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user