소스 검색

wip:解决冲突

wangkaiyue 2 년 전
부모
커밋
ff01f824b8
2개의 변경된 파일63개의 추가작업 그리고 82개의 파일을 삭제
  1. 2 10
      jyBXSubscribe/rpc/internal/logic/getviewstatuslogic.go
  2. 61 72
      jyBXSubscribe/rpc/model/push.go

+ 2 - 10
jyBXSubscribe/rpc/internal/logic/getviewstatuslogic.go

@@ -43,11 +43,7 @@ func (l *GetViewStatusLogic) GetViewStatus(in *bxsubscribe.GetViewStatusReq) (*b
 	in.InfoId = util.DecodeId(in.InfoId)
 	log.Println("查看状态参数", in)
 	res := new(bxsubscribe.ViewStatusResp)
-<<<<<<< HEAD
-	finsql = `SELECT userid,isvisit,visittime,date FROM push.pushentniche where  infoid =? and source in (2,3) order By date asc`
-=======
-	finsql = `SELECT userid,isvisit,visittime,date,source FROM pushentniche where  infoid =?  order By date asc`
->>>>>>> master
+	finsql = `SELECT userid,isvisit,visittime,date,source FROM push.pushentniche where  infoid =?  order By date asc`
 	if user.Role_admin_department {
 		users = model.GetDisUsers(common.IntAll(in.EntId), user.Dept.Id)
 		if users != nil && len(*users) > 0 {
@@ -64,11 +60,7 @@ func (l *GetViewStatusLogic) GetViewStatus(in *bxsubscribe.GetViewStatusReq) (*b
 		users = model.GetEntUsers(common.IntAll(in.EntId))
 	}
 	if len(ss) > 0 {
-<<<<<<< HEAD
-		finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date FROM push.pushentniche where  infoid =? and source in (2,3) %s order By date asc`, fmt.Sprintf(`and userid in (%s)`, strings.Join(ss, ",")))
-=======
-		finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date,source FROM pushentniche where  infoid =?  %s order By date asc`, fmt.Sprintf(`and userid in (%s)`, strings.Join(ss, ",")))
->>>>>>> master
+		finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date,source FROM push.pushentniche where  infoid =?  %s order By date asc`, fmt.Sprintf(`and userid in (%s)`, strings.Join(ss, ",")))
 	}
 	data := IC.BaseServiceMysql.SelectBySql(finsql, in.InfoId)
 	userMap := make(map[int]*model.User)

+ 61 - 72
jyBXSubscribe/rpc/model/push.go

@@ -1,6 +1,7 @@
 package model
 
 import (
+	"context"
 	"encoding/json"
 	"fmt"
 	IC "jyBXSubscribe/rpc/init"
@@ -19,7 +20,7 @@ import (
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/redis"
-	P "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
+	"bp.jydev.jianyu360.cn/BaseService/jyCodeService/rpc/codeservice/codeservice"
 	"github.com/zeromicro/go-zero/core/logx"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
@@ -35,19 +36,21 @@ 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{"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"}
+	ennicheInsertCollKey   = []string{"entid", "deptid", "userid", "infoid", "matchkeys", "date", "source", "product"}
+	subscribeInsertCollKey = []string{"userid", "infoid", "matchkeys", "date", "isvip"}
+	memberInsertCollKey    = []string{"userid", "infoid", "matchkeys", "date"}
 )
 
 var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
-	SubFreeFlag:  &AboutDbMsg{"push.pushsubscribe", "subpush"},
-	SubVipFlag:   &AboutDbMsg{"push.pushsubscribe", "subpush"},
-	MemberFlag:   &AboutDbMsg{"push.pushmember", "memberpush"},
-	EntnicheFlag: &AboutDbMsg{"push.pushentniche", "entnichepush"},
+	SubFreeFlag:  &AboutDbMsg{"pushsubscribe", "subpush"},
+	SubVipFlag:   &AboutDbMsg{"pushsubscribe", "subpush"},
+	MemberFlag:   &AboutDbMsg{"pushmember", "memberpush"},
+	EntnicheFlag: &AboutDbMsg{"pushentniche", "entnichepush"},
 }
 
 type AboutDbMsg struct {
@@ -388,9 +391,15 @@ 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, "','")))
@@ -413,8 +422,8 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 			//城市
 			city := []string{}
 			for _, v := range strings.Split(spqp.City, ",") {
-				if P.PushMapping.City[v] > 0 {
-					city = append(city, fmt.Sprint(P.PushMapping.City[v]))
+				if codeMap.Data.City[v] != "" {
+					city = append(city, fmt.Sprint(codeMap.Data.City[v]))
 				} else {
 					city = append(city, "-1")
 				}
@@ -423,14 +432,14 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 				city = append(city, "9999")
 			}
 			if len(city) > 0 {
-				sqlAreaCity = fmt.Sprintf("city in (%s)", strings.Join(city, ","))
+				sqlAreaCity = fmt.Sprintf("b.city_code in (%s)", strings.Join(city, ","))
 			}
 			//区域
 			var sqlArea = ""
 			area := []string{}
 			for _, v := range strings.Split(spqp.Area, ",") {
-				if P.PushMapping.Area[v] > 0 {
-					area = append(area, fmt.Sprint(P.PushMapping.Area[v]))
+				if codeMap.Data.Area[v] != "" {
+					area = append(area, fmt.Sprint(codeMap.Data.Area[v]))
 				} else {
 					area = append(area, "-1")
 				}
@@ -439,7 +448,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 				area = append(area, "9999")
 			}
 			if len(area) > 0 {
-				sqlArea = fmt.Sprintf("a.area in (%s)", strings.Join(area, ","))
+				sqlArea = fmt.Sprintf("b.area_code in (%s)", strings.Join(area, ","))
 			}
 			if sqlAreaCity != "" && sqlArea != "" {
 				sqlAreaCity = "( " + sqlAreaCity + " or " + sqlArea + " )"
@@ -454,13 +463,15 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 		if spqp.Buyerclass != "" {
 			buyerclass := []string{}
 			for _, v := range strings.Split(spqp.Buyerclass, ",") {
-				buyerclass = append(buyerclass, fmt.Sprint(P.PushMapping.Buyerclass[v]))
+				if codeMap.Data.Buyerclass[v] != "" {
+					buyerclass = append(buyerclass, fmt.Sprint(codeMap.Data.Buyerclass[v]))
+				}
 			}
 			if len(buyerclass) == 1 {
 				buyerclass = append(buyerclass, "9999")
 			}
 			if len(buyerclass) > 0 {
-				querys = append(querys, fmt.Sprintf("a.buyerclass_code in (%s)", strings.Join(buyerclass, ",")))
+				querys = append(querys, fmt.Sprintf("b.buyerclass_code in (%s)", strings.Join(buyerclass, ",")))
 			}
 
 		}
@@ -468,25 +479,28 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 		if spqp.Subtype != "" {
 			subtype := []string{}
 			for _, v := range strings.Split(spqp.Subtype, ",") {
-				subtype = append(subtype, fmt.Sprintf("find_in_set('%d',a.subscopeclass)", P.PushMapping.Subscopeclass[v]))
+				if codeMap.Data.Subtype[v] != "" {
+					subtype = append(subtype, fmt.Sprint(codeMap.Data.Subtype[v]))
+				}
 			}
 			if len(subtype) == 1 {
 				subtype = append(subtype, "9999")
 			}
 			if len(subtype) > 0 {
-				querys = append(querys, fmt.Sprintf("a.subtype_code in (%s)", strings.Join(subtype, ",")))
+				querys = append(querys, fmt.Sprintf("b.subtype_code in (%s)", strings.Join(subtype, ",")))
 			}
 		}
 		//信息行业
 		if spqp.Subscopeclass != "" {
 			find_in_set := []string{}
 			for _, v := range strings.Split(spqp.Subscopeclass, ",") {
-				find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%d',a.subscopeclass)", P.PushMapping.Subscopeclass[v]))
+				if codeMap.Data.Subscopeclass[v] != "" {
+					find_in_set = append(find_in_set, codeMap.Data.Subscopeclass[v])
+				}
 			}
-			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 ")))
+			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, ",")))
 			}
 		}
 		//关键词
@@ -507,19 +521,19 @@ 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("((a.bidamount>=%d and a.bidamount<=%d) or (a.budget>=%d and a.budget<=%d and a.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
+				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))
 			} else if minPriceStr != "" {
-				querys = append(querys, fmt.Sprintf("(a.bidamount>=%d  or (a.budget>=%d and a.bidamount is null))", minPrice, minPrice))
+				querys = append(querys, fmt.Sprintf("(b.bidamount>=%d  or (b.budget>=%d and b.bidamount is null))", minPrice, minPrice))
 			} else if maxPriceStr != "" {
-				querys = append(querys, fmt.Sprintf("(a.bidamount<=%d or (a.budget<=%d and a.bidamount is null))", maxPrice, maxPrice))
+				querys = append(querys, fmt.Sprintf("(b.bidamount<=%d or (b.budget<=%d and b.bidamount is null))", maxPrice, maxPrice))
 			}
 		}
 		//附件
 		if spqp.FileExists != "" {
 			if spqp.FileExists == "1" {
-				querys = append(querys, fmt.Sprintf("a.attachment_count is not null"))
+				querys = append(querys, fmt.Sprintf("b.isvalidfile =1 "))
 			} else if spqp.FileExists == "-1" {
-				querys = append(querys, fmt.Sprintf("a.attachment_count is null"))
+				querys = append(querys, fmt.Sprintf("b.isvalidfile =0 "))
 			}
 		}
 		// 是否已读
@@ -568,17 +582,10 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 			// 无查询分配人员、是否已读
 			if spqp.IsRead == "" && len(staffs) == 0 {
 				//查询数量(需要去重)
-<<<<<<< HEAD
-				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,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 ", ""))
-=======
 				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)
 				//列表查询
 				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)
->>>>>>> master
 			} else {
 				//查询分配人员或是否已读
 				staffQuery := " 1=1 "
@@ -592,17 +599,23 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 						staffQuery += " and a.isvisit=1"
 					}
 				}
-<<<<<<< HEAD
 				countSql = fmt.Sprintf("select count(1) from %s a s where %s %s %s and ((%s) or EXISTS (SELECT 1 from %s c  WHERE c.source=3 %s and %s and a.id=c.pid and (%s))) ", aboutDbMsg[s.ModuleFlag].MysqlTable, strings.Join(querys, " and "), userStr, common.If(isNew, " and a.source = 2 ", ""), staffQuery, aboutDbMsg[s.ModuleFlag].MysqlTable, strings.ReplaceAll(userStr, "a.", "c."), strings.Join(querys, " and "), strings.ReplaceAll(staffQuery, "a.", "c."))
 				//列表查询
 				findSql = fmt.Sprintf("select a.id,a.infoid,a.matchkeys,a.attachment_count from %s a where %s %s %s and ((%s) or EXISTS (SELECT 1 from %s c  WHERE c.source=3 %s and %s and a.id=c.pid and (%s))) order by a.date desc,a.id desc ", aboutDbMsg[s.ModuleFlag].MysqlTable, strings.Join(querys, " and "), userStr, common.If(isNew, " and a.source = 2 ", ""), staffQuery, aboutDbMsg[s.ModuleFlag].MysqlTable, strings.ReplaceAll(userStr, "a.", "c."), strings.Join(querys, " and "), strings.ReplaceAll(staffQuery, "a.", "c."))
-=======
-				countSql = fmt.Sprintf("select count(1) from %s a STRAIGHT_JOIN %s b ON  a.infoid = b.infoid  %s where %s %s and %s ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr, staffQuery)
-				//列表查询
-				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 and %s order by a.date desc,a.id desc ", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, strings.Join(querys, " and "), userStr, staffQuery)
->>>>>>> master
 			}
 		} else {
+			// 是否已读
+			if spqp.IsRead != "" {
+				if spqp.IsRead == "0" {
+					userStr += " and a.isvisit IS NULL"
+				} else if spqp.IsRead == "1" {
+					userStr += " and a.isvisit=1"
+				}
+			}
+			// 信息来源
+			if spqp.Source == "1" || spqp.Source == "2" || spqp.Source == "3" {
+				userStr += " and a.source=" + spqp.Source
+			}
 			if spqp.PositionType == 1 {
 				//企业主体是企业的个人查询
 				if spqp.UserType == SubVipFlag {
@@ -914,7 +927,6 @@ 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)
 
@@ -1048,6 +1060,7 @@ 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)
@@ -1064,45 +1077,19 @@ 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, 1, product)
+			pushInsert = append(pushInsert, entid, deptid, entUserId, common.InterfaceToStr(infoid), matchkey, now, 1, product)
 		case MemberFlag:
-			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId))
+			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now)
 		case SubVipFlag:
-			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), 1)
+			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 1)
 		case SubFreeFlag:
-			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), 0)
+			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 0)
 		}
 		redis.Put("pushcache_2_a", redisKey, 1, 86400)
 		resultList[i] = s.InfoFormat(&PushCa{
@@ -1125,6 +1112,7 @@ func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]i
 		resultList[i].CaIndex = id
 		id++
 	}
+	logx.Info("数据处理耗时:", time.Since(t2))
 	return
 }
 
@@ -1503,6 +1491,7 @@ 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{}))