|
@@ -390,22 +390,80 @@ func isNullSearch(scd *SieveCondition) (isNull bool) {
|
|
|
* count 返回数量 (-1:预览数据查询)
|
|
|
*/
|
|
|
|
|
|
-func GetDataExportSearchResultByScdId(sim mg.MongodbSim, elasticAddress, id, dataType string, checkCount int) (*[]map[string]interface{}, error) {
|
|
|
+func GetDataExportSearchResultByScdId(sim, bid mg.MongodbSim, elasticAddress, id, dataType string, checkCount int) (*[]map[string]interface{}, error) {
|
|
|
scd := GetSqlObjFromId(sim, id)
|
|
|
- //if scd.SelectIds != nil {
|
|
|
- // return GetDataExportSelectResult(scd, dataType, checkCount)
|
|
|
- //}
|
|
|
- return GetDataExportSearchResult(elasticAddress, scd, dataType, checkCount)
|
|
|
+ return GetDataExportSearchResult(bid, elasticAddress, scd, dataType, checkCount)
|
|
|
+}
|
|
|
+
|
|
|
+//收藏导出
|
|
|
+var contentfilterReg = regexp.MustCompile("<[^>]+>")
|
|
|
+
|
|
|
+func GetDataExportSelectResult(bidding mg.MongodbSim, 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,
|
|
|
+ }
|
|
|
+ if dataType == "2" {
|
|
|
+ for _, key := range []string{"href", "projectcode", "buyerperson", "buyertel", "budget", "bidopentime", "agency", "projectscope", "winnerperson", "winnertel"} {
|
|
|
+ selectMap[key] = 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ returnLsit := make([]map[string]interface{}, 0, len(queryIds))
|
|
|
+ iter := sess.DB("qfw_data").C("bidding").Select(selectMap).Find(map[string]interface{}{"_id": map[string]interface{}{
|
|
|
+ "$in": queryIds,
|
|
|
+ }}).Iter()
|
|
|
+ for m := make(map[string]interface{}); iter.Next(&m); {
|
|
|
+ m["_id"] = mg.BsonIdToSId(m["_id"])
|
|
|
+ detail, _ := m["detail"].(string)
|
|
|
+ if detail != "" {
|
|
|
+ m["detail"] = contentfilterReg.ReplaceAllString(detail, "")
|
|
|
+ }
|
|
|
+ returnLsit = append(returnLsit, m)
|
|
|
+ m = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ if len(returnLsit) == checkCount {
|
|
|
+ return &returnLsit, nil
|
|
|
+ }
|
|
|
+ iter_back := sess.DB("qfw_data").C("bidding_back").Select(selectMap).Find(map[string]interface{}{"_id": map[string]interface{}{
|
|
|
+ "$in": queryIds,
|
|
|
+ }}).Iter()
|
|
|
+ for m := make(map[string]interface{}); iter_back.Next(&m); {
|
|
|
+ m["_id"] = mg.BsonIdToSId(m["_id"])
|
|
|
+ detail, _ := m["detail"].(string)
|
|
|
+ if detail != "" {
|
|
|
+ m["detail"] = contentfilterReg.ReplaceAllString(detail, "")
|
|
|
+ }
|
|
|
+ returnLsit = append(returnLsit, m)
|
|
|
+ m = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ if len(returnLsit) == checkCount {
|
|
|
+ return &returnLsit, nil
|
|
|
+ }
|
|
|
+ return nil, fmt.Errorf("选择数据导出异常 数据量期望%d条,实际查询%d条", checkCount, len(returnLsit))
|
|
|
}
|
|
|
|
|
|
//GetDataExportSearchResult 获取数据导出内容
|
|
|
//entmg 高级字段包查询企业电话邮箱等字段
|
|
|
//checkCount -1 预览500条
|
|
|
-func GetDataExportSearchResult(elasticAddress string, scd *SieveCondition, dataType string, checkCount int) (*[]map[string]interface{}, error) {
|
|
|
+func GetDataExportSearchResult(bid mg.MongodbSim, elasticAddress string, scd *SieveCondition, dataType string, checkCount int) (*[]map[string]interface{}, error) {
|
|
|
defer qutil.Catch()
|
|
|
if scd == nil {
|
|
|
return nil, errors.New("GetDataExportSearchResult-获取查询条件")
|
|
|
}
|
|
|
+ if scd.SelectIds != nil {
|
|
|
+ return GetDataExportSelectResult(bid, scd, dataType, checkCount)
|
|
|
+ }
|
|
|
//获取查询语句
|
|
|
qstr := getDataExportSql(scd)
|
|
|
log.Printf("GetDataExportSearchResult-%s-sql:%s\n", scd.Id, qstr)
|
|
@@ -437,7 +495,6 @@ func GetDataExportSearchResult(elasticAddress string, scd *SieveCondition, dataT
|
|
|
//校验数量
|
|
|
if checkCount != len(res) && checkCount != -1 {
|
|
|
return nil, fmt.Errorf("GetDataExportSearchResult-%s-数据总量校验异常,期望:%d,实际:%d", scd.Id, checkCount, len(res))
|
|
|
- //发邮件
|
|
|
}
|
|
|
return &res, nil
|
|
|
}
|