xlsx_test.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  6. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  7. "log"
  8. "os"
  9. "strconv"
  10. "strings"
  11. "testing"
  12. "time"
  13. )
  14. func TestA(T *testing.T) {
  15. Mgo := &mongodb.MongodbSim{
  16. //MongodbAddr: "172.17.189.140:27080",
  17. MongodbAddr: "127.0.0.1:27017",
  18. Size: 10,
  19. DbName: "wcc",
  20. //UserName: "SJZY_RWbid_ES",
  21. //Password: "SJZY@B4i4D5e6S",
  22. //Direct: true,
  23. }
  24. Mgo.InitPool()
  25. f, err := excelize.OpenFile("./拼数据.xlsx")
  26. if err != nil {
  27. fmt.Println(err)
  28. return
  29. }
  30. defer func() {
  31. if err := f.Close(); err != nil {
  32. fmt.Println(err)
  33. }
  34. }()
  35. rows, err := f.GetRows("Sheet1")
  36. if err != nil {
  37. fmt.Println(err)
  38. return
  39. }
  40. cells, _ := f.GetCols("Sheet2")
  41. for i := 1; i < len(rows); i++ {
  42. log.Print(rows[i][3])
  43. if rows[i][2] == "省级" {
  44. for k, v := range cells[0] {
  45. if k == 0 || v == "" {
  46. continue
  47. }
  48. insert := make(map[string]interface{})
  49. insert["top"] = rows[i][0]
  50. insert["area"] = rows[i][3]
  51. insert["level"] = rows[i][2]
  52. insert["sub"] = v
  53. insert["name"] = rows[i][3] + v
  54. Mgo.InsertOrUpdate("wcc", "wcc_0313", insert)
  55. }
  56. }
  57. if rows[i][2] == "市级" {
  58. for k, v := range cells[1] {
  59. if k == 0 || v == "" {
  60. continue
  61. }
  62. insert := make(map[string]interface{})
  63. insert["top"] = rows[i][0]
  64. insert["area"] = rows[i][3]
  65. insert["city"] = rows[i][4]
  66. insert["level"] = rows[i][2]
  67. insert["sub"] = v
  68. insert["name"] = rows[i][4] + v
  69. Mgo.InsertOrUpdate("wcc", "wcc_0313", insert)
  70. }
  71. }
  72. if rows[i][2] == "县级" {
  73. for k, v := range cells[2] {
  74. if k == 0 || v == "" {
  75. continue
  76. }
  77. insert := make(map[string]interface{})
  78. insert["top"] = rows[i][0]
  79. insert["area"] = rows[i][3]
  80. insert["city"] = rows[i][4]
  81. insert["district"] = rows[i][5]
  82. insert["level"] = rows[i][2]
  83. insert["sub"] = v
  84. insert["name"] = rows[i][4] + rows[i][5] + v
  85. Mgo.InsertOrUpdate("wcc", "wcc_0313", insert)
  86. }
  87. }
  88. }
  89. fmt.Println("over")
  90. }
  91. func TestA2(T *testing.T) {
  92. Mgo := &mongodb.MongodbSim{
  93. MongodbAddr: "127.0.0.1:27017",
  94. Size: 10,
  95. DbName: "wcc",
  96. }
  97. Mgo.InitPool()
  98. f, err := excelize.OpenFile("./拼数据.xlsx")
  99. if err != nil {
  100. fmt.Println(err)
  101. return
  102. }
  103. defer func() {
  104. if err := f.Close(); err != nil {
  105. fmt.Println(err)
  106. }
  107. }()
  108. rows, err := f.GetRows("Sheet3")
  109. if err != nil {
  110. fmt.Println(err)
  111. return
  112. }
  113. for i := 1; i < len(rows); i++ {
  114. log.Print(rows[i][2])
  115. insert := map[string]interface{}{
  116. "company_name": rows[i][2],
  117. "organizer": rows[i][1],
  118. }
  119. err = Mgo.InsertOrUpdate("wcc", "wcc_henan_gov2", insert)
  120. if err != nil {
  121. log.Println("err", err)
  122. }
  123. }
  124. fmt.Println("over")
  125. }
  126. func TestB(T *testing.T) {
  127. Mgo := &mongodb.MongodbSim{
  128. //MongodbAddr: "172.17.189.140:27080",
  129. MongodbAddr: "127.0.0.1:27083",
  130. Size: 10,
  131. DbName: "qfw",
  132. UserName: "SJZY_RWbid_ES",
  133. Password: "SJZY@B4i4D5e6S",
  134. Direct: true,
  135. }
  136. Mgo.InitPool()
  137. f, err := excelize.OpenFile("./剑鱼标讯_数据导出.xlsx")
  138. if err != nil {
  139. fmt.Println(err)
  140. return
  141. }
  142. defer func() {
  143. if err := f.Close(); err != nil {
  144. fmt.Println(err)
  145. }
  146. }()
  147. rows, err := f.GetRows("Sheet1")
  148. if err != nil {
  149. fmt.Println(err)
  150. return
  151. }
  152. for i := 1; i < len(rows); i++ {
  153. url := rows[i][2]
  154. log.Println(rows[i][1])
  155. id := GetIdByURL(url)
  156. re, _ := Mgo.FindById("bidding", id, nil)
  157. (*re)["wcc_id"] = i
  158. (*re)["toptype_old"] = (*re)["toptype"]
  159. (*re)["subtype_old"] = (*re)["subtype"]
  160. delete(*re, "toptype")
  161. delete(*re, "subtype")
  162. Mgo.SaveByOriID("wcc_bidding_0518", re)
  163. }
  164. log.Println("over")
  165. }
  166. // TestAAA 处理专项债券数据
  167. func TestAAA(t *testing.T) {
  168. //87 竞品
  169. Mgo := &mongodb.MongodbSim{
  170. //MongodbAddr: "172.17.189.140:27080",
  171. MongodbAddr: "127.0.0.1:27081",
  172. Size: 10,
  173. DbName: "py_theme",
  174. UserName: "",
  175. Password: "",
  176. Direct: true,
  177. }
  178. Mgo.InitPool()
  179. sess := Mgo.GetMgoConn()
  180. defer Mgo.DestoryMongoConn(sess)
  181. f, err := excelize.OpenFile("./anhui-08.xlsx")
  182. if err != nil {
  183. fmt.Println(err)
  184. return
  185. }
  186. defer func() {
  187. f.Save()
  188. if err := f.Close(); err != nil {
  189. fmt.Println(err)
  190. }
  191. }()
  192. rows, err := f.GetRows("项目列表")
  193. if err != nil {
  194. fmt.Println(err)
  195. return
  196. }
  197. keys := []string{"projectName", "totalInvestment", "regionName", "cityName", "countyName", "capital", "applyDebt", "portfolioFinancing", "specialDebtAsCapital",
  198. "expectedReturn", "projectCost", "projectTypeName3", "projectSubject", "startDate", "endDate", "operationStartDate",
  199. "operationEndDate", "sourceIncome", "constructionContent", "remarks", "portfolioFinancingSource", "costIncomePercent", "coverageMultiple", "implementingAgency",
  200. "accountingFirm", "lawFirm", "createTime", "updateTime"}
  201. titles := []string{"项目名称", "总投资(万元)", "省份", "地市", "区县", "不含专项债资本金(万元)", "申请专项债总额(万元)", "其他债务融资(万元)", "专项债作资本金(万元)", "预期收入(万元)", "成本",
  202. "项目领域", "项目业主", "建设期开始", "建设期结束", "运营期开始", "运营期结束", "收入来源", "建设内容", "特殊情况备注", "其他债务融资来源", "成本/收入(%)", "覆盖倍数", "主管部门", "会计所", "律所", "入库时间", "更新时间"}
  203. keys2 := []string{"bondName", "bondShortName", "bondNo", "regionName", "bondType1Name", "bondType2Name", "projectType1Name", "totalAmount", "issueDate", "issuePlaceName", "issueTerm", "issueInterestRate", "issuePhase", "payInterestMethodName",
  204. "newBondAmount", "counterBondAmount", "refinancingBondAmount", "redemptionMethod", "valueDate", "expiryDate", "payInterestDate", "latelyPayInterestDate", "lastPayInterest", "cumulativePayInterest"}
  205. titles2 := []string{"项目名称", "债券名称", "债券简称", "债券编码", "省份", "债券性质", "债券类型", "官方项目类型", "发行金额(万元)", "发行日期", "发行场所", "发行期限(年)", "发行利率(%)", "发行期数", "付息方式", "新增债券(亿元)", "置换债券(亿元)", "再融资债券(亿元)", "赎回方式",
  206. "起息日", "到息日", "付息日", "最近付息日", "上期已付息(亿元)", "累计付息(亿元)"}
  207. line := 0
  208. line++
  209. f.NewSheet("项目详情")
  210. f.NewSheet("债券详情")
  211. bondLine := 0
  212. //设置第一行title
  213. _ = f.SetSheetRow("项目详情", fmt.Sprintf("%s%d", "A", line), &titles)
  214. _ = f.SetSheetRow("债券详情", fmt.Sprintf("%s%d", "A", line), &titles2)
  215. //
  216. for i := 1; i < len(rows); i++ {
  217. projectName := rows[i][0]
  218. //projectName := "新建南通至宁波高速铁路(海盐段)"
  219. log.Println(projectName)
  220. line++
  221. where := map[string]interface{}{
  222. "project.jcxx.projectName": projectName,
  223. }
  224. detail, _ := Mgo.FindOne("specialbond_detail_202408", where)
  225. if len(*detail) == 0 {
  226. continue
  227. }
  228. insert := make([]interface{}, 0)
  229. if project, ok := (*detail)["project"].(map[string]interface{}); ok {
  230. if jcxx, ok := project["jcxx"].(map[string]interface{}); ok {
  231. for _, v := range keys {
  232. insert = append(insert, jcxx[v])
  233. }
  234. }
  235. }
  236. err := f.SetSheetRow("项目详情", fmt.Sprintf("%s%d", "A", line), &insert)
  237. if err != nil {
  238. log.Println(err)
  239. return
  240. }
  241. // 债券基本信息
  242. if bonds, ok := (*detail)["bond"].([]interface{}); ok {
  243. for _, bond := range bonds {
  244. if bondData, ok := bond.(map[string]interface{}); ok {
  245. if jcxx, ok := bondData["jbxx"].(map[string]interface{}); ok {
  246. //if strings.Contains(util.ObjToString(jcxx["bondName"]), "2024") {
  247. bondInsert := make([]interface{}, 0)
  248. bondInsert = append(bondInsert, projectName)
  249. for _, v := range keys2 {
  250. bondInsert = append(bondInsert, jcxx[v])
  251. }
  252. bondLine++
  253. f.SetSheetRow("债券详情", fmt.Sprintf("%s%d", "A", line), &bondInsert)
  254. //}
  255. }
  256. }
  257. }
  258. }
  259. }
  260. //query := sess.DB("py_theme").C("specialbond_detail").Find(nil).Select(nil).Iter()
  261. //count := 0
  262. //for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  263. // if count%10000 == 0 {
  264. // log.Println("current:", count)
  265. // }
  266. //
  267. // id := mongodb.BsonIdToSId(tmp["_id"])
  268. // log.Println(id)
  269. //}
  270. }
  271. func TestGetIdByURL(t *testing.T) {
  272. url := "https://www.jianyu360.cn/article/content/AHnY1xBfikoAjYsNGd4cE8JIzAvFj1jcXNlKDhROC4eWlFwA15UCZQ%3D.html"
  273. fmt.Println(GetIdByURL(url))
  274. }
  275. // TestArea 中国行政区划数据-民政部
  276. func TestArea(t *testing.T) {
  277. Mgo := &mongodb.MongodbSim{
  278. //MongodbAddr: "172.17.189.140:27080",
  279. MongodbAddr: "127.0.0.1:27083",
  280. Size: 10,
  281. DbName: "qfw",
  282. UserName: "SJZY_RWbid_ES",
  283. Password: "SJZY@B4i4D5e6S",
  284. Direct: true,
  285. }
  286. Mgo.InitPool()
  287. f, err := excelize.OpenFile("./20240530_民政部统计数据.xlsx")
  288. if err != nil {
  289. fmt.Println(err)
  290. return
  291. }
  292. defer func() {
  293. if err := f.Close(); err != nil {
  294. fmt.Println(err)
  295. }
  296. }()
  297. rows, err := f.GetRows("2023")
  298. if err != nil {
  299. fmt.Println(err)
  300. return
  301. }
  302. for i := 1; i < len(rows); i++ {
  303. data := map[string]interface{}{}
  304. if rows[i][0] == "省份" {
  305. data["level"] = 1
  306. } else if rows[i][0] == "城市" {
  307. data["level"] = 2
  308. } else {
  309. data["level"] = 3
  310. }
  311. log.Println(rows[i][1])
  312. parts := strings.Split(rows[i][1], "(")
  313. data["province"] = parts[0]
  314. data["province_code"] = rows[i][2]
  315. if len(rows[i]) > 3 {
  316. data["city"] = rows[i][3]
  317. }
  318. if len(rows[i]) > 4 {
  319. data["city_code"] = rows[i][4]
  320. }
  321. if len(rows[i]) > 5 {
  322. data["area"] = rows[i][5]
  323. }
  324. if len(rows[i]) > 6 {
  325. data["area_code"] = rows[i][6]
  326. }
  327. Mgo.Save("wcc_area_minzhengbu", data)
  328. }
  329. }
  330. // TestArea2 中国行政区划数据-统计局
  331. func TestArea2(t *testing.T) {
  332. Mgo := &mongodb.MongodbSim{
  333. //MongodbAddr: "172.17.189.140:27080",
  334. MongodbAddr: "127.0.0.1:27083",
  335. Size: 10,
  336. DbName: "qfw",
  337. UserName: "SJZY_RWbid_ES",
  338. Password: "SJZY@B4i4D5e6S",
  339. Direct: true,
  340. }
  341. Mgo.InitPool()
  342. f, err := excelize.OpenFile("./20240530_统计局统计数据.xlsx")
  343. if err != nil {
  344. fmt.Println(err)
  345. return
  346. }
  347. defer func() {
  348. if err := f.Close(); err != nil {
  349. fmt.Println(err)
  350. }
  351. }()
  352. rows, err := f.GetRows("2023")
  353. if err != nil {
  354. fmt.Println(err)
  355. return
  356. }
  357. for i := 1; i < len(rows); i++ {
  358. data := map[string]interface{}{}
  359. data["level"] = rows[i][0]
  360. log.Println(rows[i][1], rows[3])
  361. data["province"] = rows[i][1]
  362. data["province_code"] = rows[i][2]
  363. if len(rows[i]) > 3 {
  364. data["city"] = rows[i][3]
  365. }
  366. if len(rows[i]) > 4 {
  367. data["city_code"] = rows[i][4]
  368. }
  369. if len(rows[i]) > 5 {
  370. data["area"] = rows[i][5]
  371. }
  372. if len(rows[i]) > 6 {
  373. data["area_code"] = rows[i][6]
  374. }
  375. Mgo.Save("wcc_area_tongjiju", data)
  376. }
  377. }
  378. func TestHN(t *testing.T) {
  379. Mgo := &mongodb.MongodbSim{
  380. //MongodbAddr: "172.17.189.140:27080",
  381. MongodbAddr: "127.0.0.1:27083",
  382. Size: 10,
  383. DbName: "qfw",
  384. UserName: "SJZY_RWbid_ES",
  385. Password: "SJZY@B4i4D5e6S",
  386. Direct: true,
  387. }
  388. Mgo.InitPool()
  389. //181
  390. Mgo2 := &mongodb.MongodbSim{
  391. //MongodbAddr: "172.17.4.181:27001",
  392. MongodbAddr: "127.0.0.1:27001",
  393. DbName: "mixdata",
  394. Size: 10,
  395. UserName: "",
  396. Password: "",
  397. Direct: true,
  398. }
  399. Mgo2.InitPool()
  400. f, err := excelize.OpenFile("./河南单位.xlsx")
  401. if err != nil {
  402. fmt.Println(err)
  403. return
  404. }
  405. defer func() {
  406. if err := f.Close(); err != nil {
  407. fmt.Println(err)
  408. }
  409. }()
  410. sheet := "单位"
  411. rows, err := f.GetRows(sheet)
  412. if err != nil {
  413. fmt.Println(err)
  414. return
  415. }
  416. for i := 1; i < len(rows); i++ {
  417. name := rows[i][0]
  418. log.Println(i, "----", name)
  419. //res, _ := Mgo2.FindOne("special_enterprise", map[string]interface{}{"company_name": name})
  420. //if res != nil && len(*res) > 0 {
  421. // f.SetCellValue(sheet, fmt.Sprintf("%s%d", "E", i+1), "special_enterprise")
  422. // f.SetCellValue(sheet, fmt.Sprintf("%s%d", "F", i+1), (*res)["company_status"])
  423. // f.SetCellValue(sheet, fmt.Sprintf("%s%d", "G", i+1), (*res)["company_type"])
  424. //} else {
  425. // ra, _ := Mgo2.FindOne("special_gov_unit", map[string]interface{}{"company_name": name})
  426. // if ra != nil && len(*ra) > 0 {
  427. // f.SetCellValue(sheet, fmt.Sprintf("%s%d", "E", i+1), "special_gov_unit")
  428. // f.SetCellValue(sheet, fmt.Sprintf("%s%d", "G", i+1), (*ra)["company_type"])
  429. // if util.ObjToString((*ra)["company_status"]) != "" {
  430. // f.SetCellValue(sheet, fmt.Sprintf("%s%d", "F", i+1), (*ra)["company_status"])
  431. // } else {
  432. // if util.IntAll((*ra)["use_flag"]) < 5 {
  433. // f.SetCellValue(sheet, fmt.Sprintf("%s%d", "F", i+1), "正常")
  434. // } else {
  435. // f.SetCellValue(sheet, fmt.Sprintf("%s%d", "F", i+1), "废弃")
  436. // }
  437. // }
  438. // }
  439. //}
  440. //
  441. data := map[string]interface{}{
  442. "detail": name,
  443. }
  444. res := getAreaInfo(data)
  445. if res != nil {
  446. city := res["city"]
  447. district := res["district"]
  448. f.SetCellValue("单位", fmt.Sprintf("%s%d", "B", i+1), city)
  449. f.SetCellValue("单位", fmt.Sprintf("%s%d", "C", i+1), district)
  450. }
  451. }
  452. f.Save()
  453. log.Println("结束")
  454. }
  455. // TestExportBidding 导出bidding数据
  456. func TestExportBidding(t *testing.T) {
  457. Mgo := &mongodb.MongodbSim{
  458. //MongodbAddr: "172.17.189.140:27080",
  459. MongodbAddr: "127.0.0.1:27083",
  460. Size: 10,
  461. DbName: "qfw",
  462. UserName: "SJZY_RWbid_ES",
  463. Password: "SJZY@B4i4D5e6S",
  464. Direct: true,
  465. }
  466. Mgo.InitPool()
  467. sess := Mgo.GetMgoConn()
  468. defer Mgo.DestoryMongoConn(sess)
  469. //start, _ := time.Parse("2006-01-02 15:04:05", "2023-09-06 21:00:00")
  470. //end, _ := time.Parse("2006-01-02 15:04:05", "2023-09-07 09:00:00")
  471. //////
  472. //q := map[string]interface{}{
  473. // "publish": map[string]interface{}{
  474. // "$gte": 1701360000,
  475. // "$lte": 1706716800,
  476. // },
  477. // //"modifyinfo.toptype": map[string]interface{}{
  478. // // "$exists": 1,
  479. // //},
  480. // "toptype": "拟建",
  481. // //"title": map[string]interface{}{
  482. // // "$regex": "充电",
  483. // //},
  484. //}
  485. q := map[string]interface{}{
  486. "s_classid": "57a189cbd368081d70e185cf",
  487. "s_name": map[string]interface{}{
  488. "$in": []string{"废标", "流标", "结果变更", "中标", "成交", "中选", "其它"},
  489. },
  490. }
  491. query := sess.DB("qfw").C("rc_rule").Find(q).Select(nil).Iter()
  492. count := 0
  493. file := time.Now().Format("20060102") + "导出数据.xlsx"
  494. currentPwd, _ := os.Getwd()
  495. exportFile := fmt.Sprintf("%s/%s", currentPwd, file)
  496. xlsx := excelize.NewFile(excelize.Options{ShortDatePattern: "yyyy/m/dd"})
  497. styleOne, _ := xlsx.NewStyle(
  498. &excelize.Style{
  499. Alignment: &excelize.Alignment{
  500. Horizontal: "left",
  501. Vertical: "left",
  502. },
  503. },
  504. )
  505. line := 0
  506. sheet := "Sheet1"
  507. subtitles := []string{"s_name", "s_rule"}
  508. //subtitles := []string{"bidding_id", "title", "detail", "href", "jyhref", "toptype", "new_toptype", "new_subtype"}
  509. line++
  510. //设置第一行title
  511. _ = xlsx.SetSheetRow(sheet, fmt.Sprintf("%s%d", "A", line), &subtitles)
  512. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  513. if count%1000 == 0 {
  514. log.Println("current --- ", count)
  515. }
  516. //company_phone := util.ObjToString(tmp["company_phone"])
  517. //if len(company_phone) != 11 {
  518. // continue
  519. //}
  520. //if !validateMobileNumber(company_phone) {
  521. // continue
  522. //}
  523. //if util.ObjToString(tmp["employee_name"]) == "" {
  524. // continue
  525. //}
  526. //id := mongodb.BsonIdToSId(tmp["_id"])
  527. line++
  528. val := []interface{}{}
  529. for _, v := range subtitles {
  530. if v == "employee_name" {
  531. val = append(val, strings.Split(util.ObjToString(tmp["employee_name"]), ",")[0])
  532. } else {
  533. val = append(val, tmp[v])
  534. }
  535. }
  536. err := xlsx.SetSheetRow(sheet, fmt.Sprintf("%s%d", "A", line), &val)
  537. if err != nil {
  538. log.Println(err)
  539. return
  540. }
  541. _ = xlsx.SetCellStyle(sheet, fmt.Sprintf("%s%d", "A", line), "BA"+strconv.Itoa(line), styleOne)
  542. tmp = make(map[string]interface{})
  543. }
  544. xlsx.Path = exportFile
  545. xlsx.Save()
  546. log.Println("dealTmp over ", count)
  547. }
  548. // TestZXZ 专项债数据
  549. func TestZXZ(t *testing.T) {
  550. //87 竞品
  551. Mgo := &mongodb.MongodbSim{
  552. //MongodbAddr: "172.17.189.140:27080",
  553. MongodbAddr: "127.0.0.1:27081",
  554. Size: 10,
  555. DbName: "py_theme",
  556. UserName: "",
  557. Password: "",
  558. Direct: true,
  559. }
  560. Mgo.InitPool()
  561. sess := Mgo.GetMgoConn()
  562. defer Mgo.DestoryMongoConn(sess)
  563. //1.项目列表,查询条件
  564. //where := map[string]interface{}{
  565. // "regionName": "安徽", //地区
  566. // "issueDate": map[string]interface{}{
  567. // "issueDate": map[string]interface{}{
  568. // "$gt": "2024",
  569. // },
  570. // },
  571. //}
  572. //tables := []string{"specialbond_list", "specialbond_list_202406", "specialbond_list_202407", "specialbond_list_202408"}
  573. //for _, table := range tables {
  574. // datas, _ := Mgo.Find(table, where, nil, nil, false, -1, -1)
  575. //
  576. //}
  577. f, err := excelize.OpenFile("./anhui-06.xlsx")
  578. if err != nil {
  579. fmt.Println(err)
  580. return
  581. }
  582. defer func() {
  583. f.Save()
  584. if err := f.Close(); err != nil {
  585. fmt.Println(err)
  586. }
  587. }()
  588. //2.专项债详情
  589. rows, err := f.GetRows("项目列表")
  590. if err != nil {
  591. fmt.Println(err)
  592. return
  593. }
  594. keys := []string{"projectName", "totalInvestment", "regionName", "cityName", "countyName", "capital", "applyDebt", "portfolioFinancing", "specialDebtAsCapital",
  595. "expectedReturn", "projectCost", "projectTypeName3", "projectSubject", "startDate", "endDate", "operationStartDate",
  596. "operationEndDate", "sourceIncome", "constructionContent", "remarks", "portfolioFinancingSource", "costIncomePercent", "coverageMultiple", "implementingAgency",
  597. "accountingFirm", "lawFirm", "createTime", "updateTime"}
  598. titles := []string{"项目名称", "总投资(万元)", "省份", "地市", "区县", "不含专项债资本金(万元)", "申请专项债总额(万元)", "其他债务融资(万元)", "专项债作资本金(万元)", "预期收入(万元)", "成本",
  599. "项目领域", "项目业主", "建设期开始", "建设期结束", "运营期开始", "运营期结束", "收入来源", "建设内容", "特殊情况备注", "其他债务融资来源", "成本/收入(%)", "覆盖倍数", "主管部门", "会计所", "律所", "入库时间", "更新时间"}
  600. keys2 := []string{"bondName", "bondShortName", "bondNo", "regionName", "bondType1Name", "bondType2Name", "projectType1Name", "totalAmount", "issueDate", "issuePlaceName", "issueTerm", "issueInterestRate", "issuePhase", "payInterestMethodName",
  601. "newBondAmount", "counterBondAmount", "refinancingBondAmount", "redemptionMethod", "valueDate", "expiryDate", "payInterestDate", "latelyPayInterestDate", "lastPayInterest", "cumulativePayInterest"}
  602. titles2 := []string{"项目名称", "债券名称", "债券简称", "债券编码", "省份", "债券性质", "债券类型", "官方项目类型", "发行金额(万元)", "发行日期", "发行场所", "发行期限(年)", "发行利率(%)", "发行期数", "付息方式", "新增债券(亿元)", "置换债券(亿元)", "再融资债券(亿元)", "赎回方式",
  603. "起息日", "到息日", "付息日", "最近付息日", "上期已付息(亿元)", "累计付息(亿元)"}
  604. line := 0
  605. line++
  606. f.NewSheet("项目详情")
  607. f.NewSheet("债券详情")
  608. bondLine := 0
  609. //设置第一行title
  610. _ = f.SetSheetRow("项目详情", fmt.Sprintf("%s%d", "A", line), &titles)
  611. _ = f.SetSheetRow("债券详情", fmt.Sprintf("%s%d", "A", line), &titles2)
  612. //
  613. for i := 1; i < len(rows); i++ {
  614. projectName := rows[i][0]
  615. //projectName := "新建南通至宁波高速铁路(海盐段)"
  616. log.Println(projectName)
  617. line++
  618. where := map[string]interface{}{
  619. "project.jcxx.projectName": projectName,
  620. }
  621. detail, _ := Mgo.FindOne("specialbond_detail_202406", where)
  622. if len(*detail) == 0 {
  623. continue
  624. }
  625. insert := make([]interface{}, 0)
  626. if project, ok := (*detail)["project"].(map[string]interface{}); ok {
  627. if jcxx, ok := project["jcxx"].(map[string]interface{}); ok {
  628. for _, v := range keys {
  629. insert = append(insert, jcxx[v])
  630. }
  631. }
  632. }
  633. err := f.SetSheetRow("项目详情", fmt.Sprintf("%s%d", "A", line), &insert)
  634. if err != nil {
  635. log.Println(err)
  636. return
  637. }
  638. // 债券基本信息
  639. if bonds, ok := (*detail)["bond"].([]interface{}); ok {
  640. for _, bond := range bonds {
  641. if bondData, ok := bond.(map[string]interface{}); ok {
  642. if jcxx, ok := bondData["jbxx"].(map[string]interface{}); ok {
  643. //if strings.Contains(util.ObjToString(jcxx["bondName"]), "2024") {
  644. bondInsert := make([]interface{}, 0)
  645. bondInsert = append(bondInsert, projectName)
  646. for _, v := range keys2 {
  647. bondInsert = append(bondInsert, jcxx[v])
  648. }
  649. bondLine++
  650. f.SetSheetRow("债券详情", fmt.Sprintf("%s%d", "A", line), &bondInsert)
  651. }
  652. }
  653. }
  654. }
  655. }
  656. }