修改敏感词过滤代码结构

This commit is contained in:
Rosy-zhudan
2019-08-19 10:27:04 +08:00
parent 9425f3c07a
commit dee9eea64a
9 changed files with 39 additions and 38 deletions

View File

@@ -509,13 +509,28 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
}
func CheckHasSensitiveWord(word string) (bool, error) {
if hasSensitiveWord, sensitiveWord := dao.CheckHasSensitiveWord(word); hasSensitiveWord {
if hasSensitiveWord, sensitiveWord := IsSensitiveWordInList(word); hasSensitiveWord {
return true, errors.New(fmt.Sprintf("不能包含敏感词:[%s]", sensitiveWord))
}
return false, nil
}
func IsSensitiveWordInList(str string) (bool, string) {
wordList, err := dao.GetSensitiveWordList()
if err == nil {
for _, value := range wordList {
keyWord := value.Word
checkHas := strings.Contains(str, keyWord)
if checkHas {
return true, keyWord
}
}
}
return false, ""
}
func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName string) (outSkuNameExt *model.SkuNameExt, err error) {
if skuNameExt.CategoryID == 0 {
return nil, errors.New("CategoryID不能为空")
@@ -1027,4 +1042,4 @@ func UploadImg2Platforms(ctx *jxcontext.Context, parentTask tasksch.ITask, imgUR
}
}
return imgHintMap, err
}
}

View File

@@ -18,7 +18,7 @@ import (
)
const (
canWriteTolocal = !false
canWriteTolocal = false
needStatistic = true
isFilterToBeCreateAndNotSale = true
parallelCount = 5

View File

@@ -416,8 +416,8 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
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 sensitiveWord := GetSensitiveWord(singleStoreHandler, err.Error()); sensitiveWord != "" {
dao.InsertSensitiveWord(sensitiveWord, vendorID, ctx.GetUserName())
}
}
if len(successList) > 0 {
@@ -586,12 +586,12 @@ func ClearRemoteStoreStuffAndSetNew(ctx *jxcontext.Context, parentTask tasksch.I
return rootTask.ID, err
}
func GetSensitiveWords(singleStoreHandler partner.ISingleStoreStoreSkuHandler, str string) string {
var regFindKeyWords = singleStoreHandler.GetRegexp()
var subRegFindKeyWords = regexp.MustCompile(`[^\[\]\"\}]`)
findResult := regFindKeyWords.FindStringSubmatch(str)
func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, str string) string {
var regFindKeyWord = singleStoreHandler.GetSensitiveWordRegexp()
var subRegFindKeyWord = regexp.MustCompile(`[^\[\]\"\}]`)
findResult := regFindKeyWord.FindStringSubmatch(str)
if findResult != nil && len(findResult) > 1 {
findSubResult := subRegFindKeyWords.FindAllString(findResult[1], -1)
findSubResult := subRegFindKeyWord.FindAllString(findResult[1], -1)
return strings.Join(findSubResult, "")
}