xlsx_test.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  6. "log"
  7. "testing"
  8. )
  9. func TestA(T *testing.T) {
  10. Mgo := &mongodb.MongodbSim{
  11. //MongodbAddr: "172.17.189.140:27080",
  12. MongodbAddr: "127.0.0.1:27017",
  13. Size: 10,
  14. DbName: "wcc",
  15. //UserName: "SJZY_RWbid_ES",
  16. //Password: "SJZY@B4i4D5e6S",
  17. //Direct: true,
  18. }
  19. Mgo.InitPool()
  20. f, err := excelize.OpenFile("./拼数据.xlsx")
  21. if err != nil {
  22. fmt.Println(err)
  23. return
  24. }
  25. defer func() {
  26. if err := f.Close(); err != nil {
  27. fmt.Println(err)
  28. }
  29. }()
  30. rows, err := f.GetRows("Sheet1")
  31. if err != nil {
  32. fmt.Println(err)
  33. return
  34. }
  35. cells, _ := f.GetCols("Sheet2")
  36. for i := 1; i < len(rows); i++ {
  37. log.Print(rows[i][3])
  38. if rows[i][2] == "省级" {
  39. for k, v := range cells[0] {
  40. if k == 0 || v == "" {
  41. continue
  42. }
  43. insert := make(map[string]interface{})
  44. insert["top"] = rows[i][0]
  45. insert["area"] = rows[i][3]
  46. insert["level"] = rows[i][2]
  47. insert["sub"] = v
  48. insert["name"] = rows[i][3] + v
  49. Mgo.InsertOrUpdate("wcc", "wcc_0313", insert)
  50. }
  51. }
  52. if rows[i][2] == "市级" {
  53. for k, v := range cells[1] {
  54. if k == 0 || v == "" {
  55. continue
  56. }
  57. insert := make(map[string]interface{})
  58. insert["top"] = rows[i][0]
  59. insert["area"] = rows[i][3]
  60. insert["city"] = rows[i][4]
  61. insert["level"] = rows[i][2]
  62. insert["sub"] = v
  63. insert["name"] = rows[i][4] + v
  64. Mgo.InsertOrUpdate("wcc", "wcc_0313", insert)
  65. }
  66. }
  67. if rows[i][2] == "县级" {
  68. for k, v := range cells[2] {
  69. if k == 0 || v == "" {
  70. continue
  71. }
  72. insert := make(map[string]interface{})
  73. insert["top"] = rows[i][0]
  74. insert["area"] = rows[i][3]
  75. insert["city"] = rows[i][4]
  76. insert["district"] = rows[i][5]
  77. insert["level"] = rows[i][2]
  78. insert["sub"] = v
  79. insert["name"] = rows[i][4] + rows[i][5] + v
  80. Mgo.InsertOrUpdate("wcc", "wcc_0313", insert)
  81. }
  82. }
  83. }
  84. fmt.Println("over")
  85. }
  86. func TestB(T *testing.T) {
  87. Mgo := &mongodb.MongodbSim{
  88. //MongodbAddr: "172.17.189.140:27080",
  89. MongodbAddr: "127.0.0.1:27083",
  90. Size: 10,
  91. DbName: "qfw",
  92. UserName: "SJZY_RWbid_ES",
  93. Password: "SJZY@B4i4D5e6S",
  94. Direct: true,
  95. }
  96. Mgo.InitPool()
  97. f, err := excelize.OpenFile("./fanglei.11111.xlsx")
  98. if err != nil {
  99. fmt.Println(err)
  100. return
  101. }
  102. defer func() {
  103. if err := f.Close(); err != nil {
  104. fmt.Println(err)
  105. }
  106. }()
  107. rows, err := f.GetRows("Sheet1")
  108. if err != nil {
  109. fmt.Println(err)
  110. return
  111. }
  112. for i := 1; i < len(rows); i++ {
  113. id := rows[i][0]
  114. re, _ := Mgo.FindById("bidding", id, nil)
  115. Mgo.SaveByOriID("wcc_0327_bidding", re)
  116. }
  117. log.Println("over")
  118. }
  119. func TestAAA(t *testing.T) {
  120. //87 竞品
  121. Mgo := &mongodb.MongodbSim{
  122. //MongodbAddr: "172.17.189.140:27080",
  123. MongodbAddr: "127.0.0.1:27081",
  124. Size: 10,
  125. DbName: "py_theme",
  126. UserName: "",
  127. Password: "",
  128. Direct: true,
  129. }
  130. Mgo.InitPool()
  131. sess := Mgo.GetMgoConn()
  132. defer Mgo.DestoryMongoConn(sess)
  133. f, err := excelize.OpenFile("./专项债券.xlsx")
  134. if err != nil {
  135. fmt.Println(err)
  136. return
  137. }
  138. defer func() {
  139. f.Save()
  140. if err := f.Close(); err != nil {
  141. fmt.Println(err)
  142. }
  143. }()
  144. rows, err := f.GetRows("项目列表")
  145. if err != nil {
  146. fmt.Println(err)
  147. return
  148. }
  149. keys := []string{"projectName", "totalInvestment", "regionName", "cityName", "countyName", "capital", "applyDebt", "portfolioFinancing", "specialDebtAsCapital",
  150. "expectedReturn", "projectCost", "projectTypeName3", "projectSubject", "startDate", "endDate", "operationStartDate",
  151. "operationEndDate", "sourceIncome", "constructionContent", "remarks", "portfolioFinancingSource", "costIncomePercent", "coverageMultiple", "implementingAgency",
  152. "accountingFirm", "lawFirm", "createTime", "updateTime"}
  153. titles := []string{"项目名称", "总投资(万元)", "省份", "地市", "区县", "不含专项债资本金(万元)", "申请专项债总额(万元)", "其他债务融资(万元)", "专项债作资本金(万元)", "预期收入(万元)", "成本",
  154. "项目领域", "项目业主", "建设期开始", "建设期结束", "运营期开始", "运营期结束", "收入来源", "建设内容", "特殊情况备注", "其他债务融资来源", "成本/收入(%)", "覆盖倍数", "主管部门", "会计所", "律所", "入库时间", "更新时间"}
  155. keys2 := []string{"bondName", "bondShortName", "bondNo", "regionName", "bondType1Name", "bondType2Name", "projectType1Name", "totalAmount", "issueDate", "issuePlaceName", "issueTerm", "issueInterestRate", "issuePhase", "payInterestMethodName",
  156. "newBondAmount", "counterBondAmount", "refinancingBondAmount", "redemptionMethod", "valueDate", "expiryDate", "payInterestDate", "latelyPayInterestDate", "lastPayInterest", "cumulativePayInterest"}
  157. titles2 := []string{"项目名称", "债券名称", "债券简称", "债券编码", "省份", "债券性质", "债券类型", "官方项目类型", "发行金额(万元)", "发行日期", "发行场所", "发行期限(年)", "发行利率(%)", "发行期数", "付息方式", "新增债券(亿元)", "置换债券(亿元)", "再融资债券(亿元)", "赎回方式",
  158. "起息日", "到息日", "付息日", "最近付息日", "上期已付息(亿元)", "累计付息(亿元)"}
  159. line := 0
  160. line++
  161. f.NewSheet("项目详情")
  162. f.NewSheet("债券详情")
  163. bondLine := 0
  164. //设置第一行title
  165. _ = f.SetSheetRow("项目详情", fmt.Sprintf("%s%d", "A", line), &titles)
  166. _ = f.SetSheetRow("债券详情", fmt.Sprintf("%s%d", "A", line), &titles2)
  167. //
  168. for i := 1; i < len(rows); i++ {
  169. projectName := rows[i][0]
  170. //projectName := "新建南通至宁波高速铁路(海盐段)"
  171. log.Println(projectName)
  172. line++
  173. where := map[string]interface{}{
  174. "project.jcxx.projectName": projectName,
  175. }
  176. detail, _ := Mgo.FindOne("specialbond_detail", where)
  177. if len(*detail) == 0 {
  178. continue
  179. }
  180. insert := make([]interface{}, 0)
  181. if project, ok := (*detail)["project"].(map[string]interface{}); ok {
  182. if jcxx, ok := project["jcxx"].(map[string]interface{}); ok {
  183. for _, v := range keys {
  184. insert = append(insert, jcxx[v])
  185. }
  186. }
  187. }
  188. err := f.SetSheetRow("项目详情", fmt.Sprintf("%s%d", "A", line), &insert)
  189. if err != nil {
  190. log.Println(err)
  191. return
  192. }
  193. // 债券基本信息
  194. if bonds, ok := (*detail)["bond"].([]interface{}); ok {
  195. for _, bond := range bonds {
  196. if bondData, ok := bond.(map[string]interface{}); ok {
  197. if jcxx, ok := bondData["jbxx"].(map[string]interface{}); ok {
  198. bondInsert := make([]interface{}, 0)
  199. bondInsert = append(bondInsert, projectName)
  200. for _, v := range keys2 {
  201. bondInsert = append(bondInsert, jcxx[v])
  202. }
  203. bondLine++
  204. f.SetSheetRow("债券详情", fmt.Sprintf("%s%d", "A", line), &bondInsert)
  205. }
  206. }
  207. }
  208. }
  209. }
  210. //query := sess.DB("py_theme").C("specialbond_detail").Find(nil).Select(nil).Iter()
  211. //count := 0
  212. //for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  213. // if count%10000 == 0 {
  214. // log.Println("current:", count)
  215. // }
  216. //
  217. // id := mongodb.BsonIdToSId(tmp["_id"])
  218. // log.Println(id)
  219. //}
  220. }