123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- package public
- //此处逻辑移至支付程序
- //func GetEntDataExportCount(_id string, entId, entUserId, limitNum, current int, isFirst bool, webdomain string, url string) (count, newCount int, data *[]map[string]interface{}) {
- // defer util.Catch()
- // var (
- // searchsWaitGroup = &sync.WaitGroup{}
- // //searchsPool = make(chan bool, 20)
- // // res = &[]map[string]interface{}{}
- // //newCountPool = make(chan bool, 20000)
- // )
- // //count = GetDataExportSearchCountUseId(_id)
- // count = dataexport.GetDataExportSearchCountByScdId(MQFW, DbConf.Elasticsearch.Main.Address, _id)
- // log.Println("count", count)
- // if count > ExConf.MsgMaxCount || count == -1 {
- // count = ExConf.MsgMaxCount
- // }
- // dataType := "2"
- // //数据导出数据查询
- //
- // res, err := dataexport.GetDataExportSearchResultByScdId(MQFW, Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Elasticsearch.Main.Address, _id, dataType, count)
- // if err != nil {
- // log.Println("企业数据导出错误 ", err)
- // return 0, 0, nil
- // }
- // // 20210716 由原来的redis判重改为调用判重中台接口进行判重
- // m := map[string]bool{}
- // infoIdList := []string{}
- // insertFlag := "false"
- // if !isFirst {
- // insertFlag = "true"
- // }
- // for _, v := range *res {
- // id := util.ObjToString(v["_id"])
- // if m[id] {
- // continue
- // }
- // m[id] = true
- // // 20210716 redis判重调整为调用判重中台接口 每一千个调用一次
- // infoIdList = append(infoIdList, id)
- // if len(infoIdList) > 1000 {
- // // 调接口
- // rs, err5 := Post(url, map[string]string{
- // "personId": "0", // 没有使用这个参数
- // "infoId": strings.Join(infoIdList, ","),
- // "entId": fmt.Sprintf("%d", entId),
- // "isInsert": insertFlag,
- // "isEnt": "true",
- // })
- // log.Println("响应结果:",rs)
- // if err5 != nil|| util.IntAll(rs["code"])!=0 {
- // log.Println("企业订阅数据导出接口判重失败", err5)
- // log.Println("企业订阅数据导出接口判重失败rs:",rs)
- // log.Println("企业订阅数据导出接口判重失败rs[code]:",rs["code"])
- // log.Println("企业订阅数据导出接口判重失败code是否为0",util.IntAll(rs["code"])!=0)
- // log.Println("企业订阅数据导出接口判重失败", err5,"rs:",rs," rs[code]:",rs["code"]," ",util.IntAll(rs["code"]),"code是否为0",util.IntAll(rs["code"])!=0)
- // } else {
- // log.Println("企业订阅数据导出")
- // // 置空
- // infoIdList = []string{}
- // // 本次数据累计
- // returnData := rs["data"].(map[string]interface{})
- // log.Println(newCount, "加之前")
- // newCount += int(returnData["newCount"].(float64))
- // log.Println(newCount, "加之后")
- // }
- //
- // }
- // if !isFirst {
- // delete(v, "_id")
- // v["entid"] = entId
- // v["userid"] = entUserId
- // v["infoid"] = id
- // v["createtime"] = time.Now().Unix()
- // }
- // }
- // if len(infoIdList) > 0 {
- // rs, err5 := Post(url, map[string]string{
- // "personId": "0", // 没有使用这个参数
- // "infoId": strings.Join(infoIdList, ","),
- // "entId": fmt.Sprintf("%d", entId),
- // "isInsert": insertFlag,
- // "isEnt": "true",
- // })
- // log.Println(rs)
- // if err5 != nil|| util.IntAll(rs["code"])!=0{
- // log.Println("企业订阅数据导出接口判重失败", err5)
- // log.Println("企业订阅数据导出接口判重失败rs:",rs)
- // log.Println("企业订阅数据导出接口判重失败rs[code]:",rs["code"])
- // log.Println("企业订阅数据导出接口判重失败code是否为0",util.IntAll(rs["code"])!=0)
- // log.Println("企业订阅数据导出接口判重失败", err5,"rs:",rs," rs[code]:",rs["code"]," ",util.IntAll(rs["code"]),"code是否为0",util.IntAll(rs["code"])!=0)
- // } else {
- // log.Println("企业订阅数据导出")
- // // 置空
- // infoIdList = []string{}
- // // 本次数据累计
- // returnData := rs["data"].(map[string]interface{})
- // log.Println(newCount, "加之前")
- // newCount += int(returnData["newCount"].(float64))
- // log.Println(newCount, "加之后")
- //
- // }
- // }
- // searchsWaitGroup.Wait()
- // log.Println("企业数据导出--数据遍历完成")
- // //newCount = len(newCountPool)
- // log.Println("new", newCount)
- // data = res
- // return
- //}
- //
- //func FormatExportDatas(data *[]map[string]interface{}, webdomain string, dataType string, entId int) *[]map[string]interface{} {
- // //格式化输出
- // var (
- // entexportPool = make(chan bool, 20)
- // entexportWaitGroup = &sync.WaitGroup{}
- // )
- // log.Println("补充信息开始")
- // for _, v := range *data {
- // entexportWaitGroup.Add(1)
- // entexportPool <- true
- // go func(v map[string]interface{}) {
- // defer func() {
- // entexportWaitGroup.Done()
- // <-entexportPool
- // }()
- // //有中标企业 且 高级字段查询
- // if dataType == "2" {
- // //查询企业公示 法人 公司电话 公司邮箱地址
- // s_winner := strings.Split(util.ObjToString(v["s_winner"]), ",")[0]
- // if entData, ok := Mgo_Ent.Find("winner_enterprise", bson.M{"company_name": s_winner}, nil,
- // `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
- // if entData != nil && *entData != nil && len(*entData) > 0 {
- // for _, ev := range *entData {
- // if v["s_winner"] == ev["company_name"] {
- // legal_person := ""
- // if ev["legal_person"] != nil {
- // legal_person = ev["legal_person"].(string)
- // }
- // company_phone := ""
- // if ev["company_phone"] != nil {
- // company_phone = ev["company_phone"].(string)
- // }
- // company_email := ""
- // if ev["company_email"] != nil && ev["company_email"] != "无" {
- // company_email = ev["company_email"].(string)
- // }
- // v["legal_person"] = legal_person
- // v["company_phone"] = company_phone
- // v["company_email"] = company_email
- // }
- // }
- // }
- // }
- // }
- // //====================字段补漏=========================
- // if v["toptype"] == "结果" && dataType == "2" && !(v["agency"] != nil && v["budget"] != nil && v["buyerperson"] != nil && v["buyertel"] != nil) {
- // r := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query":{"term":{"list.infoid":"%s"}},"_source": ["list"]}`, v["_id"]))
- // if len(*r) > 0 {
- // MsgList := (*r)[0]["list"]
- // if MsgList != nil {
- // list := util.ObjArrToMapArr(MsgList.([]interface{}))
- // for _, vv := range list {
- // if vv["subtype"] == "招标" {
- // if v["agency"] == nil && vv["agency"] != nil {
- // v["agency"] = vv["agency"]
- // }
- // if v["budget"] == nil && vv["budget"] != nil {
- // v["budget"] = vv["budget"]
- // }
- // if v["buyerperson"] == nil && vv["buyerperson"] != nil {
- // v["buyerperson"] = vv["buyerperson"]
- // }
- // if v["buyertel"] == nil && vv["buyertel"] != nil {
- // v["buyertel"] = vv["buyertel"]
- // }
- // break
- // }
- // }
- // }
- // }
- // }
- // if v["area"] == "A" {
- // v["area"] = "全国"
- // }
- // if v["publishtime"] != nil {
- // date := v["publishtime"]
- // v["publishtime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
- // }
- // if v["bidopentime"] != nil {
- // date := v["bidopentime"]
- // v["bidopentime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
- // }
- // if v["currency"] == "" || v["currency"] == nil {
- // v["currency"] = "人民币"
- // }
- // if v["subtype"] == nil && v["toptype"] != nil {
- // v["subtype"] = v["toptype"]
- // }
- // if v["detail"] != "" && v["detail"] != nil {
- // str := ClearHtml.ReplaceAllString(v["detail"].(string), "")
- // str = ClearOther.ReplaceAllString(str, "")
- // str = strings.Replace(str, " ", "", -1)
- // v["detail"] = str
- // }
- // if v["_id"] != nil {
- // v["url"] = webdomain + "/article/content/" + util.CommonEncodeArticle("content", v["_id"].(string)) + ".html"
- // }
- // }(v)
- // }
- // entexportWaitGroup.Wait()
- // log.Println("补充信息结束")
- // return data
- //}
- //func GetDataExportSearchResult(id string, dataType string, checkCount int) (*[]map[string]interface{}, error) {
- // defer util.Catch()
- // var (
- // onceSearchCount = 500
- // searchPool = make(chan bool, 20)
- // res []map[string]interface{}
- // )
- // //获取查询语句
- // scd := dataexport.GetSqlObjFromId(MQFW, id)
- // if scd == nil {
- // return nil, errors.New("GetDataExportSearchResult-获取查询条件")
- // }
- // qstr := getDataExportSql(scd)
- // log.Printf("GetDataExportSearchResult-%s-sql:%s\n", scd.Id, qstr)
- // //数据导出数据查询
- // if checkCount > onceSearchCount { //分批次查询
- // batchNum := util.IntAll(math.Ceil(float64(checkCount) / float64(onceSearchCount)))
- // var searchWaitGroup = &sync.WaitGroup{}
- // var lock sync.Mutex
- // for n := 0; n < batchNum; n++ {
- // searchWaitGroup.Add(1)
- // searchPool <- true
- // go func(start int) {
- // defer func() {
- // searchWaitGroup.Done()
- // <-searchPool
- // }()
- // checkNum, checkOk := onceSearchCount, false
- // if start == (batchNum - 1) {
- // if checkCount%onceSearchCount != 0 {
- // checkNum = checkCount % onceSearchCount
- // }
- // }
- //
- // var tmp *[]map[string]interface{}
- // for i := 0; i < 3; i++ {
- // tmp = doSearch(qstr, start*onceSearchCount, onceSearchCount, dataType)
- // if tmp != nil && (len(*tmp) == checkNum) { //校验数据量是否够
- // checkOk = true
- // break
- // }
- // }
- // if tmp == nil {
- // log.Printf("GetDataExportSearchResult-%s-第%d页数据查询结果为空\n", scd.Id, start+1)
- // return
- // }
- // if checkOk {
- // log.Printf("GetDataExportSearchResult-%s-第%d页数据加载完成,共%d条\n", scd.Id, start+1, len(*tmp))
- // } else {
- // log.Printf("GetDataExportSearchResult-%s-第%d页数据加载异常,共%d条,预期%d条\n", scd.Id, start+1, len(*tmp), checkNum)
- // }
- // lock.Lock()
- // res = append(res, *tmp...)
- // lock.Unlock()
- // }(n)
- // }
- // searchWaitGroup.Wait()
- // log.Printf("GetDataExportSearchResult-%s-分批次加载数据总量为%d\n", scd.Id, len(res))
- // } else {
- // tmp := doSearch(qstr, 0, checkCount, dataType)
- // if tmp == nil || len(*tmp) == 0 {
- // log.Printf("GetDataExportSearchResult-%s-一次性加载数据异常\n", scd.Id)
- // } else {
- // res = *tmp
- // log.Printf("GetDataExportSearchResult-%s-一次性加载数据总量为%d\n", scd.Id, len(res))
- // }
- // }
- // //超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
- // if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) {
- // if len(scd.Keyword) != 0 {
- // num := len(res)
- // searchTextSize := 0
- // if len(scd.Keyword) > 0 {
- // searchTextSize = len([]rune(scd.Keyword[0].Keyword))
- // }
- // if searchTextSize > 3 && num < 50 {
- // secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
- // scd.Keyword[0].Keyword = secondKWS
- // scd.SelectType = "title"
- // qstr = getDataExportSql(scd)
- // log.Printf("GetDataExportSearchResult-%s-分词查询-sql:%s\n", scd.Id, qstr)
- // res2 := doSearch(qstr, 0, 100, "")
- // res = *delRepeatMapArr(&res, res2)
- // if len(res) > 100 {
- // res = res[:100]
- // }
- // }
- // }
- // }
- // //校验数量
- // if checkCount != len(res) {
- // return nil, fmt.Errorf("GetDataExportSearchResult-%s-数据总量校验异常,期望:%d,实际:%d", scd.Id, checkCount, len(res))
- // //发邮件
- // }
- // return &res, nil
- //}
- //func Post(url string, form map[string]string) (data map[string]interface{}, err error) {
- // str := ""
- // for k, v := range form {
- // str += "&" + k + "=" + v
- // }
- // //log.Println(str)
- // res, err1 := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
- // log.Println(res)
- // if err1 != nil {
- // log.Println("post err:", err1.Error())
- // return nil, err1
- //
- // } else if res.Body != nil {
- // defer res.Body.Close()
- // bs, _ := ioutil.ReadAll(res.Body)
- // err2 := json.Unmarshal(bs, &data)
- // if err2 != nil {
- // return nil, err2
- // }
- //
- // }
- // return data, nil
- //}
|