Browse Source

数据导出修改

WH01243 2 years ago
parent
commit
468d342e14

+ 21 - 7
jyBXSubscribe/rpc/internal/logic/bypushhistorylogic.go

@@ -55,15 +55,29 @@ func (l *ByPushHistoryLogic) ByPushHistory(in *bxsubscribe.SubscribeInfosReq) (*
 		BaseServiceMysql: IC.BaseServiceMysql,
 		IsEnt:            in.IsEnt,
 	}
+
+	//主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
+	infoCount := int64(0)
+	if in.UserType == model.MemberFlag {
+		infoCount = IC.MainMysql.CountBySql("select  count(id) from  entniche_wait_empower where  ent_id=? and  end_time>NOW() and  product_type like '%大会员%' ", in.EntId)
+	} else if in.UserType == model.SubVipFlag {
+		infoCount = IC.MainMysql.CountBySql("select  count(id) from  entniche_wait_empower where  ent_id=? and  end_time>NOW() and product_type like '%VIP订阅%' ", in.EntId)
+	}
+	if infoCount > 0 {
+		in.UserType = model.EntnicheFlag
+		vipType = model.EntnicheFlag
+	}
+
+	if in.IsEnt == true {
+		newCount := IC.MainMysql.CountBySql("select  count(id) from  entniche_info where  id =? and  status=1", spqp.EntId)
+		if newCount > 0 {
+			in.UserType = model.EntnicheFlag
+			vipType = model.EntnicheFlag
+		}
+	}
+
 	logx.Info("数据导出查询参数", in)
 	if selectIds := strings.TrimSpace(in.SelectIds); selectIds != "" {
-		//encodeArr := strings.Split(selectIds, ",")
-		//idArr := make([]string, 0, len(encodeArr))
-		//for _, encodeId := range encodeArr {
-		//	if tmp := util.DecodeId(encodeId); tmp != "" {
-		//		idArr = append(idArr, tmp)
-		//	}
-		//}
 		spqp.SelectInfoIds = strings.Split(selectIds, ",")
 	}
 

+ 50 - 22
jyBXSubscribe/rpc/model/push.go

@@ -364,11 +364,19 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 		findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
 	} else {
 		if spqp.IsEnt {
-			if spqp.BuySubject == 1 {
+			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 {
@@ -1498,7 +1506,10 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 		}
 		if (spqp.VipPower == 1 || spqp.MemberPower == 1) || (spqp.UserPower == 1 && spqp.PowerSource == 0) {
 			//1、mysql entniche_user_rule表中获取自己的分发规则id
-			data := IC.MainMysql.SelectBySql(`select rule_id from entniche_user_rule where user_id =? `, spqp.EntUserId)
+			data := IC.MainMysql.SelectBySql(`SELECT rule_id FROM entniche_user_rule a 
+                                                                        INNER JOIN entniche_department b ON  a.dept_id = b.id AND a.user_id =?
+                                                                        ORDER BY b.pid
+                                                                        LIMIT 1 `, spqp.EntUserId)
 			if data == nil || len(*data) == 0 {
 				return MapToarr(keyData)
 			}
@@ -1513,13 +1524,17 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 				return MapToarr(keyData)
 			}
 			//2、entniche_rule表, 企业订阅关键词查询条件:  {i_entid:123,i_deptid:0},取 o_entniche.a_items
-			res_, _ := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
-				"i_deptid": map[string]interface{}{"$exists": false},
-				"i_userid": map[string]interface{}{
-					"$exists": false,
-				},
+			deptid := common.Int64All((*res)["i_deptid"])
+			ruleMap := map[string]interface{}{
 				"i_entid": common.Int64All(spqp.EntId),
-			}, `{"o_entniche":1}`)
+			}
+			if deptid == 0 {
+				ruleMap["i_deptid"] = map[string]interface{}{"$exists": false}
+				ruleMap["i_userid"] = map[string]interface{}{"$exists": false}
+			} else {
+				ruleMap["i_deptid"] = deptid
+			}
+			res_, _ := IC.Mgo.FindOneByField("entniche_rule", ruleMap, `{"o_entniche":1}`)
 			o_entniche := &map[string]interface{}{}
 			if res_ != nil {
 				o_entniche = common.ObjToMap((*res_)["o_entniche"])
@@ -1551,26 +1566,39 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 		}
 	} else {
 		//企业关键词查找
-		res_, _ := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
-			"i_deptid": map[string]interface{}{"$exists": false},
+		res_, _ := IC.Mgo.Find("entniche_rule", map[string]interface{}{
+			"i_deptid": map[string]interface{}{"$exists": true},
 			"i_userid": map[string]interface{}{
 				"$exists": false,
 			},
 			"i_entid": common.Int64All(spqp.EntId),
-		}, `{"o_entniche":1}`)
-		o_entniche := &map[string]interface{}{}
-		if res_ != nil {
-			o_entniche = common.ObjToMap((*res_)["o_entniche"])
-		}
-		if (*o_entniche)["a_items"] != nil {
-			a_item := common.ObjArrToMapArr((*o_entniche)["a_items"].([]interface{}))
-			for _, v := range a_item {
-				if v["a_key"] != nil {
-					a_key_arr := v["a_key"].([]interface{})
-					keyData[common.InterfaceToStr(v["s_item"])] = a_key_arr
+		}, "", `{"o_entniche":1}`, false, -1, -1)
+		o_entniche := map[string]interface{}{}
+		if res_ == nil || len(*res_) == 0 {
+
+			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{}))
+				for _, v := range a_item {
+					if v["a_key"] != nil {
+						a_key_arr := v["a_key"].([]interface{})
+						s_item := common.InterfaceToStr(v["s_item"])
+						if keyData[s_item] != nil {
+							//第一次搜索存在
+							//去重
+							keyData[s_item] = MergeArray(a_key_arr, keyData[s_item])
+						} else {
+							//第一次搜索不存在
+							keyData[s_item] = a_key_arr
+						}
+					}
 				}
 			}
 		}
+
 	}
 
 	return MapToarr(keyData)