entdataexport.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. package public
  2. //此处逻辑移至支付程序
  3. //func GetEntDataExportCount(_id string, entId, entUserId, limitNum, current int, isFirst bool, webdomain string, url string) (count, newCount int, data *[]map[string]interface{}) {
  4. // defer util.Catch()
  5. // var (
  6. // searchsWaitGroup = &sync.WaitGroup{}
  7. // //searchsPool = make(chan bool, 20)
  8. // // res = &[]map[string]interface{}{}
  9. // //newCountPool = make(chan bool, 20000)
  10. // )
  11. // //count = GetDataExportSearchCountUseId(_id)
  12. // count = dataexport.GetDataExportSearchCountByScdId(MQFW, DbConf.Elasticsearch.Main.Address, _id)
  13. // log.Println("count", count)
  14. // if count > ExConf.MsgMaxCount || count == -1 {
  15. // count = ExConf.MsgMaxCount
  16. // }
  17. // dataType := "2"
  18. // //数据导出数据查询
  19. //
  20. // res, err := dataexport.GetDataExportSearchResultByScdId(MQFW, Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Elasticsearch.Main.Address, _id, dataType, count)
  21. // if err != nil {
  22. // log.Println("企业数据导出错误 ", err)
  23. // return 0, 0, nil
  24. // }
  25. // // 20210716 由原来的redis判重改为调用判重中台接口进行判重
  26. // m := map[string]bool{}
  27. // infoIdList := []string{}
  28. // insertFlag := "false"
  29. // if !isFirst {
  30. // insertFlag = "true"
  31. // }
  32. // for _, v := range *res {
  33. // id := util.ObjToString(v["_id"])
  34. // if m[id] {
  35. // continue
  36. // }
  37. // m[id] = true
  38. // // 20210716 redis判重调整为调用判重中台接口 每一千个调用一次
  39. // infoIdList = append(infoIdList, id)
  40. // if len(infoIdList) > 1000 {
  41. // // 调接口
  42. // rs, err5 := Post(url, map[string]string{
  43. // "personId": "0", // 没有使用这个参数
  44. // "infoId": strings.Join(infoIdList, ","),
  45. // "entId": fmt.Sprintf("%d", entId),
  46. // "isInsert": insertFlag,
  47. // "isEnt": "true",
  48. // })
  49. // log.Println("响应结果:",rs)
  50. // if err5 != nil|| util.IntAll(rs["code"])!=0 {
  51. // log.Println("企业订阅数据导出接口判重失败", err5)
  52. // log.Println("企业订阅数据导出接口判重失败rs:",rs)
  53. // log.Println("企业订阅数据导出接口判重失败rs[code]:",rs["code"])
  54. // log.Println("企业订阅数据导出接口判重失败code是否为0",util.IntAll(rs["code"])!=0)
  55. // log.Println("企业订阅数据导出接口判重失败", err5,"rs:",rs," rs[code]:",rs["code"]," ",util.IntAll(rs["code"]),"code是否为0",util.IntAll(rs["code"])!=0)
  56. // } else {
  57. // log.Println("企业订阅数据导出")
  58. // // 置空
  59. // infoIdList = []string{}
  60. // // 本次数据累计
  61. // returnData := rs["data"].(map[string]interface{})
  62. // log.Println(newCount, "加之前")
  63. // newCount += int(returnData["newCount"].(float64))
  64. // log.Println(newCount, "加之后")
  65. // }
  66. //
  67. // }
  68. // if !isFirst {
  69. // delete(v, "_id")
  70. // v["entid"] = entId
  71. // v["userid"] = entUserId
  72. // v["infoid"] = id
  73. // v["createtime"] = time.Now().Unix()
  74. // }
  75. // }
  76. // if len(infoIdList) > 0 {
  77. // rs, err5 := Post(url, map[string]string{
  78. // "personId": "0", // 没有使用这个参数
  79. // "infoId": strings.Join(infoIdList, ","),
  80. // "entId": fmt.Sprintf("%d", entId),
  81. // "isInsert": insertFlag,
  82. // "isEnt": "true",
  83. // })
  84. // log.Println(rs)
  85. // if err5 != nil|| util.IntAll(rs["code"])!=0{
  86. // log.Println("企业订阅数据导出接口判重失败", err5)
  87. // log.Println("企业订阅数据导出接口判重失败rs:",rs)
  88. // log.Println("企业订阅数据导出接口判重失败rs[code]:",rs["code"])
  89. // log.Println("企业订阅数据导出接口判重失败code是否为0",util.IntAll(rs["code"])!=0)
  90. // log.Println("企业订阅数据导出接口判重失败", err5,"rs:",rs," rs[code]:",rs["code"]," ",util.IntAll(rs["code"]),"code是否为0",util.IntAll(rs["code"])!=0)
  91. // } else {
  92. // log.Println("企业订阅数据导出")
  93. // // 置空
  94. // infoIdList = []string{}
  95. // // 本次数据累计
  96. // returnData := rs["data"].(map[string]interface{})
  97. // log.Println(newCount, "加之前")
  98. // newCount += int(returnData["newCount"].(float64))
  99. // log.Println(newCount, "加之后")
  100. //
  101. // }
  102. // }
  103. // searchsWaitGroup.Wait()
  104. // log.Println("企业数据导出--数据遍历完成")
  105. // //newCount = len(newCountPool)
  106. // log.Println("new", newCount)
  107. // data = res
  108. // return
  109. //}
  110. //
  111. //func FormatExportDatas(data *[]map[string]interface{}, webdomain string, dataType string, entId int) *[]map[string]interface{} {
  112. // //格式化输出
  113. // var (
  114. // entexportPool = make(chan bool, 20)
  115. // entexportWaitGroup = &sync.WaitGroup{}
  116. // )
  117. // log.Println("补充信息开始")
  118. // for _, v := range *data {
  119. // entexportWaitGroup.Add(1)
  120. // entexportPool <- true
  121. // go func(v map[string]interface{}) {
  122. // defer func() {
  123. // entexportWaitGroup.Done()
  124. // <-entexportPool
  125. // }()
  126. // //有中标企业 且 高级字段查询
  127. // if dataType == "2" {
  128. // //查询企业公示 法人 公司电话 公司邮箱地址
  129. // s_winner := strings.Split(util.ObjToString(v["s_winner"]), ",")[0]
  130. // if entData, ok := Mgo_Ent.Find("winner_enterprise", bson.M{"company_name": s_winner}, nil,
  131. // `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
  132. // if entData != nil && *entData != nil && len(*entData) > 0 {
  133. // for _, ev := range *entData {
  134. // if v["s_winner"] == ev["company_name"] {
  135. // legal_person := ""
  136. // if ev["legal_person"] != nil {
  137. // legal_person = ev["legal_person"].(string)
  138. // }
  139. // company_phone := ""
  140. // if ev["company_phone"] != nil {
  141. // company_phone = ev["company_phone"].(string)
  142. // }
  143. // company_email := ""
  144. // if ev["company_email"] != nil && ev["company_email"] != "无" {
  145. // company_email = ev["company_email"].(string)
  146. // }
  147. // v["legal_person"] = legal_person
  148. // v["company_phone"] = company_phone
  149. // v["company_email"] = company_email
  150. // }
  151. // }
  152. // }
  153. // }
  154. // }
  155. // //====================字段补漏=========================
  156. // if v["toptype"] == "结果" && dataType == "2" && !(v["agency"] != nil && v["budget"] != nil && v["buyerperson"] != nil && v["buyertel"] != nil) {
  157. // r := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query":{"term":{"list.infoid":"%s"}},"_source": ["list"]}`, v["_id"]))
  158. // if len(*r) > 0 {
  159. // MsgList := (*r)[0]["list"]
  160. // if MsgList != nil {
  161. // list := util.ObjArrToMapArr(MsgList.([]interface{}))
  162. // for _, vv := range list {
  163. // if vv["subtype"] == "招标" {
  164. // if v["agency"] == nil && vv["agency"] != nil {
  165. // v["agency"] = vv["agency"]
  166. // }
  167. // if v["budget"] == nil && vv["budget"] != nil {
  168. // v["budget"] = vv["budget"]
  169. // }
  170. // if v["buyerperson"] == nil && vv["buyerperson"] != nil {
  171. // v["buyerperson"] = vv["buyerperson"]
  172. // }
  173. // if v["buyertel"] == nil && vv["buyertel"] != nil {
  174. // v["buyertel"] = vv["buyertel"]
  175. // }
  176. // break
  177. // }
  178. // }
  179. // }
  180. // }
  181. // }
  182. // if v["area"] == "A" {
  183. // v["area"] = "全国"
  184. // }
  185. // if v["publishtime"] != nil {
  186. // date := v["publishtime"]
  187. // v["publishtime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
  188. // }
  189. // if v["bidopentime"] != nil {
  190. // date := v["bidopentime"]
  191. // v["bidopentime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
  192. // }
  193. // if v["currency"] == "" || v["currency"] == nil {
  194. // v["currency"] = "人民币"
  195. // }
  196. // if v["subtype"] == nil && v["toptype"] != nil {
  197. // v["subtype"] = v["toptype"]
  198. // }
  199. // if v["detail"] != "" && v["detail"] != nil {
  200. // str := ClearHtml.ReplaceAllString(v["detail"].(string), "")
  201. // str = ClearOther.ReplaceAllString(str, "")
  202. // str = strings.Replace(str, " ", "", -1)
  203. // v["detail"] = str
  204. // }
  205. // if v["_id"] != nil {
  206. // v["url"] = webdomain + "/article/content/" + util.CommonEncodeArticle("content", v["_id"].(string)) + ".html"
  207. // }
  208. // }(v)
  209. // }
  210. // entexportWaitGroup.Wait()
  211. // log.Println("补充信息结束")
  212. // return data
  213. //}
  214. //func GetDataExportSearchResult(id string, dataType string, checkCount int) (*[]map[string]interface{}, error) {
  215. // defer util.Catch()
  216. // var (
  217. // onceSearchCount = 500
  218. // searchPool = make(chan bool, 20)
  219. // res []map[string]interface{}
  220. // )
  221. // //获取查询语句
  222. // scd := dataexport.GetSqlObjFromId(MQFW, id)
  223. // if scd == nil {
  224. // return nil, errors.New("GetDataExportSearchResult-获取查询条件")
  225. // }
  226. // qstr := getDataExportSql(scd)
  227. // log.Printf("GetDataExportSearchResult-%s-sql:%s\n", scd.Id, qstr)
  228. // //数据导出数据查询
  229. // if checkCount > onceSearchCount { //分批次查询
  230. // batchNum := util.IntAll(math.Ceil(float64(checkCount) / float64(onceSearchCount)))
  231. // var searchWaitGroup = &sync.WaitGroup{}
  232. // var lock sync.Mutex
  233. // for n := 0; n < batchNum; n++ {
  234. // searchWaitGroup.Add(1)
  235. // searchPool <- true
  236. // go func(start int) {
  237. // defer func() {
  238. // searchWaitGroup.Done()
  239. // <-searchPool
  240. // }()
  241. // checkNum, checkOk := onceSearchCount, false
  242. // if start == (batchNum - 1) {
  243. // if checkCount%onceSearchCount != 0 {
  244. // checkNum = checkCount % onceSearchCount
  245. // }
  246. // }
  247. //
  248. // var tmp *[]map[string]interface{}
  249. // for i := 0; i < 3; i++ {
  250. // tmp = doSearch(qstr, start*onceSearchCount, onceSearchCount, dataType)
  251. // if tmp != nil && (len(*tmp) == checkNum) { //校验数据量是否够
  252. // checkOk = true
  253. // break
  254. // }
  255. // }
  256. // if tmp == nil {
  257. // log.Printf("GetDataExportSearchResult-%s-第%d页数据查询结果为空\n", scd.Id, start+1)
  258. // return
  259. // }
  260. // if checkOk {
  261. // log.Printf("GetDataExportSearchResult-%s-第%d页数据加载完成,共%d条\n", scd.Id, start+1, len(*tmp))
  262. // } else {
  263. // log.Printf("GetDataExportSearchResult-%s-第%d页数据加载异常,共%d条,预期%d条\n", scd.Id, start+1, len(*tmp), checkNum)
  264. // }
  265. // lock.Lock()
  266. // res = append(res, *tmp...)
  267. // lock.Unlock()
  268. // }(n)
  269. // }
  270. // searchWaitGroup.Wait()
  271. // log.Printf("GetDataExportSearchResult-%s-分批次加载数据总量为%d\n", scd.Id, len(res))
  272. // } else {
  273. // tmp := doSearch(qstr, 0, checkCount, dataType)
  274. // if tmp == nil || len(*tmp) == 0 {
  275. // log.Printf("GetDataExportSearchResult-%s-一次性加载数据异常\n", scd.Id)
  276. // } else {
  277. // res = *tmp
  278. // log.Printf("GetDataExportSearchResult-%s-一次性加载数据总量为%d\n", scd.Id, len(res))
  279. // }
  280. // }
  281. // //超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
  282. // if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) {
  283. // if len(scd.Keyword) != 0 {
  284. // num := len(res)
  285. // searchTextSize := 0
  286. // if len(scd.Keyword) > 0 {
  287. // searchTextSize = len([]rune(scd.Keyword[0].Keyword))
  288. // }
  289. // if searchTextSize > 3 && num < 50 {
  290. // secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
  291. // scd.Keyword[0].Keyword = secondKWS
  292. // scd.SelectType = "title"
  293. // qstr = getDataExportSql(scd)
  294. // log.Printf("GetDataExportSearchResult-%s-分词查询-sql:%s\n", scd.Id, qstr)
  295. // res2 := doSearch(qstr, 0, 100, "")
  296. // res = *delRepeatMapArr(&res, res2)
  297. // if len(res) > 100 {
  298. // res = res[:100]
  299. // }
  300. // }
  301. // }
  302. // }
  303. // //校验数量
  304. // if checkCount != len(res) {
  305. // return nil, fmt.Errorf("GetDataExportSearchResult-%s-数据总量校验异常,期望:%d,实际:%d", scd.Id, checkCount, len(res))
  306. // //发邮件
  307. // }
  308. // return &res, nil
  309. //}
  310. //func Post(url string, form map[string]string) (data map[string]interface{}, err error) {
  311. // str := ""
  312. // for k, v := range form {
  313. // str += "&" + k + "=" + v
  314. // }
  315. // //log.Println(str)
  316. // res, err1 := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
  317. // log.Println(res)
  318. // if err1 != nil {
  319. // log.Println("post err:", err1.Error())
  320. // return nil, err1
  321. //
  322. // } else if res.Body != nil {
  323. // defer res.Body.Close()
  324. // bs, _ := ioutil.ReadAll(res.Body)
  325. // err2 := json.Unmarshal(bs, &data)
  326. // if err2 != nil {
  327. // return nil, err2
  328. // }
  329. //
  330. // }
  331. // return data, nil
  332. //}