xlsx_test.go 7.3 KB

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