main.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. package main
  2. import (
  3. "go.uber.org/zap"
  4. "gorm.io/gorm"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  6. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  8. "strings"
  9. )
  10. var (
  11. Mgo *mongodb.MongodbSim //87 环境,采集 存储的MongoDB
  12. MysqlDB *gorm.DB
  13. )
  14. func main() {
  15. Init()
  16. //dealProject() // 处理项目、债券数据
  17. //dealProjectBondRelation() //更新项目和债券的关联关系
  18. /*导出数据*/
  19. exportData()
  20. }
  21. // dealProject 处理项目相关数据
  22. func dealProject() {
  23. tables := strings.Split(GF.Mongob.List, ",")
  24. detailNames := strings.Split(GF.Mongob.Detail, ",")
  25. //table := GF.Mongob.List
  26. //detailName := GF.Mongob.Detail //专项债详细表
  27. sess := Mgo.GetMgoConn()
  28. defer Mgo.DestoryMongoConn(sess)
  29. for k, table := range tables {
  30. detailName := detailNames[k]
  31. /**
  32. 这里测试用,使用 “新建成都至达州至万州铁路(南充段)(万源市)” 这个项目测试,他有变更信息
  33. */
  34. //where1 := map[string]interface{}{
  35. // //"projectName": "新建成都至达州至万州铁路(南充段)(万源市)",
  36. // "projectName": "新建成都至达州至万州铁路(南充段)(万源市)",
  37. //}
  38. //query := sess.DB("py_theme").C(table).Find(where1).Select(nil).Iter()
  39. query := sess.DB("py_theme").C(table).Find(nil).Select(nil).Iter()
  40. count := 0
  41. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  42. if count%100 == 0 {
  43. log.Info("current:", zap.Int("count", count), zap.Any("projectName", tmp["projectName"]), zap.String(table, detailName))
  44. }
  45. projectName := util.ObjToString(tmp["projectName"])
  46. //
  47. where := map[string]interface{}{
  48. "project.jcxx.projectName": projectName,
  49. }
  50. detail, _ := Mgo.FindOne(detailName, where)
  51. if len(*detail) == 0 {
  52. continue
  53. }
  54. //1.项目数据
  55. if project, ok := (*detail)["project"].(map[string]interface{}); ok {
  56. //1.基础信息
  57. var projectId int
  58. if jcxx, ok := project["jcxx"].(map[string]interface{}); ok {
  59. projectId = dealProjectBaseInfo(jcxx, projectName)
  60. }
  61. //2.还本付息
  62. if hbfx, ok := project["hbfx"].(map[string]interface{}); ok {
  63. dealProjectRepayment(hbfx, projectName, projectId)
  64. }
  65. //3.变更
  66. if bg, ok := project["bg"].([]interface{}); ok {
  67. if len(bg) > 0 {
  68. dealProjectChange(bg, projectName, projectId)
  69. }
  70. }
  71. //4.发行明细
  72. if fxmx, ok := project["fxmx"].([]interface{}); ok {
  73. if len(fxmx) > 0 {
  74. dealProjectIssueDetails(fxmx, projectName, projectId)
  75. }
  76. }
  77. }
  78. //2.处理债券信息
  79. if bonds, ok := (*detail)["bond"].([]interface{}); ok {
  80. dealBondInfo(bonds, projectName)
  81. }
  82. }
  83. log.Info("dealProject over ", zap.Int("total", count))
  84. }
  85. }
  86. // dealProjectBaseInfo 处理项目基本信息
  87. func dealProjectBaseInfo(jcxx map[string]interface{}, projectName string) (projectID int) {
  88. project_base_info_exist := ProjectBaseInfo{}
  89. err := MysqlDB.Where(&ProjectBaseInfo{ProjectName: projectName}).First(&project_base_info_exist).Error
  90. if err != nil && err != gorm.ErrRecordNotFound {
  91. // 处理查询错误
  92. log.Error("dealProjectBaseInfo;Error checking for existing project", zap.Error(err))
  93. }
  94. //当前项目基本信息已经存在
  95. if project_base_info_exist.ID > 0 {
  96. // 直接修改已存在记录的字段
  97. project_base_info_exist.TotalInvestment = util.Float64All(jcxx["totalInvestment"])
  98. project_base_info_exist.Area = util.ObjToString(jcxx["regionName"])
  99. project_base_info_exist.City = strings.ReplaceAll(util.ObjToString(jcxx["cityName"]), "本级", "")
  100. project_base_info_exist.District = strings.ReplaceAll(util.ObjToString(jcxx["countyName"]), "本级", "")
  101. project_base_info_exist.Capital = util.Float64All(jcxx["capital"])
  102. project_base_info_exist.ApplyTotalBonds = util.Float64All(jcxx["applyDebt"])
  103. project_base_info_exist.OtherDebtFinancing = util.Float64All(jcxx["portfolioFinancing"])
  104. project_base_info_exist.SpecialDebtCapital = util.Float64All(jcxx["specialDebtAsCapital"])
  105. project_base_info_exist.ExpectedReturn = util.Float64All(jcxx["expectedReturn"])
  106. project_base_info_exist.ProjectCost = util.IntAll(jcxx["projectCost"])
  107. project_base_info_exist.ProjectDomain = util.ObjToString(jcxx["projectTypeName3"])
  108. project_base_info_exist.ProjectOwner = util.ObjToString(jcxx["projectSubject"])
  109. project_base_info_exist.StartDate = util.ObjToString(jcxx["startDate"])
  110. project_base_info_exist.EndDate = util.ObjToString(jcxx["endDate"])
  111. project_base_info_exist.OperationStartDate = util.ObjToString(jcxx["operationStartDate"])
  112. project_base_info_exist.OperationEndDate = util.ObjToString(jcxx["operationEndDate"])
  113. project_base_info_exist.SourceIncome = util.ObjToString(jcxx["sourceIncome"])
  114. project_base_info_exist.ConstructionContent = util.ObjToString(jcxx["constructionContent"])
  115. project_base_info_exist.Remarks = util.ObjToString(jcxx["remarks"])
  116. project_base_info_exist.OtherDebtFinancingSource = util.ObjToString(jcxx["portfolioFinancingSource"])
  117. project_base_info_exist.CostIncomePercent = util.ObjToString(jcxx["costIncomePercent"])
  118. project_base_info_exist.CoverageMultiple = util.Float64All(jcxx["coverageMultiple"])
  119. project_base_info_exist.CompetentDepartment = util.ObjToString(jcxx["implementingAgency"])
  120. project_base_info_exist.AccountingFirm = util.ObjToString(jcxx["accountingFirm"])
  121. project_base_info_exist.LawFirm = util.ObjToString(jcxx["lawFirm"])
  122. project_base_info_exist.UpdateDate = util.ObjToString(jcxx["updateTime"])
  123. project_base_info_exist.CreateDate = util.ObjToString(jcxx["createTime"])
  124. // 使用 Save 来更新
  125. err = MysqlDB.Save(&project_base_info_exist).Error
  126. if err != nil {
  127. log.Info("dealProject Save (Update) ", zap.Error(err))
  128. }
  129. return project_base_info_exist.ID
  130. } else {
  131. project_base_info := ProjectBaseInfo{
  132. ProjectName: projectName,
  133. TotalInvestment: util.Float64All(jcxx["totalInvestment"]),
  134. Area: util.ObjToString(jcxx["regionName"]),
  135. City: strings.ReplaceAll(util.ObjToString(jcxx["cityName"]), "本级", ""),
  136. District: strings.ReplaceAll(util.ObjToString(jcxx["countyName"]), "本级", ""),
  137. Capital: util.Float64All(jcxx["capital"]),
  138. ApplyTotalBonds: util.Float64All(jcxx["applyDebt"]),
  139. OtherDebtFinancing: util.Float64All(jcxx["portfolioFinancing"]),
  140. SpecialDebtCapital: util.Float64All(jcxx["specialDebtAsCapital"]),
  141. ExpectedReturn: util.Float64All(jcxx["expectedReturn"]),
  142. ProjectCost: util.IntAll(jcxx["projectCost"]),
  143. ProjectDomain: util.ObjToString(jcxx["projectTypeName3"]), // 项目领域
  144. ProjectOwner: util.ObjToString(jcxx["projectSubject"]), //项目业主
  145. StartDate: util.ObjToString(jcxx["startDate"]),
  146. EndDate: util.ObjToString(jcxx["endDate"]),
  147. OperationStartDate: util.ObjToString(jcxx["operationStartDate"]),
  148. OperationEndDate: util.ObjToString(jcxx["operationEndDate"]),
  149. SourceIncome: util.ObjToString(jcxx["sourceIncome"]),
  150. ConstructionContent: util.ObjToString(jcxx["constructionContent"]),
  151. Remarks: util.ObjToString(jcxx["remarks"]),
  152. OtherDebtFinancingSource: util.ObjToString(jcxx["portfolioFinancingSource"]),
  153. CostIncomePercent: util.ObjToString(jcxx["costIncomePercent"]),
  154. CoverageMultiple: util.Float64All(jcxx["coverageMultiple"]),
  155. CompetentDepartment: util.ObjToString(jcxx["implementingAgency"]),
  156. AccountingFirm: util.ObjToString(jcxx["accountingFirm"]),
  157. LawFirm: util.ObjToString(jcxx["lawFirm"]),
  158. CreateDate: util.ObjToString(jcxx["createTime"]),
  159. UpdateDate: util.ObjToString(jcxx["updateTime"]),
  160. }
  161. err = MysqlDB.Create(&project_base_info).Error
  162. if err != nil {
  163. log.Info("dealProjectBaseInfo;dealProject Create ", zap.Error(err), zap.String("project", projectName))
  164. }
  165. return project_base_info.ID
  166. }
  167. }
  168. // dealProjectRepayment 处理项目-还本付息
  169. func dealProjectRepayment(hbfx map[string]interface{}, projectName string, projectID int) {
  170. project_repayment_exist := ProjectRepayment{}
  171. err := MysqlDB.Where(&ProjectRepayment{ProjectName: projectName, BondName: util.ObjToString(hbfx["bondName"])}).First(&project_repayment_exist).Error
  172. if err != nil && err != gorm.ErrRecordNotFound {
  173. // 处理查询错误
  174. log.Error("dealProjectRepayment;Error checking for existing project", zap.Error(err))
  175. }
  176. if project_repayment_exist.ID > 0 {
  177. project_repayment_exist.IssueTerm = util.IntAll(hbfx["issueTerm"])
  178. project_repayment_exist.PayInterestMethodName = util.ObjToString(hbfx["payInterestMethodName"])
  179. project_repayment_exist.ValueDate = util.ObjToString(hbfx["valueDate"])
  180. project_repayment_exist.InterestDate = util.ObjToString(hbfx["payInterestDate"])
  181. project_repayment_exist.LastInterestDate = util.ObjToString(hbfx["latelyPayInterestDate"])
  182. project_repayment_exist.ReminderRepayDays = util.IntAll(hbfx["days"])
  183. project_repayment_exist.MaturityDate = util.ObjToString(hbfx["expiryDate"])
  184. project_repayment_exist.DebtService = util.Float64All(hbfx["repayCapitalWithInterest"])
  185. project_repayment_exist.RedemptionMethod = util.ObjToString(hbfx["redemptionMethod"])
  186. project_repayment_exist.CumulativePayInterest = util.IntAll(hbfx["cumulativePayInterest"])
  187. project_repayment_exist.IsEarlyRepayPrincipal = util.ObjToString(hbfx["isEarlyRepayPrincipal"])
  188. project_repayment_exist.Remarks = util.ObjToString(hbfx["remarks"])
  189. // 使用 Save 来更新
  190. err = MysqlDB.Save(&project_repayment_exist).Error
  191. if err != nil {
  192. log.Info("dealProjectRepayment Save (Update) ", zap.Error(err))
  193. }
  194. } else {
  195. project_payment := ProjectRepayment{
  196. ProjectName: projectName,
  197. ProjectID: projectID,
  198. BondName: util.ObjToString(hbfx["bondName"]),
  199. IssueTerm: util.IntAll(hbfx["issueTerm"]),
  200. PayInterestMethodName: util.ObjToString(hbfx["payInterestMethodName"]),
  201. ValueDate: util.ObjToString(hbfx["valueDate"]),
  202. InterestDate: util.ObjToString(hbfx["payInterestDate"]),
  203. LastInterestDate: util.ObjToString(hbfx["latelyPayInterestDate"]),
  204. ReminderRepayDays: util.IntAll(hbfx["days"]), //提醒还款天数
  205. MaturityDate: util.ObjToString(hbfx["expiryDate"]), //到期日
  206. DebtService: util.Float64All(hbfx["repayCapitalWithInterest"]), //还本付息(万元)
  207. RedemptionMethod: util.ObjToString(hbfx["redemptionMethod"]),
  208. CumulativePayInterest: util.IntAll(hbfx["cumulativePayInterest"]),
  209. IsEarlyRepayPrincipal: util.ObjToString(hbfx["isEarlyRepayPrincipal"]),
  210. Remarks: util.ObjToString(hbfx["remarks"]),
  211. }
  212. err = MysqlDB.Create(&project_payment).Error
  213. if err != nil {
  214. log.Info("dealProjectRepayment;dealProject Create ", zap.Error(err), zap.String("project", projectName))
  215. }
  216. }
  217. }
  218. // dealProjectChange 处理项目变更
  219. func dealProjectChange(bg []interface{}, projectName string, projectId int) {
  220. for _, v := range bg {
  221. if bgda, ok := v.(map[string]interface{}); ok {
  222. project_change := ProjectChange{
  223. ProjectName: projectName,
  224. ProjectID: projectId,
  225. ChangeContent: util.ObjToString(bgda["changeContent"]),
  226. UpdateReason: util.ObjToString(bgda["updateReason"]),
  227. SubmitTime: util.ObjToString(bgda["submitTime"]),
  228. }
  229. err := MysqlDB.Create(&project_change).Error
  230. if err != nil {
  231. log.Info("dealProjectChange; Create err", zap.Error(err))
  232. }
  233. }
  234. }
  235. }
  236. // dealProjectIssueDetails 处理项目发行明细
  237. func dealProjectIssueDetails(fxmx []interface{}, projectName string, projectId int) {
  238. for _, v := range fxmx {
  239. if fx, ok := v.(map[string]interface{}); ok {
  240. project_bach_name := util.ObjToString(fx["projectBatchName"])
  241. issue_detail_exist := ProjectIssueDetails{}
  242. err := MysqlDB.Where(&ProjectIssueDetails{ProjectName: projectName, ProjectBachName: project_bach_name, BondName: util.ObjToString(fx["bondName"])}).First(&issue_detail_exist).Error
  243. if err != nil && err != gorm.ErrRecordNotFound {
  244. // 处理查询错误
  245. log.Error("dealProjectIssueDetails;Error checking for existing project", zap.Error(err))
  246. }
  247. // 存在
  248. if issue_detail_exist.ID > 0 {
  249. issue_detail_exist.FirstPublishDate = util.ObjToString(fx["firstPublishDate"])
  250. issue_detail_exist.BatchNum = util.IntAll(fx["batchNum"])
  251. issue_detail_exist.PresentIssueAmount = util.Float64All(fx["presentIssueAmount"])
  252. issue_detail_exist.IssueInterestRate = util.Float64All(fx["issueInterestRate"])
  253. issue_detail_exist.PresentAsSpecialAmount = util.Float64All(fx["presentAsSpecialAmount"])
  254. issue_detail_exist.TotalIssueAmount = util.Float64All(fx["totalIssueAmount"])
  255. issue_detail_exist.ReviseLog = util.ObjToString(fx["revise_log"])
  256. err = MysqlDB.Save(&issue_detail_exist).Error
  257. if err != nil {
  258. log.Info("dealProjectIssueDetails Save (Update) ", zap.Error(err))
  259. }
  260. } else {
  261. issue_detail := ProjectIssueDetails{
  262. ProjectName: projectName,
  263. ProjectID: projectId,
  264. ProjectBachName: project_bach_name,
  265. BondName: util.ObjToString(fx["bondName"]),
  266. FirstPublishDate: util.ObjToString(fx["firstPublishDate"]),
  267. BatchNum: util.IntAll(fx["batchNum"]),
  268. PresentIssueAmount: util.Float64All(fx["presentIssueAmount"]),
  269. IssueInterestRate: util.Float64All(fx["issueInterestRate"]),
  270. PresentAsSpecialAmount: util.Float64All(fx["presentAsSpecialAmount"]),
  271. TotalIssueAmount: util.Float64All(fx["totalIssueAmount"]),
  272. ReviseLog: util.ObjToString(fx["revise_log"]),
  273. }
  274. err := MysqlDB.Create(&issue_detail).Error
  275. if err != nil {
  276. log.Info("dealProjectIssueDetails; Create err", zap.Error(err))
  277. }
  278. }
  279. }
  280. }
  281. }
  282. // dealBondInfo 处理债券信息
  283. func dealBondInfo(bonds []interface{}, projectName string) {
  284. for _, v := range bonds {
  285. if bond, ok := v.(map[string]interface{}); ok {
  286. //1.基本信息
  287. if jbxx, ok := bond["jbxx"].(map[string]interface{}); ok {
  288. dealBondBase(jbxx, projectName)
  289. }
  290. //2.债券-修改记录;xgjl
  291. if xgjl, ok := bond["xgjl"].([]interface{}); ok && len(xgjl) > 0 {
  292. dealBondChange(xgjl)
  293. }
  294. ////3.相关小项目
  295. //if xgxxx, ok := bond["xgxxx"].([]interface{}); ok && len(xgxxx) > 0 {
  296. // dealRelationProject(xgxxx)
  297. //}
  298. }
  299. }
  300. }
  301. // dealBondBase 处理债券基本信息
  302. func dealBondBase(jbxx map[string]interface{}, projectName string) {
  303. bond_info_exist := BondInfo{}
  304. err := MysqlDB.Where(&BondInfo{BondName: util.ObjToString(jbxx["bondName"]), BondNo: util.ObjToString(jbxx["bondNo"])}).First(&bond_info_exist).Error
  305. if err != nil && err != gorm.ErrRecordNotFound {
  306. // 处理查询错误
  307. log.Error("dealBondBase;Error checking for existing project", zap.Error(err))
  308. }
  309. if bond_info_exist.ID > 0 {
  310. bond_info_exist.BondShortName = util.ObjToString(jbxx["bondName"])
  311. bond_info_exist.Area = util.ObjToString(jbxx["regionName"])
  312. bond_info_exist.BondNature = util.ObjToString(jbxx["bondType1Name"])
  313. bond_info_exist.BondType = util.ObjToString(jbxx["bondType2Name"])
  314. bond_info_exist.OfficialProjectType = util.ObjToString(jbxx["projectType1Name"])
  315. bond_info_exist.TotalAmount = util.Float64All(jbxx["totalAmount"])
  316. bond_info_exist.IssueDate = util.ObjToString(jbxx["issueDate"])
  317. bond_info_exist.IssuePlace = util.ObjToString(jbxx["issuePlaceName"])
  318. bond_info_exist.IssueTerm = util.IntAll(jbxx["issueTerm"])
  319. bond_info_exist.IssueInterestRate = util.ObjToString(jbxx["issueInterestRate"])
  320. bond_info_exist.IssuePhase = util.ObjToString(jbxx["issuePhase"])
  321. bond_info_exist.WayOfPayInterest = util.ObjToString(jbxx["payInterestMethodName"])
  322. bond_info_exist.NewBondAmount = util.Float64All(jbxx["newBondAmount"])
  323. bond_info_exist.CounterBondAmount = util.Float64All(jbxx["counterBondAmount"])
  324. bond_info_exist.RefinancingBondAmount = util.Float64All(jbxx["refinancingBondAmount"])
  325. bond_info_exist.RedemptionMethod = util.ObjToString(jbxx["redemptionMethod"])
  326. bond_info_exist.ValueDate = util.ObjToString(jbxx["valueDate"])
  327. bond_info_exist.ExpiryDate = util.ObjToString(jbxx["expiryDate"])
  328. bond_info_exist.PayInterestDate = util.ObjToString(jbxx["payInterestDate"])
  329. bond_info_exist.LatePayInterestDate = util.ObjToString(jbxx["latelyPayInterestDate"])
  330. bond_info_exist.IsEarlyRepayPrincipal = util.ObjToString(jbxx["isEarlyRepayPrincipal"])
  331. bond_info_exist.CumulativePayInterest = util.Float64All(jbxx["cumulativePayInterest"])
  332. bond_info_exist.IsCounterBond = util.ObjToString(jbxx["isCounterBond"])
  333. err = MysqlDB.Save(&bond_info_exist).Error
  334. if err != nil {
  335. log.Info("dealBondBase Save (Update) ", zap.Error(err))
  336. }
  337. } else {
  338. bond_info := BondInfo{
  339. BondName: util.ObjToString(jbxx["bondName"]),
  340. BondShortName: util.ObjToString(jbxx["bondShortName"]),
  341. BondNo: util.ObjToString(jbxx["bondNo"]),
  342. Area: util.ObjToString(jbxx["regionName"]),
  343. BondNature: util.ObjToString(jbxx["bondType1Name"]),
  344. BondType: util.ObjToString(jbxx["bondType2Name"]),
  345. OfficialProjectType: util.ObjToString(jbxx["projectType1Name"]),
  346. TotalAmount: util.Float64All(jbxx["totalAmount"]),
  347. IssueDate: util.ObjToString(jbxx["issueDate"]),
  348. IssuePlace: util.ObjToString(jbxx["issuePlaceName"]),
  349. IssueTerm: util.IntAll(jbxx["issueTerm"]),
  350. IssueInterestRate: util.ObjToString(jbxx["issueInterestRate"]),
  351. IssuePhase: util.ObjToString(jbxx["issuePhase"]),
  352. WayOfPayInterest: util.ObjToString(jbxx["payInterestMethodName"]),
  353. NewBondAmount: util.Float64All(jbxx["newBondAmount"]),
  354. CounterBondAmount: util.Float64All(jbxx["counterBondAmount"]),
  355. RefinancingBondAmount: util.Float64All(jbxx["refinancingBondAmount"]),
  356. RedemptionMethod: util.ObjToString(jbxx["redemptionMethod"]),
  357. ValueDate: util.ObjToString(jbxx["valueDate"]),
  358. ExpiryDate: util.ObjToString(jbxx["expiryDate"]),
  359. PayInterestDate: util.ObjToString(jbxx["payInterestDate"]),
  360. LatePayInterestDate: util.ObjToString(jbxx["latelyPayInterestDate"]),
  361. RemindPayDays: util.IntAll(jbxx["days"]),
  362. LastPayInterest: util.Float64All(jbxx["lastPayInterest"]),
  363. IsEarlyRepayPrincipal: util.ObjToString(jbxx["isEarlyRepayPrincipal"]),
  364. CumulativePayInterest: util.Float64All(jbxx["cumulativePayInterest"]),
  365. IsCounterBond: util.ObjToString(jbxx["isCounterBond"]),
  366. }
  367. //
  368. err = MysqlDB.Create(&bond_info).Error
  369. if err != nil {
  370. log.Info("dealBondBase;dealProject Create ", zap.Error(err), zap.String("project", projectName))
  371. }
  372. }
  373. }
  374. // dealBondChange 修改债券修改信息
  375. func dealBondChange(xgjl []interface{}) {
  376. }
  377. // dealProjectBondRelation 处理项目债券关联关系
  378. func dealProjectBondRelation() {
  379. //detailName := GF.Mongob.Detail //专项债详细表
  380. detailNames := strings.Split(GF.Mongob.Detail, ",")
  381. sess := Mgo.GetMgoConn()
  382. defer Mgo.DestoryMongoConn(sess)
  383. for _, detailName := range detailNames {
  384. query := sess.DB("py_theme").C(detailName).Find(nil).Select(nil).Iter()
  385. count := 0
  386. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  387. if count%100 == 0 {
  388. log.Info("current:", zap.Int("count", count))
  389. }
  390. if project, ok := tmp["project"].(map[string]interface{}); ok {
  391. //1.基础信息
  392. if jcxx, ok := project["jcxx"].(map[string]interface{}); ok {
  393. project_name := util.ObjToString(jcxx["projectName"])
  394. //fmt.Println(project_name)
  395. project_base_info_exist := ProjectBaseInfo{}
  396. err := MysqlDB.Where(&ProjectBaseInfo{ProjectName: project_name}).First(&project_base_info_exist).Error
  397. if err != nil && err != gorm.ErrRecordNotFound {
  398. // 处理查询错误
  399. log.Error("dealProjectBondRelation;Error checking for existing project", zap.Error(err))
  400. } else {
  401. if project_base_info_exist.ID > 0 {
  402. //1.更新项目的创建时间
  403. project_base_info_exist.CreateDate = util.ObjToString(jcxx["createTime"])
  404. project_base_info_exist.UpdateDate = util.ObjToString(jcxx["updateTime"])
  405. err = MysqlDB.Save(&project_base_info_exist).Error
  406. if err != nil {
  407. log.Info("dealProjectBondRelation Save (Update) ", zap.Error(err))
  408. }
  409. //2.更新项目和债券的对应关系
  410. if fxmx, ok := project["fxmx"].([]interface{}); ok {
  411. for _, v := range fxmx {
  412. if fx, ok := v.(map[string]interface{}); ok {
  413. bond_name := util.ObjToString(fx["bondName"])
  414. bond_info_exist := BondInfo{}
  415. err := MysqlDB.Where(&BondInfo{BondName: bond_name}).First(&bond_info_exist).Error
  416. if err != nil && err != gorm.ErrRecordNotFound {
  417. // 处理查询错误
  418. log.Error("dealProjectBondRelation;Error checking for existing project", zap.Error(err))
  419. } else {
  420. // 整理对应关系
  421. relation := ProjectBondRelation{
  422. ProjectID: project_base_info_exist.ID,
  423. BondID: bond_info_exist.ID,
  424. }
  425. result := MysqlDB.FirstOrCreate(&relation, ProjectBondRelation{
  426. ProjectID: relation.ProjectID,
  427. BondID: relation.BondID,
  428. })
  429. if result.Error != nil {
  430. // 处理错误
  431. log.Error("dealProjectBondRelation;Error checking for existing project", zap.Error(err), zap.String(project_name, bond_name))
  432. }
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. log.Info("dealProjectBondRelation", zap.Any("数据处理完毕", count))
  443. }
  444. }