|
@@ -1,19 +1,9 @@
|
|
|
package model
|
|
|
|
|
|
import (
|
|
|
- "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/date"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- "app.yhyue.com/moapp/jybase/esv1"
|
|
|
- "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"
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
- "github.com/zeromicro/go-zero/core/logx"
|
|
|
- "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
IC "jyBXSubscribe/rpc/init"
|
|
|
ms "jyBXSubscribe/rpc/model/service"
|
|
|
"jyBXSubscribe/rpc/type/bxsubscribe"
|
|
@@ -22,6 +12,17 @@ import (
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
+
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/esv1"
|
|
|
+ "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"
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -344,16 +345,11 @@ 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) {
|
|
|
- start := time.Now().Unix()
|
|
|
querys := []string{}
|
|
|
userStr := " "
|
|
|
leftJoinStr := " "
|
|
|
var (
|
|
|
-<<<<<<< HEAD
|
|
|
- searchSql, findSql string
|
|
|
-=======
|
|
|
countSql, findSql string
|
|
|
->>>>>>> master
|
|
|
)
|
|
|
codeMap, err := IC.CodeLib.CodeTransformation(context.Background(), &codeservice.Request{})
|
|
|
if codeMap.Data == nil || err != nil {
|
|
@@ -361,56 +357,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
return result, count
|
|
|
}
|
|
|
querys = append(querys, " 1=1 ")
|
|
|
- start2 := int64(0)
|
|
|
if spqp.SelectInfoIds != nil && len(spqp.SelectInfoIds) > 0 {
|
|
|
-<<<<<<< HEAD
|
|
|
- searchSql = fmt.Sprintf(" from %s a LEFT JOIN %s b ON a.infoid = b.infoid where %s order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
|
|
|
- logx.Info("searchSql", searchSql)
|
|
|
- //查询总数
|
|
|
- count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count(a.id)" + searchSql))
|
|
|
- findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
|
|
|
- } else {
|
|
|
- if spqp.IsEnt {
|
|
|
-
|
|
|
- isNew := 0
|
|
|
- if spqp.UserType == EntnicheFlag {
|
|
|
- //商机管理判断
|
|
|
- newCount := IC.MainMysql.CountBySql("select count(id) from entniche_info where id =? and isNew=1 and status=1", spqp.EntId)
|
|
|
- if newCount > 0 {
|
|
|
- //新商机管理
|
|
|
- isNew = 1
|
|
|
- }
|
|
|
- }
|
|
|
- if spqp.BuySubject == 1 || isNew == 1 {
|
|
|
- //企业主体是企业的企业查询
|
|
|
- userStr = fmt.Sprintf(" a.entid='%s' and (a.source > 1) ", spqp.EntId)
|
|
|
- } else {
|
|
|
- userStr = fmt.Sprintf(" a.entid='%s' ", spqp.EntId)
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- if spqp.BuySubject == 1 {
|
|
|
- //企业主体是企业的个人查询
|
|
|
- if spqp.UserType == SubVipFlag {
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s' and ( a.product=1 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- } else if spqp.UserType == MemberFlag {
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s' and ( a.product=2 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- } else {
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s' and ( a.product is null or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- }
|
|
|
- } else {
|
|
|
- if s.ModuleFlag == EntnicheFlag {
|
|
|
- //老商机管理个人订阅查询
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s' and a.product is null", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- } else {
|
|
|
- //个人订阅查询
|
|
|
- userStr = fmt.Sprintf(" a.userid='%s'", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-=======
|
|
|
countSql = fmt.Sprintf("select count(1) as count from %s a LEFT JOIN %s b ON a.infoid = b.infoid where %s", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
|
|
|
logx.Info("countSql", countSql)
|
|
|
findSql = fmt.Sprintf("select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count from %s a LEFT JOIN %s b ON a.infoid = b.infoid where %s order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
|
|
@@ -418,10 +365,9 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
count = spqp.BaseServiceMysql.CountBySql(countSql)
|
|
|
} else {
|
|
|
//公共查询条件
|
|
|
->>>>>>> master
|
|
|
//时间
|
|
|
if starttime > 0 && endtime > 0 {
|
|
|
- userStr += fmt.Sprintf(" and a.date>=%d and date<=%d", starttime, endtime)
|
|
|
+ userStr += fmt.Sprintf(" and a.date>=%d and a.date<=%d", starttime, endtime)
|
|
|
} else if starttime > 0 && endtime == 0 {
|
|
|
userStr += fmt.Sprintf(" and a.date>=%d", starttime)
|
|
|
} else if starttime == 0 && endtime > 0 {
|
|
@@ -550,24 +496,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
querys = append(querys, fmt.Sprintf("b.isvalidfile =0 "))
|
|
|
}
|
|
|
}
|
|
|
-<<<<<<< HEAD
|
|
|
- searchSql = fmt.Sprintf(" from %s a STRAIGHT_JOIN %s b ON %s and a.infoid = b.infoid %s where %s"+
|
|
|
- " order by a.date desc,a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, userStr, leftJoinStr, strings.Join(querys, " and "))
|
|
|
- logx.Info("searchSql", searchSql)
|
|
|
- //查询总数
|
|
|
- logx.Info(fmt.Sprintf("select count(DISTINCT a.id) " + searchSql))
|
|
|
- count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count( DISTINCT a.id) " + searchSql))
|
|
|
- start2 = time.Now().Unix()
|
|
|
- logx.Info("count:", count, "---", s.ModuleFlag)
|
|
|
- logx.Info("查询数据总数用时", start2-start)
|
|
|
- findSql = "select DISTINCT a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
|
|
|
- if s.ModuleFlag == EntnicheFlag {
|
|
|
- findSql += ", IF(a.source is NULL,1,a.source) as source "
|
|
|
- }
|
|
|
- }
|
|
|
- if s.ModuleFlag != MemberFlag && s.ModuleFlag != EntnicheFlag {
|
|
|
- findSql += ",a.isvip"
|
|
|
-=======
|
|
|
|
|
|
if spqp.IsEnt {
|
|
|
var staffs []string
|
|
@@ -687,20 +615,14 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
//查询总数
|
|
|
logx.Info("countSql", countSql)
|
|
|
count = spqp.BaseServiceMysql.CountBySql(countSql)
|
|
|
->>>>>>> master
|
|
|
}
|
|
|
if isLimit {
|
|
|
findSql += fmt.Sprintf(" limit %d,%d", (spqp.PageNum-1)*size, size)
|
|
|
}
|
|
|
-
|
|
|
logx.Info(spqp.NewUserId, "subscribePush query sql:", findSql)
|
|
|
list := spqp.BaseServiceMysql.SelectBySql(findSql)
|
|
|
- start3 := time.Now().Unix()
|
|
|
- logx.Info("查询数据用时", start3-start2)
|
|
|
if list != nil && len(*list) > 0 {
|
|
|
pushCas := s.GetJyPushs(*list)
|
|
|
- start4 := time.Now().Unix()
|
|
|
- logx.Info("清洗数据耗时", start4-start3)
|
|
|
if !spqp.Export {
|
|
|
result = s.GetInfoByIds(spqp.Mgo_bidding, spqp.Bidding, spqp.Bidding_back, pushCas)
|
|
|
} else {
|
|
@@ -1521,29 +1443,15 @@ func (s *subscribePush) IsInTsGuide(userid string) bool {
|
|
|
func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
|
|
|
keyData := map[string][]interface{}{}
|
|
|
if !spqp.IsEnt {
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": spqp.EntUserId,
|
|
|
- "i_entid": spqp.EntId,
|
|
|
- }
|
|
|
//个人关键词查找
|
|
|
//fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户
|
|
|
mData, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
|
|
|
if s.ModuleFlag == SubVipFlag {
|
|
|
- o_vipjy := &map[string]interface{}{}
|
|
|
- if spqp.VipPower == 1 {
|
|
|
- query["i_type"] = 1
|
|
|
- mData, ok := IC.Mgo.FindOne("entniche_rule", query)
|
|
|
- if mData == nil || len(*mData) == 0 || !ok {
|
|
|
- return nil
|
|
|
- }
|
|
|
- o_vipjy = common.ObjToMap((*mData)["o_entniche"])
|
|
|
- } else {
|
|
|
- //从user表中取 o_vipjy.a_items
|
|
|
- if mData == nil || len(*mData) == 0 || !ok {
|
|
|
- return nil
|
|
|
- }
|
|
|
- o_vipjy = common.ObjToMap((*mData)["o_vipjy"])
|
|
|
+ //从user表中取 o_vipjy.a_items
|
|
|
+ if mData == nil || len(*mData) == 0 || !ok {
|
|
|
+ return nil
|
|
|
}
|
|
|
+ o_vipjy := common.ObjToMap((*mData)["o_vipjy"])
|
|
|
if (*o_vipjy)["a_items"] != nil {
|
|
|
a_items := common.ObjArrToMapArr((*o_vipjy)["a_items"].([]interface{}))
|
|
|
for _, v := range a_items {
|
|
@@ -1553,32 +1461,20 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
} else if s.ModuleFlag == MemberFlag {
|
|
|
- o_memeberjy := &map[string]interface{}{}
|
|
|
- if spqp.MemberPower == 1 {
|
|
|
- query["i_type"] = 1
|
|
|
- mData, ok := IC.Mgo.FindOne("entniche_rule", query)
|
|
|
- if mData == nil || len(*mData) == 0 || !ok {
|
|
|
- return nil
|
|
|
- }
|
|
|
- o_memeberjy = common.ObjToMap((*mData)["o_entniche"])
|
|
|
- } else {
|
|
|
- //从user表中取 o_member_jy.a_items
|
|
|
+ //从user表中取 o_member_jy.a_items
|
|
|
+ if mData == nil || len(*mData) == 0 || !ok {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ sub_status := common.Int64All((*mData)["i_member_sub_status"])
|
|
|
+ if sub_status == 1 {
|
|
|
+ //大会员子账号处理
|
|
|
+ mData, ok = IC.Mgo.FindById("user", common.InterfaceToStr((*mData)["s_member_mainid"]), `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
|
|
|
if mData == nil || len(*mData) == 0 || !ok {
|
|
|
return nil
|
|
|
}
|
|
|
- sub_status := common.Int64All((*mData)["i_member_sub_status"])
|
|
|
- if sub_status == 1 {
|
|
|
- //大会员子账号处理
|
|
|
- mData, ok = IC.Mgo.FindById("user", common.InterfaceToStr((*mData)["s_member_mainid"]), `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
|
|
|
- if mData == nil || len(*mData) == 0 || !ok {
|
|
|
- return nil
|
|
|
- }
|
|
|
- }
|
|
|
- o_memeberjy = common.ObjToMap((*mData)["o_member_jy"])
|
|
|
}
|
|
|
-
|
|
|
+ o_memeberjy := common.ObjToMap((*mData)["o_member_jy"])
|
|
|
if (*o_memeberjy)["a_items"] != nil {
|
|
|
a_items := common.ObjArrToMapArr((*o_memeberjy)["a_items"].([]interface{}))
|
|
|
for _, v := range a_items {
|
|
@@ -1843,148 +1739,3 @@ func MergeArray(dest []interface{}, src []interface{}) (result []interface{}) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func (s *subscribePush) GetSubScribeInfo(in *bxsubscribe.UserReq) *map[string]interface{} {
|
|
|
- data := &map[string]interface{}{}
|
|
|
- if in.PositionType == 0 {
|
|
|
- ok := false
|
|
|
- query := map[string]interface{}{
|
|
|
- "_id": mongodb.StringTOBsonId(in.UserId),
|
|
|
- }
|
|
|
- data, ok = IC.Mgo.FindOneByField("user", query, `{"i_vip_status":1,"l_vip_starttime":1,"l_vip_endtime":1,"i_member_status":1,"i_member_starttime":1,"i_member_endtime":1,"o_jy":1,"o_vipjy":1,"o_member_jy":1,"s_phone":1,"s_m_phone":1,"s_nickname":1,"s_jyname":1,"s_headimageurl":1,"s_headimage":1}`)
|
|
|
- if !ok || data == nil || len(*data) <= 0 {
|
|
|
- return nil
|
|
|
- }
|
|
|
- }
|
|
|
- object := &map[string]interface{}{}
|
|
|
- jyData := &map[string]interface{}{}
|
|
|
- switch in.Types {
|
|
|
- case MemberFlag:
|
|
|
- //大会员
|
|
|
- if in.PositionType == 0 {
|
|
|
- //个人
|
|
|
- if (*data)["o_member_jy"] != nil {
|
|
|
- jyData = common.ObjToMap((*data)["o_member_jy"])
|
|
|
- }
|
|
|
- } else {
|
|
|
- jyData = EntnicheSub(in.EntUserId, in.EntId, 1)
|
|
|
- }
|
|
|
-
|
|
|
- case EntnicheFlag:
|
|
|
- //商机管理
|
|
|
- jyData = EntnicheSub(in.EntUserId, in.EntId, 0)
|
|
|
- log.Println("~~~", jyData)
|
|
|
-
|
|
|
- case SubVipFlag:
|
|
|
- //超级订阅
|
|
|
- if in.PositionType == 0 {
|
|
|
- if (*data)["o_vipjy"] != nil {
|
|
|
- //个人
|
|
|
- jyData = common.ObjToMap((*data)["o_vipjy"])
|
|
|
- }
|
|
|
- } else {
|
|
|
- jyData = EntnicheSub(in.EntUserId, in.EntId, 1)
|
|
|
- }
|
|
|
-
|
|
|
- case SubFreeFlag:
|
|
|
- if in.PositionType == 0 {
|
|
|
- //个人
|
|
|
- if (*data)["o_jy"] != nil {
|
|
|
- ojy := common.ObjToMap((*data)["o_jy"])
|
|
|
- if (*ojy)["a_key"] != nil {
|
|
|
- akey := common.ObjArrToMapArr((*ojy)["a_key"].([]interface{}))
|
|
|
- (*object)["a_items"] = []map[string]interface{}{ //转换至和其它结构一致
|
|
|
- map[string]interface{}{
|
|
|
- "a_key": akey,
|
|
|
- },
|
|
|
- }
|
|
|
- }
|
|
|
- if (*ojy)["o_area"] == nil {
|
|
|
- (*object)["o_area"] = map[string]interface{}{}
|
|
|
- } else {
|
|
|
- (*object)["o_area"] = (*ojy)["o_area"]
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- jyData = EntnicheSub(in.EntUserId, in.EntId, 2)
|
|
|
- }
|
|
|
- }
|
|
|
- if jyData != nil {
|
|
|
- object = format(jyData)
|
|
|
- }
|
|
|
- return object
|
|
|
-}
|
|
|
-
|
|
|
-//商机管理订阅设置
|
|
|
-func EntnicheSub(entUserId, entId int64, types int64) *map[string]interface{} {
|
|
|
- object := &map[string]interface{}{}
|
|
|
- entnicheJy := &map[string]interface{}{}
|
|
|
- res, _ := IC.Mgo.FindOne("entniche_rule", map[string]interface{}{
|
|
|
- "i_userid": entUserId,
|
|
|
- "i_entid": entId,
|
|
|
- "types": types,
|
|
|
- })
|
|
|
- if types == 2 {
|
|
|
- if (*res)["o_entniche"] != nil {
|
|
|
- ojy := common.ObjToMap((*res)["o_jy"])
|
|
|
- if (*ojy)["a_key"] != nil {
|
|
|
- akey := common.ObjArrToMapArr((*ojy)["a_key"].([]interface{}))
|
|
|
- (*object)["a_items"] = []map[string]interface{}{ //转换至和其它结构一致
|
|
|
- map[string]interface{}{
|
|
|
- "a_key": akey,
|
|
|
- },
|
|
|
- }
|
|
|
- }
|
|
|
- if (*ojy)["o_area"] == nil {
|
|
|
- (*object)["o_area"] = map[string]interface{}{}
|
|
|
- } else {
|
|
|
- (*object)["o_area"] = (*ojy)["o_area"]
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- entnicheJy = common.ObjToMap((*res)["o_entniche"])
|
|
|
- }
|
|
|
- //获取商机管理的订阅设置
|
|
|
- return entnicheJy
|
|
|
-}
|
|
|
-
|
|
|
-//格式化数据 大会员/超级订阅/商机管理 结构一致 关键词格式化
|
|
|
-func format(data *map[string]interface{}) *map[string]interface{} {
|
|
|
- if data == nil {
|
|
|
- return nil
|
|
|
- }
|
|
|
- //关键词
|
|
|
- if (*data)["a_items"] != nil {
|
|
|
- a_items := common.ObjArrToMapArr((*data)["a_items"].([]interface{}))
|
|
|
- for k, v := range a_items {
|
|
|
- if v["a_key"] != nil {
|
|
|
- a_keys := []map[string]interface{}{}
|
|
|
- ak, ok := v["a_key"].([]interface{})
|
|
|
- if !ok {
|
|
|
- a_keys, _ = v["a_key"].([]map[string]interface{})
|
|
|
- } else {
|
|
|
- a_keys = common.ObjArrToMapArr(ak)
|
|
|
-
|
|
|
- }
|
|
|
- for kk, vv := range a_keys {
|
|
|
- if vv["key"] != nil {
|
|
|
- keyArr, ok1 := vv["key"].([]interface{})
|
|
|
- if ok1 {
|
|
|
- if vv["appendkey"] != nil {
|
|
|
- appendkeyArr, ok2 := vv["appendkey"].([]interface{})
|
|
|
- if ok2 {
|
|
|
- key := common.ObjArrToStringArr(keyArr)
|
|
|
- appendkey := common.ObjArrToStringArr(appendkeyArr)
|
|
|
- a_keys[kk]["key"] = append(key, appendkey...)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- delete(a_keys[kk], "appendkey")
|
|
|
- }
|
|
|
- a_items[k]["a_key"] = a_keys
|
|
|
- }
|
|
|
- }
|
|
|
- (*data)["a_items"] = a_items
|
|
|
- }
|
|
|
- return data
|
|
|
-}
|