Browse Source

Merge branch 'feature/v1.1.17_wh' of BaseService/jyMicroservices into feature/v1.1.17

王浩 2 years ago
parent
commit
1bb93386e3

+ 1 - 1
jyBXSubscribe/go.mod

@@ -3,7 +3,7 @@ module jyBXSubscribe
 go 1.18
 
 require (
-	app.yhyue.com/moapp/jybase v0.0.0-20230417095507-cf35f190347e
+	app.yhyue.com/moapp/jybase v0.0.0-20230427031503-e78871a3f7d8
 	app.yhyue.com/moapp/jypkg v0.0.0-20230218064127-1de4f4f3e6a3
 	bp.jydev.jianyu360.cn/BaseService/gateway v1.3.4
 	bp.jydev.jianyu360.cn/BaseService/jyCodeService v0.0.0-20220927093612-72958b15cdf0

+ 2 - 2
jyBXSubscribe/go.sum

@@ -10,8 +10,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20220617085837-48c1bf245c2f/go.mod h1:qNRA0sHu
 app.yhyue.com/moapp/jybase v0.0.0-20220719064915-2fef79005dfa/go.mod h1:FjBF25AYoBrPhVKTXGXWcmEAbBT0ATTK6KJMOA+I80Q=
 app.yhyue.com/moapp/jybase v0.0.0-20220802080941-07f401baab8b/go.mod h1:HelrO6tcD9TcKb/HOP2BLbzppyDz2kpQSFhPMQTUgbQ=
 app.yhyue.com/moapp/jybase v0.0.0-20230109015757-aa3d5e19b196/go.mod h1:zB47XTeJvpcbtBRYgkQuxOICWNexiZfbUO+7aUf6mNs=
-app.yhyue.com/moapp/jybase v0.0.0-20230417095507-cf35f190347e h1:BZEMetT36NokzQwEDRGHbQ5c/2A3cRQ12Z+rw0I5xhQ=
-app.yhyue.com/moapp/jybase v0.0.0-20230417095507-cf35f190347e/go.mod h1:zB47XTeJvpcbtBRYgkQuxOICWNexiZfbUO+7aUf6mNs=
+app.yhyue.com/moapp/jybase v0.0.0-20230427031503-e78871a3f7d8 h1:mLI8P4TnohyRYLGrWu0I0td6pymEeepR4hduQePmGrE=
+app.yhyue.com/moapp/jybase v0.0.0-20230427031503-e78871a3f7d8/go.mod h1:zB47XTeJvpcbtBRYgkQuxOICWNexiZfbUO+7aUf6mNs=
 app.yhyue.com/moapp/jypkg v0.0.0-20230218064127-1de4f4f3e6a3 h1:7vKwqvf/7dvKO0Q5B9Yj6yaDf8EDL3jJrbFqJ/vsIEk=
 app.yhyue.com/moapp/jypkg v0.0.0-20230218064127-1de4f4f3e6a3/go.mod h1:s5dthI0jGiOB+eHG8GAV15jlsu2YX1XA2gsLxw2m1sA=
 bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=

+ 1 - 1
jyBXSubscribe/rpc/etc/db.yaml

@@ -1,7 +1,7 @@
 mysql:
     main:
         dbName: jianyu
-        address: 192.168.3.242:3306
+        address: 192.168.3.149:3306
         userName: root
         password: Topnet123
         maxOpenConns: 5

+ 178 - 160
jyBXSubscribe/rpc/model/push.go

@@ -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,89 +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 "))
-			}
-		}
-		// 是否已读
-		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.IsEnt {
-			var staffs []string
-			userStr += fmt.Sprintf(" and  a.entid='%s' ", spqp.EntId)
-			//判断是企业管理员还是部门管理员 部门管理员获取所有子部门
-			userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
-			if !(userEnt.Role_admin_system || userEnt.Role_admin_department) {
-				result = []*bxsubscribe.SubscribeInfo{}
-				return
-			}
-			if userEnt.Role_admin_department { //部门管理员 获取所有部门和子部门员工
-				users := GetDisUsers(common.IntAll(spqp.EntId), userEnt.Dept.Id)
-				if users != nil && len(*users) > 0 {
-					for _, v := range *users {
-						if len(spqp.Staffs) > 0 {
-							for _, vv := range spqp.Staffs {
-								if fmt.Sprintf("%d", v.Id) == vv {
-									staffs = append(staffs, common.InterfaceToStr(v.Id))
-								}
-							}
-						} else {
-							staffs = append(staffs, common.InterfaceToStr(v.Id))
-						}
-					}
-				} else {
-					log.Printf("部门管理员为获取到部门员工:%s", spqp.EntUserId)
-					result = []*bxsubscribe.SubscribeInfo{}
-					return
-				}
-			} else if len(spqp.Staffs) > 0 {
-				staffs = spqp.Staffs
-			}
-			// 无查询分配人员、是否已读
-			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)
-				//列表查询
-				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)
-			} else {
-				//查询分配人员或是否已读
-				staffQuery := " 1=1 "
-				if len(staffs) > 0 {
-					staffQuery += fmt.Sprintf(" and  a.userid in ('%s')  ", strings.Join(staffs, "','"))
-				}
-				if spqp.IsRead != "" {
-					if spqp.IsRead == "0" {
-						staffQuery += " and a.isvisit IS NULL"
-					} else if spqp.IsRead == "1" {
-						staffQuery += " and a.isvisit=1"
-					}
-				}
-				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."))
+				querys = append(querys, fmt.Sprintf("a.attachment_count is null"))
 			}
-		} else {
 			// 是否已读
 			if spqp.IsRead != "" {
 				if spqp.IsRead == "0" {
@@ -616,57 +533,134 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 			if spqp.Source == "1" || spqp.Source == "2" || spqp.Source == "3" {
 				userStr += " and a.source=" + spqp.Source
 			}
-			if spqp.PositionType == 1 {
-				//企业主体是企业的个人查询
-				if spqp.UserType == SubVipFlag {
-					userStr += fmt.Sprintf(" and  a.userid='%s' and (  a.product=1 or a.product=3 or a.source>1     ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
-				} else if spqp.UserType == MemberFlag {
-					userStr += fmt.Sprintf(" and  a.userid='%s' and (  a.product=2 or a.product=3  or a.source>1  ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
-				} else if spqp.UserType == EntnicheFlag {
-					userStr += fmt.Sprintf(" and  a.userid='%s' and (  a.product is null or a.product=3  or a.source>1  ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+			if spqp.IsEnt {
+				var staffs []string
+				userStr += fmt.Sprintf(" and  a.entid='%s' ", spqp.EntId)
+				//判断是企业管理员还是部门管理员 部门管理员获取所有子部门
+				userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
+				if !(userEnt.Role_admin_system || userEnt.Role_admin_department) {
+					result = []*bxsubscribe.SubscribeInfo{}
+					return
+				}
+				if userEnt.Role_admin_department { //部门管理员 获取所有部门和子部门员工
+					users := GetDisUsers(common.IntAll(spqp.EntId), userEnt.Dept.Id)
+					if users != nil && len(*users) > 0 {
+						for _, v := range *users {
+							if len(spqp.Staffs) > 0 {
+								for _, vv := range spqp.Staffs {
+									if fmt.Sprintf("%d", v.Id) == vv {
+										staffs = append(staffs, common.InterfaceToStr(v.Id))
+									}
+								}
+							} else {
+								staffs = append(staffs, common.InterfaceToStr(v.Id))
+							}
+						}
+					} else {
+						log.Printf("部门管理员为获取到部门员工:%s", spqp.EntUserId)
+						result = []*bxsubscribe.SubscribeInfo{}
+						return
+					}
+				} 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    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 ", ""))
 				} else {
-					userStr += fmt.Sprintf(" and  a.userid='%s' ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+					//查询分配人员或是否已读
+					staffQuery := " 1=1 "
+					if len(staffs) > 0 {
+						staffQuery += fmt.Sprintf(" and  a.userid in ('%s')  ", strings.Join(staffs, "','"))
+					}
+					if spqp.IsRead != "" {
+						if spqp.IsRead == "0" {
+							staffQuery += " and a.isvisit IS NULL"
+						} else if spqp.IsRead == "1" {
+							staffQuery += " and a.isvisit=1"
+						}
+					}
+					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."))
 				}
 			} else {
-				if s.ModuleFlag == EntnicheFlag {
-					//老商机管理个人订阅查询
-					userStr += fmt.Sprintf(" and  a.userid='%s'  and a.product is null", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+				// 是否已读
+				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 {
+						userStr += fmt.Sprintf(" and  a.userid='%s' and (  a.product=1 or a.product=3 or a.source>1     ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+					} else if spqp.UserType == MemberFlag {
+						userStr += fmt.Sprintf(" and  a.userid='%s' and (  a.product=2 or a.product=3  or a.source>1  ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+					} else if spqp.UserType == EntnicheFlag {
+						userStr += fmt.Sprintf(" and  a.userid='%s' and (  a.product is null or a.product=3  or a.source>1  ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+					} else {
+						userStr += fmt.Sprintf(" and  a.userid='%s' ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+					}
 				} else {
-					//个人订阅查询
-					userStr += fmt.Sprintf(" and  a.userid='%s'", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+					if s.ModuleFlag == EntnicheFlag {
+						//老商机管理个人订阅查询
+						userStr += fmt.Sprintf(" and  a.userid='%s'  and a.product is null", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+					} else {
+						//个人订阅查询
+						userStr += fmt.Sprintf(" and  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  where 1=1 %s and %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, strings.Join(querys, " and "))
+				//列表查询语句
+				findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,a.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"
+				}
+				findSql = fmt.Sprintf("%s from %s  a  where  %s %s "+
+					" order by a.date desc,a.id desc", findSql, aboutDbMsg[s.ModuleFlag].MysqlTable, strings.Join(querys, " and "), userStr)
 			}
-			//查询数量
-			countSql = fmt.Sprintf("select count(1) as count from %s  a  where 1=1 %s and %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr, strings.Join(querys, " and "))
-			//列表查询语句
-			findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,a.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"
-			}
-			findSql = fmt.Sprintf("%s from %s  a  where  %s %s "+
-				" order by a.date desc,a.id desc", findSql, aboutDbMsg[s.ModuleFlag].MysqlTable, strings.Join(querys, " and "), userStr)
+			//查询总数
+			logx.Info("countSql", countSql)
+			count = spqp.BaseServiceMysql.CountBySql(countSql)
 		}
-		//查询总数
-		logx.Info("countSql", countSql)
-		count = spqp.BaseServiceMysql.CountBySql(countSql)
-	}
-	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)
-	if list != nil && len(*list) > 0 {
-		pushCas := s.GetJyPushs(*list)
-		if !spqp.Export {
-			result = s.GetInfoByIds(spqp.Mgo_bidding, spqp.Bidding, spqp.Bidding_back, pushCas, spqp.IsPayUser)
+		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)
+		if list != nil && len(*list) > 0 {
+			pushCas := s.GetJyPushs(*list)
+			if !spqp.Export {
+				result = s.GetInfoByIds(spqp.Mgo_bidding, spqp.Bidding, spqp.Bidding_back, pushCas, spqp.IsPayUser)
+			} else {
+				result = s.GetOnlyExportInfo(pushCas)
+			}
 		} else {
-			result = s.GetOnlyExportInfo(pushCas)
+			result = []*bxsubscribe.SubscribeInfo{}
 		}
-	} else {
-		result = []*bxsubscribe.SubscribeInfo{}
+		return
 	}
 	return
 }
@@ -927,6 +921,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 +1055,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 +1071,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 +1132,6 @@ func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]i
 		resultList[i].CaIndex = id
 		id++
 	}
-	logx.Info("数据处理耗时:", time.Since(t2))
 	return
 }
 
@@ -1491,7 +1510,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{}))

+ 9 - 35
jyBXSubscribe/rpc/model/service/matchjob.go

@@ -2,15 +2,12 @@ package service
 
 import (
 	util "app.yhyue.com/moapp/jybase/common"
-	. "app.yhyue.com/moapp/jybase/mongodb"
-	"app.yhyue.com/moapp/jybase/mysql"
+	"fmt"
 	"github.com/zeromicro/go-zero/core/logx"
 	IC "jyBXSubscribe/rpc/init"
+	"log"
 )
 
-var Mysql *mysql.Mysql
-var Mgo *MongodbSim
-
 //用户基本信息
 type UserInfo struct {
 	Entniche *Entniche
@@ -40,8 +37,8 @@ func (m *MatchJob) Start(entId, entUserId int) (map[string]interface{}, int) {
 func (m *MatchJob) LoadSubSet(entId int) map[*UserInfo]bool {
 	defer util.Catch()
 	Users := map[*UserInfo]bool{}
-	sess := Mgo.GetMgoConn()
-	defer Mgo.DestoryMongoConn(sess)
+	sess := IC.Mgo.GetMgoConn()
+	defer IC.Mgo.DestoryMongoConn(sess)
 	it := sess.DB("qfw").C("entniche_rule").Find(map[string]interface{}{
 		"i_entid": entId,
 	}).Select(map[string]interface{}{
@@ -50,18 +47,17 @@ func (m *MatchJob) LoadSubSet(entId int) map[*UserInfo]bool {
 		"i_userid":   1,
 		"o_entniche": 1,
 	}).Iter()
+	log.Println("it", it)
 	for _temp := make(map[string]interface{}); it.Next(&_temp); {
 		func(temp map[string]interface{}) {
+			log.Println("temp", temp)
 			entId := util.IntAll(temp["i_entid"])
 			deptId := util.IntAll(temp["i_deptid"])
 			userId := util.IntAll(temp["i_userid"])
 			if entId == 0 || (deptId == 0 && userId == 0) {
 				return
-			} else if Ents[entId] == nil {
-				logx.Info("没有找到该企业", entId)
-				return
 			}
-			entName := Ents[entId].Name
+			entName := fmt.Sprint(entId)
 			if deptId > 0 && EntDepts[deptId] == nil {
 				logx.Info("没有找到该部门", entName, entId, deptId)
 				return
@@ -77,13 +73,7 @@ func (m *MatchJob) LoadSubSet(entId int) map[*UserInfo]bool {
 			}
 			//
 			if deptId > 0 { //部门订阅
-				if Ents[entId].Model != 1 {
-					logx.Info("不是统一订阅模式,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId] == nil {
-					logx.Info("没有找到该部门,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId].Subdis == 0 {
+				if EntDepts[deptId].Subdis == 0 {
 					logx.Info("该部门的订阅分发没有开启,过滤掉", entName, entId, deptName, deptId)
 					return
 				} else if EntDepts[deptId].Nodiff == 0 && EntDeptDis[deptId] == nil {
@@ -98,15 +88,9 @@ func (m *MatchJob) LoadSubSet(entId int) map[*UserInfo]bool {
 					}
 				}
 			} else if userId > 0 { //个人订阅
-				if Ents[entId].Model != 2 {
-					logx.Info("不是个人订阅模式,过滤掉", entName, entId, userId)
-					return
-				} else if EntUsers[userId] == nil {
+				if EntUsers[userId] == nil {
 					logx.Info("没有找到该用户,过滤掉", entName, entId, userId)
 					return
-				} else if EntUsers[userId].Power == 0 {
-					logx.Info("该用户没有权限,过滤掉", entName, entId, userId)
-					return
 				}
 			}
 			user := &UserInfo{
@@ -121,17 +105,7 @@ func (m *MatchJob) LoadSubSet(entId int) map[*UserInfo]bool {
 			}
 			logx.Info("加载订阅设置", "entId", entId, "entName", entName, "deptId", deptId, "deptName", deptName, "userId", userId)
 			Users[user] = true
-			if deptId <= 0 {
-				return
-			}
 			//分发规则
-			if EntDepts[deptId].Nodiff == 1 {
-				logx.Info("该部门开启了全员无差别,分发规则无效", entName, entId, deptName, deptId)
-				return
-			} else if EntDeptDis[deptId] == nil {
-				logx.Info("该部门没有分发规则", entName, entId, deptName, deptId)
-				return
-			}
 			itemMap := map[string]interface{}{}
 			items, _ := subSet["a_items"].([]interface{})
 			for _, v := range items {