|
@@ -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))
|