|
@@ -1,14 +1,6 @@
|
|
|
package jy
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
- "fmt"
|
|
|
- "log"
|
|
|
- "regexp"
|
|
|
- "sort"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
-
|
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
|
"app.yhyue.com/moapp/jybase/es"
|
|
@@ -20,9 +12,16 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/sms"
|
|
|
. "app.yhyue.com/moapp/jypkg/middleground"
|
|
|
"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "log"
|
|
|
+ "regexp"
|
|
|
+ "sort"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
-//获取用户合并以前,合并以后的openid
|
|
|
+// 获取用户合并以前,合并以后的openid
|
|
|
func GetOldOpenid(s_m_openid, a_m_openid, s_phone string, mergeorder interface{}) string {
|
|
|
a_mergeorder, _ := mergeorder.([]interface{})
|
|
|
openid := ""
|
|
@@ -55,19 +54,20 @@ var filterReg_1 = regexp.MustCompile("^([0-9]{1,3}|[零一二三四五六七八
|
|
|
var filterReg = regexp.MustCompile("^[的人号时元万公告项目地址电话邮编日期联系招标中结果成交项目项目采购采购项目政府采购公告更正公告]+$")
|
|
|
var PhoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
|
|
|
var EmailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
|
|
|
+var filterReg_4 = regexp.MustCompile("([)>》】\\]\\}}〕。,,;;::'\"“”。\\.\\??、/\\+=\\\\_—\\*&……\\^%$¥@!!`~·(\\(<《【\\[\\{{〔])")
|
|
|
|
|
|
-//P279删除通用过滤词,例如“公告”
|
|
|
+// P279删除通用过滤词,例如“公告”
|
|
|
func FilteKey(k string) string {
|
|
|
k = strings.TrimSpace(k)
|
|
|
// k = filterReg_3.ReplaceAllString(k, "")
|
|
|
- k = filterReg_2.ReplaceAllString(k, "")
|
|
|
+ k = filterReg_4.ReplaceAllString(k, " ")
|
|
|
// k = filterReg_1.ReplaceAllString(k, "")
|
|
|
// k = filterReg.ReplaceAllString(k, "")
|
|
|
return k
|
|
|
}
|
|
|
|
|
|
// InterceptSearchKW 超过20个字,截断
|
|
|
-//返回截取后的字符串和截取掉中的前3个字
|
|
|
+// 返回截取后的字符串和截取掉中的前3个字
|
|
|
func InterceptSearchKW(word string, keywordsLimit int, isFilter bool) (b_word, a_word, s_word string) {
|
|
|
if word == "" {
|
|
|
return
|
|
@@ -97,7 +97,7 @@ func HttpEs(ques, analyzer, esAddress string) string {
|
|
|
return es.Analyze(ques, "bidding", analyzer)
|
|
|
}
|
|
|
|
|
|
-//发送邮箱验证码
|
|
|
+// 发送邮箱验证码
|
|
|
func SendMailIdentCode(to, code string, auth []*mail.GmailAuth) bool {
|
|
|
html := fmt.Sprintf(`<div>
|
|
|
<div>
|
|
@@ -133,13 +133,12 @@ func SendMailIdentCode(to, code string, auth []*mail.GmailAuth) bool {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
func SendSMS(address, mobile string, params ...string) {
|
|
|
sms.SendSms(address, "01", mobile, params...)
|
|
|
}
|
|
|
|
|
|
-//发送验证码
|
|
|
-//增加sessionKey字段 更换手机号防止绕过身份校验
|
|
|
+// 发送验证码
|
|
|
+// 增加sessionKey字段 更换手机号防止绕过身份校验
|
|
|
func SendPhoneIdentCode(address, phone string, session *httpsession.Session, sessionKey ...string) bool {
|
|
|
sessionKeyFlag := defaultPhoneFlag
|
|
|
if len(sessionKey) > 0 && sessionKey[0] != "" {
|
|
@@ -164,7 +163,7 @@ func SendPhoneIdentCode(address, phone string, session *httpsession.Session, ses
|
|
|
|
|
|
const defaultPhoneFlag = "identCode"
|
|
|
|
|
|
-//短信验证码校验
|
|
|
+// 短信验证码校验
|
|
|
func CheckPhoneIdent(session *httpsession.Session, code string, sessionKey ...string) string {
|
|
|
sessionKeyFlag := defaultPhoneFlag
|
|
|
if len(sessionKey) > 0 && sessionKey[0] != "" {
|
|
@@ -179,7 +178,7 @@ func CheckPhoneIdent(session *httpsession.Session, code string, sessionKey ...st
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
-//删除短信验证码有关的session
|
|
|
+// 删除短信验证码有关的session
|
|
|
func ClearPhoneIdentSession(session *httpsession.Session, sessionKey ...string) {
|
|
|
sessionKeyFlag := defaultPhoneFlag
|
|
|
if len(sessionKey) > 0 && sessionKey[0] != "" {
|
|
@@ -190,17 +189,17 @@ func ClearPhoneIdentSession(session *httpsession.Session, sessionKey ...string)
|
|
|
session.Del(fmt.Sprintf("%sTime", sessionKeyFlag))
|
|
|
}
|
|
|
|
|
|
-//邮箱校验
|
|
|
+// 邮箱校验
|
|
|
func IsEmail(value string) bool {
|
|
|
return EmailPattern.MatchString(value)
|
|
|
}
|
|
|
|
|
|
-//手机号校验
|
|
|
+// 手机号校验
|
|
|
func IsPhone(phone string) bool {
|
|
|
return PhoneReg.MatchString(phone)
|
|
|
}
|
|
|
|
|
|
-//获取信息行业
|
|
|
+// 获取信息行业
|
|
|
func Getindustrys(industryname string, mongodb MongodbSim) (industry map[string][]string, sortArray []string) {
|
|
|
industry = map[string][]string{}
|
|
|
sortArray = []string{}
|
|
@@ -243,8 +242,7 @@ func Getindustrys(industryname string, mongodb MongodbSim) (industry map[string]
|
|
|
return industry, sortArray
|
|
|
}
|
|
|
|
|
|
-//对应月份
|
|
|
-//
|
|
|
+// 对应月份
|
|
|
func GetMonth(mon string) int {
|
|
|
month := map[string]int{
|
|
|
"January": 1,
|
|
@@ -263,12 +261,12 @@ func GetMonth(mon string) int {
|
|
|
return month[mon]
|
|
|
}
|
|
|
|
|
|
-//value unlimited 并发限制登陆用户
|
|
|
+// value unlimited 并发限制登陆用户
|
|
|
func LoginRedisKey(userid string) string {
|
|
|
return fmt.Sprintf("unlimited_%s", userid)
|
|
|
}
|
|
|
|
|
|
-//获取loginSess
|
|
|
+// 获取loginSess
|
|
|
func GetLoginSess(userid string) []string {
|
|
|
key := LoginRedisKey(userid)
|
|
|
if data, ok := redis.Get("other", key).([]interface{}); ok {
|
|
@@ -277,7 +275,7 @@ func GetLoginSess(userid string) []string {
|
|
|
return []string{}
|
|
|
}
|
|
|
|
|
|
-//判断是否在内
|
|
|
+// 判断是否在内
|
|
|
func IsInLoginSess(key string, arr []string) bool {
|
|
|
for _, v := range arr {
|
|
|
if key == v {
|
|
@@ -298,7 +296,7 @@ type AppLoginPush struct {
|
|
|
PhoneType string `json:"phoneType"`
|
|
|
}
|
|
|
|
|
|
-//更新存储用户sessionid的队列 【sessionid ttl小于三天的清除】 key:sessionid
|
|
|
+// 更新存储用户sessionid的队列 【sessionid ttl小于三天的清除】 key:sessionid
|
|
|
func PutLoginSess(mongodb MongodbSim, apppushRpc, key, userid string, limit, max int) bool {
|
|
|
value := GetLoginSess(userid)
|
|
|
if !IsInLoginSess(key, value) {
|
|
@@ -344,7 +342,7 @@ func PutLoginSess(mongodb MongodbSim, apppushRpc, key, userid string, limit, max
|
|
|
return redis.Put("other", LoginRedisKey(userid), value, -1)
|
|
|
}
|
|
|
|
|
|
-//清除数组中的s
|
|
|
+// 清除数组中的s
|
|
|
func removeArr(arr []string, s string) []string {
|
|
|
result := []string{}
|
|
|
for _, v := range arr {
|
|
@@ -356,7 +354,6 @@ func removeArr(arr []string, s string) []string {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
func LoginOutPush(mongodb MongodbSim, userid, sessid, apppushRpc string) {
|
|
|
rediskey := fmt.Sprintf("app_%s", sessid)
|
|
|
r := redis.Get("other", rediskey)
|
|
@@ -393,7 +390,7 @@ func LoginOutPush(mongodb MongodbSim, userid, sessid, apppushRpc string) {
|
|
|
log.Println("ok:", ok)
|
|
|
}
|
|
|
|
|
|
-//session数组清除某个value[针对多账号同时在线的方法、退出登录时调用]
|
|
|
+// session数组清除某个value[针对多账号同时在线的方法、退出登录时调用]
|
|
|
func DelUnlimitSessionId(sessid, userid string) []string {
|
|
|
sessArr := GetLoginSess(userid)
|
|
|
newArr := []string{}
|
|
@@ -406,7 +403,7 @@ func DelUnlimitSessionId(sessid, userid string) []string {
|
|
|
return newArr
|
|
|
}
|
|
|
|
|
|
-//获取当天结束时间 单位秒
|
|
|
+// 获取当天结束时间 单位秒
|
|
|
func GetExpire() int {
|
|
|
t, _ := time.ParseInLocation(Date_Short_Layout, time.Now().AddDate(0, 0, 1).Format(Date_Short_Layout), time.Local)
|
|
|
t2, _ := time.ParseInLocation(Date_Full_Layout, time.Now().Format(Date_Full_Layout), time.Local)
|
|
@@ -420,10 +417,46 @@ func TimeProcessing(hour interface{}, duration int) time.Time {
|
|
|
return t
|
|
|
}
|
|
|
|
|
|
-//清除用户权益缓存、菜单缓存
|
|
|
+// 清除用户权益缓存、菜单缓存
|
|
|
func ClearUserCache(middleground *Middleground, positionId int64) {
|
|
|
middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
PositionId: fmt.Sprint(positionId),
|
|
|
})
|
|
|
middleground.PowerCheckCenter.DelCheckRedis("10000", positionId)
|
|
|
}
|
|
|
+
|
|
|
+// 关键词分词处理
|
|
|
+func KeywordsProcessing(keywords, sep string) string {
|
|
|
+ keywords = MatchSpace.ReplaceAllString(keywords, " ")
|
|
|
+ if keywords == "" || len(strings.Split(keywords, sep)) == 1 {
|
|
|
+ return keywords
|
|
|
+ }
|
|
|
+ var newWords = make([]string, 0, 0)
|
|
|
+ if keywords != "" && len(strings.Split(keywords, sep)) > 1 {
|
|
|
+ var words = strings.Split(keywords, sep)
|
|
|
+ for k := 0; k < len(words); k++ {
|
|
|
+ v := words[k]
|
|
|
+ //连续性空格
|
|
|
+ if len([]rune(v)) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if len([]rune(v)) == 1 {
|
|
|
+ //compare
|
|
|
+ if k == 0 { //first
|
|
|
+ words[k+1] = v + words[k+1]
|
|
|
+ } else if k == len(words)-1 { //last
|
|
|
+ newWords[len(newWords)-1] += v
|
|
|
+ } else {
|
|
|
+ if len(newWords[len(newWords)-1]) < len(words[k+1]) {
|
|
|
+ newWords[len(newWords)-1] += v
|
|
|
+ } else {
|
|
|
+ words[k+1] = v + words[k+1]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ newWords = append(newWords, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return strings.Join(newWords, sep)
|
|
|
+}
|