test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. package extract
  2. import (
  3. "data_ai/clean"
  4. "data_ai/prompt"
  5. "data_ai/ul"
  6. "fmt"
  7. log "github.com/donnie4w/go-logger/logger"
  8. new_xlsx "github.com/tealeg/xlsx/v3"
  9. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  10. "os"
  11. "strings"
  12. "sync"
  13. "unicode/utf8"
  14. )
  15. func TestSingleFieldInfo(name string, tmpid string) {
  16. tmp := ul.BidMgo.FindById(name, tmpid)
  17. if len(tmp) == 0 || tmp == nil {
  18. log.Debug("未查询到数据...", tmpid)
  19. return
  20. }
  21. data := ResolveInfo(tmp)
  22. //最终结果...
  23. for k, v := range data {
  24. log.Debug(k, "~", v)
  25. }
  26. }
  27. // 导出需要修复的
  28. func TestFullJinOrCodeInfo() {
  29. q := map[string]interface{}{}
  30. pool_mgo := make(chan bool, 20)
  31. wg_mgo := &sync.WaitGroup{}
  32. sess := ul.SourceMgo.GetMgoConn()
  33. defer ul.SourceMgo.DestoryMongoConn(sess)
  34. total := 0
  35. it := sess.DB(ul.SourceMgo.DbName).C("result_20220218").Find(&q).Sort("_id").Iter()
  36. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  37. if total%10000 == 0 {
  38. log.Debug("cur index ", total)
  39. }
  40. pool_mgo <- true
  41. wg_mgo.Add(1)
  42. go func(tmp map[string]interface{}) {
  43. defer func() {
  44. <-pool_mgo
  45. wg_mgo.Done()
  46. }()
  47. tmpid := ul.BsonTOStringId(tmp["_id"])
  48. isPcode, update := false, map[string]interface{}{}
  49. ext_ai_record := qu.ObjToMap(tmp["ext_ai_record"])
  50. o_projectcode, o_budget, o_bidamount := "", 0.0, 0.0
  51. if ext_ai_record != nil {
  52. o_projectcode = qu.ObjToString((*ext_ai_record)["projectcode"])
  53. o_budget = qu.Float64All((*ext_ai_record)["budget"])
  54. o_bidamount = qu.Float64All((*ext_ai_record)["bidamount"])
  55. }
  56. if r_budget := qu.Float64All(tmp["budget"]); r_budget > 0.0 && o_budget > 0.0 && r_budget < 1000000000.0 {
  57. if r_budget/o_budget == 10000.0 || o_budget/r_budget == 10000.0 {
  58. update["budget"] = filterAmount(r_budget, o_budget)
  59. }
  60. }
  61. if r_bidamount := qu.Float64All(tmp["bidamount"]); r_bidamount > 0.0 && o_bidamount > 0.0 && r_bidamount < 1000000000.0 {
  62. if r_bidamount/o_bidamount == 10000.0 || o_bidamount/r_bidamount == 10000.0 {
  63. update["bidamount"] = filterAmount(r_bidamount, o_bidamount)
  64. }
  65. }
  66. //对于编号
  67. if projectcode := qu.ObjToString(tmp["projectcode"]); projectcode != "" {
  68. if o_projectcode != projectcode {
  69. if data := ul.SourceMgo.FindById("bidding", tmpid); data != nil {
  70. fns := getpnsinfo(data) //获取附件名字
  71. for _, v := range fns {
  72. if utf8.RuneCountInString(v) >= utf8.RuneCountInString(projectcode) {
  73. if strings.Contains(v, projectcode) {
  74. isPcode = true
  75. break
  76. }
  77. }
  78. }
  79. if isPcode {
  80. update["projectcode"] = o_projectcode
  81. }
  82. }
  83. }
  84. }
  85. if len(update) > 0 {
  86. //更新抽取表
  87. ul.SourceMgo.UpdateById("result_20220218", tmpid, map[string]interface{}{
  88. "$set": update,
  89. })
  90. //保存待修复表
  91. update["_id"] = tmp["_id"]
  92. ul.SourceMgo.Save("zzzzz_kkk_uc_0907", update)
  93. }
  94. }(tmp)
  95. tmp = make(map[string]interface{})
  96. }
  97. wg_mgo.Wait()
  98. log.Debug("repair ai is over ...")
  99. }
  100. // 修复金额和编号
  101. func TestRepairJinOrCodeInfo() {
  102. q := map[string]interface{}{}
  103. pool_mgo := make(chan bool, 20)
  104. wg_mgo := &sync.WaitGroup{}
  105. sess := ul.SourceMgo.GetMgoConn()
  106. defer ul.SourceMgo.DestoryMongoConn(sess)
  107. total := 0
  108. it := sess.DB(ul.SourceMgo.DbName).C("zktest_repeat_new").Find(&q).Sort("_id").Iter()
  109. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  110. if total%10000 == 0 {
  111. log.Debug("cur index ", total)
  112. }
  113. pool_mgo <- true
  114. wg_mgo.Add(1)
  115. go func(tmp map[string]interface{}) {
  116. defer func() {
  117. <-pool_mgo
  118. wg_mgo.Done()
  119. }()
  120. tmpid := ul.BsonTOStringId(tmp["_id"])
  121. isPcode, update := false, map[string]interface{}{}
  122. ext_ai_record := qu.ObjToMap(tmp["ext_ai_record"])
  123. o_projectcode, o_budget, o_bidamount := "", 0.0, 0.0
  124. if ext_ai_record != nil {
  125. o_projectcode = qu.ObjToString((*ext_ai_record)["projectcode"])
  126. o_budget = qu.Float64All((*ext_ai_record)["budget"])
  127. o_bidamount = qu.Float64All((*ext_ai_record)["bidamount"])
  128. }
  129. if r_budget := qu.Float64All(tmp["budget"]); r_budget > 0.0 && o_budget > 0.0 && r_budget < 1000000000.0 {
  130. if r_budget/o_budget == 10000.0 || o_budget/r_budget == 10000.0 {
  131. update["budget"] = filterAmount(r_budget, o_budget)
  132. }
  133. }
  134. if r_bidamount := qu.Float64All(tmp["bidamount"]); r_bidamount > 0.0 && o_bidamount > 0.0 && r_bidamount < 1000000000.0 {
  135. if r_bidamount/o_bidamount == 10000.0 || o_bidamount/r_bidamount == 10000.0 {
  136. update["bidamount"] = filterAmount(r_bidamount, o_bidamount)
  137. }
  138. }
  139. //对于编号
  140. if projectcode := qu.ObjToString(tmp["projectcode"]); projectcode != "" {
  141. if o_projectcode != projectcode {
  142. if data := ul.SourceMgo.FindById("bidding", tmpid); data != nil {
  143. fns := getpnsinfo(data) //获取附件名字
  144. for _, v := range fns {
  145. if utf8.RuneCountInString(v) >= utf8.RuneCountInString(projectcode) {
  146. if strings.Contains(v, projectcode) {
  147. isPcode = true
  148. break
  149. }
  150. }
  151. }
  152. if isPcode {
  153. update["projectcode"] = o_projectcode
  154. }
  155. }
  156. }
  157. }
  158. if len(update) > 0 {
  159. ul.SourceMgo.UpdateById("zktest_repeat_new", tmpid, map[string]interface{}{
  160. "$set": update,
  161. })
  162. }
  163. }(tmp)
  164. tmp = make(map[string]interface{})
  165. }
  166. wg_mgo.Wait()
  167. log.Debug("repair ai is over ...")
  168. }
  169. // 筛选金额
  170. func filterAmount(f1 float64, f2 float64) float64 {
  171. //选取一个合适的金额 ...
  172. if f1 > f2 {
  173. if f1 > 100000000.0 {
  174. return f2
  175. } else {
  176. return f1
  177. }
  178. } else if f1 < f2 {
  179. if f2 > 100000000.0 {
  180. return f1
  181. } else {
  182. return f2
  183. }
  184. } else {
  185. return f1
  186. }
  187. }
  188. func TestExportJinErInfo() {
  189. q := map[string]interface{}{}
  190. pool_mgo := make(chan bool, 20)
  191. wg_mgo := &sync.WaitGroup{}
  192. sess := ul.SourceMgo.GetMgoConn()
  193. defer ul.SourceMgo.DestoryMongoConn(sess)
  194. total, isok := 0, 0
  195. it := sess.DB(ul.SourceMgo.DbName).C("result_20220218").Find(&q).Sort("_id").Iter()
  196. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  197. if total%10000 == 0 {
  198. log.Debug("cur index ", total)
  199. }
  200. isok++
  201. pool_mgo <- true
  202. wg_mgo.Add(1)
  203. go func(tmp map[string]interface{}) {
  204. defer func() {
  205. <-pool_mgo
  206. wg_mgo.Done()
  207. }()
  208. tmpid := ul.BsonTOStringId(tmp["_id"])
  209. budget := qu.Float64All(tmp["budget"])
  210. bidamount := qu.Float64All(tmp["bidamount"])
  211. saveinfo := map[string]interface{}{}
  212. if ext_ai_record := qu.ObjToMap(tmp["ext_ai_record"]); ext_ai_record != nil {
  213. ext_budget := qu.Float64All((*ext_ai_record)["budget"])
  214. ext_bidamount := qu.Float64All((*ext_ai_record)["bidamount"])
  215. if budget > 0.0 && ext_budget > 0.0 {
  216. if budget/ext_budget == 10000.0 || ext_budget/budget == 10000.0 {
  217. saveinfo["budget"] = budget
  218. saveinfo["ext_budget"] = ext_budget
  219. }
  220. }
  221. if bidamount > 0.0 && ext_bidamount > 0.0 {
  222. if bidamount/ext_bidamount == 10000.0 || ext_bidamount/bidamount == 10000.0 {
  223. saveinfo["bidamount"] = bidamount
  224. saveinfo["ext_bidamount"] = ext_bidamount
  225. }
  226. }
  227. }
  228. if len(saveinfo) > 0 && tmpid != "" {
  229. saveinfo["toptype"] = tmp["toptype"]
  230. saveinfo["subtype"] = tmp["subtype"]
  231. saveinfo["href"] = tmp["href"]
  232. saveinfo["jyhref"] = tmp["jytest_href"]
  233. ul.SourceMgo.Save("zktest_zzzzzkkk_0903", saveinfo)
  234. }
  235. }(tmp)
  236. tmp = make(map[string]interface{})
  237. }
  238. wg_mgo.Wait()
  239. log.Debug("repair ai is over ...", isok)
  240. }
  241. // 修正buyer等字段
  242. func TestRepairBuyerInfo(name string) {
  243. q := map[string]interface{}{}
  244. pool_mgo := make(chan bool, 20)
  245. wg_mgo := &sync.WaitGroup{}
  246. sess := ul.SourceMgo.GetMgoConn()
  247. defer ul.SourceMgo.DestoryMongoConn(sess)
  248. total, isok := 0, 0
  249. it := sess.DB(ul.SourceMgo.DbName).C("zktest_repeat_new").Find(&q).Sort("_id").Iter()
  250. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  251. if total%10000 == 0 {
  252. log.Debug("cur index ", total)
  253. }
  254. isok++
  255. pool_mgo <- true
  256. wg_mgo.Add(1)
  257. go func(tmp map[string]interface{}) {
  258. defer func() {
  259. <-pool_mgo
  260. wg_mgo.Done()
  261. }()
  262. tmpid := ul.BsonTOStringId(tmp["_id"])
  263. buyer := qu.ObjToString(tmp["buyer"])
  264. agency := qu.ObjToString(tmp["agency"])
  265. winner := qu.ObjToString(tmp["winner"])
  266. update := map[string]interface{}{}
  267. if ext_ai_record := qu.ObjToMap(tmp["ext_ai_record"]); ext_ai_record != nil {
  268. o_buyer := qu.ObjToString((*ext_ai_record)["buyer"])
  269. if buyer == agency && o_buyer != "" {
  270. update["buyer"] = o_buyer
  271. }
  272. o_winner := qu.ObjToString((*ext_ai_record)["winner"])
  273. if o_winner != "" && strings.Contains(winner, o_winner) && o_winner != o_winner {
  274. update["winner"] = o_winner
  275. }
  276. }
  277. if len(update) > 0 && tmpid != "" {
  278. ul.SourceMgo.UpdateById("zktest_repeat_new", tmpid, map[string]interface{}{
  279. "$set": update,
  280. })
  281. }
  282. }(tmp)
  283. tmp = make(map[string]interface{})
  284. }
  285. wg_mgo.Wait()
  286. log.Debug("repair ai is over ...", isok)
  287. }
  288. func TestDelUpBuyerAi() {
  289. dataArr, _ := ul.SourceMgo.Find("zktest_buyer_0828_new", map[string]interface{}{}, nil, nil)
  290. pool_mgo := make(chan bool, 50)
  291. wg_mgo := &sync.WaitGroup{}
  292. for k, v := range dataArr {
  293. if k%1000 == 0 {
  294. log.Debug(k, "~", v["_id"])
  295. }
  296. pool_mgo <- true
  297. wg_mgo.Add(1)
  298. go func(v map[string]interface{}) {
  299. defer func() {
  300. <-pool_mgo
  301. wg_mgo.Done()
  302. }()
  303. buyer := qu.ObjToString(v["buyer"])
  304. tmpid := ul.BsonTOStringId(v["_id"])
  305. data1 := ul.SourceMgo.FindById("result_20220218", tmpid)
  306. if len(data1) > 0 {
  307. ul.SourceMgo.UpdateById("result_20220218", tmpid, map[string]interface{}{
  308. "$set": map[string]interface{}{"buyer": buyer},
  309. })
  310. }
  311. data2 := ul.SourceMgo.FindById("result_20220219", tmpid)
  312. if len(data2) > 0 {
  313. ul.SourceMgo.UpdateById("result_20220219", tmpid, map[string]interface{}{
  314. "$set": map[string]interface{}{"buyer": buyer},
  315. })
  316. }
  317. }(v)
  318. }
  319. wg_mgo.Wait()
  320. log.Debug("del ai is over ...")
  321. }
  322. func TestAiBuyerInfo() {
  323. //dataArr, _ := ul.SourceMgo.Find("zktest_buyer_info", map[string]interface{}{}, nil, nil)
  324. q := map[string]interface{}{}
  325. pool_mgo := make(chan bool, 50)
  326. wg_mgo := &sync.WaitGroup{}
  327. sess := ul.SourceMgo.GetMgoConn()
  328. defer ul.SourceMgo.DestoryMongoConn(sess)
  329. total, isok := 0, 0
  330. it := sess.DB(ul.SourceMgo.DbName).C("zktest_repeat_new").Find(&q).Sort("_id").Iter()
  331. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  332. if total%1000 == 0 {
  333. log.Debug("cur index ", total)
  334. }
  335. isok++
  336. pool_mgo <- true
  337. wg_mgo.Add(1)
  338. go func(tmp map[string]interface{}) {
  339. defer func() {
  340. <-pool_mgo
  341. wg_mgo.Done()
  342. }()
  343. tmpid := ul.BsonTOStringId(tmp["_id"])
  344. if buyer := qu.ObjToString(tmp["buyer"]); buyer != "" {
  345. if zp_buyer := prompt.AcquireBuyerInfo(buyer); zp_buyer["实体单位"] != nil {
  346. if ns_buyer := clean.CleanBuyer(qu.ObjToString(zp_buyer["实体单位"])); ns_buyer != "" {
  347. ul.SourceMgo.UpdateById("zktest_repeat_new", tmpid, map[string]interface{}{
  348. "$set": map[string]interface{}{"buyer": ns_buyer},
  349. })
  350. }
  351. }
  352. }
  353. }(tmp)
  354. tmp = make(map[string]interface{})
  355. }
  356. wg_mgo.Wait()
  357. log.Debug("repair ai is over ...", isok)
  358. }
  359. func TestExportAiBuyer() {
  360. sess := ul.SourceMgo.GetMgoConn()
  361. defer ul.SourceMgo.DestoryMongoConn(sess)
  362. pool_mgo := make(chan bool, 10)
  363. wg_mgo := &sync.WaitGroup{}
  364. q, total := map[string]interface{}{
  365. "_id": map[string]interface{}{
  366. "$lte": ul.StringTOBsonId("66cd8299b25c3e1deb9488dd"),
  367. },
  368. }, 0
  369. it := sess.DB(ul.SourceMgo.DbName).C("result_20220218").Find(&q).Sort("_id").Select(map[string]interface{}{
  370. "ai_zhipu": 1,
  371. "ext_ai_record": 1,
  372. }).Iter()
  373. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  374. if total%10000 == 0 {
  375. log.Debug("cur index ", total, "~", tmp["_id"])
  376. }
  377. pool_mgo <- true
  378. wg_mgo.Add(1)
  379. go func(tmp map[string]interface{}) {
  380. defer func() {
  381. <-pool_mgo
  382. wg_mgo.Done()
  383. }()
  384. ai_buyer, ext_buyer := "", ""
  385. if ai_zhipu := qu.ObjToMap(tmp["ai_zhipu"]); ai_zhipu != nil {
  386. ai_buyer = qu.ObjToString((*ai_zhipu)["s_buyer"])
  387. }
  388. if ext_ai_record := qu.ObjToMap(tmp["ext_ai_record"]); ext_ai_record != nil {
  389. ext_buyer = qu.ObjToString((*ext_ai_record)["buyer"])
  390. }
  391. if ai_buyer != "" {
  392. ul.SourceMgo.Save("zktest_buyer_0827", map[string]interface{}{
  393. "_id": tmp["_id"],
  394. "ai_buyer": ai_buyer,
  395. "ext_buyer": ext_buyer,
  396. })
  397. }
  398. }(tmp)
  399. tmp = make(map[string]interface{})
  400. }
  401. wg_mgo.Wait()
  402. log.Debug("export is over ", total)
  403. }
  404. func TestIsPackage() {
  405. tmpArr := []string{
  406. "669e83fe66cf0db42a6520b3",
  407. "669e892066cf0db42a652c9b",
  408. "669e904966cf0db42a653b5d",
  409. "669f16f466cf0db42a669069",
  410. "669f186c66cf0db42a669bf0",
  411. "669efb6766cf0db42a65e0b4",
  412. "669f004266cf0db42a65f201",
  413. "669f02a666cf0db42a65fff3",
  414. "669f172766cf0db42a669193",
  415. "669ec89566cf0db42a659020",
  416. "669e86b266cf0db42a6526ac",
  417. "669e86e466cf0db42a6527b7",
  418. "669e87b766cf0db42a652a3e",
  419. "669f082d66cf0db42a662323",
  420. "669e95e966cf0db42a654dd1",
  421. "669ea39466cf0db42a656311",
  422. "669f140366cf0db42a66772f",
  423. "669ee59466cf0db42a65b8aa",
  424. "669f05a166cf0db42a66117b",
  425. "669e90d666cf0db42a653e0a",
  426. "669f08c466cf0db42a66273c",
  427. "669f155166cf0db42a6682c7",
  428. "669ef0ff66cf0db42a65c83a",
  429. "669efdc166cf0db42a65e8f3",
  430. "669f090066cf0db42a6629d0",
  431. "669f111366cf0db42a665ce7",
  432. "669f15fb66cf0db42a668901",
  433. "669f0baa66cf0db42a663a72",
  434. "669f039766cf0db42a66044e",
  435. "669eff3e66cf0db42a65ee73",
  436. "669f12c366cf0db42a666b9d",
  437. "669e913b66cf0db42a653ffc",
  438. "669e833466cf0db42a651e3a",
  439. "669f071e66cf0db42a661b03",
  440. "669f1a1266cf0db42a66a892",
  441. "669f0aec66cf0db42a6635e8",
  442. "669f169c66cf0db42a668e1d",
  443. "669ed6c966cf0db42a65a75d",
  444. "669f072866cf0db42a661b26",
  445. "669f185866cf0db42a669af0",
  446. "669f15d366cf0db42a6687aa",
  447. "669f182466cf0db42a669960",
  448. "669f0ed066cf0db42a664e5c",
  449. "669f076466cf0db42a661cd4",
  450. "669f172966cf0db42a6691c0",
  451. "669f198466cf0db42a66a385",
  452. "669f1ad366cf0db42a66afb9",
  453. "669f156666cf0db42a668403",
  454. "669f093c66cf0db42a662c08",
  455. "669f0d8266cf0db42a6646cb",
  456. "669f06e866cf0db42a661a1d",
  457. "669f1bd766cf0db42a66b86e",
  458. "669efcd066cf0db42a65e4f4",
  459. }
  460. pkgArr := []int{
  461. 1,
  462. 1,
  463. 1,
  464. 1,
  465. 0,
  466. 1,
  467. 1,
  468. 1,
  469. 1,
  470. 1,
  471. 1,
  472. 1,
  473. 1,
  474. 0,
  475. 0,
  476. 1,
  477. 1,
  478. 1,
  479. 1,
  480. 1,
  481. 0,
  482. 0,
  483. 0,
  484. 1,
  485. 0,
  486. 0,
  487. 0,
  488. 1,
  489. 0,
  490. 1,
  491. 0,
  492. 0,
  493. 1,
  494. 0,
  495. 1,
  496. 0,
  497. 1,
  498. 1,
  499. 0,
  500. 1,
  501. 0,
  502. 0,
  503. 1,
  504. 1,
  505. 1,
  506. 1,
  507. 1,
  508. 1,
  509. 0,
  510. 1,
  511. 1,
  512. 0,
  513. 1,
  514. }
  515. ok := 0
  516. for k, v := range tmpArr {
  517. data := ul.SourceMgo.FindById("ai_41411", v)
  518. if len(data) == 0 {
  519. data = ul.SourceMgo.FindById("ai_294", v)
  520. }
  521. detail := qu.ObjToString(data["detail"])
  522. ispkg := prompt.AcquireIsPackageInfo(detail)
  523. if (ispkg && pkgArr[k] == 1) || (!ispkg && pkgArr[k] == 0) {
  524. ok++
  525. } else {
  526. log.Debug("错误~", v)
  527. }
  528. }
  529. log.Debug("is over ~ ", len(tmpArr)-ok)
  530. }
  531. func TestPackageInfo() {
  532. query := map[string]interface{}{
  533. "new_pkg": map[string]interface{}{
  534. "$exists": 1,
  535. },
  536. }
  537. dataArr, _ := ul.SourceMgo.Find("ai_41411_zhipu", query, nil, map[string]interface{}{})
  538. log.Debug("查询数量...", len(dataArr))
  539. os.Remove("test.xlsx")
  540. f := new_xlsx.NewFile()
  541. sheet, _ := f.AddSheet("数据信息")
  542. row := sheet.AddRow()
  543. writeRow(row, []string{"唯一标识", "站点", "剑鱼链接", "子包名称", "子包单位", "子包金额"})
  544. for _, v := range dataArr {
  545. tmpid := ul.BsonTOStringId(v["_id"])
  546. ttt := ul.SourceMgo.FindById("ai_41411", tmpid)
  547. site := qu.ObjToString(ttt["site"])
  548. jyhref := fmt.Sprintf(ul.Url, qu.CommonEncodeArticle("content", tmpid))
  549. p_info := *qu.ObjToMap(v["new_pkg"])
  550. p_arr := ul.IsMarkInterfaceMap(p_info["分包信息"])
  551. for _, v1 := range p_arr {
  552. row = sheet.AddRow()
  553. arr := []string{}
  554. arr = append(arr, tmpid)
  555. arr = append(arr, site)
  556. arr = append(arr, jyhref)
  557. arr = append(arr, qu.ObjToString(v1["包项目名称"]))
  558. arr = append(arr, qu.ObjToString(v1["中标单位"]))
  559. arr = append(arr, qu.ObjToString(v1["中标金额"]))
  560. writeRow(row, arr)
  561. }
  562. }
  563. if err := f.Save("test.xlsx"); err != nil {
  564. fmt.Println("保存xlsx失败:", err)
  565. } else {
  566. fmt.Println("保存xlsx成功:", err)
  567. }
  568. log.Debug("is over ...")
  569. return
  570. //分包判断,获取信息
  571. pool_mgo := make(chan bool, 80)
  572. wg_mgo := &sync.WaitGroup{}
  573. for k, v := range dataArr {
  574. if k%10 == 0 {
  575. log.Debug(k, "~", v["_id"])
  576. }
  577. pool_mgo <- true
  578. wg_mgo.Add(1)
  579. go func(v map[string]interface{}) {
  580. defer func() {
  581. <-pool_mgo
  582. wg_mgo.Done()
  583. }()
  584. tmpid := ul.BsonTOStringId(v["_id"])
  585. data := ul.SourceMgo.FindById("ai_41411", tmpid)
  586. if detail := qu.ObjToString(data["detail"]); utf8.RuneCountInString(detail) > 100 {
  587. pkg := prompt.AcquireMultiplePackageInfo(detail)
  588. //最终结果...
  589. ul.SourceMgo.UpdateById("ai_41411_zhipu", tmpid, map[string]interface{}{
  590. "$set": map[string]interface{}{
  591. "new_pkg": pkg,
  592. },
  593. })
  594. }
  595. }(v)
  596. }
  597. wg_mgo.Wait()
  598. }
  599. // 更新链接
  600. func TestUpdateJyhref(name string) {
  601. dataArr, _ := ul.SourceMgo.Find(name, map[string]interface{}{}, nil, map[string]interface{}{"_id": 1})
  602. for _, v := range dataArr {
  603. tmpid := ul.BsonTOStringId(v["_id"])
  604. jyhref := fmt.Sprintf(ul.Url, qu.CommonEncodeArticle("content", tmpid))
  605. ul.SourceMgo.UpdateById(name, tmpid, map[string]interface{}{
  606. "$set": map[string]interface{}{
  607. "jyhref": jyhref,
  608. },
  609. })
  610. }
  611. log.Debug("is over ...")
  612. }
  613. func writeRow(row *new_xlsx.Row, arr []string) {
  614. for _, v := range arr {
  615. row.AddCell().Value = v
  616. }
  617. }