xlsx_test.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. // TestAAA 处理专项债券数据
  120. func TestAAA(t *testing.T) {
  121. //87 竞品
  122. Mgo := &mongodb.MongodbSim{
  123. //MongodbAddr: "172.17.189.140:27080",
  124. MongodbAddr: "127.0.0.1:27081",
  125. Size: 10,
  126. DbName: "py_theme",
  127. UserName: "",
  128. Password: "",
  129. Direct: true,
  130. }
  131. Mgo.InitPool()
  132. sess := Mgo.GetMgoConn()
  133. defer Mgo.DestoryMongoConn(sess)
  134. f, err := excelize.OpenFile("./四川专项债.xlsx")
  135. if err != nil {
  136. fmt.Println(err)
  137. return
  138. }
  139. defer func() {
  140. f.Save()
  141. if err := f.Close(); err != nil {
  142. fmt.Println(err)
  143. }
  144. }()
  145. rows, err := f.GetRows("项目列表")
  146. if err != nil {
  147. fmt.Println(err)
  148. return
  149. }
  150. keys := []string{"projectName", "totalInvestment", "regionName", "cityName", "countyName", "capital", "applyDebt", "portfolioFinancing", "specialDebtAsCapital",
  151. "expectedReturn", "projectCost", "projectTypeName3", "projectSubject", "startDate", "endDate", "operationStartDate",
  152. "operationEndDate", "sourceIncome", "constructionContent", "remarks", "portfolioFinancingSource", "costIncomePercent", "coverageMultiple", "implementingAgency",
  153. "accountingFirm", "lawFirm", "createTime", "updateTime"}
  154. titles := []string{"项目名称", "总投资(万元)", "省份", "地市", "区县", "不含专项债资本金(万元)", "申请专项债总额(万元)", "其他债务融资(万元)", "专项债作资本金(万元)", "预期收入(万元)", "成本",
  155. "项目领域", "项目业主", "建设期开始", "建设期结束", "运营期开始", "运营期结束", "收入来源", "建设内容", "特殊情况备注", "其他债务融资来源", "成本/收入(%)", "覆盖倍数", "主管部门", "会计所", "律所", "入库时间", "更新时间"}
  156. keys2 := []string{"bondName", "bondShortName", "bondNo", "regionName", "bondType1Name", "bondType2Name", "projectType1Name", "totalAmount", "issueDate", "issuePlaceName", "issueTerm", "issueInterestRate", "issuePhase", "payInterestMethodName",
  157. "newBondAmount", "counterBondAmount", "refinancingBondAmount", "redemptionMethod", "valueDate", "expiryDate", "payInterestDate", "latelyPayInterestDate", "lastPayInterest", "cumulativePayInterest"}
  158. titles2 := []string{"项目名称", "债券名称", "债券简称", "债券编码", "省份", "债券性质", "债券类型", "官方项目类型", "发行金额(万元)", "发行日期", "发行场所", "发行期限(年)", "发行利率(%)", "发行期数", "付息方式", "新增债券(亿元)", "置换债券(亿元)", "再融资债券(亿元)", "赎回方式",
  159. "起息日", "到息日", "付息日", "最近付息日", "上期已付息(亿元)", "累计付息(亿元)"}
  160. line := 0
  161. line++
  162. f.NewSheet("项目详情")
  163. f.NewSheet("债券详情")
  164. bondLine := 0
  165. //设置第一行title
  166. _ = f.SetSheetRow("项目详情", fmt.Sprintf("%s%d", "A", line), &titles)
  167. _ = f.SetSheetRow("债券详情", fmt.Sprintf("%s%d", "A", line), &titles2)
  168. //
  169. for i := 1; i < len(rows); i++ {
  170. projectName := rows[i][0]
  171. //projectName := "新建南通至宁波高速铁路(海盐段)"
  172. log.Println(projectName)
  173. line++
  174. where := map[string]interface{}{
  175. "project.jcxx.projectName": projectName,
  176. }
  177. detail, _ := Mgo.FindOne("specialbond_detail", where)
  178. if len(*detail) == 0 {
  179. continue
  180. }
  181. insert := make([]interface{}, 0)
  182. if project, ok := (*detail)["project"].(map[string]interface{}); ok {
  183. if jcxx, ok := project["jcxx"].(map[string]interface{}); ok {
  184. for _, v := range keys {
  185. insert = append(insert, jcxx[v])
  186. }
  187. }
  188. }
  189. err := f.SetSheetRow("项目详情", fmt.Sprintf("%s%d", "A", line), &insert)
  190. if err != nil {
  191. log.Println(err)
  192. return
  193. }
  194. // 债券基本信息
  195. if bonds, ok := (*detail)["bond"].([]interface{}); ok {
  196. for _, bond := range bonds {
  197. if bondData, ok := bond.(map[string]interface{}); ok {
  198. if jcxx, ok := bondData["jbxx"].(map[string]interface{}); ok {
  199. //if strings.Contains(util.ObjToString(jcxx["bondName"]), "2024") {
  200. bondInsert := make([]interface{}, 0)
  201. bondInsert = append(bondInsert, projectName)
  202. for _, v := range keys2 {
  203. bondInsert = append(bondInsert, jcxx[v])
  204. }
  205. bondLine++
  206. f.SetSheetRow("债券详情", fmt.Sprintf("%s%d", "A", line), &bondInsert)
  207. //}
  208. }
  209. }
  210. }
  211. }
  212. }
  213. //query := sess.DB("py_theme").C("specialbond_detail").Find(nil).Select(nil).Iter()
  214. //count := 0
  215. //for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  216. // if count%10000 == 0 {
  217. // log.Println("current:", count)
  218. // }
  219. //
  220. // id := mongodb.BsonIdToSId(tmp["_id"])
  221. // log.Println(id)
  222. //}
  223. }