浏览代码

fix:数据导出数量校验

wangkaiyue 3 年之前
父节点
当前提交
702acb069e

+ 1 - 1
src/jfw/front/dataExport.go

@@ -391,7 +391,7 @@ func (d *DataExport) ToCreateOrderPage(_id string) error {
 	} else {
 		d.DelSession("Structed")
 	}
-	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.DbConf.Elasticsearch.Main.Address, id)
+	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, id)
 	if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
 		msgCount = public.ExConf.MsgMaxCount
 	}

+ 1 - 1
src/jfw/front/ws_dataExport.go

@@ -291,7 +291,7 @@ func (w *WsDataExport) SubmitOrder() error {
 			return errors.New("未登录")
 		}
 	}
-	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.DbConf.Elasticsearch.Main.Address, id)
+	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, id)
 	if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
 		msgCount = public.ExConf.MsgMaxCount
 	}

+ 1 - 1
src/jfw/modules/app/src/app/front/ws_dataExport.go

@@ -258,7 +258,7 @@ func (w *WsDataExport) ToCreateOrderPage() error {
 		return errors.New("未登录")
 	}
 	log.Println(id)
-	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.DbConf.Elasticsearch.Main.Address, id)
+	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.DbName, public.DbConf.Elasticsearch.Main.Address, id)
 	if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
 		msgCount = public.ExConf.MsgMaxCount
 	}

+ 40 - 9
src/jfw/modules/common/src/qfw/util/dataexport/dataexport.go

@@ -310,10 +310,12 @@ func GetSqlObjFromId(mongo mg.MongodbSim, _id string) *SieveCondition {
 }
 
 //数据导出-查询结果数量
-func GetDataExportSearchCountByScdId(sim mg.MongodbSim, elasticAddress, id string) (count int) {
+func GetDataExportSearchCountByScdId(sim, bid mg.MongodbSim, biddingName, elasticAddress, id string) (count int) {
 	scd := GetSqlObjFromId(sim, id) //用户筛选条件
 	if scd.SelectIds != nil {
-		return len(scd.SelectIds)
+		//部分数据可能已删除、不存在;此处需要统计返回实际数量
+		//return len(scd.SelectIds)
+		return int(GetDataExportSelectReallyCount(bid, biddingName, scd.SelectIds))
 	}
 	return GetDataExportSearchCountBySieveCondition(scd, elasticAddress)
 }
@@ -406,19 +408,48 @@ func GetDataExportIdArrByScdId(sim mg.MongodbSim, elasticAddress, id string, che
 //收藏导出
 var contentfilterReg = regexp.MustCompile("<[^>]+>")
 
+//GetDataExportSelectReallyCount 查询实际可调导出数量
+func GetDataExportSelectReallyCount(bid mg.MongodbSim, biddingName string, ids []string) int64 {
+	sess := bid.GetMgoConn()
+	defer bid.DestoryMongoConn(sess)
+	if ids == nil || len(ids) == 0 {
+		return 0
+	}
+	var queryIds []interface{}
+	for _, idStr := range ids {
+		queryIds = append(queryIds, mg.StringTOBsonId(idStr))
+	}
+	lenNum := int64(len(ids))
+	num1, err1 := sess.DB(biddingName).C("bidding").Find(map[string]interface{}{"_id": map[string]interface{}{
+		"$in": queryIds,
+	}}).Count()
+	if err1 == nil {
+		if num1 == lenNum {
+			return lenNum
+		}
+		num2, err2 := sess.DB(biddingName).C("bidding_back").Find(map[string]interface{}{"_id": map[string]interface{}{
+			"$in": queryIds,
+		}}).Count()
+		if err2 == nil {
+			if num2+num1 == lenNum {
+				return lenNum
+			} else if num1+num2 > lenNum {
+				return lenNum
+			} else if num1+num2 < lenNum {
+				return num1 + num2
+			}
+		}
+	}
+	return -2
+}
+
 func GetDataExportSelectResult(bidding mg.MongodbSim, biddingName string, scd *SieveCondition, dataType string, checkCount int) (*[]map[string]interface{}, error) {
 	sess := bidding.GetMgoConn()
 	defer bidding.DestoryMongoConn(sess)
-	if checkCount == -1 {
-		checkCount = len(scd.SelectIds)
-	}
 	var queryIds []interface{}
 	for _, idStr := range scd.SelectIds {
 		queryIds = append(queryIds, mg.StringTOBsonId(idStr))
 	}
-	if queryIds == nil || len(queryIds) != checkCount {
-		return nil, fmt.Errorf("选择数据导出异常 id数量不一致 期望%d 实际%d", checkCount, len(queryIds))
-	}
 	selectMap := map[string]interface{}{
 		"_id": 1, "title": 1, "detail": 1, "area": 1, "city": 1, "publishtime": 1, "projectname": 1, "buyer": 1, "s_winner": 1, "bidamount": 1, "subtype": 1, "toptype": 1,
 	}
@@ -455,7 +486,7 @@ func GetDataExportSelectResult(bidding mg.MongodbSim, biddingName string, scd *S
 		returnLsit = append(returnLsit, m)
 		m = make(map[string]interface{})
 	}
-	if len(returnLsit) == checkCount {
+	if len(returnLsit) == checkCount || checkCount == -1 {
 		return &returnLsit, nil
 	}
 	return nil, fmt.Errorf("选择数据导出异常 数据量期望%d条,实际查询%d条", checkCount, len(returnLsit))

+ 1 - 1
src/jfw/modules/common/src/qfw/util/dataexport/entdataexport.go

@@ -31,7 +31,7 @@ func GetEntDataExportCount(sim, bid mg.MongodbSim, bidMgoDBName, elasticAddress,
 	var (
 		searchsWaitGroup = &sync.WaitGroup{}
 	)
-	count = GetDataExportSearchCountByScdId(sim, elasticAddress, _id)
+	count = GetDataExportSearchCountByScdId(sim, bid, bidMgoDBName, elasticAddress, _id)
 	if count > maxCount || count == -1 {
 		count = maxCount
 	}

+ 2 - 2
src/jfw/modules/subscribepay/src/service/dataExportPay.go

@@ -71,12 +71,12 @@ func (p *DataExportPay) CreateOrder() {
 		data_spec = "高级字段包"
 	}
 
-	data_count := dataexport.GetDataExportSearchCountByScdId(util.MQFW, config.Config.Elasticsearch, id)
+	data_count := dataexport.GetDataExportSearchCountByScdId(util.MQFW, util.Mgo_bidding, config.Config.Mongobidding.DbName, config.Config.Elasticsearch, id)
 	if data_count > config.ExConf.MsgMaxCount || data_count == -1 {
 		data_count = config.ExConf.MsgMaxCount
 	}
 
-	if data_count == 0 {
+	if data_count <= 0 {
 		log.Println("未查询到检索信息", userId, id)
 		p.ServeJson(map[string]interface{}{
 			"status": "n",

+ 6 - 3
src/jfw/modules/subscribepay/src/service/dataexportPack.go

@@ -238,10 +238,13 @@ func (this *DataExportPack) Statistics() {
 		if filterId == "" {
 			return nil, fmt.Errorf("请求参数异常")
 		}
-		selectCount := dataexport.GetDataExportSearchCountByScdId(util.MQFW, config.Config.Elasticsearch, filterId)
+		selectCount := dataexport.GetDataExportSearchCountByScdId(util.MQFW, util.Mgo_bidding, config.Config.Mongobidding.DbName, config.Config.Elasticsearch, filterId)
 		if selectCount > config.ExConf.MsgMaxCount || selectCount == -1 {
 			selectCount = config.ExConf.MsgMaxCount
 		}
+		if selectCount <= 0 {
+			return nil, fmt.Errorf("导出数据异常")
+		}
 		if entId := this.GetString("entId"); entId != "" {
 			deduct, err := entity.JyDataExportPack.DoEntPackRepeatCheck(this.Session(), userId, entId, filterId, selectCount)
 			if err != nil {
@@ -291,8 +294,8 @@ func (this *DataExportPack) PackPay() {
 		if filterId == "" {
 			return nil, fmt.Errorf("请求参数异常")
 		}
-		selectCount := dataexport.GetDataExportSearchCountByScdId(util.MQFW, config.Config.Elasticsearch, filterId)
-		if selectCount > config.ExConf.MsgMaxCount {
+		selectCount := dataexport.GetDataExportSearchCountByScdId(util.MQFW, util.Mgo_bidding, config.Config.Mongobidding.DbName, config.Config.Elasticsearch, filterId)
+		if selectCount > config.ExConf.MsgMaxCount || selectCount == -1 {
 			selectCount = config.ExConf.MsgMaxCount
 		}
 		if total_req != selectCount {