|
@@ -1,7 +1,6 @@
|
|
|
package model
|
|
|
|
|
|
import (
|
|
|
- "context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
IC "jyBXSubscribe/rpc/init"
|
|
@@ -20,7 +19,7 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/mongodb"
|
|
|
"app.yhyue.com/moapp/jybase/mysql"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
- "bp.jydev.jianyu360.cn/BaseService/jyCodeService/rpc/codeservice/codeservice"
|
|
|
+ P "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
)
|
|
@@ -36,21 +35,19 @@ const (
|
|
|
MemberFlag = "mType"
|
|
|
EntnicheFlag = "eType"
|
|
|
oneDay = 24 * 60 * 60
|
|
|
- Baseinfo = "global_common_data.dws_f_bid_baseinfo"
|
|
|
- BidTags = "global_common_data.dws_f_bid_tags"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- ennicheInsertCollKey = []string{"entid", "deptid", "userid", "infoid", "matchkeys", "date", "source", "product"}
|
|
|
- subscribeInsertCollKey = []string{"userid", "infoid", "matchkeys", "date", "isvip"}
|
|
|
- memberInsertCollKey = []string{"userid", "infoid", "matchkeys", "date"}
|
|
|
+ ennicheInsertCollKey = []string{"infoid", "matchkeys", "date", "area", "city", "buyerclass", "toptype", "subtype", "subscopeclass", "budget", "bidamount", "attachment_count", "userid", "entid", "deptid", "source", "product"}
|
|
|
+ subscribeInsertCollKey = []string{"infoid", "matchkeys", "date", "area", "city", "buyerclass", "toptype", "subtype", "subscopeclass", "budget", "bidamount", "attachment_count", "userid", "isvip"}
|
|
|
+ memberInsertCollKey = []string{"infoid", "matchkeys", "date", "area", "city", "buyerclass", "toptype", "subtype", "subscopeclass", "budget", "bidamount", "attachment_count", "userid"}
|
|
|
)
|
|
|
|
|
|
var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
|
|
|
- SubFreeFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
- SubVipFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
- MemberFlag: &AboutDbMsg{"pushmember", "memberpush"},
|
|
|
- EntnicheFlag: &AboutDbMsg{"pushentniche", "entnichepush"},
|
|
|
+ SubFreeFlag: &AboutDbMsg{"push.pushsubscribe", "subpush"},
|
|
|
+ SubVipFlag: &AboutDbMsg{"push.pushsubscribe", "subpush"},
|
|
|
+ MemberFlag: &AboutDbMsg{"push.pushmember", "memberpush"},
|
|
|
+ EntnicheFlag: &AboutDbMsg{"push.pushentniche", "entnichepush"},
|
|
|
}
|
|
|
|
|
|
type AboutDbMsg struct {
|
|
@@ -391,15 +388,9 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
|
|
|
func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, endtime int64, size int, isLimit bool) (result []*bxsubscribe.SubscribeInfo, count int64) {
|
|
|
querys := []string{}
|
|
|
userStr := " "
|
|
|
- leftJoinStr := " "
|
|
|
var (
|
|
|
countSql, findSql string
|
|
|
)
|
|
|
- codeMap, err := IC.CodeLib.CodeTransformation(context.Background(), &codeservice.Request{})
|
|
|
- if codeMap.Data == nil || err != nil {
|
|
|
- logx.Error("代码表获取失败")
|
|
|
- return result, count
|
|
|
- }
|
|
|
querys = append(querys, " 1=1 ")
|
|
|
if spqp.SelectInfoIds != nil && len(spqp.SelectInfoIds) > 0 {
|
|
|
countSql = fmt.Sprintf("select count(1) as count from %s a where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
|
|
@@ -422,8 +413,8 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
//城市
|
|
|
city := []string{}
|
|
|
for _, v := range strings.Split(spqp.City, ",") {
|
|
|
- if codeMap.Data.City[v] != "" {
|
|
|
- city = append(city, fmt.Sprint(codeMap.Data.City[v]))
|
|
|
+ if P.PushMapping.City[v] > 0 {
|
|
|
+ city = append(city, fmt.Sprint(P.PushMapping.City[v]))
|
|
|
} else {
|
|
|
city = append(city, "-1")
|
|
|
}
|
|
@@ -432,14 +423,14 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
city = append(city, "9999")
|
|
|
}
|
|
|
if len(city) > 0 {
|
|
|
- sqlAreaCity = fmt.Sprintf("b.city_code in (%s)", strings.Join(city, ","))
|
|
|
+ sqlAreaCity = fmt.Sprintf("city in (%s)", strings.Join(city, ","))
|
|
|
}
|
|
|
//区域
|
|
|
var sqlArea = ""
|
|
|
area := []string{}
|
|
|
for _, v := range strings.Split(spqp.Area, ",") {
|
|
|
- if codeMap.Data.Area[v] != "" {
|
|
|
- area = append(area, fmt.Sprint(codeMap.Data.Area[v]))
|
|
|
+ if P.PushMapping.Area[v] > 0 {
|
|
|
+ area = append(area, fmt.Sprint(P.PushMapping.Area[v]))
|
|
|
} else {
|
|
|
area = append(area, "-1")
|
|
|
}
|
|
@@ -448,7 +439,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
area = append(area, "9999")
|
|
|
}
|
|
|
if len(area) > 0 {
|
|
|
- sqlArea = fmt.Sprintf("b.area_code in (%s)", strings.Join(area, ","))
|
|
|
+ sqlArea = fmt.Sprintf("a.area in (%s)", strings.Join(area, ","))
|
|
|
}
|
|
|
if sqlAreaCity != "" && sqlArea != "" {
|
|
|
sqlAreaCity = "( " + sqlAreaCity + " or " + sqlArea + " )"
|
|
@@ -463,15 +454,13 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if spqp.Buyerclass != "" {
|
|
|
buyerclass := []string{}
|
|
|
for _, v := range strings.Split(spqp.Buyerclass, ",") {
|
|
|
- if codeMap.Data.Buyerclass[v] != "" {
|
|
|
- buyerclass = append(buyerclass, fmt.Sprint(codeMap.Data.Buyerclass[v]))
|
|
|
- }
|
|
|
+ buyerclass = append(buyerclass, fmt.Sprint(P.PushMapping.Buyerclass[v]))
|
|
|
}
|
|
|
if len(buyerclass) == 1 {
|
|
|
buyerclass = append(buyerclass, "9999")
|
|
|
}
|
|
|
if len(buyerclass) > 0 {
|
|
|
- querys = append(querys, fmt.Sprintf("b.buyerclass_code in (%s)", strings.Join(buyerclass, ",")))
|
|
|
+ querys = append(querys, fmt.Sprintf("a.buyerclass_code in (%s)", strings.Join(buyerclass, ",")))
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -479,28 +468,25 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if spqp.Subtype != "" {
|
|
|
subtype := []string{}
|
|
|
for _, v := range strings.Split(spqp.Subtype, ",") {
|
|
|
- if codeMap.Data.Subtype[v] != "" {
|
|
|
- subtype = append(subtype, fmt.Sprint(codeMap.Data.Subtype[v]))
|
|
|
- }
|
|
|
+ subtype = append(subtype, fmt.Sprintf("find_in_set('%d',a.subscopeclass)", P.PushMapping.Subscopeclass[v]))
|
|
|
}
|
|
|
if len(subtype) == 1 {
|
|
|
subtype = append(subtype, "9999")
|
|
|
}
|
|
|
if len(subtype) > 0 {
|
|
|
- querys = append(querys, fmt.Sprintf("b.subtype_code in (%s)", strings.Join(subtype, ",")))
|
|
|
+ querys = append(querys, fmt.Sprintf("a.subtype_code in (%s)", strings.Join(subtype, ",")))
|
|
|
}
|
|
|
}
|
|
|
//信息行业
|
|
|
if spqp.Subscopeclass != "" {
|
|
|
find_in_set := []string{}
|
|
|
for _, v := range strings.Split(spqp.Subscopeclass, ",") {
|
|
|
- if codeMap.Data.Subscopeclass[v] != "" {
|
|
|
- find_in_set = append(find_in_set, codeMap.Data.Subscopeclass[v])
|
|
|
- }
|
|
|
+ find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%d',a.subscopeclass)", P.PushMapping.Subscopeclass[v]))
|
|
|
}
|
|
|
- if len(find_in_set) > 0 {
|
|
|
- leftJoinStr = fmt.Sprintf(" STRAIGHT_JOIN %s t on t.infoid = b.infoid and t.labelcode=2 ", BidTags)
|
|
|
- querys = append(querys, fmt.Sprintf(" t.labelvalues in (%s)", strings.Join(find_in_set, ",")))
|
|
|
+ if len(find_in_set) == 1 {
|
|
|
+ querys = append(querys, find_in_set[0])
|
|
|
+ } else if len(find_in_set) > 1 {
|
|
|
+ querys = append(querys, fmt.Sprintf("(%s)", strings.Join(find_in_set, " or ")))
|
|
|
}
|
|
|
}
|
|
|
//关键词
|
|
@@ -521,21 +507,20 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
|
|
|
maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
|
|
|
if minPriceStr != "" && maxPriceStr != "" {
|
|
|
- querys = append(querys, fmt.Sprintf("((b.bidamount>=%d and b.bidamount<=%d) or (b.budget>=%d and b.budget<=%d and b.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
|
|
|
+ querys = append(querys, fmt.Sprintf("((a.bidamount>=%d and a.bidamount<=%d) or (a.budget>=%d and a.budget<=%d and a.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
|
|
|
} else if minPriceStr != "" {
|
|
|
- querys = append(querys, fmt.Sprintf("(b.bidamount>=%d or (b.budget>=%d and b.bidamount is null))", minPrice, minPrice))
|
|
|
+ querys = append(querys, fmt.Sprintf("(a.bidamount>=%d or (a.budget>=%d and a.bidamount is null))", minPrice, minPrice))
|
|
|
} else if maxPriceStr != "" {
|
|
|
- querys = append(querys, fmt.Sprintf("(b.bidamount<=%d or (b.budget<=%d and b.bidamount is null))", maxPrice, maxPrice))
|
|
|
+ querys = append(querys, fmt.Sprintf("(a.bidamount<=%d or (a.budget<=%d and a.bidamount is null))", maxPrice, maxPrice))
|
|
|
}
|
|
|
}
|
|
|
//附件
|
|
|
if spqp.FileExists != "" {
|
|
|
if spqp.FileExists == "1" {
|
|
|
- querys = append(querys, fmt.Sprintf("b.isvalidfile =1 "))
|
|
|
+ querys = append(querys, fmt.Sprintf("a.attachment_count is not null"))
|
|
|
} else if spqp.FileExists == "-1" {
|
|
|
- querys = append(querys, fmt.Sprintf("b.isvalidfile =0 "))
|
|
|
+ querys = append(querys, fmt.Sprintf("a.attachment_count is null"))
|
|
|
}
|
|
|
- }
|
|
|
// 是否已读
|
|
|
if spqp.IsRead != "" {
|
|
|
if spqp.IsRead == "0" {
|
|
@@ -579,13 +564,20 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
} else if len(spqp.Staffs) > 0 {
|
|
|
staffs = spqp.Staffs
|
|
|
}
|
|
|
+ //老板商机管理需要查询全部来源
|
|
|
+ isNew := true
|
|
|
+ //商机管理判断
|
|
|
+ newCount := IC.MainMysql.CountBySql("select count(id) from entniche_info where id =? and isNew != 1 and status=1", spqp.EntId)
|
|
|
+ if newCount > 0 {
|
|
|
+ isNew = false
|
|
|
+ }
|
|
|
// 无查询分配人员、是否已读
|
|
|
if spqp.IsRead == "" && len(staffs) == 0 {
|
|
|
//查询数量(需要去重)
|
|
|
- countSql = fmt.Sprintf("select count(1) from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr)
|
|
|
+ countSql = fmt.Sprintf("select count(1) from %s a where %s %s %s", aboutDbMsg[s.ModuleFlag].MysqlTable, strings.Join(querys, " and "), userStr, common.If(isNew, " and a.source = 2 ", ""))
|
|
|
//列表查询
|
|
|
- findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,b.isvalidfile as attachment_count, IF(a.source is NULL,1,a.source) as source from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where %s %s order by a.date desc,a.id desc",
|
|
|
- aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr)
|
|
|
+ findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,a.attachment_count from %s a where %s %s %s order by a.date desc,a.id desc",
|
|
|
+ aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, common.If(isNew, " and a.source = 2 ", ""))
|
|
|
} else {
|
|
|
//查询分配人员或是否已读
|
|
|
staffQuery := " 1=1 "
|
|
@@ -927,6 +919,7 @@ func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId st
|
|
|
if isEnt {
|
|
|
if s.ModuleFlag == EntnicheFlag {
|
|
|
IC.BaseServiceMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 ,visittime=now() where entid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), entId, id)
|
|
|
+
|
|
|
} else {
|
|
|
IC.BaseServiceMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 where entid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), entId, id)
|
|
|
|
|
@@ -1060,7 +1053,6 @@ func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam) (hasNextPage bool,
|
|
|
|
|
|
// 保存推送表
|
|
|
func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]interface{}, keyword []ViewKeyWord) (resultList []*bxsubscribe.SubscribeInfo) {
|
|
|
- t2 := time.Now()
|
|
|
now := time.Now().Unix()
|
|
|
length := len(list)
|
|
|
resultList = make([]*bxsubscribe.SubscribeInfo, length)
|
|
@@ -1077,19 +1069,45 @@ func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]i
|
|
|
infoid := common.InterfaceToStr(v["_id"])
|
|
|
matchkeys := getKeys(title, keyword)
|
|
|
matchkey := strings.Join(matchkeys, " ")
|
|
|
+ subscopeclassStr := ""
|
|
|
+ area := common.If(v["area"] == nil, nil, common.If(common.ObjToString(v["area"]) == "A", 0, common.If(P.PushMapping.Area[common.ObjToString(v["area"])] > 0, P.PushMapping.Area[common.ObjToString(v["area"])], 0)))
|
|
|
+ city := common.If(P.PushMapping.City[common.ObjToString(v["city"])] == 0, nil, P.PushMapping.City[common.ObjToString(v["city"])])
|
|
|
+ subtype := common.If(P.PushMapping.Subtype[common.ObjToString(v["subtype"])] == 0, nil, P.PushMapping.Subtype[common.ObjToString(v["subtype"])])
|
|
|
+ toptype := common.If(P.PushMapping.Toptype[common.ObjToString(v["toptype"])] == 0, nil, P.PushMapping.Toptype[common.ObjToString(v["toptype"])])
|
|
|
+ buyerclass := common.If(P.PushMapping.Buyerclass[common.ObjToString(v["buyerclass"])] == 0, nil, P.PushMapping.Buyerclass[common.ObjToString(v["buyerclass"])])
|
|
|
+ attachment_count := 0
|
|
|
+ if v["isValidFile"] != nil {
|
|
|
+ isValidFile, _ := v["isValidFile"].(bool)
|
|
|
+ attachment_count = common.If(isValidFile, 1, 0).(int)
|
|
|
+ }
|
|
|
+ bidamount := common.If(v["bidamount"] == nil, nil, v["bidamount"])
|
|
|
+ budget := common.If(v["budget"] == nil, nil, v["budget"])
|
|
|
+ if s_subscopeclass := common.ObjToString(v["s_subscopeclass"]); s_subscopeclass != "" {
|
|
|
+ subscopeclass := []string{}
|
|
|
+ for _, v := range strings.Split(s_subscopeclass, ",") {
|
|
|
+ if subscopeclass_mapping, ok := P.PushMapping.Subscopeclass[v]; ok {
|
|
|
+ subscopeclass = append(subscopeclass, fmt.Sprint(subscopeclass_mapping))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(subscopeclass) > 0 {
|
|
|
+ subscopeclassStr = strings.Join(subscopeclass, ",")
|
|
|
+ }
|
|
|
+ }
|
|
|
redisKey := fmt.Sprintf("pushinfo_%s_%s", spqp.UserId, common.ObjToString(v["_id"]))
|
|
|
entid := spqp.EntId
|
|
|
entUserId := spqp.EntUserId
|
|
|
deptid := spqp.DeptId
|
|
|
+ //公共字段处理
|
|
|
+ pushInsert = append(pushInsert, common.InterfaceToStr(infoid), matchkey, now, area, city, buyerclass, toptype, subtype, subscopeclassStr, budget, bidamount, attachment_count)
|
|
|
switch s.ModuleFlag {
|
|
|
case EntnicheFlag:
|
|
|
- pushInsert = append(pushInsert, entid, deptid, entUserId, common.InterfaceToStr(infoid), matchkey, now, 1, product)
|
|
|
+ pushInsert = append(pushInsert, entid, deptid, entUserId, 1, product)
|
|
|
case MemberFlag:
|
|
|
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now)
|
|
|
+ pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId))
|
|
|
case SubVipFlag:
|
|
|
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 1)
|
|
|
+ pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), 1)
|
|
|
case SubFreeFlag:
|
|
|
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 0)
|
|
|
+ pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), 0)
|
|
|
}
|
|
|
redis.Put("pushcache_2_a", redisKey, 1, 86400)
|
|
|
resultList[i] = s.InfoFormat(&PushCa{
|
|
@@ -1112,7 +1130,6 @@ func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]i
|
|
|
resultList[i].CaIndex = id
|
|
|
id++
|
|
|
}
|
|
|
- logx.Info("数据处理耗时:", time.Since(t2))
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1491,7 +1508,6 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
|
|
|
return MapToarr(keyData)
|
|
|
}
|
|
|
for _, ruleV := range *res_ {
|
|
|
-
|
|
|
o_entniche = common.StructToMapMore(ruleV["o_entniche"])
|
|
|
if o_entniche["a_items"] != nil {
|
|
|
a_item := common.ObjArrToMapArr(o_entniche["a_items"].([]interface{}))
|